blob: cdcf010894049c46daeb7e4484d76bd44bf8c921 [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
Yuta HIGUCHIaa132f52014-06-26 10:18:39 -070054// CHECKSTYLE IGNORE WriteTag FOR NEXT 2 LINES
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080055/**
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080056 * @author David Erickson (daviderickson@cs.stanford.edu)
57 */
58public class LinkDiscoveryManagerTest extends FloodlightTestCase {
59
60 private TestLinkDiscoveryManager ldm;
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -070061 protected static final Logger log = LoggerFactory.getLogger(LinkDiscoveryManagerTest.class);
Ray Milkey269ffb92014-04-03 14:43:30 -070062
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080063 public class TestLinkDiscoveryManager extends LinkDiscoveryManager {
64 public boolean isSendLLDPsCalled = false;
65 public boolean isClearLinksCalled = false;
66
67 @Override
68 protected void discoverOnAllPorts() {
69 isSendLLDPsCalled = true;
70 super.discoverOnAllPorts();
71 }
72
73 public void reset() {
74 isSendLLDPsCalled = false;
75 isClearLinksCalled = false;
76 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080077 }
Ray Milkey269ffb92014-04-03 14:43:30 -070078
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080079 public LinkDiscoveryManager getTopology() {
80 return ldm;
81 }
82
83 public IOFSwitch createMockSwitch(Long id) {
84 IOFSwitch mockSwitch = createNiceMock(IOFSwitch.class);
85 expect(mockSwitch.getId()).andReturn(id).anyTimes();
86 return mockSwitch;
87 }
88
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -070089 @Override
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080090 @Before
91 public void setUp() throws Exception {
92 super.setUp();
93 FloodlightModuleContext cntx = new FloodlightModuleContext();
94 ldm = new TestLinkDiscoveryManager();
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080095 ldm.linkDiscoveryAware = new ArrayList<ILinkDiscoveryListener>();
96 MockThreadPoolService tp = new MockThreadPoolService();
97 RestApiServer restApi = new RestApiServer();
98 cntx.addService(IRestApiService.class, restApi);
99 cntx.addService(IThreadPoolService.class, tp);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800100 cntx.addService(ILinkDiscoveryService.class, ldm);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800101 cntx.addService(IFloodlightProviderService.class, getMockFloodlightProvider());
102 restApi.init(cntx);
103 tp.init(cntx);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800104 ldm.init(cntx);
105 restApi.startUp(cntx);
106 tp.startUp(cntx);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800107 ldm.startUp(cntx);
108
109 IOFSwitch sw1 = createMockSwitch(1L);
110 IOFSwitch sw2 = createMockSwitch(2L);
111 Map<Long, IOFSwitch> switches = new HashMap<Long, IOFSwitch>();
112 switches.put(1L, sw1);
113 switches.put(2L, sw2);
114 getMockFloodlightProvider().setSwitches(switches);
115 replay(sw1, sw2);
116 }
117
118 @Test
119 public void testAddOrUpdateLink() throws Exception {
120 LinkDiscoveryManager topology = getTopology();
121
122 Link lt = new Link(1L, 2, 2L, 1);
123 LinkInfo info = new LinkInfo(System.currentTimeMillis(),
Ray Milkey269ffb92014-04-03 14:43:30 -0700124 System.currentTimeMillis(), null,
125 0, 0);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800126 topology.addOrUpdateLink(lt, info);
127
128
129 NodePortTuple srcNpt = new NodePortTuple(1L, 2);
130 NodePortTuple dstNpt = new NodePortTuple(2L, 1);
131
132 // check invariants hold
133 assertNotNull(topology.switchLinks.get(lt.getSrc()));
134 assertTrue(topology.switchLinks.get(lt.getSrc()).contains(lt));
135 assertNotNull(topology.portLinks.get(srcNpt));
136 assertTrue(topology.portLinks.get(srcNpt).contains(lt));
137 assertNotNull(topology.portLinks.get(dstNpt));
138 assertTrue(topology.portLinks.get(dstNpt).contains(lt));
139 assertTrue(topology.links.containsKey(lt));
140 }
141
142 @Test
143 public void testDeleteLink() throws Exception {
144 LinkDiscoveryManager topology = getTopology();
145
146 Link lt = new Link(1L, 2, 2L, 1);
147 LinkInfo info = new LinkInfo(System.currentTimeMillis(),
Ray Milkey269ffb92014-04-03 14:43:30 -0700148 System.currentTimeMillis(), null,
149 0, 0);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800150 topology.addOrUpdateLink(lt, info);
151 topology.deleteLinks(Collections.singletonList(lt), "Test");
152
153 // check invariants hold
154 assertNull(topology.switchLinks.get(lt.getSrc()));
155 assertNull(topology.switchLinks.get(lt.getDst()));
156 assertNull(topology.portLinks.get(lt.getSrc()));
157 assertNull(topology.portLinks.get(lt.getDst()));
158 assertTrue(topology.links.isEmpty());
159 }
160
161 @Test
162 public void testAddOrUpdateLinkToSelf() throws Exception {
163 LinkDiscoveryManager topology = getTopology();
164
165 Link lt = new Link(1L, 2, 2L, 3);
166 NodePortTuple srcNpt = new NodePortTuple(1L, 2);
167 NodePortTuple dstNpt = new NodePortTuple(2L, 3);
168
169 LinkInfo info = new LinkInfo(System.currentTimeMillis(),
Ray Milkey269ffb92014-04-03 14:43:30 -0700170 System.currentTimeMillis(), null,
171 0, 0);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800172 topology.addOrUpdateLink(lt, info);
173
174 // check invariants hold
175 assertNotNull(topology.switchLinks.get(lt.getSrc()));
176 assertTrue(topology.switchLinks.get(lt.getSrc()).contains(lt));
177 assertNotNull(topology.portLinks.get(srcNpt));
178 assertTrue(topology.portLinks.get(srcNpt).contains(lt));
179 assertNotNull(topology.portLinks.get(dstNpt));
180 assertTrue(topology.portLinks.get(dstNpt).contains(lt));
181 assertTrue(topology.links.containsKey(lt));
182 }
183
184 @Test
185 public void testDeleteLinkToSelf() throws Exception {
186 LinkDiscoveryManager topology = getTopology();
187
188 Link lt = new Link(1L, 2, 1L, 3);
189 NodePortTuple srcNpt = new NodePortTuple(1L, 2);
190 NodePortTuple dstNpt = new NodePortTuple(2L, 3);
191
192 LinkInfo info = new LinkInfo(System.currentTimeMillis(),
Ray Milkey269ffb92014-04-03 14:43:30 -0700193 System.currentTimeMillis(), null,
194 0, 0);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800195 topology.addOrUpdateLink(lt, info);
196 topology.deleteLinks(Collections.singletonList(lt), "Test to self");
197
198 // check invariants hold
199 assertNull(topology.switchLinks.get(lt.getSrc()));
200 assertNull(topology.switchLinks.get(lt.getDst()));
201 assertNull(topology.portLinks.get(srcNpt));
202 assertNull(topology.portLinks.get(dstNpt));
203 assertTrue(topology.links.isEmpty());
204 }
205
206 @Test
207 public void testRemovedSwitch() {
208 LinkDiscoveryManager topology = getTopology();
209
210 Link lt = new Link(1L, 2, 2L, 1);
211 NodePortTuple srcNpt = new NodePortTuple(1L, 2);
212 NodePortTuple dstNpt = new NodePortTuple(2L, 1);
213 LinkInfo info = new LinkInfo(System.currentTimeMillis(),
Ray Milkey269ffb92014-04-03 14:43:30 -0700214 System.currentTimeMillis(), null,
215 0, 0);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800216 topology.addOrUpdateLink(lt, info);
217
218 IOFSwitch sw1 = getMockFloodlightProvider().getSwitches().get(1L);
219 IOFSwitch sw2 = getMockFloodlightProvider().getSwitches().get(2L);
220 // Mock up our expected behavior
221 topology.removedSwitch(sw1);
222 verify(sw1, sw2);
223
224 // check invariants hold
225 assertNull(topology.switchLinks.get(lt.getSrc()));
226 assertNull(topology.switchLinks.get(lt.getDst()));
227 assertNull(topology.portLinks.get(srcNpt));
228 assertNull(topology.portLinks.get(dstNpt));
229 assertTrue(topology.links.isEmpty());
230 }
231
232 @Test
233 public void testRemovedSwitchSelf() {
234 LinkDiscoveryManager topology = getTopology();
235 IOFSwitch sw1 = createMockSwitch(1L);
236 replay(sw1);
237 Link lt = new Link(1L, 2, 1L, 3);
238 LinkInfo info = new LinkInfo(System.currentTimeMillis(),
Ray Milkey269ffb92014-04-03 14:43:30 -0700239 System.currentTimeMillis(), null,
240 0, 0);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800241 topology.addOrUpdateLink(lt, info);
242
243 // Mock up our expected behavior
244 topology.removedSwitch(sw1);
245
246 verify(sw1);
247 // check invariants hold
248 assertNull(topology.switchLinks.get(lt.getSrc()));
249 assertNull(topology.portLinks.get(lt.getSrc()));
250 assertNull(topology.portLinks.get(lt.getDst()));
251 assertTrue(topology.links.isEmpty());
252 }
253
254 @Test
255 public void testAddUpdateLinks() throws Exception {
256 LinkDiscoveryManager topology = getTopology();
257
258 Link lt = new Link(1L, 1, 2L, 1);
259 NodePortTuple srcNpt = new NodePortTuple(1L, 1);
260 NodePortTuple dstNpt = new NodePortTuple(2L, 1);
Ray Milkey269ffb92014-04-03 14:43:30 -0700261
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800262 LinkInfo info;
263
264 info = new LinkInfo(System.currentTimeMillis() - 40000,
Ray Milkey269ffb92014-04-03 14:43:30 -0700265 System.currentTimeMillis() - 40000, null,
266 0, 0);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800267 topology.addOrUpdateLink(lt, info);
268
269 // check invariants hold
270 assertNotNull(topology.switchLinks.get(lt.getSrc()));
271 assertTrue(topology.switchLinks.get(lt.getSrc()).contains(lt));
272 assertNotNull(topology.portLinks.get(srcNpt));
273 assertTrue(topology.portLinks.get(srcNpt).contains(lt));
274 assertNotNull(topology.portLinks.get(dstNpt));
275 assertTrue(topology.portLinks.get(dstNpt).contains(lt));
276 assertTrue(topology.links.containsKey(lt));
277 assertTrue(topology.portBroadcastDomainLinks.get(srcNpt) == null ||
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700278 !topology.portBroadcastDomainLinks.get(srcNpt).contains(lt));
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800279 assertTrue(topology.portBroadcastDomainLinks.get(dstNpt) == null ||
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700280 !topology.portBroadcastDomainLinks.get(dstNpt).contains(lt));
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800281
282 topology.timeoutLinks();
283
284
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700285 info = new LinkInfo(System.currentTimeMillis(), /* firstseen */
286 null, /* unicast */
Ray Milkey269ffb92014-04-03 14:43:30 -0700287 System.currentTimeMillis(), 0, 0);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800288 topology.addOrUpdateLink(lt, info);
289 assertTrue(topology.links.get(lt).getUnicastValidTime() == null);
290 assertTrue(topology.links.get(lt).getMulticastValidTime() != null);
291 assertTrue(topology.portBroadcastDomainLinks.get(srcNpt).contains(lt));
292 assertTrue(topology.portBroadcastDomainLinks.get(dstNpt).contains(lt));
293
294
295 // Add a link info based on info that woudld be obtained from unicast LLDP
296 // Setting the unicast LLDP reception time to be 40 seconds old, so we can use
297 // this to test timeout after this test. Although the info is initialized
298 // with LT_OPENFLOW_LINK, the link property should be changed to LT_NON_OPENFLOW
299 // by the addOrUpdateLink method.
300 info = new LinkInfo(System.currentTimeMillis() - 40000,
Ray Milkey269ffb92014-04-03 14:43:30 -0700301 System.currentTimeMillis() - 40000, null, 0, 0);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800302 topology.addOrUpdateLink(lt, info);
303 assertTrue(topology.portBroadcastDomainLinks.get(srcNpt) == null ||
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700304 !topology.portBroadcastDomainLinks.get(srcNpt).contains(lt));
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800305 assertTrue(topology.portBroadcastDomainLinks.get(dstNpt) == null ||
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700306 !topology.portBroadcastDomainLinks.get(dstNpt).contains(lt));
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800307
308 // Expect to timeout the unicast Valid Time, but not the multicast Valid time
309 // So the link type should go back to non-openflow link.
310 topology.timeoutLinks();
311 assertTrue(topology.links.get(lt).getUnicastValidTime() == null);
312 assertTrue(topology.links.get(lt).getMulticastValidTime() != null);
313 assertTrue(topology.portBroadcastDomainLinks.get(srcNpt).contains(lt));
314 assertTrue(topology.portBroadcastDomainLinks.get(dstNpt).contains(lt));
315
316 // Set the multicastValidTime to be old and see if that also times out.
317 info = new LinkInfo(System.currentTimeMillis() - 40000,
Ray Milkey269ffb92014-04-03 14:43:30 -0700318 null, System.currentTimeMillis() - 40000, 0, 0);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800319 topology.addOrUpdateLink(lt, info);
320 topology.timeoutLinks();
321 assertTrue(topology.links.get(lt) == null);
322 assertTrue(topology.portBroadcastDomainLinks.get(srcNpt) == null ||
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700323 !topology.portBroadcastDomainLinks.get(srcNpt).contains(lt));
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800324 assertTrue(topology.portBroadcastDomainLinks.get(dstNpt) == null ||
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700325 !topology.portBroadcastDomainLinks.get(dstNpt).contains(lt));
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800326
327
328 // Test again only with multicast LLDP
329 info = new LinkInfo(System.currentTimeMillis() - 40000,
Ray Milkey269ffb92014-04-03 14:43:30 -0700330 null, System.currentTimeMillis() - 40000, 0, 0);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800331 topology.addOrUpdateLink(lt, info);
332 assertTrue(topology.links.get(lt).getUnicastValidTime() == null);
333 assertTrue(topology.links.get(lt).getMulticastValidTime() != null);
334 assertTrue(topology.portBroadcastDomainLinks.get(srcNpt).contains(lt));
335 assertTrue(topology.portBroadcastDomainLinks.get(dstNpt).contains(lt));
336
337 // Call timeout and check if link is no longer present.
338 topology.timeoutLinks();
339 assertTrue(topology.links.get(lt) == null);
340 assertTrue(topology.portBroadcastDomainLinks.get(srcNpt) == null ||
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700341 !topology.portBroadcastDomainLinks.get(srcNpt).contains(lt));
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800342 assertTrue(topology.portBroadcastDomainLinks.get(dstNpt) == null ||
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700343 !topology.portBroadcastDomainLinks.get(dstNpt).contains(lt));
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800344
345 // Start clean and see if loops are also added.
346 lt = new Link(1L, 1, 1L, 2);
347 srcNpt = new NodePortTuple(1L, 1);
348 dstNpt = new NodePortTuple(1L, 2);
349 info = new LinkInfo(System.currentTimeMillis() - 40000,
Ray Milkey269ffb92014-04-03 14:43:30 -0700350 null, System.currentTimeMillis() - 40000, 0, 0);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800351 topology.addOrUpdateLink(lt, info);
352 assertTrue(topology.portBroadcastDomainLinks.get(srcNpt).contains(lt));
353 assertTrue(topology.portBroadcastDomainLinks.get(dstNpt).contains(lt));
354
355
356 // Start clean and see if loops are also added.
357 lt = new Link(1L, 1, 1L, 3);
358 srcNpt = new NodePortTuple(1L, 1);
359 dstNpt = new NodePortTuple(1L, 3);
360 info = new LinkInfo(System.currentTimeMillis() - 40000,
Ray Milkey269ffb92014-04-03 14:43:30 -0700361 null, System.currentTimeMillis() - 40000, 0, 0);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800362 topology.addOrUpdateLink(lt, info);
363 assertTrue(topology.portBroadcastDomainLinks.get(srcNpt).contains(lt));
364 assertTrue(topology.portBroadcastDomainLinks.get(dstNpt).contains(lt));
365
366
367 // Start clean and see if loops are also added.
368 lt = new Link(1L, 4, 1L, 5);
369 srcNpt = new NodePortTuple(1L, 4);
370 dstNpt = new NodePortTuple(1L, 5);
371 info = new LinkInfo(System.currentTimeMillis() - 40000,
Ray Milkey269ffb92014-04-03 14:43:30 -0700372 null, System.currentTimeMillis() - 40000, 0, 0);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800373 topology.addOrUpdateLink(lt, info);
374 assertTrue(topology.portBroadcastDomainLinks.get(srcNpt).contains(lt));
375 assertTrue(topology.portBroadcastDomainLinks.get(dstNpt).contains(lt));
376
377
378 // Start clean and see if loops are also added.
379 lt = new Link(1L, 3, 1L, 5);
380 srcNpt = new NodePortTuple(1L, 3);
381 dstNpt = new NodePortTuple(1L, 5);
382 info = new LinkInfo(System.currentTimeMillis() - 40000,
Ray Milkey269ffb92014-04-03 14:43:30 -0700383 null, System.currentTimeMillis() - 40000, 0, 0);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800384 topology.addOrUpdateLink(lt, info);
385 assertTrue(topology.portBroadcastDomainLinks.get(srcNpt).contains(lt));
386 assertTrue(topology.portBroadcastDomainLinks.get(dstNpt).contains(lt));
387 }
srikanth9f383342014-06-12 11:49:00 -0700388
389 /**
390 * This test case verifies that LinkDiscoveryManager.sendDiscoveryMessage()
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700391 * performs "write" operation on the specified IOFSwitch object
392 * with a LLDP packet.
393 *
srikanth9f383342014-06-12 11:49:00 -0700394 * @throws IOException
395 */
396 @Test
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700397 public void testSendDiscoveryMessage() throws IOException {
srikanth9f383342014-06-12 11:49:00 -0700398 LinkDiscoveryManager topology = getTopology();
399
400 // Mock up our expected behavior
401 IOFSwitch swTest = createMockSwitch(3L);
402 getMockFloodlightProvider().getSwitches().put(3L, swTest);
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700403
srikanth9f383342014-06-12 11:49:00 -0700404 short portNum = 1;
405 OFPhysicalPort ofpPort = new OFPhysicalPort();
406 ofpPort.setPortNumber(portNum);
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700407
408 /* sendDiscoverMessage() should perform the following actions on
srikanth9f383342014-06-12 11:49:00 -0700409 * IOFSwitch object
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700410 * - getPort() with argument as "1"
411 * - write() with OFPacketOut
412 * - flush()
srikanth9f383342014-06-12 11:49:00 -0700413 */
414 expect(swTest.getPort(portNum)).andReturn(ofpPort).atLeastOnce();
415 swTest.write(EasyMock.anyObject(OFMessage.class), EasyMock.anyObject(FloodlightContext.class));
416 EasyMock.expectLastCall().times(1);
417 swTest.flush();
418 EasyMock.expectLastCall().once();
419 replay(swTest);
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700420
srikanth9f383342014-06-12 11:49:00 -0700421 topology.sendDiscoveryMessage(3L, portNum, true, false);
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700422
srikanth9f383342014-06-12 11:49:00 -0700423 verify(swTest);
424 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800425}