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 | 284e70f | 2014-07-05 12:32:51 -0700 | [diff] [blame] | 18 | package net.onrc.onos.core.linkdiscovery; |
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; |
Jonathan Hart | 2fa2806 | 2013-11-25 20:16:28 -0800 | [diff] [blame] | 26 | import java.util.Collections; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 27 | import java.util.HashMap; |
| 28 | import java.util.Map; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 29 | import java.util.Set; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 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; |
Jonathan Hart | 0f38354 | 2014-07-09 11:38:03 -0700 | [diff] [blame] | 33 | import net.floodlightcontroller.core.IListener.Command; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 34 | import net.floodlightcontroller.core.IOFSwitch; |
| 35 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 36 | import net.floodlightcontroller.core.test.MockThreadPoolService; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 37 | import net.floodlightcontroller.restserver.IRestApiService; |
| 38 | import net.floodlightcontroller.restserver.RestApiServer; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 39 | import net.floodlightcontroller.test.FloodlightTestCase; |
| 40 | import net.floodlightcontroller.threadpool.IThreadPoolService; |
Jonathan Hart | 0f38354 | 2014-07-09 11:38:03 -0700 | [diff] [blame] | 41 | import net.onrc.onos.core.packet.Ethernet; |
| 42 | import net.onrc.onos.core.packet.OnosLldp; |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 43 | import net.onrc.onos.core.registry.IControllerRegistryService; |
Jonathan Hart | 2fa2806 | 2013-11-25 20:16:28 -0800 | [diff] [blame] | 44 | |
srikanth | 9f38334 | 2014-06-12 11:49:00 -0700 | [diff] [blame] | 45 | import org.easymock.EasyMock; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 46 | import org.easymock.IArgumentMatcher; |
Jonathan Hart | 2fa2806 | 2013-11-25 20:16:28 -0800 | [diff] [blame] | 47 | import org.junit.Before; |
| 48 | import org.junit.Test; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 49 | import org.projectfloodlight.openflow.protocol.OFFactories; |
| 50 | import org.projectfloodlight.openflow.protocol.OFFactory; |
| 51 | import org.projectfloodlight.openflow.protocol.OFPacketIn; |
| 52 | import org.projectfloodlight.openflow.protocol.OFPacketOut; |
| 53 | import org.projectfloodlight.openflow.protocol.OFPortConfig; |
| 54 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
| 55 | import org.projectfloodlight.openflow.protocol.OFPortReason; |
| 56 | import org.projectfloodlight.openflow.protocol.OFPortState; |
| 57 | import org.projectfloodlight.openflow.protocol.OFPortStatus; |
| 58 | import org.projectfloodlight.openflow.protocol.OFVersion; |
| 59 | import org.projectfloodlight.openflow.protocol.action.OFActionOutput; |
| 60 | import org.projectfloodlight.openflow.types.MacAddress; |
| 61 | import org.projectfloodlight.openflow.types.OFPort; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 62 | |
Yuta HIGUCHI | aa132f5 | 2014-06-26 10:18:39 -0700 | [diff] [blame] | 63 | // CHECKSTYLE IGNORE WriteTag FOR NEXT 2 LINES |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 64 | /** |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 65 | * @author David Erickson (daviderickson@cs.stanford.edu) |
| 66 | */ |
| 67 | public class LinkDiscoveryManagerTest extends FloodlightTestCase { |
| 68 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 69 | private LinkDiscoveryManager ldm; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 70 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 71 | private static final Set<OFPortState> EMPTY_PORT_STATE = |
| 72 | Collections.<OFPortState>emptySet(); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 73 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 74 | // Arbitrary MAC address that we can feed in to our mock objects. This |
| 75 | // value is never actually checked during the tests so it doesn't matter if |
| 76 | // all ports have the same MAC address. |
| 77 | private static final byte[] DEFAULT_MAC_ADDRESS = |
| 78 | new byte[] {0x0, 0x0, 0x0, 0x0, 0x0, 0x1}; |
| 79 | |
| 80 | private OFFactory factory10 = OFFactories.getFactory(OFVersion.OF_10); |
| 81 | |
| 82 | /** |
| 83 | * EasyMock matcher to verify the value of the output port of a packet out. |
| 84 | * This is used to verify that the packet out messages generated by |
| 85 | * LinkDiscoveryManager contain the correct output port. |
| 86 | * |
| 87 | */ |
| 88 | private static final class PacketOutPortMatcher implements IArgumentMatcher { |
| 89 | private final int portNumber; |
| 90 | |
| 91 | public PacketOutPortMatcher(int portNumber) { |
| 92 | this.portNumber = portNumber; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 93 | } |
| 94 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 95 | @Override |
| 96 | public void appendTo(StringBuffer strBuffer) { |
| 97 | strBuffer.append("PacketOutPortMatcher failed to verify output port"); |
| 98 | } |
| 99 | |
| 100 | @Override |
| 101 | public boolean matches(Object object) { |
| 102 | if (!(object instanceof OFPacketOut)) { |
| 103 | return false; |
| 104 | } |
| 105 | |
| 106 | OFPacketOut po = (OFPacketOut) object; |
| 107 | |
| 108 | if (po.getActions().size() != 1 |
| 109 | || !(po.getActions().get(0) instanceof OFActionOutput)) { |
| 110 | return false; |
| 111 | } |
| 112 | |
| 113 | OFActionOutput action = (OFActionOutput) po.getActions().get(0); |
| 114 | |
| 115 | return action.getPort().getPortNumber() == portNumber; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 116 | } |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 117 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 118 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 119 | /** |
| 120 | * Matcher method to match a given output port against a packet out message |
| 121 | * passed as an argument to a mock switch. |
| 122 | * |
| 123 | * @param outPort the output port to check in the packet out |
| 124 | * @return anything of type OFPacketOut |
| 125 | */ |
| 126 | private static OFPacketOut matchOutPort(int outPort) { |
| 127 | EasyMock.reportMatcher(new PacketOutPortMatcher(outPort)); |
| 128 | return null; |
| 129 | } |
| 130 | |
| 131 | private LinkDiscoveryManager getLinkDiscoveryManager() { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 132 | return ldm; |
| 133 | } |
| 134 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 135 | private IOFSwitch createMockSwitch(Long id) { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 136 | IOFSwitch mockSwitch = createNiceMock(IOFSwitch.class); |
| 137 | expect(mockSwitch.getId()).andReturn(id).anyTimes(); |
Jonathan Hart | 0f38354 | 2014-07-09 11:38:03 -0700 | [diff] [blame] | 138 | expect(mockSwitch.portEnabled(EasyMock.anyShort())).andReturn(true).anyTimes(); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 139 | return mockSwitch; |
| 140 | } |
| 141 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 142 | private OFPortDesc createMockPort(short portNumber) { |
| 143 | return createMockPortWithState(portNumber, |
| 144 | Collections.<OFPortState>emptySet()); |
| 145 | } |
| 146 | |
| 147 | private OFPortDesc createMockPortWithState(short portNumber, |
| 148 | Set<OFPortState> state) { |
| 149 | OFPort ofPort = EasyMock.createMock(OFPort.class); |
| 150 | expect(ofPort.getShortPortNumber()).andReturn(portNumber).anyTimes(); |
| 151 | |
| 152 | OFPortDesc ofPortDesc = EasyMock.createMock(OFPortDesc.class); |
| 153 | expect(ofPortDesc.getPortNo()).andReturn(ofPort).anyTimes(); |
| 154 | expect(ofPortDesc.getHwAddr()).andReturn( |
| 155 | MacAddress.of(DEFAULT_MAC_ADDRESS)).anyTimes(); |
| 156 | expect(ofPortDesc.getConfig()). |
| 157 | andReturn(Collections.<OFPortConfig>emptySet()).anyTimes(); |
| 158 | expect(ofPortDesc.getState()).andReturn(state).anyTimes(); |
| 159 | |
| 160 | replay(ofPort); |
| 161 | replay(ofPortDesc); |
| 162 | |
| 163 | return ofPortDesc; |
| 164 | } |
| 165 | |
Yuta HIGUCHI | 44a0b35 | 2014-05-14 21:32:48 -0700 | [diff] [blame] | 166 | @Override |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 167 | @Before |
| 168 | public void setUp() throws Exception { |
| 169 | super.setUp(); |
| 170 | FloodlightModuleContext cntx = new FloodlightModuleContext(); |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 171 | ldm = new LinkDiscoveryManager(); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 172 | MockThreadPoolService tp = new MockThreadPoolService(); |
| 173 | RestApiServer restApi = new RestApiServer(); |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 174 | IControllerRegistryService registry = |
| 175 | EasyMock.createMock(IControllerRegistryService.class); |
| 176 | expect(registry.hasControl(EasyMock.anyLong())).andReturn(true).anyTimes(); |
| 177 | replay(registry); |
| 178 | cntx.addService(IControllerRegistryService.class, registry); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 179 | cntx.addService(IRestApiService.class, restApi); |
| 180 | cntx.addService(IThreadPoolService.class, tp); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 181 | cntx.addService(ILinkDiscoveryService.class, ldm); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 182 | cntx.addService(IFloodlightProviderService.class, getMockFloodlightProvider()); |
| 183 | restApi.init(cntx); |
| 184 | tp.init(cntx); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 185 | ldm.init(cntx); |
| 186 | restApi.startUp(cntx); |
| 187 | tp.startUp(cntx); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 188 | ldm.startUp(cntx); |
| 189 | |
| 190 | IOFSwitch sw1 = createMockSwitch(1L); |
| 191 | IOFSwitch sw2 = createMockSwitch(2L); |
| 192 | Map<Long, IOFSwitch> switches = new HashMap<Long, IOFSwitch>(); |
| 193 | switches.put(1L, sw1); |
| 194 | switches.put(2L, sw2); |
| 195 | getMockFloodlightProvider().setSwitches(switches); |
| 196 | replay(sw1, sw2); |
| 197 | } |
| 198 | |
| 199 | @Test |
| 200 | public void testAddOrUpdateLink() throws Exception { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 201 | LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager(); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 202 | |
| 203 | Link lt = new Link(1L, 2, 2L, 1); |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 204 | long firstSeenTime = System.currentTimeMillis(); |
| 205 | LinkInfo info = new LinkInfo(firstSeenTime, |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 206 | System.currentTimeMillis(), EMPTY_PORT_STATE, |
| 207 | EMPTY_PORT_STATE); |
| 208 | linkDiscovery.addOrUpdateLink(lt, info); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 209 | |
| 210 | NodePortTuple srcNpt = new NodePortTuple(1L, 2); |
| 211 | NodePortTuple dstNpt = new NodePortTuple(2L, 1); |
| 212 | |
| 213 | // check invariants hold |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 214 | assertNotNull(linkDiscovery.switchLinks.get(lt.getSrc())); |
| 215 | assertTrue(linkDiscovery.switchLinks.get(lt.getSrc()).contains(lt)); |
| 216 | assertNotNull(linkDiscovery.portLinks.get(srcNpt)); |
| 217 | assertTrue(linkDiscovery.portLinks.get(srcNpt).contains(lt)); |
| 218 | assertNotNull(linkDiscovery.portLinks.get(dstNpt)); |
| 219 | assertTrue(linkDiscovery.portLinks.get(dstNpt).contains(lt)); |
| 220 | assertTrue(linkDiscovery.links.containsKey(lt)); |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 221 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 222 | LinkInfo infoToVerify = linkDiscovery.links.get(lt); |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 223 | assertEquals(firstSeenTime, infoToVerify.getFirstSeenTime()); |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 224 | assertEquals(EMPTY_PORT_STATE, infoToVerify.getSrcPortState()); |
| 225 | assertEquals(EMPTY_PORT_STATE, infoToVerify.getDstPortState()); |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 226 | |
| 227 | // Arbitrary new port states to verify that the port state is updated |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 228 | final Set<OFPortState> newSrcPortState = |
| 229 | Collections.singleton(OFPortState.STP_BLOCK); |
| 230 | final Set<OFPortState> newDstPortState = |
| 231 | Collections.singleton(OFPortState.LINK_DOWN); |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 232 | |
| 233 | // Update the last received probe timestamp and the port states |
| 234 | LinkInfo infoWithStateChange = new LinkInfo(System.currentTimeMillis(), |
| 235 | System.currentTimeMillis(), newSrcPortState, newDstPortState); |
| 236 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 237 | linkDiscovery.addOrUpdateLink(lt, infoWithStateChange); |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 238 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 239 | assertNotNull(linkDiscovery.links.get(lt)); |
| 240 | infoToVerify = linkDiscovery.links.get(lt); |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 241 | // First seen time should be the original time, not the second update time |
| 242 | assertEquals(firstSeenTime, infoToVerify.getFirstSeenTime()); |
| 243 | // Both port states should have been updated |
| 244 | assertEquals(newSrcPortState, infoToVerify.getSrcPortState()); |
| 245 | assertEquals(newDstPortState, infoToVerify.getDstPortState()); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | @Test |
| 249 | public void testDeleteLink() throws Exception { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 250 | LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager(); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 251 | |
| 252 | Link lt = new Link(1L, 2, 2L, 1); |
| 253 | LinkInfo info = new LinkInfo(System.currentTimeMillis(), |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 254 | System.currentTimeMillis(), EMPTY_PORT_STATE, EMPTY_PORT_STATE); |
| 255 | linkDiscovery.addOrUpdateLink(lt, info); |
| 256 | linkDiscovery.deleteLinks(Collections.singletonList(lt)); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 257 | |
| 258 | // check invariants hold |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 259 | assertNull(linkDiscovery.switchLinks.get(lt.getSrc())); |
| 260 | assertNull(linkDiscovery.switchLinks.get(lt.getDst())); |
| 261 | assertNull(linkDiscovery.portLinks.get(lt.getSrc())); |
| 262 | assertNull(linkDiscovery.portLinks.get(lt.getDst())); |
| 263 | assertTrue(linkDiscovery.links.isEmpty()); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | @Test |
| 267 | public void testAddOrUpdateLinkToSelf() throws Exception { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 268 | LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager(); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 269 | |
| 270 | Link lt = new Link(1L, 2, 2L, 3); |
| 271 | NodePortTuple srcNpt = new NodePortTuple(1L, 2); |
| 272 | NodePortTuple dstNpt = new NodePortTuple(2L, 3); |
| 273 | |
| 274 | LinkInfo info = new LinkInfo(System.currentTimeMillis(), |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 275 | System.currentTimeMillis(), EMPTY_PORT_STATE, EMPTY_PORT_STATE); |
| 276 | linkDiscovery.addOrUpdateLink(lt, info); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 277 | |
| 278 | // check invariants hold |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 279 | assertNotNull(linkDiscovery.switchLinks.get(lt.getSrc())); |
| 280 | assertTrue(linkDiscovery.switchLinks.get(lt.getSrc()).contains(lt)); |
| 281 | assertNotNull(linkDiscovery.portLinks.get(srcNpt)); |
| 282 | assertTrue(linkDiscovery.portLinks.get(srcNpt).contains(lt)); |
| 283 | assertNotNull(linkDiscovery.portLinks.get(dstNpt)); |
| 284 | assertTrue(linkDiscovery.portLinks.get(dstNpt).contains(lt)); |
| 285 | assertTrue(linkDiscovery.links.containsKey(lt)); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | @Test |
| 289 | public void testDeleteLinkToSelf() throws Exception { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 290 | LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager(); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 291 | |
| 292 | Link lt = new Link(1L, 2, 1L, 3); |
| 293 | NodePortTuple srcNpt = new NodePortTuple(1L, 2); |
| 294 | NodePortTuple dstNpt = new NodePortTuple(2L, 3); |
| 295 | |
| 296 | LinkInfo info = new LinkInfo(System.currentTimeMillis(), |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 297 | System.currentTimeMillis(), EMPTY_PORT_STATE, EMPTY_PORT_STATE); |
| 298 | linkDiscovery.addOrUpdateLink(lt, info); |
| 299 | linkDiscovery.deleteLinks(Collections.singletonList(lt)); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 300 | |
| 301 | // check invariants hold |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 302 | assertNull(linkDiscovery.switchLinks.get(lt.getSrc())); |
| 303 | assertNull(linkDiscovery.switchLinks.get(lt.getDst())); |
| 304 | assertNull(linkDiscovery.portLinks.get(srcNpt)); |
| 305 | assertNull(linkDiscovery.portLinks.get(dstNpt)); |
| 306 | assertTrue(linkDiscovery.links.isEmpty()); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | @Test |
| 310 | public void testRemovedSwitch() { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 311 | LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager(); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 312 | |
| 313 | Link lt = new Link(1L, 2, 2L, 1); |
| 314 | NodePortTuple srcNpt = new NodePortTuple(1L, 2); |
| 315 | NodePortTuple dstNpt = new NodePortTuple(2L, 1); |
| 316 | LinkInfo info = new LinkInfo(System.currentTimeMillis(), |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 317 | System.currentTimeMillis(), EMPTY_PORT_STATE, EMPTY_PORT_STATE); |
| 318 | linkDiscovery.addOrUpdateLink(lt, info); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 319 | |
| 320 | IOFSwitch sw1 = getMockFloodlightProvider().getSwitches().get(1L); |
| 321 | IOFSwitch sw2 = getMockFloodlightProvider().getSwitches().get(2L); |
| 322 | // Mock up our expected behavior |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 323 | linkDiscovery.switchDisconnected(sw1.getId()); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 324 | verify(sw1, sw2); |
| 325 | |
| 326 | // check invariants hold |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 327 | assertNull(linkDiscovery.switchLinks.get(lt.getSrc())); |
| 328 | assertNull(linkDiscovery.switchLinks.get(lt.getDst())); |
| 329 | assertNull(linkDiscovery.portLinks.get(srcNpt)); |
| 330 | assertNull(linkDiscovery.portLinks.get(dstNpt)); |
| 331 | assertTrue(linkDiscovery.links.isEmpty()); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | @Test |
| 335 | public void testRemovedSwitchSelf() { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 336 | LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager(); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 337 | IOFSwitch sw1 = createMockSwitch(1L); |
| 338 | replay(sw1); |
| 339 | Link lt = new Link(1L, 2, 1L, 3); |
| 340 | LinkInfo info = new LinkInfo(System.currentTimeMillis(), |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 341 | System.currentTimeMillis(), EMPTY_PORT_STATE, EMPTY_PORT_STATE); |
| 342 | linkDiscovery.addOrUpdateLink(lt, info); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 343 | |
| 344 | // Mock up our expected behavior |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 345 | linkDiscovery.switchDisconnected(sw1.getId()); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 346 | |
| 347 | verify(sw1); |
| 348 | // check invariants hold |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 349 | assertNull(linkDiscovery.switchLinks.get(lt.getSrc())); |
| 350 | assertNull(linkDiscovery.portLinks.get(lt.getSrc())); |
| 351 | assertNull(linkDiscovery.portLinks.get(lt.getDst())); |
| 352 | assertTrue(linkDiscovery.links.isEmpty()); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | @Test |
| 356 | public void testAddUpdateLinks() throws Exception { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 357 | LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager(); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 358 | |
| 359 | Link lt = new Link(1L, 1, 2L, 1); |
| 360 | NodePortTuple srcNpt = new NodePortTuple(1L, 1); |
| 361 | NodePortTuple dstNpt = new NodePortTuple(2L, 1); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 362 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 363 | LinkInfo info; |
| 364 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 365 | // Setting the last LLDP reception time to be 40 seconds old, so we |
| 366 | // can use this to test that an old link times out correctly |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 367 | info = new LinkInfo(System.currentTimeMillis() - 40000, |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 368 | System.currentTimeMillis() - 40000, |
| 369 | EMPTY_PORT_STATE, EMPTY_PORT_STATE); |
| 370 | linkDiscovery.addOrUpdateLink(lt, info); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 371 | |
| 372 | // check invariants hold |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 373 | assertNotNull(linkDiscovery.switchLinks.get(lt.getSrc())); |
| 374 | assertTrue(linkDiscovery.switchLinks.get(lt.getSrc()).contains(lt)); |
| 375 | assertNotNull(linkDiscovery.portLinks.get(srcNpt)); |
| 376 | assertTrue(linkDiscovery.portLinks.get(srcNpt).contains(lt)); |
| 377 | assertNotNull(linkDiscovery.portLinks.get(dstNpt)); |
| 378 | assertTrue(linkDiscovery.portLinks.get(dstNpt).contains(lt)); |
| 379 | assertTrue(linkDiscovery.links.containsKey(lt)); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 380 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 381 | linkDiscovery.timeOutLinks(); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 382 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 383 | // Setting the last LLDP reception time to be 40 seconds old, so we |
| 384 | // can use this to test that an old link times out correctly |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 385 | info = new LinkInfo(System.currentTimeMillis() - 40000, |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 386 | System.currentTimeMillis() - 40000, |
| 387 | EMPTY_PORT_STATE, EMPTY_PORT_STATE); |
| 388 | linkDiscovery.addOrUpdateLink(lt, info); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 389 | |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 390 | // Expect to timeout the unicast Valid Time, so the link should disappear |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 391 | linkDiscovery.timeOutLinks(); |
| 392 | assertTrue(linkDiscovery.links.get(lt) == null); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 393 | } |
srikanth | 9f38334 | 2014-06-12 11:49:00 -0700 | [diff] [blame] | 394 | |
| 395 | /** |
| 396 | * This test case verifies that LinkDiscoveryManager.sendDiscoveryMessage() |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 397 | * performs "write" operation on the specified IOFSwitch object |
| 398 | * with a LLDP packet. |
| 399 | * |
srikanth | 9f38334 | 2014-06-12 11:49:00 -0700 | [diff] [blame] | 400 | * @throws IOException |
| 401 | */ |
| 402 | @Test |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 403 | public void testSendDiscoveryMessage() throws IOException { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 404 | LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager(); |
srikanth | 9f38334 | 2014-06-12 11:49:00 -0700 | [diff] [blame] | 405 | |
| 406 | // Mock up our expected behavior |
| 407 | IOFSwitch swTest = createMockSwitch(3L); |
| 408 | getMockFloodlightProvider().getSwitches().put(3L, swTest); |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 409 | |
srikanth | 9f38334 | 2014-06-12 11:49:00 -0700 | [diff] [blame] | 410 | short portNum = 1; |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 411 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 412 | OFPortDesc ofPortDesc = createMockPort(portNum); |
| 413 | |
| 414 | expect(swTest.getPort(portNum)).andReturn(ofPortDesc).atLeastOnce(); |
| 415 | swTest.write(matchOutPort(portNum), |
| 416 | EasyMock.anyObject(FloodlightContext.class)); |
srikanth | 9f38334 | 2014-06-12 11:49:00 -0700 | [diff] [blame] | 417 | EasyMock.expectLastCall().times(1); |
| 418 | swTest.flush(); |
| 419 | EasyMock.expectLastCall().once(); |
| 420 | replay(swTest); |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 421 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 422 | linkDiscovery.sendDiscoveryMessage(3L, portNum, false); |
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 | verify(swTest); |
| 425 | } |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 426 | |
| 427 | @Test |
| 428 | public void testHandlePortStatusForNewPort() throws IOException { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 429 | LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager(); |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 430 | |
| 431 | long dpid = 3L; |
| 432 | IOFSwitch sw = createMockSwitch(dpid); |
| 433 | getMockFloodlightProvider().getSwitches().put(dpid, sw); |
| 434 | |
| 435 | short portNum = 1; |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 436 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 437 | OFPortDesc ofPortDesc = createMockPort(portNum); |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 438 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 439 | OFPortStatus portStatus = factory10.buildPortStatus() |
| 440 | .setDesc(ofPortDesc) |
| 441 | .setReason(OFPortReason.ADD) |
| 442 | .build(); |
| 443 | |
| 444 | expect(sw.getPort(portNum)).andReturn(ofPortDesc).once(); |
| 445 | |
| 446 | sw.write(matchOutPort(portNum), |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 447 | EasyMock.anyObject(FloodlightContext.class)); |
| 448 | sw.flush(); |
| 449 | |
| 450 | replay(sw); |
| 451 | |
| 452 | linkDiscovery.handlePortStatus(sw, portStatus); |
| 453 | |
| 454 | verify(sw); |
| 455 | } |
| 456 | |
| 457 | @Test |
| 458 | public void testHandlePortStatusForExistingPort() { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 459 | LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager(); |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 460 | |
| 461 | // Add a link that we can update later during the test |
| 462 | Link lt = new Link(1L, 1, 2L, 1); |
| 463 | LinkInfo info = new LinkInfo(System.currentTimeMillis(), |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 464 | System.currentTimeMillis(), EMPTY_PORT_STATE, EMPTY_PORT_STATE); |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 465 | linkDiscovery.addOrUpdateLink(lt, info); |
| 466 | |
| 467 | short portNum = 1; |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 468 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 469 | // Arbitrary states to test state changes |
| 470 | Set<OFPortState> srcPortState = |
| 471 | Collections.singleton(OFPortState.STP_FORWARD); |
| 472 | Set<OFPortState> dstPortState = |
| 473 | Collections.singleton(OFPortState.STP_LISTEN); |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 474 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 475 | OFPortDesc srcPortDesc = createMockPortWithState(portNum, srcPortState); |
| 476 | OFPortDesc dstPortDesc = createMockPortWithState(portNum, dstPortState); |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 477 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 478 | OFPortStatus srcPortStatus = factory10.buildPortStatus() |
| 479 | .setDesc(srcPortDesc) |
| 480 | .setReason(OFPortReason.MODIFY) |
| 481 | .build(); |
| 482 | |
| 483 | OFPortStatus dstPortStatus = factory10.buildPortStatus() |
| 484 | .setDesc(dstPortDesc) |
| 485 | .setReason(OFPortReason.MODIFY) |
| 486 | .build(); |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 487 | |
| 488 | linkDiscovery.handlePortStatus( |
| 489 | getMockFloodlightProvider().getSwitches().get(1L), srcPortStatus); |
| 490 | |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 491 | LinkInfo newInfo = linkDiscovery.links.get(lt); |
| 492 | assertEquals(srcPortState, newInfo.getSrcPortState()); |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 493 | assertEquals(EMPTY_PORT_STATE, newInfo.getDstPortState()); |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 494 | |
| 495 | linkDiscovery.handlePortStatus( |
| 496 | getMockFloodlightProvider().getSwitches().get(2L), dstPortStatus); |
| 497 | |
| 498 | newInfo = linkDiscovery.links.get(lt); |
| 499 | assertEquals(srcPortState, newInfo.getSrcPortState()); |
| 500 | assertEquals(dstPortState, newInfo.getDstPortState()); |
| 501 | } |
Jonathan Hart | 0f38354 | 2014-07-09 11:38:03 -0700 | [diff] [blame] | 502 | |
| 503 | @Test |
| 504 | public void testHandlePortStatusForDeletePort() { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 505 | LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager(); |
Jonathan Hart | 0f38354 | 2014-07-09 11:38:03 -0700 | [diff] [blame] | 506 | |
| 507 | // Add a link that we can delete later during the test |
| 508 | Link lt = new Link(1L, 1, 2L, 2); |
| 509 | LinkInfo info = new LinkInfo(System.currentTimeMillis(), |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 510 | System.currentTimeMillis(), EMPTY_PORT_STATE, EMPTY_PORT_STATE); |
Jonathan Hart | 0f38354 | 2014-07-09 11:38:03 -0700 | [diff] [blame] | 511 | linkDiscovery.addOrUpdateLink(lt, info); |
| 512 | |
| 513 | short portNum = 1; |
Jonathan Hart | 0f38354 | 2014-07-09 11:38:03 -0700 | [diff] [blame] | 514 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 515 | OFPortDesc srcPortDesc = createMockPort(portNum); |
| 516 | OFPortStatus srcPortStatus = factory10.buildPortStatus() |
| 517 | .setDesc(srcPortDesc) |
| 518 | .setReason(OFPortReason.DELETE) |
| 519 | .build(); |
Jonathan Hart | 0f38354 | 2014-07-09 11:38:03 -0700 | [diff] [blame] | 520 | |
| 521 | assertNotNull(linkDiscovery.getLinks().get(lt)); |
| 522 | |
| 523 | // Send a delete port status for the source port, which should result |
| 524 | // in the link being deleted |
| 525 | linkDiscovery.handlePortStatus( |
| 526 | getMockFloodlightProvider().getSwitches().get(1L), srcPortStatus); |
| 527 | |
| 528 | assertNull(linkDiscovery.getLinks().get(lt)); |
| 529 | } |
| 530 | |
| 531 | @Test |
| 532 | public void testReceive() { |
Jonathan Hart | 0f38354 | 2014-07-09 11:38:03 -0700 | [diff] [blame] | 533 | OnosLldp lldpPacket = new OnosLldp(); |
| 534 | lldpPacket.setPort((short) 1); |
| 535 | lldpPacket.setSwitch(1L); |
| 536 | lldpPacket.setReverse(false); |
| 537 | |
| 538 | Ethernet ethPacket = new Ethernet(); |
| 539 | ethPacket.setEtherType(Ethernet.TYPE_LLDP); |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 540 | ethPacket.setSourceMACAddress(DEFAULT_MAC_ADDRESS); |
Jonathan Hart | 0f38354 | 2014-07-09 11:38:03 -0700 | [diff] [blame] | 541 | ethPacket.setDestinationMACAddress( |
| 542 | LinkDiscoveryManager.LLDP_STANDARD_DST_MAC_STRING); |
| 543 | ethPacket.setPayload(lldpPacket); |
| 544 | ethPacket.setPad(true); |
| 545 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 546 | OFPacketIn pi = EasyMock.createMock(OFPacketIn.class); |
| 547 | expect(pi.getData()).andReturn(ethPacket.serialize()).anyTimes(); |
| 548 | replay(pi); |
Jonathan Hart | 0f38354 | 2014-07-09 11:38:03 -0700 | [diff] [blame] | 549 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 550 | LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager(); |
Jonathan Hart | 0f38354 | 2014-07-09 11:38:03 -0700 | [diff] [blame] | 551 | |
| 552 | Link expectedLink = new Link(1L, 1, 2L, 2); |
| 553 | |
| 554 | assertNull(linkDiscovery.links.get(expectedLink)); |
| 555 | |
| 556 | // Sending in the LLDP packet should cause the link to be created |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 557 | Command command = linkDiscovery.handleLldp(lldpPacket, 2L, pi, (short) 2); |
Jonathan Hart | 0f38354 | 2014-07-09 11:38:03 -0700 | [diff] [blame] | 558 | |
| 559 | assertEquals(Command.STOP, command); |
| 560 | assertNotNull(linkDiscovery.links.get(expectedLink)); |
| 561 | } |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 562 | } |