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(); |
Jonathan Hart | a213bce | 2014-08-11 15:44:07 -0700 | [diff] [blame] | 139 | expect(mockSwitch.getFactory()).andReturn(factory10).anyTimes(); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 140 | return mockSwitch; |
| 141 | } |
| 142 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 143 | private OFPortDesc createMockPort(short portNumber) { |
| 144 | return createMockPortWithState(portNumber, |
| 145 | Collections.<OFPortState>emptySet()); |
| 146 | } |
| 147 | |
| 148 | private OFPortDesc createMockPortWithState(short portNumber, |
| 149 | Set<OFPortState> state) { |
| 150 | OFPort ofPort = EasyMock.createMock(OFPort.class); |
| 151 | expect(ofPort.getShortPortNumber()).andReturn(portNumber).anyTimes(); |
| 152 | |
| 153 | OFPortDesc ofPortDesc = EasyMock.createMock(OFPortDesc.class); |
| 154 | expect(ofPortDesc.getPortNo()).andReturn(ofPort).anyTimes(); |
| 155 | expect(ofPortDesc.getHwAddr()).andReturn( |
| 156 | MacAddress.of(DEFAULT_MAC_ADDRESS)).anyTimes(); |
| 157 | expect(ofPortDesc.getConfig()). |
| 158 | andReturn(Collections.<OFPortConfig>emptySet()).anyTimes(); |
| 159 | expect(ofPortDesc.getState()).andReturn(state).anyTimes(); |
| 160 | |
| 161 | replay(ofPort); |
| 162 | replay(ofPortDesc); |
| 163 | |
| 164 | return ofPortDesc; |
| 165 | } |
| 166 | |
Yuta HIGUCHI | 44a0b35 | 2014-05-14 21:32:48 -0700 | [diff] [blame] | 167 | @Override |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 168 | @Before |
| 169 | public void setUp() throws Exception { |
| 170 | super.setUp(); |
| 171 | FloodlightModuleContext cntx = new FloodlightModuleContext(); |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 172 | ldm = new LinkDiscoveryManager(); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 173 | MockThreadPoolService tp = new MockThreadPoolService(); |
| 174 | RestApiServer restApi = new RestApiServer(); |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 175 | IControllerRegistryService registry = |
| 176 | EasyMock.createMock(IControllerRegistryService.class); |
| 177 | expect(registry.hasControl(EasyMock.anyLong())).andReturn(true).anyTimes(); |
| 178 | replay(registry); |
| 179 | cntx.addService(IControllerRegistryService.class, registry); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 180 | cntx.addService(IRestApiService.class, restApi); |
| 181 | cntx.addService(IThreadPoolService.class, tp); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 182 | cntx.addService(ILinkDiscoveryService.class, ldm); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 183 | cntx.addService(IFloodlightProviderService.class, getMockFloodlightProvider()); |
| 184 | restApi.init(cntx); |
| 185 | tp.init(cntx); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 186 | ldm.init(cntx); |
| 187 | restApi.startUp(cntx); |
| 188 | tp.startUp(cntx); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 189 | ldm.startUp(cntx); |
| 190 | |
| 191 | IOFSwitch sw1 = createMockSwitch(1L); |
| 192 | IOFSwitch sw2 = createMockSwitch(2L); |
| 193 | Map<Long, IOFSwitch> switches = new HashMap<Long, IOFSwitch>(); |
| 194 | switches.put(1L, sw1); |
| 195 | switches.put(2L, sw2); |
| 196 | getMockFloodlightProvider().setSwitches(switches); |
| 197 | replay(sw1, sw2); |
| 198 | } |
| 199 | |
| 200 | @Test |
| 201 | public void testAddOrUpdateLink() throws Exception { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 202 | LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager(); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 203 | |
| 204 | Link lt = new Link(1L, 2, 2L, 1); |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 205 | long firstSeenTime = System.currentTimeMillis(); |
| 206 | LinkInfo info = new LinkInfo(firstSeenTime, |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 207 | System.currentTimeMillis(), EMPTY_PORT_STATE, |
| 208 | EMPTY_PORT_STATE); |
| 209 | linkDiscovery.addOrUpdateLink(lt, info); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 210 | |
| 211 | NodePortTuple srcNpt = new NodePortTuple(1L, 2); |
| 212 | NodePortTuple dstNpt = new NodePortTuple(2L, 1); |
| 213 | |
| 214 | // check invariants hold |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 215 | assertNotNull(linkDiscovery.switchLinks.get(lt.getSrc())); |
| 216 | assertTrue(linkDiscovery.switchLinks.get(lt.getSrc()).contains(lt)); |
| 217 | assertNotNull(linkDiscovery.portLinks.get(srcNpt)); |
| 218 | assertTrue(linkDiscovery.portLinks.get(srcNpt).contains(lt)); |
| 219 | assertNotNull(linkDiscovery.portLinks.get(dstNpt)); |
| 220 | assertTrue(linkDiscovery.portLinks.get(dstNpt).contains(lt)); |
| 221 | assertTrue(linkDiscovery.links.containsKey(lt)); |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 222 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 223 | LinkInfo infoToVerify = linkDiscovery.links.get(lt); |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 224 | assertEquals(firstSeenTime, infoToVerify.getFirstSeenTime()); |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 225 | assertEquals(EMPTY_PORT_STATE, infoToVerify.getSrcPortState()); |
| 226 | assertEquals(EMPTY_PORT_STATE, infoToVerify.getDstPortState()); |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 227 | |
| 228 | // 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] | 229 | final Set<OFPortState> newSrcPortState = |
| 230 | Collections.singleton(OFPortState.STP_BLOCK); |
| 231 | final Set<OFPortState> newDstPortState = |
| 232 | Collections.singleton(OFPortState.LINK_DOWN); |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 233 | |
| 234 | // Update the last received probe timestamp and the port states |
| 235 | LinkInfo infoWithStateChange = new LinkInfo(System.currentTimeMillis(), |
| 236 | System.currentTimeMillis(), newSrcPortState, newDstPortState); |
| 237 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 238 | linkDiscovery.addOrUpdateLink(lt, infoWithStateChange); |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 239 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 240 | assertNotNull(linkDiscovery.links.get(lt)); |
| 241 | infoToVerify = linkDiscovery.links.get(lt); |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 242 | // First seen time should be the original time, not the second update time |
| 243 | assertEquals(firstSeenTime, infoToVerify.getFirstSeenTime()); |
| 244 | // Both port states should have been updated |
| 245 | assertEquals(newSrcPortState, infoToVerify.getSrcPortState()); |
| 246 | assertEquals(newDstPortState, infoToVerify.getDstPortState()); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | @Test |
| 250 | public void testDeleteLink() throws Exception { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 251 | LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager(); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 252 | |
| 253 | Link lt = new Link(1L, 2, 2L, 1); |
| 254 | LinkInfo info = new LinkInfo(System.currentTimeMillis(), |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 255 | System.currentTimeMillis(), EMPTY_PORT_STATE, EMPTY_PORT_STATE); |
| 256 | linkDiscovery.addOrUpdateLink(lt, info); |
| 257 | linkDiscovery.deleteLinks(Collections.singletonList(lt)); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 258 | |
| 259 | // check invariants hold |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 260 | assertNull(linkDiscovery.switchLinks.get(lt.getSrc())); |
| 261 | assertNull(linkDiscovery.switchLinks.get(lt.getDst())); |
| 262 | assertNull(linkDiscovery.portLinks.get(lt.getSrc())); |
| 263 | assertNull(linkDiscovery.portLinks.get(lt.getDst())); |
| 264 | assertTrue(linkDiscovery.links.isEmpty()); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | @Test |
| 268 | public void testAddOrUpdateLinkToSelf() throws Exception { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 269 | LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager(); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 270 | |
| 271 | Link lt = new Link(1L, 2, 2L, 3); |
| 272 | NodePortTuple srcNpt = new NodePortTuple(1L, 2); |
| 273 | NodePortTuple dstNpt = new NodePortTuple(2L, 3); |
| 274 | |
| 275 | LinkInfo info = new LinkInfo(System.currentTimeMillis(), |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 276 | System.currentTimeMillis(), EMPTY_PORT_STATE, EMPTY_PORT_STATE); |
| 277 | linkDiscovery.addOrUpdateLink(lt, info); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 278 | |
| 279 | // check invariants hold |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 280 | assertNotNull(linkDiscovery.switchLinks.get(lt.getSrc())); |
| 281 | assertTrue(linkDiscovery.switchLinks.get(lt.getSrc()).contains(lt)); |
| 282 | assertNotNull(linkDiscovery.portLinks.get(srcNpt)); |
| 283 | assertTrue(linkDiscovery.portLinks.get(srcNpt).contains(lt)); |
| 284 | assertNotNull(linkDiscovery.portLinks.get(dstNpt)); |
| 285 | assertTrue(linkDiscovery.portLinks.get(dstNpt).contains(lt)); |
| 286 | assertTrue(linkDiscovery.links.containsKey(lt)); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | @Test |
| 290 | public void testDeleteLinkToSelf() throws Exception { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 291 | LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager(); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 292 | |
| 293 | Link lt = new Link(1L, 2, 1L, 3); |
| 294 | NodePortTuple srcNpt = new NodePortTuple(1L, 2); |
| 295 | NodePortTuple dstNpt = new NodePortTuple(2L, 3); |
| 296 | |
| 297 | LinkInfo info = new LinkInfo(System.currentTimeMillis(), |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 298 | System.currentTimeMillis(), EMPTY_PORT_STATE, EMPTY_PORT_STATE); |
| 299 | linkDiscovery.addOrUpdateLink(lt, info); |
| 300 | linkDiscovery.deleteLinks(Collections.singletonList(lt)); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 301 | |
| 302 | // check invariants hold |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 303 | assertNull(linkDiscovery.switchLinks.get(lt.getSrc())); |
| 304 | assertNull(linkDiscovery.switchLinks.get(lt.getDst())); |
| 305 | assertNull(linkDiscovery.portLinks.get(srcNpt)); |
| 306 | assertNull(linkDiscovery.portLinks.get(dstNpt)); |
| 307 | assertTrue(linkDiscovery.links.isEmpty()); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | @Test |
| 311 | public void testRemovedSwitch() { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 312 | LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager(); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 313 | |
| 314 | Link lt = new Link(1L, 2, 2L, 1); |
| 315 | NodePortTuple srcNpt = new NodePortTuple(1L, 2); |
| 316 | NodePortTuple dstNpt = new NodePortTuple(2L, 1); |
| 317 | LinkInfo info = new LinkInfo(System.currentTimeMillis(), |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 318 | System.currentTimeMillis(), EMPTY_PORT_STATE, EMPTY_PORT_STATE); |
| 319 | linkDiscovery.addOrUpdateLink(lt, info); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 320 | |
| 321 | IOFSwitch sw1 = getMockFloodlightProvider().getSwitches().get(1L); |
| 322 | IOFSwitch sw2 = getMockFloodlightProvider().getSwitches().get(2L); |
| 323 | // Mock up our expected behavior |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 324 | linkDiscovery.switchDisconnected(sw1.getId()); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 325 | verify(sw1, sw2); |
| 326 | |
| 327 | // check invariants hold |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 328 | assertNull(linkDiscovery.switchLinks.get(lt.getSrc())); |
| 329 | assertNull(linkDiscovery.switchLinks.get(lt.getDst())); |
| 330 | assertNull(linkDiscovery.portLinks.get(srcNpt)); |
| 331 | assertNull(linkDiscovery.portLinks.get(dstNpt)); |
| 332 | assertTrue(linkDiscovery.links.isEmpty()); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | @Test |
| 336 | public void testRemovedSwitchSelf() { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 337 | LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager(); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 338 | IOFSwitch sw1 = createMockSwitch(1L); |
| 339 | replay(sw1); |
| 340 | Link lt = new Link(1L, 2, 1L, 3); |
| 341 | LinkInfo info = new LinkInfo(System.currentTimeMillis(), |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 342 | System.currentTimeMillis(), EMPTY_PORT_STATE, EMPTY_PORT_STATE); |
| 343 | linkDiscovery.addOrUpdateLink(lt, info); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 344 | |
| 345 | // Mock up our expected behavior |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 346 | linkDiscovery.switchDisconnected(sw1.getId()); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 347 | |
| 348 | verify(sw1); |
| 349 | // check invariants hold |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 350 | assertNull(linkDiscovery.switchLinks.get(lt.getSrc())); |
| 351 | assertNull(linkDiscovery.portLinks.get(lt.getSrc())); |
| 352 | assertNull(linkDiscovery.portLinks.get(lt.getDst())); |
| 353 | assertTrue(linkDiscovery.links.isEmpty()); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | @Test |
| 357 | public void testAddUpdateLinks() throws Exception { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 358 | LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager(); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 359 | |
| 360 | Link lt = new Link(1L, 1, 2L, 1); |
| 361 | NodePortTuple srcNpt = new NodePortTuple(1L, 1); |
| 362 | NodePortTuple dstNpt = new NodePortTuple(2L, 1); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 363 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 364 | LinkInfo info; |
| 365 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 366 | // Setting the last LLDP reception time to be 40 seconds old, so we |
| 367 | // can use this to test that an old link times out correctly |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 368 | info = new LinkInfo(System.currentTimeMillis() - 40000, |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 369 | System.currentTimeMillis() - 40000, |
| 370 | EMPTY_PORT_STATE, EMPTY_PORT_STATE); |
| 371 | linkDiscovery.addOrUpdateLink(lt, info); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 372 | |
| 373 | // check invariants hold |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 374 | assertNotNull(linkDiscovery.switchLinks.get(lt.getSrc())); |
| 375 | assertTrue(linkDiscovery.switchLinks.get(lt.getSrc()).contains(lt)); |
| 376 | assertNotNull(linkDiscovery.portLinks.get(srcNpt)); |
| 377 | assertTrue(linkDiscovery.portLinks.get(srcNpt).contains(lt)); |
| 378 | assertNotNull(linkDiscovery.portLinks.get(dstNpt)); |
| 379 | assertTrue(linkDiscovery.portLinks.get(dstNpt).contains(lt)); |
| 380 | assertTrue(linkDiscovery.links.containsKey(lt)); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 381 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 382 | linkDiscovery.timeOutLinks(); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 383 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 384 | // Setting the last LLDP reception time to be 40 seconds old, so we |
| 385 | // can use this to test that an old link times out correctly |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 386 | info = new LinkInfo(System.currentTimeMillis() - 40000, |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 387 | System.currentTimeMillis() - 40000, |
| 388 | EMPTY_PORT_STATE, EMPTY_PORT_STATE); |
| 389 | linkDiscovery.addOrUpdateLink(lt, info); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 390 | |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 391 | // 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] | 392 | linkDiscovery.timeOutLinks(); |
| 393 | assertTrue(linkDiscovery.links.get(lt) == null); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 394 | } |
srikanth | 9f38334 | 2014-06-12 11:49:00 -0700 | [diff] [blame] | 395 | |
| 396 | /** |
| 397 | * This test case verifies that LinkDiscoveryManager.sendDiscoveryMessage() |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 398 | * performs "write" operation on the specified IOFSwitch object |
| 399 | * with a LLDP packet. |
| 400 | * |
srikanth | 9f38334 | 2014-06-12 11:49:00 -0700 | [diff] [blame] | 401 | * @throws IOException |
| 402 | */ |
| 403 | @Test |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 404 | public void testSendDiscoveryMessage() throws IOException { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 405 | LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager(); |
srikanth | 9f38334 | 2014-06-12 11:49:00 -0700 | [diff] [blame] | 406 | |
| 407 | // Mock up our expected behavior |
| 408 | IOFSwitch swTest = createMockSwitch(3L); |
| 409 | getMockFloodlightProvider().getSwitches().put(3L, swTest); |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 410 | |
srikanth | 9f38334 | 2014-06-12 11:49:00 -0700 | [diff] [blame] | 411 | short portNum = 1; |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 412 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 413 | OFPortDesc ofPortDesc = createMockPort(portNum); |
| 414 | |
| 415 | expect(swTest.getPort(portNum)).andReturn(ofPortDesc).atLeastOnce(); |
| 416 | swTest.write(matchOutPort(portNum), |
| 417 | EasyMock.anyObject(FloodlightContext.class)); |
srikanth | 9f38334 | 2014-06-12 11:49:00 -0700 | [diff] [blame] | 418 | EasyMock.expectLastCall().times(1); |
| 419 | swTest.flush(); |
| 420 | EasyMock.expectLastCall().once(); |
| 421 | replay(swTest); |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 422 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 423 | linkDiscovery.sendDiscoveryMessage(3L, portNum, false); |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 424 | |
srikanth | 9f38334 | 2014-06-12 11:49:00 -0700 | [diff] [blame] | 425 | verify(swTest); |
| 426 | } |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 427 | |
| 428 | @Test |
| 429 | public void testHandlePortStatusForNewPort() throws IOException { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 430 | LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager(); |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 431 | |
| 432 | long dpid = 3L; |
| 433 | IOFSwitch sw = createMockSwitch(dpid); |
| 434 | getMockFloodlightProvider().getSwitches().put(dpid, sw); |
| 435 | |
| 436 | short portNum = 1; |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 437 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 438 | OFPortDesc ofPortDesc = createMockPort(portNum); |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 439 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 440 | OFPortStatus portStatus = factory10.buildPortStatus() |
| 441 | .setDesc(ofPortDesc) |
| 442 | .setReason(OFPortReason.ADD) |
| 443 | .build(); |
| 444 | |
| 445 | expect(sw.getPort(portNum)).andReturn(ofPortDesc).once(); |
| 446 | |
| 447 | sw.write(matchOutPort(portNum), |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 448 | EasyMock.anyObject(FloodlightContext.class)); |
| 449 | sw.flush(); |
| 450 | |
| 451 | replay(sw); |
| 452 | |
| 453 | linkDiscovery.handlePortStatus(sw, portStatus); |
| 454 | |
| 455 | verify(sw); |
| 456 | } |
| 457 | |
| 458 | @Test |
| 459 | public void testHandlePortStatusForExistingPort() { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 460 | LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager(); |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 461 | |
| 462 | // Add a link that we can update later during the test |
| 463 | Link lt = new Link(1L, 1, 2L, 1); |
| 464 | LinkInfo info = new LinkInfo(System.currentTimeMillis(), |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 465 | System.currentTimeMillis(), EMPTY_PORT_STATE, EMPTY_PORT_STATE); |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 466 | linkDiscovery.addOrUpdateLink(lt, info); |
| 467 | |
| 468 | short portNum = 1; |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 469 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 470 | // Arbitrary states to test state changes |
| 471 | Set<OFPortState> srcPortState = |
| 472 | Collections.singleton(OFPortState.STP_FORWARD); |
| 473 | Set<OFPortState> dstPortState = |
| 474 | Collections.singleton(OFPortState.STP_LISTEN); |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 475 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 476 | OFPortDesc srcPortDesc = createMockPortWithState(portNum, srcPortState); |
| 477 | OFPortDesc dstPortDesc = createMockPortWithState(portNum, dstPortState); |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 478 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 479 | OFPortStatus srcPortStatus = factory10.buildPortStatus() |
| 480 | .setDesc(srcPortDesc) |
| 481 | .setReason(OFPortReason.MODIFY) |
| 482 | .build(); |
| 483 | |
| 484 | OFPortStatus dstPortStatus = factory10.buildPortStatus() |
| 485 | .setDesc(dstPortDesc) |
| 486 | .setReason(OFPortReason.MODIFY) |
| 487 | .build(); |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 488 | |
| 489 | linkDiscovery.handlePortStatus( |
| 490 | getMockFloodlightProvider().getSwitches().get(1L), srcPortStatus); |
| 491 | |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 492 | LinkInfo newInfo = linkDiscovery.links.get(lt); |
| 493 | assertEquals(srcPortState, newInfo.getSrcPortState()); |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 494 | assertEquals(EMPTY_PORT_STATE, newInfo.getDstPortState()); |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 495 | |
| 496 | linkDiscovery.handlePortStatus( |
| 497 | getMockFloodlightProvider().getSwitches().get(2L), dstPortStatus); |
| 498 | |
| 499 | newInfo = linkDiscovery.links.get(lt); |
| 500 | assertEquals(srcPortState, newInfo.getSrcPortState()); |
| 501 | assertEquals(dstPortState, newInfo.getDstPortState()); |
| 502 | } |
Jonathan Hart | 0f38354 | 2014-07-09 11:38:03 -0700 | [diff] [blame] | 503 | |
| 504 | @Test |
| 505 | public void testHandlePortStatusForDeletePort() { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 506 | LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager(); |
Jonathan Hart | 0f38354 | 2014-07-09 11:38:03 -0700 | [diff] [blame] | 507 | |
| 508 | // Add a link that we can delete later during the test |
| 509 | Link lt = new Link(1L, 1, 2L, 2); |
| 510 | LinkInfo info = new LinkInfo(System.currentTimeMillis(), |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 511 | System.currentTimeMillis(), EMPTY_PORT_STATE, EMPTY_PORT_STATE); |
Jonathan Hart | 0f38354 | 2014-07-09 11:38:03 -0700 | [diff] [blame] | 512 | linkDiscovery.addOrUpdateLink(lt, info); |
| 513 | |
| 514 | short portNum = 1; |
Jonathan Hart | 0f38354 | 2014-07-09 11:38:03 -0700 | [diff] [blame] | 515 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 516 | OFPortDesc srcPortDesc = createMockPort(portNum); |
| 517 | OFPortStatus srcPortStatus = factory10.buildPortStatus() |
| 518 | .setDesc(srcPortDesc) |
| 519 | .setReason(OFPortReason.DELETE) |
| 520 | .build(); |
Jonathan Hart | 0f38354 | 2014-07-09 11:38:03 -0700 | [diff] [blame] | 521 | |
| 522 | assertNotNull(linkDiscovery.getLinks().get(lt)); |
| 523 | |
| 524 | // Send a delete port status for the source port, which should result |
| 525 | // in the link being deleted |
| 526 | linkDiscovery.handlePortStatus( |
| 527 | getMockFloodlightProvider().getSwitches().get(1L), srcPortStatus); |
| 528 | |
| 529 | assertNull(linkDiscovery.getLinks().get(lt)); |
| 530 | } |
| 531 | |
| 532 | @Test |
| 533 | public void testReceive() { |
Jonathan Hart | 0f38354 | 2014-07-09 11:38:03 -0700 | [diff] [blame] | 534 | OnosLldp lldpPacket = new OnosLldp(); |
| 535 | lldpPacket.setPort((short) 1); |
| 536 | lldpPacket.setSwitch(1L); |
| 537 | lldpPacket.setReverse(false); |
| 538 | |
| 539 | Ethernet ethPacket = new Ethernet(); |
| 540 | ethPacket.setEtherType(Ethernet.TYPE_LLDP); |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 541 | ethPacket.setSourceMACAddress(DEFAULT_MAC_ADDRESS); |
Jonathan Hart | 0f38354 | 2014-07-09 11:38:03 -0700 | [diff] [blame] | 542 | ethPacket.setDestinationMACAddress( |
| 543 | LinkDiscoveryManager.LLDP_STANDARD_DST_MAC_STRING); |
| 544 | ethPacket.setPayload(lldpPacket); |
| 545 | ethPacket.setPad(true); |
| 546 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 547 | OFPacketIn pi = EasyMock.createMock(OFPacketIn.class); |
| 548 | expect(pi.getData()).andReturn(ethPacket.serialize()).anyTimes(); |
| 549 | replay(pi); |
Jonathan Hart | 0f38354 | 2014-07-09 11:38:03 -0700 | [diff] [blame] | 550 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 551 | LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager(); |
Jonathan Hart | 0f38354 | 2014-07-09 11:38:03 -0700 | [diff] [blame] | 552 | |
| 553 | Link expectedLink = new Link(1L, 1, 2L, 2); |
| 554 | |
| 555 | assertNull(linkDiscovery.links.get(expectedLink)); |
| 556 | |
| 557 | // 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] | 558 | Command command = linkDiscovery.handleLldp(lldpPacket, 2L, pi, (short) 2); |
Jonathan Hart | 0f38354 | 2014-07-09 11:38:03 -0700 | [diff] [blame] | 559 | |
| 560 | assertEquals(Command.STOP, command); |
| 561 | assertNotNull(linkDiscovery.links.get(expectedLink)); |
| 562 | } |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 563 | } |