Java 类net.floodlightcontroller.core.IOFSwitch.PortChangeType 实例源码

项目: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    文件: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    文件: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    文件: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;
}
项目:spring-open    文件:TopologyPublisher.java   
@Override
public void switchPortChanged(long swId, OFPortDesc port,
        PortChangeType changeType) {
    switch (changeType) {
    case ADD:
        switchPortAdded(swId, port);
        break;
    case DELETE:
        switchPortRemoved(swId, port);
        break;
    case UP:
        // NOTE: Currently, we treat Port UP/DOWN same as Port ADD/DELETE
        switchPortAdded(swId, port);
        break;
    case DOWN:
        // NOTE: Currently, we treat Port UP/DOWN same as Port ADD/DELETE
        switchPortRemoved(swId, port);
        break;
    case OTHER_UPDATE:
    default:
        // XXX S what is the right set of port change handlers?
        log.debug("Topology publisher does not handle these port updates: {}",
                    changeType);
    }
}
项目:spring-open    文件:Controller.java   
public SwitchUpdate(long swId,
        SwitchUpdateType switchUpdateType,
        OFPortDesc 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;
}
项目:spring-open    文件:Controller.java   
/**
 * Indicates that ports on the given switch have changed. Enqueue a switch
 * update.
 *
 * @param sw
 */
protected void notifyPortChanged(long dpid, OFPortDesc port,
        PortChangeType changeType) {
    if (port == null || changeType == null) {
        String msg = String.format("Switch port or changeType must not "
                + "be null in port change notification");
        throw new NullPointerException(msg);
    }
    if (connectedSwitches.get(dpid) == null || getSwitch(dpid) == null) {
        log.warn("Port change update on switch {} not connected or activated "
                + "... Aborting.", HexString.toHexString(dpid));
        return;
    }

    SwitchUpdate update = new SwitchUpdate(dpid, SwitchUpdateType.PORTCHANGED,
            port, changeType);
    addUpdateToQueue(update);
}
项目:spring-open    文件:ControllerTest.java   
/**
 * Test the method to notify the controller of a port change.
 * The controller should send out an update to the switch listeners.
 *
 * @throws InterruptedException
 */
@Test
public void testNotifyPortChanged() throws InterruptedException {
    long dpid = 1L;

    // No difference between OpenFlow versions here
    OFVersion version = OFVersion.OF_10;
    IOFSwitch sw = createMockSwitch(dpid, version);
    OFPortDesc port = OFFactories.getFactory(version).buildPortDesc()
            .setName("myPortName1")
            .setPortNo(OFPort.of(42))
            .build();

    replay(sw);

    controller.connectedSwitches.put(1L, new OFChannelHandler(controller));
    controller.activeMasterSwitches.put(1L, sw);

    doTestNotifyPortChanged(dpid, port, PortChangeType.ADD);
    doTestNotifyPortChanged(dpid, port, PortChangeType.OTHER_UPDATE);
    doTestNotifyPortChanged(dpid, port, PortChangeType.DELETE);
    doTestNotifyPortChanged(dpid, port, PortChangeType.UP);
    doTestNotifyPortChanged(dpid, port, PortChangeType.DOWN);

}
项目: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);
}
项目: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    文件: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    文件: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);
}
项目:multicastSDN    文件: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);
}
项目:spring-open    文件:ControllerTest.java   
private void doTestUpdateQueueWithPortUpdate(long dpid, OFPortDesc port,
        PortChangeType type,
        DummySwitchListener listener) throws InterruptedException {
    controller.updates.put(controller.new SwitchUpdate(dpid,
            SwitchUpdateType.PORTCHANGED, port, type));
    synchronized (listener) {
        listener.wait(500);
    }
    // Test that the update was seen by the listener 1 time
    assertEquals(1, listener.getPortUpdateCount(type));
}
项目:spring-open    文件:ControllerTest.java   
private void doTestNotifyPortChanged(long dpid, OFPortDesc port,
        PortChangeType changeType) throws InterruptedException {
    controller.notifyPortChanged(dpid, port, changeType);

    assertEquals(1, controller.updates.size());
    IUpdate update = controller.updates.take();
    assertEquals(true, update instanceof SwitchUpdate);
    SwitchUpdate swUpdate = (SwitchUpdate) update;
    assertEquals(dpid, swUpdate.getSwId());
    assertEquals(SwitchUpdateType.PORTCHANGED, swUpdate.getSwitchUpdateType());
    assertEquals(changeType, swUpdate.getPortChangeType());
}
项目:QoS-floodlight    文件:ControllerTest.java   
/**
 * Test that notifyPortChanged() results in an IOFSwitchListener
 * update and that its arguments are passed through to
 * the listener call
 */
@Test
public void testNotifySwitchPoArtChanged() throws Exception {
    long dpid = 42L;

    OFFeaturesReply fr1 = createOFFeaturesReply();
    fr1.setDatapathId(dpid);
    OFPhysicalPort p1 = createOFPhysicalPort("Port1", 1);
    fr1.setPorts(Collections.singletonList(p1));

    OFFeaturesReply fr2 = createOFFeaturesReply();
    fr1.setDatapathId(dpid);
    OFPhysicalPort p2 = createOFPhysicalPort("Port1", 1);
    p2.setAdvertisedFeatures(0x2); // just some bogus values
    fr2.setPorts(Collections.singletonList(p2));

    OFDescriptionStatistics desc = createOFDescriptionStatistics();

    // activate switch
    IOFSwitch sw = doActivateNewSwitch(dpid, desc, fr1);

    // check the store
    SwitchSyncRepresentation ssr = storeClient.getValue(dpid);
    assertNotNull(ssr);
    assertEquals(dpid, ssr.getDpid());
    assertEquals(1, ssr.getPorts().size());
    assertEquals(p1, ssr.getPorts().get(0).toOFPhysicalPort());

    IOFSwitchListener listener = createMock(IOFSwitchListener.class);
    controller.addOFSwitchListener(listener);
    // setup switch with the new, second features reply (and thus ports)
    setupSwitchForAddSwitch(sw, dpid, desc, fr2);
    listener.switchPortChanged(dpid, ImmutablePort.fromOFPhysicalPort(p2),
                               PortChangeType.OTHER_UPDATE);
    expectLastCall().once();
    replay(listener);
    replay(sw);
    controller.notifyPortChanged(sw, ImmutablePort.fromOFPhysicalPort(p2),
                                 PortChangeType.OTHER_UPDATE);
    controller.processUpdateQueueForTesting();
    verify(listener);
    verify(sw);

    // check the store
    ssr = storeClient.getValue(dpid);
    assertNotNull(ssr);
    assertEquals(dpid, ssr.getDpid());
    assertEquals(1, ssr.getPorts().size());
    assertEquals(p2, ssr.getPorts().get(0).toOFPhysicalPort());
}
项目:QoS-floodlight    文件:OFChannelHandlerTest.java   
/**
 * Test port status message handling while MASTER
 *
 */
@Test
public void testPortStatusMessageMaster() throws Exception {
    long dpid = featuresReply.getDatapathId();
    testInitialMoveToMasterWithRole();

    OFPhysicalPort p = new OFPhysicalPort();
    p.setName("Port1");
    p.setPortNumber((short)1);
    OFPortStatus ps = (OFPortStatus)
            BasicFactory.getInstance().getMessage(OFType.PORT_STATUS);
    ps.setDesc(p);

    // The events we expect sw.handlePortStatus to return
    // We'll just use the same list for all valid OFPortReasons and add
    // arbitrary events for arbitrary ports that are not necessarily
    // related to the port status message. Our goal
    // here is not to return the correct set of events but the make sure
    // that a) sw.handlePortStatus is called
    //      b) the list of events sw.handlePortStatus returns is sent
    //         as IOFSwitchListener notifications.
    OrderedCollection<PortChangeEvent> events =
            new LinkedHashSetWrapper<PortChangeEvent>();
    ImmutablePort p1 = ImmutablePort.create("eth1", (short)1);
    ImmutablePort p2 = ImmutablePort.create("eth2", (short)2);
    ImmutablePort p3 = ImmutablePort.create("eth3", (short)3);
    ImmutablePort p4 = ImmutablePort.create("eth4", (short)4);
    ImmutablePort p5 = ImmutablePort.create("eth5", (short)5);
    events.add(new PortChangeEvent(p1, PortChangeType.ADD));
    events.add(new PortChangeEvent(p2, PortChangeType.DELETE));
    events.add(new PortChangeEvent(p3, PortChangeType.UP));
    events.add(new PortChangeEvent(p4, PortChangeType.DOWN));
    events.add(new PortChangeEvent(p5, PortChangeType.OTHER_UPDATE));


    for (OFPortReason reason: OFPortReason.values()) {
        ps.setReason(reason.getReasonCode());

        reset(sw);
        expect(sw.inputThrottled(anyObject(OFMessage.class)))
                .andReturn(false).anyTimes();
        expect(sw.getId()).andReturn(dpid).anyTimes();

        expect(sw.processOFPortStatus(ps)).andReturn(events).once();
        replay(sw);

        reset(controller);
        controller.notifyPortChanged(sw, p1, PortChangeType.ADD);
        controller.notifyPortChanged(sw, p2, PortChangeType.DELETE);
        controller.notifyPortChanged(sw, p3, PortChangeType.UP);
        controller.notifyPortChanged(sw, p4, PortChangeType.DOWN);
        controller.notifyPortChanged(sw, p5, PortChangeType.OTHER_UPDATE);
        sendMessageToHandlerNoControllerReset(
               Collections.<OFMessage>singletonList(ps));
        verify(sw);
        verify(controller);
    }
}
项目:floodlight_with_topoguard    文件:ControllerTest.java   
/**
 * Test that notifyPortChanged() results in an IOFSwitchListener
 * update and that its arguments are passed through to
 * the listener call
 */
@Test
public void testNotifySwitchPoArtChanged() throws Exception {
    long dpid = 42L;

    OFFeaturesReply fr1 = createOFFeaturesReply();
    fr1.setDatapathId(dpid);
    OFPhysicalPort p1 = createOFPhysicalPort("Port1", 1);
    fr1.setPorts(Collections.singletonList(p1));

    OFFeaturesReply fr2 = createOFFeaturesReply();
    fr1.setDatapathId(dpid);
    OFPhysicalPort p2 = createOFPhysicalPort("Port1", 1);
    p2.setAdvertisedFeatures(0x2); // just some bogus values
    fr2.setPorts(Collections.singletonList(p2));

    OFDescriptionStatistics desc = createOFDescriptionStatistics();

    // activate switch
    IOFSwitch sw = doActivateNewSwitch(dpid, desc, fr1);

    // check the store
    SwitchSyncRepresentation ssr = storeClient.getValue(dpid);
    assertNotNull(ssr);
    assertEquals(dpid, ssr.getDpid());
    assertEquals(1, ssr.getPorts().size());
    assertEquals(p1, ssr.getPorts().get(0).toOFPhysicalPort());

    IOFSwitchListener listener = createMock(IOFSwitchListener.class);
    controller.addOFSwitchListener(listener);
    // setup switch with the new, second features reply (and thus ports)
    setupSwitchForAddSwitch(sw, dpid, desc, fr2);
    listener.switchPortChanged(dpid, ImmutablePort.fromOFPhysicalPort(p2),
                               PortChangeType.OTHER_UPDATE);
    expectLastCall().once();
    replay(listener);
    replay(sw);
    controller.notifyPortChanged(sw, ImmutablePort.fromOFPhysicalPort(p2),
                                 PortChangeType.OTHER_UPDATE);
    controller.processUpdateQueueForTesting();
    verify(listener);
    verify(sw);

    // check the store
    ssr = storeClient.getValue(dpid);
    assertNotNull(ssr);
    assertEquals(dpid, ssr.getDpid());
    assertEquals(1, ssr.getPorts().size());
    assertEquals(p2, ssr.getPorts().get(0).toOFPhysicalPort());
}
项目:floodlight_with_topoguard    文件:OFChannelHandlerTest.java   
/**
 * Test port status message handling while MASTER
 *
 */
@Test
public void testPortStatusMessageMaster() throws Exception {
    long dpid = featuresReply.getDatapathId();
    testInitialMoveToMasterWithRole();

    OFPhysicalPort p = new OFPhysicalPort();
    p.setName("Port1");
    p.setPortNumber((short)1);
    OFPortStatus ps = (OFPortStatus)
            BasicFactory.getInstance().getMessage(OFType.PORT_STATUS);
    ps.setDesc(p);

    // The events we expect sw.handlePortStatus to return
    // We'll just use the same list for all valid OFPortReasons and add
    // arbitrary events for arbitrary ports that are not necessarily
    // related to the port status message. Our goal
    // here is not to return the correct set of events but the make sure
    // that a) sw.handlePortStatus is called
    //      b) the list of events sw.handlePortStatus returns is sent
    //         as IOFSwitchListener notifications.
    OrderedCollection<PortChangeEvent> events =
            new LinkedHashSetWrapper<PortChangeEvent>();
    ImmutablePort p1 = ImmutablePort.create("eth1", (short)1);
    ImmutablePort p2 = ImmutablePort.create("eth2", (short)2);
    ImmutablePort p3 = ImmutablePort.create("eth3", (short)3);
    ImmutablePort p4 = ImmutablePort.create("eth4", (short)4);
    ImmutablePort p5 = ImmutablePort.create("eth5", (short)5);
    events.add(new PortChangeEvent(p1, PortChangeType.ADD));
    events.add(new PortChangeEvent(p2, PortChangeType.DELETE));
    events.add(new PortChangeEvent(p3, PortChangeType.UP));
    events.add(new PortChangeEvent(p4, PortChangeType.DOWN));
    events.add(new PortChangeEvent(p5, PortChangeType.OTHER_UPDATE));


    for (OFPortReason reason: OFPortReason.values()) {
        ps.setReason(reason.getReasonCode());

        reset(sw);
        expect(sw.inputThrottled(anyObject(OFMessage.class)))
                .andReturn(false).anyTimes();
        expect(sw.getId()).andReturn(dpid).anyTimes();

        expect(sw.processOFPortStatus(ps)).andReturn(events).once();
        replay(sw);

        reset(controller);
        controller.notifyPortChanged(sw, p1, PortChangeType.ADD);
        controller.notifyPortChanged(sw, p2, PortChangeType.DELETE);
        controller.notifyPortChanged(sw, p3, PortChangeType.UP);
        controller.notifyPortChanged(sw, p4, PortChangeType.DOWN);
        controller.notifyPortChanged(sw, p5, PortChangeType.OTHER_UPDATE);
        sendMessageToHandlerNoControllerReset(
               Collections.<OFMessage>singletonList(ps));
        verify(sw);
        verify(controller);
    }
}
项目:SDN-Traceroute    文件:Traceroute.java   
@Override
public void switchPortChanged(long switchId, ImmutablePort port,
        PortChangeType type) {
    // TODO Auto-generated method stub
    flag=true;color = decideSWColor();setDefaultRules();
}
项目:FloodligtModule    文件:ControllerTest.java   
/**
 * Test that notifyPortChanged() results in an IOFSwitchListener
 * update and that its arguments are passed through to
 * the listener call
 */
@Test
public void testNotifySwitchPoArtChanged() throws Exception {
    long dpid = 42L;

    OFFeaturesReply fr1 = createOFFeaturesReply();
    fr1.setDatapathId(dpid);
    OFPhysicalPort p1 = createOFPhysicalPort("Port1", 1);
    fr1.setPorts(Collections.singletonList(p1));

    OFFeaturesReply fr2 = createOFFeaturesReply();
    fr1.setDatapathId(dpid);
    OFPhysicalPort p2 = createOFPhysicalPort("Port1", 1);
    p2.setAdvertisedFeatures(0x2); // just some bogus values
    fr2.setPorts(Collections.singletonList(p2));

    OFDescriptionStatistics desc = createOFDescriptionStatistics();

    // activate switch
    IOFSwitch sw = doActivateNewSwitch(dpid, desc, fr1);

    // check the store
    SwitchSyncRepresentation ssr = storeClient.getValue(dpid);
    assertNotNull(ssr);
    assertEquals(dpid, ssr.getDpid());
    assertEquals(1, ssr.getPorts().size());
    assertEquals(p1, ssr.getPorts().get(0).toOFPhysicalPort());

    IOFSwitchListener listener = createMock(IOFSwitchListener.class);
    controller.addOFSwitchListener(listener);
    // setup switch with the new, second features reply (and thus ports)
    setupSwitchForAddSwitch(sw, dpid, desc, fr2);
    listener.switchPortChanged(dpid, ImmutablePort.fromOFPhysicalPort(p2),
                               PortChangeType.OTHER_UPDATE);
    expectLastCall().once();
    replay(listener);
    replay(sw);
    controller.notifyPortChanged(sw, ImmutablePort.fromOFPhysicalPort(p2),
                                 PortChangeType.OTHER_UPDATE);
    controller.processUpdateQueueForTesting();
    verify(listener);
    verify(sw);

    // check the store
    ssr = storeClient.getValue(dpid);
    assertNotNull(ssr);
    assertEquals(dpid, ssr.getDpid());
    assertEquals(1, ssr.getPorts().size());
    assertEquals(p2, ssr.getPorts().get(0).toOFPhysicalPort());
}
项目:FloodligtModule    文件:OFChannelHandlerTest.java   
/**
 * Test port status message handling while MASTER
 *
 */
@Test
public void testPortStatusMessageMaster() throws Exception {
    long dpid = featuresReply.getDatapathId();
    testInitialMoveToMasterWithRole();

    OFPhysicalPort p = new OFPhysicalPort();
    p.setName("Port1");
    p.setPortNumber((short)1);
    OFPortStatus ps = (OFPortStatus)
            BasicFactory.getInstance().getMessage(OFType.PORT_STATUS);
    ps.setDesc(p);

    // The events we expect sw.handlePortStatus to return
    // We'll just use the same list for all valid OFPortReasons and add
    // arbitrary events for arbitrary ports that are not necessarily
    // related to the port status message. Our goal
    // here is not to return the correct set of events but the make sure
    // that a) sw.handlePortStatus is called
    //      b) the list of events sw.handlePortStatus returns is sent
    //         as IOFSwitchListener notifications.
    OrderedCollection<PortChangeEvent> events =
            new LinkedHashSetWrapper<PortChangeEvent>();
    ImmutablePort p1 = ImmutablePort.create("eth1", (short)1);
    ImmutablePort p2 = ImmutablePort.create("eth2", (short)2);
    ImmutablePort p3 = ImmutablePort.create("eth3", (short)3);
    ImmutablePort p4 = ImmutablePort.create("eth4", (short)4);
    ImmutablePort p5 = ImmutablePort.create("eth5", (short)5);
    events.add(new PortChangeEvent(p1, PortChangeType.ADD));
    events.add(new PortChangeEvent(p2, PortChangeType.DELETE));
    events.add(new PortChangeEvent(p3, PortChangeType.UP));
    events.add(new PortChangeEvent(p4, PortChangeType.DOWN));
    events.add(new PortChangeEvent(p5, PortChangeType.OTHER_UPDATE));


    for (OFPortReason reason: OFPortReason.values()) {
        ps.setReason(reason.getReasonCode());

        reset(sw);
        expect(sw.inputThrottled(anyObject(OFMessage.class)))
                .andReturn(false).anyTimes();
        expect(sw.getId()).andReturn(dpid).anyTimes();

        expect(sw.processOFPortStatus(ps)).andReturn(events).once();
        replay(sw);

        reset(controller);
        controller.notifyPortChanged(sw, p1, PortChangeType.ADD);
        controller.notifyPortChanged(sw, p2, PortChangeType.DELETE);
        controller.notifyPortChanged(sw, p3, PortChangeType.UP);
        controller.notifyPortChanged(sw, p4, PortChangeType.DOWN);
        controller.notifyPortChanged(sw, p5, PortChangeType.OTHER_UPDATE);
        sendMessageToHandlerNoControllerReset(
               Collections.<OFMessage>singletonList(ps));
        verify(sw);
        verify(controller);
    }
}
项目:multicastSDN    文件:ControllerTest.java   
/**
 * Test that notifyPortChanged() results in an IOFSwitchListener
 * update and that its arguments are passed through to
 * the listener call
 */
@Test
public void testNotifySwitchPoArtChanged() throws Exception {
    long dpid = 42L;

    OFFeaturesReply fr1 = createOFFeaturesReply();
    fr1.setDatapathId(dpid);
    OFPhysicalPort p1 = createOFPhysicalPort("Port1", 1);
    fr1.setPorts(Collections.singletonList(p1));

    OFFeaturesReply fr2 = createOFFeaturesReply();
    fr1.setDatapathId(dpid);
    OFPhysicalPort p2 = createOFPhysicalPort("Port1", 1);
    p2.setAdvertisedFeatures(0x2); // just some bogus values
    fr2.setPorts(Collections.singletonList(p2));

    OFDescriptionStatistics desc = createOFDescriptionStatistics();

    // activate switch
    IOFSwitch sw = doActivateNewSwitch(dpid, desc, fr1);

    // check the store
    SwitchSyncRepresentation ssr = storeClient.getValue(dpid);
    assertNotNull(ssr);
    assertEquals(dpid, ssr.getDpid());
    assertEquals(1, ssr.getPorts().size());
    assertEquals(p1, ssr.getPorts().get(0).toOFPhysicalPort());

    IOFSwitchListener listener = createMock(IOFSwitchListener.class);
    controller.addOFSwitchListener(listener);
    // setup switch with the new, second features reply (and thus ports)
    setupSwitchForAddSwitch(sw, dpid, desc, fr2);
    listener.switchPortChanged(dpid, ImmutablePort.fromOFPhysicalPort(p2),
                               PortChangeType.OTHER_UPDATE);
    expectLastCall().once();
    replay(listener);
    replay(sw);
    controller.notifyPortChanged(sw, ImmutablePort.fromOFPhysicalPort(p2),
                                 PortChangeType.OTHER_UPDATE);
    controller.processUpdateQueueForTesting();
    verify(listener);
    verify(sw);

    // check the store
    ssr = storeClient.getValue(dpid);
    assertNotNull(ssr);
    assertEquals(dpid, ssr.getDpid());
    assertEquals(1, ssr.getPorts().size());
    assertEquals(p2, ssr.getPorts().get(0).toOFPhysicalPort());
}
项目:multicastSDN    文件:OFChannelHandlerTest.java   
/**
 * Test port status message handling while MASTER
 *
 */
@Test
public void testPortStatusMessageMaster() throws Exception {
    long dpid = featuresReply.getDatapathId();
    testInitialMoveToMasterWithRole();

    OFPhysicalPort p = new OFPhysicalPort();
    p.setName("Port1");
    p.setPortNumber((short)1);
    OFPortStatus ps = (OFPortStatus)
            BasicFactory.getInstance().getMessage(OFType.PORT_STATUS);
    ps.setDesc(p);

    // The events we expect sw.handlePortStatus to return
    // We'll just use the same list for all valid OFPortReasons and add
    // arbitrary events for arbitrary ports that are not necessarily
    // related to the port status message. Our goal
    // here is not to return the correct set of events but the make sure
    // that a) sw.handlePortStatus is called
    //      b) the list of events sw.handlePortStatus returns is sent
    //         as IOFSwitchListener notifications.
    OrderedCollection<PortChangeEvent> events =
            new LinkedHashSetWrapper<PortChangeEvent>();
    ImmutablePort p1 = ImmutablePort.create("eth1", (short)1);
    ImmutablePort p2 = ImmutablePort.create("eth2", (short)2);
    ImmutablePort p3 = ImmutablePort.create("eth3", (short)3);
    ImmutablePort p4 = ImmutablePort.create("eth4", (short)4);
    ImmutablePort p5 = ImmutablePort.create("eth5", (short)5);
    events.add(new PortChangeEvent(p1, PortChangeType.ADD));
    events.add(new PortChangeEvent(p2, PortChangeType.DELETE));
    events.add(new PortChangeEvent(p3, PortChangeType.UP));
    events.add(new PortChangeEvent(p4, PortChangeType.DOWN));
    events.add(new PortChangeEvent(p5, PortChangeType.OTHER_UPDATE));


    for (OFPortReason reason: OFPortReason.values()) {
        ps.setReason(reason.getReasonCode());

        reset(sw);
        expect(sw.inputThrottled(anyObject(OFMessage.class)))
                .andReturn(false).anyTimes();
        expect(sw.getId()).andReturn(dpid).anyTimes();

        expect(sw.processOFPortStatus(ps)).andReturn(events).once();
        replay(sw);

        reset(controller);
        controller.notifyPortChanged(sw, p1, PortChangeType.ADD);
        controller.notifyPortChanged(sw, p2, PortChangeType.DELETE);
        controller.notifyPortChanged(sw, p3, PortChangeType.UP);
        controller.notifyPortChanged(sw, p4, PortChangeType.DOWN);
        controller.notifyPortChanged(sw, p5, PortChangeType.OTHER_UPDATE);
        sendMessageToHandlerNoControllerReset(
               Collections.<OFMessage>singletonList(ps));
        verify(sw);
        verify(controller);
    }
}
项目:spring-open    文件:DefaultRules.java   
@Override
public void switchPortChanged(long swId, OFPortDesc port, PortChangeType changeType) {
}
项目:spring-open    文件:LinkDiscoveryManager.java   
@Override
public void switchPortChanged(long swId, OFPortDesc port,
        PortChangeType changeType) {
    // TODO Auto-generated method stub

}
项目:spring-open    文件:FlowProgrammer.java   
@Override
public void switchPortChanged(long swId, OFPortDesc port, PortChangeType pct) {
    // TODO Auto-generated method stub
}
项目:spring-open    文件:Controller.java   
public PortChangeType getPortChangeType() {
    return changeType;
}
项目:spring-open    文件:ControllerTest.java   
@Override
public synchronized void switchPortChanged(long swId, OFPortDesc port,
        PortChangeType changeType) {
    portUpdateCount.add(changeType);
    notifyAll();
}
项目:spring-open    文件:ControllerTest.java   
/**
 * Tests that updates sent into the Controller updates queue are dispatched
 * to the listeners correctly.
 *
 * @throws InterruptedException
 */
@Test
public void testUpdateQueue() throws InterruptedException {
    // No difference between OpenFlow versions here
    OFVersion version = OFVersion.OF_10;
    OFPortDesc port = OFFactories.getFactory(version)
            .buildPortDesc().build();
    long dpid = 1L;

    DummySwitchListener switchListener = new DummySwitchListener();
    IOFSwitch sw = createMockSwitch(dpid, version);
    replay(sw);
    ControllerRunThread t = new ControllerRunThread();
    t.start();

    controller.addOFSwitchListener(switchListener);

    // Switch updates
    doTestUpdateQueueWithUpdate(dpid, SwitchUpdateType.ACTIVATED_MASTER,
            switchListener);
    doTestUpdateQueueWithUpdate(dpid, SwitchUpdateType.ACTIVATED_EQUAL,
            switchListener);
    doTestUpdateQueueWithUpdate(dpid, SwitchUpdateType.EQUAL_TO_MASTER,
            switchListener);
    doTestUpdateQueueWithUpdate(dpid, SwitchUpdateType.MASTER_TO_EQUAL,
            switchListener);
    doTestUpdateQueueWithUpdate(dpid, SwitchUpdateType.DISCONNECTED,
            switchListener);

    // Port updates
    doTestUpdateQueueWithPortUpdate(dpid, port, PortChangeType.ADD,
            switchListener);
    doTestUpdateQueueWithPortUpdate(dpid, port, PortChangeType.OTHER_UPDATE,
            switchListener);
    doTestUpdateQueueWithPortUpdate(dpid, port, PortChangeType.DELETE,
            switchListener);
    doTestUpdateQueueWithPortUpdate(dpid, port, PortChangeType.UP,
            switchListener);
    doTestUpdateQueueWithPortUpdate(dpid, port, PortChangeType.DOWN,
            switchListener);
}
项目:FlowSpaceFirewall    文件:FlowSpaceFirewall.java   
@Override
public void switchPortChanged(long switchId, ImmutablePort port,
        PortChangeType type) {
    //nothing to do here
}
项目:spring-open    文件:IOFSwitchListener.java   
/**
    * Fired when a port on a known switch changes.
    *
    * A user of this notification needs to take care if the port and type
    * information is used directly and if the collection of ports has been
    * queried as well. This notification will only be dispatched after the
    * the port changes have been committed to the IOFSwitch instance. However,
    * if a user has previously called {@link IOFSwitch#getPorts()} or related
    * method a subsequent update might already be present in the information
    * returned by getPorts.
    * @param switchId
    * @param port
    * @param type
    */
public void switchPortChanged(long swId, OFPortDesc port,
        PortChangeType changeType);
项目:spring-open    文件:ControllerTest.java   
/**
 * Gets the number of times a port update event of the specified type
 * has been received.
 *
 * @param type PortChangeType to get the count for
 * @return number of times the event has been received
 */
public int getPortUpdateCount(PortChangeType type) {
    return portUpdateCount.count(type);
}