/** * Process an OF message received on the channel and * update state accordingly. * * The main "event" of the state machine. Process the received message, * send follow up message if required and update state if required. * * Switches on the message type and calls more specific event handlers * for each individual OF message type. If we receive a message that * is supposed to be sent from a controller to a switch we throw * a SwitchStateExeption. * * The more specific handlers can also throw SwitchStateExceptions * * @param h The OFChannelHandler that received the message * @param m The message we received. * @throws SwitchStateException * @throws IOException */ void processOFMessage(OFMessage m) { roleChanger.checkTimeout(); switch(m.getType()) { case BARRIER_REPLY: processOFBarrierReply((OFBarrierReply) m); break; case ERROR: processOFError((OFErrorMsg) m); break; case FLOW_REMOVED: processOFFlowRemoved((OFFlowRemoved) m); break; case GET_CONFIG_REPLY: processOFGetConfigReply((OFGetConfigReply) m); break; case PACKET_IN: processOFPacketIn((OFPacketIn) m); break; case PORT_STATUS: processOFPortStatus((OFPortStatus) m); break; case QUEUE_GET_CONFIG_REPLY: processOFQueueGetConfigReply((OFQueueGetConfigReply) m); break; case STATS_REPLY: processOFStatsReply((OFStatsReply) m); break; case ROLE_REPLY: processOFRoleReply((OFRoleReply) m); break; case EXPERIMENTER: processOFExperimenter((OFExperimenter) m); break; default: illegalMessageReceived(m); break; } }
/** * Create a map of queues to switches, with each queue grouped by port number. * @param queueBandwidthMap * @param switchMap * @param switchPortMap * @return HashMap<IOFSwitch, HashMap<Integer, ArrayList<FlowQueue>>>, ArrayList<FlowQueue> per port number per switch */ public HashMap<IOFSwitch, HashMap<Integer, ArrayList<FlowQueue>>> createQueueMap(HashMap<Long, Long> queueBandwidthMap, Map<DatapathId, IOFSwitch> switchMap, HashMap<IOFSwitch, ArrayList<OFPortDesc>> switchPortMap){ HashMap<IOFSwitch, HashMap<Integer, ArrayList<FlowQueue>>> queueMap = new HashMap<IOFSwitch, HashMap<Integer, ArrayList<FlowQueue>>>(); for(IOFSwitch thisSwitch : switchMap.values()){ HashMap<Integer, ArrayList<FlowQueue>> portQueueMap = new HashMap<Integer, ArrayList<FlowQueue>>(); for(OFPortDesc portDesc : switchPortMap.get(thisSwitch)){ ArrayList<FlowQueue> queuesThisPort = new ArrayList<FlowQueue>(); OFQueueGetConfigRequest cr = arscheduler.of13Factory.buildQueueGetConfigRequest().setPort(portDesc.getPortNo()).build(); // Get all queues on all ports ListenableFuture<OFQueueGetConfigReply> future = thisSwitch.writeRequest(cr); // Send request to switch 1 try { // Wait up to 10s for a reply; return when received; else exception thrown OFQueueGetConfigReply reply = future.get(10, TimeUnit.SECONDS); // Iterate over all queues for (OFPacketQueue q : reply.getQueues()) { ///queues.add(q); if(q.getQueueId() == 0) continue; FlowQueue newQueue = new FlowQueue(portDesc.getPortNo().getPortNumber(), q.getQueueId(), queueBandwidthMap.get(Long.valueOf(q.getQueueId()))); queuesThisPort.add(newQueue); } int portNum = portDesc.getPortNo().getPortNumber(); portQueueMap.put(Integer.valueOf(portNum), queuesThisPort); } catch (InterruptedException | ExecutionException | TimeoutException e) { e.printStackTrace(); } } queueMap.put(thisSwitch, portQueueMap); } return queueMap; }
/** * Process an OF message received on the channel and * update state accordingly. * 处理从管道接收的OF报文并更新状态 * The main "event" of the state machine. Process the received message, * send follow up message if required and update state if required. * 处理接收报文,如果需要发送跟踪报文和更新状态 * Switches on the message type and calls more specific event handlers * for each individual OF message type. If we receive a message that * is supposed to be sent from a controller to a switch we throw * a SwitchStateExeption. * * The more specific handlers can also throw SwitchStateExceptions * * @param h The OFChannelHandler that received the message * @param m The message we received. * @throws SwitchStateException * @throws IOException */ void processOFMessage(OFMessage m) { roleChanger.checkTimeout(); switch(m.getType()) { case BARRIER_REPLY: processOFBarrierReply((OFBarrierReply) m); break; case ERROR: processOFError((OFErrorMsg) m); break; case FLOW_REMOVED: processOFFlowRemoved((OFFlowRemoved) m); break; case GET_CONFIG_REPLY: processOFGetConfigReply((OFGetConfigReply) m); break; case PACKET_IN: processOFPacketIn((OFPacketIn) m); break; case PORT_STATUS: processOFPortStatus((OFPortStatus) m); break; case QUEUE_GET_CONFIG_REPLY: processOFQueueGetConfigReply((OFQueueGetConfigReply) m); break; case STATS_REPLY: processOFStatsReply((OFStatsReply) m); break; case ROLE_REPLY: processOFRoleReply((OFRoleReply) m); break; case EXPERIMENTER: processOFExperimenter((OFExperimenter) m); break; default: illegalMessageReceived(m); break; } }
void processOFQueueGetConfigReply(OFChannelHandler h, OFQueueGetConfigReply m) throws IOException { unhandledMessageReceived(h, m); }
void processOFQueueGetConfigReply(OFQueueGetConfigReply m) { unhandledMessageReceived(m); }
/** * Test dispatch of messages while in Complete state */ @Test public void testMessageDispatchComplete() throws Exception { moveToComplete(); newConnection.getValue().setListener(connectionListener); resetChannel(); expect(channel.writeAndFlush(capture(writeCapture))).andReturn(null).once(); replay(channel); // Send echo request. expect reply OFMessage echoRequest = factory.buildEchoRequest().build(); sendMessageToHandlerWithControllerReset(ImmutableList.<OFMessage>of(echoRequest)); List<OFMessage> msgs = getMessagesFromCapture(); assertEquals(1, msgs.size()); assertEquals(OFType.ECHO_REPLY, msgs.get(0).getType()); // Send barrier reply. expect dispatch OFBarrierReply barrierReply = factory.buildBarrierReply() .build(); resetAndExpectConnectionListener(barrierReply); // Send packet in. expect dispatch OFFlowRemoved flowRemoved = factory.buildFlowRemoved() .build(); resetAndExpectConnectionListener(flowRemoved); // Send get config reply. expect dispatch OFGetConfigReply getConfigReply = factory.buildGetConfigReply() .build(); resetAndExpectConnectionListener(getConfigReply); // Send packet in. expect dispatch OFPacketIn pi = factory.buildPacketIn() .setReason(OFPacketInReason.NO_MATCH) .build(); resetAndExpectConnectionListener(pi); // Send port status. expect dispatch OFPortStatus portStatus = factory.buildPortStatus() .setReason(OFPortReason.DELETE) .setDesc(portDesc) .build(); resetAndExpectConnectionListener(portStatus); // Send queue reply. expect dispatch OFQueueGetConfigReply queueReply = factory.buildQueueGetConfigReply() .build(); resetAndExpectConnectionListener(queueReply); // Send stat reply. expect dispatch OFFlowStatsReply statReply = factory.buildFlowStatsReply() .build(); resetAndExpectConnectionListener(statReply); // Send role reply. expect dispatch OFRoleReply roleReply = factory.buildRoleReply() .setRole(OFControllerRole.ROLE_MASTER) .build(); resetAndExpectConnectionListener(roleReply); // Send experimenter. expect dispatch OFBsnSetAuxCxnsReply auxReply = factory.buildBsnSetAuxCxnsReply() .build(); resetAndExpectConnectionListener(auxReply); }
/** * Test dispatch of messages while in Complete state */ @Test public void testMessageDispatchComplete() throws Exception { moveToComplete(); newConnection.getValue().setListener(connectionListener); resetChannel(); expect(channel.writeAndFlush(capture(writeCapture))).andReturn(null).atLeastOnce(); replay(channel); // Send echo request. expect reply OFMessage echoRequest = factory.buildEchoRequest().build(); sendMessageToHandlerWithControllerReset(ImmutableList.<OFMessage>of(echoRequest)); List<OFMessage> msgs = getMessagesFromCapture(); assertEquals(1, msgs.size()); assertEquals(OFType.ECHO_REPLY, msgs.get(0).getType()); // Send barrier reply. expect dispatch OFBarrierReply barrierReply = factory.buildBarrierReply() .build(); resetAndExpectConnectionListener(barrierReply); // Send packet in. expect dispatch OFFlowRemoved flowRemoved = factory.buildFlowRemoved() .build(); resetAndExpectConnectionListener(flowRemoved); // Send get config reply. expect dispatch OFGetConfigReply getConfigReply = factory.buildGetConfigReply() .build(); resetAndExpectConnectionListener(getConfigReply); // Send packet in. expect dispatch OFPacketIn pi = factory.buildPacketIn() .setReason(OFPacketInReason.NO_MATCH) .build(); resetAndExpectConnectionListener(pi); // Send port status. expect dispatch OFPortStatus portStatus = factory.buildPortStatus() .setReason(OFPortReason.DELETE) .setDesc(portDesc) .build(); resetAndExpectConnectionListener(portStatus); // Send queue reply. expect dispatch OFQueueGetConfigReply queueReply = factory.buildQueueGetConfigReply() .build(); resetAndExpectConnectionListener(queueReply); // Send stat reply. expect dispatch OFFlowStatsReply statReply = factory.buildFlowStatsReply() .build(); resetAndExpectConnectionListener(statReply); // Send role reply. expect dispatch OFNiciraControllerRoleReply roleReply = factory.buildNiciraControllerRoleReply() .setRole(OFNiciraControllerRole.ROLE_MASTER) .build(); resetAndExpectConnectionListener(roleReply); }
/** * Test dispatch of messages while in Complete state */ @Test public void testMessageDispatchComplete() throws Exception { moveToComplete(); newConnection.getValue().setListener(connectionListener); resetChannel(); channel.write(capture(writeCapture)); expectLastCall().andReturn(null).atLeastOnce(); replay(channel); // Send echo request. expect reply OFMessage echoRequest = factory.buildEchoRequest().build(); sendMessageToHandlerWithControllerReset(ImmutableList.<OFMessage>of(echoRequest)); List<OFMessage> msgs = getMessagesFromCapture(); assertEquals(1, msgs.size()); assertEquals(OFType.ECHO_REPLY, msgs.get(0).getType()); // Send barrier reply. expect dispatch OFBarrierReply barrierReply = factory.buildBarrierReply() .build(); resetAndExpectConnectionListener(barrierReply); // Send packet in. expect dispatch OFFlowRemoved flowRemoved = factory.buildFlowRemoved() .build(); resetAndExpectConnectionListener(flowRemoved); // Send get config reply. expect dispatch OFGetConfigReply getConfigReply = factory.buildGetConfigReply() .build(); resetAndExpectConnectionListener(getConfigReply); // Send packet in. expect dispatch OFPacketIn pi = factory.buildPacketIn() .setReason(OFPacketInReason.NO_MATCH) .build(); resetAndExpectConnectionListener(pi); // Send port status. expect dispatch OFPortStatus portStatus = factory.buildPortStatus() .setReason(OFPortReason.DELETE) .setDesc(portDesc) .build(); resetAndExpectConnectionListener(portStatus); // Send queue reply. expect dispatch OFQueueGetConfigReply queueReply = factory.buildQueueGetConfigReply() .build(); resetAndExpectConnectionListener(queueReply); // Send stat reply. expect dispatch OFFlowStatsReply statReply = factory.buildFlowStatsReply() .build(); resetAndExpectConnectionListener(statReply); // Send role reply. expect dispatch OFNiciraControllerRoleReply roleReply = factory.buildNiciraControllerRoleReply() .setRole(OFNiciraControllerRole.ROLE_MASTER) .build(); resetAndExpectConnectionListener(roleReply); }
/** * Process an OF message received on the channel and * update state accordingly. * * The main "event" of the state machine. Process the received message, * send follow up message if required and update state if required. * * Switches on the message type and calls more specific event handlers * for each individual OF message type. If we receive a message that * is supposed to be sent from a controller to a switch we throw * a SwitchStateExeption. * * The more specific handlers can also throw SwitchStateExceptions * * @param h The OFChannelHandler that received the message * @param m The message we received. * @throws SwitchStateException * @throws IOException */ void processOFMessage(OFMessage m) { roleChanger.checkTimeout(); switch(m.getType()) { case BARRIER_REPLY: processOFBarrierReply((OFBarrierReply) m); break; case ERROR: processOFError((OFErrorMsg) m); break; case FLOW_REMOVED: processOFFlowRemoved((OFFlowRemoved) m); break; case GET_CONFIG_REPLY: processOFGetConfigReply((OFGetConfigReply) m); break; case PACKET_IN: processOFPacketIn((OFPacketIn) m); break; case PORT_STATUS: processOFPortStatus((OFPortStatus) m); break; case QUEUE_GET_CONFIG_REPLY: processOFQueueGetConfigReply((OFQueueGetConfigReply) m); break; case STATS_REPLY: processOFStatsReply((OFStatsReply) m); break; case ROLE_REPLY: processOFRoleReply((OFRoleReply) m); break; case EXPERIMENTER: processOFExperimenter((OFExperimenter) m); break; case ROLE_STATUS: processOFRoleStatus((OFRoleStatus) m); break; default: illegalMessageReceived(m); break; } }