diff --git a/src/main/java/net/floodlightcontroller/core/IFloodlightProviderService.java b/src/main/java/net/floodlightcontroller/core/IFloodlightProviderService.java index 7f9ff596ad0ab785fa33660c55512ef6d94fd37e..683e0dee8436e941e5663378d3e352f38cafafc9 100644 --- a/src/main/java/net/floodlightcontroller/core/IFloodlightProviderService.java +++ b/src/main/java/net/floodlightcontroller/core/IFloodlightProviderService.java @@ -211,6 +211,17 @@ public interface IFloodlightProviderService extends */ public void setAlwaysClearFlowsOnSwAdd(boolean value); + /** + * Get controller memory information + */ + public Map<String, Long> getMemory(); + + /** + * returns the uptime of this controller. + * @return + */ + public Long getUptime(); + /** * Adds an OFSwitch driver * @param desc The starting portion of switch's manufacturer string diff --git a/src/main/java/net/floodlightcontroller/core/internal/Controller.java b/src/main/java/net/floodlightcontroller/core/internal/Controller.java index db0e2e87be822d5855bff33897e046428305a419..104b1d26eb3de013d52c5048c285d9f390279cc0 100644 --- a/src/main/java/net/floodlightcontroller/core/internal/Controller.java +++ b/src/main/java/net/floodlightcontroller/core/internal/Controller.java @@ -19,6 +19,8 @@ package net.floodlightcontroller.core.internal; import java.io.FileInputStream; import java.io.IOException; +import java.lang.management.ManagementFactory; +import java.lang.management.RuntimeMXBean; import java.net.InetSocketAddress; import java.nio.channels.ClosedChannelException; import java.util.ArrayList; @@ -199,9 +201,6 @@ public class Controller implements IFloodlightProviderService, protected RoleChanger roleChanger; protected SingletonTask roleChangeDamper; - // Start time of the controller - protected long systemStartTime; - // Flag to always flush flow table on switch reconnect (HA or otherwise) protected boolean alwaysClearFlowsOnSwAdd = false; @@ -1791,7 +1790,6 @@ public class Controller implements IFloodlightProviderService, this.notifiedRole = this.role; this.roleChanger = new RoleChanger(this); initVendorMessages(); - this.systemStartTime = System.currentTimeMillis(); String option = configParams.get("flushSwitchesOnReconnect"); @@ -1972,7 +1970,8 @@ public class Controller implements IFloodlightProviderService, @Override public long getSystemStartTime() { - return (this.systemStartTime); + RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean(); + return rb.getStartTime(); } @Override @@ -1984,6 +1983,21 @@ public class Controller implements IFloodlightProviderService, return this.alwaysClearFlowsOnSwAdd; } + @Override + public Map<String, Long> getMemory() { + Map<String, Long> m = new HashMap<String, Long>(); + Runtime runtime = Runtime.getRuntime(); + m.put("total", runtime.totalMemory()); + m.put("free", runtime.freeMemory()); + return m; + } + + @Override + public Long getUptime() { + RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean(); + return rb.getUptime(); + } + @Override public void addOFSwitchDriver(String description, IOFSwitchDriver driver) { IOFSwitchDriver existingDriver = switchBindingMap.get(description); diff --git a/src/main/java/net/floodlightcontroller/core/web/SystemUptimeResource.java b/src/main/java/net/floodlightcontroller/core/web/SystemUptimeResource.java index 978419873037467e4ad67439905fae510c24ea72..b6981ef252fc7c6c5a8ad69e39e3197ecf30c06c 100644 --- a/src/main/java/net/floodlightcontroller/core/web/SystemUptimeResource.java +++ b/src/main/java/net/floodlightcontroller/core/web/SystemUptimeResource.java @@ -23,25 +23,24 @@ import org.restlet.resource.ServerResource; public class SystemUptimeResource extends ServerResource { - - public class UptimeRest { - long systemUptimeMsec; - - public long getSystemUptimeMsec() { - return systemUptimeMsec; - } - } - - @Get("json") - public UptimeRest retrieve() { - IFloodlightProviderService floodlightProvider = - (IFloodlightProviderService)getContext().getAttributes(). - get(IFloodlightProviderService.class.getCanonicalName()); - - UptimeRest uptime = new UptimeRest(); - uptime.systemUptimeMsec = - System.currentTimeMillis() - floodlightProvider.getSystemStartTime(); - - return (uptime); - } + + public class UptimeRest { + long systemUptimeMsec; + + public long getSystemUptimeMsec() { + return systemUptimeMsec; + } + } + + @Get("json") + public UptimeRest retrieve() { + IFloodlightProviderService floodlightProvider = + (IFloodlightProviderService)getContext().getAttributes(). + get(IFloodlightProviderService.class.getCanonicalName()); + + UptimeRest uptime = new UptimeRest(); + uptime.systemUptimeMsec = floodlightProvider.getUptime(); + + return (uptime); + } } diff --git a/src/main/java/net/floodlightcontroller/devicemanager/internal/Device.java b/src/main/java/net/floodlightcontroller/devicemanager/internal/Device.java index 4525a50944409e2b385c363ccb1961d1addabf46..e6083f93acf39a4f356443e051d9ef3d4ee3177d 100755 --- a/src/main/java/net/floodlightcontroller/devicemanager/internal/Device.java +++ b/src/main/java/net/floodlightcontroller/devicemanager/internal/Device.java @@ -418,7 +418,9 @@ public class Device implements IDevice { if (apMap == null || apMap.isEmpty()) { apList.add(newAP); attachmentPoints = apList; - return true; + // there are no old attachment points - we should not treat this + // as a device moved. + return false; } long id = topology.getL2DomainId(sw); diff --git a/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImpl.java b/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImpl.java index 261ec6beff1a372194ae5fa65689ed0756ad0b9f..2c82e6076f2b4c8c4b90961386c8ed9fd779a6f0 100755 --- a/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImpl.java +++ b/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImpl.java @@ -794,7 +794,7 @@ IFlowReconcileListener, IInfoProvider, IHAListener { if (srcEntity == null) return Command.STOP; - // Learn from ARP packet. + // Learn from ARP packet for special VRRP settings. // In VRRP settings, the source MAC address and sender MAC // addresses can be different. In such cases, we need to learn // the IP to MAC mapping of the VRRP IP address. The source @@ -1036,6 +1036,7 @@ IFlowReconcileListener, IInfoProvider, IHAListener { (learnap ? (int)inPort : null), new Date()); } + /** * Look up a {@link Device} based on the provided {@link Entity}. We first * check the primary index. If we do not find an entry there we classify @@ -1076,9 +1077,10 @@ IFlowReconcileListener, IInfoProvider, IHAListener { * the given source device. The source device is important since * there could be ambiguity in the destination device without the * attachment point information. - * @param source the source device. The returned destination will be - * in the same entity class as the source. - * @param dstEntity the entity to look up + * @param reference the source device's entity class. + * The returned destination will be + * in the same entity class as the source. + * @param dstEntity the entity to look up * @return an {@link Device} or null if no device is found. */ protected Device findDestByEntity(IEntityClass reference, @@ -1107,7 +1109,6 @@ IFlowReconcileListener, IInfoProvider, IHAListener { return deviceMap.get(deviceKey); } - /** * Look up a {@link Device} within a particular entity class based on * the provided {@link Entity}. @@ -1707,6 +1708,7 @@ IFlowReconcileListener, IInfoProvider, IHAListener { return new Device(device, entity, insertionpoint); } + //not used protected Device allocateDevice(Device device, Set <Entity> entities) { List <AttachmentPoint> newPossibleAPs = new ArrayList<AttachmentPoint>(); @@ -1737,7 +1739,7 @@ IFlowReconcileListener, IInfoProvider, IHAListener { } // ********************* - // IEntityClassListener + // ITopologyListener // ********************* /** diff --git a/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceUniqueIndex.java b/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceUniqueIndex.java index 4f2d3f8c4995b466f2fc5e22edbf11160fbaf3ab..4811013e77258654c9577b0271a51f72c31bfd8d 100644 --- a/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceUniqueIndex.java +++ b/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceUniqueIndex.java @@ -1,7 +1,7 @@ /** -* Copyright 2012 Big Switch Networks, Inc. +* Copyright 2012 Big Switch Networks, Inc. * Originally created by David Erickson, Stanford University -* +* * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain * a copy of the License at @@ -31,7 +31,7 @@ public class DeviceUniqueIndex extends DeviceIndex { /** * The index */ - private ConcurrentHashMap<IndexedEntity, Long> index; + private final ConcurrentHashMap<IndexedEntity, Long> index; /** * Construct a new device index using the provided key fields @@ -51,10 +51,10 @@ public class DeviceUniqueIndex extends DeviceIndex { final Long deviceKey = findByEntity(entity); if (deviceKey != null) return Collections.<Long>singleton(deviceKey).iterator(); - + return Collections.<Long>emptySet().iterator(); } - + @Override public Iterator<Long> getAll() { return index.values().iterator(); @@ -68,15 +68,15 @@ public class DeviceUniqueIndex extends DeviceIndex { Long ret = index.putIfAbsent(ie, deviceKey); if (ret != null && !ret.equals(deviceKey)) { - // If the return value is non-null, then fail the insert - // (this implies that a device using this entity has + // If the return value is non-null, then fail the insert + // (this implies that a device using this entity has // already been created in another thread). return false; } } return true; } - + @Override public void updateIndex(Entity entity, Long deviceKey) { IndexedEntity ie = new IndexedEntity(keyFields, entity); diff --git a/src/main/java/net/floodlightcontroller/routing/IRoutingDecision.java b/src/main/java/net/floodlightcontroller/routing/IRoutingDecision.java index 5fbb38d748971197531c5046cbf913421916b1c8..81c3c138f60a59d4eedce92173f2595682347a76 100644 --- a/src/main/java/net/floodlightcontroller/routing/IRoutingDecision.java +++ b/src/main/java/net/floodlightcontroller/routing/IRoutingDecision.java @@ -54,4 +54,6 @@ public interface IRoutingDecision { public void setMulticastInterfaces(List<SwitchPort> lspt); public Integer getWildcards(); public void setWildcards(Integer wildcards); + public short getHardTimeout(); + public void setHardTimeout(short hardTimeout); } diff --git a/src/main/java/net/floodlightcontroller/routing/RoutingDecision.java b/src/main/java/net/floodlightcontroller/routing/RoutingDecision.java index 5fff3a2251333bd62e3125b661f3a8378bdccbca..aa4b3dde823ab75a38671e53767294d1964012f3 100644 --- a/src/main/java/net/floodlightcontroller/routing/RoutingDecision.java +++ b/src/main/java/net/floodlightcontroller/routing/RoutingDecision.java @@ -29,6 +29,7 @@ public class RoutingDecision implements IRoutingDecision { protected RoutingAction action; protected Integer wildcards; + protected short hardTimeout; protected SwitchPort srcPort; protected IDevice srcDevice; protected List<IDevice> destDevices; @@ -46,6 +47,7 @@ public class RoutingDecision implements IRoutingDecision { Collections.synchronizedList(new ArrayList<SwitchPort>()); this.action = action; this.wildcards = null; + this.hardTimeout = ForwardingBase.FLOWMOD_DEFAULT_HARD_TIMEOUT; } @Override @@ -100,6 +102,16 @@ public class RoutingDecision implements IRoutingDecision { this.wildcards = wildcards; } + @Override + public short getHardTimeout() { + return hardTimeout; + } + + @Override + public void setHardTimeout(short hardTimeout) { + this.hardTimeout = hardTimeout; + } + @Override public void addToContext(FloodlightContext cntx) { rtStore.put(cntx, IRoutingDecision.CONTEXT_DECISION, this); diff --git a/src/test/java/net/floodlightcontroller/core/test/MockFloodlightProvider.java b/src/test/java/net/floodlightcontroller/core/test/MockFloodlightProvider.java index 6db18a150c8fed2d8fb84c412cfe0bfa3aad3c98..7b5cd6293c1888250299c6352918c610df70733c 100644 --- a/src/test/java/net/floodlightcontroller/core/test/MockFloodlightProvider.java +++ b/src/test/java/net/floodlightcontroller/core/test/MockFloodlightProvider.java @@ -17,6 +17,8 @@ package net.floodlightcontroller.core.test; +import java.lang.management.ManagementFactory; +import java.lang.management.RuntimeMXBean; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -361,4 +363,18 @@ public class MockFloodlightProvider implements IFloodlightModule, IFloodlightPro return null; } + @Override + public Map<String, Long> getMemory() { + Map<String, Long> m = new HashMap<String, Long>(); + Runtime runtime = Runtime.getRuntime(); + m.put("total", runtime.totalMemory()); + m.put("free", runtime.freeMemory()); + return m; + } + + @Override + public Long getUptime() { + RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean(); + return rb.getUptime(); + } } diff --git a/src/test/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImplTest.java b/src/test/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImplTest.java index be3d85727062d0a6e172c9020f9bdeb02a860fcb..40986e9f2577af119523534ac3762404bb66c6f0 100644 --- a/src/test/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImplTest.java +++ b/src/test/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImplTest.java @@ -223,7 +223,7 @@ public class DeviceManagerImplTest extends FloodlightTestCase { - + @Test public void testLastSeen() throws Exception { Calendar c = Calendar.getInstance(); @@ -397,11 +397,11 @@ public class DeviceManagerImplTest extends FloodlightTestCase { assertEquals(4, deviceManager.getAllDevices().size()); verify(mockListener); - - + + reset(mockListener); replay(mockListener); - + reset(deviceManager.topology); deviceManager.topology.addListener(deviceManager); expectLastCall().times(1); @@ -411,16 +411,16 @@ public class DeviceManagerImplTest extends FloodlightTestCase { deviceManager.startUp(null); Entity entityNoClass = new Entity(5L, (short)1, 5, -1L, 1, new Date()); assertEquals(null, deviceManager.learnDeviceByEntity(entityNoClass)); - + verify(mockListener); } - - + + private void doTestEntityOrdering(boolean computeInsertionPoint) throws Exception { Entity e = new Entity(10L, null, null, null, null, null); IEntityClass ec = createNiceMock(IEntityClass.class); Device d = new Device(deviceManager, 1L, e, ec); - + int expectedLength = 1; Long[] macs = new Long[] { 5L, // new first element 15L, // new last element @@ -431,7 +431,7 @@ public class DeviceManagerImplTest extends FloodlightTestCase { 1L, 20L }; - + for (Long mac: macs) { e = new Entity(mac, null, null, null, null, null); int insertionPoint; @@ -447,12 +447,12 @@ public class DeviceManagerImplTest extends FloodlightTestCase { assertEquals(-1, d.entities[i].compareTo(d.entities[i+1])); } } - + @Test public void testEntityOrderingExternal() throws Exception { doTestEntityOrdering(true); } - + @Test public void testEntityOrderingInternal() throws Exception { doTestEntityOrdering(false); @@ -568,12 +568,12 @@ public class DeviceManagerImplTest extends FloodlightTestCase { assertArrayEquals(new Integer[] { 1 }, ips); verify(mockListener); } - + private void verifyEntityArray(Entity[] expected, Device d) { Arrays.sort(expected); assertArrayEquals(expected, d.entities); } - + @Test public void testNoLearningOnInternalPorts() throws Exception { IDeviceListener mockListener = @@ -610,7 +610,7 @@ public class DeviceManagerImplTest extends FloodlightTestCase { // Switches 2 and 4 have only internal ports expect(mockTopology.isAttachmentPointPort(or(eq(2L), eq(4L)), anyShort())) .andReturn(false).anyTimes(); - + expect(mockTopology.isConsistent(1L, (short)1, 3L, (short)1)) .andReturn(false).once(); @@ -638,13 +638,13 @@ public class DeviceManagerImplTest extends FloodlightTestCase { mockListener.deviceAdded(isA(IDevice.class)); expectLastCall().once(); replay(mockListener); - + // cannot learn device internal ports d = deviceManager.learnDeviceByEntity(entity2); assertNull(d); d = deviceManager.learnDeviceByEntity(entity4); assertNull(d); - + d = deviceManager.learnDeviceByEntity(entity1); assertEquals(1, deviceManager.getAllDevices().size()); aps = d.getAttachmentPoints(); @@ -653,10 +653,10 @@ public class DeviceManagerImplTest extends FloodlightTestCase { ips = d.getIPv4Addresses(); assertArrayEquals(new Integer[] { 1 }, ips); verify(mockListener); - + reset(mockListener); replay(mockListener); - + // don't learn d = deviceManager.learnDeviceByEntity(entity2); assertEquals(1, deviceManager.getAllDevices().size()); @@ -666,12 +666,12 @@ public class DeviceManagerImplTest extends FloodlightTestCase { ips = d.getIPv4Addresses(); assertArrayEquals(new Integer[] { 1 }, ips); verify(mockListener); - + reset(mockListener); mockListener.deviceMoved(isA(IDevice.class)); mockListener.deviceIPV4AddrChanged(isA(IDevice.class)); replay(mockListener); - + // learn d = deviceManager.learnDeviceByEntity(entity3); assertEquals(1, deviceManager.getAllDevices().size()); @@ -682,10 +682,10 @@ public class DeviceManagerImplTest extends FloodlightTestCase { Arrays.sort(ips); assertArrayEquals(new Integer[] { 1, 3 }, ips); verify(mockListener); - + reset(mockListener); replay(mockListener); - + // don't learn d = deviceManager.learnDeviceByEntity(entity4); assertEquals(1, deviceManager.getAllDevices().size()); @@ -697,7 +697,7 @@ public class DeviceManagerImplTest extends FloodlightTestCase { assertArrayEquals(new Integer[] { 1, 3 }, ips); verify(mockListener); } - + @Test public void testAttachmentPointSuppression() throws Exception { IDeviceListener mockListener = @@ -747,6 +747,7 @@ public class DeviceManagerImplTest extends FloodlightTestCase { Calendar c = Calendar.getInstance(); Entity entity0 = new Entity(1L, null, null, null, null, c.getTime()); + // No attachment point should be learnt on 1L, 1 Entity entity1 = new Entity(1L, null, 1, 1L, 1, c.getTime()); c.add(Calendar.SECOND, 1); Entity entity2 = new Entity(1L, null, 1, 5L, 1, c.getTime()); @@ -762,7 +763,7 @@ public class DeviceManagerImplTest extends FloodlightTestCase { mockListener.deviceAdded(isA(IDevice.class)); mockListener.deviceIPV4AddrChanged((isA(IDevice.class))); replay(mockListener); - + // TODO: we currently do learn entities on suppressed APs // // cannot learn device on suppressed AP // d = deviceManager.learnDeviceByEntity(entity1); @@ -779,10 +780,10 @@ public class DeviceManagerImplTest extends FloodlightTestCase { verify(mockListener); reset(mockListener); - mockListener.deviceMoved((isA(IDevice.class))); + //mockListener.deviceMoved((isA(IDevice.class))); //mockListener.deviceIPV4AddrChanged((isA(IDevice.class))); replay(mockListener); - + // there is no device moved because entity 1 was not learned due to suppression d = deviceManager.learnDeviceByEntity(entity2); assertEquals(1, deviceManager.getAllDevices().size()); aps = d.getAttachmentPoints(); @@ -1166,12 +1167,12 @@ public class DeviceManagerImplTest extends FloodlightTestCase { .andReturn(false).atLeastOnce(); expect(mockListener.isCallbackOrderingPrereq((String)anyObject(), (String)anyObject())) .andReturn(false).atLeastOnce(); - + Calendar c = Calendar.getInstance(); c.add(Calendar.MILLISECOND, -DeviceManagerImpl.ENTITY_TIMEOUT-1); Entity entity1 = new Entity(1L, null, 1, 1L, 1, c.getTime()); Entity entity2 = new Entity(1L, null, 2, 5L, 1, c.getTime()); - + ITopologyService mockTopology = createMock(ITopologyService.class); deviceManager.topology = mockTopology; @@ -1213,16 +1214,16 @@ public class DeviceManagerImplTest extends FloodlightTestCase { r = deviceManager.findDevice(1L, null, null, null, null); assertNull(r); - + verify(mockListener); } - + /* * A ConcurrentHashMap for devices (deviceMap) that can be used to test * code that specially handles concurrent modification situations. In * particular, we overwrite values() and will replace / remove all the * elements returned by values. - * + * * The remove flag in the constructor specifies if devices returned by * values() should be removed or replaced. */ @@ -1234,7 +1235,7 @@ public class DeviceManagerImplTest extends FloodlightTestCase { super(); this.remove = remove; } - + @Override public Collection<Device> values() { // Get the values from the real map and copy them since @@ -1276,17 +1277,17 @@ public class DeviceManagerImplTest extends FloodlightTestCase { return devs; } } - + @Test public void testEntityExpiration() throws Exception { doTestEntityExpiration(); } - + @Test public void testDeviceExpiration() throws Exception { doTestDeviceExpiration(); } - + /* Test correct entity cleanup behavior when a concurrent modification * occurs. */ @@ -1295,7 +1296,7 @@ public class DeviceManagerImplTest extends FloodlightTestCase { deviceManager.deviceMap = new ConcurrentlyModifiedDeviceMap(false); doTestEntityExpiration(); } - + /* Test correct entity cleanup behavior when a concurrent remove * occurs. */ @@ -1304,7 +1305,7 @@ public class DeviceManagerImplTest extends FloodlightTestCase { deviceManager.deviceMap = new ConcurrentlyModifiedDeviceMap(true); doTestDeviceExpiration(); } - + /* Test correct entity cleanup behavior when a concurrent modification * occurs. */ @@ -1313,7 +1314,7 @@ public class DeviceManagerImplTest extends FloodlightTestCase { deviceManager.deviceMap = new ConcurrentlyModifiedDeviceMap(false); doTestDeviceExpiration(); } - + @Test public void testAttachmentPointFlapping() throws Exception { @@ -1582,7 +1583,7 @@ public class DeviceManagerImplTest extends FloodlightTestCase { andReturn(true).anyTimes(); expect(mockTopology.getL2DomainId(EasyMock.anyLong())).andReturn(1L).anyTimes(); replay(mockTopology); - + doTestDeviceQuery(); } @@ -1686,19 +1687,19 @@ public class DeviceManagerImplTest extends FloodlightTestCase { 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); - + // Make sure the entity classifier worked as expected assertEquals(MockEntityClassifierMac.testECMac1, d1.getEntityClass()); assertEquals(MockEntityClassifierMac.testECMac1, d2.getEntityClass()); @@ -1706,7 +1707,7 @@ public class DeviceManagerImplTest extends FloodlightTestCase { assertEquals(MockEntityClassifierMac.testECMac2, d4.getEntityClass()); assertEquals(DefaultEntityClassifier.entityClass, d5.getEntityClass()); - + // Look up the device using findDevice() which uses only the primary // index assertEquals(d1, deviceManager.findDevice(entity1.getMacAddress(), @@ -1773,12 +1774,12 @@ public class DeviceManagerImplTest extends FloodlightTestCase { } 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)); - - + + // Now look up destination devices assertEquals(d1, deviceManager.findClassDevice(d2.getEntityClass(), entity1.getMacAddress(), @@ -1794,12 +1795,12 @@ public class DeviceManagerImplTest extends FloodlightTestCase { 0)); } - + @Test public void testGetIPv4Addresses() { // Looks like Date is only 1s granularity - + ITopologyService mockTopology = createMock(ITopologyService.class); deviceManager.topology = mockTopology; expect(mockTopology.isAttachmentPointPort(anyLong(), @@ -1826,8 +1827,8 @@ public class DeviceManagerImplTest extends FloodlightTestCase { Entity e1 = new Entity(1L, (short)1, null, null, null, new Date(2000)); Device d1 = deviceManager.learnDeviceByEntity(e1); assertArrayEquals(new Integer[0], d1.getIPv4Addresses()); - - + + Entity e2 = new Entity(2L, (short)2, 2, null, null, new Date(2000)); Device d2 = deviceManager.learnDeviceByEntity(e2); d2 = deviceManager.learnDeviceByEntity(e2); @@ -1842,7 +1843,7 @@ public class DeviceManagerImplTest extends FloodlightTestCase { d2 = deviceManager.learnDeviceByEntity(e2c); assertArrayEquals(new Integer[] { 2 }, d2.getIPv4Addresses()); assertEquals(3, d2.entities.length); - + // Other devices with different IPs shouldn't interfere Entity e3 = new Entity(3L, (short)3, 3, null, null, new Date(4000)); Entity e3b = new Entity(3L, (short)3, 3, 3L, 3, new Date(4400)); @@ -1850,14 +1851,14 @@ public class DeviceManagerImplTest extends FloodlightTestCase { d3 = deviceManager.learnDeviceByEntity(e3b); assertArrayEquals(new Integer[] { 2 }, d2.getIPv4Addresses()); assertArrayEquals(new Integer[] { 3 }, d3.getIPv4Addresses()); - + // Add another IP to d3 Entity e3c = new Entity(3L, (short)3, 33, 3L, 3, new Date(4400)); d3 = deviceManager.learnDeviceByEntity(e3c); Integer[] ips = d3.getIPv4Addresses(); Arrays.sort(ips); assertArrayEquals(new Integer[] { 3, 33 }, ips); - + // Add another device that also claims IP2 but is older than e2 Entity e4 = new Entity(4L, (short)4, 2, null, null, new Date(1000)); Entity e4b = new Entity(4L, (short)4, null, 4L, 4, new Date(1000)); @@ -1867,7 +1868,7 @@ public class DeviceManagerImplTest extends FloodlightTestCase { // add another entity to d4 d4 = deviceManager.learnDeviceByEntity(e4b); assertArrayEquals(new Integer[0], d4.getIPv4Addresses()); - + // Make e4 and e4a newer Entity e4c = new Entity(4L, (short)4, 2, null, null, new Date(5000)); Entity e4d = new Entity(4L, (short)4, null, 4L, 5, new Date(5000)); @@ -1876,7 +1877,7 @@ public class DeviceManagerImplTest extends FloodlightTestCase { assertArrayEquals(new Integer[0], d2.getIPv4Addresses()); // FIXME: d4 should not return IP4 assertArrayEquals(new Integer[] { 2 }, d4.getIPv4Addresses()); - + // Add another newer entity to d2 but with different IP Entity e2d = new Entity(2L, (short)2, 22, 4L, 6, new Date(6000)); d2 = deviceManager.learnDeviceByEntity(e2d); @@ -1894,7 +1895,7 @@ public class DeviceManagerImplTest extends FloodlightTestCase { ips= d4.getIPv4Addresses(); Arrays.sort(ips); assertArrayEquals(new Integer[] { 2, 42 }, ips); - + // add a couple more IPs Entity e2f = new Entity(2L, (short)2, 4242, 2L, 5, new Date(8000)); d2 = deviceManager.learnDeviceByEntity(e2f); @@ -1907,7 +1908,7 @@ public class DeviceManagerImplTest extends FloodlightTestCase { Arrays.sort(ips); assertArrayEquals(new Integer[] { 2, 42, 4242 }, ips); } - + // TODO: this test should really go into a separate class that collects // unit tests for Device @Test @@ -1934,7 +1935,7 @@ public class DeviceManagerImplTest extends FloodlightTestCase { assertArrayEquals(new Short[0], d.getSwitchPortVlanIds(swp2x1)); } - + @Test public void testReclassifyDevice() { MockFlexEntityClassifier flexClassifier = @@ -1959,20 +1960,20 @@ public class DeviceManagerImplTest extends FloodlightTestCase { .andReturn(false) .anyTimes(); replay(mockTopology); - + //flexClassifier.createTestEntityClass("Class1"); - + Entity entity1 = new Entity(1L, (short)1, 1, 1L, 1, new Date()); Entity entity1b = new Entity(1L, (short)2, 1, 1L, 1, new Date()); Entity entity2 = new Entity(2L, (short)1, 2, 2L, 2, new Date()); Entity entity2b = new Entity(2L, (short)2, 2, 2L, 2, new Date()); - - + + Device d1 = deviceManager.learnDeviceByEntity(entity1); Device d2 = deviceManager.learnDeviceByEntity(entity2); Device d1b = deviceManager.learnDeviceByEntity(entity1b); Device d2b = deviceManager.learnDeviceByEntity(entity2b); - + d1 = deviceManager.getDeviceIteratorForQuery(entity1.getMacAddress(), entity1.getVlan(), entity1.getIpv4Address(), entity1.getSwitchDPID(), entity1.getSwitchPort()) @@ -1980,9 +1981,9 @@ public class DeviceManagerImplTest extends FloodlightTestCase { d1b = deviceManager.getDeviceIteratorForQuery(entity1b.getMacAddress(), entity1b.getVlan(), entity1b.getIpv4Address(), entity1b.getSwitchDPID(), entity1b.getSwitchPort()).next(); - + assertEquals(d1, d1b); - + d2 = deviceManager.getDeviceIteratorForQuery(entity2.getMacAddress(), entity2.getVlan(), entity2.getIpv4Address(), entity2.getSwitchDPID(), entity2.getSwitchPort()).next(); @@ -1990,32 +1991,32 @@ public class DeviceManagerImplTest extends FloodlightTestCase { entity2b.getVlan(), entity2b.getIpv4Address(), entity2b.getSwitchDPID(), entity2b.getSwitchPort()).next(); assertEquals(d2, d2b); - + IEntityClass eC1 = flexClassifier.createTestEntityClass("C1"); IEntityClass eC2 = flexClassifier.createTestEntityClass("C2"); - + flexClassifier.addVlanEntities((short)1, eC1); flexClassifier.addVlanEntities((short)2, eC1); - + deviceManager.reclassifyDevice(d1); deviceManager.reclassifyDevice(d2); - + d1 = deviceManager.deviceMap.get( deviceManager.primaryIndex.findByEntity(entity1)); d1b = deviceManager.deviceMap.get( deviceManager.primaryIndex.findByEntity(entity1b)); - + assertEquals(d1, d1b); - + d2 = deviceManager.deviceMap.get( deviceManager.primaryIndex.findByEntity(entity2)); d2b = deviceManager.deviceMap.get( deviceManager.primaryIndex.findByEntity(entity2b)); - + assertEquals(d2, d2b); - + flexClassifier.addVlanEntities((short)1, eC2); - + deviceManager.reclassifyDevice(d1); deviceManager.reclassifyDevice(d2); d1 = deviceManager.deviceMap.get( @@ -2026,11 +2027,11 @@ public class DeviceManagerImplTest extends FloodlightTestCase { deviceManager.primaryIndex.findByEntity(entity2)); d2b = deviceManager.deviceMap.get( deviceManager.primaryIndex.findByEntity(entity2b)); - + assertNotSame(d1, d1b); - + assertNotSame(d2, d2b); - + flexClassifier.addVlanEntities((short)1, eC1); deviceManager.reclassifyDevice(d1); deviceManager.reclassifyDevice(d2); @@ -2051,7 +2052,7 @@ public class DeviceManagerImplTest extends FloodlightTestCase { classState.classIndex.findByEntity(entity2b); assertEquals(deviceKey1, deviceKey1b); - + assertEquals(deviceKey2, deviceKey2b);