/** * 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) { try { // TODO revisit states other than ports should // also ignore role state. if (m.getType() == OFType.PORT_STATUS) { OFPortStatus portStatus = (OFPortStatus) m; if (portStatus.getReason() == OFPortReason.DELETE) { portDescs.remove(portStatus.getDesc().getPortNo()); } else { portDescs.put(portStatus.getDesc().getPortNo(), portStatus.getDesc()); } } this.agent.processMessage(dpid, m); } catch (Exception e) { log.warn("Unhandled exception processing {}@{}", m, dpid, e); } } else { log.trace("Dropping received message {}, was not MASTER", m); } }
private void sendPortStatus(Port port, OFPortReason ofPortReason) { Set<Channel> channels = controllerChannels(); if (channels.isEmpty()) { log.trace("No channels present. Port status will not be sent."); return; } OFPortDesc ofPortDesc = portDesc(port); OFPortStatus ofPortStatus = FACTORY.buildPortStatus() .setDesc(ofPortDesc) .setReason(ofPortReason) .build(); log.trace("Sending port status {}", ofPortStatus); channels.forEach(channel -> { channel.writeAndFlush(Collections.singletonList(ofPortStatus)); }); }
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()); }
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 = makePortNameAnnotation(port); return new DefaultPortDescription(portNo, false, type, portSpeed(port), annotations); } }
private OFPortStatus portStatus(boolean up, int port) { OFPortDesc desc = portDesc(port, up); OFPortStatus status = OFFactoryVer10.INSTANCE.buildPortStatus() .setDesc(desc) .setReason(up ? OFPortReason.ADD : OFPortReason.DELETE).build(); return status; }
public static OFPortReason readFrom(ChannelBuffer bb) throws OFParseError { try { return ofWireValue(bb.readByte()); } catch (IllegalArgumentException e) { throw new OFParseError(e); } }
public static OFPortReason ofWireValue(byte val) { switch(val) { case ADD_VAL: return OFPortReason.ADD; case DELETE_VAL: return OFPortReason.DELETE; case MODIFY_VAL: return OFPortReason.MODIFY; default: throw new IllegalArgumentException("Illegal wire value for type OFPortReason in version 1.2: " + val); } }
public static byte toWireValue(OFPortReason e) { switch(e) { case ADD: return ADD_VAL; case DELETE: return DELETE_VAL; case MODIFY: return MODIFY_VAL; default: throw new IllegalArgumentException("Illegal enum value for type OFPortReason in version 1.2: " + e); } }
public static OFPortReason ofWireValue(byte val) { switch(val) { case ADD_VAL: return OFPortReason.ADD; case DELETE_VAL: return OFPortReason.DELETE; case MODIFY_VAL: return OFPortReason.MODIFY; default: throw new IllegalArgumentException("Illegal wire value for type OFPortReason in version 1.3: " + val); } }
public static byte toWireValue(OFPortReason e) { switch(e) { case ADD: return ADD_VAL; case DELETE: return DELETE_VAL; case MODIFY: return MODIFY_VAL; default: throw new IllegalArgumentException("Illegal enum value for type OFPortReason in version 1.3: " + e); } }
public static OFPortReason ofWireValue(byte val) { switch(val) { case ADD_VAL: return OFPortReason.ADD; case DELETE_VAL: return OFPortReason.DELETE; case MODIFY_VAL: return OFPortReason.MODIFY; default: throw new IllegalArgumentException("Illegal wire value for type OFPortReason in version 1.0: " + val); } }
public static byte toWireValue(OFPortReason e) { switch(e) { case ADD: return ADD_VAL; case DELETE: return DELETE_VAL; case MODIFY: return MODIFY_VAL; default: throw new IllegalArgumentException("Illegal enum value for type OFPortReason in version 1.0: " + e); } }
public static OFPortReason ofWireValue(byte val) { switch(val) { case ADD_VAL: return OFPortReason.ADD; case DELETE_VAL: return OFPortReason.DELETE; case MODIFY_VAL: return OFPortReason.MODIFY; default: throw new IllegalArgumentException("Illegal wire value for type OFPortReason in version 1.1: " + val); } }
public static byte toWireValue(OFPortReason e) { switch(e) { case ADD: return ADD_VAL; case DELETE: return DELETE_VAL; case MODIFY: return MODIFY_VAL; default: throw new IllegalArgumentException("Illegal enum value for type OFPortReason in version 1.1: " + e); } }
public static OFPortReason ofWireValue(byte val) { switch(val) { case ADD_VAL: return OFPortReason.ADD; case DELETE_VAL: return OFPortReason.DELETE; case MODIFY_VAL: return OFPortReason.MODIFY; default: throw new IllegalArgumentException("Illegal wire value for type OFPortReason in version 1.4: " + val); } }
public static byte toWireValue(OFPortReason e) { switch(e) { case ADD: return ADD_VAL; case DELETE: return DELETE_VAL; case MODIFY: return MODIFY_VAL; default: throw new IllegalArgumentException("Illegal enum value for type OFPortReason in version 1.4: " + e); } }
@Test public void testHandlePortStatusForNewPort() throws IOException { LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager(); long dpid = 3L; IOFSwitch sw = createMockSwitch(dpid); getMockFloodlightProvider().getSwitches().put(dpid, sw); short portNum = 1; OFPortDesc ofPortDesc = createMockPort(portNum); OFPortStatus portStatus = factory10.buildPortStatus() .setDesc(ofPortDesc) .setReason(OFPortReason.ADD) .build(); expect(sw.getPort(portNum)).andReturn(ofPortDesc).once(); sw.write(matchOutPort(portNum), anyObject(FloodlightContext.class)); sw.flush(); replay(sw); linkDiscovery.handlePortStatus(sw, portStatus); verify(sw); }
@Test public void testHandlePortStatusForDeletePort() { LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager(); // Add a link that we can delete later during the test Link lt = new Link(1L, 1, 2L, 2); LinkInfo info = new LinkInfo(System.currentTimeMillis(), System.currentTimeMillis(), EMPTY_PORT_STATE, EMPTY_PORT_STATE); linkDiscovery.addOrUpdateLink(lt, info); short portNum = 1; OFPortDesc srcPortDesc = createMockPort(portNum); OFPortStatus srcPortStatus = factory10.buildPortStatus() .setDesc(srcPortDesc) .setReason(OFPortReason.DELETE) .build(); assertNotNull(linkDiscovery.getLinks().get(lt)); // Send a delete port status for the source port, which should result // in the link being deleted linkDiscovery.handlePortStatus( getMockFloodlightProvider().getSwitches().get(1L), srcPortStatus); assertNull(linkDiscovery.getLinks().get(lt)); }
@Override public void portChanged(Dpid dpid, OFPortStatus status) { LOG.debug("portChanged({},{})", dpid, status); PortDescription portDescription = buildPortDescription(status); if (status.getReason() != OFPortReason.DELETE) { providerService.portStatusChanged(deviceId(uri(dpid)), portDescription); } else { providerService.deletePort(deviceId(uri(dpid)), portDescription); } }
private PortDescription buildPortDescription(OFPortStatus status) { OFPortDesc port = status.getDesc(); if (status.getReason() != OFPortReason.DELETE) { return buildPortDescription(port); } else { PortDescription desc = buildPortDescription(port); if (desc.isEnabled()) { return DefaultPortDescription.builder(desc) .isEnabled(false) .build(); } return desc; } }
public static OFPortReason readFrom(ByteBuf bb) throws OFParseError { try { return ofWireValue(bb.readByte()); } catch (IllegalArgumentException e) { throw new OFParseError(e); } }
public static OFPortReason ofWireValue(byte val) { switch(val) { case ADD_VAL: return OFPortReason.ADD; case DELETE_VAL: return OFPortReason.DELETE; case MODIFY_VAL: return OFPortReason.MODIFY; default: throw new IllegalArgumentException("Illegal wire value for type OFPortReason in version 1.5: " + val); } }
public static byte toWireValue(OFPortReason e) { switch(e) { case ADD: return ADD_VAL; case DELETE: return DELETE_VAL; case MODIFY: return MODIFY_VAL; default: throw new IllegalArgumentException("Illegal enum value for type OFPortReason in version 1.5: " + e); } }