@Test public void testFindDevice() throws FloodlightModuleException { boolean exceptionCaught; deviceManager.entityClassifier= new MockEntityClassifierMac(); deviceManager.startUp(null); ITopologyService mockTopology = createMock(ITopologyService.class); deviceManager.topology = mockTopology; expect(mockTopology.isAttachmentPointPort(anyLong(), anyShort())). andReturn(true).anyTimes(); expect(mockTopology.getL2DomainId(EasyMock.anyLong())).andReturn(1L).anyTimes(); replay(mockTopology); Entity entity1 = new Entity(1L, (short)1, 1, 1L, 1, new Date()); Entity entity2 = new Entity(2L, (short)2, 2, 1L, 2, new Date()); Entity entity2b = new Entity(22L, (short)2, 2, 1L, 2, new Date()); Entity entity3 = new Entity(3L, (short)1, 3, 2L, 1, new Date()); Entity entity4 = new Entity(4L, (short)2, 4, 2L, 2, new Date()); Entity entity5 = new Entity(5L, (short)1, 5, 3L, 1, new Date()); IDevice d1 = deviceManager.learnDeviceByEntity(entity1); IDevice d2 = deviceManager.learnDeviceByEntity(entity2); IDevice d3 = deviceManager.learnDeviceByEntity(entity3); IDevice d4 = deviceManager.learnDeviceByEntity(entity4); IDevice d5 = deviceManager.learnDeviceByEntity(entity5); assertEquals(MockEntityClassifierMac.testECMac1, d1.getEntityClass()); assertEquals(MockEntityClassifierMac.testECMac1, d2.getEntityClass()); assertEquals(MockEntityClassifierMac.testECMac2, d3.getEntityClass()); assertEquals(MockEntityClassifierMac.testECMac2, d4.getEntityClass()); assertEquals(DefaultEntityClassifier.entityClass, d5.getEntityClass()); assertEquals(d1, deviceManager.findDevice(entity1.getMacAddress(), entity1.getVlan(), entity1.getIpv4Address(), entity1.getSwitchDPID(), entity1.getSwitchPort())); assertEquals(d1, deviceManager.findDevice(entity1.getMacAddress(), entity1.getVlan(), entity1.getIpv4Address(), entity1.getSwitchDPID(), entity1.getSwitchPort()+1)); assertEquals(null, deviceManager.findDevice(entity1.getMacAddress(), (short)42, entity1.getIpv4Address(), entity1.getSwitchDPID(), entity1.getSwitchPort())); assertEquals(null, deviceManager.findDevice(entity1.getMacAddress(), null, entity1.getIpv4Address(), entity1.getSwitchDPID(), entity1.getSwitchPort())); assertEquals(d2, deviceManager.findDeviceByEntity(entity2)); assertEquals(null, deviceManager.findDeviceByEntity(entity2b)); assertEquals(d3, deviceManager.findDevice(entity3.getMacAddress(), entity3.getVlan(), entity3.getIpv4Address(), entity3.getSwitchDPID(), entity3.getSwitchPort())); exceptionCaught = false; try { assertEquals(null, deviceManager.findDevice(entity3.getMacAddress(), entity3.getVlan(), entity3.getIpv4Address(), null, null)); } catch (IllegalArgumentException e) { exceptionCaught = true; } if (!exceptionCaught) fail("findDevice() did not throw IllegalArgumentException"); assertEquals(d4, deviceManager.findDeviceByEntity(entity4)); assertEquals(d5, deviceManager.findDevice(entity5.getMacAddress(), entity5.getVlan(), entity5.getIpv4Address(), entity5.getSwitchDPID(), entity5.getSwitchPort())); exceptionCaught = false; try { assertEquals(d5, deviceManager.findDevice(entity5.getMacAddress(), entity5.getVlan(), entity5.getIpv4Address(), null, null)); } catch (IllegalArgumentException e) { exceptionCaught = true; } if (!exceptionCaught) fail("findDevice() did not throw IllegalArgumentException"); Entity entityNoClass = new Entity(5L, (short)1, 5, -1L, 1, new Date()); assertEquals(null, deviceManager.findDeviceByEntity(entityNoClass)); assertEquals(d1, deviceManager.findClassDevice(d2.getEntityClass(), entity1.getMacAddress(), entity1.getVlan(), entity1.getIpv4Address())); assertEquals(d1, deviceManager.findClassDevice(d2.getEntityClass(), entity1.getMacAddress(), entity1.getVlan(), null)); assertEquals(null, deviceManager.findClassDevice(d2.getEntityClass(), entity1.getMacAddress(), (short) -1, 0)); }
@Override public IDevice findDevice(long macAddress, Short vlan, Integer ipv4Address, Long switchDPID, Integer switchPort) throws IllegalArgumentException { if (vlan != null && vlan.shortValue() <= 0) vlan = null; if (ipv4Address != null && ipv4Address == 0) ipv4Address = null; Entity e = new Entity(macAddress, vlan, ipv4Address, switchDPID, switchPort, null); if (!allKeyFieldsPresent(e, entityClassifier.getKeyFields())) { throw new IllegalArgumentException("Not all key fields specified." + " Required fields: " + entityClassifier.getKeyFields()); } return findDeviceByEntity(e); }
DeviceManagerImpl implements
IDeviceService, IOFMessageListener, ITopologyListener,
IFloodlightModule, IEntityClassListener,
IFlowReconcileListener, IInfoProvider { @Override public IDevice findDevice(long macAddress, Short vlan, Integer ipv4Address, Long switchDPID, Integer switchPort) throws IllegalArgumentException { if (vlan != null && vlan.shortValue() <= 0) vlan = null; if (ipv4Address != null && ipv4Address == 0) ipv4Address = null; Entity e = new Entity(macAddress, vlan, ipv4Address, switchDPID, switchPort, null); if (!allKeyFieldsPresent(e, entityClassifier.getKeyFields())) { throw new IllegalArgumentException("Not all key fields specified." + " Required fields: " + entityClassifier.getKeyFields()); } return findDeviceByEntity(e); } }
DeviceManagerImpl implements
IDeviceService, IOFMessageListener, ITopologyListener,
IFloodlightModule, IEntityClassListener,
IFlowReconcileListener, IInfoProvider { @Override public IDevice findDevice(long macAddress, Short vlan, Integer ipv4Address, Long switchDPID, Integer switchPort) throws IllegalArgumentException { if (vlan != null && vlan.shortValue() <= 0) vlan = null; if (ipv4Address != null && ipv4Address == 0) ipv4Address = null; Entity e = new Entity(macAddress, vlan, ipv4Address, switchDPID, switchPort, null); if (!allKeyFieldsPresent(e, entityClassifier.getKeyFields())) { throw new IllegalArgumentException("Not all key fields specified." + " Required fields: " + entityClassifier.getKeyFields()); } return findDeviceByEntity(e); }  }
DeviceManagerImpl implements
IDeviceService, IOFMessageListener, ITopologyListener,
IFloodlightModule, IEntityClassListener,
IFlowReconcileListener, IInfoProvider { @Override public IDevice findDevice(long macAddress, Short vlan, Integer ipv4Address, Long switchDPID, Integer switchPort) throws IllegalArgumentException { if (vlan != null && vlan.shortValue() <= 0) vlan = null; if (ipv4Address != null && ipv4Address == 0) ipv4Address = null; Entity e = new Entity(macAddress, vlan, ipv4Address, switchDPID, switchPort, null); if (!allKeyFieldsPresent(e, entityClassifier.getKeyFields())) { throw new IllegalArgumentException("Not all key fields specified." + " Required fields: " + entityClassifier.getKeyFields()); } return findDeviceByEntity(e); }  @Override IDevice getDevice(Long deviceKey); @Override IDevice findDevice(long macAddress, Short vlan,
                              Integer ipv4Address, Long switchDPID,
                              Integer switchPort); @Override IDevice findClassDevice(IEntityClass entityClass, long macAddress,
                                  Short vlan, Integer ipv4Address); @Override Collection<? extends IDevice> getAllDevices(); @Override void addIndex(boolean perClass,
                         EnumSet<DeviceField> keyFields); @Override Iterator<? extends IDevice> queryDevices(Long macAddress,
                                                    Short vlan,
                                                    Integer ipv4Address,
                                                    Long switchDPID,
                                                    Integer switchPort); @Override Iterator<? extends IDevice> queryClassDevices(IEntityClass entityClass,
                                                         Long macAddress,
                                                         Short vlan,
                                                         Integer ipv4Address,
                                                         Long switchDPID,
                                                         Integer switchPort); @Override void addListener(IDeviceListener listener); @Override void addSuppressAPs(long swId, short port); @Override void removeSuppressAPs(long swId, short port); @Override Set<SwitchPort> getSuppressAPs(); @Override Map<String, Object> getInfo(String type); @Override String getName(); @Override boolean isCallbackOrderingPrereq(OFType type, String name); @Override boolean isCallbackOrderingPostreq(OFType type, String name); @Override Command receive(IOFSwitch sw, OFMessage msg,
                           FloodlightContext cntx); @Override Command reconcileFlows(ArrayList<OFMatchReconcile> ofmRcList); @Override Collection<Class<? extends IFloodlightService>> getModuleServices(); @Override Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls(); @Override Collection<Class<? extends IFloodlightService>> getModuleDependencies(); @Override void init(FloodlightModuleContext fmc); @Override void startUp(FloodlightModuleContext fmc); boolean isValidAttachmentPoint(long switchDPID,
                                             int switchPort); @Override void topologyChanged(List<LDUpdate> updateList); @Override void entityClassChanged(Set<String> entityClassNames); }
DeviceManagerImpl implements
IDeviceService, IOFMessageListener, ITopologyListener,
IFloodlightModule, IEntityClassListener,
IFlowReconcileListener, IInfoProvider { @Override public IDevice findDevice(long macAddress, Short vlan, Integer ipv4Address, Long switchDPID, Integer switchPort) throws IllegalArgumentException { if (vlan != null && vlan.shortValue() <= 0) vlan = null; if (ipv4Address != null && ipv4Address == 0) ipv4Address = null; Entity e = new Entity(macAddress, vlan, ipv4Address, switchDPID, switchPort, null); if (!allKeyFieldsPresent(e, entityClassifier.getKeyFields())) { throw new IllegalArgumentException("Not all key fields specified." + " Required fields: " + entityClassifier.getKeyFields()); } return findDeviceByEntity(e); }  @Override IDevice getDevice(Long deviceKey); @Override IDevice findDevice(long macAddress, Short vlan,
                              Integer ipv4Address, Long switchDPID,
                              Integer switchPort); @Override IDevice findClassDevice(IEntityClass entityClass, long macAddress,
                                  Short vlan, Integer ipv4Address); @Override Collection<? extends IDevice> getAllDevices(); @Override void addIndex(boolean perClass,
                         EnumSet<DeviceField> keyFields); @Override Iterator<? extends IDevice> queryDevices(Long macAddress,
                                                    Short vlan,
                                                    Integer ipv4Address,
                                                    Long switchDPID,
                                                    Integer switchPort); @Override Iterator<? extends IDevice> queryClassDevices(IEntityClass entityClass,
                                                         Long macAddress,
                                                         Short vlan,
                                                         Integer ipv4Address,
                                                         Long switchDPID,
                                                         Integer switchPort); @Override void addListener(IDeviceListener listener); @Override void addSuppressAPs(long swId, short port); @Override void removeSuppressAPs(long swId, short port); @Override Set<SwitchPort> getSuppressAPs(); @Override Map<String, Object> getInfo(String type); @Override String getName(); @Override boolean isCallbackOrderingPrereq(OFType type, String name); @Override boolean isCallbackOrderingPostreq(OFType type, String name); @Override Command receive(IOFSwitch sw, OFMessage msg,
                           FloodlightContext cntx); @Override Command reconcileFlows(ArrayList<OFMatchReconcile> ofmRcList); @Override Collection<Class<? extends IFloodlightService>> getModuleServices(); @Override Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls(); @Override Collection<Class<? extends IFloodlightService>> getModuleDependencies(); @Override void init(FloodlightModuleContext fmc); @Override void startUp(FloodlightModuleContext fmc); boolean isValidAttachmentPoint(long switchDPID,
                                             int switchPort); @Override void topologyChanged(List<LDUpdate> updateList); @Override void entityClassChanged(Set<String> entityClassNames); static final String MODULE_NAME; static final String PACKAGE; public IDebugCounter cntIncoming; public IDebugCounter cntReconcileRequest; public IDebugCounter cntReconcileNoSource; public IDebugCounter cntReconcileNoDest; public IDebugCounter cntInvalidSource; public IDebugCounter cntInvalidDest; public IDebugCounter cntNoSource; public IDebugCounter cntNoDest; public IDebugCounter cntDhcpClientNameSnooped; public IDebugCounter cntDeviceOnInternalPortNotLearned; public IDebugCounter cntPacketNotAllowed; public IDebugCounter cntNewDevice; public IDebugCounter cntPacketOnInternalPortForKnownDevice; public IDebugCounter cntNewEntity; public IDebugCounter cntDeviceChanged; public IDebugCounter cntDeviceMoved; public IDebugCounter cntCleanupEntitiesRuns; public IDebugCounter cntEntityRemovedTimeout; public IDebugCounter cntDeviceDeleted; public IDebugCounter cntDeviceReclassifyDelete; public IDebugCounter cntDeviceStrored; public IDebugCounter cntDeviceStoreThrottled; public IDebugCounter cntDeviceRemovedFromStore; public IDebugCounter cntSyncException; public IDebugCounter cntDevicesFromStore; public IDebugCounter cntConsolidateStoreRuns; public IDebugCounter cntConsolidateStoreDevicesRemoved; public IDebugCounter cntTransitionToMaster; public AttachmentPointComparator apComparator; public SingletonTask entityCleanupTask; }