@Override public void processDriverHandshakeMessage(OFMessage m) { if (!startDriverHandshakeCalled) { throw new SwitchDriverSubHandshakeNotStarted(); } if (driverHandshakeComplete.get()) { throw new SwitchDriverSubHandshakeCompleted(m); } log.debug("processDriverHandshakeMessage for sw {}", getStringId()); switch (m.getType()) { case STATS_REPLY: // multipart message is reported as STAT processOFMultipartReply((OFStatsReply) m); break; default: log.warn("Received message {} during switch-driver " + "subhandshake " + "from switch {} ... " + "Ignoring message", m, getStringId()); } }
private void processOFMultipartReply(OFStatsReply stats) { log.debug("Received message {} during switch-driver " + "subhandshake " + "from switch {} ... " + stats, getStringId()); if (stats.getStatsType() == OFStatsType.EXPERIMENTER) { try { OFExpPortDescReply expPortDescReply = (OFExpPortDescReply) stats; expPortDes.addAll(expPortDescReply.getEntries()); if (!expPortDescReply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { driverHandshakeComplete.set(true); return; } } catch (ClassCastException e) { log.error("Unexspected Experimenter Multipart message type {} ", stats.getClass().getName()); } } }
@Override public void handleMessage(Dpid dpid, OFMessage msg) { switch (msg.getType()) { case STATS_REPLY: pushMeterStats(dpid, (OFStatsReply) msg); break; case ERROR: OFErrorMsg error = (OFErrorMsg) msg; if (error.getErrType() == OFErrorType.METER_MOD_FAILED) { MeterOperation op = pendingOperations.getIfPresent(error.getXid()); pendingOperations.invalidate(error.getXid()); if (op == null) { log.warn("Unknown Meter operation failed {}", error); } else { OFMeterModFailedErrorMsg meterError = (OFMeterModFailedErrorMsg) error; signalMeterError(meterError, op); } } break; default: break; } }
@Override /** * Accumulate a list of the OFTableFeaturesStatsReply's until there * are no more remaining. Then, pass the list to the switch for * parsing and configuration. * * The assumption is that the OFMessage dispatcher will call this each * time, which it does. We don't loop and receive here. * * @param m, The potential OFTableFeaturesStatsReply message we want to include */ void processOFStatsReply(OFStatsReply m) { if (m.getStatsType() == OFStatsType.TABLE_FEATURES) { replies.add((OFTableFeaturesStatsReply) m); if (!((OFTableFeaturesStatsReply)m).getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { handleTableFeaturesMessage(replies, false); nextState(); } } else { /* should only receive TABLE_FEATURES here */ log.error("Received {} message but expected TABLE_FEATURES.", m.getStatsType().toString()); } }
@SuppressWarnings("unchecked") @Override public <REPLY extends OFStatsReply> ListenableFuture<List<REPLY>> writeStatsRequest(OFStatsRequest<REPLY> request) { ListenableFuture<List<REPLY>> ofStatsFuture = EasyMock.createNiceMock(ListenableFuture.class); // We create a mock future and return info from the map try { OFStatsType statsType = request.getStatsType(); List<REPLY> replies = (List<REPLY>) statsMap.get(statsType); EasyMock.expect(ofStatsFuture.get(EasyMock.anyLong(), EasyMock.anyObject(TimeUnit.class))).andReturn(replies).anyTimes(); EasyMock.expect(ofStatsFuture.get()).andReturn(replies).anyTimes(); EasyMock.replay(ofStatsFuture); } catch (Exception e) { throw new RuntimeException(e); } return ofStatsFuture; }
@Override void processOFStatisticsReply(OFChannelHandler h, OFStatsReply m) throws SwitchStateException { // Read port description if (m.getStatsType() != OFStatsType.PORT_DESC) { log.warn("Expecting port description stats but received stats " + "type {} from {}. Ignoring ...", m.getStatsType(), h.channel.getRemoteAddress()); return; } if (m.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { log.debug("Stats reply indicates more stats from sw {} for " + "port description", h.getSwitchInfoString()); h.portDescReplies.add((OFPortDescStatsReply)m); return; } else { h.portDescReplies.add((OFPortDescStatsReply)m); } //h.portDescReply = (OFPortDescStatsReply) m; // temp store log.info("Received port desc reply for switch at {}", h.getSwitchInfoString()); try { h.sendHandshakeSetConfig(); } catch (IOException e) { log.error("Unable to send setConfig after PortDescReply. " + "Error: {}", e.getMessage()); } h.setState(WAIT_CONFIG_REPLY); }
@Override void processOFStatisticsReply(OFChannelHandler h, OFStatsReply m) throws IOException, SwitchStateException { log.error("Received multipart(stats) message sub-type {}", m.getStatsType()); illegalMessageReceived(h, m); }
@Override void processOFStatisticsReply(OFChannelHandler h, OFStatsReply m) { if (m.getStatsType().equals(OFStatsType.PORT_DESC)) { h.sw.setPortDescReply((OFPortDescStatsReply) m); } h.dispatchMessage(m); }
@Override public void handleMessage(Dpid dpid, OFMessage msg) { if (isDisabled) { return; } try { switch (msg.getType()) { case STATS_REPLY: if (((OFStatsReply) msg).getStatsType() == OFStatsType.PORT) { OFPortStatsReply portStatsReply = (OFPortStatsReply) msg; List<OFPortStatsEntry> portStatsReplyList = portStatsReplies.get(dpid); if (portStatsReplyList == null) { portStatsReplyList = Lists.newCopyOnWriteArrayList(); } portStatsReplyList.addAll(portStatsReply.getEntries()); portStatsReplies.put(dpid, portStatsReplyList); if (!portStatsReply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { List<OFPortStatsEntry> statsEntries = portStatsReplies.get(dpid); if (statsEntries != null) { pushPortMetrics(dpid, statsEntries); statsEntries.clear(); } } } break; case ERROR: if (((OFErrorMsg) msg).getErrType() == OFErrorType.PORT_MOD_FAILED) { LOG.error("port mod failed"); } default: break; } } catch (IllegalStateException e) { // system is shutting down and the providerService is no longer // valid. Messages cannot be processed. } }
void processOFStatsReply(OFStatsReply m) { switch(m.getStatsType()) { case PORT_DESC: processPortDescStatsReply((OFPortDescStatsReply) m); break; default: unhandledMessageReceived(m); } }
/** * 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; } }
@Override void processOFStatsReply(OFStatsReply m) { // Read description, if it has been updated if (m.getStatsType() != OFStatsType.DESC) { illegalMessageReceived(m); return; } OFDescStatsReply descStatsReply = (OFDescStatsReply) m; SwitchDescription description = new SwitchDescription(descStatsReply); sw = switchManager.getOFSwitchInstance(mainConnection, description, factory, featuresReply.getDatapathId()); // set switch information // set features reply and channel first so we a DPID and // channel info. sw.setFeaturesReply(featuresReply); if (portDescStats != null) { sw.setPortDescStats(portDescStats); } /* * Need to add after setting the features. */ switchManager.switchAdded(sw); // Handle pending messages now that we have a sw object handlePendingPortStatusMessages(description); setState(new WaitTableFeaturesReplyState()); }
@LogMessageDoc(message="Switch {switch info} bound to class " + "{switch driver}, description {switch description}", explanation="The specified switch has been bound to " + "a switch driver based on the switch description" + "received from the switch") @Override void processOFStatsReply(OFStatsReply m) { // Read description, if it has been updated if (m.getStatsType() != OFStatsType.DESC) { illegalMessageReceived(m); return; } OFDescStatsReply descStatsReply = (OFDescStatsReply) m; SwitchDescription description = new SwitchDescription(descStatsReply); sw = switchManager.getOFSwitchInstance(mainConnection, description, factory, featuresReply.getDatapathId()); switchManager.switchAdded(sw); // set switch information // set features reply and channel first so we a DPID and // channel info. sw.setFeaturesReply(featuresReply); if (portDescStats != null) { sw.setPortDescStats(portDescStats); } // Handle pending messages now that we have a sw object handlePendingPortStatusMessages(description); sw.startDriverHandshake(); if (sw.isDriverHandshakeComplete()) { setState(new WaitAppHandshakeState()); } else { setState(new WaitSwitchDriverSubHandshakeState()); } }
@Override public void processDriverHandshakeMessage(OFMessage m) { if (!startDriverHandshakeCalled) { throw new SwitchDriverSubHandshakeNotStarted(); } if (driverHandshakeComplete.get()) { throw new SwitchDriverSubHandshakeCompleted(m); } switch (m.getType()) { case BARRIER_REPLY: log.debug("OPLK ROADM Received barrier response"); break; case ERROR: log.error("Switch {} Error {}", getStringId(), m); break; case FEATURES_REPLY: break; case FLOW_REMOVED: break; case GET_ASYNC_REPLY: break; case PACKET_IN: break; case PORT_STATUS: processOFPortStatus((OFCircuitPortStatus) m); break; case QUEUE_GET_CONFIG_REPLY: break; case ROLE_REPLY: break; case STATS_REPLY: OFStatsReply stats = (OFStatsReply) m; if (stats.getStatsType() == OFStatsType.EXPERIMENTER) { log.warn("OPLK ROADM : Received multipart (port desc) reply message {}", m); //OTN Optical extension 1.0 port-desc createOpticalPortList((OFCircuitPortsReply) m); driverHandshakeComplete.set(true); } break; default: log.warn("Received message {} during switch-driver " + "subhandshake " + "from switch {} ... " + "Ignoring message", m, getStringId()); } }