Package net.floodlightcontroller.devicemanager

Examples of net.floodlightcontroller.devicemanager.IDevice


        Entity entity2 = new Entity(1L, null, null, 1L, (int)OFPort.OFPP_LOCAL.getValue(), c.getTime());
        c.add(Calendar.MILLISECOND,
              (int)AttachmentPoint.OPENFLOW_TO_EXTERNAL_TIMEOUT + 1);
        Entity entity3 = new Entity(1L, null, null, 1L, 2, c.getTime());

        IDevice d;
        SwitchPort[] aps;

        d = deviceManager.learnDeviceByEntity(entity1);
        assertEquals(1, deviceManager.getAllDevices().size());
        aps = d.getAttachmentPoints();
        assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1) }, aps);

        // Ensure that the attachment point changes to OFPP_LOCAL
        d = deviceManager.learnDeviceByEntity(entity2);
        assertEquals(1, deviceManager.getAllDevices().size());
        aps = d.getAttachmentPoints();
        assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, OFPort.OFPP_LOCAL.getValue()) }, aps);

        // Even though the new attachment point is consistent with old
        // and the time has elapsed, OFPP_LOCAL attachment point should
        // be maintained.
        d = deviceManager.learnDeviceByEntity(entity3);
        assertEquals(1, deviceManager.getAllDevices().size());
        aps = d.getAttachmentPoints();
        assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, OFPort.OFPP_LOCAL.getValue()) }, aps);
    }
View Full Code Here


        Device rdevice = (Device)
                deviceManager.findDevice(Ethernet.toLong(deviceMac),
                        (short)5, null, null, null);
        verifyDevice(rdevice, Ethernet.toLong(deviceMac),
                     (short)5, ipaddr, 1L, 1);
        IDevice cntxSrcDev = IDeviceService.fcStore.get(cntx,
                IDeviceService.CONTEXT_SRC_DEVICE);
        assertEquals(rdevice, cntxSrcDev);
        IDevice cntxDstDev = IDeviceService.fcStore.get(cntx,
                IDeviceService.CONTEXT_DST_DEVICE);
        assertNull(cntxDstDev);

        Device result = null;
        Iterator<? extends IDevice> dstiter =
                deviceManager.queryDevices(null, null, ipaddr,
                        null, null);
        if (dstiter.hasNext()) {
            result = (Device)dstiter.next();
        }
        assertFalse("There shouldn't be more than 1 device", dstiter.hasNext());
        assertEquals(rdevice, result);


        //-----------------
        // Test packetIn again with a different source port. Should be
        // the same device
        reset(mockTopology);
        mockTopologyForPacketInTests(mockTopology);
        replay(mockTopology);

        // trigger the packet in
        cntx = new FloodlightContext();
        packetIn.setInPort((short)2);
        cmd = dispatchPacketIn(5L, packetIn, cntx);
        verify(mockTopology);
        // Verify the replay matched our expectations
        assertEquals(Command.CONTINUE, cmd);

        // Verify the device
        rdevice = (Device)
                deviceManager.findDevice(Ethernet.toLong(deviceMac),
                        (short)5, null, null, null);
        verifyDevice(rdevice, Ethernet.toLong(deviceMac),
                     (short)5, ipaddr, 5L, 2);
        cntxSrcDev = IDeviceService.fcStore.get(cntx,
                IDeviceService.CONTEXT_SRC_DEVICE);
        assertEquals(rdevice, cntxSrcDev);
        cntxDstDev = IDeviceService.fcStore.get(cntx,
                IDeviceService.CONTEXT_DST_DEVICE);
        assertNull(cntxDstDev);
        // There can be only one device
        assertEquals(1, deviceManager.getAllDevices().size());

        //----------------------------
        // Test packetIn with a different packet going the reverse direction.
        // We should now get source and dest device in the context
        //==> The destination device in this step has been learned just before
        long srcMac = Ethernet.toLong(testUDPPacket.getSourceMACAddress());
        long dstMac = Ethernet.toLong(deviceMac);
        reset(mockTopology);
        mockTopologyForPacketInTests(mockTopology);
        replay(mockTopology);
        // trigger the packet in
        cntx = new FloodlightContext();
        cmd = dispatchPacketIn(1L, testUDPPacketIn, cntx);
        verify(mockTopology);

        assertEquals(Command.CONTINUE, cmd);
        IDevice srcDev =
                deviceManager.findDevice(srcMac, (short)5, null, null, null);
        verifyDevice(srcDev, srcMac, (short)5, null,
                     1L, testUDPPacketIn.getInPort());

        IDevice dstDev =
                deviceManager.findDevice(dstMac, (short)5, null, null, null);
        verifyDevice(dstDev, dstMac, (short)5, ipaddr, 5L, 2);

        cntxSrcDev = IDeviceService.fcStore.get(cntx,
                IDeviceService.CONTEXT_SRC_DEVICE);
View Full Code Here

        // must NOT learn IP on this device
        verifyDevice(srcDev, sourceMac, (short)5, null, 1L, 1);
        assertFalse("Device must differ", srcDev.equals(senderDev));
        // Context is annotated with this device, not the device associated
        // with ARP sender address
        IDevice cntxSrcDev = IDeviceService.fcStore.get(cntx,
                IDeviceService.CONTEXT_SRC_DEVICE);
        assertEquals(srcDev, cntxSrcDev);

        assertEquals(2, deviceManager.getAllDevices().size());
    }
View Full Code Here

        testUDPPacket.setSourceMACAddress(Ethernet.toByteArray(0L));
        updateUDPPacketIn();
        Command cmd = dispatchPacketIn(1L, testUDPPacketIn, cntx);
        assertEquals(Command.STOP, cmd);
        IDevice cntxSrcDev = IDeviceService.fcStore.get(cntx,
                IDeviceService.CONTEXT_SRC_DEVICE);
        assertNull(cntxSrcDev);
        IDevice cntxDstDev = IDeviceService.fcStore.get(cntx,
                IDeviceService.CONTEXT_DST_DEVICE);
        assertNull(cntxDstDev);

        testUDPPacket.setSourceMACAddress(Ethernet.toByteArray(-1L));
        updateUDPPacketIn();
View Full Code Here

        long dstMac = Ethernet.toLong(testUDPPacket.getDestinationMACAddress());

        // Prime device manager with the source device
        Command cmd = dispatchPacketIn(1L, testUDPPacketIn, cntx);
        assertEquals(Command.CONTINUE, cmd);
        IDevice cntxSrcDev = IDeviceService.fcStore.get(cntx,
                IDeviceService.CONTEXT_SRC_DEVICE);
        verifyDevice(cntxSrcDev, srcMac, (short)5, null,
                     1L, testUDPPacketIn.getInPort());
        IDevice cntxDstDev = IDeviceService.fcStore.get(cntx,
                IDeviceService.CONTEXT_DST_DEVICE);
        assertNull(cntxDstDev);
        IDevice expectedSrcDev = cntxSrcDev;

        // Create a device for the destination. We can use testARPPacketIn_1
        // for that.
        cntx = new FloodlightContext();
        // Prime device manager with the source device
        cmd = dispatchPacketIn(1L, testARPReplyPacketIn_1, cntx);
        assertEquals(Command.CONTINUE, cmd);
        cntxSrcDev = IDeviceService.fcStore.get(cntx,
                IDeviceService.CONTEXT_SRC_DEVICE);
        // yes: we check that cntxSrcDev matched dstMAC because we are
        // just adding the dest device
        int ip = IPv4.toIPv4Address("192.168.1.1");
        verifyDevice(cntxSrcDev, dstMac, (short)5, ip,
                     1L, testARPReplyPacketIn_1.getInPort());
        // yes: we set the expected dst device to the current srcDev
        IDevice expectedDstDev = cntxSrcDev;

        //-------------------------------
        // Let the real tests begin

        cntx = new FloodlightContext();
View Full Code Here

        Entity entity1 = new Entity(1L, null, 2, 1L, 1, c.getTime());
        c.add(Calendar.MILLISECOND, -DeviceManagerImpl.ENTITY_TIMEOUT-1);
        Entity entity2 = new Entity(1L, null, 1, 5L, 1, c.getTime());

        deviceManager.learnDeviceByEntity(entity1);
        IDevice d = deviceManager.learnDeviceByEntity(entity2);
        assertArrayEquals(new Integer[] { 1, 2 }, d.getIPv4Addresses());
        assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1),
                                             new SwitchPort(5L, 1)},
                                             d.getAttachmentPoints());
        Iterator<? extends IDevice> diter =
                deviceManager.queryClassDevices(d.getEntityClass(),
                                                null, null, 1, null, null);
        assertTrue(diter.hasNext());
        assertEquals(d.getDeviceKey(), diter.next().getDeviceKey());
        diter = deviceManager.queryClassDevices(d.getEntityClass(),
                                                null, null, 2, null, null);
        assertTrue(diter.hasNext());
        assertEquals(d.getDeviceKey(), diter.next().getDeviceKey());

        replay(mockListener);
        deviceManager.addListener(mockListener);
        verify(mockListener);
        reset(mockListener);

        mockListener.deviceIPV4AddrChanged(isA(IDevice.class));
        replay(mockListener);
        deviceManager.entityCleanupTask.reschedule(0, null);

        d = deviceManager.getDevice(d.getDeviceKey());
        assertArrayEquals(new Integer[] { 2 }, d.getIPv4Addresses());

        // Attachment points are not removed, previous ones are still valid.
        assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1),
                                             new SwitchPort(5L, 1) },
                          d.getAttachmentPoints());
        diter = deviceManager.queryClassDevices(d.getEntityClass(),
                                                null, null, 2, null, null);
        assertTrue(diter.hasNext());
        assertEquals(d.getDeviceKey(), diter.next().getDeviceKey());
        diter = deviceManager.queryClassDevices(d.getEntityClass(),
                                                null, null, 1, null, null);
        assertFalse(diter.hasNext());

        d = deviceManager.findDevice(1L, null, null, null, null);
        assertArrayEquals(new Integer[] { 2 }, d.getIPv4Addresses());

        // Attachment points are not removed, previous ones are still valid.
        assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1),
                                             new SwitchPort(5L, 1) },
                          d.getAttachmentPoints());

        verify(mockListener);
    }
View Full Code Here

        expect(mockTopology.isBroadcastDomainPort(EasyMock.anyLong(),
                                                  EasyMock.anyShort())).
                                                  andReturn(false).anyTimes();
        replay(mockTopology);

        IDevice d = deviceManager.learnDeviceByEntity(entity2);
        d = deviceManager.learnDeviceByEntity(entity1);
        assertArrayEquals(new Integer[] { 1, 2 }, d.getIPv4Addresses());

        replay(mockListener);
        deviceManager.addListener(mockListener);
        verify(mockListener);
        reset(mockListener);

        mockListener.deviceRemoved(isA(IDevice.class));
        replay(mockListener);
        deviceManager.entityCleanupTask.reschedule(0, null);

        IDevice r = deviceManager.getDevice(d.getDeviceKey());
        assertNull(r);
        Iterator<? extends IDevice> diter =
                deviceManager.queryClassDevices(d.getEntityClass(),
                                                null, null, 1, null, null);
        assertFalse(diter.hasNext());
View Full Code Here

        c.add(Calendar.MILLISECOND, 1);
        entity3.setLastSeenTimestamp(c.getTime());



        IDevice d;
        d = deviceManager.learnDeviceByEntity(entity1);
        d = deviceManager.learnDeviceByEntity(entity1a);
        d = deviceManager.learnDeviceByEntity(entity2);
        d = deviceManager.learnDeviceByEntity(entity3);

        // all entities are active, so entity3 should win
        assertArrayEquals(new SwitchPort[] { new SwitchPort(10L, 1) },
                          d.getAttachmentPoints());

        assertArrayEquals(new SwitchPort[] { new SwitchPort(10L, 1),},
                              d.getAttachmentPoints(true));

        c.add(Calendar.MILLISECOND, Entity.ACTIVITY_TIMEOUT/4);
        entity1.setLastSeenTimestamp(c.getTime());
        d = deviceManager.learnDeviceByEntity(entity1);

        // all are still active; entity3 should still win
        assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1) },
                          d.getAttachmentPoints());
        assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1),
                                             new SwitchPort(5L, 1,
                                                            ErrorStatus.DUPLICATE_DEVICE),
                                                            new SwitchPort(10L, 1,
                                                                           ErrorStatus.DUPLICATE_DEVICE) },
                                                                           d.getAttachmentPoints(true));

        c.add(Calendar.MILLISECOND, Entity.ACTIVITY_TIMEOUT+2000);
        entity1.setLastSeenTimestamp(c.getTime());
        d = deviceManager.learnDeviceByEntity(entity1);

        assertEquals(entity1.getActiveSince(), entity1.getLastSeenTimestamp());
        // entity1 should now be the only active entity
        assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1) },
                          d.getAttachmentPoints());
        assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1) },
                          d.getAttachmentPoints(true));
    }
View Full Code Here

        entity4.setLastSeenTimestamp(c.getTime());

        deviceManager.learnDeviceByEntity(entity1);
        deviceManager.learnDeviceByEntity(entity2);
        deviceManager.learnDeviceByEntity(entity3);
        IDevice d = deviceManager.learnDeviceByEntity(entity4);

        // all entities are active, so entities 2,4 should win
        assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 2),
                                             new SwitchPort(5L, 2) },
                                             d.getAttachmentPoints());
        assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 2),
                                             new SwitchPort(5L, 2)},
                                             d.getAttachmentPoints(true));

        c.add(Calendar.MILLISECOND, 1);
        entity1.setLastSeenTimestamp(c.getTime());
        d = deviceManager.learnDeviceByEntity(entity1);

        // all entities are active, so entities 2,4 should win
        assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1),
                                             new SwitchPort(5L, 2) },
                                             d.getAttachmentPoints());
        assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1),
                                             new SwitchPort(5L, 2),
                                             new SwitchPort(1L, 2, ErrorStatus.DUPLICATE_DEVICE)},
                                             d.getAttachmentPoints(true));

        c.add(Calendar.MILLISECOND, Entity.ACTIVITY_TIMEOUT+1);
        entity1.setLastSeenTimestamp(c.getTime());
        d = deviceManager.learnDeviceByEntity(entity1);

        // entities 3,4 are still in conflict, but 1 should be resolved
        assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1),
                                             new SwitchPort(5L, 2) },
                                             d.getAttachmentPoints());
        assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1),
                                             new SwitchPort(5L, 2)},
                                             d.getAttachmentPoints(true));

        entity3.setLastSeenTimestamp(c.getTime());
        d = deviceManager.learnDeviceByEntity(entity3);

        // no conflicts, 1 and 3 will win
        assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1),
                                             new SwitchPort(5L, 1) },
                                             d.getAttachmentPoints());
        assertArrayEquals(new SwitchPort[] { new SwitchPort(1L, 1),
                                             new SwitchPort(5L, 1) },
                                             d.getAttachmentPoints(true));

    }
View Full Code Here

        Device d1 = deviceManager.learnDeviceByEntity(entity1);
        deviceManager.learnDeviceByEntity(entity2);
        Device d3 = deviceManager.learnDeviceByEntity(entity3);
        Device d4 = deviceManager.learnDeviceByEntity(entity4);

        IDevice d;

        Iterator<? extends IDevice> iter =
                deviceManager.queryDevices(null, (short)1, 1, null, null);
        int count = 0;
        while (iter.hasNext()) {
            count += 1;
            d = iter.next();
            assertEquals(d1.getDeviceKey(), d.getDeviceKey());
        }
        assertEquals(1, count);

        iter = deviceManager.queryDevices(null, (short)3, 3, null, null);
        count = 0;
        while (iter.hasNext()) {
            count += 1;
            d = iter.next();
            assertEquals(d3.getDeviceKey(), d.getDeviceKey());
        }
        assertEquals(1, count);

        iter = deviceManager.queryDevices(null, (short)1, 3, null, null);
        count = 0;
        while (iter.hasNext()) {
            count += 1;
            iter.next();
        }
        assertEquals(0, count);

        Device d5 = deviceManager.learnDeviceByEntity(entity5);
        iter = deviceManager.queryDevices(null, (short)4, 3, null, null);
        count = 0;
        Set<Long> deviceKeysFromIterator = new HashSet<Long>();
        while (iter.hasNext()) {
            count += 1;
            d = iter.next();
            deviceKeysFromIterator.add(d.getDeviceKey());
        }
        Set<Long> expectedDeviceKeys = new HashSet<Long>();
        expectedDeviceKeys.add(d4.getDeviceKey());
        expectedDeviceKeys.add(d5.getDeviceKey());
        assertEquals(expectedDeviceKeys, deviceKeysFromIterator);
        assertEquals(2, count);


        iter = deviceManager.queryDevices(1L, null, null, null, null);
        count = 0;
        deviceKeysFromIterator = new HashSet<Long>();
        while (iter.hasNext()) {
            count += 1;
            d = iter.next();
            deviceKeysFromIterator.add(d.getDeviceKey());
        }
        expectedDeviceKeys = new HashSet<Long>();
        expectedDeviceKeys.add(d1.getDeviceKey());
        expectedDeviceKeys.add(d5.getDeviceKey());
        assertEquals(expectedDeviceKeys, deviceKeysFromIterator);
View Full Code Here

TOP

Related Classes of net.floodlightcontroller.devicemanager.IDevice

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.