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(), |
Jonathan Hart | ba354e0 | 2014-06-30 19:18:16 -0700 | [diff] [blame^] | 124 | System.currentTimeMillis(), 0, 0); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 125 | 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(), |
Jonathan Hart | ba354e0 | 2014-06-30 19:18:16 -0700 | [diff] [blame^] | 147 | System.currentTimeMillis(), 0, 0); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 148 | topology.addOrUpdateLink(lt, info); |
| 149 | topology.deleteLinks(Collections.singletonList(lt), "Test"); |
| 150 | |
| 151 | // check invariants hold |
| 152 | assertNull(topology.switchLinks.get(lt.getSrc())); |
| 153 | assertNull(topology.switchLinks.get(lt.getDst())); |
| 154 | assertNull(topology.portLinks.get(lt.getSrc())); |
| 155 | assertNull(topology.portLinks.get(lt.getDst())); |
| 156 | assertTrue(topology.links.isEmpty()); |
| 157 | } |
| 158 | |
| 159 | @Test |
| 160 | public void testAddOrUpdateLinkToSelf() throws Exception { |
| 161 | LinkDiscoveryManager topology = getTopology(); |
| 162 | |
| 163 | Link lt = new Link(1L, 2, 2L, 3); |
| 164 | NodePortTuple srcNpt = new NodePortTuple(1L, 2); |
| 165 | NodePortTuple dstNpt = new NodePortTuple(2L, 3); |
| 166 | |
| 167 | LinkInfo info = new LinkInfo(System.currentTimeMillis(), |
Jonathan Hart | ba354e0 | 2014-06-30 19:18:16 -0700 | [diff] [blame^] | 168 | System.currentTimeMillis(), 0, 0); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 169 | topology.addOrUpdateLink(lt, info); |
| 170 | |
| 171 | // check invariants hold |
| 172 | assertNotNull(topology.switchLinks.get(lt.getSrc())); |
| 173 | assertTrue(topology.switchLinks.get(lt.getSrc()).contains(lt)); |
| 174 | assertNotNull(topology.portLinks.get(srcNpt)); |
| 175 | assertTrue(topology.portLinks.get(srcNpt).contains(lt)); |
| 176 | assertNotNull(topology.portLinks.get(dstNpt)); |
| 177 | assertTrue(topology.portLinks.get(dstNpt).contains(lt)); |
| 178 | assertTrue(topology.links.containsKey(lt)); |
| 179 | } |
| 180 | |
| 181 | @Test |
| 182 | public void testDeleteLinkToSelf() throws Exception { |
| 183 | LinkDiscoveryManager topology = getTopology(); |
| 184 | |
| 185 | Link lt = new Link(1L, 2, 1L, 3); |
| 186 | NodePortTuple srcNpt = new NodePortTuple(1L, 2); |
| 187 | NodePortTuple dstNpt = new NodePortTuple(2L, 3); |
| 188 | |
| 189 | LinkInfo info = new LinkInfo(System.currentTimeMillis(), |
Jonathan Hart | ba354e0 | 2014-06-30 19:18:16 -0700 | [diff] [blame^] | 190 | System.currentTimeMillis(), 0, 0); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 191 | topology.addOrUpdateLink(lt, info); |
| 192 | topology.deleteLinks(Collections.singletonList(lt), "Test to self"); |
| 193 | |
| 194 | // check invariants hold |
| 195 | assertNull(topology.switchLinks.get(lt.getSrc())); |
| 196 | assertNull(topology.switchLinks.get(lt.getDst())); |
| 197 | assertNull(topology.portLinks.get(srcNpt)); |
| 198 | assertNull(topology.portLinks.get(dstNpt)); |
| 199 | assertTrue(topology.links.isEmpty()); |
| 200 | } |
| 201 | |
| 202 | @Test |
| 203 | public void testRemovedSwitch() { |
| 204 | LinkDiscoveryManager topology = getTopology(); |
| 205 | |
| 206 | Link lt = new Link(1L, 2, 2L, 1); |
| 207 | NodePortTuple srcNpt = new NodePortTuple(1L, 2); |
| 208 | NodePortTuple dstNpt = new NodePortTuple(2L, 1); |
| 209 | LinkInfo info = new LinkInfo(System.currentTimeMillis(), |
Jonathan Hart | ba354e0 | 2014-06-30 19:18:16 -0700 | [diff] [blame^] | 210 | System.currentTimeMillis(), 0, 0); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 211 | topology.addOrUpdateLink(lt, info); |
| 212 | |
| 213 | IOFSwitch sw1 = getMockFloodlightProvider().getSwitches().get(1L); |
| 214 | IOFSwitch sw2 = getMockFloodlightProvider().getSwitches().get(2L); |
| 215 | // Mock up our expected behavior |
| 216 | topology.removedSwitch(sw1); |
| 217 | verify(sw1, sw2); |
| 218 | |
| 219 | // check invariants hold |
| 220 | assertNull(topology.switchLinks.get(lt.getSrc())); |
| 221 | assertNull(topology.switchLinks.get(lt.getDst())); |
| 222 | assertNull(topology.portLinks.get(srcNpt)); |
| 223 | assertNull(topology.portLinks.get(dstNpt)); |
| 224 | assertTrue(topology.links.isEmpty()); |
| 225 | } |
| 226 | |
| 227 | @Test |
| 228 | public void testRemovedSwitchSelf() { |
| 229 | LinkDiscoveryManager topology = getTopology(); |
| 230 | IOFSwitch sw1 = createMockSwitch(1L); |
| 231 | replay(sw1); |
| 232 | Link lt = new Link(1L, 2, 1L, 3); |
| 233 | LinkInfo info = new LinkInfo(System.currentTimeMillis(), |
Jonathan Hart | ba354e0 | 2014-06-30 19:18:16 -0700 | [diff] [blame^] | 234 | System.currentTimeMillis(), 0, 0); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 235 | topology.addOrUpdateLink(lt, info); |
| 236 | |
| 237 | // Mock up our expected behavior |
| 238 | topology.removedSwitch(sw1); |
| 239 | |
| 240 | verify(sw1); |
| 241 | // check invariants hold |
| 242 | assertNull(topology.switchLinks.get(lt.getSrc())); |
| 243 | assertNull(topology.portLinks.get(lt.getSrc())); |
| 244 | assertNull(topology.portLinks.get(lt.getDst())); |
| 245 | assertTrue(topology.links.isEmpty()); |
| 246 | } |
| 247 | |
| 248 | @Test |
| 249 | public void testAddUpdateLinks() throws Exception { |
| 250 | LinkDiscoveryManager topology = getTopology(); |
| 251 | |
| 252 | Link lt = new Link(1L, 1, 2L, 1); |
| 253 | NodePortTuple srcNpt = new NodePortTuple(1L, 1); |
| 254 | NodePortTuple dstNpt = new NodePortTuple(2L, 1); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 255 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 256 | LinkInfo info; |
| 257 | |
| 258 | info = new LinkInfo(System.currentTimeMillis() - 40000, |
Jonathan Hart | ba354e0 | 2014-06-30 19:18:16 -0700 | [diff] [blame^] | 259 | System.currentTimeMillis() - 40000, 0, 0); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 260 | topology.addOrUpdateLink(lt, info); |
| 261 | |
| 262 | // check invariants hold |
| 263 | assertNotNull(topology.switchLinks.get(lt.getSrc())); |
| 264 | assertTrue(topology.switchLinks.get(lt.getSrc()).contains(lt)); |
| 265 | assertNotNull(topology.portLinks.get(srcNpt)); |
| 266 | assertTrue(topology.portLinks.get(srcNpt).contains(lt)); |
| 267 | assertNotNull(topology.portLinks.get(dstNpt)); |
| 268 | assertTrue(topology.portLinks.get(dstNpt).contains(lt)); |
| 269 | assertTrue(topology.links.containsKey(lt)); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 270 | |
| 271 | topology.timeoutLinks(); |
| 272 | |
| 273 | |
Yuta HIGUCHI | 44a0b35 | 2014-05-14 21:32:48 -0700 | [diff] [blame] | 274 | info = new LinkInfo(System.currentTimeMillis(), /* firstseen */ |
Jonathan Hart | ba354e0 | 2014-06-30 19:18:16 -0700 | [diff] [blame^] | 275 | null, /* unicast */0, 0); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 276 | topology.addOrUpdateLink(lt, info); |
| 277 | assertTrue(topology.links.get(lt).getUnicastValidTime() == null); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 278 | |
| 279 | |
Jonathan Hart | ba354e0 | 2014-06-30 19:18:16 -0700 | [diff] [blame^] | 280 | // Add a link info based on info that would be obtained from unicast LLDP |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 281 | // Setting the unicast LLDP reception time to be 40 seconds old, so we can use |
| 282 | // this to test timeout after this test. Although the info is initialized |
| 283 | // with LT_OPENFLOW_LINK, the link property should be changed to LT_NON_OPENFLOW |
| 284 | // by the addOrUpdateLink method. |
| 285 | info = new LinkInfo(System.currentTimeMillis() - 40000, |
Jonathan Hart | ba354e0 | 2014-06-30 19:18:16 -0700 | [diff] [blame^] | 286 | System.currentTimeMillis() - 40000, 0, 0); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 287 | topology.addOrUpdateLink(lt, info); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 288 | |
| 289 | // Expect to timeout the unicast Valid Time, but not the multicast Valid time |
| 290 | // So the link type should go back to non-openflow link. |
| 291 | topology.timeoutLinks(); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 292 | assertTrue(topology.links.get(lt) == null); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 293 | } |
srikanth | 9f38334 | 2014-06-12 11:49:00 -0700 | [diff] [blame] | 294 | |
| 295 | /** |
| 296 | * This test case verifies that LinkDiscoveryManager.sendDiscoveryMessage() |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 297 | * performs "write" operation on the specified IOFSwitch object |
| 298 | * with a LLDP packet. |
| 299 | * |
srikanth | 9f38334 | 2014-06-12 11:49:00 -0700 | [diff] [blame] | 300 | * @throws IOException |
| 301 | */ |
| 302 | @Test |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 303 | public void testSendDiscoveryMessage() throws IOException { |
Jonathan Hart | 299d113 | 2014-06-27 09:25:28 -0700 | [diff] [blame] | 304 | byte[] macAddress = new byte[] {0x0, 0x0, 0x0, 0x0, 0x0, 0x1}; |
| 305 | |
srikanth | 9f38334 | 2014-06-12 11:49:00 -0700 | [diff] [blame] | 306 | LinkDiscoveryManager topology = getTopology(); |
| 307 | |
| 308 | // Mock up our expected behavior |
| 309 | IOFSwitch swTest = createMockSwitch(3L); |
| 310 | getMockFloodlightProvider().getSwitches().put(3L, swTest); |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 311 | |
srikanth | 9f38334 | 2014-06-12 11:49:00 -0700 | [diff] [blame] | 312 | short portNum = 1; |
| 313 | OFPhysicalPort ofpPort = new OFPhysicalPort(); |
| 314 | ofpPort.setPortNumber(portNum); |
Jonathan Hart | 299d113 | 2014-06-27 09:25:28 -0700 | [diff] [blame] | 315 | ofpPort.setHardwareAddress(macAddress); |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 316 | |
| 317 | /* sendDiscoverMessage() should perform the following actions on |
srikanth | 9f38334 | 2014-06-12 11:49:00 -0700 | [diff] [blame] | 318 | * IOFSwitch object |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 319 | * - getPort() with argument as "1" |
| 320 | * - write() with OFPacketOut |
| 321 | * - flush() |
srikanth | 9f38334 | 2014-06-12 11:49:00 -0700 | [diff] [blame] | 322 | */ |
| 323 | expect(swTest.getPort(portNum)).andReturn(ofpPort).atLeastOnce(); |
| 324 | swTest.write(EasyMock.anyObject(OFMessage.class), EasyMock.anyObject(FloodlightContext.class)); |
| 325 | EasyMock.expectLastCall().times(1); |
| 326 | swTest.flush(); |
| 327 | EasyMock.expectLastCall().once(); |
| 328 | replay(swTest); |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 329 | |
Jonathan Hart | ba354e0 | 2014-06-30 19:18:16 -0700 | [diff] [blame^] | 330 | topology.sendDiscoveryMessage(3L, portNum, false); |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 331 | |
srikanth | 9f38334 | 2014-06-12 11:49:00 -0700 | [diff] [blame] | 332 | verify(swTest); |
| 333 | } |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 334 | } |