Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | /** |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 2 | * 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 Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 17 | |
Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 18 | package net.onrc.onos.core.linkdiscovery.internal; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 19 | |
Jonathan Hart | 2fa2806 | 2013-11-25 20:16:28 -0800 | [diff] [blame] | 20 | import static org.easymock.EasyMock.createNiceMock; |
| 21 | import static org.easymock.EasyMock.expect; |
| 22 | import static org.easymock.EasyMock.replay; |
| 23 | import static org.easymock.EasyMock.verify; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 24 | |
srikanth | 9f38334 | 2014-06-12 11:49:00 -0700 | [diff] [blame] | 25 | import java.io.IOException; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 26 | import java.util.ArrayList; |
Jonathan Hart | 2fa2806 | 2013-11-25 20:16:28 -0800 | [diff] [blame] | 27 | import java.util.Collections; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 28 | import java.util.HashMap; |
| 29 | import java.util.Map; |
| 30 | |
srikanth | 9f38334 | 2014-06-12 11:49:00 -0700 | [diff] [blame] | 31 | import net.floodlightcontroller.core.FloodlightContext; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 32 | import net.floodlightcontroller.core.IFloodlightProviderService; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 33 | import net.floodlightcontroller.core.IOFSwitch; |
| 34 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 35 | import net.floodlightcontroller.core.test.MockThreadPoolService; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 36 | import net.floodlightcontroller.restserver.IRestApiService; |
| 37 | import net.floodlightcontroller.restserver.RestApiServer; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 38 | import net.floodlightcontroller.test.FloodlightTestCase; |
| 39 | import net.floodlightcontroller.threadpool.IThreadPoolService; |
Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 40 | import net.onrc.onos.core.linkdiscovery.ILinkDiscoveryListener; |
| 41 | import net.onrc.onos.core.linkdiscovery.ILinkDiscoveryService; |
| 42 | import net.onrc.onos.core.linkdiscovery.Link; |
| 43 | import net.onrc.onos.core.linkdiscovery.LinkInfo; |
| 44 | import net.onrc.onos.core.linkdiscovery.NodePortTuple; |
Jonathan Hart | 2fa2806 | 2013-11-25 20:16:28 -0800 | [diff] [blame] | 45 | |
srikanth | 9f38334 | 2014-06-12 11:49:00 -0700 | [diff] [blame] | 46 | import org.easymock.EasyMock; |
Jonathan Hart | 2fa2806 | 2013-11-25 20:16:28 -0800 | [diff] [blame] | 47 | import org.junit.Before; |
| 48 | import org.junit.Test; |
srikanth | 9f38334 | 2014-06-12 11:49:00 -0700 | [diff] [blame] | 49 | import org.openflow.protocol.OFMessage; |
| 50 | import org.openflow.protocol.OFPhysicalPort; |
Jonathan Hart | 2fa2806 | 2013-11-25 20:16:28 -0800 | [diff] [blame] | 51 | import org.slf4j.Logger; |
| 52 | import org.slf4j.LoggerFactory; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 53 | |
Yuta HIGUCHI | aa132f5 | 2014-06-26 10:18:39 -0700 | [diff] [blame] | 54 | // CHECKSTYLE IGNORE WriteTag FOR NEXT 2 LINES |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 55 | /** |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 56 | * @author David Erickson (daviderickson@cs.stanford.edu) |
| 57 | */ |
| 58 | public class LinkDiscoveryManagerTest extends FloodlightTestCase { |
| 59 | |
| 60 | private TestLinkDiscoveryManager ldm; |
Yuta HIGUCHI | 44a0b35 | 2014-05-14 21:32:48 -0700 | [diff] [blame] | 61 | protected static final Logger log = LoggerFactory.getLogger(LinkDiscoveryManagerTest.class); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 62 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 63 | 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 Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 77 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 78 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 79 | 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 HIGUCHI | 44a0b35 | 2014-05-14 21:32:48 -0700 | [diff] [blame] | 89 | @Override |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 90 | @Before |
| 91 | public void setUp() throws Exception { |
| 92 | super.setUp(); |
| 93 | FloodlightModuleContext cntx = new FloodlightModuleContext(); |
| 94 | ldm = new TestLinkDiscoveryManager(); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 95 | 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 Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 100 | cntx.addService(ILinkDiscoveryService.class, ldm); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 101 | cntx.addService(IFloodlightProviderService.class, getMockFloodlightProvider()); |
| 102 | restApi.init(cntx); |
| 103 | tp.init(cntx); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 104 | ldm.init(cntx); |
| 105 | restApi.startUp(cntx); |
| 106 | tp.startUp(cntx); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 107 | 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 124 | System.currentTimeMillis(), null, |
| 125 | 0, 0); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 126 | 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 148 | System.currentTimeMillis(), null, |
| 149 | 0, 0); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 150 | 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 170 | System.currentTimeMillis(), null, |
| 171 | 0, 0); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 172 | 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 193 | System.currentTimeMillis(), null, |
| 194 | 0, 0); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 195 | 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 214 | System.currentTimeMillis(), null, |
| 215 | 0, 0); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 216 | 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 239 | System.currentTimeMillis(), null, |
| 240 | 0, 0); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 241 | 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 261 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 262 | LinkInfo info; |
| 263 | |
| 264 | info = new LinkInfo(System.currentTimeMillis() - 40000, |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 265 | System.currentTimeMillis() - 40000, null, |
| 266 | 0, 0); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 267 | 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 HIGUCHI | 44a0b35 | 2014-05-14 21:32:48 -0700 | [diff] [blame] | 278 | !topology.portBroadcastDomainLinks.get(srcNpt).contains(lt)); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 279 | assertTrue(topology.portBroadcastDomainLinks.get(dstNpt) == null || |
Yuta HIGUCHI | 44a0b35 | 2014-05-14 21:32:48 -0700 | [diff] [blame] | 280 | !topology.portBroadcastDomainLinks.get(dstNpt).contains(lt)); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 281 | |
| 282 | topology.timeoutLinks(); |
| 283 | |
| 284 | |
Yuta HIGUCHI | 44a0b35 | 2014-05-14 21:32:48 -0700 | [diff] [blame] | 285 | info = new LinkInfo(System.currentTimeMillis(), /* firstseen */ |
| 286 | null, /* unicast */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 287 | System.currentTimeMillis(), 0, 0); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 288 | 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 301 | System.currentTimeMillis() - 40000, null, 0, 0); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 302 | topology.addOrUpdateLink(lt, info); |
| 303 | assertTrue(topology.portBroadcastDomainLinks.get(srcNpt) == null || |
Yuta HIGUCHI | 44a0b35 | 2014-05-14 21:32:48 -0700 | [diff] [blame] | 304 | !topology.portBroadcastDomainLinks.get(srcNpt).contains(lt)); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 305 | assertTrue(topology.portBroadcastDomainLinks.get(dstNpt) == null || |
Yuta HIGUCHI | 44a0b35 | 2014-05-14 21:32:48 -0700 | [diff] [blame] | 306 | !topology.portBroadcastDomainLinks.get(dstNpt).contains(lt)); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 307 | |
| 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 318 | null, System.currentTimeMillis() - 40000, 0, 0); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 319 | topology.addOrUpdateLink(lt, info); |
| 320 | topology.timeoutLinks(); |
| 321 | assertTrue(topology.links.get(lt) == null); |
| 322 | assertTrue(topology.portBroadcastDomainLinks.get(srcNpt) == null || |
Yuta HIGUCHI | 44a0b35 | 2014-05-14 21:32:48 -0700 | [diff] [blame] | 323 | !topology.portBroadcastDomainLinks.get(srcNpt).contains(lt)); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 324 | assertTrue(topology.portBroadcastDomainLinks.get(dstNpt) == null || |
Yuta HIGUCHI | 44a0b35 | 2014-05-14 21:32:48 -0700 | [diff] [blame] | 325 | !topology.portBroadcastDomainLinks.get(dstNpt).contains(lt)); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 326 | |
| 327 | |
| 328 | // Test again only with multicast LLDP |
| 329 | info = new LinkInfo(System.currentTimeMillis() - 40000, |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 330 | null, System.currentTimeMillis() - 40000, 0, 0); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 331 | 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 HIGUCHI | 44a0b35 | 2014-05-14 21:32:48 -0700 | [diff] [blame] | 341 | !topology.portBroadcastDomainLinks.get(srcNpt).contains(lt)); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 342 | assertTrue(topology.portBroadcastDomainLinks.get(dstNpt) == null || |
Yuta HIGUCHI | 44a0b35 | 2014-05-14 21:32:48 -0700 | [diff] [blame] | 343 | !topology.portBroadcastDomainLinks.get(dstNpt).contains(lt)); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 344 | |
| 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 350 | null, System.currentTimeMillis() - 40000, 0, 0); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 351 | 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 361 | null, System.currentTimeMillis() - 40000, 0, 0); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 362 | 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 372 | null, System.currentTimeMillis() - 40000, 0, 0); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 373 | 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 383 | null, System.currentTimeMillis() - 40000, 0, 0); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 384 | topology.addOrUpdateLink(lt, info); |
| 385 | assertTrue(topology.portBroadcastDomainLinks.get(srcNpt).contains(lt)); |
| 386 | assertTrue(topology.portBroadcastDomainLinks.get(dstNpt).contains(lt)); |
| 387 | } |
srikanth | 9f38334 | 2014-06-12 11:49:00 -0700 | [diff] [blame] | 388 | |
| 389 | /** |
| 390 | * This test case verifies that LinkDiscoveryManager.sendDiscoveryMessage() |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 391 | * performs "write" operation on the specified IOFSwitch object |
| 392 | * with a LLDP packet. |
| 393 | * |
srikanth | 9f38334 | 2014-06-12 11:49:00 -0700 | [diff] [blame] | 394 | * @throws IOException |
| 395 | */ |
| 396 | @Test |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 397 | public void testSendDiscoveryMessage() throws IOException { |
Jonathan Hart | 299d113 | 2014-06-27 09:25:28 -0700 | [diff] [blame^] | 398 | byte[] macAddress = new byte[] {0x0, 0x0, 0x0, 0x0, 0x0, 0x1}; |
| 399 | |
srikanth | 9f38334 | 2014-06-12 11:49:00 -0700 | [diff] [blame] | 400 | LinkDiscoveryManager topology = getTopology(); |
| 401 | |
| 402 | // Mock up our expected behavior |
| 403 | IOFSwitch swTest = createMockSwitch(3L); |
| 404 | getMockFloodlightProvider().getSwitches().put(3L, swTest); |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 405 | |
srikanth | 9f38334 | 2014-06-12 11:49:00 -0700 | [diff] [blame] | 406 | short portNum = 1; |
| 407 | OFPhysicalPort ofpPort = new OFPhysicalPort(); |
| 408 | ofpPort.setPortNumber(portNum); |
Jonathan Hart | 299d113 | 2014-06-27 09:25:28 -0700 | [diff] [blame^] | 409 | ofpPort.setHardwareAddress(macAddress); |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 410 | |
| 411 | /* sendDiscoverMessage() should perform the following actions on |
srikanth | 9f38334 | 2014-06-12 11:49:00 -0700 | [diff] [blame] | 412 | * IOFSwitch object |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 413 | * - getPort() with argument as "1" |
| 414 | * - write() with OFPacketOut |
| 415 | * - flush() |
srikanth | 9f38334 | 2014-06-12 11:49:00 -0700 | [diff] [blame] | 416 | */ |
| 417 | expect(swTest.getPort(portNum)).andReturn(ofpPort).atLeastOnce(); |
| 418 | swTest.write(EasyMock.anyObject(OFMessage.class), EasyMock.anyObject(FloodlightContext.class)); |
| 419 | EasyMock.expectLastCall().times(1); |
| 420 | swTest.flush(); |
| 421 | EasyMock.expectLastCall().once(); |
| 422 | replay(swTest); |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 423 | |
srikanth | 9f38334 | 2014-06-12 11:49:00 -0700 | [diff] [blame] | 424 | topology.sendDiscoveryMessage(3L, portNum, true, false); |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 425 | |
srikanth | 9f38334 | 2014-06-12 11:49:00 -0700 | [diff] [blame] | 426 | verify(swTest); |
| 427 | } |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 428 | } |