Java 类net.floodlightcontroller.core.ImmutablePort 实例源码

项目:QoS-floodlight    文件:LinkDiscoveryManager.java   
/**
 * We don't react the port changed notifications here. we listen for
 * OFPortStatus messages directly. Might consider using this notifier
 * instead
 */
@Override
public void switchPortChanged(long switchId,
        ImmutablePort port,
        IOFSwitch.PortChangeType type) {

    switch (type) {
    case UP:
        processNewPort(switchId, port.getPortNumber());
        break;
    case DELETE: case DOWN:
        handlePortDown(switchId, port.getPortNumber());
        break;
    case OTHER_UPDATE: case ADD:
        // This is something other than port add or delete.
        // Topology does not worry about this.
        // If for some reason the port features change, which
        // we may have to react.
        break;
    }
}
项目:QoS-floodlight    文件:Controller.java   
/**
 * Called when ports on the given switch have changed. Writes the
 * updated switch to the sync store and queues a switch notification
 * to listeners
 * @param sw
 */
public synchronized void switchPortsChanged(IOFSwitch sw,
                                            ImmutablePort port,
                                            PortChangeType type) {
    if (role != Role.MASTER) {
        counters.invalidPortsChanged.updateCounterWithFlush();
        return;
    }
    if (!this.activeSwitches.containsKey(sw.getId())) {
        counters.invalidPortsChanged.updateCounterWithFlush();
        return;
    }
    // update switch in store
    addSwitchToStore(sw);
    // no need to count here. SwitchUpdate.dispatch will count
    // the portchanged
    SwitchUpdate update = new SwitchUpdate(sw.getId(),
                                           SwitchUpdateType.PORTCHANGED,
                                           port, type);
    addUpdateToQueue(update);
}
项目:QoS-floodlight    文件:Controller.java   
public SwitchUpdate(long swId,
                    SwitchUpdateType switchUpdateType,
                    ImmutablePort port,
                    PortChangeType changeType) {
    if (switchUpdateType == SwitchUpdateType.PORTCHANGED) {
        if (port == null) {
            throw new NullPointerException("Port must not be null " +
                    "for PORTCHANGED updates");
        }
        if (changeType == null) {
            throw new NullPointerException("ChangeType must not be " +
                    "null for PORTCHANGED updates");
        }
    } else {
        if (port != null || changeType != null) {
            throw new IllegalArgumentException("port and changeType " +
                    "must be null for " + switchUpdateType +
                    " updates");
        }
    }
    this.swId = swId;
    this.switchUpdateType = switchUpdateType;
    this.port = port;
    this.changeType = changeType;
}
项目:floodlight_with_topoguard    文件:LinkDiscoveryManager.java   
/**
 * We don't react the port changed notifications here. we listen for
 * OFPortStatus messages directly. Might consider using this notifier
 * instead
 */
@Override
public void switchPortChanged(long switchId,
        ImmutablePort port,
        IOFSwitch.PortChangeType type) {

    switch (type) {
    case UP:
        processNewPort(switchId, port.getPortNumber());
        break;
    case DELETE: case DOWN:
        handlePortDown(switchId, port.getPortNumber());
        break;
    case OTHER_UPDATE: case ADD:
        // This is something other than port add or delete.
        // Topology does not worry about this.
        // If for some reason the port features change, which
        // we may have to react.
        break;
    }
}
项目:floodlight_with_topoguard    文件:Controller.java   
/**
 * Called when ports on the given switch have changed. Writes the
 * updated switch to the sync store and queues a switch notification
 * to listeners
 * @param sw
 */
public synchronized void switchPortsChanged(IOFSwitch sw,
                                            ImmutablePort port,
                                            PortChangeType type) {
    if (role != Role.MASTER) {
        counters.invalidPortsChanged.updateCounterWithFlush();
        return;
    }
    if (!this.activeSwitches.containsKey(sw.getId())) {
        counters.invalidPortsChanged.updateCounterWithFlush();
        return;
    }
    // update switch in store
    addSwitchToStore(sw);
    // no need to count here. SwitchUpdate.dispatch will count
    // the portchanged
    SwitchUpdate update = new SwitchUpdate(sw.getId(),
                                           SwitchUpdateType.PORTCHANGED,
                                           port, type);
    addUpdateToQueue(update);
}
项目:floodlight_with_topoguard    文件:Controller.java   
public SwitchUpdate(long swId,
                    SwitchUpdateType switchUpdateType,
                    ImmutablePort port,
                    PortChangeType changeType) {
    if (switchUpdateType == SwitchUpdateType.PORTCHANGED) {
        if (port == null) {
            throw new NullPointerException("Port must not be null " +
                    "for PORTCHANGED updates");
        }
        if (changeType == null) {
            throw new NullPointerException("ChangeType must not be " +
                    "null for PORTCHANGED updates");
        }
    } else {
        if (port != null || changeType != null) {
            throw new IllegalArgumentException("port and changeType " +
                    "must be null for " + switchUpdateType +
                    " updates");
        }
    }
    this.swId = swId;
    this.switchUpdateType = switchUpdateType;
    this.port = port;
    this.changeType = changeType;
}
项目:FloodligtModule    文件:LinkDiscoveryManager.java   
/**
 * We don't react the port changed notifications here. we listen for
 * OFPortStatus messages directly. Might consider using this notifier
 * instead
 */
@Override
public void switchPortChanged(long switchId,
        ImmutablePort port,
        IOFSwitch.PortChangeType type) {

    switch (type) {
    case UP:
        processNewPort(switchId, port.getPortNumber());
        break;
    case DELETE: case DOWN:
        handlePortDown(switchId, port.getPortNumber());
        break;
    case OTHER_UPDATE: case ADD:
        // This is something other than port add or delete.
        // Topology does not worry about this.
        // If for some reason the port features change, which
        // we may have to react.
        break;
    }
}
项目:FloodligtModule    文件:Controller.java   
/**
 * Called when ports on the given switch have changed. Writes the
 * updated switch to the sync store and queues a switch notification
 * to listeners
 * @param sw
 */
public synchronized void switchPortsChanged(IOFSwitch sw,
                                            ImmutablePort port,
                                            PortChangeType type) {
    if (role != Role.MASTER) {
        counters.invalidPortsChanged.updateCounterWithFlush();
        return;
    }
    if (!this.activeSwitches.containsKey(sw.getId())) {
        counters.invalidPortsChanged.updateCounterWithFlush();
        return;
    }
    // update switch in store
    addSwitchToStore(sw);
    // no need to count here. SwitchUpdate.dispatch will count
    // the portchanged
    SwitchUpdate update = new SwitchUpdate(sw.getId(),
                                           SwitchUpdateType.PORTCHANGED,
                                           port, type);
    addUpdateToQueue(update);
}
项目:FloodligtModule    文件:Controller.java   
public SwitchUpdate(long swId,
                    SwitchUpdateType switchUpdateType,
                    ImmutablePort port,
                    PortChangeType changeType) {
    if (switchUpdateType == SwitchUpdateType.PORTCHANGED) {
        if (port == null) {
            throw new NullPointerException("Port must not be null " +
                    "for PORTCHANGED updates");
        }
        if (changeType == null) {
            throw new NullPointerException("ChangeType must not be " +
                    "null for PORTCHANGED updates");
        }
    } else {
        if (port != null || changeType != null) {
            throw new IllegalArgumentException("port and changeType " +
                    "must be null for " + switchUpdateType +
                    " updates");
        }
    }
    this.swId = swId;
    this.switchUpdateType = switchUpdateType;
    this.port = port;
    this.changeType = changeType;
}
项目:multicastSDN    文件:LinkDiscoveryManager.java   
/**
 * We don't react the port changed notifications here. we listen for
 * OFPortStatus messages directly. Might consider using this notifier
 * instead
 */
@Override
public void switchPortChanged(long switchId,
        ImmutablePort port,
        IOFSwitch.PortChangeType type) {

    switch (type) {
    case UP:
        processNewPort(switchId, port.getPortNumber());
        break;
    case DELETE: case DOWN:
        handlePortDown(switchId, port.getPortNumber());
        break;
    case OTHER_UPDATE: case ADD:
        // This is something other than port add or delete.
        // Topology does not worry about this.
        // If for some reason the port features change, which
        // we may have to react.
        break;
    }
}
项目:multicastSDN    文件:Controller.java   
/**
 * Called when ports on the given switch have changed. Writes the
 * updated switch to the sync store and queues a switch notification
 * to listeners
 * @param sw
 */
public synchronized void switchPortsChanged(IOFSwitch sw,
                                            ImmutablePort port,
                                            PortChangeType type) {
    if (role != Role.MASTER) {
        counters.invalidPortsChanged.updateCounterWithFlush();
        return;
    }
    if (!this.activeSwitches.containsKey(sw.getId())) {
        counters.invalidPortsChanged.updateCounterWithFlush();
        return;
    }
    // update switch in store
    addSwitchToStore(sw);
    // no need to count here. SwitchUpdate.dispatch will count
    // the portchanged
    SwitchUpdate update = new SwitchUpdate(sw.getId(),
                                           SwitchUpdateType.PORTCHANGED,
                                           port, type);
    addUpdateToQueue(update);
}
项目:multicastSDN    文件:Controller.java   
public SwitchUpdate(long swId,
                    SwitchUpdateType switchUpdateType,
                    ImmutablePort port,
                    PortChangeType changeType) {
    if (switchUpdateType == SwitchUpdateType.PORTCHANGED) {
        if (port == null) {
            throw new NullPointerException("Port must not be null " +
                    "for PORTCHANGED updates");
        }
        if (changeType == null) {
            throw new NullPointerException("ChangeType must not be " +
                    "null for PORTCHANGED updates");
        }
    } else {
        if (port != null || changeType != null) {
            throw new IllegalArgumentException("port and changeType " +
                    "must be null for " + switchUpdateType +
                    " updates");
        }
    }
    this.swId = swId;
    this.switchUpdateType = switchUpdateType;
    this.port = port;
    this.changeType = changeType;
}
项目:FlowSpaceFirewall    文件:OFControllerChannelHandler.java   
void processOFFeaturesRequest(OFControllerChannelHandler h, OFMessage  m)
        throws IOException {
    log.debug("Have a features request... generating features reply.");
    OFFeaturesReply response = (OFFeaturesReply) BasicFactory.getInstance().getMessage(OFType.FEATURES_REPLY);
    response.setDatapathId(h.sw.getId());
    response.setCapabilities(h.sw.getCapabilities());
    response.setActions(h.sw.getActions());
    //need to take the collection of ports and turn them into the list
    List <OFPhysicalPort> ports = new ArrayList<OFPhysicalPort>();
    for(ImmutablePort port : h.sw.getPorts()){
        if(h.proxy.getSlicer().isPortPartOfSlice(port.getPortNumber())){
            OFPhysicalPort p = port.toOFPhysicalPort();
            ports.add(p);
        }   
    }

    response.setPorts(ports);
    response.setBuffers(h.sw.getBuffers());
    response.setTables(h.sw.getTables());
    response.setXid(m.getXid());
    log.debug("sending OFFeatureReply");
    h.sendMessage(response);
}
项目:FlowSpaceFirewall    文件:VLANSlicer.java   
/**
 * sets the switch object as our slicer
 * probably existed before the switch connected
 * @param sw the IOFSwitch to set as the switch
 */

public void setSwitch(IOFSwitch sw){
    this.sw = sw;
    Iterator <ImmutablePort> portIterator = sw.getPorts().iterator();
    while(portIterator.hasNext()){
        ImmutablePort port = portIterator.next();
        PortConfig ptCfg = this.getPortConfig(port.getName());
        if(ptCfg != null){
            log.debug("Setting port named: " + port.getName() + " to port ID: " + port.getPortNumber());
            ptCfg.setPortId(port.getPortNumber());
        }else{
            log.debug("No configuration for port named: " + port.getName());
        }
    }
}
项目:FlowSpaceFirewall    文件:VLANSlicer.java   
/**
 * sets the portConfig for the portNamed portname
 * @param portName
 * @param portConfig
 */

public void setPortConfig(String portName, PortConfig portConfig){
    portList.put(portName, portConfig);
    if(this.sw != null){
        Iterator <ImmutablePort> portIterator = sw.getPorts().iterator();
        while(portIterator.hasNext()){
            ImmutablePort port = portIterator.next();
            log.debug("port: " + port.getName() + ":" + port.getPortNumber());
            if(port.getName().equals(portName)){
                PortConfig ptCfg = this.getPortConfig(port.getName());
                ptCfg.setPortId(port.getPortNumber());
                log.debug("Set port " + portConfig.getPortName() + " to port id " + port.getPortNumber());
            }
        }
    }
}
项目:FlowSpaceFirewall    文件:VLANSlicer.java   
/**
 * returns the <PortConfig> object for a given port
 * based on the portId specified where portId is the 
 * openflow identifier for the port
 * If the switch is null (not connected) or the port is 
 * not found, the return result will be null
 * @param portId the openflow port id
 **/

public PortConfig getPortConfig(short portId){

    if(this.sw == null){
        throw new IllegalStateException("Switch not connected so we don't know the port id");
    }
    ImmutablePort thisPort = this.sw.getPort(portId);

    if(thisPort == null){
        log.info("Port: " + portId + " was not found on this switch.");
        return null;
    }
    log.debug("Looking for PORT: " + thisPort.getName());
    if(portList.containsKey(thisPort.getName())){
        return portList.get(thisPort.getName());
    }else{
        return null;
    }
}
项目:QoS-floodlight    文件:LinkDiscoveryManager.java   
/**
 * Check if incoming discovery messages are enabled or not.
 * @param sw
 * @param port
 * @param isStandard
 * @return
 */
protected boolean isIncomingDiscoveryAllowed(long sw, short port,
                                             boolean isStandard) {

    if (isLinkDiscoverySuppressed(sw, port)) {
        /* Do not process LLDPs from this port as suppressLLDP is set */
        return false;
    }

    IOFSwitch iofSwitch = floodlightProvider.getSwitch(sw);
    if (iofSwitch == null) {
        return false;
    }

    if (port == OFPort.OFPP_LOCAL.getValue()) return false;

    ImmutablePort ofpPort = iofSwitch.getPort(port);
    if (ofpPort == null) {
        if (log.isTraceEnabled()) {
            log.trace("Null physical port. sw={}, port={}",
                      HexString.toHexString(sw), port);
        }
        return false;
    }

    return true;
}
项目:QoS-floodlight    文件:LinkDiscoveryManager.java   
/**
 * Check if outgoing discovery messages are enabled or not.
 * @param sw
 * @param port
 * @param isStandard
 * @param isReverse
 * @return
 */
protected boolean isOutgoingDiscoveryAllowed(long sw, short port,
                                             boolean isStandard,
                                             boolean isReverse) {

    if (isLinkDiscoverySuppressed(sw, port)) {
        /* Dont send LLDPs out of this port as suppressLLDP is set */
        return false;
    }

    IOFSwitch iofSwitch = floodlightProvider.getSwitch(sw);
    if (iofSwitch == null) {
        return false;
    }

    if (port == OFPort.OFPP_LOCAL.getValue()) return false;

    ImmutablePort ofpPort = iofSwitch.getPort(port);
    if (ofpPort == null) {
        if (log.isTraceEnabled()) {
            log.trace("Null physical port. sw={}, port={}",
                      HexString.toHexString(sw), port);
        }
        return false;
    }

    // For fast ports, do not send forward LLDPs or BDDPs.
    if (!isReverse && autoPortFastFeature && iofSwitch.isFastPort(port))
        return false;
    return true;
}
项目:QoS-floodlight    文件:LinkDiscoveryManager.java   
/**
 * Send LLDPs to all switch-ports
 */
protected void discoverOnAllPorts() {
    if (log.isTraceEnabled()) {
        log.trace("Sending LLDP packets out of all the enabled ports");
    }
    // Send standard LLDPs
    for (long sw : floodlightProvider.getAllSwitchDpids()) {
        IOFSwitch iofSwitch = floodlightProvider.getSwitch(sw);
        if (iofSwitch == null) continue;
        if (iofSwitch.getEnabledPorts() != null) {
            for (ImmutablePort ofp : iofSwitch.getEnabledPorts()) {
                if (isLinkDiscoverySuppressed(sw, ofp.getPortNumber()))
                                                                       continue;
                if (autoPortFastFeature
                    && iofSwitch.isFastPort(ofp.getPortNumber()))
                                                                 continue;

                // sends forward LLDP only non-fastports.
                sendDiscoveryMessage(sw, ofp.getPortNumber(), true,
                                     false);

                // If the switch port is not already in the maintenance
                // queue, add it.
                NodePortTuple npt = new NodePortTuple(
                                                      sw,
                                                      ofp.getPortNumber());
                addToMaintenanceQueue(npt);
            }
        }
    }
}
项目:QoS-floodlight    文件:Controller.java   
@Override
public void switchPortChanged(long switchId, ImmutablePort port,
                              PortChangeType type) {
    String msg = String.format("Switch %s port %s changed: %s",
                               HexString.toHexString(switchId),
                               port.getName(),
                               type.toString());
    notifier.postNotification(msg);
}
项目:QoS-floodlight    文件:DeviceManagerImplTest.java   
private IOFSwitch makeSwitchMock(long id) {
    IOFSwitch mockSwitch = createMock(IOFSwitch.class);
    ImmutablePort port = ImmutablePort.create("p1", (short)1);
    expect(mockSwitch.getId()).andReturn(id).anyTimes();
    expect(mockSwitch.getStringId())
            .andReturn(HexString.toHexString(id, 6)).anyTimes();
    expect(mockSwitch.getPort(anyShort()))
            .andReturn(port).anyTimes();
    return mockSwitch;
}
项目:QoS-floodlight    文件:OFSwitchBaseTest.java   
@Before
public void setUpPorts() {
    ImmutablePort.Builder bld = new ImmutablePort.Builder();
    // p1a is disabled
    p1a = bld.setName("port1")
             .setPortNumber((short)1)
             .setPortStateLinkDown(true)
             .build();
    assertFalse("Sanity check portEnabled", p1a.isEnabled());

    // p1b is enabled
    // p1b has different feature from p1a
    p1b = bld.addCurrentFeature(OFPortFeatures.OFPPF_1GB_FD)
             .setPortStateLinkDown(false)
             .build();
    assertTrue("Sanity check portEnabled", p1b.isEnabled());

    // p2 is disabled
    // p2 has mixed case
    bld = new ImmutablePort.Builder();
    p2a = bld.setName("Port2")
            .setPortNumber((short)2)
            .setPortStateLinkDown(false)
            .addConfig(OFPortConfig.OFPPC_PORT_DOWN)
            .build();
    // p2b only differs in PortFeatures
    p2b = bld.addCurrentFeature(OFPortFeatures.OFPPF_100MB_HD)
             .build();
    assertFalse("Sanity check portEnabled", p2a.isEnabled());
    // p3 is enabled
    // p3 has mixed case
    bld = new ImmutablePort.Builder();
    p3 = bld.setName("porT3")
            .setPortNumber((short)3)
            .setPortStateLinkDown(false)
            .build();
    assertTrue("Sanity check portEnabled", p3.isEnabled());

}
项目:QoS-floodlight    文件:ControllerTest.java   
/** Set the mock expectations for sw when sw is passed to addSwitch
 * The same expectations can be used when a new SwitchSyncRepresentation
 * is created from the given mocked switch */
protected void setupSwitchForAddSwitch(IOFSwitch sw, long dpid,
                                       OFDescriptionStatistics desc,
                                       OFFeaturesReply featuresReply) {
    String dpidString = HexString.toHexString(dpid);

    if (desc == null) {
        desc = createOFDescriptionStatistics();
    }
    if (featuresReply == null) {
        featuresReply = createOFFeaturesReply();
        featuresReply.setDatapathId(dpid);
    }
    List<ImmutablePort> ports =
            ImmutablePort.immutablePortListOf(featuresReply.getPorts());

    expect(sw.getId()).andReturn(dpid).anyTimes();
    expect(sw.getStringId()).andReturn(dpidString).anyTimes();
    expect(sw.getDescriptionStatistics()) .andReturn(desc).atLeastOnce();
    expect(sw.getBuffers())
            .andReturn(featuresReply.getBuffers()).atLeastOnce();
    expect(sw.getTables())
            .andReturn(featuresReply.getTables()).atLeastOnce();
    expect(sw.getCapabilities())
            .andReturn(featuresReply.getCapabilities()).atLeastOnce();
    expect(sw.getActions())
            .andReturn(featuresReply.getActions()).atLeastOnce();
    expect(sw.getPorts())
            .andReturn(ports).atLeastOnce();
    expect(sw.attributeEquals(IOFSwitch.SWITCH_SUPPORTS_NX_ROLE, true))
            .andReturn(false).anyTimes();
    expect(sw.getInetAddress()).andReturn(null).anyTimes();
}
项目:floodlight_with_topoguard    文件:TopoloyUpdateChecker.java   
@Override
public void switchPortChanged(long switchId, ImmutablePort port,
        PortChangeType type) {
    switch (type) {
    case DELETE:
    case DOWN:
        this.handlePortDown(switchId, port);
        break;
    default:
        break;
    }

}
项目:floodlight_with_topoguard    文件:TopoloyUpdateChecker.java   
void handleSwitchAdd(long dpid) {
    IOFSwitch sw = floodlightProvider.getSwitch(dpid);
    for (ImmutablePort port : sw.getPorts()) {
        Port switch_port = new Port(dpid, port.getPortNumber());
        if (!this.port_list.containsKey(switch_port)) {
            this.port_list.put(switch_port, new PortProperty());
        }

    }
}
项目:floodlight_with_topoguard    文件:LinkDiscoveryManager.java   
/**
 * Check if incoming discovery messages are enabled or not.
 * @param sw
 * @param port
 * @param isStandard
 * @return
 */
protected boolean isIncomingDiscoveryAllowed(long sw, short port,
                                             boolean isStandard) {

    if (isLinkDiscoverySuppressed(sw, port)) {
        /* Do not process LLDPs from this port as suppressLLDP is set */
        return false;
    }

    IOFSwitch iofSwitch = floodlightProvider.getSwitch(sw);
    if (iofSwitch == null) {
        return false;
    }

    if (port == OFPort.OFPP_LOCAL.getValue()) return false;

    ImmutablePort ofpPort = iofSwitch.getPort(port);
    if (ofpPort == null) {
        if (log.isTraceEnabled()) {
            log.trace("Null physical port. sw={}, port={}",
                      HexString.toHexString(sw), port);
        }
        return false;
    }

    return true;
}
项目:floodlight_with_topoguard    文件:LinkDiscoveryManager.java   
/**
 * Check if outgoing discovery messages are enabled or not.
 * @param sw
 * @param port
 * @param isStandard
 * @param isReverse
 * @return
 */
protected boolean isOutgoingDiscoveryAllowed(long sw, short port,
                                             boolean isStandard,
                                             boolean isReverse) {

    if (isLinkDiscoverySuppressed(sw, port)) {
        /* Dont send LLDPs out of this port as suppressLLDP is set */
        return false;
    }

    IOFSwitch iofSwitch = floodlightProvider.getSwitch(sw);
    if (iofSwitch == null) {
        return false;
    }

    if (port == OFPort.OFPP_LOCAL.getValue()) return false;

    ImmutablePort ofpPort = iofSwitch.getPort(port);
    if (ofpPort == null) {
        if (log.isTraceEnabled()) {
            log.trace("Null physical port. sw={}, port={}",
                      HexString.toHexString(sw), port);
        }
        return false;
    }

    // For fast ports, do not send forward LLDPs or BDDPs.
    if (!isReverse && autoPortFastFeature && iofSwitch.isFastPort(port))
        return false;
    return true;
}
项目:floodlight_with_topoguard    文件:LinkDiscoveryManager.java   
/**
 * Send LLDPs to all switch-ports
 */
protected void discoverOnAllPorts() {
    if (log.isTraceEnabled()) {
        log.trace("Sending LLDP packets out of all the enabled ports");
    }
    // Send standard LLDPs
    for (long sw : floodlightProvider.getAllSwitchDpids()) {
        IOFSwitch iofSwitch = floodlightProvider.getSwitch(sw);
        if (iofSwitch == null) continue;
        if (iofSwitch.getEnabledPorts() != null) {
            for (ImmutablePort ofp : iofSwitch.getEnabledPorts()) {
                if (isLinkDiscoverySuppressed(sw, ofp.getPortNumber()))
                                                                       continue;
                if (autoPortFastFeature
                    && iofSwitch.isFastPort(ofp.getPortNumber()))
                                                                 continue;

                // sends forward LLDP only non-fastports.
                sendDiscoveryMessage(sw, ofp.getPortNumber(), true,
                                     false);

                // If the switch port is not already in the maintenance
                // queue, add it.
                NodePortTuple npt = new NodePortTuple(
                                                      sw,
                                                      ofp.getPortNumber());
                addToMaintenanceQueue(npt);
            }
        }
    }
}
项目:floodlight_with_topoguard    文件:Controller.java   
@Override
public void switchPortChanged(long switchId, ImmutablePort port,
                              PortChangeType type) {
    String msg = String.format("Switch %s port %s changed: %s",
                               HexString.toHexString(switchId),
                               port.getName(),
                               type.toString());
    notifier.postNotification(msg);
}
项目:floodlight_with_topoguard    文件:DeviceManagerImplTest.java   
private IOFSwitch makeSwitchMock(long id) {
    IOFSwitch mockSwitch = createMock(IOFSwitch.class);
    ImmutablePort port = ImmutablePort.create("p1", (short)1);
    expect(mockSwitch.getId()).andReturn(id).anyTimes();
    expect(mockSwitch.getStringId())
            .andReturn(HexString.toHexString(id, 6)).anyTimes();
    expect(mockSwitch.getPort(anyShort()))
            .andReturn(port).anyTimes();
    return mockSwitch;
}
项目:floodlight_with_topoguard    文件:OFSwitchBaseTest.java   
@Before
public void setUpPorts() {
    ImmutablePort.Builder bld = new ImmutablePort.Builder();
    // p1a is disabled
    p1a = bld.setName("port1")
             .setPortNumber((short)1)
             .setPortStateLinkDown(true)
             .build();
    assertFalse("Sanity check portEnabled", p1a.isEnabled());

    // p1b is enabled
    // p1b has different feature from p1a
    p1b = bld.addCurrentFeature(OFPortFeatures.OFPPF_1GB_FD)
             .setPortStateLinkDown(false)
             .build();
    assertTrue("Sanity check portEnabled", p1b.isEnabled());

    // p2 is disabled
    // p2 has mixed case
    bld = new ImmutablePort.Builder();
    p2a = bld.setName("Port2")
            .setPortNumber((short)2)
            .setPortStateLinkDown(false)
            .addConfig(OFPortConfig.OFPPC_PORT_DOWN)
            .build();
    // p2b only differs in PortFeatures
    p2b = bld.addCurrentFeature(OFPortFeatures.OFPPF_100MB_HD)
             .build();
    assertFalse("Sanity check portEnabled", p2a.isEnabled());
    // p3 is enabled
    // p3 has mixed case
    bld = new ImmutablePort.Builder();
    p3 = bld.setName("porT3")
            .setPortNumber((short)3)
            .setPortStateLinkDown(false)
            .build();
    assertTrue("Sanity check portEnabled", p3.isEnabled());

}
项目:floodlight_with_topoguard    文件:ControllerTest.java   
/** Set the mock expectations for sw when sw is passed to addSwitch
 * The same expectations can be used when a new SwitchSyncRepresentation
 * is created from the given mocked switch */
protected void setupSwitchForAddSwitch(IOFSwitch sw, long dpid,
                                       OFDescriptionStatistics desc,
                                       OFFeaturesReply featuresReply) {
    String dpidString = HexString.toHexString(dpid);

    if (desc == null) {
        desc = createOFDescriptionStatistics();
    }
    if (featuresReply == null) {
        featuresReply = createOFFeaturesReply();
        featuresReply.setDatapathId(dpid);
    }
    List<ImmutablePort> ports =
            ImmutablePort.immutablePortListOf(featuresReply.getPorts());

    expect(sw.getId()).andReturn(dpid).anyTimes();
    expect(sw.getStringId()).andReturn(dpidString).anyTimes();
    expect(sw.getDescriptionStatistics()) .andReturn(desc).atLeastOnce();
    expect(sw.getBuffers())
            .andReturn(featuresReply.getBuffers()).atLeastOnce();
    expect(sw.getTables())
            .andReturn(featuresReply.getTables()).atLeastOnce();
    expect(sw.getCapabilities())
            .andReturn(featuresReply.getCapabilities()).atLeastOnce();
    expect(sw.getActions())
            .andReturn(featuresReply.getActions()).atLeastOnce();
    expect(sw.getPorts())
            .andReturn(ports).atLeastOnce();
    expect(sw.attributeEquals(IOFSwitch.SWITCH_SUPPORTS_NX_ROLE, true))
            .andReturn(false).anyTimes();
    expect(sw.getInetAddress()).andReturn(null).anyTimes();
}
项目:FloodligtModule    文件:LinkDiscoveryManager.java   
/**
 * Check if incoming discovery messages are enabled or not.
 * @param sw
 * @param port
 * @param isStandard
 * @return
 */
protected boolean isIncomingDiscoveryAllowed(long sw, short port,
                                             boolean isStandard) {

    if (isLinkDiscoverySuppressed(sw, port)) {
        /* Do not process LLDPs from this port as suppressLLDP is set */
        return false;
    }

    IOFSwitch iofSwitch = floodlightProvider.getSwitch(sw);
    if (iofSwitch == null) {
        return false;
    }

    if (port == OFPort.OFPP_LOCAL.getValue()) return false;

    ImmutablePort ofpPort = iofSwitch.getPort(port);
    if (ofpPort == null) {
        if (log.isTraceEnabled()) {
            log.trace("Null physical port. sw={}, port={}",
                      HexString.toHexString(sw), port);
        }
        return false;
    }

    return true;
}
项目:FloodligtModule    文件:LinkDiscoveryManager.java   
/**
 * Check if outgoing discovery messages are enabled or not.
 * @param sw
 * @param port
 * @param isStandard
 * @param isReverse
 * @return
 */
protected boolean isOutgoingDiscoveryAllowed(long sw, short port,
                                             boolean isStandard,
                                             boolean isReverse) {

    if (isLinkDiscoverySuppressed(sw, port)) {
        /* Dont send LLDPs out of this port as suppressLLDP is set */
        return false;
    }

    IOFSwitch iofSwitch = floodlightProvider.getSwitch(sw);
    if (iofSwitch == null) {
        return false;
    }

    if (port == OFPort.OFPP_LOCAL.getValue()) return false;

    ImmutablePort ofpPort = iofSwitch.getPort(port);
    if (ofpPort == null) {
        if (log.isTraceEnabled()) {
            log.trace("Null physical port. sw={}, port={}",
                      HexString.toHexString(sw), port);
        }
        return false;
    }

    // For fast ports, do not send forward LLDPs or BDDPs.
    if (!isReverse && autoPortFastFeature && iofSwitch.isFastPort(port))
        return false;
    return true;
}
项目:FloodligtModule    文件:LinkDiscoveryManager.java   
/**
 * Send LLDPs to all switch-ports
 */
protected void discoverOnAllPorts() {
    if (log.isTraceEnabled()) {
        log.trace("Sending LLDP packets out of all the enabled ports");
    }
    // Send standard LLDPs
    for (long sw : floodlightProvider.getAllSwitchDpids()) {
        IOFSwitch iofSwitch = floodlightProvider.getSwitch(sw);
        if (iofSwitch == null) continue;
        if (iofSwitch.getEnabledPorts() != null) {
            for (ImmutablePort ofp : iofSwitch.getEnabledPorts()) {
                if (isLinkDiscoverySuppressed(sw, ofp.getPortNumber()))
                                                                       continue;
                if (autoPortFastFeature
                    && iofSwitch.isFastPort(ofp.getPortNumber()))
                                                                 continue;

                // sends forward LLDP only non-fastports.
                sendDiscoveryMessage(sw, ofp.getPortNumber(), true,
                                     false);

                // If the switch port is not already in the maintenance
                // queue, add it.
                NodePortTuple npt = new NodePortTuple(
                                                      sw,
                                                      ofp.getPortNumber());
                addToMaintenanceQueue(npt);
            }
        }
    }
}
项目:FloodligtModule    文件:Controller.java   
@Override
public void switchPortChanged(long switchId, ImmutablePort port,
                              PortChangeType type) {
    String msg = String.format("Switch %s port %s changed: %s",
                               HexString.toHexString(switchId),
                               port.getName(),
                               type.toString());
    notifier.postNotification(msg);
}
项目:FloodligtModule    文件:DeviceManagerImplTest.java   
private IOFSwitch makeSwitchMock(long id) {
    IOFSwitch mockSwitch = createMock(IOFSwitch.class);
    ImmutablePort port = ImmutablePort.create("p1", (short)1);
    expect(mockSwitch.getId()).andReturn(id).anyTimes();
    expect(mockSwitch.getStringId())
            .andReturn(HexString.toHexString(id, 6)).anyTimes();
    expect(mockSwitch.getPort(anyShort()))
            .andReturn(port).anyTimes();
    return mockSwitch;
}
项目:FloodligtModule    文件:OFSwitchBaseTest.java   
@Before
public void setUpPorts() {
    ImmutablePort.Builder bld = new ImmutablePort.Builder();
    // p1a is disabled
    p1a = bld.setName("port1")
             .setPortNumber((short)1)
             .setPortStateLinkDown(true)
             .build();
    assertFalse("Sanity check portEnabled", p1a.isEnabled());

    // p1b is enabled
    // p1b has different feature from p1a
    p1b = bld.addCurrentFeature(OFPortFeatures.OFPPF_1GB_FD)
             .setPortStateLinkDown(false)
             .build();
    assertTrue("Sanity check portEnabled", p1b.isEnabled());

    // p2 is disabled
    // p2 has mixed case
    bld = new ImmutablePort.Builder();
    p2a = bld.setName("Port2")
            .setPortNumber((short)2)
            .setPortStateLinkDown(false)
            .addConfig(OFPortConfig.OFPPC_PORT_DOWN)
            .build();
    // p2b only differs in PortFeatures
    p2b = bld.addCurrentFeature(OFPortFeatures.OFPPF_100MB_HD)
             .build();
    assertFalse("Sanity check portEnabled", p2a.isEnabled());
    // p3 is enabled
    // p3 has mixed case
    bld = new ImmutablePort.Builder();
    p3 = bld.setName("porT3")
            .setPortNumber((short)3)
            .setPortStateLinkDown(false)
            .build();
    assertTrue("Sanity check portEnabled", p3.isEnabled());

}
项目:FloodligtModule    文件:ControllerTest.java   
/** Set the mock expectations for sw when sw is passed to addSwitch
 * The same expectations can be used when a new SwitchSyncRepresentation
 * is created from the given mocked switch */
protected void setupSwitchForAddSwitch(IOFSwitch sw, long dpid,
                                       OFDescriptionStatistics desc,
                                       OFFeaturesReply featuresReply) {
    String dpidString = HexString.toHexString(dpid);

    if (desc == null) {
        desc = createOFDescriptionStatistics();
    }
    if (featuresReply == null) {
        featuresReply = createOFFeaturesReply();
        featuresReply.setDatapathId(dpid);
    }
    List<ImmutablePort> ports =
            ImmutablePort.immutablePortListOf(featuresReply.getPorts());

    expect(sw.getId()).andReturn(dpid).anyTimes();
    expect(sw.getStringId()).andReturn(dpidString).anyTimes();
    expect(sw.getDescriptionStatistics()) .andReturn(desc).atLeastOnce();
    expect(sw.getBuffers())
            .andReturn(featuresReply.getBuffers()).atLeastOnce();
    expect(sw.getTables())
            .andReturn(featuresReply.getTables()).atLeastOnce();
    expect(sw.getCapabilities())
            .andReturn(featuresReply.getCapabilities()).atLeastOnce();
    expect(sw.getActions())
            .andReturn(featuresReply.getActions()).atLeastOnce();
    expect(sw.getPorts())
            .andReturn(ports).atLeastOnce();
    expect(sw.attributeEquals(IOFSwitch.SWITCH_SUPPORTS_NX_ROLE, true))
            .andReturn(false).anyTimes();
    expect(sw.getInetAddress()).andReturn(null).anyTimes();
}
项目:multicastSDN    文件:LinkDiscoveryManager.java   
/**
 * Check if incoming discovery messages are enabled or not.
 * @param sw
 * @param port
 * @param isStandard
 * @return
 */
protected boolean isIncomingDiscoveryAllowed(long sw, short port,
                                             boolean isStandard) {

    if (isLinkDiscoverySuppressed(sw, port)) {
        /* Do not process LLDPs from this port as suppressLLDP is set */
        return false;
    }

    IOFSwitch iofSwitch = floodlightProvider.getSwitch(sw);
    if (iofSwitch == null) {
        return false;
    }

    if (port == OFPort.OFPP_LOCAL.getValue()) return false;

    ImmutablePort ofpPort = iofSwitch.getPort(port);
    if (ofpPort == null) {
        if (log.isTraceEnabled()) {
            log.trace("Null physical port. sw={}, port={}",
                      HexString.toHexString(sw), port);
        }
        return false;
    }

    return true;
}