@Test public void testDeviceUpdates() { Device referenceDevice; DeviceEvent event; int numDevices = 10; int numInfraPorts = 5; totalPorts = 10; defaultPopulator(numDevices, numInfraPorts); referenceDevice = NetTestTools.device("1"); event = new DeviceEvent(DEVICE_ADDED, referenceDevice, new DefaultPort(referenceDevice, PortNumber.portNumber(1), true)); testDeviceManager.listener.event(event); assertTrue("Unexpected number of new ports added", mgr.deviceService.getPorts(NetTestTools.did("1")).size() == 10); assertEquals("Unexpected number of new edge ports added", (totalPorts - numInfraPorts), events.size()); for (int index = 0; index < numInfraPorts; index++) { assertTrue("Unexpected type of event", events.get(index).type() == EDGE_PORT_ADDED); } for (int index = 0; index < events.size(); index++) { assertEquals("Port added had unexpected port number.", events.get(index).subject().port(), NetTestTools.connectPoint("a", index + numInfraPorts + 1).port()); } events.clear(); testDeviceManager.listener.event(event); assertEquals("The redundant notification should not have created additional notifications.", 0, events.size()); Iterable<ConnectPoint> pts = mgr.getEdgePoints(); Iterator pointIterator = pts.iterator(); int count = 0; for (; pointIterator.hasNext(); count++) { pointIterator.next(); } assertEquals("Unexpected number of edge points", totalPorts - numInfraPorts, count); events.clear(); event = (new DeviceEvent(DEVICE_REMOVED, referenceDevice, new DefaultPort(referenceDevice, PortNumber.portNumber(1), true))); testDeviceManager.listener.event(event); assertEquals("There should be five new events from removal of edge points", totalPorts - numInfraPorts, events.size()); for (int index = 0; index < events.size(); index++) { assertEquals("Port removed had unexpected port number.", events.get(index).subject().port(), (NetTestTools.connectPoint("a", index + numInfraPorts + 1).port())); assertEquals("Unexpected type of event", events.get(index).type(), EDGE_PORT_REMOVED); } events.clear(); testDeviceManager.listener.event(event); assertEquals("Rebroadcast of removal event should not produce additional events", 0, events.size()); events.clear(); addDevice(referenceDevice, "1", 5); devices.put(referenceDevice.id(), referenceDevice); event = new DeviceEvent(DEVICE_AVAILABILITY_CHANGED, referenceDevice); testDeviceManager.listener.event(event); assertEquals("An unexpected number of events were generated.", totalPorts - numInfraPorts, events.size()); for (int i = 0; i < 5; i++) { assertEquals("The event was not of the right type", events.get(i).type(), EDGE_PORT_ADDED); } events.clear(); testDeviceManager.listener.event(event); assertEquals("No events should have been generated for a set of existing ports.", 0, events.size()); removeDevice(referenceDevice); alwaysReturnPorts = true; testDeviceManager.listener.event(event); alwaysReturnPorts = false; assertEquals("An unexpected number of events were created.", totalPorts - numInfraPorts, events.size()); for (int i = 0; i < 5; i++) { EdgePortEvent edgeEvent = events.get(i); assertEquals("The event is of an unexpected type.", EdgePortEvent.Type.EDGE_PORT_REMOVED, edgeEvent.type()); assertEquals("The event pertains to an unexpected port", PortNumber.portNumber(i + numInfraPorts + 1), edgeEvent.subject().port()); } }
@Override public Iterable<ConnectPoint> getEdgePoints() { checkPermission(TOPOLOGY_READ); ImmutableSet.Builder<ConnectPoint> builder = ImmutableSet.builder(); connectionPoints.forEach((k, v) -> v.forEach(builder::add)); return builder.build(); }
EdgeManager extends AbstractListenerManager<EdgePortEvent, EdgePortListener> implements EdgePortService { @Override public Iterable<ConnectPoint> getEdgePoints() { checkPermission(TOPOLOGY_READ); ImmutableSet.Builder<ConnectPoint> builder = ImmutableSet.builder(); connectionPoints.forEach((k, v) -> v.forEach(builder::add)); return builder.build(); } }
EdgeManager extends AbstractListenerManager<EdgePortEvent, EdgePortListener> implements EdgePortService { @Override public Iterable<ConnectPoint> getEdgePoints() { checkPermission(TOPOLOGY_READ); ImmutableSet.Builder<ConnectPoint> builder = ImmutableSet.builder(); connectionPoints.forEach((k, v) -> v.forEach(builder::add)); return builder.build(); }  }
EdgeManager extends AbstractListenerManager<EdgePortEvent, EdgePortListener> implements EdgePortService { @Override public Iterable<ConnectPoint> getEdgePoints() { checkPermission(TOPOLOGY_READ); ImmutableSet.Builder<ConnectPoint> builder = ImmutableSet.builder(); connectionPoints.forEach((k, v) -> v.forEach(builder::add)); return builder.build(); }  @Activate void activate(); @Deactivate void deactivate(); @Override boolean isEdgePoint(ConnectPoint point); @Override Iterable<ConnectPoint> getEdgePoints(); @Override Iterable<ConnectPoint> getEdgePoints(DeviceId deviceId); @Override void emitPacket(ByteBuffer data, Optional<TrafficTreatment> treatment); @Override void emitPacket(DeviceId deviceId, ByteBuffer data,
                           Optional<TrafficTreatment> treatment); }
EdgeManager extends AbstractListenerManager<EdgePortEvent, EdgePortListener> implements EdgePortService { @Override public Iterable<ConnectPoint> getEdgePoints() { checkPermission(TOPOLOGY_READ); ImmutableSet.Builder<ConnectPoint> builder = ImmutableSet.builder(); connectionPoints.forEach((k, v) -> v.forEach(builder::add)); return builder.build(); }  @Activate void activate(); @Deactivate void deactivate(); @Override boolean isEdgePoint(ConnectPoint point); @Override Iterable<ConnectPoint> getEdgePoints(); @Override Iterable<ConnectPoint> getEdgePoints(DeviceId deviceId); @Override void emitPacket(ByteBuffer data, Optional<TrafficTreatment> treatment); @Override void emitPacket(DeviceId deviceId, ByteBuffer data,
                           Optional<TrafficTreatment> treatment);  }