/** * Handle the message coming from the dataplane. * * @param m the actual message */ @Override public final void handleMessage(OFMessage m) { if (this.role == RoleState.MASTER || m instanceof OFPortStatus) { this.agent.processMessage(dpid, m); } else { log.trace("Dropping received message {}, was not MASTER", m); } }
/** * Create a new unconnected OFChannelHandler. * @param controller parent controller */ OFChannelHandler(Controller controller) { this.controller = controller; this.state = ChannelState.INIT; this.pendingPortStatusMsg = new CopyOnWriteArrayList<OFPortStatus>(); this.portDescReplies = new ArrayList<OFPortDescStatsReply>(); factory13 = controller.getOFMessageFactory13(); factory10 = controller.getOFMessageFactory10(); duplicateDpidFound = Boolean.FALSE; }
private void handlePendingPortStatusMessages(OFChannelHandler h, int index) throws SwitchStateException { if (h.sw == null) { String msg = "State machine error: switch is null. Should never " + "happen"; throw new SwitchStateException(msg); } log.info("Processing {} pending port status messages for {}", h.pendingPortStatusMsg.size(), h.sw.getStringId()); ArrayList<OFPortStatus> temp = new ArrayList<OFPortStatus>(); for (OFPortStatus ps: h.pendingPortStatusMsg) { temp.add(ps); handlePortStatusMessage(h, ps, false); } // expensive but ok - we don't expect too many port-status messages // note that we cannot use clear(), because of the reasons below h.pendingPortStatusMsg.removeAll(temp); temp.clear(); // the iterator above takes a snapshot of the list - so while we were // dealing with the pending port-status messages, we could have received // newer ones. Handle them recursively, but break the recursion after // five steps to avoid an attack. if (!h.pendingPortStatusMsg.isEmpty() && ++index < 5) { handlePendingPortStatusMessages(h, index); } }
private PortDescription buildPortDescription(OFPortStatus status) { OFPortDesc port = status.getDesc(); if (status.getReason() != OFPortReason.DELETE) { return buildPortDescription(port); } else { PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); Port.Type type = port.getCurr().contains(OFPortFeatures.PF_FIBER) ? FIBER : COPPER; SparseAnnotations annotations = makePortAnnotation(port.getName(), port.getHwAddr().toString()); return new DefaultPortDescription(portNo, false, type, portSpeed(port), annotations); } }
@Test public void portChanged() { OFPortStatus stat = SW1.factory().buildPortStatus() .setReason(OFPortReason.ADD) .setDesc(PD3) .build(); controller.listener.portChanged(DPID1, stat); assertNotNull("never went throught the provider service", registry.descr); assertEquals("port status unhandled", 3, registry.ports.get(DID1).size()); }
/** * 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; } }
void handlePendingPortStatusMessages(SwitchDescription description){ for (OFPortStatus ps: pendingPortStatusMsg) { handlePortStatusMessage(ps, false); } pendingPortStatusMsg.clear(); log.info("Switch {} bound to class {}, description {}", new Object[] { sw, sw.getClass(), description }); }
@Override void processOFMessage(OFMessage m) { if(m.getType() == OFType.PORT_STATUS){ OFPortStatus status = (OFPortStatus) m; handlePortStatusMessage(status, false); } else if(plugin != null){ this.plugin.processOFMessage(m); } else{ super.processOFMessage(m); } }
/** * Create a new unconnected OFChannelHandler. * @param controller * @param broker * @throws SwitchHandshakeHandlerException */ OFSwitchHandshakeHandler(@Nonnull IOFConnectionBackend connection, @Nonnull OFFeaturesReply featuresReply, @Nonnull IOFSwitchManager switchManager, @Nonnull RoleManager roleManager, @Nonnull Timer timer) { Preconditions.checkNotNull(connection, "connection"); Preconditions.checkNotNull(featuresReply, "featuresReply"); Preconditions.checkNotNull(switchManager, "switchManager"); Preconditions.checkNotNull(roleManager, "roleManager"); Preconditions.checkNotNull(timer, "timer"); Preconditions.checkArgument(connection.getAuxId().equals(OFAuxId.MAIN), "connection must be MAIN connection but is %s", connection); this.switchManager = switchManager; this.roleManager = roleManager; this.mainConnection = connection; this.auxConnections = new ConcurrentHashMap<OFAuxId, IOFConnectionBackend>(); this.featuresReply = featuresReply; this.timer = timer; this.switchManagerCounters = switchManager.getCounters(); this.factory = OFFactories.getFactory(featuresReply.getVersion()); this.roleChanger = new RoleChanger(DEFAULT_ROLE_TIMEOUT_NS); setState(new InitState()); this.pendingPortStatusMsg = new ArrayList<OFPortStatus>(); connection.setListener(this); }
@Override void processOFPortStatus(OFChannelHandler h, OFPortStatus m) throws IOException { unhandledMessageReceived(h, m); }
@Override void processOFPortStatus(OFChannelHandler h, OFPortStatus m) throws IOException { h.pendingPortStatusMsg.add(m); }
@Override void processOFPortStatus(OFChannelHandler h, OFPortStatus m) throws IOException, SwitchStateException { h.pendingPortStatusMsg.add(m); }
@Override void processOFPortStatus(OFChannelHandler h, OFPortStatus m) throws SwitchStateException { handlePortStatusMessage(h, m, true); //h.dispatchMessage(m); }