Jonathan Hart
Committed by Gerrit Code Review

Move EdgeService back to Link/Device services rather than TopologyService.

I think the EdgeService has to use one or the other, because the
TopologyService is not in sync with the Link/Device services. The problem
with using the TopologyService is that it does not handle Port events,
only Device and Link, so it is not suitable for building an inventory of
edge ports.

Change-Id: If31d6d7013985da3e03f8c83f2f2eb2957deffe1
...@@ -18,8 +18,14 @@ package org.onosproject.cli.net; ...@@ -18,8 +18,14 @@ package org.onosproject.cli.net;
18 import org.apache.karaf.shell.commands.Argument; 18 import org.apache.karaf.shell.commands.Argument;
19 import org.apache.karaf.shell.commands.Command; 19 import org.apache.karaf.shell.commands.Command;
20 import org.onosproject.cli.AbstractShellCommand; 20 import org.onosproject.cli.AbstractShellCommand;
21 +import org.onosproject.net.ConnectPoint;
21 import org.onosproject.net.edge.EdgePortService; 22 import org.onosproject.net.edge.EdgePortService;
23 +import org.onosproject.utils.Comparators;
22 24
25 +import java.util.Collections;
26 +import java.util.List;
27 +
28 +import static com.google.common.collect.Lists.newArrayList;
23 import static org.onosproject.net.DeviceId.deviceId; 29 import static org.onosproject.net.DeviceId.deviceId;
24 30
25 /** 31 /**
...@@ -35,16 +41,24 @@ public class EdgePortsListCommand extends AbstractShellCommand { ...@@ -35,16 +41,24 @@ public class EdgePortsListCommand extends AbstractShellCommand {
35 required = false, multiValued = false) 41 required = false, multiValued = false)
36 String uri = null; 42 String uri = null;
37 43
38 -
39 -
40 @Override 44 @Override
41 protected void execute() { 45 protected void execute() {
42 EdgePortService service = get(EdgePortService.class); 46 EdgePortService service = get(EdgePortService.class);
43 if (uri == null) { 47 if (uri == null) {
44 - service.getEdgePoints().forEach(e -> print(FMT, e.deviceId(), e.port())); 48 + printEdgePoints(service.getEdgePoints());
45 } else { 49 } else {
46 - service.getEdgePoints(deviceId(uri)).forEach(e -> print(FMT, e.deviceId(), e.port())); 50 + printEdgePoints(service.getEdgePoints(deviceId(uri)));
51 + }
47 } 52 }
53 +
54 + private void printEdgePoints(Iterable<ConnectPoint> edgePoints) {
55 + sort(edgePoints).forEach(e -> print(FMT, e.deviceId(), e.port()));
56 + }
57 +
58 + private static List<ConnectPoint> sort(Iterable<ConnectPoint> connectPoints) {
59 + List<ConnectPoint> edgePoints = newArrayList(connectPoints);
60 + Collections.sort(edgePoints, Comparators.CONNECT_POINT_COMPARATOR);
61 + return edgePoints;
48 } 62 }
49 63
50 } 64 }
......
...@@ -229,6 +229,7 @@ ...@@ -229,6 +229,7 @@
229 <action class="org.onosproject.cli.net.EdgePortsListCommand"/> 229 <action class="org.onosproject.cli.net.EdgePortsListCommand"/>
230 <completers> 230 <completers>
231 <ref component-id="deviceIdCompleter"/> 231 <ref component-id="deviceIdCompleter"/>
232 + <null/>
232 </completers> 233 </completers>
233 </command> 234 </command>
234 235
......
...@@ -31,6 +31,7 @@ import org.onosproject.net.ConnectPoint; ...@@ -31,6 +31,7 @@ import org.onosproject.net.ConnectPoint;
31 import org.onosproject.net.DeviceId; 31 import org.onosproject.net.DeviceId;
32 import org.onosproject.net.Link.Type; 32 import org.onosproject.net.Link.Type;
33 import org.onosproject.net.device.DeviceEvent; 33 import org.onosproject.net.device.DeviceEvent;
34 +import org.onosproject.net.device.DeviceListener;
34 import org.onosproject.net.device.DeviceService; 35 import org.onosproject.net.device.DeviceService;
35 import org.onosproject.net.edge.EdgePortEvent; 36 import org.onosproject.net.edge.EdgePortEvent;
36 import org.onosproject.net.edge.EdgePortListener; 37 import org.onosproject.net.edge.EdgePortListener;
...@@ -38,25 +39,29 @@ import org.onosproject.net.edge.EdgePortService; ...@@ -38,25 +39,29 @@ import org.onosproject.net.edge.EdgePortService;
38 import org.onosproject.net.flow.DefaultTrafficTreatment; 39 import org.onosproject.net.flow.DefaultTrafficTreatment;
39 import org.onosproject.net.flow.TrafficTreatment; 40 import org.onosproject.net.flow.TrafficTreatment;
40 import org.onosproject.net.link.LinkEvent; 41 import org.onosproject.net.link.LinkEvent;
42 +import org.onosproject.net.link.LinkListener;
43 +import org.onosproject.net.link.LinkService;
41 import org.onosproject.net.packet.DefaultOutboundPacket; 44 import org.onosproject.net.packet.DefaultOutboundPacket;
42 import org.onosproject.net.packet.OutboundPacket; 45 import org.onosproject.net.packet.OutboundPacket;
43 import org.onosproject.net.packet.PacketService; 46 import org.onosproject.net.packet.PacketService;
44 -import org.onosproject.net.topology.Topology;
45 -import org.onosproject.net.topology.TopologyEvent;
46 -import org.onosproject.net.topology.TopologyListener;
47 -import org.onosproject.net.topology.TopologyService;
48 import org.slf4j.Logger; 47 import org.slf4j.Logger;
49 48
50 import java.nio.ByteBuffer; 49 import java.nio.ByteBuffer;
51 import java.util.Map; 50 import java.util.Map;
52 import java.util.Optional; 51 import java.util.Optional;
53 import java.util.Set; 52 import java.util.Set;
54 -import static org.onosproject.net.device.DeviceEvent.Type.*; 53 +
54 +import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_ADDED;
55 +import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED;
56 +import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_REMOVED;
57 +import static org.onosproject.net.device.DeviceEvent.Type.PORT_STATS_UPDATED;
58 +import static org.onosproject.net.device.DeviceEvent.Type.PORT_UPDATED;
55 import static org.onosproject.net.edge.EdgePortEvent.Type.EDGE_PORT_ADDED; 59 import static org.onosproject.net.edge.EdgePortEvent.Type.EDGE_PORT_ADDED;
56 import static org.onosproject.net.edge.EdgePortEvent.Type.EDGE_PORT_REMOVED; 60 import static org.onosproject.net.edge.EdgePortEvent.Type.EDGE_PORT_REMOVED;
57 -import static org.slf4j.LoggerFactory.getLogger;
58 import static org.onosproject.security.AppGuard.checkPermission; 61 import static org.onosproject.security.AppGuard.checkPermission;
59 -import static org.onosproject.security.AppPermission.Type.*; 62 +import static org.onosproject.security.AppPermission.Type.PACKET_WRITE;
63 +import static org.onosproject.security.AppPermission.Type.TOPOLOGY_READ;
64 +import static org.slf4j.LoggerFactory.getLogger;
60 65
61 /** 66 /**
62 * This is an implementation of the edge net service. 67 * This is an implementation of the edge net service.
...@@ -69,14 +74,11 @@ public class EdgeManager ...@@ -69,14 +74,11 @@ public class EdgeManager
69 74
70 private final Logger log = getLogger(getClass()); 75 private final Logger log = getLogger(getClass());
71 76
72 - private Topology topology; 77 + // Set of edge ConnectPoints per Device.
73 -
74 - /**
75 - * Set of edge ConnectPoints per Device.
76 - */
77 private final Map<DeviceId, Set<ConnectPoint>> connectionPoints = Maps.newConcurrentMap(); 78 private final Map<DeviceId, Set<ConnectPoint>> connectionPoints = Maps.newConcurrentMap();
78 79
79 - private final TopologyListener topologyListener = new InnerTopologyListener(); 80 + private final DeviceListener deviceListener = new InnerDeviceListener();
81 + private final LinkListener linkListener = new InnerLinkListener();
80 82
81 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 83 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
82 protected PacketService packetService; 84 protected PacketService packetService;
...@@ -85,19 +87,21 @@ public class EdgeManager ...@@ -85,19 +87,21 @@ public class EdgeManager
85 protected DeviceService deviceService; 87 protected DeviceService deviceService;
86 88
87 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 89 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
88 - protected TopologyService topologyService; 90 + protected LinkService linkService;
89 91
90 @Activate 92 @Activate
91 public void activate() { 93 public void activate() {
92 eventDispatcher.addSink(EdgePortEvent.class, listenerRegistry); 94 eventDispatcher.addSink(EdgePortEvent.class, listenerRegistry);
93 - topologyService.addListener(topologyListener); 95 + deviceService.addListener(deviceListener);
96 + linkService.addListener(linkListener);
94 loadAllEdgePorts(); 97 loadAllEdgePorts();
95 log.info("Started"); 98 log.info("Started");
96 } 99 }
97 100
98 @Deactivate 101 @Deactivate
99 public void deactivate() { 102 public void deactivate() {
100 - topologyService.removeListener(topologyListener); 103 + deviceService.removeListener(deviceListener);
104 + linkService.removeListener(linkListener);
101 eventDispatcher.removeSink(EdgePortEvent.class); 105 eventDispatcher.removeSink(EdgePortEvent.class);
102 log.info("Stopped"); 106 log.info("Stopped");
103 } 107 }
...@@ -105,7 +109,8 @@ public class EdgeManager ...@@ -105,7 +109,8 @@ public class EdgeManager
105 @Override 109 @Override
106 public boolean isEdgePoint(ConnectPoint point) { 110 public boolean isEdgePoint(ConnectPoint point) {
107 checkPermission(TOPOLOGY_READ); 111 checkPermission(TOPOLOGY_READ);
108 - return !topologyService.isInfrastructure(topologyService.currentTopology(), point); 112 + Set<ConnectPoint> connectPoints = connectionPoints.get(point.deviceId());
113 + return connectPoints != null && connectPoints.contains(point);
109 } 114 }
110 115
111 @Override 116 @Override
...@@ -148,26 +153,25 @@ public class EdgeManager ...@@ -148,26 +153,25 @@ public class EdgeManager
148 return new DefaultOutboundPacket(point.deviceId(), builder.build(), data); 153 return new DefaultOutboundPacket(point.deviceId(), builder.build(), data);
149 } 154 }
150 155
151 - private class InnerTopologyListener implements TopologyListener { 156 + private class InnerLinkListener implements LinkListener {
157 + @Override
158 + public void event(LinkEvent event) {
159 + processLinkEvent(event);
160 + }
161 + }
152 162
163 + private class InnerDeviceListener implements DeviceListener {
153 @Override 164 @Override
154 - public void event(TopologyEvent event) { 165 + public void event(DeviceEvent event) {
155 - log.trace("Processing TopologyEvent {} caused by {}", 166 + if (event.type() == PORT_STATS_UPDATED) {
156 - event.subject(), event.reasons()); 167 + return;
157 - topology = event.subject();
158 - event.reasons().forEach(reason -> {
159 - if (reason instanceof DeviceEvent) {
160 - processDeviceEvent((DeviceEvent) reason);
161 - } else if (reason instanceof LinkEvent) {
162 - processLinkEvent((LinkEvent) reason);
163 } 168 }
164 - }); 169 + processDeviceEvent(event);
165 } 170 }
166 } 171 }
167 172
168 // Initial loading of the edge port cache. 173 // Initial loading of the edge port cache.
169 private void loadAllEdgePorts() { 174 private void loadAllEdgePorts() {
170 - topology = topologyService.currentTopology();
171 deviceService.getAvailableDevices().forEach(d -> deviceService.getPorts(d.id()) 175 deviceService.getAvailableDevices().forEach(d -> deviceService.getPorts(d.id())
172 .forEach(p -> addEdgePort(new ConnectPoint(d.id(), p.number())))); 176 .forEach(p -> addEdgePort(new ConnectPoint(d.id(), p.number()))));
173 } 177 }
...@@ -177,8 +181,7 @@ public class EdgeManager ...@@ -177,8 +181,7 @@ public class EdgeManager
177 // negative Link event can result in increase of edge ports 181 // negative Link event can result in increase of edge ports
178 boolean addEdgePort = event.type() == LinkEvent.Type.LINK_REMOVED; 182 boolean addEdgePort = event.type() == LinkEvent.Type.LINK_REMOVED;
179 183
180 - // but if the Link is an Edge type, 184 + // but if the Link is an Edge type, it will be the opposite
181 - // it will be the opposite
182 if (event.subject().type() == Type.EDGE) { 185 if (event.subject().type() == Type.EDGE) {
183 addEdgePort = !addEdgePort; 186 addEdgePort = !addEdgePort;
184 } 187 }
...@@ -198,8 +201,6 @@ public class EdgeManager ...@@ -198,8 +201,6 @@ public class EdgeManager
198 DeviceEvent.Type type = event.type(); 201 DeviceEvent.Type type = event.type();
199 DeviceId id = event.subject().id(); 202 DeviceId id = event.subject().id();
200 203
201 - // FIXME there's still chance that Topology and Device Service
202 - // view is out-of-sync
203 if (type == DEVICE_ADDED || 204 if (type == DEVICE_ADDED ||
204 type == DEVICE_AVAILABILITY_CHANGED && deviceService.isAvailable(id)) { 205 type == DEVICE_AVAILABILITY_CHANGED && deviceService.isAvailable(id)) {
205 // When device is added or becomes available, add all its ports 206 // When device is added or becomes available, add all its ports
...@@ -223,8 +224,11 @@ public class EdgeManager ...@@ -223,8 +224,11 @@ public class EdgeManager
223 } 224 }
224 225
225 private boolean isEdgePort(ConnectPoint point) { 226 private boolean isEdgePort(ConnectPoint point) {
226 - return !topologyService.isInfrastructure(topology, point) && 227 + // Logical ports are not counted as edge ports nor are infrastructure
227 - !point.port().isLogical(); 228 + // ports. Ports that have only edge links are considered edge ports.
229 + return !point.port().isLogical() &&
230 + linkService.getLinks(point).stream()
231 + .allMatch(link -> link.type() == Type.EDGE);
228 } 232 }
229 233
230 // Adds the specified connection point to the edge points if needed. 234 // Adds the specified connection point to the edge points if needed.
......
...@@ -19,7 +19,6 @@ import com.google.common.collect.ImmutableList; ...@@ -19,7 +19,6 @@ import com.google.common.collect.ImmutableList;
19 import com.google.common.collect.Lists; 19 import com.google.common.collect.Lists;
20 import com.google.common.collect.Maps; 20 import com.google.common.collect.Maps;
21 import com.google.common.collect.Sets; 21 import com.google.common.collect.Sets;
22 -
23 import org.junit.After; 22 import org.junit.After;
24 import org.junit.Before; 23 import org.junit.Before;
25 import org.junit.Test; 24 import org.junit.Test;
...@@ -29,6 +28,7 @@ import org.onosproject.net.ConnectPoint; ...@@ -29,6 +28,7 @@ import org.onosproject.net.ConnectPoint;
29 import org.onosproject.net.DefaultPort; 28 import org.onosproject.net.DefaultPort;
30 import org.onosproject.net.Device; 29 import org.onosproject.net.Device;
31 import org.onosproject.net.DeviceId; 30 import org.onosproject.net.DeviceId;
31 +import org.onosproject.net.Link;
32 import org.onosproject.net.NetTestTools; 32 import org.onosproject.net.NetTestTools;
33 import org.onosproject.net.Port; 33 import org.onosproject.net.Port;
34 import org.onosproject.net.PortNumber; 34 import org.onosproject.net.PortNumber;
...@@ -38,26 +38,32 @@ import org.onosproject.net.device.DeviceServiceAdapter; ...@@ -38,26 +38,32 @@ import org.onosproject.net.device.DeviceServiceAdapter;
38 import org.onosproject.net.edge.EdgePortEvent; 38 import org.onosproject.net.edge.EdgePortEvent;
39 import org.onosproject.net.edge.EdgePortListener; 39 import org.onosproject.net.edge.EdgePortListener;
40 import org.onosproject.net.link.LinkEvent; 40 import org.onosproject.net.link.LinkEvent;
41 +import org.onosproject.net.link.LinkListener;
42 +import org.onosproject.net.link.LinkServiceAdapter;
41 import org.onosproject.net.packet.OutboundPacket; 43 import org.onosproject.net.packet.OutboundPacket;
42 import org.onosproject.net.packet.PacketServiceAdapter; 44 import org.onosproject.net.packet.PacketServiceAdapter;
43 -import org.onosproject.net.topology.Topology;
44 import org.onosproject.net.topology.TopologyEvent; 45 import org.onosproject.net.topology.TopologyEvent;
45 import org.onosproject.net.topology.TopologyEvent.Type; 46 import org.onosproject.net.topology.TopologyEvent.Type;
46 -import org.onosproject.net.topology.TopologyListener;
47 -import org.onosproject.net.topology.TopologyServiceAdapter;
48 47
49 import java.nio.ByteBuffer; 48 import java.nio.ByteBuffer;
50 import java.util.ArrayList; 49 import java.util.ArrayList;
50 +import java.util.Collections;
51 import java.util.Iterator; 51 import java.util.Iterator;
52 import java.util.List; 52 import java.util.List;
53 import java.util.Map; 53 import java.util.Map;
54 import java.util.Optional; 54 import java.util.Optional;
55 import java.util.Set; 55 import java.util.Set;
56 56
57 -import static org.hamcrest.Matchers.*; 57 +import static org.hamcrest.Matchers.greaterThanOrEqualTo;
58 -import static org.junit.Assert.*; 58 +import static org.hamcrest.Matchers.is;
59 +import static org.junit.Assert.assertEquals;
60 +import static org.junit.Assert.assertFalse;
61 +import static org.junit.Assert.assertThat;
62 +import static org.junit.Assert.assertTrue;
59 import static org.onosproject.net.NetTestTools.injectEventDispatcher; 63 import static org.onosproject.net.NetTestTools.injectEventDispatcher;
60 -import static org.onosproject.net.device.DeviceEvent.Type.*; 64 +import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_ADDED;
65 +import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED;
66 +import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_REMOVED;
61 import static org.onosproject.net.edge.EdgePortEvent.Type.EDGE_PORT_ADDED; 67 import static org.onosproject.net.edge.EdgePortEvent.Type.EDGE_PORT_ADDED;
62 import static org.onosproject.net.edge.EdgePortEvent.Type.EDGE_PORT_REMOVED; 68 import static org.onosproject.net.edge.EdgePortEvent.Type.EDGE_PORT_REMOVED;
63 import static org.onosproject.net.link.LinkEvent.Type.LINK_ADDED; 69 import static org.onosproject.net.link.LinkEvent.Type.LINK_ADDED;
...@@ -78,23 +84,23 @@ public class EdgeManagerTest { ...@@ -78,23 +84,23 @@ public class EdgeManagerTest {
78 private Set<OutboundPacket> packets = Sets.newConcurrentHashSet(); 84 private Set<OutboundPacket> packets = Sets.newConcurrentHashSet();
79 private final EdgePortListener testListener = new TestListener(events); 85 private final EdgePortListener testListener = new TestListener(events);
80 private TestDeviceManager testDeviceManager; 86 private TestDeviceManager testDeviceManager;
81 - private TestTopologyManager testTopologyManager; 87 + private TestLinkService testLinkService;
82 88
83 @Before 89 @Before
84 public void setUp() { 90 public void setUp() {
85 mgr = new EdgeManager(); 91 mgr = new EdgeManager();
86 injectEventDispatcher(mgr, new TestEventDispatcher()); 92 injectEventDispatcher(mgr, new TestEventDispatcher());
87 - testTopologyManager = new TestTopologyManager(infrastructurePorts);
88 - mgr.topologyService = testTopologyManager;
89 testDeviceManager = new TestDeviceManager(devices); 93 testDeviceManager = new TestDeviceManager(devices);
90 mgr.deviceService = testDeviceManager; 94 mgr.deviceService = testDeviceManager;
95 +
96 + testLinkService = new TestLinkService();
97 + mgr.linkService = testLinkService;
98 +
91 mgr.packetService = new TestPacketManager(); 99 mgr.packetService = new TestPacketManager();
92 mgr.activate(); 100 mgr.activate();
93 mgr.addListener(testListener); 101 mgr.addListener(testListener);
94 -
95 } 102 }
96 103
97 -
98 @After 104 @After
99 public void tearDown() { 105 public void tearDown() {
100 mgr.removeListener(testListener); 106 mgr.removeListener(testListener);
...@@ -110,13 +116,12 @@ public class EdgeManagerTest { ...@@ -110,13 +116,12 @@ public class EdgeManagerTest {
110 116
111 assertEquals("Unexpected number of ports", numDevices * numPorts, infrastructurePorts.size()); 117 assertEquals("Unexpected number of ports", numDevices * numPorts, infrastructurePorts.size());
112 118
113 - assertFalse("no ports expected", mgr.getEdgePoints().iterator().hasNext());
114 -
115 assertFalse("Expected isEdge to return false", 119 assertFalse("Expected isEdge to return false",
116 mgr.isEdgePoint(NetTestTools.connectPoint(Integer.toString(1), 1))); 120 mgr.isEdgePoint(NetTestTools.connectPoint(Integer.toString(1), 1)));
117 121
118 removeInfraPort(NetTestTools.connectPoint(Integer.toString(1), 1)); 122 removeInfraPort(NetTestTools.connectPoint(Integer.toString(1), 1));
119 - assertTrue("Expected isEdge to return false", 123 + postTopologyEvent(new LinkEvent(LINK_REMOVED, NetTestTools.link(Integer.toString(1), 1, "b", 2)));
124 + assertTrue("Expected isEdge to return true",
120 mgr.isEdgePoint(NetTestTools.connectPoint(Integer.toString(1), 1))); 125 mgr.isEdgePoint(NetTestTools.connectPoint(Integer.toString(1), 1)));
121 } 126 }
122 127
...@@ -190,17 +195,25 @@ public class EdgeManagerTest { ...@@ -190,17 +195,25 @@ public class EdgeManagerTest {
190 int numDevices = 10; 195 int numDevices = 10;
191 int numInfraPorts = 5; 196 int numInfraPorts = 5;
192 totalPorts = 10; 197 totalPorts = 10;
198 +
193 defaultPopulator(numDevices, numInfraPorts); 199 defaultPopulator(numDevices, numInfraPorts);
194 200
201 + events.clear();
202 +
195 //Test response to device added events 203 //Test response to device added events
196 - referenceDevice = NetTestTools.device("1"); 204 +
205 + referenceDevice = NetTestTools.device("11");
206 + devices.put(referenceDevice.id(), referenceDevice);
207 + for (int port = 1; port <= numInfraPorts; port++) {
208 + infrastructurePorts.add(NetTestTools.connectPoint("11", port));
209 + }
197 event = new DeviceEvent(DEVICE_ADDED, referenceDevice, 210 event = new DeviceEvent(DEVICE_ADDED, referenceDevice,
198 new DefaultPort(referenceDevice, PortNumber.portNumber(1), true)); 211 new DefaultPort(referenceDevice, PortNumber.portNumber(1), true));
199 postTopologyEvent(event); 212 postTopologyEvent(event);
200 213
201 //Check that ports were populated correctly 214 //Check that ports were populated correctly
202 assertTrue("Unexpected number of new ports added", 215 assertTrue("Unexpected number of new ports added",
203 - mgr.deviceService.getPorts(NetTestTools.did("1")).size() == 10); 216 + mgr.deviceService.getPorts(NetTestTools.did("11")).size() == 10);
204 217
205 //Check that of the ten ports the half that are infrastructure ports aren't added 218 //Check that of the ten ports the half that are infrastructure ports aren't added
206 assertEquals("Unexpected number of new edge ports added", (totalPorts - numInfraPorts), events.size()); 219 assertEquals("Unexpected number of new edge ports added", (totalPorts - numInfraPorts), events.size());
...@@ -227,7 +240,7 @@ public class EdgeManagerTest { ...@@ -227,7 +240,7 @@ public class EdgeManagerTest {
227 for (; pointIterator.hasNext(); count++) { 240 for (; pointIterator.hasNext(); count++) {
228 pointIterator.next(); 241 pointIterator.next();
229 } 242 }
230 - assertEquals("Unexpected number of edge points", totalPorts - numInfraPorts, count); 243 + assertEquals("Unexpected number of edge points", (numDevices + 1) * numInfraPorts, count);
231 //Testing device removal 244 //Testing device removal
232 events.clear(); 245 events.clear();
233 event = (new DeviceEvent(DEVICE_REMOVED, referenceDevice, 246 event = (new DeviceEvent(DEVICE_REMOVED, referenceDevice,
...@@ -271,10 +284,11 @@ public class EdgeManagerTest { ...@@ -271,10 +284,11 @@ public class EdgeManagerTest {
271 284
272 //Ensure that the deviceManager shows the device as unavailable 285 //Ensure that the deviceManager shows the device as unavailable
273 removeDevice(referenceDevice); 286 removeDevice(referenceDevice);
274 - /*This variable copies the behavior of the topology by returning ports attached to an unavailable device 287 + // This variable copies the behavior of the topology by returning ports
275 - //this behavior is necessary for the following event to execute properly, if these statements are removed 288 + // attached to an unavailable device this behavior is necessary for the
276 - no events will be generated since no ports will be provided in getPorts() to EdgeManager. 289 + // following event to execute properly, if these statements are removed
277 - */ 290 + // no events will be generated since no ports will be provided in
291 + // getPorts() to EdgeManager.
278 alwaysReturnPorts = true; 292 alwaysReturnPorts = true;
279 postTopologyEvent(event); 293 postTopologyEvent(event);
280 alwaysReturnPorts = false; 294 alwaysReturnPorts = false;
...@@ -330,7 +344,6 @@ public class EdgeManagerTest { ...@@ -330,7 +344,6 @@ public class EdgeManagerTest {
330 } 344 }
331 } 345 }
332 346
333 -
334 @Test 347 @Test
335 public void testEmit() { 348 public void testEmit() {
336 byte[] arr = new byte[10]; 349 byte[] arr = new byte[10];
...@@ -345,7 +358,7 @@ public class EdgeManagerTest { ...@@ -345,7 +358,7 @@ public class EdgeManagerTest {
345 } 358 }
346 for (int i = 0; i < numDevices; i++) { 359 for (int i = 0; i < numDevices; i++) {
347 referenceDevice = NetTestTools.device(Integer.toString(i)); 360 referenceDevice = NetTestTools.device(Integer.toString(i));
348 - postTopologyEvent(new DeviceEvent(DEVICE_ADDED, referenceDevice, 361 + testDeviceManager.listener.event(new DeviceEvent(DEVICE_ADDED, referenceDevice,
349 new DefaultPort(referenceDevice, 362 new DefaultPort(referenceDevice,
350 PortNumber.portNumber(1), 363 PortNumber.portNumber(1),
351 true))); 364 true)));
...@@ -392,7 +405,13 @@ public class EdgeManagerTest { ...@@ -392,7 +405,13 @@ public class EdgeManagerTest {
392 * @param event Event 405 * @param event Event
393 */ 406 */
394 private void postTopologyEvent(Event event) { 407 private void postTopologyEvent(Event event) {
395 - testTopologyManager.listener.event(topologyEventOf(event)); 408 + if (event instanceof DeviceEvent) {
409 + testDeviceManager.listener.event((DeviceEvent) event);
410 + }
411 + if (event instanceof LinkEvent) {
412 + testLinkService.listener.event((LinkEvent) event);
413 + }
414 + //testTopologyManager.listener.event(topologyEventOf(event));
396 } 415 }
397 416
398 417
...@@ -406,7 +425,9 @@ public class EdgeManagerTest { ...@@ -406,7 +425,9 @@ public class EdgeManagerTest {
406 String str = Integer.toString(device); 425 String str = Integer.toString(device);
407 Device deviceToAdd = NetTestTools.device(str); 426 Device deviceToAdd = NetTestTools.device(str);
408 devices.put(deviceToAdd.id(), deviceToAdd); 427 devices.put(deviceToAdd.id(), deviceToAdd);
428 + testDeviceManager.listener.event(new DeviceEvent(DEVICE_ADDED, deviceToAdd));
409 for (int port = 1; port <= numInfraPorts; port++) { 429 for (int port = 1; port <= numInfraPorts; port++) {
430 + testLinkService.listener.event(new LinkEvent(LINK_ADDED, NetTestTools.link(str, port, "other", 1)));
410 infrastructurePorts.add(NetTestTools.connectPoint(str, port)); 431 infrastructurePorts.add(NetTestTools.connectPoint(str, port));
411 } 432 }
412 } 433 }
...@@ -436,30 +457,6 @@ public class EdgeManagerTest { ...@@ -436,30 +457,6 @@ public class EdgeManagerTest {
436 infrastructurePorts.remove(port); 457 infrastructurePorts.remove(port);
437 } 458 }
438 459
439 - private class TestTopologyManager extends TopologyServiceAdapter {
440 - private TopologyListener listener;
441 - private Set<ConnectPoint> infrastructurePorts;
442 -
443 - public TestTopologyManager(Set<ConnectPoint> infrastructurePorts) {
444 - this.infrastructurePorts = infrastructurePorts;
445 - }
446 -
447 - @Override
448 - public boolean isInfrastructure(Topology topology, ConnectPoint connectPoint) {
449 - return infrastructurePorts.contains(connectPoint);
450 - }
451 -
452 - @Override
453 - public void addListener(TopologyListener listener) {
454 - this.listener = listener;
455 - }
456 -
457 - @Override
458 - public void removeListener(TopologyListener listener) {
459 - this.listener = null;
460 - }
461 - }
462 -
463 private class TestDeviceManager extends DeviceServiceAdapter { 460 private class TestDeviceManager extends DeviceServiceAdapter {
464 private DeviceListener listener; 461 private DeviceListener listener;
465 462
...@@ -510,6 +507,25 @@ public class EdgeManagerTest { ...@@ -510,6 +507,25 @@ public class EdgeManagerTest {
510 } 507 }
511 } 508 }
512 509
510 + private class TestLinkService extends LinkServiceAdapter {
511 +
512 + private LinkListener listener;
513 +
514 + @Override
515 + public Set<Link> getLinks(ConnectPoint connectPoint) {
516 + if (infrastructurePorts.contains(connectPoint)) {
517 + return Collections.singleton(NetTestTools.link("1", 1, "2", 1));
518 + } else {
519 + return Collections.emptySet();
520 + }
521 + }
522 +
523 + @Override
524 + public void addListener(LinkListener listener) {
525 + this.listener = listener;
526 + }
527 + }
528 +
513 private class TestPacketManager extends PacketServiceAdapter { 529 private class TestPacketManager extends PacketServiceAdapter {
514 @Override 530 @Override
515 public void emit(OutboundPacket packet) { 531 public void emit(OutboundPacket packet) {
......