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

项目:QoS-floodlight    文件:OFChannelHandler.java   
/**
 * Handle a port status message.
 *
 * Handle a port status message by updating the port maps in the
 * IOFSwitch instance and notifying Controller about the change so
 * it can dispatch a switch update.
 *
 * @param h The OFChannelHhandler that received the message
 * @param m The PortStatus message we received
 * @param doNotify if true switch port changed events will be
 * dispatched
 */
protected void handlePortStatusMessage(OFChannelHandler h,
                                       OFPortStatus m,
                                       boolean doNotify) {
    if (h.sw == null) {
        String msg = getSwitchStateMessage(h, m,
                "State machine error: switch is null. Should never " +
                "happen");
        throw new SwitchStateException(msg);
    }
    Collection<PortChangeEvent> changes = h.sw.processOFPortStatus(m);
    if (doNotify) {
        for (PortChangeEvent ev: changes)
            h.controller.notifyPortChanged(h.sw, ev.port, ev.type);
    }
}
项目:floodlight_with_topoguard    文件:OFChannelHandler.java   
/**
 * Handle a port status message.
 *
 * Handle a port status message by updating the port maps in the
 * IOFSwitch instance and notifying Controller about the change so
 * it can dispatch a switch update.
 *
 * @param h The OFChannelHhandler that received the message
 * @param m The PortStatus message we received
 * @param doNotify if true switch port changed events will be
 * dispatched
 */
protected void handlePortStatusMessage(OFChannelHandler h,
                                       OFPortStatus m,
                                       boolean doNotify) {
    if (h.sw == null) {
        String msg = getSwitchStateMessage(h, m,
                "State machine error: switch is null. Should never " +
                "happen");
        throw new SwitchStateException(msg);
    }
    Collection<PortChangeEvent> changes = h.sw.processOFPortStatus(m);
    if (doNotify) {
        for (PortChangeEvent ev: changes)
            h.controller.notifyPortChanged(h.sw, ev.port, ev.type);
    }
}
项目:FloodligtModule    文件:OFChannelHandler.java   
/**
 * Handle a port status message.
 *
 * Handle a port status message by updating the port maps in the
 * IOFSwitch instance and notifying Controller about the change so
 * it can dispatch a switch update.
 *
 * @param h The OFChannelHhandler that received the message
 * @param m The PortStatus message we received
 * @param doNotify if true switch port changed events will be
 * dispatched
 */
protected void handlePortStatusMessage(OFChannelHandler h,
                                       OFPortStatus m,
                                       boolean doNotify) {
    if (h.sw == null) {
        String msg = getSwitchStateMessage(h, m,
                "State machine error: switch is null. Should never " +
                "happen");
        throw new SwitchStateException(msg);
    }
    Collection<PortChangeEvent> changes = h.sw.processOFPortStatus(m);
    if (doNotify) {
        for (PortChangeEvent ev: changes)
            h.controller.notifyPortChanged(h.sw, ev.port, ev.type);
    }
}
项目:multicastSDN    文件:OFChannelHandler.java   
/**
 * Handle a port status message.
 *
 * Handle a port status message by updating the port maps in the
 * IOFSwitch instance and notifying Controller about the change so
 * it can dispatch a switch update.
 *
 * @param h The OFChannelHhandler that received the message
 * @param m The PortStatus message we received
 * @param doNotify if true switch port changed events will be
 * dispatched
 */
protected void handlePortStatusMessage(OFChannelHandler h,
                                       OFPortStatus m,
                                       boolean doNotify) {
    if (h.sw == null) {
        String msg = getSwitchStateMessage(h, m,
                "State machine error: switch is null. Should never " +
                "happen");
        throw new SwitchStateException(msg);
    }
    Collection<PortChangeEvent> changes = h.sw.processOFPortStatus(m);
    if (doNotify) {
        for (PortChangeEvent ev: changes)
            h.controller.notifyPortChanged(h.sw, ev.port, ev.type);
    }
}
项目:spring-open    文件:OFChannelHandler.java   
/**
 * Handle a port status message.
 *
 * Handle a port status message by updating the port maps in the
 * IOFSwitch instance and notifying Controller about the change so it
 * can dispatch a switch update.
 *
 * @param h The OFChannelHhandler that received the message
 * @param m The PortStatus message we received
 * @param doNotify if true switch port changed events will be dispatched
 * @throws SwitchStateException
 *
 */
protected void handlePortStatusMessage(OFChannelHandler h, OFPortStatus m,
        boolean doNotify) throws SwitchStateException {
    if (h.sw == null) {
        String msg = getSwitchStateMessage(h, m,
                "State machine error: switch is null. Should never " +
                        "happen");
        throw new SwitchStateException(msg);
    }

    Collection<PortChangeEvent> changes = h.sw.processOFPortStatus(m);
    if (doNotify) {
        for (PortChangeEvent ev : changes)
            h.controller.notifyPortChanged(h.sw.getId(), ev.port, ev.type);
    }
}
项目:QoS-floodlight    文件:Controller.java   
/**
 * Check if the two switches differ in their ports or in other
 * fields and if they differ enqueue a switch update
 * @param oldSw
 * @param newSw
 */
private synchronized void
        sendNotificationsIfSwitchDiffers(IOFSwitch oldSw,
                                         IOFSwitch newSw) {
    Collection<PortChangeEvent> portDiffs =
            oldSw.comparePorts(newSw.getPorts());
    for (PortChangeEvent ev: portDiffs) {
        SwitchUpdate update =
                new SwitchUpdate(newSw.getId(),
                                 SwitchUpdateType.PORTCHANGED,
                                 ev.port, ev.type);
        addUpdateToQueue(update);
    }
}
项目:floodlight_with_topoguard    文件:Controller.java   
/**
 * Check if the two switches differ in their ports or in other
 * fields and if they differ enqueue a switch update
 * @param oldSw
 * @param newSw
 */
private synchronized void
        sendNotificationsIfSwitchDiffers(IOFSwitch oldSw,
                                         IOFSwitch newSw) {
    Collection<PortChangeEvent> portDiffs =
            oldSw.comparePorts(newSw.getPorts());
    for (PortChangeEvent ev: portDiffs) {
        SwitchUpdate update =
                new SwitchUpdate(newSw.getId(),
                                 SwitchUpdateType.PORTCHANGED,
                                 ev.port, ev.type);
        addUpdateToQueue(update);
    }
}
项目:FloodligtModule    文件:Controller.java   
/**
 * Check if the two switches differ in their ports or in other
 * fields and if they differ enqueue a switch update
 * @param oldSw
 * @param newSw
 */
private synchronized void
        sendNotificationsIfSwitchDiffers(IOFSwitch oldSw,
                                         IOFSwitch newSw) {
    Collection<PortChangeEvent> portDiffs =
            oldSw.comparePorts(newSw.getPorts());
    for (PortChangeEvent ev: portDiffs) {
        SwitchUpdate update =
                new SwitchUpdate(newSw.getId(),
                                 SwitchUpdateType.PORTCHANGED,
                                 ev.port, ev.type);
        addUpdateToQueue(update);
    }
}
项目:multicastSDN    文件:Controller.java   
/**
 * Check if the two switches differ in their ports or in other
 * fields and if they differ enqueue a switch update
 * @param oldSw
 * @param newSw
 */
private synchronized void
        sendNotificationsIfSwitchDiffers(IOFSwitch oldSw,
                                         IOFSwitch newSw) {
    Collection<PortChangeEvent> portDiffs =
            oldSw.comparePorts(newSw.getPorts());
    for (PortChangeEvent ev: portDiffs) {
        SwitchUpdate update =
                new SwitchUpdate(newSw.getId(),
                                 SwitchUpdateType.PORTCHANGED,
                                 ev.port, ev.type);
        addUpdateToQueue(update);
    }
}
项目: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    文件: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);
    }
}
项目: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    文件: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);
    }
}