Package org.openflow.protocol

Examples of org.openflow.protocol.OFPortStatus


     * Test "normal" OFPortStatus handling. No name<->number
     * conflicts or exception testing.
     */
    @Test
    public void testBasicPortStatusOperation() {
        OFPortStatus ps = (OFPortStatus)
                BasicFactory.getInstance().getMessage(OFType.PORT_STATUS);
        List<ImmutablePort> ports = new ArrayList<ImmutablePort>();
        ports.add(p1a);
        ports.add(p2a);


        // Set p1a and p2a as baseline
        PortChangeEvent evP1aAdded =
                new PortChangeEvent(p1a, PortChangeType.ADD);
        PortChangeEvent evP2aAdded =
                new PortChangeEvent(p2a, PortChangeType.ADD);

        Collection<PortChangeEvent> expectedChanges =
                new ArrayList<IOFSwitch.PortChangeEvent>();
        expectedChanges.add(evP1aAdded);
        expectedChanges.add(evP2aAdded);

        Collection<PortChangeEvent> actualChanges = sw.comparePorts(ports);
        assertEquals(0, sw.getPorts().size());
        assertEquals(0, sw.getEnabledPorts().size());
        assertEquals(0, sw.getEnabledPortNumbers().size());
        assertEquals(2, actualChanges.size());
        assertCollectionEqualsNoOrder(expectedChanges, actualChanges);

        actualChanges = sw.setPorts(ports);
        assertEquals(2, actualChanges.size());
        assertCollectionEqualsNoOrder(expectedChanges, actualChanges);

        assertCollectionEqualsNoOrder(ports, sw.getPorts());
        assertTrue("enabled ports should be empty",
                   sw.getEnabledPortNumbers().isEmpty());
        assertTrue("enabled ports should be empty",
                   sw.getEnabledPorts().isEmpty());
        assertEquals(p1a, sw.getPort((short)1));
        assertEquals(p1a, sw.getPort("port1"));
        assertEquals(p1a, sw.getPort("PoRt1")); // case insensitive get

        assertEquals(p2a, sw.getPort((short)2));
        assertEquals(p2a, sw.getPort("port2"));
        assertEquals(p2a, sw.getPort("PoRt2")); // case insensitive get

        //----------------------------------------------------
        // P1a -> p1b. Should receive a port up
        ports.clear();
        ports.add(p2a);
        ports.add(p1b);

        ps.setReason(OFPortReason.OFPPR_MODIFY.getReasonCode());
        ps.setDesc(p1b.toOFPhysicalPort());

        PortChangeEvent evP1bUp = new PortChangeEvent(p1b, PortChangeType.UP);
        actualChanges = sw.processOFPortStatus(ps);
        expectedChanges.clear();
        expectedChanges.add(evP1bUp);
        assertCollectionEqualsNoOrder(expectedChanges, actualChanges);
        assertCollectionEqualsNoOrder(ports, sw.getPorts());
        List<ImmutablePort> enabledPorts = new ArrayList<ImmutablePort>();
        enabledPorts.add(p1b);
        List<Short> enabledPortNumbers = new ArrayList<Short>();
        enabledPortNumbers.add((short)1);
        assertCollectionEqualsNoOrder(enabledPorts, sw.getEnabledPorts());
        assertCollectionEqualsNoOrder(enabledPortNumbers,
                                   sw.getEnabledPortNumbers());
        assertEquals(p1b, sw.getPort((short)1));
        assertEquals(p1b, sw.getPort("port1"));
        assertEquals(p1b, sw.getPort("PoRt1")); // case insensitive get

        assertEquals(p2a, sw.getPort((short)2));
        assertEquals(p2a, sw.getPort("port2"));
        assertEquals(p2a, sw.getPort("PoRt2")); // case insensitive get

        //----------------------------------------------------
        // p2a -> p2b. Should receive a port modify
        ports.clear();
        ports.add(p2b);
        ports.add(p1b);

        PortChangeEvent evP2bModified =
                new PortChangeEvent(p2b, PortChangeType.OTHER_UPDATE);

        ps.setReason(OFPortReason.OFPPR_MODIFY.getReasonCode());
        ps.setDesc(p2b.toOFPhysicalPort());

        actualChanges = sw.processOFPortStatus(ps);
        expectedChanges.clear();
        expectedChanges.add(evP2bModified);
        assertCollectionEqualsNoOrder(expectedChanges, actualChanges);
        assertCollectionEqualsNoOrder(ports, sw.getPorts());
        enabledPorts = new ArrayList<ImmutablePort>();
        enabledPorts.add(p1b);
        enabledPortNumbers = new ArrayList<Short>();
        enabledPortNumbers.add((short)1);
        assertCollectionEqualsNoOrder(enabledPorts, sw.getEnabledPorts());
        assertCollectionEqualsNoOrder(enabledPortNumbers,
                                   sw.getEnabledPortNumbers());
        assertEquals(p1b, sw.getPort((short)1));
        assertEquals(p1b, sw.getPort("port1"));
        assertEquals(p1b, sw.getPort("PoRt1")); // case insensitive get

        assertEquals(p2b, sw.getPort((short)2));
        assertEquals(p2b, sw.getPort("port2"));
        assertEquals(p2b, sw.getPort("PoRt2")); // case insensitive get

        assertEquals(null, sw.getPort((short)3));
        assertEquals(null, sw.getPort("port3"));
        assertEquals(null, sw.getPort("PoRt3")); // case insensitive get


        //----------------------------------------------------
        // p1b -> p1a. Via an OFPPR_ADD, Should receive a port DOWN
        ports.clear();
        ports.add(p2b);
        ports.add(p1a);

        // we use an ADD here. We treat ADD and MODIFY the same way
        ps.setReason(OFPortReason.OFPPR_ADD.getReasonCode());
        ps.setDesc(p1a.toOFPhysicalPort());

        PortChangeEvent evP1aDown =
                new PortChangeEvent(p1a, PortChangeType.DOWN);
        actualChanges = sw.processOFPortStatus(ps);
        expectedChanges.clear();
        expectedChanges.add(evP1aDown);
        assertCollectionEqualsNoOrder(expectedChanges, actualChanges);
        assertCollectionEqualsNoOrder(ports, sw.getPorts());
        enabledPorts.clear();
        enabledPortNumbers.clear();
        assertCollectionEqualsNoOrder(enabledPorts, sw.getEnabledPorts());
        assertCollectionEqualsNoOrder(enabledPortNumbers,
                                   sw.getEnabledPortNumbers());
        assertEquals(p1a, sw.getPort((short)1));
        assertEquals(p1a, sw.getPort("port1"));
        assertEquals(p1a, sw.getPort("PoRt1")); // case insensitive get

        assertEquals(p2b, sw.getPort((short)2));
        assertEquals(p2b, sw.getPort("port2"));
        assertEquals(p2b, sw.getPort("PoRt2")); // case insensitive get


        //----------------------------------------------------
        // p2b -> p2a. Via an OFPPR_ADD, Should receive a port MODIFY
        ports.clear();
        ports.add(p2a);
        ports.add(p1a);

        // we use an ADD here. We treat ADD and MODIFY the same way
        ps.setReason(OFPortReason.OFPPR_ADD.getReasonCode());
        ps.setDesc(p2a.toOFPhysicalPort());

        PortChangeEvent evP2aModify =
                new PortChangeEvent(p2a, PortChangeType.OTHER_UPDATE);
        actualChanges = sw.processOFPortStatus(ps);
        expectedChanges.clear();
        expectedChanges.add(evP2aModify);
        assertCollectionEqualsNoOrder(expectedChanges, actualChanges);
        assertCollectionEqualsNoOrder(ports, sw.getPorts());
        enabledPorts.clear();
        enabledPortNumbers.clear();
        assertCollectionEqualsNoOrder(enabledPorts, sw.getEnabledPorts());
        assertCollectionEqualsNoOrder(enabledPortNumbers,
                                   sw.getEnabledPortNumbers());
        assertEquals(p1a, sw.getPort((short)1));
        assertEquals(p1a, sw.getPort("port1"));
        assertEquals(p1a, sw.getPort("PoRt1")); // case insensitive get

        assertEquals(p2a, sw.getPort((short)2));
        assertEquals(p2a, sw.getPort("port2"));
        assertEquals(p2a, sw.getPort("PoRt2")); // case insensitive get


        //----------------------------------------------------
        // Remove p2a
        ports.clear();
        ports.add(p1a);

        ps.setReason(OFPortReason.OFPPR_DELETE.getReasonCode());
        ps.setDesc(p2a.toOFPhysicalPort());

        PortChangeEvent evP2aDel =
                new PortChangeEvent(p2a, PortChangeType.DELETE);
        actualChanges = sw.processOFPortStatus(ps);
        expectedChanges.clear();
        expectedChanges.add(evP2aDel);
        assertCollectionEqualsNoOrder(expectedChanges, actualChanges);
        assertCollectionEqualsNoOrder(ports, sw.getPorts());
        enabledPorts.clear();
        enabledPortNumbers.clear();
        assertCollectionEqualsNoOrder(enabledPorts, sw.getEnabledPorts());
        assertCollectionEqualsNoOrder(enabledPortNumbers,
                                   sw.getEnabledPortNumbers());
        assertEquals(p1a, sw.getPort((short)1));
        assertEquals(p1a, sw.getPort("port1"));
        assertEquals(p1a, sw.getPort("PoRt1")); // case insensitive get

        assertEquals(null, sw.getPort((short)2));
        assertEquals(null, sw.getPort("port2"));
        assertEquals(null, sw.getPort("PoRt2")); // case insensitive get

        //----------------------------------------------------
        // Remove p2a again. Nothing should happen.
        ports.clear();
        ports.add(p1a);

        ps.setReason(OFPortReason.OFPPR_DELETE.getReasonCode());
        ps.setDesc(p2a.toOFPhysicalPort());

        actualChanges = sw.processOFPortStatus(ps);
        expectedChanges.clear();
        assertCollectionEqualsNoOrder(expectedChanges, actualChanges);
        assertCollectionEqualsNoOrder(ports, sw.getPorts());
        enabledPorts.clear();
        enabledPortNumbers.clear();
        assertCollectionEqualsNoOrder(enabledPorts, sw.getEnabledPorts());
        assertCollectionEqualsNoOrder(enabledPortNumbers,
                                   sw.getEnabledPortNumbers());
        assertEquals(p1a, sw.getPort((short)1));
        assertEquals(p1a, sw.getPort("port1"));
        assertEquals(p1a, sw.getPort("PoRt1")); // case insensitive get

        assertEquals(null, sw.getPort((short)2));
        assertEquals(null, sw.getPort("port2"));
        assertEquals(null, sw.getPort("PoRt2")); // case insensitive get


        //----------------------------------------------------
        // Remove p1a
        ports.clear();

        ps.setReason(OFPortReason.OFPPR_DELETE.getReasonCode());
        ps.setDesc(p1a.toOFPhysicalPort());

        PortChangeEvent evP1aDel =
                new PortChangeEvent(p1a, PortChangeType.DELETE);
        actualChanges = sw.processOFPortStatus(ps);
        expectedChanges.clear();
        expectedChanges.add(evP1aDel);
        assertCollectionEqualsNoOrder(expectedChanges, actualChanges);
        assertCollectionEqualsNoOrder(ports, sw.getPorts());
        enabledPorts.clear();
        enabledPortNumbers.clear();
        assertCollectionEqualsNoOrder(enabledPorts, sw.getEnabledPorts());
        assertCollectionEqualsNoOrder(enabledPortNumbers,
                                   sw.getEnabledPortNumbers());
        assertEquals(null, sw.getPort((short)1));
        assertEquals(null, sw.getPort("port1"));
        assertEquals(null, sw.getPort("PoRt1")); // case insensitive get

        assertEquals(null, sw.getPort((short)2));
        assertEquals(null, sw.getPort("port2"));
        assertEquals(null, sw.getPort("PoRt2")); // case insensitive get


        //----------------------------------------------------
        // Add p3, should receive an add
        ports.clear();
        ports.add(p3);

        PortChangeEvent evP3Add =
                new PortChangeEvent(p3, PortChangeType.ADD);
        expectedChanges.clear();
        expectedChanges.add(evP3Add);

        ps.setReason(OFPortReason.OFPPR_ADD.getReasonCode());
        ps.setDesc(p3.toOFPhysicalPort());

        actualChanges = sw.processOFPortStatus(ps);
        assertCollectionEqualsNoOrder(expectedChanges, actualChanges);
        assertCollectionEqualsNoOrder(ports, sw.getPorts());
        enabledPorts.clear();
        enabledPorts.add(p3);
        enabledPortNumbers.clear();
        enabledPortNumbers.add((short)3);
        assertCollectionEqualsNoOrder(enabledPorts, sw.getEnabledPorts());
        assertCollectionEqualsNoOrder(enabledPortNumbers,
                                   sw.getEnabledPortNumbers());
        assertEquals(null, sw.getPort((short)1));
        assertEquals(null, sw.getPort("port1"));
        assertEquals(null, sw.getPort("PoRt1")); // case insensitive get

        assertEquals(null, sw.getPort((short)2));
        assertEquals(null, sw.getPort("port2"));
        assertEquals(null, sw.getPort("PoRt2")); // case insensitive get

        assertEquals(p3, sw.getPort((short)3));
        assertEquals(p3, sw.getPort("port3"));
        assertEquals(p3, sw.getPort("PoRt3")); // case insensitive get

        //----------------------------------------------------
        // Add p1b, back should receive an add
        ports.clear();
        ports.add(p1b);
        ports.add(p3);

        PortChangeEvent evP1bAdd =
                new PortChangeEvent(p1b, PortChangeType.ADD);
        expectedChanges.clear();
        expectedChanges.add(evP1bAdd);

        // use a modify to add the port
        ps.setReason(OFPortReason.OFPPR_MODIFY.getReasonCode());
        ps.setDesc(p1b.toOFPhysicalPort());

        actualChanges = sw.processOFPortStatus(ps);
        assertCollectionEqualsNoOrder(expectedChanges, actualChanges);
        assertCollectionEqualsNoOrder(ports, sw.getPorts());
        enabledPorts.clear();
        enabledPorts.add(p3);
        enabledPorts.add(p1b);
        enabledPortNumbers.clear();
        enabledPortNumbers.add((short)3);
        enabledPortNumbers.add((short)1);
        assertCollectionEqualsNoOrder(enabledPorts, sw.getEnabledPorts());
        assertCollectionEqualsNoOrder(enabledPortNumbers,
                                   sw.getEnabledPortNumbers());
        assertEquals(p1b, sw.getPort((short)1));
        assertEquals(p1b, sw.getPort("port1"));
        assertEquals(p1b, sw.getPort("PoRt1")); // case insensitive get

        assertEquals(null, sw.getPort((short)2));
        assertEquals(null, sw.getPort("port2"));
        assertEquals(null, sw.getPort("PoRt2")); // case insensitive get

        assertEquals(p3, sw.getPort((short)3));
        assertEquals(p3, sw.getPort("port3"));
        assertEquals(p3, sw.getPort("PoRt3")); // case insensitive get

        //----------------------------------------------------
        // Modify, but nothing really changed
        ports.clear();
        ports.add(p1b);
        ports.add(p3);

        expectedChanges.clear();

        // use a modify to add the port
        ps.setReason(OFPortReason.OFPPR_MODIFY.getReasonCode());
        ps.setDesc(p1b.toOFPhysicalPort());

        actualChanges = sw.processOFPortStatus(ps);
        assertCollectionEqualsNoOrder(expectedChanges, actualChanges);
        assertCollectionEqualsNoOrder(ports, sw.getPorts());
        enabledPorts.clear();
View Full Code Here


    }

    @Test
    public void testPortStatusExceptions() {
        OFPortStatus ps = (OFPortStatus)
                BasicFactory.getInstance().getMessage(OFType.PORT_STATUS);

        try {
            sw.processOFPortStatus(null);
            fail("Expected exception not thrown");
        } catch (NullPointerException e)  { }

        // illegal reason code
        ps.setReason((byte)0x42);
        ps.setDesc(ImmutablePort.create("p1", (short)1).toOFPhysicalPort());
        try {
            sw.processOFPortStatus(ps);
            fail("Expected exception not thrown");
        } catch (IllegalArgumentException e)  { }

        // null port
        ps.setReason(OFPortReason.OFPPR_ADD.getReasonCode());
        ps.setDesc(null);
        try {
            sw.processOFPortStatus(ps);
            fail("Expected exception not thrown");
        } catch (NullPointerException e)  { }
    }
View Full Code Here

        ports.add(portFoo1);
        ports.add(p1a);
        sw.setPorts(ports);
        assertCollectionEqualsNoOrder(ports, sw.getPorts());

        OFPortStatus ps = (OFPortStatus)
                BasicFactory.getInstance().getMessage(OFType.PORT_STATUS);

        // portFoo1 -> portFoo2 via MODIFY : name collision
        ps.setReason(OFPortReason.OFPPR_MODIFY.getReasonCode());
        ps.setDesc(portFoo2.toOFPhysicalPort());
        ports.clear();
        ports.add(portFoo2);
        ports.add(p1a);
        early.clear();
        late.clear();
        anytime.clear();
        actualChanges = sw.processOFPortStatus(ps);
        early.add(portFoo1Del);
        late.add(portFoo2Add);
        assertChangeEvents(early, late, anytime, actualChanges);
        assertCollectionEqualsNoOrder(ports, sw.getPorts());

        // portFoo2 -> portBar2 via ADD number collision
        ps.setReason(OFPortReason.OFPPR_ADD.getReasonCode());
        ps.setDesc(portBar2.toOFPhysicalPort());
        ports.clear();
        ports.add(portBar2);
        ports.add(p1a);
        early.clear();
        late.clear();
        anytime.clear();
        actualChanges = sw.processOFPortStatus(ps);
        early.add(portFoo2Del);
        late.add(portBar2Add);
        assertChangeEvents(early, late, anytime, actualChanges);
        assertCollectionEqualsNoOrder(ports, sw.getPorts());

        // Set to portFoo1, portBar2
        ports.clear();
        ports.add(portFoo1);
        ports.add(portBar2);
        sw.setPorts(ports);
        assertCollectionEqualsNoOrder(ports, sw.getPorts());

        // portFoo1 + portBar2 -> portFoo2: name and number collision
        ps.setReason(OFPortReason.OFPPR_MODIFY.getReasonCode());
        ps.setDesc(portFoo2.toOFPhysicalPort());
        ports.clear();
        ports.add(portFoo2);
        early.clear();
        late.clear();
        anytime.clear();
        actualChanges = sw.processOFPortStatus(ps);
        early.add(portFoo1Del);
        early.add(portBar2Del);
        late.add(portFoo2Add);
        assertChangeEvents(early, late, anytime, actualChanges);
        assertCollectionEqualsNoOrder(ports, sw.getPorts());

        //----------------------
        // Test DELETEs

        // del portFoo1: name exists (portFoo2), but number doesn't.
        ps.setReason(OFPortReason.OFPPR_DELETE.getReasonCode());
        ps.setDesc(portFoo1.toOFPhysicalPort());
        ports.clear();
        early.clear();
        late.clear();
        anytime.clear();
        actualChanges = sw.processOFPortStatus(ps);
        anytime.add(portFoo2Del);
        assertChangeEvents(early, late, anytime, actualChanges);
        assertCollectionEqualsNoOrder(ports, sw.getPorts());

        // Set to portFoo1
        ports.clear();
        ports.add(portFoo1);
        sw.setPorts(ports);
        assertCollectionEqualsNoOrder(ports, sw.getPorts());

        // del portBar1: number exists (portFoo1), but name doesn't.
        ps.setReason(OFPortReason.OFPPR_DELETE.getReasonCode());
        ps.setDesc(portBar1.toOFPhysicalPort());
        ports.clear();
        early.clear();
        late.clear();
        anytime.clear();
        actualChanges = sw.processOFPortStatus(ps);
        anytime.add(portFoo1Del);
        assertChangeEvents(early, late, anytime, actualChanges);
        assertCollectionEqualsNoOrder(ports, sw.getPorts());


        // Set to portFoo1, portBar2
        ports.clear();
        ports.add(portFoo1);
        ports.add(portBar2);
        sw.setPorts(ports);
        assertCollectionEqualsNoOrder(ports, sw.getPorts());

        // del portFoo2: name and number exists
        ps.setReason(OFPortReason.OFPPR_DELETE.getReasonCode());
        ps.setDesc(portFoo2.toOFPhysicalPort());
        ports.clear();
        early.clear();
        late.clear();
        anytime.clear();
        actualChanges = sw.processOFPortStatus(ps);
View Full Code Here

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

      logger.info(
          "controller received a port status message from switch {}",
          HexString.toHexString(sw.getId()));

      OFPortStatus ps = (OFPortStatus) msg;

      logger.info(
          "port {}, with h/w address {} sent a port update message",
          ps.getDesc().getPortNumber(),
          HexString.toHexString(ps.getDesc().getHardwareAddress()));

      logger.info("Status of port is {}",
          (ps.getDesc().getState() % 2 == 0) ? "up" : "down");

      if (OFPortReason.values()[ps.getReason()] == OFPortReason.OFPPR_MODIFY) {

        updateGroupsWithPortStatus(sw, ps.getDesc().getPortNumber(),
            ps.getDesc());

      }

      // update switch as well
View Full Code Here

TOP

Related Classes of org.openflow.protocol.OFPortStatus

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.