@Test(timeout = 5000) public void testSingleMessageWrite() throws InterruptedException, ExecutionException { Capture<List<OFMessage>> cMsgList = prepareChannelForWriteList(); OFPacketOut packetOut = factory.buildPacketOut() .setData(new byte[] { 0x01, 0x02, 0x03, 0x04 }) .setActions(ImmutableList.<OFAction>of( factory.actions().output(OFPort.of(1), 0))) .build(); conn.write(packetOut); assertThat("Write should have been flushed", cMsgList.hasCaptured(), equalTo(true)); List<OFMessage> value = cMsgList.getValue(); logger.info("Captured channel write: "+value); assertThat("Should have captured MsgList", cMsgList.getValue(), Matchers.<OFMessage> contains(packetOut)); }
@Override public void write(OFMessage m) { if (!isConnected()) { if (logger.isDebugEnabled()) logger.debug("{}: not connected - dropping message {}", this, m); return; } if (logger.isDebugEnabled()) logger.debug("{}: send {}", this, m); List<OFMessage> msgBuffer = localMsgBuffer.get(); if (msgBuffer == null) { msgBuffer = new ArrayList<OFMessage>(); localMsgBuffer.set(msgBuffer); } counters.updateWriteStats(m); msgBuffer.add(m); if ((msgBuffer.size() >= Controller.BATCH_MAX_SIZE) || ((m.getType() != OFType.PACKET_OUT) && (m.getType() != OFType.FLOW_MOD))) { this.write(msgBuffer); localMsgBuffer.set(null); } }
OFConnection implements IOFConnection, IOFConnectionBackend { @Override public void write(OFMessage m) { if (!isConnected()) { if (logger.isDebugEnabled()) logger.debug("{}: not connected - dropping message {}", this, m); return; } if (logger.isDebugEnabled()) logger.debug("{}: send {}", this, m); List<OFMessage> msgBuffer = localMsgBuffer.get(); if (msgBuffer == null) { msgBuffer = new ArrayList<OFMessage>(); localMsgBuffer.set(msgBuffer); } counters.updateWriteStats(m); msgBuffer.add(m); if ((msgBuffer.size() >= Controller.BATCH_MAX_SIZE) || ((m.getType() != OFType.PACKET_OUT) && (m.getType() != OFType.FLOW_MOD))) { this.write(msgBuffer); localMsgBuffer.set(null); } } }
OFConnection implements IOFConnection, IOFConnectionBackend { @Override public void write(OFMessage m) { if (!isConnected()) { if (logger.isDebugEnabled()) logger.debug("{}: not connected - dropping message {}", this, m); return; } if (logger.isDebugEnabled()) logger.debug("{}: send {}", this, m); List<OFMessage> msgBuffer = localMsgBuffer.get(); if (msgBuffer == null) { msgBuffer = new ArrayList<OFMessage>(); localMsgBuffer.set(msgBuffer); } counters.updateWriteStats(m); msgBuffer.add(m); if ((msgBuffer.size() >= Controller.BATCH_MAX_SIZE) || ((m.getType() != OFType.PACKET_OUT) && (m.getType() != OFType.FLOW_MOD))) { this.write(msgBuffer); localMsgBuffer.set(null); } } OFConnection(@Nonnull DatapathId dpid,
                        @Nonnull OFFactory factory,
                        @Nonnull Channel channel,
                        @Nonnull OFAuxId auxId,
                        @Nonnull IDebugCounterService debugCounters,
                        @Nonnull Timer timer); }
OFConnection implements IOFConnection, IOFConnectionBackend { @Override public void write(OFMessage m) { if (!isConnected()) { if (logger.isDebugEnabled()) logger.debug("{}: not connected - dropping message {}", this, m); return; } if (logger.isDebugEnabled()) logger.debug("{}: send {}", this, m); List<OFMessage> msgBuffer = localMsgBuffer.get(); if (msgBuffer == null) { msgBuffer = new ArrayList<OFMessage>(); localMsgBuffer.set(msgBuffer); } counters.updateWriteStats(m); msgBuffer.add(m); if ((msgBuffer.size() >= Controller.BATCH_MAX_SIZE) || ((m.getType() != OFType.PACKET_OUT) && (m.getType() != OFType.FLOW_MOD))) { this.write(msgBuffer); localMsgBuffer.set(null); } } OFConnection(@Nonnull DatapathId dpid,
                        @Nonnull OFFactory factory,
                        @Nonnull Channel channel,
                        @Nonnull OFAuxId auxId,
                        @Nonnull IDebugCounterService debugCounters,
                        @Nonnull Timer timer); @Override void write(OFMessage m); @Override ListenableFuture<R> writeRequest(OFRequest<R> request); @Override @LogMessageDoc(level = "WARN", message = "Sending OF message that modifies switch " + "state while in the slave role: {switch}", explanation = "An application has sent a message to a switch " + "that is not valid when the switch is in a slave role", recommendation = LogMessageDoc.REPORT_CONTROLLER_BUG) void write(Iterable<OFMessage> msglist); void disconnected(); @Override void disconnect(); @Override String toString(); @Override Date getConnectedSince(); @Override ListenableFuture<List<REPLY>> writeStatsRequest(
            OFStatsRequest<REPLY> request); boolean handleGenericDeliverable(OFMessage reply); @Override void cancelAllPendingRequests(); @Override boolean isConnected(); @Override void flush(); @Override SocketAddress getRemoteInetAddress(); @Override SocketAddress getLocalInetAddress(); boolean deliverResponse(OFMessage m); @Override boolean isWritable(); @Override DatapathId getDatapathId(); @Override OFAuxId getAuxId(); @Override OFFactory getOFFactory(); IOFConnectionListener getListener(); @Override void setListener(IOFConnectionListener listener); void messageReceived(OFMessage m); }
OFConnection implements IOFConnection, IOFConnectionBackend { @Override public void write(OFMessage m) { if (!isConnected()) { if (logger.isDebugEnabled()) logger.debug("{}: not connected - dropping message {}", this, m); return; } if (logger.isDebugEnabled()) logger.debug("{}: send {}", this, m); List<OFMessage> msgBuffer = localMsgBuffer.get(); if (msgBuffer == null) { msgBuffer = new ArrayList<OFMessage>(); localMsgBuffer.set(msgBuffer); } counters.updateWriteStats(m); msgBuffer.add(m); if ((msgBuffer.size() >= Controller.BATCH_MAX_SIZE) || ((m.getType() != OFType.PACKET_OUT) && (m.getType() != OFType.FLOW_MOD))) { this.write(msgBuffer); localMsgBuffer.set(null); } } OFConnection(@Nonnull DatapathId dpid,
                        @Nonnull OFFactory factory,
                        @Nonnull Channel channel,
                        @Nonnull OFAuxId auxId,
                        @Nonnull IDebugCounterService debugCounters,
                        @Nonnull Timer timer); @Override void write(OFMessage m); @Override ListenableFuture<R> writeRequest(OFRequest<R> request); @Override @LogMessageDoc(level = "WARN", message = "Sending OF message that modifies switch " + "state while in the slave role: {switch}", explanation = "An application has sent a message to a switch " + "that is not valid when the switch is in a slave role", recommendation = LogMessageDoc.REPORT_CONTROLLER_BUG) void write(Iterable<OFMessage> msglist); void disconnected(); @Override void disconnect(); @Override String toString(); @Override Date getConnectedSince(); @Override ListenableFuture<List<REPLY>> writeStatsRequest(
            OFStatsRequest<REPLY> request); boolean handleGenericDeliverable(OFMessage reply); @Override void cancelAllPendingRequests(); @Override boolean isConnected(); @Override void flush(); @Override SocketAddress getRemoteInetAddress(); @Override SocketAddress getLocalInetAddress(); boolean deliverResponse(OFMessage m); @Override boolean isWritable(); @Override DatapathId getDatapathId(); @Override OFAuxId getAuxId(); @Override OFFactory getOFFactory(); IOFConnectionListener getListener(); @Override void setListener(IOFConnectionListener listener); void messageReceived(OFMessage m);  }