blob: 33a1cd651bfbb8e02d34c2aacef92ce902b3d270 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
Ray Milkey269ffb92014-04-03 14:43:30 -07002 * Copyright 2011, Big Switch Networks, Inc.
3 * Originally created by David Erickson, Stanford University
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may
6 * not use this file except in compliance with the License. You may obtain
7 * a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations
15 * under the License.
16 **/
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080017
Jonathan Hart23701d12014-04-03 10:45:48 -070018package net.onrc.onos.core.linkdiscovery.internal;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080019
Jonathan Hart2fa28062013-11-25 20:16:28 -080020import static org.easymock.EasyMock.createNiceMock;
21import static org.easymock.EasyMock.expect;
22import static org.easymock.EasyMock.replay;
23import static org.easymock.EasyMock.verify;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080024
srikanth9f383342014-06-12 11:49:00 -070025import java.io.IOException;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080026import java.util.ArrayList;
Jonathan Hart2fa28062013-11-25 20:16:28 -080027import java.util.Collections;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080028import java.util.HashMap;
29import java.util.Map;
30
srikanth9f383342014-06-12 11:49:00 -070031import net.floodlightcontroller.core.FloodlightContext;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080032import net.floodlightcontroller.core.IFloodlightProviderService;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080033import net.floodlightcontroller.core.IOFSwitch;
34import net.floodlightcontroller.core.module.FloodlightModuleContext;
35import net.floodlightcontroller.core.test.MockThreadPoolService;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080036import net.floodlightcontroller.restserver.IRestApiService;
37import net.floodlightcontroller.restserver.RestApiServer;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080038import net.floodlightcontroller.test.FloodlightTestCase;
39import net.floodlightcontroller.threadpool.IThreadPoolService;
Jonathan Hart23701d12014-04-03 10:45:48 -070040import net.onrc.onos.core.linkdiscovery.ILinkDiscoveryListener;
41import net.onrc.onos.core.linkdiscovery.ILinkDiscoveryService;
42import net.onrc.onos.core.linkdiscovery.Link;
43import net.onrc.onos.core.linkdiscovery.LinkInfo;
44import net.onrc.onos.core.linkdiscovery.NodePortTuple;
Jonathan Hart2fa28062013-11-25 20:16:28 -080045
srikanth9f383342014-06-12 11:49:00 -070046import org.easymock.EasyMock;
Jonathan Hart2fa28062013-11-25 20:16:28 -080047import org.junit.Before;
48import org.junit.Test;
srikanth9f383342014-06-12 11:49:00 -070049import org.openflow.protocol.OFMessage;
50import org.openflow.protocol.OFPhysicalPort;
Jonathan Hart2fa28062013-11-25 20:16:28 -080051import org.slf4j.Logger;
52import org.slf4j.LoggerFactory;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080053
54/**
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080055 * @author David Erickson (daviderickson@cs.stanford.edu)
56 */
57public class LinkDiscoveryManagerTest extends FloodlightTestCase {
58
59 private TestLinkDiscoveryManager ldm;
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -070060 protected static final Logger log = LoggerFactory.getLogger(LinkDiscoveryManagerTest.class);
Ray Milkey269ffb92014-04-03 14:43:30 -070061
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080062 public class TestLinkDiscoveryManager extends LinkDiscoveryManager {
63 public boolean isSendLLDPsCalled = false;
64 public boolean isClearLinksCalled = false;
65
66 @Override
67 protected void discoverOnAllPorts() {
68 isSendLLDPsCalled = true;
69 super.discoverOnAllPorts();
70 }
71
72 public void reset() {
73 isSendLLDPsCalled = false;
74 isClearLinksCalled = false;
75 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080076 }
Ray Milkey269ffb92014-04-03 14:43:30 -070077
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080078 public LinkDiscoveryManager getTopology() {
79 return ldm;
80 }
81
82 public IOFSwitch createMockSwitch(Long id) {
83 IOFSwitch mockSwitch = createNiceMock(IOFSwitch.class);
84 expect(mockSwitch.getId()).andReturn(id).anyTimes();
85 return mockSwitch;
86 }
87
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -070088 @Override
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080089 @Before
90 public void setUp() throws Exception {
91 super.setUp();
92 FloodlightModuleContext cntx = new FloodlightModuleContext();
93 ldm = new TestLinkDiscoveryManager();
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080094 ldm.linkDiscoveryAware = new ArrayList<ILinkDiscoveryListener>();
95 MockThreadPoolService tp = new MockThreadPoolService();
96 RestApiServer restApi = new RestApiServer();
97 cntx.addService(IRestApiService.class, restApi);
98 cntx.addService(IThreadPoolService.class, tp);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080099 cntx.addService(ILinkDiscoveryService.class, ldm);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800100 cntx.addService(IFloodlightProviderService.class, getMockFloodlightProvider());
101 restApi.init(cntx);
102 tp.init(cntx);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800103 ldm.init(cntx);
104 restApi.startUp(cntx);
105 tp.startUp(cntx);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800106 ldm.startUp(cntx);
107
108 IOFSwitch sw1 = createMockSwitch(1L);
109 IOFSwitch sw2 = createMockSwitch(2L);
110 Map<Long, IOFSwitch> switches = new HashMap<Long, IOFSwitch>();
111 switches.put(1L, sw1);
112 switches.put(2L, sw2);
113 getMockFloodlightProvider().setSwitches(switches);
114 replay(sw1, sw2);
115 }
116
117 @Test
118 public void testAddOrUpdateLink() throws Exception {
119 LinkDiscoveryManager topology = getTopology();
120
121 Link lt = new Link(1L, 2, 2L, 1);
122 LinkInfo info = new LinkInfo(System.currentTimeMillis(),
Ray Milkey269ffb92014-04-03 14:43:30 -0700123 System.currentTimeMillis(), null,
124 0, 0);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800125 topology.addOrUpdateLink(lt, info);
126
127
128 NodePortTuple srcNpt = new NodePortTuple(1L, 2);
129 NodePortTuple dstNpt = new NodePortTuple(2L, 1);
130
131 // check invariants hold
132 assertNotNull(topology.switchLinks.get(lt.getSrc()));
133 assertTrue(topology.switchLinks.get(lt.getSrc()).contains(lt));
134 assertNotNull(topology.portLinks.get(srcNpt));
135 assertTrue(topology.portLinks.get(srcNpt).contains(lt));
136 assertNotNull(topology.portLinks.get(dstNpt));
137 assertTrue(topology.portLinks.get(dstNpt).contains(lt));
138 assertTrue(topology.links.containsKey(lt));
139 }
140
141 @Test
142 public void testDeleteLink() throws Exception {
143 LinkDiscoveryManager topology = getTopology();
144
145 Link lt = new Link(1L, 2, 2L, 1);
146 LinkInfo info = new LinkInfo(System.currentTimeMillis(),
Ray Milkey269ffb92014-04-03 14:43:30 -0700147 System.currentTimeMillis(), null,
148 0, 0);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800149 topology.addOrUpdateLink(lt, info);
150 topology.deleteLinks(Collections.singletonList(lt), "Test");
151
152 // check invariants hold
153 assertNull(topology.switchLinks.get(lt.getSrc()));
154 assertNull(topology.switchLinks.get(lt.getDst()));
155 assertNull(topology.portLinks.get(lt.getSrc()));
156 assertNull(topology.portLinks.get(lt.getDst()));
157 assertTrue(topology.links.isEmpty());
158 }
159
160 @Test
161 public void testAddOrUpdateLinkToSelf() throws Exception {
162 LinkDiscoveryManager topology = getTopology();
163
164 Link lt = new Link(1L, 2, 2L, 3);
165 NodePortTuple srcNpt = new NodePortTuple(1L, 2);
166 NodePortTuple dstNpt = new NodePortTuple(2L, 3);
167
168 LinkInfo info = new LinkInfo(System.currentTimeMillis(),
Ray Milkey269ffb92014-04-03 14:43:30 -0700169 System.currentTimeMillis(), null,
170 0, 0);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800171 topology.addOrUpdateLink(lt, info);
172
173 // check invariants hold
174 assertNotNull(topology.switchLinks.get(lt.getSrc()));
175 assertTrue(topology.switchLinks.get(lt.getSrc()).contains(lt));
176 assertNotNull(topology.portLinks.get(srcNpt));
177 assertTrue(topology.portLinks.get(srcNpt).contains(lt));
178 assertNotNull(topology.portLinks.get(dstNpt));
179 assertTrue(topology.portLinks.get(dstNpt).contains(lt));
180 assertTrue(topology.links.containsKey(lt));
181 }
182
183 @Test
184 public void testDeleteLinkToSelf() throws Exception {
185 LinkDiscoveryManager topology = getTopology();
186
187 Link lt = new Link(1L, 2, 1L, 3);
188 NodePortTuple srcNpt = new NodePortTuple(1L, 2);
189 NodePortTuple dstNpt = new NodePortTuple(2L, 3);
190
191 LinkInfo info = new LinkInfo(System.currentTimeMillis(),
Ray Milkey269ffb92014-04-03 14:43:30 -0700192 System.currentTimeMillis(), null,
193 0, 0);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800194 topology.addOrUpdateLink(lt, info);
195 topology.deleteLinks(Collections.singletonList(lt), "Test to self");
196
197 // check invariants hold
198 assertNull(topology.switchLinks.get(lt.getSrc()));
199 assertNull(topology.switchLinks.get(lt.getDst()));
200 assertNull(topology.portLinks.get(srcNpt));
201 assertNull(topology.portLinks.get(dstNpt));
202 assertTrue(topology.links.isEmpty());
203 }
204
205 @Test
206 public void testRemovedSwitch() {
207 LinkDiscoveryManager topology = getTopology();
208
209 Link lt = new Link(1L, 2, 2L, 1);
210 NodePortTuple srcNpt = new NodePortTuple(1L, 2);
211 NodePortTuple dstNpt = new NodePortTuple(2L, 1);
212 LinkInfo info = new LinkInfo(System.currentTimeMillis(),
Ray Milkey269ffb92014-04-03 14:43:30 -0700213 System.currentTimeMillis(), null,
214 0, 0);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800215 topology.addOrUpdateLink(lt, info);
216
217 IOFSwitch sw1 = getMockFloodlightProvider().getSwitches().get(1L);
218 IOFSwitch sw2 = getMockFloodlightProvider().getSwitches().get(2L);
219 // Mock up our expected behavior
220 topology.removedSwitch(sw1);
221 verify(sw1, sw2);
222
223 // check invariants hold
224 assertNull(topology.switchLinks.get(lt.getSrc()));
225 assertNull(topology.switchLinks.get(lt.getDst()));
226 assertNull(topology.portLinks.get(srcNpt));
227 assertNull(topology.portLinks.get(dstNpt));
228 assertTrue(topology.links.isEmpty());
229 }
230
231 @Test
232 public void testRemovedSwitchSelf() {
233 LinkDiscoveryManager topology = getTopology();
234 IOFSwitch sw1 = createMockSwitch(1L);
235 replay(sw1);
236 Link lt = new Link(1L, 2, 1L, 3);
237 LinkInfo info = new LinkInfo(System.currentTimeMillis(),
Ray Milkey269ffb92014-04-03 14:43:30 -0700238 System.currentTimeMillis(), null,
239 0, 0);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800240 topology.addOrUpdateLink(lt, info);
241
242 // Mock up our expected behavior
243 topology.removedSwitch(sw1);
244
245 verify(sw1);
246 // check invariants hold
247 assertNull(topology.switchLinks.get(lt.getSrc()));
248 assertNull(topology.portLinks.get(lt.getSrc()));
249 assertNull(topology.portLinks.get(lt.getDst()));
250 assertTrue(topology.links.isEmpty());
251 }
252
253 @Test
254 public void testAddUpdateLinks() throws Exception {
255 LinkDiscoveryManager topology = getTopology();
256
257 Link lt = new Link(1L, 1, 2L, 1);
258 NodePortTuple srcNpt = new NodePortTuple(1L, 1);
259 NodePortTuple dstNpt = new NodePortTuple(2L, 1);
Ray Milkey269ffb92014-04-03 14:43:30 -0700260
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800261 LinkInfo info;
262
263 info = new LinkInfo(System.currentTimeMillis() - 40000,
Ray Milkey269ffb92014-04-03 14:43:30 -0700264 System.currentTimeMillis() - 40000, null,
265 0, 0);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800266 topology.addOrUpdateLink(lt, info);
267
268 // check invariants hold
269 assertNotNull(topology.switchLinks.get(lt.getSrc()));
270 assertTrue(topology.switchLinks.get(lt.getSrc()).contains(lt));
271 assertNotNull(topology.portLinks.get(srcNpt));
272 assertTrue(topology.portLinks.get(srcNpt).contains(lt));
273 assertNotNull(topology.portLinks.get(dstNpt));
274 assertTrue(topology.portLinks.get(dstNpt).contains(lt));
275 assertTrue(topology.links.containsKey(lt));
276 assertTrue(topology.portBroadcastDomainLinks.get(srcNpt) == null ||
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700277 !topology.portBroadcastDomainLinks.get(srcNpt).contains(lt));
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800278 assertTrue(topology.portBroadcastDomainLinks.get(dstNpt) == null ||
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700279 !topology.portBroadcastDomainLinks.get(dstNpt).contains(lt));
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800280
281 topology.timeoutLinks();
282
283
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700284 info = new LinkInfo(System.currentTimeMillis(), /* firstseen */
285 null, /* unicast */
Ray Milkey269ffb92014-04-03 14:43:30 -0700286 System.currentTimeMillis(), 0, 0);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800287 topology.addOrUpdateLink(lt, info);
288 assertTrue(topology.links.get(lt).getUnicastValidTime() == null);
289 assertTrue(topology.links.get(lt).getMulticastValidTime() != null);
290 assertTrue(topology.portBroadcastDomainLinks.get(srcNpt).contains(lt));
291 assertTrue(topology.portBroadcastDomainLinks.get(dstNpt).contains(lt));
292
293
294 // Add a link info based on info that woudld be obtained from unicast LLDP
295 // Setting the unicast LLDP reception time to be 40 seconds old, so we can use
296 // this to test timeout after this test. Although the info is initialized
297 // with LT_OPENFLOW_LINK, the link property should be changed to LT_NON_OPENFLOW
298 // by the addOrUpdateLink method.
299 info = new LinkInfo(System.currentTimeMillis() - 40000,
Ray Milkey269ffb92014-04-03 14:43:30 -0700300 System.currentTimeMillis() - 40000, null, 0, 0);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800301 topology.addOrUpdateLink(lt, info);
302 assertTrue(topology.portBroadcastDomainLinks.get(srcNpt) == null ||
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700303 !topology.portBroadcastDomainLinks.get(srcNpt).contains(lt));
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800304 assertTrue(topology.portBroadcastDomainLinks.get(dstNpt) == null ||
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700305 !topology.portBroadcastDomainLinks.get(dstNpt).contains(lt));
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800306
307 // Expect to timeout the unicast Valid Time, but not the multicast Valid time
308 // So the link type should go back to non-openflow link.
309 topology.timeoutLinks();
310 assertTrue(topology.links.get(lt).getUnicastValidTime() == null);
311 assertTrue(topology.links.get(lt).getMulticastValidTime() != null);
312 assertTrue(topology.portBroadcastDomainLinks.get(srcNpt).contains(lt));
313 assertTrue(topology.portBroadcastDomainLinks.get(dstNpt).contains(lt));
314
315 // Set the multicastValidTime to be old and see if that also times out.
316 info = new LinkInfo(System.currentTimeMillis() - 40000,
Ray Milkey269ffb92014-04-03 14:43:30 -0700317 null, System.currentTimeMillis() - 40000, 0, 0);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800318 topology.addOrUpdateLink(lt, info);
319 topology.timeoutLinks();
320 assertTrue(topology.links.get(lt) == null);
321 assertTrue(topology.portBroadcastDomainLinks.get(srcNpt) == null ||
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700322 !topology.portBroadcastDomainLinks.get(srcNpt).contains(lt));
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800323 assertTrue(topology.portBroadcastDomainLinks.get(dstNpt) == null ||
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700324 !topology.portBroadcastDomainLinks.get(dstNpt).contains(lt));
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800325
326
327 // Test again only with multicast LLDP
328 info = new LinkInfo(System.currentTimeMillis() - 40000,
Ray Milkey269ffb92014-04-03 14:43:30 -0700329 null, System.currentTimeMillis() - 40000, 0, 0);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800330 topology.addOrUpdateLink(lt, info);
331 assertTrue(topology.links.get(lt).getUnicastValidTime() == null);
332 assertTrue(topology.links.get(lt).getMulticastValidTime() != null);
333 assertTrue(topology.portBroadcastDomainLinks.get(srcNpt).contains(lt));
334 assertTrue(topology.portBroadcastDomainLinks.get(dstNpt).contains(lt));
335
336 // Call timeout and check if link is no longer present.
337 topology.timeoutLinks();
338 assertTrue(topology.links.get(lt) == null);
339 assertTrue(topology.portBroadcastDomainLinks.get(srcNpt) == null ||
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700340 !topology.portBroadcastDomainLinks.get(srcNpt).contains(lt));
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800341 assertTrue(topology.portBroadcastDomainLinks.get(dstNpt) == null ||
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700342 !topology.portBroadcastDomainLinks.get(dstNpt).contains(lt));
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800343
344 // Start clean and see if loops are also added.
345 lt = new Link(1L, 1, 1L, 2);
346 srcNpt = new NodePortTuple(1L, 1);
347 dstNpt = new NodePortTuple(1L, 2);
348 info = new LinkInfo(System.currentTimeMillis() - 40000,
Ray Milkey269ffb92014-04-03 14:43:30 -0700349 null, System.currentTimeMillis() - 40000, 0, 0);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800350 topology.addOrUpdateLink(lt, info);
351 assertTrue(topology.portBroadcastDomainLinks.get(srcNpt).contains(lt));
352 assertTrue(topology.portBroadcastDomainLinks.get(dstNpt).contains(lt));
353
354
355 // Start clean and see if loops are also added.
356 lt = new Link(1L, 1, 1L, 3);
357 srcNpt = new NodePortTuple(1L, 1);
358 dstNpt = new NodePortTuple(1L, 3);
359 info = new LinkInfo(System.currentTimeMillis() - 40000,
Ray Milkey269ffb92014-04-03 14:43:30 -0700360 null, System.currentTimeMillis() - 40000, 0, 0);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800361 topology.addOrUpdateLink(lt, info);
362 assertTrue(topology.portBroadcastDomainLinks.get(srcNpt).contains(lt));
363 assertTrue(topology.portBroadcastDomainLinks.get(dstNpt).contains(lt));
364
365
366 // Start clean and see if loops are also added.
367 lt = new Link(1L, 4, 1L, 5);
368 srcNpt = new NodePortTuple(1L, 4);
369 dstNpt = new NodePortTuple(1L, 5);
370 info = new LinkInfo(System.currentTimeMillis() - 40000,
Ray Milkey269ffb92014-04-03 14:43:30 -0700371 null, System.currentTimeMillis() - 40000, 0, 0);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800372 topology.addOrUpdateLink(lt, info);
373 assertTrue(topology.portBroadcastDomainLinks.get(srcNpt).contains(lt));
374 assertTrue(topology.portBroadcastDomainLinks.get(dstNpt).contains(lt));
375
376
377 // Start clean and see if loops are also added.
378 lt = new Link(1L, 3, 1L, 5);
379 srcNpt = new NodePortTuple(1L, 3);
380 dstNpt = new NodePortTuple(1L, 5);
381 info = new LinkInfo(System.currentTimeMillis() - 40000,
Ray Milkey269ffb92014-04-03 14:43:30 -0700382 null, System.currentTimeMillis() - 40000, 0, 0);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800383 topology.addOrUpdateLink(lt, info);
384 assertTrue(topology.portBroadcastDomainLinks.get(srcNpt).contains(lt));
385 assertTrue(topology.portBroadcastDomainLinks.get(dstNpt).contains(lt));
386 }
srikanth9f383342014-06-12 11:49:00 -0700387
388 /**
389 * This test case verifies that LinkDiscoveryManager.sendDiscoveryMessage()
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700390 * performs "write" operation on the specified IOFSwitch object
391 * with a LLDP packet.
392 *
srikanth9f383342014-06-12 11:49:00 -0700393 * @throws IOException
394 */
395 @Test
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700396 public void testSendDiscoveryMessage() throws IOException {
srikanth9f383342014-06-12 11:49:00 -0700397 LinkDiscoveryManager topology = getTopology();
398
399 // Mock up our expected behavior
400 IOFSwitch swTest = createMockSwitch(3L);
401 getMockFloodlightProvider().getSwitches().put(3L, swTest);
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700402
srikanth9f383342014-06-12 11:49:00 -0700403 short portNum = 1;
404 OFPhysicalPort ofpPort = new OFPhysicalPort();
405 ofpPort.setPortNumber(portNum);
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700406
407 /* sendDiscoverMessage() should perform the following actions on
srikanth9f383342014-06-12 11:49:00 -0700408 * IOFSwitch object
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700409 * - getPort() with argument as "1"
410 * - write() with OFPacketOut
411 * - flush()
srikanth9f383342014-06-12 11:49:00 -0700412 */
413 expect(swTest.getPort(portNum)).andReturn(ofpPort).atLeastOnce();
414 swTest.write(EasyMock.anyObject(OFMessage.class), EasyMock.anyObject(FloodlightContext.class));
415 EasyMock.expectLastCall().times(1);
416 swTest.flush();
417 EasyMock.expectLastCall().once();
418 replay(swTest);
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700419
srikanth9f383342014-06-12 11:49:00 -0700420 topology.sendDiscoveryMessage(3L, portNum, true, false);
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700421
srikanth9f383342014-06-12 11:49:00 -0700422 verify(swTest);
423 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800424}