Package net.floodlightcontroller.core

Examples of net.floodlightcontroller.core.IOFSwitch


    }

    @Test
    public void testHandleMessagesSlave() throws Exception {
        doSetUp(Role.SLAVE);
        IOFSwitch sw = createMock(IOFSwitch.class);
        expect(sw.getId()).andReturn(0L).anyTimes();
        expect(sw.getStringId()).andReturn("00:00:00:00:00:00:00").anyTimes();

        IOFMessageListener test1 = createMock(IOFMessageListener.class);
        expect(test1.getName()).andReturn("test1").atLeastOnce();
        expect(test1.isCallbackOrderingPrereq((OFType)anyObject(),
                                              (String)anyObject()))
View Full Code Here


    }


    @Test
    public void testHandleMessageWithContext() throws Exception {
        IOFSwitch sw = createMock(IOFSwitch.class);
        expect(sw.getId()).andReturn(0L).anyTimes();
        expect(sw.getStringId()).andReturn("00:00:00:00:00:00:00").anyTimes();

        IOFMessageListener test1 = createMock(IOFMessageListener.class);
        expect(test1.getName()).andReturn("test1").anyTimes();
        expect(test1.isCallbackOrderingPrereq((OFType)anyObject(),
                                              (String)anyObject()))
View Full Code Here

     * @throws Exception
     */
    @Test
    public void testInjectMessage() throws Exception {
        FloodlightContext cntx = new FloodlightContext();
        IOFSwitch sw = createMock(IOFSwitch.class);
        expect(sw.getId()).andReturn(0L).anyTimes();
        expect(sw.getStringId()).andReturn("00:00:00:00:00:00:00").anyTimes();

        // Add listeners
        IOFMessageListener test1 = createMock(IOFMessageListener.class);
        expect(test1.getName()).andReturn("test1").anyTimes();
        setupListenerOrdering(test1);

        IOFMessageListener test2 = createMock(IOFMessageListener.class);
        expect(test2.getName()).andReturn("test2").anyTimes();
        test2.isCallbackOrderingPostreq(OFType.PACKET_IN, "test1");
        expectLastCall().andReturn(true).atLeastOnce();
        setupListenerOrdering(test2);
        replay(test1, test2);
        controller.addOFMessageListener(OFType.PACKET_IN, test1);
        controller.addOFMessageListener(OFType.PACKET_IN, test2);
        verify(test1);
        verify(test2);

        // Test inject with null switch and no message. Should not work.
        reset(test1, test2);
        replay(test1, test2, sw);
        try {
            controller.injectOfMessage(null, pi);
            fail("InjectOfMessage should have thrown a NPE");
        } catch (NullPointerException e) {
            // expected
        }
        try {
            controller.injectOfMessage(null, pi, cntx);
            fail("InjectOfMessage should have thrown a NPE");
        } catch (NullPointerException e) {
            // expected
        }
        try {
            controller.injectOfMessage(sw, null);
            fail("InjectOfMessage should have thrown a NPE");
        } catch (NullPointerException e) {
            // expected
        }
        try {
            controller.injectOfMessage(sw, null, cntx);
            fail("InjectOfMessage should have thrown a NPE");
        } catch (NullPointerException e) {
            // expected
        }
        verify(test1);
        verify(test2);
        verify(sw);

        //
        // Test inject with inActive switch. Should not work.
        reset(test1, test2, sw);
        expect(sw.getId()).andReturn(0L).anyTimes();
        expect(sw.getStringId()).andReturn("00:00:00:00:00:00:00").anyTimes();
        expect(sw.isActive()).andReturn(false).atLeastOnce();
        replay(test1, test2, sw);
        assertFalse("Inject should have failed",
                    controller.injectOfMessage(sw, pi));
        assertFalse("Inject should have failed",
                    controller.injectOfMessage(sw, pi, cntx));
        verify(test1);
        verify(test2);
        verify(sw);


        // Test inject in the "normal" case without context
        reset(test1, test2, sw);
        expect(sw.getId()).andReturn(0L).anyTimes();
        expect(sw.getStringId()).andReturn("00:00:00:00:00:00:00").anyTimes();
        expect(sw.isActive()).andReturn(true).atLeastOnce();
        expect(test2.receive(same(sw), same(pi) , isA(FloodlightContext.class)))
                .andReturn(Command.STOP);
        // test1 will not receive any message!
        replay(test1, test2, sw);
        assertTrue("Inject should have worked",
                    controller.injectOfMessage(sw, pi));
        verify(test1);
        verify(test2);
        verify(sw);

        // Test inject in the "normal" case with context
        reset(test1, test2, sw);
        expect(sw.getId()).andReturn(0L).anyTimes();
        expect(sw.getStringId()).andReturn("00:00:00:00:00:00:00").anyTimes();
        expect(sw.isActive()).andReturn(true).atLeastOnce();
        expect(test2.receive(same(sw), same(pi) , same(cntx)))
                .andReturn(Command.STOP);
        // test1 will not receive any message!
        replay(test1, test2, sw);
        assertTrue("Inject should have worked",
View Full Code Here

     */
    @Test
    public void testHandleOutgoingMessage() throws Exception {
        OFMessage m = BasicFactory.getInstance().getMessage(OFType.ECHO_REQUEST);
        FloodlightContext cntx = new FloodlightContext();
        IOFSwitch sw = createMock(IOFSwitch.class);
        expect(sw.getId()).andReturn(0L).anyTimes();
        expect(sw.getStringId()).andReturn("00:00:00:00:00:00:00").anyTimes();

        // Add listeners
        IOFMessageListener test1 = createMock(IOFMessageListener.class);
        expect(test1.getName()).andReturn("test1").anyTimes();
        setupListenerOrdering(test1);

        IOFMessageListener test2 = createMock(IOFMessageListener.class);
        expect(test2.getName()).andReturn("test2").anyTimes();
        test2.isCallbackOrderingPostreq(OFType.ECHO_REQUEST, "test1");
        expectLastCall().andReturn(true).atLeastOnce();
        setupListenerOrdering(test2);

        IOFMessageListener test3 = createMock(IOFMessageListener.class);
        expect(test3.getName()).andReturn("test3").anyTimes();
        test3.isCallbackOrderingPostreq(OFType.ECHO_REQUEST, "test2");
        expectLastCall().andReturn(true).atLeastOnce();
        setupListenerOrdering(test3);

        // expected ordering is test3, test2, test1

        replay(test1, test2, test3);
        controller.addOFMessageListener(OFType.ECHO_REQUEST, test1);
        controller.addOFMessageListener(OFType.ECHO_REQUEST, test3);
        controller.addOFMessageListener(OFType.ECHO_REQUEST, test2);
        verify(test1);
        verify(test2);
        verify(test3);

        // Test inject with null switch and no message. Should not work.
        reset(test1, test2, test3);
        replay(test1, test2, test3, sw);
        try {
            controller.handleOutgoingMessage(null, pi, cntx);
            fail("handleOutgoindMessage should have thrown a NPE");
        } catch (NullPointerException e) {
            // expected
        }
        try {
            controller.handleOutgoingMessage(sw, null, cntx);
            fail("handleOutgoingMessage should have thrown a NPE");
        } catch (NullPointerException e) {
            // expected
        }
        verify(test1);
        verify(test2);
        verify(test3);
        verify(sw);

        // Test the handleOutgoingMessage
        reset(test1, test2, test3, sw);
        expect(sw.getId()).andReturn(0L).anyTimes();
        expect(sw.getStringId()).andReturn("00:00:00:00:00:00:00").anyTimes();
        expect(test2.receive(same(sw), same(m) , same(cntx)))
                .andReturn(Command.STOP);
        expect(test3.receive(same(sw), same(m) , same(cntx)))
                .andReturn(Command.CONTINUE);
        // test1 will not receive any message!
        replay(test1, test2, test3, sw);
        controller.handleOutgoingMessage(sw, m, cntx);
        verify(test1);
        verify(test2);
        verify(test3);
        verify(sw);

        // Test the handleOutgoingMessage with null context
        reset(test1, test2, test3, sw);
        expect(sw.getId()).andReturn(0L).anyTimes();
        expect(sw.getStringId()).andReturn("00:00:00:00:00:00:00").anyTimes();
        expect(test2.receive(same(sw), same(m) , isA(FloodlightContext.class)))
                .andReturn(Command.STOP);
        expect(test3.receive(same(sw), same(m) , isA(FloodlightContext.class)))
                .andReturn(Command.CONTINUE);
        // test1 will not receive any message!
View Full Code Here

        // Deleting the filter works.
        mfm.setupFilter(sid, null, -1);
        assertTrue(mfm.getNumberOfFilters() == mfm.getMaxFilterSize()-1);

        // Creating mock switch to which we will send packet out and
        IOFSwitch sw = createMock(IOFSwitch.class);
        expect(sw.getId()).andReturn(new Long(0));

        // Mock Packet-in
        IPacket testPacket = new Ethernet()
        .setSourceMACAddress("00:44:33:22:11:00")
        .setDestinationMACAddress("00:11:22:33:44:55")
View Full Code Here

        // We set AlwaysClearFlowsOnSwActivate to false but we still
        // expect a clearAllFlowMods() because the AlwaysClearFlowsOnSwActivate
        // is only relevant if a switch that was previously known is activated!!
        controller.setAlwaysClearFlowsOnSwActivate(false);

        IOFSwitch sw = createMock(IOFSwitch.class);
        setupSwitchForAddSwitch(sw, 0L, null, null);
        sw.clearAllFlowMods();
        expectLastCall().once();

        // strict mock. Order of events matters!
        IOFSwitchListener listener = createStrictMock(IOFSwitchListener.class);
        listener.switchAdded(0L);
View Full Code Here

     * Test switchActivated for a new switch while in slave: a no-op
     */
    @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
View Full Code Here

                                          OFFeaturesReply featuresReply,
                                          boolean clearFlows)
                                          throws Exception {
        controller.setAlwaysClearFlowsOnSwActivate(true);

        IOFSwitch sw = createMock(IOFSwitch.class);
        if (featuresReply == null) {
            featuresReply = createOFFeaturesReply();
            featuresReply.setDatapathId(dpid);
        }
        if (desc == null) {
            desc = createOFDescriptionStatistics();
        }
        setupSwitchForAddSwitch(sw, dpid, desc, featuresReply);
        if (clearFlows) {
            sw.clearAllFlowMods();
            expectLastCall().once();
        }

        replay(sw);
        controller.switchActivated(sw);
View Full Code Here

        //--------------
        // 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);
View Full Code Here

        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);
View Full Code Here

TOP

Related Classes of net.floodlightcontroller.core.IOFSwitch

Copyright © 2018 www.massapicom. 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.