private void generateSwitchPortStatusUpdate(DatapathId sw, OFPort port) { UpdateOperation operation; IOFSwitch iofSwitch = switchService.getSwitch(sw); if (iofSwitch == null) return; OFPortDesc ofp = iofSwitch.getPort(port); if (ofp == null) return; Set<OFPortState> srcPortState = ofp.getState(); boolean portUp = !srcPortState.contains(OFPortState.STP_BLOCK); if (portUp) { operation = UpdateOperation.PORT_UP; } else { operation = UpdateOperation.PORT_DOWN; } updates.add(new LDUpdate(sw, port, operation)); }
@Override public void portChanged(Dpid dpid, OFPortStatus status) { LinkDiscovery ld = discoverers.get(dpid); if (ld == null) { return; } final OFPortDesc port = status.getDesc(); final boolean enabled = !port.getState().contains(OFPortState.LINK_DOWN) && !port.getConfig().contains(OFPortConfig.PORT_DOWN); if (enabled) { ld.addPort(port); } else { /* * remove port calls linkVanished */ ld.removePort(port); } }
public static int toWireValue(Set<OFPortState> set) { int wireValue = 0; for(OFPortState e: set) { switch(e) { case LINK_DOWN: wireValue |= LINK_DOWN_VAL; break; case BLOCKED: wireValue |= BLOCKED_VAL; break; case LIVE: wireValue |= LIVE_VAL; break; default: throw new IllegalArgumentException("Illegal enum value for type OFPortState in version 1.2: " + e); } } return wireValue; }
public static int toWireValue(Set<OFPortState> set) { int wireValue = 0; for(OFPortState e: set) { switch(e) { case LINK_DOWN: wireValue |= LINK_DOWN_VAL; break; case BLOCKED: wireValue |= BLOCKED_VAL; break; case LIVE: wireValue |= LIVE_VAL; break; default: throw new IllegalArgumentException("Illegal enum value for type OFPortState in version 1.3: " + e); } } return wireValue; }
public static int toWireValue(Set<OFPortState> set) { int wireValue = 0; for(OFPortState e: set) { switch(e) { case LINK_DOWN: wireValue |= LINK_DOWN_VAL; break; case STP_LISTEN: wireValue |= STP_LISTEN_VAL; break; case STP_LEARN: wireValue |= STP_LEARN_VAL; break; case STP_FORWARD: wireValue |= STP_FORWARD_VAL; break; case STP_BLOCK: wireValue |= STP_BLOCK_VAL; break; default: throw new IllegalArgumentException("Illegal enum value for type OFPortState in version 1.0: " + e); } } return wireValue; }
public static int toWireValue(Set<OFPortState> set) { int wireValue = 0; for(OFPortState e: set) { switch(e) { case LINK_DOWN: wireValue |= LINK_DOWN_VAL; break; case BLOCKED: wireValue |= BLOCKED_VAL; break; case LIVE: wireValue |= LIVE_VAL; break; default: throw new IllegalArgumentException("Illegal enum value for type OFPortState in version 1.1: " + e); } } return wireValue; }
public static int toWireValue(Set<OFPortState> set) { int wireValue = 0; for(OFPortState e: set) { switch(e) { case LINK_DOWN: wireValue |= LINK_DOWN_VAL; break; case BLOCKED: wireValue |= BLOCKED_VAL; break; case LIVE: wireValue |= LIVE_VAL; break; default: throw new IllegalArgumentException("Illegal enum value for type OFPortState in version 1.4: " + e); } } return wireValue; }
private OFPortDesc createMockPortWithState(short portNumber, Set<OFPortState> state) { OFPort ofPort = createMock(OFPort.class); expect(ofPort.getShortPortNumber()).andReturn(portNumber).anyTimes(); OFPortDesc ofPortDesc = createMock(OFPortDesc.class); expect(ofPortDesc.getPortNo()).andReturn(ofPort).anyTimes(); expect(ofPortDesc.getHwAddr()).andReturn( MacAddress.of(DEFAULT_MAC_ADDRESS)).anyTimes(); expect(ofPortDesc.getConfig()). andReturn(Collections.<OFPortConfig>emptySet()).anyTimes(); expect(ofPortDesc.getState()).andReturn(state).anyTimes(); replay(ofPort); replay(ofPortDesc); return ofPortDesc; }
/** * Build a portDescription from a given Ethernet port description. * * @param port the port to build from. * @return portDescription for the port. */ private PortDescription buildPortDescription(OFPortDesc port) { if (port.getVersion().wireVersion >= OFVersion.OF_14.getWireVersion()) { return buildPortDescription14(port); } PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); boolean enabled = !port.getState().contains(OFPortState.LINK_DOWN) && !port.getConfig().contains(OFPortConfig.PORT_DOWN); Port.Type type = port.getCurr().contains(OFPortFeatures.PF_FIBER) ? FIBER : COPPER; boolean adminDown = port.getConfig().contains(OFPortConfig.PORT_DOWN); SparseAnnotations annotations = makePortAnnotation(port.getName(), port.getHwAddr().toString(), adminDown).build(); return new DefaultPortDescription(portNo, enabled, type, portSpeed(port), annotations); }
public static int toWireValue(Set<OFPortState> set) { int wireValue = 0; for(OFPortState e: set) { switch(e) { case LINK_DOWN: wireValue |= LINK_DOWN_VAL; break; case BLOCKED: wireValue |= BLOCKED_VAL; break; case LIVE: wireValue |= LIVE_VAL; break; default: throw new IllegalArgumentException("Illegal enum value for type OFPortState in version 1.5: " + e); } } return wireValue; }
public void testIsEnabledForFactory(OFFactory factory) { // Default OFPortDesc desc = factory.buildPortDesc() .build(); assertThat(desc.isEnabled(), is(true)); // Partially disabled desc = factory.buildPortDesc() .setConfig(new HashSet<OFPortConfig>(Arrays.asList(OFPortConfig.PORT_DOWN))) .build(); assertThat(desc.isEnabled(), is(false)); // Fully disabled desc = factory.buildPortDesc() .setConfig(new HashSet<OFPortConfig>(Arrays.asList(OFPortConfig.PORT_DOWN))) .setState(new HashSet<OFPortState>(Arrays.asList(OFPortState.LINK_DOWN))) .build(); assertThat(desc.isEnabled(), is(false)); }
private PortDescription buildOduCltPortDescription(OFPortDesc port) { PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); boolean enabled = !port.getState().contains(OFPortState.LINK_DOWN) && !port.getConfig().contains(OFPortConfig.PORT_DOWN); Long portSpeedInMbps = portSpeed(port); CltSignalType sigType = null; switch (portSpeedInMbps.toString()) { case "1000": sigType = CltSignalType.CLT_1GBE; break; case "10000": sigType = CltSignalType.CLT_10GBE; break; case "40000": sigType = CltSignalType.CLT_40GBE; break; case "100000": sigType = CltSignalType.CLT_100GBE; break; default: throw new RuntimeException("Un recognize OduClt speed: " + portSpeedInMbps.toString()); } SparseAnnotations annotations = buildOduCltAnnotation(port); return oduCltPortDescription(portNo, enabled, sigType, annotations); }
/** * Build a portDescription from a given Ethernet port description. * * @param port the port to build from. * @return portDescription for the port. */ private PortDescription buildPortDescription(OFPortDesc port) { PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); boolean enabled = !port.getState().contains(OFPortState.LINK_DOWN) && !port.getConfig().contains(OFPortConfig.PORT_DOWN); Port.Type type = port.getCurr().contains(OFPortFeatures.PF_FIBER) ? FIBER : COPPER; SparseAnnotations annotations = makePortAnnotation(port.getName(), port.getHwAddr().toString()); return new DefaultPortDescription(portNo, enabled, type, portSpeed(port), annotations); }
/** * Build a portDescription from a given a port description describing some * Optical port. * * @param port description property type. * @param port the port to build from. * @return portDescription for the port. */ private PortDescription buildPortDescription(PortDescPropertyType ptype, OFPortOptical port) { checkArgument(port.getDesc().size() >= 1); // Minimally functional fixture. This needs to be fixed as we add better support. PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); boolean enabled = !port.getState().contains(OFPortState.LINK_DOWN) && !port.getConfig().contains(OFPortConfig.PORT_DOWN); SparseAnnotations annotations = makePortAnnotation(port.getName(), port.getHwAddr().toString()); if (port.getVersion() == OFVersion.OF_13 && ptype == PortDescPropertyType.OPTICAL_TRANSPORT) { // At this point, not much is carried in the optical port message. LOG.debug("Optical transport port message {}", port.toString()); } else { // removable once 1.4+ support complete. LOG.debug("Unsupported optical port properties"); } OFPortDescPropOpticalTransport desc = port.getDesc().get(0); switch (desc.getPortSignalType()) { // FIXME: use constants once loxi has full optical extensions case 2: // OMS port // Assume complete optical spectrum and 50 GHz grid // LINC-OE is only supported optical OF device for now return omsPortDescription(portNo, enabled, Spectrum.U_BAND_MIN, Spectrum.O_BAND_MAX, Frequency.ofGHz(50), annotations); case 5: // OCH port OchSignal signal = new OchSignal(GridType.DWDM, ChannelSpacing.CHL_50GHZ, 0, 4); return ochPortDescription(portNo, enabled, OduSignalType.ODU4, true, signal, annotations); default: break; } return new DefaultPortDescription(portNo, enabled, FIBER, 0, annotations); }
protected UpdateOperation getUpdateOperation(OFPortState srcPortState, OFPortState dstPortState) { boolean added = ((srcPortState != OFPortState.STP_BLOCK) && (dstPortState != OFPortState.STP_BLOCK)); if (added) { return UpdateOperation.LINK_UPDATED; } else { return UpdateOperation.LINK_REMOVED; } }
protected UpdateOperation getUpdateOperation(OFPortState srcPortState) { boolean portUp = (srcPortState != OFPortState.STP_BLOCK); if (portUp) { return UpdateOperation.PORT_UP; } else { return UpdateOperation.PORT_DOWN; } }
/** * Set the internal data structure storing this switch's port * to the ports specified by newPortsByNumber * * CALLER MUST HOLD WRITELOCK * * @param newPortsByNumber * @throws IllegaalStateException if called without holding the * writelock */ private void updatePortsWithNewPortsByNumber( Map<OFPort,OFPortDesc> newPortsByNumber) { if (!lock.writeLock().isHeldByCurrentThread()) { throw new IllegalStateException("Method called without " + "holding writeLock"); } Map<String,OFPortDesc> newPortsByName = new HashMap<String, OFPortDesc>(); List<OFPortDesc> newPortList = new ArrayList<OFPortDesc>(); List<OFPortDesc> newEnabledPortList = new ArrayList<OFPortDesc>(); List<OFPort> newEnabledPortNumbers = new ArrayList<OFPort>(); for(OFPortDesc p: newPortsByNumber.values()) { newPortList.add(p); newPortsByName.put(p.getName().toLowerCase(), p); if (!p.getState().contains(OFPortState.LINK_DOWN) && !p.getConfig().contains(OFPortConfig.PORT_DOWN)) { if (!newEnabledPortList.contains(p)) { newEnabledPortList.add(p); } if (!newEnabledPortNumbers.contains(p.getPortNo())) { newEnabledPortNumbers.add(p.getPortNo()); } } } portsByName = Collections.unmodifiableMap(newPortsByName); portsByNumber = Collections.unmodifiableMap(newPortsByNumber); enabledPortList = Collections.unmodifiableList(newEnabledPortList); enabledPortNumbers = Collections.unmodifiableList(newEnabledPortNumbers); portList = Collections.unmodifiableList(newPortList); }
/** * Set the internal data structure storing this switch's port * to the ports specified by newPortsByNumber * * CALLER MUST HOLD WRITELOCK * * @param newPortsByNumber * @throws IllegaalStateException if called without holding the * writelock */ private void updatePortsWithNewPortsByNumber( Map<OFPort,OFPortDesc> newPortsByNumber) { if (!lock.writeLock().isHeldByCurrentThread()) { throw new IllegalStateException("Method called without " + "holding writeLock"); } Map<String,OFPortDesc> newPortsByName = new HashMap<String, OFPortDesc>(); List<OFPortDesc> newPortList = new ArrayList<OFPortDesc>(); List<OFPortDesc> newEnabledPortList = new ArrayList<OFPortDesc>(); List<OFPort> newEnabledPortNumbers = new ArrayList<OFPort>(); for(OFPortDesc p: newPortsByNumber.values()) { newPortList.add(p); newPortsByName.put(p.getName().toLowerCase(), p); if (!p.getState().contains(OFPortState.LINK_DOWN) && !p.getConfig().contains(OFPortConfig.PORT_DOWN)) { newEnabledPortList.add(p); newEnabledPortNumbers.add(p.getPortNo()); } } portsByName = Collections.unmodifiableMap(newPortsByName); portsByNumber = Collections.unmodifiableMap(newPortsByNumber); enabledPortList = Collections.unmodifiableList(newEnabledPortList); enabledPortNumbers = Collections.unmodifiableList(newEnabledPortNumbers); portList = Collections.unmodifiableList(newPortList); }