Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 2 | * Copyright 2014 Open Networking Laboratory |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.provider.lldp.impl; |
alshabib | 0ed6a20 | 2014-10-19 12:42:57 -0700 | [diff] [blame] | 17 | |
Pavlin Radoslavov | d36a74b | 2015-01-09 11:59:07 -0800 | [diff] [blame] | 18 | import static org.easymock.EasyMock.createMock; |
| 19 | import static org.easymock.EasyMock.expect; |
Pavlin Radoslavov | d36a74b | 2015-01-09 11:59:07 -0800 | [diff] [blame] | 20 | import static org.easymock.EasyMock.replay; |
Jonathan Hart | 3cfce8e | 2015-01-14 16:43:27 -0800 | [diff] [blame] | 21 | import static org.junit.Assert.assertEquals; |
| 22 | import static org.junit.Assert.assertFalse; |
| 23 | import static org.junit.Assert.assertNotNull; |
| 24 | import static org.junit.Assert.assertNull; |
| 25 | import static org.junit.Assert.assertTrue; |
alshabib | 0ed6a20 | 2014-10-19 12:42:57 -0700 | [diff] [blame] | 26 | |
Jonathan Hart | 3cfce8e | 2015-01-14 16:43:27 -0800 | [diff] [blame] | 27 | import java.nio.ByteBuffer; |
| 28 | import java.util.Collections; |
| 29 | import java.util.HashMap; |
| 30 | import java.util.List; |
| 31 | import java.util.Map; |
| 32 | import java.util.Set; |
Yuta HIGUCHI | 376d750 | 2014-10-19 15:57:52 -0700 | [diff] [blame] | 33 | |
alshabib | 0ed6a20 | 2014-10-19 12:42:57 -0700 | [diff] [blame] | 34 | import org.junit.After; |
| 35 | import org.junit.Before; |
| 36 | import org.junit.Test; |
Jonathan Hart | 3cfce8e | 2015-01-14 16:43:27 -0800 | [diff] [blame] | 37 | import org.onlab.packet.ChassisId; |
| 38 | import org.onlab.packet.Ethernet; |
| 39 | import org.onlab.packet.ONOSLLDP; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 40 | import org.onosproject.cluster.NodeId; |
| 41 | import org.onosproject.cluster.RoleInfo; |
Pavlin Radoslavov | d36a74b | 2015-01-09 11:59:07 -0800 | [diff] [blame] | 42 | import org.onosproject.core.ApplicationId; |
| 43 | import org.onosproject.core.CoreService; |
| 44 | import org.onosproject.core.DefaultApplicationId; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 45 | import org.onosproject.mastership.MastershipListener; |
| 46 | import org.onosproject.mastership.MastershipService; |
| 47 | import org.onosproject.net.ConnectPoint; |
| 48 | import org.onosproject.net.DefaultDevice; |
| 49 | import org.onosproject.net.DefaultPort; |
| 50 | import org.onosproject.net.Device; |
| 51 | import org.onosproject.net.DeviceId; |
| 52 | import org.onosproject.net.MastershipRole; |
| 53 | import org.onosproject.net.Port; |
| 54 | import org.onosproject.net.PortNumber; |
| 55 | import org.onosproject.net.device.DeviceEvent; |
| 56 | import org.onosproject.net.device.DeviceListener; |
| 57 | import org.onosproject.net.device.DeviceServiceAdapter; |
Saurav Das | c313c40 | 2015-02-27 10:09:47 -0800 | [diff] [blame] | 58 | import org.onosproject.net.flow.FlowRule; |
Jonathan Hart | 3cfce8e | 2015-01-14 16:43:27 -0800 | [diff] [blame] | 59 | import org.onosproject.net.flow.TrafficSelector; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 60 | import org.onosproject.net.flow.TrafficTreatment; |
| 61 | import org.onosproject.net.link.LinkDescription; |
| 62 | import org.onosproject.net.link.LinkProvider; |
| 63 | import org.onosproject.net.link.LinkProviderRegistry; |
| 64 | import org.onosproject.net.link.LinkProviderService; |
| 65 | import org.onosproject.net.packet.DefaultInboundPacket; |
| 66 | import org.onosproject.net.packet.InboundPacket; |
| 67 | import org.onosproject.net.packet.OutboundPacket; |
| 68 | import org.onosproject.net.packet.PacketContext; |
Jonathan Hart | 3cfce8e | 2015-01-14 16:43:27 -0800 | [diff] [blame] | 69 | import org.onosproject.net.packet.PacketPriority; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 70 | import org.onosproject.net.packet.PacketProcessor; |
| 71 | import org.onosproject.net.packet.PacketService; |
| 72 | import org.onosproject.net.provider.AbstractProviderService; |
| 73 | import org.onosproject.net.provider.ProviderId; |
alshabib | 0ed6a20 | 2014-10-19 12:42:57 -0700 | [diff] [blame] | 74 | |
Jonathan Hart | 3cfce8e | 2015-01-14 16:43:27 -0800 | [diff] [blame] | 75 | import com.google.common.collect.ArrayListMultimap; |
| 76 | import com.google.common.collect.Lists; |
| 77 | import com.google.common.collect.Maps; |
alshabib | 0ed6a20 | 2014-10-19 12:42:57 -0700 | [diff] [blame] | 78 | |
| 79 | public class LLDPLinkProviderTest { |
| 80 | |
| 81 | private static final DeviceId DID1 = DeviceId.deviceId("of:0000000000000001"); |
| 82 | private static final DeviceId DID2 = DeviceId.deviceId("of:0000000000000002"); |
| 83 | |
| 84 | private static Port pd1; |
| 85 | private static Port pd2; |
| 86 | private static Port pd3; |
| 87 | private static Port pd4; |
| 88 | |
| 89 | private final LLDPLinkProvider provider = new LLDPLinkProvider(); |
| 90 | private final TestLinkRegistry linkService = new TestLinkRegistry(); |
| 91 | private final TestPacketService packetService = new TestPacketService(); |
| 92 | private final TestDeviceService deviceService = new TestDeviceService(); |
| 93 | private final TestMasterShipService masterService = new TestMasterShipService(); |
| 94 | |
Pavlin Radoslavov | d36a74b | 2015-01-09 11:59:07 -0800 | [diff] [blame] | 95 | private CoreService coreService; |
alshabib | 0ed6a20 | 2014-10-19 12:42:57 -0700 | [diff] [blame] | 96 | private TestLinkProviderService providerService; |
| 97 | |
| 98 | private PacketProcessor testProcessor; |
| 99 | private DeviceListener deviceListener; |
| 100 | |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 101 | private ApplicationId appId = |
| 102 | new DefaultApplicationId(100, "org.onosproject.provider.lldp"); |
Pavlin Radoslavov | d36a74b | 2015-01-09 11:59:07 -0800 | [diff] [blame] | 103 | |
alshabib | 0ed6a20 | 2014-10-19 12:42:57 -0700 | [diff] [blame] | 104 | @Before |
| 105 | public void setUp() { |
| 106 | |
Pavlin Radoslavov | d36a74b | 2015-01-09 11:59:07 -0800 | [diff] [blame] | 107 | coreService = createMock(CoreService.class); |
| 108 | expect(coreService.registerApplication(appId.name())) |
| 109 | .andReturn(appId).anyTimes(); |
| 110 | replay(coreService); |
| 111 | |
Pavlin Radoslavov | d36a74b | 2015-01-09 11:59:07 -0800 | [diff] [blame] | 112 | provider.coreService = coreService; |
Pavlin Radoslavov | d36a74b | 2015-01-09 11:59:07 -0800 | [diff] [blame] | 113 | |
alshabib | 0ed6a20 | 2014-10-19 12:42:57 -0700 | [diff] [blame] | 114 | provider.deviceService = deviceService; |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 115 | provider.packetService = packetService; |
alshabib | 0ed6a20 | 2014-10-19 12:42:57 -0700 | [diff] [blame] | 116 | provider.providerRegistry = linkService; |
| 117 | provider.masterService = masterService; |
| 118 | |
| 119 | |
Saurav Das | c313c40 | 2015-02-27 10:09:47 -0800 | [diff] [blame] | 120 | provider.activate(null); |
alshabib | 0ed6a20 | 2014-10-19 12:42:57 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | @Test |
| 124 | public void basics() { |
| 125 | assertNotNull("registration expected", providerService); |
| 126 | assertEquals("incorrect provider", provider, providerService.provider()); |
| 127 | } |
| 128 | |
| 129 | @Test |
| 130 | public void switchAdd() { |
| 131 | DeviceEvent de = deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID1); |
| 132 | deviceListener.event(de); |
| 133 | |
| 134 | assertFalse("Device not added", provider.discoverers.isEmpty()); |
| 135 | } |
| 136 | |
| 137 | @Test |
| 138 | public void switchRemove() { |
| 139 | deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID1)); |
| 140 | deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_REMOVED, DID1)); |
| 141 | |
| 142 | assertTrue("Discoverer is not gone", provider.discoverers.get(DID1).isStopped()); |
| 143 | assertTrue("Device is not gone.", vanishedDpid(DID1)); |
| 144 | } |
| 145 | |
| 146 | @Test |
| 147 | public void portUp() { |
| 148 | deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID1)); |
| 149 | deviceListener.event(portEvent(DeviceEvent.Type.PORT_ADDED, DID1, port(DID1, 3, true))); |
| 150 | |
| 151 | assertTrue("Port not added to discoverer", |
| 152 | provider.discoverers.get(DID1).containsPort((long) 3)); |
| 153 | } |
| 154 | |
| 155 | @Test |
| 156 | public void portDown() { |
| 157 | |
| 158 | deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID1)); |
| 159 | deviceListener.event(portEvent(DeviceEvent.Type.PORT_ADDED, DID1, port(DID1, 1, false))); |
| 160 | |
| 161 | |
| 162 | |
| 163 | assertFalse("Port added to discoverer", |
| 164 | provider.discoverers.get(DID1).containsPort((long) 1)); |
| 165 | assertTrue("Port is not gone.", vanishedPort((long) 1)); |
| 166 | } |
| 167 | |
| 168 | @Test |
| 169 | public void portUnknown() { |
| 170 | deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID1)); |
| 171 | deviceListener.event(portEvent(DeviceEvent.Type.PORT_ADDED, DID2, port(DID2, 1, false))); |
| 172 | |
| 173 | |
alshabib | dfc7afb | 2014-10-21 20:13:27 -0700 | [diff] [blame] | 174 | assertNull("DeviceId exists", |
alshabib | 0ed6a20 | 2014-10-19 12:42:57 -0700 | [diff] [blame] | 175 | provider.discoverers.get(DID2)); |
| 176 | } |
| 177 | |
| 178 | @Test |
| 179 | public void unknownPktCtx() { |
| 180 | |
| 181 | PacketContext pktCtx = new TestPacketContext(deviceService.getDevice(DID2)); |
| 182 | |
| 183 | testProcessor.process(pktCtx); |
| 184 | assertFalse("Context should still be free", pktCtx.isHandled()); |
| 185 | } |
| 186 | |
| 187 | @Test |
| 188 | public void knownPktCtx() { |
| 189 | deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID1)); |
| 190 | deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID2)); |
| 191 | PacketContext pktCtx = new TestPacketContext(deviceService.getDevice(DID2)); |
| 192 | |
| 193 | |
| 194 | testProcessor.process(pktCtx); |
| 195 | |
| 196 | assertTrue("Link not detected", detectedLink(DID1, DID2)); |
| 197 | |
| 198 | } |
| 199 | |
| 200 | |
| 201 | @After |
| 202 | public void tearDown() { |
| 203 | provider.deactivate(); |
Pavlin Radoslavov | d36a74b | 2015-01-09 11:59:07 -0800 | [diff] [blame] | 204 | provider.coreService = null; |
alshabib | 0ed6a20 | 2014-10-19 12:42:57 -0700 | [diff] [blame] | 205 | provider.providerRegistry = null; |
| 206 | provider.deviceService = null; |
Marc De Leenheer | 8b3e80b | 2015-03-06 14:27:03 -0800 | [diff] [blame] | 207 | provider.packetService = null; |
alshabib | 0ed6a20 | 2014-10-19 12:42:57 -0700 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | private DeviceEvent deviceEvent(DeviceEvent.Type type, DeviceId did) { |
| 211 | return new DeviceEvent(type, deviceService.getDevice(did)); |
| 212 | |
| 213 | } |
| 214 | |
Saurav Das | c313c40 | 2015-02-27 10:09:47 -0800 | [diff] [blame] | 215 | @SuppressWarnings(value = { "unused" }) |
alshabib | 0ed6a20 | 2014-10-19 12:42:57 -0700 | [diff] [blame] | 216 | private DeviceEvent portEvent(DeviceEvent.Type type, DeviceId did, PortNumber port) { |
| 217 | return new DeviceEvent(type, deviceService.getDevice(did), |
| 218 | deviceService.getPort(did, port)); |
| 219 | } |
| 220 | |
| 221 | private DeviceEvent portEvent(DeviceEvent.Type type, DeviceId did, Port port) { |
| 222 | return new DeviceEvent(type, deviceService.getDevice(did), port); |
| 223 | } |
| 224 | |
| 225 | private Port port(DeviceId did, long port, boolean enabled) { |
| 226 | return new DefaultPort(deviceService.getDevice(did), |
| 227 | PortNumber.portNumber(port), enabled); |
| 228 | } |
| 229 | |
| 230 | |
| 231 | private boolean vanishedDpid(DeviceId... dids) { |
| 232 | for (int i = 0; i < dids.length; i++) { |
| 233 | if (!providerService.vanishedDpid.contains(dids[i])) { |
| 234 | return false; |
| 235 | } |
| 236 | } |
| 237 | return true; |
| 238 | } |
| 239 | |
| 240 | private boolean vanishedPort(Long... ports) { |
| 241 | for (int i = 0; i < ports.length; i++) { |
| 242 | if (!providerService.vanishedPort.contains(ports[i])) { |
| 243 | return false; |
| 244 | } |
| 245 | } |
| 246 | return true; |
| 247 | } |
| 248 | |
| 249 | private boolean detectedLink(DeviceId src, DeviceId dst) { |
| 250 | for (DeviceId key : providerService.discoveredLinks.keySet()) { |
| 251 | if (key.equals(src)) { |
| 252 | return providerService.discoveredLinks.get(src).equals(dst); |
| 253 | } |
| 254 | } |
| 255 | return false; |
| 256 | } |
| 257 | |
| 258 | |
| 259 | private class TestLinkRegistry implements LinkProviderRegistry { |
| 260 | |
| 261 | @Override |
| 262 | public LinkProviderService register(LinkProvider provider) { |
| 263 | providerService = new TestLinkProviderService(provider); |
| 264 | return providerService; |
| 265 | } |
| 266 | |
| 267 | @Override |
| 268 | public void unregister(LinkProvider provider) { |
| 269 | } |
| 270 | |
| 271 | @Override |
| 272 | public Set<ProviderId> getProviders() { |
| 273 | return null; |
| 274 | } |
| 275 | |
| 276 | } |
| 277 | |
| 278 | private class TestLinkProviderService |
| 279 | extends AbstractProviderService<LinkProvider> |
| 280 | implements LinkProviderService { |
| 281 | |
| 282 | List<DeviceId> vanishedDpid = Lists.newLinkedList(); |
| 283 | List<Long> vanishedPort = Lists.newLinkedList(); |
| 284 | Map<DeviceId, DeviceId> discoveredLinks = Maps.newHashMap(); |
| 285 | |
| 286 | protected TestLinkProviderService(LinkProvider provider) { |
| 287 | super(provider); |
| 288 | } |
| 289 | |
| 290 | @Override |
| 291 | public void linkDetected(LinkDescription linkDescription) { |
| 292 | DeviceId sDid = linkDescription.src().deviceId(); |
| 293 | DeviceId dDid = linkDescription.dst().deviceId(); |
| 294 | discoveredLinks.put(sDid, dDid); |
| 295 | } |
| 296 | |
| 297 | @Override |
| 298 | public void linkVanished(LinkDescription linkDescription) { |
alshabib | 0ed6a20 | 2014-10-19 12:42:57 -0700 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | @Override |
| 302 | public void linksVanished(ConnectPoint connectPoint) { |
| 303 | vanishedPort.add(connectPoint.port().toLong()); |
| 304 | |
| 305 | } |
| 306 | |
| 307 | @Override |
| 308 | public void linksVanished(DeviceId deviceId) { |
| 309 | vanishedDpid.add(deviceId); |
| 310 | } |
| 311 | |
| 312 | |
| 313 | } |
| 314 | |
| 315 | |
| 316 | |
| 317 | private class TestPacketContext implements PacketContext { |
| 318 | |
| 319 | protected Device device; |
| 320 | protected boolean blocked = false; |
| 321 | |
| 322 | public TestPacketContext(Device dev) { |
| 323 | device = dev; |
| 324 | } |
| 325 | |
| 326 | @Override |
| 327 | public long time() { |
| 328 | return 0; |
| 329 | } |
| 330 | |
| 331 | @Override |
| 332 | public InboundPacket inPacket() { |
| 333 | ONOSLLDP lldp = new ONOSLLDP(); |
| 334 | lldp.setChassisId(device.chassisId()); |
| 335 | lldp.setPortId((int) pd1.number().toLong()); |
| 336 | lldp.setDevice(deviceService.getDevice(DID1).id().toString()); |
| 337 | |
| 338 | |
| 339 | Ethernet ethPacket = new Ethernet(); |
| 340 | ethPacket.setEtherType(Ethernet.TYPE_LLDP); |
| 341 | ethPacket.setDestinationMACAddress(ONOSLLDP.LLDP_NICIRA); |
| 342 | ethPacket.setPayload(lldp); |
| 343 | ethPacket.setPad(true); |
| 344 | |
| 345 | |
| 346 | |
| 347 | ethPacket.setSourceMACAddress("DE:AD:BE:EF:BA:11"); |
| 348 | |
| 349 | ConnectPoint cp = new ConnectPoint(device.id(), pd3.number()); |
| 350 | |
| 351 | return new DefaultInboundPacket(cp, ethPacket, |
| 352 | ByteBuffer.wrap(ethPacket.serialize())); |
| 353 | |
| 354 | } |
| 355 | |
| 356 | @Override |
| 357 | public OutboundPacket outPacket() { |
| 358 | return null; |
| 359 | } |
| 360 | |
| 361 | @Override |
| 362 | public TrafficTreatment.Builder treatmentBuilder() { |
| 363 | return null; |
| 364 | } |
| 365 | |
| 366 | @Override |
| 367 | public void send() { |
| 368 | |
| 369 | } |
| 370 | |
| 371 | @Override |
| 372 | public boolean block() { |
| 373 | blocked = true; |
| 374 | return blocked; |
| 375 | } |
| 376 | |
| 377 | @Override |
| 378 | public boolean isHandled() { |
| 379 | return blocked; |
| 380 | } |
| 381 | |
| 382 | } |
| 383 | |
| 384 | private class TestPacketService implements PacketService { |
| 385 | |
| 386 | @Override |
| 387 | public void addProcessor(PacketProcessor processor, int priority) { |
| 388 | testProcessor = processor; |
| 389 | } |
| 390 | |
| 391 | @Override |
| 392 | public void removeProcessor(PacketProcessor processor) { |
| 393 | |
| 394 | } |
| 395 | |
| 396 | @Override |
| 397 | public void emit(OutboundPacket packet) { |
| 398 | |
| 399 | } |
Jonathan Hart | 3cfce8e | 2015-01-14 16:43:27 -0800 | [diff] [blame] | 400 | |
| 401 | @Override |
| 402 | public void requestPackets(TrafficSelector selector, |
| 403 | PacketPriority priority, ApplicationId appId) { |
| 404 | } |
Saurav Das | c313c40 | 2015-02-27 10:09:47 -0800 | [diff] [blame] | 405 | |
| 406 | @Override |
| 407 | public void requestPackets(TrafficSelector selector, |
| 408 | PacketPriority priority, ApplicationId appId, |
| 409 | FlowRule.Type tableType) { |
| 410 | } |
alshabib | 0ed6a20 | 2014-10-19 12:42:57 -0700 | [diff] [blame] | 411 | } |
| 412 | |
Yuta HIGUCHI | f1f2ac0 | 2014-11-26 14:02:22 -0800 | [diff] [blame] | 413 | private class TestDeviceService extends DeviceServiceAdapter { |
alshabib | 0ed6a20 | 2014-10-19 12:42:57 -0700 | [diff] [blame] | 414 | |
| 415 | private Map<DeviceId, Device> devices = new HashMap<>(); |
| 416 | private final ArrayListMultimap<DeviceId, Port> ports = |
| 417 | ArrayListMultimap.create(); |
| 418 | |
| 419 | public TestDeviceService() { |
| 420 | Device d1 = new DefaultDevice(ProviderId.NONE, DID1, Device.Type.SWITCH, |
| 421 | "TESTMF", "TESTHW", "TESTSW", "TESTSN", new ChassisId()); |
| 422 | Device d2 = new DefaultDevice(ProviderId.NONE, DID2, Device.Type.SWITCH, |
| 423 | "TESTMF", "TESTHW", "TESTSW", "TESTSN", new ChassisId()); |
| 424 | devices.put(DID1, d1); |
| 425 | devices.put(DID2, d2); |
| 426 | |
| 427 | pd1 = new DefaultPort(d1, PortNumber.portNumber(1), true); |
| 428 | pd2 = new DefaultPort(d1, PortNumber.portNumber(2), true); |
| 429 | pd3 = new DefaultPort(d2, PortNumber.portNumber(1), true); |
| 430 | pd4 = new DefaultPort(d2, PortNumber.portNumber(2), true); |
| 431 | |
| 432 | ports.putAll(DID1, Lists.newArrayList(pd1, pd2)); |
| 433 | ports.putAll(DID2, Lists.newArrayList(pd3, pd4)); |
| 434 | |
| 435 | |
| 436 | } |
| 437 | |
| 438 | @Override |
| 439 | public int getDeviceCount() { |
| 440 | return devices.values().size(); |
| 441 | } |
| 442 | |
| 443 | @Override |
| 444 | public Iterable<Device> getDevices() { |
Yuta HIGUCHI | f1f2ac0 | 2014-11-26 14:02:22 -0800 | [diff] [blame] | 445 | return Collections.emptyList(); |
alshabib | 0ed6a20 | 2014-10-19 12:42:57 -0700 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | @Override |
| 449 | public Device getDevice(DeviceId deviceId) { |
| 450 | return devices.get(deviceId); |
| 451 | } |
| 452 | |
| 453 | @Override |
| 454 | public MastershipRole getRole(DeviceId deviceId) { |
| 455 | return MastershipRole.MASTER; |
| 456 | } |
| 457 | |
| 458 | @Override |
| 459 | public List<Port> getPorts(DeviceId deviceId) { |
| 460 | return ports.get(deviceId); |
| 461 | } |
| 462 | |
| 463 | @Override |
| 464 | public Port getPort(DeviceId deviceId, PortNumber portNumber) { |
| 465 | for (Port p : ports.get(deviceId)) { |
| 466 | if (p.number().equals(portNumber)) { |
| 467 | return p; |
| 468 | } |
| 469 | } |
| 470 | return null; |
| 471 | } |
| 472 | |
| 473 | @Override |
| 474 | public boolean isAvailable(DeviceId deviceId) { |
| 475 | return true; |
| 476 | } |
| 477 | |
| 478 | @Override |
| 479 | public void addListener(DeviceListener listener) { |
| 480 | deviceListener = listener; |
| 481 | |
| 482 | } |
| 483 | |
| 484 | @Override |
| 485 | public void removeListener(DeviceListener listener) { |
| 486 | |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | private final class TestMasterShipService implements MastershipService { |
| 491 | |
| 492 | @Override |
| 493 | public MastershipRole getLocalRole(DeviceId deviceId) { |
| 494 | return MastershipRole.MASTER; |
| 495 | } |
| 496 | |
| 497 | @Override |
| 498 | public MastershipRole requestRoleFor(DeviceId deviceId) { |
| 499 | return null; |
| 500 | } |
| 501 | |
| 502 | @Override |
| 503 | public void relinquishMastership(DeviceId deviceId) { |
| 504 | |
| 505 | } |
| 506 | |
| 507 | @Override |
| 508 | public NodeId getMasterFor(DeviceId deviceId) { |
| 509 | return null; |
| 510 | } |
| 511 | |
| 512 | @Override |
| 513 | public Set<DeviceId> getDevicesOf(NodeId nodeId) { |
| 514 | return null; |
| 515 | } |
| 516 | |
| 517 | @Override |
alshabib | 0ed6a20 | 2014-10-19 12:42:57 -0700 | [diff] [blame] | 518 | public void addListener(MastershipListener listener) { |
| 519 | |
| 520 | } |
| 521 | |
| 522 | @Override |
| 523 | public void removeListener(MastershipListener listener) { |
| 524 | |
| 525 | } |
Yuta HIGUCHI | 376d750 | 2014-10-19 15:57:52 -0700 | [diff] [blame] | 526 | |
| 527 | @Override |
Ayaka Koshibe | abedb09 | 2014-10-20 17:01:31 -0700 | [diff] [blame] | 528 | public RoleInfo getNodesFor(DeviceId deviceId) { |
| 529 | return new RoleInfo(new NodeId("foo"), Collections.<NodeId>emptyList()); |
Yuta HIGUCHI | 376d750 | 2014-10-19 15:57:52 -0700 | [diff] [blame] | 530 | } |
alshabib | 0ed6a20 | 2014-10-19 12:42:57 -0700 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | |
| 534 | } |