/** * Returns a summary of the message * * @return "ofmsg=v=$version;t=$type:l=$len:xid=$xid" */ @Override public String toString() { return "ofmsg" + ":v=" + U8.f(this.getVersion()) + ";t=" + this.getType() + ";l=" + this.getLengthU() + ";x=" + U32.f(this.getXid()); }
@Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (!super.equals(obj)) { return false; } if (!(obj instanceof OFQueueGetConfigReply)) { return false; } final OFQueueGetConfigReply other = (OFQueueGetConfigReply) obj; if (this.portNumber != other.portNumber) { return false; } return true; } }
@Override public int hashCode() { final int prime = 349; int result = super.hashCode(); result = prime * result + this.portNumber; return result; }
/** * Write this offending message into the payload of the Error message * * @param offendingMsg */ public void setOffendingMsg(final OFMessage offendingMsg) { if (offendingMsg == null) { super.setLengthU(OFError.MINIMUM_LENGTH); } else { this.error = new byte[offendingMsg.getLengthU()]; final ChannelBuffer data = ChannelBuffers.wrappedBuffer(this.error); data.writerIndex(0); offendingMsg.writeTo(data); super.setLengthU(OFError.MINIMUM_LENGTH + offendingMsg.getLengthU()); } }
@Override protected Object encode(final ChannelHandlerContext ctx, final Channel channel, final Object msg) throws Exception { if (!(msg instanceof List)) { return msg; } @SuppressWarnings("unchecked") final List<OFMessage> msglist = (List<OFMessage>) msg; int size = 0; for (final OFMessage ofm : msglist) { size += ofm.getLengthU(); } final ChannelBuffer buf = ChannelBuffers.buffer(size); for (final OFMessage ofm : msglist) { ofm.writeTo(buf); } return buf; }
public XidPair<OVXSwitch> untranslate(final OFMessage ofm) { final XidPair<OVXSwitch> pair = this.translator.untranslate(ofm .getXid()); if (pair == null) { return null; } return pair; }
public boolean canSend(Channel channel, OFMessage m) { Role r = this.currentState.get().get(channel); if (r == Role.MASTER || r == Role.EQUAL) { return true; } switch (m.getType()) { case GET_CONFIG_REQUEST: case QUEUE_GET_CONFIG_REQUEST: case PORT_STATUS: case STATS_REQUEST: return true; default: return false; } }
@Override public void writeTo(final ChannelBuffer bb) { super.writeTo(bb); if (this.payload != null) { bb.writeBytes(this.payload); } }
@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); } }
public OFMessage parseMessageOne(final ChannelBuffer data) throws MessageParseException { try { final OFMessage demux = new OFMessage(); OFMessage ofm = null; demux.readFrom(data); data.resetReaderIndex(); if (demux.getLengthU() > data.readableBytes()) { return ofm; ofm = this.getMessage(demux.getType()); if (ofm == null) { return null; ofm.readFrom(data); if (OFMessage.class.equals(ofm.getClass())) { data.readerIndex(data.readerIndex() + ofm.getLengthU() - OFMessage.MINIMUM_LENGTH);
/** * 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 public void readFrom(final ChannelBuffer data) { super.readFrom(data); this.vendor = data.readInt(); if (this.vendorDataFactory == null) { throw new RuntimeException("OFVendorDataFactory not set"); } this.vendorData = this.vendorDataFactory.parseVendorData(this.vendor, data, super.getLengthU() - OFVendor.MINIMUM_LENGTH); }
public static byte[] getData(final OFMessage msg) { return OFMessage.getDataAsString(msg).getBytes(); } }
public int translate(final OFMessage ofm, final OVXSwitch sw) { return this.translator.translate(ofm.getXid(), sw); }
public boolean canReceive(Channel channel, OFMessage m) { Role r = this.currentState.get().get(channel); if (r == Role.MASTER || r == Role.EQUAL) { return true; } switch (m.getType()) { case GET_CONFIG_REPLY: case QUEUE_GET_CONFIG_REPLY: case PORT_STATUS: case STATS_REPLY: return true; default: return false; } }
@Override public void writeTo(final ChannelBuffer data) { super.writeTo(data); data.writeInt(this.vendor); if (this.vendorData != null) { this.vendorData.writeTo(data); } }
@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); } }
public void asyncSend(OFMessage msg) throws Exception { synchronized (outBuffer) { int msgLen = msg.getLengthU(); if (outBuffer.remaining() < msgLen) { msg.writeTo(outBuffer);