@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.warn("Stats reply indicates more stats from sw {} for " + "port description - not currently handled", h.getSwitchInfoString()); } 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 public void switchAdded(Dpid dpid) { OpenFlowSwitch sw = controller.getSwitch(dpid); OFVersion version = sw.factory().getVersion(); Integer ofVersion = version.getWireVersion(); shimController.setSupportedProtocol(ofVersion.byteValue()); OFFeaturesReply featuresReply = shimController.getFeatureReply(sw); controller.setRole(dpid, RoleState.MASTER); shimController.sendOpenFlowMessageToCore(featuresReply,featuresReply.getXid(),sw.getId(),0); //Create OFPortDescStatsReply for OF_13 if (sw.factory().getVersion() == OFVersion.OF_13) { OFPortDescStatsReply.Builder statsReplyBuilder = sw.factory().buildPortDescStatsReply(); statsReplyBuilder.setEntries(sw.getPorts()) .setXid(0); OFPortDescStatsReply ofPortStatsReply = statsReplyBuilder.build(); shimController.sendOpenFlowMessageToCore(ofPortStatsReply,ofPortStatsReply.getXid(),sw.getId(),0); } log.info("Switch {} connected", dpid); }
/** * Checks if given port is also part of the regular port desc stats, i.e., is the port a tap port. * * @param port given port number * @return true if the port is a tap (OCh), false otherwise (OMS port) */ private boolean isOChPort(long port) { for (OFPortDescStatsReply reply : this.ports) { for (OFPortDesc p : reply.getEntries()) { if (p.getPortNo().getPortNumber() == port) { return true; } } } return false; }
/** * 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; }
@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) { if (m.getStatsType().equals(OFStatsType.PORT_DESC)) { h.sw.setPortDescReply((OFPortDescStatsReply) m); } h.dispatchMessage(m); }
@Override public void setPortDescStats(OFPortDescStatsReply reply) { /* ports are updated via port status message, so we * only fill in ports on initial connection. */ List<OFPortDesc> OFPortDescs = reply.getEntries(); portManager.updatePorts(OFPortDescs); }
void processOFStatsReply(OFStatsReply m) { switch(m.getStatsType()) { case PORT_DESC: processPortDescStatsReply((OFPortDescStatsReply) m); break; default: unhandledMessageReceived(m); } }
OFPortDescStatsReply getPortDescStatsReply() { OFPortDesc portDesc = factory.buildPortDesc() .setName("Eth1") .setPortNo(OFPort.of(1)) .build(); return factory.buildPortDescStatsReply() .setEntries(ImmutableList.<OFPortDesc>of(portDesc)) .build(); }
public void handleDescStatsAndCreateSwitch() throws Exception { // build the stats reply OFDescStatsReply sr = createDescriptionStatsReply(); reset(sw); SwitchDescription switchDescription = new SwitchDescription(sr); setupSwitchForInstantiationWithReset(); sw.setPortDescStats(anyObject(OFPortDescStatsReply.class)); expectLastCall().once(); expect(sw.getOFFactory()).andReturn(factory).once(); replay(sw); reset(switchManager); expect(switchManager.getHandshakePlugins()).andReturn(plugins).anyTimes(); expect( switchManager.getOFSwitchInstance(anyObject(OFConnection.class), eq(switchDescription), anyObject(OFFactory.class), anyObject(DatapathId.class))).andReturn(sw).once(); expect(switchManager.getNumRequiredConnections()).andReturn(1).anyTimes(); switchManager.switchAdded(sw); expectLastCall().once(); replay(switchManager); // send the description stats reply switchHandler.processOFMessage(sr); OFMessage msg = connection.retrieveMessage(); assertThat(msg, CoreMatchers.instanceOf(OFTableFeaturesStatsRequest.class)); verifyUniqueXids(msg); verify(sw, switchManager); }
public void handleDescStatsAndCreateSwitch(boolean switchDriverComplete) throws Exception { // build the stats reply OFDescStatsReply sr = createDescriptionStatsReply(); reset(sw); SwitchDescription switchDescription = new SwitchDescription(sr); setupSwitchForInstantiationWithReset(); sw.startDriverHandshake(); expectLastCall().once(); expect(sw.getOFFactory()).andReturn(factory).once(); sw.isDriverHandshakeComplete(); expectLastCall().andReturn(switchDriverComplete).once(); if(factory.getVersion().compareTo(OFVersion.OF_13) >= 0) { sw.setPortDescStats(anyObject(OFPortDescStatsReply.class)); expectLastCall().once(); } replay(sw); reset(switchManager); expect(switchManager.getHandshakePlugins()).andReturn(plugins).anyTimes(); expect( switchManager.getOFSwitchInstance(anyObject(OFConnection.class), eq(switchDescription), anyObject(OFFactory.class), anyObject(DatapathId.class))).andReturn(sw).once(); switchManager.switchAdded(sw); expectLastCall().once(); replay(switchManager); // send the description stats reply switchHandler.processOFMessage(sr); }
public void handleDescStatsAndCreateSwitch(boolean subHandShakeComplete) throws Exception { // build the stats reply OFDescStatsReply sr = createDescriptionStatsReply(); reset(sw); SwitchDescription switchDescription = new SwitchDescription(sr); setupSwitchForInstantiationWithReset(); sw.setPortDescStats(anyObject(OFPortDescStatsReply.class)); expectLastCall().once(); sw.startDriverHandshake(); expectLastCall().once(); expect(sw.isDriverHandshakeComplete()).andReturn(subHandShakeComplete).once(); replay(sw); reset(switchManager); expect(switchManager.getHandshakePlugins()).andReturn(plugins).anyTimes(); expect( switchManager.getOFSwitchInstance(anyObject(OFConnection.class), eq(switchDescription), anyObject(OFFactory.class), anyObject(DatapathId.class))).andReturn(sw).once(); expect(switchManager.getNumRequiredConnections()).andReturn(1).anyTimes(); switchManager.switchAdded(sw); expectLastCall().once(); replay(switchManager); // send the description stats reply switchHandler.processOFMessage(sr); verify(sw, switchManager); }
public void handleDescStatsAndCreateSwitch(boolean switchDriverComplete) throws Exception { // build the stats reply OFDescStatsReply sr = createDescriptionStatsReply(); reset(sw); SwitchDescription switchDescription = new SwitchDescription(sr); setupSwitchForInstantiationWithReset(); sw.startDriverHandshake(); expectLastCall().once(); sw.isDriverHandshakeComplete(); expectLastCall().andReturn(switchDriverComplete).once(); if(factory.getVersion().compareTo(OFVersion.OF_13) >= 0) { sw.setPortDescStats(anyObject(OFPortDescStatsReply.class)); expectLastCall().once(); } replay(sw); reset(switchManager); expect(switchManager.getHandshakePlugins()).andReturn(plugins).anyTimes(); expect( switchManager.getOFSwitchInstance(anyObject(OFConnection.class), eq(switchDescription), anyObject(OFFactory.class), anyObject(DatapathId.class))).andReturn(sw).once(); switchManager.switchAdded(sw); expectLastCall().once(); replay(switchManager); // send the description stats reply switchHandler.processOFMessage(sr); }