/** * Xid translation based on OVXSwitch, for cases where port cannot be * determined. * * @param msg the OpenFlow message * @param vsw the virtual switch instance * @return new Xid for msg */ public static Integer translateXid(final OFMessage msg, final OVXSwitch vsw) { // this returns the original XID for a BigSwitch final Integer xid = vsw.translate(msg, null); msg.setXid(xid); return xid; }
@Override protected void sendHandShakeMessage(final OFType type) throws IOException { final OFMessage m = BasicFactory.getInstance().getMessage(type); m.setXid(this.handshakeTransactionIds--); this.channel.write(Collections.singletonList(m)); }
/** * Send a message to the switch using the handshake transactions ids. * * @param type the type * @throws IOException */ @Override protected void sendHandShakeMessage(final OFType type) throws IOException { final OFMessage m = BasicFactory.getInstance().getMessage(type); m.setXid(this.handshakeTransactionIds--); this.channel.write(Collections.singletonList(m)); }
/** * Xid translation based on port for "accurate" translation with a specific * PhysicalSwitch. * * @param msg the OpenFlow message * @param inPort the virtual input port instance * @return the virtual switch */ public static OVXSwitch translateXid(final OFMessage msg, final OVXPort inPort) { final OVXSwitch vsw = inPort.getParentSwitch(); final int xid = vsw.translate(msg, inPort); msg.setXid(xid); return vsw; }
/** * This method puts the message in an outgoing priority queue with high * priority. It will be served first before normal priority messages. The * method should be used for critical messages such as hello, echo reply * etc. The specified XID is inserted into the message. * * @param msg * The OF message to be sent * @return The XID used */ @Override public Integer asyncFastSend(OFMessage msg, int xid) { msg.setXid(xid); if (transmitQ != null) { transmitQ.add(new PriorityMessage(msg, 1)); } return xid; }
/** * This method bypasses the transmit queue and sends the message over the * socket directly. If the input xid is not null, the specified xid is * inserted into the message. Otherwise, an unique xid is generated * automatically and inserted into the message. * * @param msg * Message to be sent * @param xid * Message xid */ private void asyncSendNow(OFMessage msg, Integer xid) { if (xid == null) { xid = getNextXid(); } msg.setXid(xid); asyncSendNow(msg); }
/** * This method puts the message in an outgoing priority queue with normal * priority. It will be served after high priority messages. The method * should be used for non-critical messages such as statistics request, * discovery packets, etc. The specified XID is inserted into the message. * * @param msg * The OF message to be Sent * @param xid * The XID to be used in the message * @return The XID used */ @Override public Integer asyncSend(OFMessage msg, int xid) { msg.setXid(xid); if (transmitQ != null) { transmitQ.add(new PriorityMessage(msg, 0)); } return xid; }
/** * Undoes the XID translation and returns the original virtual switch. * * @param msg the OpenFlow message * @param psw the physical switch * @return the virtual switch */ public static OVXSwitch untranslateXid(final OFMessage msg, final PhysicalSwitch psw) { final XidPair<OVXSwitch> pair = psw.untranslate(msg); if (pair == null) { return null; } msg.setXid(pair.getXid()); return pair.getSwitch(); }
/** * Translates the Xid of a PhysicalSwitch-bound message and sends it there. * For when port is not known. * * @param msg the OpenFlow message * @param vsw the virtual switch instance */ public static void translateXidAndSend(final OFMessage msg, final OVXSwitch vsw) { final int newXid = OVXMessageUtil.translateXid(msg, vsw); if (vsw instanceof OVXBigSwitch) { // no port info for BigSwitch, to all its PhysicalSwitches. Is this // ok? try { for (final PhysicalSwitch psw : vsw.getMap() .getPhysicalSwitches(vsw)) { final int xid = psw.translate(msg, vsw); msg.setXid(xid); psw.sendMsg(msg, vsw); msg.setXid(newXid); } } catch (SwitchMappingException e) { log.error("Switch {} is not mapped to any physical switches.", vsw); } } else { vsw.sendSouth(msg, null); } }
@Override public void sendMsg(final OFMessage msg, final OVXSendMsg from) { XidPair<Channel> pair = channelMux.untranslate(msg.getXid()); Channel c = null; if (pair != null) { msg.setXid(pair.getXid()); c = pair.getSwitch(); } if (this.isConnected && this.isActive) { roleMan.sendMsg(msg, c); } else { // TODO: we probably should install a drop rule here. log.warn( "Virtual switch {} is not active or is not connected to a controller", switchName); } }
@Override public void handleIO(final OFMessage msg, Channel channel) { /* * Save the channel the msg came in on */ msg.setXid(channelMux.translate(msg.getXid(), channel)); try { /* * Check whether this channel (i.e., controller) is permitted to * send this msg to the dataplane */ if (this.roleMan.canSend(channel, msg)) { ((Devirtualizable) msg).devirtualize(this); } else { denyAccess(channel, msg, this.roleMan.getRole(channel)); } } catch (final ClassCastException e) { OVXSwitch.log.error("Received illegal message: " + msg); } }