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