Examples of IOFSwitchListener


Examples of net.floodlightcontroller.core.IOFSwitchListener

        setupSwitchForAddSwitch(sw, 0L, null, null);
        sw.clearAllFlowMods();
        expectLastCall().once();

        // strict mock. Order of events matters!
        IOFSwitchListener listener = createStrictMock(IOFSwitchListener.class);
        listener.switchAdded(0L);
        expectLastCall().once();
        listener.switchActivated(0L);
        expectLastCall().once();
        replay(listener);
        controller.addOFSwitchListener(listener);

        replay(sw);
View Full Code Here

Examples of net.floodlightcontroller.core.IOFSwitchListener

    @Test
    public void testNewSwitchActivatedWhileSlave() throws Exception {
        doSetUp(Role.SLAVE);
        IOFSwitch sw = createMock(IOFSwitch.class);

        IOFSwitchListener listener = createMock(IOFSwitchListener.class);
        controller.addOFSwitchListener(listener);

        replay(sw, listener); // nothing recorded
        controller.switchActivated(sw);
        verify(sw);
View Full Code Here

Examples of net.floodlightcontroller.core.IOFSwitchListener


    /** (remotely) add switch to store and then remove while master. no-op */
    @Test
    public void testAddSwitchToStoreMaster() throws Exception {
        IOFSwitchListener listener = createMock(IOFSwitchListener.class);
        controller.addOFSwitchListener(listener);
        replay(listener);

        //--------------
        // add switch
        doAddSwitchToStore(1L, null, null);
        controller.processUpdateQueueForTesting();
        IOFSwitch sw = controller.getSwitch(1L);
        assertNull("There shouldn't be a switch", sw);
        verify(listener);

        //--------------
        // add a real switch
        controller.setAlwaysClearFlowsOnSwActivate(true);
        sw = createMock(IOFSwitch.class);
        setupSwitchForAddSwitch(sw, 1L, null, null);
        sw.clearAllFlowMods();
        expectLastCall().once();
        reset(listener);
        listener.switchAdded(1L);
        expectLastCall().once();
        listener.switchActivated(1L);
        expectLastCall().once();
        replay(listener);
        replay(sw);
        controller.switchActivated(sw);
        verify(sw);
View Full Code Here

Examples of net.floodlightcontroller.core.IOFSwitchListener

     */
    @Test
    public void testAddSwitchRemoveSwitchStoreSlave() throws Exception {
        doSetUp(Role.SLAVE);

        IOFSwitchListener listener = createMock(IOFSwitchListener.class);
        controller.addOFSwitchListener(listener);

        //------
        // Add switch
        listener.switchAdded(1L);
        expectLastCall().once();
        replay(listener);

        OFDescriptionStatistics desc = createOFDescriptionStatistics();
        desc.setDatapathDescription("The Switch");
        doAddSwitchToStore(1L, desc, null);
        controller.processUpdateQueueForTesting();
        verify(listener);

        IOFSwitch sw = controller.getSwitch(1L);
        assertNotNull("Switch should be present", sw);
        assertEquals(1L, sw.getId());
        assertFalse("Switch should be inactive", sw.isActive());
        assertEquals("The Switch",
                     sw.getDescriptionStatistics().getDatapathDescription());

        //------
        // remove switch
        reset(listener);
        listener.switchRemoved(1L);
        replay(listener);
        doRemoveSwitchFromStore(1L);
        controller.processUpdateQueueForTesting();
        verify(listener);
        assertNull("Switch should not exist anymore", controller.getSwitch(1L));
View Full Code Here

Examples of net.floodlightcontroller.core.IOFSwitchListener

     */
    @Test
    public void testInconsistentStoreDpid() throws Exception {
        doSetUp(Role.SLAVE);

        IOFSwitchListener listener = createMock(IOFSwitchListener.class);
        controller.addOFSwitchListener(listener);
        replay(listener);


        OFFeaturesReply featuresReply = createOFFeaturesReply();
View Full Code Here

Examples of net.floodlightcontroller.core.IOFSwitchListener

        controller.addHAListener(haListener);
        verify(haListener);
        reset(haListener);

        // Add switch listener
        IOFSwitchListener switchListener = createMock(IOFSwitchListener.class);
        controller.addOFSwitchListener(switchListener);

        // Add readyForReconcile listener
        IReadyForReconcileListener readyForReconcileListener =
                createMock(IReadyForReconcileListener.class);
        controller.addReadyForReconcileListener(readyForReconcileListener);

        //---------------------------------------
        // Initialization
        //---------------------------------------

        // Switch 1
        // no actual IOFSwitch here because we simply add features reply
        // and desc stats to store
        OFFeaturesReply fr1a = createOFFeaturesReply();
        fr1a.setDatapathId(1L);
        OFPhysicalPort p = createOFPhysicalPort("P1", 1);
        ImmutablePort sw1p1 = ImmutablePort.fromOFPhysicalPort(p);
        List<OFPhysicalPort> ports1a = Collections.singletonList(p);
        fr1a.setPorts(ports1a);
        List<ImmutablePort> ports1aImmutable =
                ImmutablePort.immutablePortListOf(ports1a);
        // an alternative featuers reply
        OFFeaturesReply fr1b = createOFFeaturesReply();
        fr1b.setDatapathId(1L);
        p = new OFPhysicalPort();
        p = createOFPhysicalPort("P1", 1); // same port as above
        List<OFPhysicalPort> ports1b = new ArrayList<OFPhysicalPort>();
        ports1b.add(p);
        p = createOFPhysicalPort("P2", 42000);
        ImmutablePort sw1p2 = ImmutablePort.fromOFPhysicalPort(p);
        ports1b.add(p);
        fr1b.setPorts(ports1b);
        List<ImmutablePort> ports1bImmutable =
                ImmutablePort.immutablePortListOf(ports1b);

        // Switch 2
        // no actual IOFSwitch here because we simply add features reply
        // and desc stats to store
        OFFeaturesReply fr2a = createOFFeaturesReply();
        fr2a.setDatapathId(2L);
        ImmutablePort sw2p1 = sw1p1;
        List<OFPhysicalPort> ports2a = new ArrayList<OFPhysicalPort>(ports1a);
        fr2a.setPorts(ports2a);
        List<ImmutablePort> ports2aImmutable =
                ImmutablePort.immutablePortListOf(ports2a);
        // an alternative features reply
        OFFeaturesReply fr2b = createOFFeaturesReply();
        fr2b.setDatapathId(2L);
        p = new OFPhysicalPort();
        p = createOFPhysicalPort("P1", 2); // port number changed
        ImmutablePort sw2p1Changed = ImmutablePort.fromOFPhysicalPort(p);
        List<OFPhysicalPort> ports2b = Collections.singletonList(p);
        fr2b.setPorts(ports2b);

        // Switches 3 and 4 are create with default features reply and desc
        // so nothing to do here

        //---------------------------------------
        // Adding switches to store
        //---------------------------------------

        replay(haListener); // nothing should happen to haListener
        replay(readyForReconcileListener); // nothing should happen to
                                           // readyForReconcileListener

        // add switch1 with fr1a to store
        reset(switchListener);
        switchListener.switchAdded(1L);
        expectLastCall().once();
        replay(switchListener);
        doAddSwitchToStore(1L, null, fr1a);
        controller.processUpdateQueueForTesting();
        verify(switchListener);
        reset(switchListener);

        IOFSwitch sw = controller.getSwitch(1L);
        assertNotNull("Switch should be present", sw);
        assertEquals(1L, sw.getId());
        assertFalse("Switch should be inactive", sw.isActive());
        assertEquals(new HashSet<ImmutablePort>(ports1aImmutable),
                     new HashSet<ImmutablePort>(sw.getPorts()));

        // add switch 2 with fr2a to store
        reset(switchListener);
        switchListener.switchAdded(2L);
        expectLastCall().once();
        replay(switchListener);
        doAddSwitchToStore(2L, null, fr2a);
        controller.processUpdateQueueForTesting();
        verify(switchListener);
        reset(switchListener);

        sw = controller.getSwitch(2L);
        assertNotNull("Switch should be present", sw);
        assertEquals(2L, sw.getId());
        assertFalse("Switch should be inactive", sw.isActive());
        assertEquals(new HashSet<ImmutablePort>(ports2aImmutable),
                     new HashSet<ImmutablePort>(sw.getPorts()));

        // add switch 3 to store
        reset(switchListener);
        switchListener.switchAdded(3L);
        expectLastCall().once();
        replay(switchListener);
        doAddSwitchToStore(3L, null, null);
        controller.processUpdateQueueForTesting();
        verify(switchListener);
        reset(switchListener);

        sw = controller.getSwitch(3L);
        assertNotNull("Switch should be present", sw);
        assertEquals(3L, sw.getId());
        assertFalse("Switch should be inactive", sw.isActive());

        // add switch 4 to store
        reset(switchListener);
        switchListener.switchAdded(4L);
        expectLastCall().once();
        replay(switchListener);
        doAddSwitchToStore(4L, null, null);
        controller.processUpdateQueueForTesting();
        verify(switchListener);
        reset(switchListener);

        sw = controller.getSwitch(4L);
        assertNotNull("Switch should be present", sw);
        assertEquals(4L, sw.getId());
        assertFalse("Switch should be inactive", sw.isActive());

        // update switch 1 with fr1b
        reset(switchListener);
        switchListener.switchPortChanged(1L, sw1p2, PortChangeType.ADD);
        expectLastCall().once();
        replay(switchListener);
        doAddSwitchToStore(1L, null, fr1b);
        controller.processUpdateQueueForTesting();
        verify(switchListener);
        reset(switchListener);

        sw = controller.getSwitch(1L);
        assertNotNull("Switch should be present", sw);
        assertEquals(1L, sw.getId());
        assertFalse("Switch should be inactive", sw.isActive());
        assertEquals(new HashSet<ImmutablePort>(ports1bImmutable),
                     new HashSet<ImmutablePort>(sw.getPorts()));

        // Check getAllSwitchDpids() and getAllSwitchMap()
        Set<Long> expectedDpids = new HashSet<Long>();
        expectedDpids.add(1L);
        expectedDpids.add(2L);
        expectedDpids.add(3L);
        expectedDpids.add(4L);
        assertEquals(expectedDpids, controller.getAllSwitchDpids());
        Map<Long, IOFSwitch> expectedSwitchMap = new HashMap<Long, IOFSwitch>();
        expectedSwitchMap.put(1L, controller.getSwitch(1L));
        expectedSwitchMap.put(2L, controller.getSwitch(2L));
        expectedSwitchMap.put(3L, controller.getSwitch(3L));
        expectedSwitchMap.put(4L, controller.getSwitch(4L));
        assertEquals(expectedSwitchMap, controller.getAllSwitchMap());

        verify(haListener);
        //--------------------------------------
        // Transition to master
        //--------------------------------------
        reset(haListener);
        haListener.transitionToMaster();
        expectLastCall().once();
        replay(haListener);
        controller.setConsolidateStoreTaskDelay(consolidateStoreDelayMs);
        controller.setRole(Role.MASTER, "FooBar");
        controller.processUpdateQueueForTesting();
        verify(haListener);
        reset(haListener);
        replay(haListener);

        //--------------------------------------
        // Activate switches
        //--------------------------------------

        // Activate switch 1
        IOFSwitch sw1 = createMock(IOFSwitch.class);
        setupSwitchForAddSwitch(sw1, 1L, null, fr1b);
        reset(switchListener);
        switchListener.switchActivated(1L);
        expectLastCall().once();
        replay(sw1);
        replay(switchListener);
        controller.switchActivated(sw1);
        controller.processUpdateQueueForTesting();
        verify(switchListener);
        verify(sw1);

        sw = controller.getSwitch(1L);
        assertNotNull("Switch should be present", sw);
        assertSame(sw1, sw);   // the mock switch should be returned

        // Activate switch 2 with different features reply
        // should get portChanged
        // also set alwaysClearFlorModOnSwAcitvate to true;
        controller.setAlwaysClearFlowsOnSwActivate(true);
        IOFSwitch sw2 = createMock(IOFSwitch.class);
        setupSwitchForAddSwitch(sw2, 2L, null, fr2b);
        sw2.clearAllFlowMods();
        expectLastCall().once();
        reset(switchListener);
        switchListener.switchActivated(2L);
        expectLastCall().once();
        switchListener.switchPortChanged(2L, sw2p1, PortChangeType.DELETE);
        switchListener.switchPortChanged(2L, sw2p1Changed, PortChangeType.ADD);
        expectLastCall().once();
        replay(sw2);
        replay(switchListener);
        controller.switchActivated(sw2);
        controller.processUpdateQueueForTesting();
        verify(switchListener);
        verify(sw2);

        sw = controller.getSwitch(2L);
        assertNotNull("Switch should be present", sw);
        assertSame(sw2, sw); // the mock switch should be returned


        // Do not activate switch 3, but it should still be present
        sw = controller.getSwitch(3L);
        IOFSwitch sw3 = sw;
        assertNotNull("Switch should be present", sw);
        assertEquals(3L, sw.getId());
        assertFalse("Switch should be inactive", sw.isActive());

        // Do not activate switch 4, but it should still be present
        sw = controller.getSwitch(4L);
        IOFSwitch sw4 = sw;
        assertNotNull("Switch should be present", sw);
        assertEquals(4L, sw.getId());
        assertFalse("Switch should be inactive", sw.isActive());

        // Check getAllSwitchDpids() and getAllSwitchMap()
        expectedDpids = new HashSet<Long>();
        expectedDpids.add(1L);
        expectedDpids.add(2L);
        expectedDpids.add(3L);
        expectedDpids.add(4L);
        assertEquals(expectedDpids, controller.getAllSwitchDpids());
        expectedSwitchMap = new HashMap<Long, IOFSwitch>();
        expectedSwitchMap.put(1L, sw1);
        expectedSwitchMap.put(2L, sw2);
        expectedSwitchMap.put(3L, sw3);
        expectedSwitchMap.put(4L, sw4);
        assertEquals(expectedSwitchMap, controller.getAllSwitchMap());

        // silently remove switch 4 from the store and notify the
        // store listener. Since the controller is MASTER it will ignore
        // this notification.
        reset(switchListener);
        replay(switchListener);
        doRemoveSwitchFromStore(4L);
        controller.processUpdateQueueForTesting();
        verify(switchListener);
        // Switch should still be queryable
        sw = controller.getSwitch(4L);
        assertNotNull("Switch should be present", sw);
        assertEquals(4L, sw.getId());
        assertFalse("Switch should be inactive", sw.isActive());

        //--------------------------------
        // Wait for consolidateStore
        //--------------------------------
        verify(readyForReconcileListener);
        reset(readyForReconcileListener);
        readyForReconcileListener.readyForReconcile();
        replay(readyForReconcileListener);
        reset(switchListener);
        switchListener.switchRemoved(3L);
        switchListener.switchRemoved(4L);
        replay(switchListener);
        Thread.sleep(2*consolidateStoreDelayMs);
        controller.processUpdateQueueForTesting();
        verify(switchListener);
        verify(readyForReconcileListener);
View Full Code Here

Examples of net.floodlightcontroller.core.IOFSwitchListener

        controller.addHAListener(haListener);
        verify(haListener);
        reset(haListener);

        // Add switch listener
        IOFSwitchListener switchListener = createMock(IOFSwitchListener.class);
        controller.addOFSwitchListener(switchListener);

        // Add readyForReconcile listener
        IReadyForReconcileListener readyForReconcileListener =
                createMock(IReadyForReconcileListener.class);
        controller.addReadyForReconcileListener(readyForReconcileListener);

        //---------------------------------------
        // Adding switches to store
        //---------------------------------------

        replay(haListener); // nothing should happen to haListener
        replay(readyForReconcileListener); // nothing should happen to
                                           // readyForReconcileListener

        // add switch 1 to store
        reset(switchListener);
        switchListener.switchAdded(1L);
        expectLastCall().once();
        replay(switchListener);
        doAddSwitchToStore(1L, null, null);
        controller.processUpdateQueueForTesting();
        verify(switchListener);
        reset(switchListener);

        IOFSwitch sw = controller.getSwitch(1L);
        assertNotNull("Switch should be present", sw);
        assertEquals(1L, sw.getId());
        assertFalse("Switch should be inactive", sw.isActive());

        // add switch 2 to store
        reset(switchListener);
        switchListener.switchAdded(2L);
        expectLastCall().once();
        replay(switchListener);
        doAddSwitchToStore(2L, null, null);
        controller.processUpdateQueueForTesting();
        verify(switchListener);
        reset(switchListener);

        sw = controller.getSwitch(2L);
        assertNotNull("Switch should be present", sw);
        assertEquals(2L, sw.getId());
        assertFalse("Switch should be inactive", sw.isActive());

        // Check getAllSwitchDpids() and getAllSwitchMap()
        Set<Long> expectedDpids = new HashSet<Long>();
        expectedDpids.add(1L);
        expectedDpids.add(2L);
        assertEquals(expectedDpids, controller.getAllSwitchDpids());
        Map<Long, IOFSwitch> expectedSwitchMap = new HashMap<Long, IOFSwitch>();
        expectedSwitchMap.put(1L, controller.getSwitch(1L));
        expectedSwitchMap.put(2L, controller.getSwitch(2L));
        assertEquals(expectedSwitchMap, controller.getAllSwitchMap());

        verify(haListener);
        //--------------------------------------
        // Transition to master
        //--------------------------------------
        reset(haListener);
        haListener.transitionToMaster();
        expectLastCall().once();
        replay(haListener);
        controller.setConsolidateStoreTaskDelay(consolidateStoreDelayMs);
        controller.setRole(Role.MASTER, "FooBar");
        controller.processUpdateQueueForTesting();
        verify(haListener);
        reset(haListener);
        replay(haListener);

        //--------------------------------------
        // Activate switches
        //--------------------------------------

        // Activate switch 1
        IOFSwitch sw1 = createMock(IOFSwitch.class);
        setupSwitchForAddSwitch(sw1, 1L, null, null);
        reset(switchListener);
        switchListener.switchActivated(1L);
        expectLastCall().once();
        replay(sw1);
        replay(switchListener);
        controller.switchActivated(sw1);
        controller.processUpdateQueueForTesting();
        verify(switchListener);
        verify(sw1);

        sw = controller.getSwitch(1L);
        assertNotNull("Switch should be present", sw);
        assertSame(sw1, sw);   // the mock switch should be returned

        // Activate switch 2
        // Since this is the last inactive switch to activate we should
        // get the readyForReconcile notifiction
        verify(readyForReconcileListener);
        reset(readyForReconcileListener);
        readyForReconcileListener.readyForReconcile();
        replay(readyForReconcileListener);
        controller.setAlwaysClearFlowsOnSwActivate(true);
        IOFSwitch sw2 = createMock(IOFSwitch.class);
        setupSwitchForAddSwitch(sw2, 2L, null, null);
        sw2.clearAllFlowMods();
        expectLastCall().once();
        reset(switchListener);
        switchListener.switchActivated(2L);
        expectLastCall().once();
        replay(sw2);
        replay(switchListener);
        controller.switchActivated(sw2);
        controller.processUpdateQueueForTesting();
View Full Code Here

Examples of net.floodlightcontroller.core.IOFSwitchListener

        IOFSwitch sw = doActivateNewSwitch(1L, null, null);
        expect(sw.getId()).andReturn(1L).anyTimes();
        expect(sw.getStringId()).andReturn(HexString.toHexString(1L)).anyTimes();
        sw.cancelAllStatisticsReplies();
        expectLastCall().once();
        IOFSwitchListener listener = createMock(IOFSwitchListener.class);
        listener.switchRemoved(1L);
        expectLastCall().once();
        controller.addOFSwitchListener(listener);
        replay(sw, listener);
        controller.switchDisconnected(sw);
        controller.processUpdateQueueForTesting();
View Full Code Here

Examples of net.floodlightcontroller.core.IOFSwitchListener

    @Test
    public void testNonexistingSwitchDisconnected() throws Exception {
        IOFSwitch sw = createMock(IOFSwitch.class);
        expect(sw.getId()).andReturn(1L).anyTimes();
        expect(sw.getStringId()).andReturn(HexString.toHexString(1L)).anyTimes();
        IOFSwitchListener listener = createMock(IOFSwitchListener.class);
        controller.addOFSwitchListener(listener);
        replay(sw, listener);
        controller.switchDisconnected(sw);
        controller.processUpdateQueueForTesting();
        verify(sw, listener);
View Full Code Here

Examples of net.floodlightcontroller.core.IOFSwitchListener

        IOFSwitch origSw = doActivateNewSwitch(1L, null, null);
        // create a new mock switch
        IOFSwitch sw = createMock(IOFSwitch.class);
        expect(sw.getId()).andReturn(1L).anyTimes();
        expect(sw.getStringId()).andReturn(HexString.toHexString(1L)).anyTimes();
        IOFSwitchListener listener = createMock(IOFSwitchListener.class);
        controller.addOFSwitchListener(listener);
        replay(sw, listener);
        controller.switchDisconnected(sw);
        controller.processUpdateQueueForTesting();
        verify(sw, listener);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.