blob: 8990b6e48eb8eec7c5ffc33e84c26141e483a6dc [file] [log] [blame]
HIGUCHI Yuta15653fd2015-11-09 11:05:09 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
HIGUCHI Yuta15653fd2015-11-09 11:05:09 -08003 *
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
7 *
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.
15 */
16package org.onosproject.incubator.rpc.grpc;
17
18import static org.junit.Assert.*;
19import static org.onosproject.net.DeviceId.deviceId;
HIGUCHI Yuta7c1583c2015-12-03 23:08:54 -080020import static org.onosproject.net.PortNumber.portNumber;
HIGUCHI Yuta15653fd2015-11-09 11:05:09 -080021
HIGUCHI Yuta15653fd2015-11-09 11:05:09 -080022import java.net.URI;
23import java.util.Collection;
24import java.util.Collections;
25import java.util.List;
26import java.util.Set;
27import java.util.concurrent.CountDownLatch;
28import java.util.concurrent.TimeUnit;
29
HIGUCHI Yuta15653fd2015-11-09 11:05:09 -080030import org.junit.After;
31import org.junit.Before;
32import org.junit.Test;
HIGUCHI Yuta97f7e472016-01-22 10:03:48 -080033import org.onlab.junit.TestTools;
HIGUCHI Yuta15653fd2015-11-09 11:05:09 -080034import org.onlab.packet.ChassisId;
35import org.onosproject.incubator.rpc.RemoteServiceContext;
36import org.onosproject.incubator.rpc.RemoteServiceContextProvider;
37import org.onosproject.incubator.rpc.RemoteServiceContextProviderService;
38import org.onosproject.incubator.rpc.RemoteServiceProviderRegistry;
HIGUCHI Yuta7c1583c2015-12-03 23:08:54 -080039import org.onosproject.net.ConnectPoint;
HIGUCHI Yuta15653fd2015-11-09 11:05:09 -080040import org.onosproject.net.DefaultAnnotations;
41import org.onosproject.net.Device.Type;
42import org.onosproject.net.DeviceId;
HIGUCHI Yuta7c1583c2015-12-03 23:08:54 -080043import org.onosproject.net.Link;
HIGUCHI Yuta15653fd2015-11-09 11:05:09 -080044import org.onosproject.net.MastershipRole;
45import org.onosproject.net.PortNumber;
46import org.onosproject.net.SparseAnnotations;
47import org.onosproject.net.device.DefaultDeviceDescription;
48import org.onosproject.net.device.DefaultPortDescription;
49import org.onosproject.net.device.DeviceDescription;
50import org.onosproject.net.device.DeviceProvider;
51import org.onosproject.net.device.DeviceProviderRegistry;
52import org.onosproject.net.device.DeviceProviderService;
53import org.onosproject.net.device.PortDescription;
54import org.onosproject.net.device.PortStatistics;
HIGUCHI Yuta7c1583c2015-12-03 23:08:54 -080055import org.onosproject.net.link.DefaultLinkDescription;
56import org.onosproject.net.link.LinkDescription;
57import org.onosproject.net.link.LinkProvider;
58import org.onosproject.net.link.LinkProviderRegistry;
59import org.onosproject.net.link.LinkProviderService;
HIGUCHI Yuta15653fd2015-11-09 11:05:09 -080060import org.onosproject.net.provider.AbstractProviderRegistry;
61import org.onosproject.net.provider.AbstractProviderService;
62import org.onosproject.net.provider.ProviderId;
63import org.slf4j.Logger;
64import org.slf4j.LoggerFactory;
65
66import com.google.common.collect.ImmutableList;
67
68/**
69 * Set of tests of the gRPC RemoteService components.
70 */
71public class GrpcRemoteServiceTest {
72
73 private static final DeviceId DEVICE_ID = deviceId("dev:000001");
74
75 private final Logger log = LoggerFactory.getLogger(getClass());
76
Ray Milkeyc108a6b2017-08-23 15:23:50 -070077 private static final ProviderId PID = new ProviderId("test", "com.example.test");
HIGUCHI Yuta15653fd2015-11-09 11:05:09 -080078
79 private static final URI DURI = URI.create("dev:000001");
80
81 private static final String MFR = "mfr";
82
83 private static final String HW = "hw";
84
85 private static final String SW = "sw";
86
87 private static final String SN = "serial";
88
89 private static final ChassisId CHASSIS = new ChassisId(42);
90
91 private static final SparseAnnotations ANON = DefaultAnnotations.builder()
92 .set("foo", "var")
93 .build();
94
95 private static final PortNumber PORT = PortNumber.portNumber(99);
96
97 private static final DeviceDescription DDESC
98 = new DefaultDeviceDescription(DURI, Type.SWITCH, MFR, HW, SW, SN,
99 CHASSIS, ANON);
100
101 private GrpcRemoteServiceServer server;
102 private GrpcRemoteServiceProvider client;
103
104 private DeviceProvider svSideDeviceProvider;
105
106 private MTestDeviceProviderService svDeviceProviderService;
107
HIGUCHI Yuta7c1583c2015-12-03 23:08:54 -0800108 private ServerSideLinkProviderService svLinkProviderService;
109
110
HIGUCHI Yuta15653fd2015-11-09 11:05:09 -0800111 private CountDownLatch serverReady;
112
113 private URI uri;
114
HIGUCHI Yuta15653fd2015-11-09 11:05:09 -0800115 @Before
116 public void setUp() throws Exception {
117 serverReady = new CountDownLatch(1);
118 server = new GrpcRemoteServiceServer();
119 server.deviceProviderRegistry = new MTestDeviceProviderRegistry();
HIGUCHI Yuta7c1583c2015-12-03 23:08:54 -0800120 server.linkProviderRegistry = new ServerSideLinkProviderRegistry();
HIGUCHI Yuta97f7e472016-01-22 10:03:48 -0800121 server.listenPort = TestTools.findAvailablePort(11984);
HIGUCHI Yuta15653fd2015-11-09 11:05:09 -0800122 uri = URI.create("grpc://localhost:" + server.listenPort);
HIGUCHI Yuta97f7e472016-01-22 10:03:48 -0800123 // todo: pass proper ComponentContext
HIGUCHI Yuta15653fd2015-11-09 11:05:09 -0800124 server.activate(null);
125
126 client = new GrpcRemoteServiceProvider();
127 client.rpcRegistry = new NoOpRemoteServiceProviderRegistry();
128 client.activate();
129 }
130
131 @After
132 public void tearDown() {
133 client.deactivate();
134 server.deactivate();
HIGUCHI Yuta7c1583c2015-12-03 23:08:54 -0800135 svLinkProviderService = null;
HIGUCHI Yuta15653fd2015-11-09 11:05:09 -0800136 }
137
138 private static void assertEqualsButNotSame(Object expected, Object actual) {
139 assertEquals(expected, actual);
140 assertNotSame("Cannot be same instance if it properly went through gRPC",
141 expected, actual);
142 }
143
144 @Test
HIGUCHI Yuta7c1583c2015-12-03 23:08:54 -0800145 public void deviceServiceBasics() throws InterruptedException {
HIGUCHI Yuta15653fd2015-11-09 11:05:09 -0800146 RemoteServiceContext remoteServiceContext = client.get(uri);
147 assertNotNull(remoteServiceContext);
148
149 DeviceProviderRegistry deviceProviderRegistry = remoteServiceContext.get(DeviceProviderRegistry.class);
150 assertNotNull(deviceProviderRegistry);
151
152 CTestDeviceProvider clDeviceProvider = new CTestDeviceProvider();
153 DeviceProviderService clDeviceProviderService = deviceProviderRegistry.register(clDeviceProvider);
154
155 assertTrue(serverReady.await(10, TimeUnit.SECONDS));
156
157 // client to server communication
158 clDeviceProviderService.deviceConnected(DEVICE_ID, DDESC);
159 assertTrue(svDeviceProviderService.deviceConnected.await(10, TimeUnit.SECONDS));
160 assertEqualsButNotSame(DEVICE_ID, svDeviceProviderService.deviceConnectedDid);
161 assertEqualsButNotSame(DDESC, svDeviceProviderService.deviceConnectedDesc);
162
Yuta HIGUCHI53e47962018-03-01 23:50:48 -0800163 PortDescription portDescription = DefaultPortDescription.builder().withPortNumber(PORT)
164 .isEnabled(true).annotations(ANON).build();
HIGUCHI Yuta15653fd2015-11-09 11:05:09 -0800165 List<PortDescription> portDescriptions = ImmutableList.of(portDescription);
166 clDeviceProviderService.updatePorts(DEVICE_ID, portDescriptions);
167 assertTrue(svDeviceProviderService.updatePorts.await(10, TimeUnit.SECONDS));
168 assertEqualsButNotSame(DEVICE_ID, svDeviceProviderService.updatePortsDid);
169 assertEqualsButNotSame(portDescriptions, svDeviceProviderService.updatePortsDescs);
170
171 MastershipRole cRole = MastershipRole.MASTER;
172 MastershipRole dRole = MastershipRole.STANDBY;
173 clDeviceProviderService.receivedRoleReply(DEVICE_ID, cRole, dRole);
174 assertTrue(svDeviceProviderService.receivedRoleReply.await(10, TimeUnit.SECONDS));
175 assertEqualsButNotSame(DEVICE_ID, svDeviceProviderService.receivedRoleReplyDid);
176 assertEquals(cRole, svDeviceProviderService.receivedRoleReplyRequested);
177 assertEquals(dRole, svDeviceProviderService.receivedRoleReplyResponse);
178
179 clDeviceProviderService.portStatusChanged(DEVICE_ID, portDescription);
180 assertTrue(svDeviceProviderService.portStatusChanged.await(10, TimeUnit.SECONDS));
181 assertEqualsButNotSame(DEVICE_ID, svDeviceProviderService.portStatusChangedDid);
182 assertEqualsButNotSame(portDescription, svDeviceProviderService.portStatusChangedDesc);
183
184 Collection<PortStatistics> portStatistics = Collections.emptyList();
185 clDeviceProviderService.updatePortStatistics(DEVICE_ID, portStatistics);
186 assertTrue(svDeviceProviderService.updatePortStatistics.await(10, TimeUnit.SECONDS));
187 assertEqualsButNotSame(DEVICE_ID, svDeviceProviderService.updatePortStatisticsDid);
188 assertEqualsButNotSame(portStatistics, svDeviceProviderService.updatePortStatisticsStats);
189
190 clDeviceProviderService.deviceDisconnected(DEVICE_ID);
191 assertTrue(svDeviceProviderService.deviceDisconnected.await(10, TimeUnit.SECONDS));
192 assertEqualsButNotSame(DEVICE_ID, svDeviceProviderService.deviceDisconnectedDid);
193
194
195
196 // server to client communication
197 svSideDeviceProvider.triggerProbe(DEVICE_ID);
198 assertTrue(clDeviceProvider.triggerProbe.await(10, TimeUnit.SECONDS));
199 assertEquals(DEVICE_ID, clDeviceProvider.triggerProbeDid);
200 assertNotSame("Cannot be same instance if it properly went through gRPC",
201 DEVICE_ID, clDeviceProvider.triggerProbeDid);
202
203 svSideDeviceProvider.roleChanged(DEVICE_ID, MastershipRole.STANDBY);
204 assertTrue(clDeviceProvider.roleChanged.await(10, TimeUnit.SECONDS));
205 assertEquals(DEVICE_ID, clDeviceProvider.roleChangedDid);
206 assertNotSame("Cannot be same instance if it properly went through gRPC",
207 DEVICE_ID, clDeviceProvider.roleChangedDid);
208 assertEquals(MastershipRole.STANDBY, clDeviceProvider.roleChangedNewRole);
209
210 clDeviceProvider.isReachableReply = false;
211 assertEquals(clDeviceProvider.isReachableReply,
212 svSideDeviceProvider.isReachable(DEVICE_ID));
213 assertTrue(clDeviceProvider.isReachable.await(10, TimeUnit.SECONDS));
214 assertEquals(DEVICE_ID, clDeviceProvider.isReachableDid);
215 assertNotSame("Cannot be same instance if it properly went through gRPC",
216 DEVICE_ID, clDeviceProvider.isReachableDid);
217 }
218
HIGUCHI Yuta7c1583c2015-12-03 23:08:54 -0800219 @Test
220 public void linkVanishedDevice() throws InterruptedException {
221 RemoteServiceContext remoteServiceContext = client.get(uri);
222 assertNotNull(remoteServiceContext);
223
224 LinkProviderRegistry providerRegistry = remoteServiceContext.get(LinkProviderRegistry.class);
225 assertNotNull(providerRegistry);
226
227 final String schemeTest = "test";
228 LinkProviderService client = providerRegistry.register(new StubLinkProvider(schemeTest));
229 assertNotNull(client);
230
231 client.linksVanished(DEVICE_ID);
232
233 assertEquals(schemeTest, svLinkProviderService.provider().id().scheme());
234 assertTrue(svLinkProviderService.calls.await(10, TimeUnit.SECONDS));
235 assertEqualsButNotSame(DEVICE_ID, svLinkProviderService.arg);
236 }
237
238 @Test
239 public void linkVanishedPort() throws InterruptedException {
240 RemoteServiceContext remoteServiceContext = client.get(uri);
241 assertNotNull(remoteServiceContext);
242
243 LinkProviderRegistry providerRegistry = remoteServiceContext.get(LinkProviderRegistry.class);
244 assertNotNull(providerRegistry);
245
246 final String schemeTest = "test";
247 LinkProviderService client = providerRegistry.register(new StubLinkProvider(schemeTest));
248 assertNotNull(client);
249
250
251 final ConnectPoint cp = new ConnectPoint(DEVICE_ID, PORT);
252 client.linksVanished(cp);
253 assertEquals(schemeTest, svLinkProviderService.provider().id().scheme());
254 assertTrue(svLinkProviderService.calls.await(10, TimeUnit.SECONDS));
255 assertEqualsButNotSame(cp, svLinkProviderService.arg);
256 }
257
258 @Test
259 public void linkVanishedDescription() throws InterruptedException {
260 RemoteServiceContext remoteServiceContext = client.get(uri);
261 assertNotNull(remoteServiceContext);
262
263 LinkProviderRegistry providerRegistry = remoteServiceContext.get(LinkProviderRegistry.class);
264 assertNotNull(providerRegistry);
265
266 final String schemeTest = "test";
267 LinkProviderService client = providerRegistry.register(new StubLinkProvider(schemeTest));
268 assertNotNull(client);
269
270 ConnectPoint src = new ConnectPoint(deviceId("dev:1"), portNumber(10));
271 ConnectPoint dst = new ConnectPoint(deviceId("dev:2"), portNumber(20));
272 LinkDescription linkDescription = new DefaultLinkDescription(src, dst, Link.Type.DIRECT, ANON);
273 client.linkVanished(linkDescription);
274 assertEquals(schemeTest, svLinkProviderService.provider().id().scheme());
275 assertTrue(svLinkProviderService.calls.await(10, TimeUnit.SECONDS));
276 assertEqualsButNotSame(linkDescription, svLinkProviderService.arg);
277 }
278
279 @Test
280 public void linkDetected() throws InterruptedException {
281 RemoteServiceContext remoteServiceContext = client.get(uri);
282 assertNotNull(remoteServiceContext);
283
284 LinkProviderRegistry providerRegistry = remoteServiceContext.get(LinkProviderRegistry.class);
285 assertNotNull(providerRegistry);
286
287 final String schemeTest = "test";
288 LinkProviderService client = providerRegistry.register(new StubLinkProvider(schemeTest));
289 assertNotNull(client);
290
291 ConnectPoint src = new ConnectPoint(deviceId("dev:1"), portNumber(10));
292 ConnectPoint dst = new ConnectPoint(deviceId("dev:2"), portNumber(20));
293 LinkDescription linkDescription = new DefaultLinkDescription(src, dst, Link.Type.DIRECT, ANON);
294 client.linkDetected(linkDescription);
295 assertEquals(schemeTest, svLinkProviderService.provider().id().scheme());
296 assertTrue(svLinkProviderService.calls.await(10, TimeUnit.SECONDS));
297 assertEqualsButNotSame(linkDescription, svLinkProviderService.arg);
298 }
299
300 @Test
301 public void linkServiceBasics() throws InterruptedException {
302 RemoteServiceContext remoteServiceContext = client.get(uri);
303 assertNotNull(remoteServiceContext);
304
305 LinkProviderRegistry providerRegistry = remoteServiceContext.get(LinkProviderRegistry.class);
306 assertNotNull(providerRegistry);
307
308 final String schemeTest = "test";
309 LinkProviderService client = providerRegistry.register(new StubLinkProvider(schemeTest));
310 assertNotNull(client);
311
312 ConnectPoint src = new ConnectPoint(deviceId("dev:1"), portNumber(10));
313 ConnectPoint dst = new ConnectPoint(deviceId("dev:2"), portNumber(20));
314 LinkDescription linkDescription = new DefaultLinkDescription(src, dst, Link.Type.DIRECT, ANON);
315
316 client.linkDetected(linkDescription);
317 assertEquals(schemeTest, svLinkProviderService.provider().id().scheme());
318 assertTrue(svLinkProviderService.calls.await(10, TimeUnit.SECONDS));
319 assertEqualsButNotSame(linkDescription, svLinkProviderService.arg);
320
321 svLinkProviderService.reset();
322
323 client.linkVanished(linkDescription);
324 assertEquals(schemeTest, svLinkProviderService.provider().id().scheme());
325 assertTrue(svLinkProviderService.calls.await(10, TimeUnit.SECONDS));
326 assertEqualsButNotSame(linkDescription, svLinkProviderService.arg);
327 }
328
HIGUCHI Yuta15653fd2015-11-09 11:05:09 -0800329 /**
330 * Device Provider on CO side.
331 */
332 public class CTestDeviceProvider implements DeviceProvider {
333
334 final CountDownLatch triggerProbe = new CountDownLatch(1);
335 DeviceId triggerProbeDid;
336
337 final CountDownLatch roleChanged = new CountDownLatch(1);
338 DeviceId roleChangedDid;
339 MastershipRole roleChangedNewRole;
340
341 final CountDownLatch isReachable = new CountDownLatch(1);
342 DeviceId isReachableDid;
343 boolean isReachableReply = false;
344
Saurav Dasa2d37502016-03-25 17:50:40 -0700345 final CountDownLatch portStateChanged = new CountDownLatch(1);
346 DeviceId portStateChangedDid;
347 PortNumber portStateChangedPort;
348
HIGUCHI Yuta15653fd2015-11-09 11:05:09 -0800349 @Override
350 public ProviderId id() {
351 return PID;
352 }
353
354 @Override
355 public void triggerProbe(DeviceId deviceId) {
356 log.info("triggerProbe({}) on Client called", deviceId);
357 triggerProbeDid = deviceId;
358 triggerProbe.countDown();
359 }
360
361 @Override
362 public void roleChanged(DeviceId deviceId, MastershipRole newRole) {
363 log.info("roleChanged({},{}) on Client called", deviceId, newRole);
364 roleChangedDid = deviceId;
365 roleChangedNewRole = newRole;
366 roleChanged.countDown();
367 }
368
369 @Override
370 public boolean isReachable(DeviceId deviceId) {
371 log.info("isReachable({}) on Client called", deviceId);
372 isReachableDid = deviceId;
373 isReachable.countDown();
374 return isReachableReply;
375 }
376
Saurav Dasa2d37502016-03-25 17:50:40 -0700377 @Override
378 public void changePortState(DeviceId deviceId, PortNumber portNumber,
379 boolean enable) {
380 log.info("portState change to {} on ({},{}) on Client called", enable,
381 deviceId, portNumber);
382 portStateChangedDid = deviceId;
383 portStateChangedPort = portNumber;
384 portStateChanged.countDown();
385
386 }
387
HIGUCHI Yuta15653fd2015-11-09 11:05:09 -0800388 }
389
390 class NoOpRemoteServiceProviderRegistry
391 implements RemoteServiceProviderRegistry {
392
393 @Override
394 public RemoteServiceContextProviderService register(RemoteServiceContextProvider provider) {
395 return new RemoteServiceContextProviderService() {
396
397 @Override
398 public RemoteServiceContextProvider provider() {
399 return provider;
400 }
401 };
402 }
403
404 @Override
405 public void unregister(RemoteServiceContextProvider provider) {
406 }
407
408 @Override
409 public Set<ProviderId> getProviders() {
410 return Collections.emptySet();
411 }
412 }
413
414 /**
415 * DeviceProvider on Metro side.
416 */
417 public class MTestDeviceProviderRegistry
418 extends AbstractProviderRegistry<DeviceProvider, DeviceProviderService>
419 implements DeviceProviderRegistry {
420
421 @Override
422 protected DeviceProviderService createProviderService(DeviceProvider provider) {
423 log.info("createProviderService({})", provider);
424 svSideDeviceProvider = provider;
425 svDeviceProviderService = new MTestDeviceProviderService(provider);
426 serverReady.countDown();
427 return svDeviceProviderService;
428 }
429
430 }
431
432 private final class MTestDeviceProviderService
433 extends AbstractProviderService<DeviceProvider>
434 implements DeviceProviderService {
435
436 public MTestDeviceProviderService(DeviceProvider provider) {
437 super(provider);
438 }
439
440
441 final CountDownLatch deviceConnected = new CountDownLatch(1);
442 DeviceId deviceConnectedDid;
443 DeviceDescription deviceConnectedDesc;
444
445 @Override
446 public void deviceConnected(DeviceId deviceId,
447 DeviceDescription deviceDescription) {
448 log.info("deviceConnected({}, {}) on Server called", deviceId, deviceDescription);
449 deviceConnectedDid = deviceId;
450 deviceConnectedDesc = deviceDescription;
451 deviceConnected.countDown();
452 }
453
HIGUCHI Yuta15653fd2015-11-09 11:05:09 -0800454 final CountDownLatch updatePorts = new CountDownLatch(1);
455 DeviceId updatePortsDid;
456 List<PortDescription> updatePortsDescs;
457
458 @Override
459 public void updatePorts(DeviceId deviceId,
460 List<PortDescription> portDescriptions) {
461 log.info("updatePorts({}, {}) on Server called", deviceId, portDescriptions);
462 updatePortsDid = deviceId;
463 updatePortsDescs = portDescriptions;
464 updatePorts.countDown();
465 }
466
467 final CountDownLatch receivedRoleReply = new CountDownLatch(1);
468 DeviceId receivedRoleReplyDid;
469 MastershipRole receivedRoleReplyRequested;
470 MastershipRole receivedRoleReplyResponse;
471
472 @Override
473 public void receivedRoleReply(DeviceId deviceId, MastershipRole requested,
474 MastershipRole response) {
475 log.info("receivedRoleReply({}, {}, {}) on Server called", deviceId, requested, response);
476 receivedRoleReplyDid = deviceId;
477 receivedRoleReplyRequested = requested;
478 receivedRoleReplyResponse = response;
479 receivedRoleReply.countDown();
480 }
481
482 final CountDownLatch portStatusChanged = new CountDownLatch(1);
483 DeviceId portStatusChangedDid;
484 PortDescription portStatusChangedDesc;
485
486
487 @Override
488 public void portStatusChanged(DeviceId deviceId,
489 PortDescription portDescription) {
490 log.info("portStatusChanged({}, {}) on Server called", deviceId, portDescription);
491 portStatusChangedDid = deviceId;
492 portStatusChangedDesc = portDescription;
493 portStatusChanged.countDown();
494 }
495
496 final CountDownLatch updatePortStatistics = new CountDownLatch(1);
497 DeviceId updatePortStatisticsDid;
498 Collection<PortStatistics> updatePortStatisticsStats;
499
500
501 @Override
502 public void updatePortStatistics(DeviceId deviceId,
503 Collection<PortStatistics> portStatistics) {
504 log.info("updatePortStatistics({}, {}) on Server called", deviceId, portStatistics);
505 updatePortStatisticsDid = deviceId;
506 updatePortStatisticsStats = portStatistics;
507 updatePortStatistics.countDown();
508 }
509
510 final CountDownLatch deviceDisconnected = new CountDownLatch(1);
511 DeviceId deviceDisconnectedDid;
512
513 @Override
514 public void deviceDisconnected(DeviceId deviceId) {
515 log.info("deviceDisconnected({}) on Server called", deviceId);
516 deviceDisconnectedDid = deviceId;
517 deviceDisconnected.countDown();
518 }
519 }
520
HIGUCHI Yuta7c1583c2015-12-03 23:08:54 -0800521 public class ServerSideLinkProviderRegistry
522 extends AbstractProviderRegistry<LinkProvider, LinkProviderService>
523 implements LinkProviderRegistry {
524
525 @Override
526 protected LinkProviderService createProviderService(LinkProvider provider) {
527 svLinkProviderService = new ServerSideLinkProviderService(provider);
528 return svLinkProviderService;
529 }
530
531 }
532
533 public class ServerSideLinkProviderService
534 extends AbstractProviderService<LinkProvider>
535 implements LinkProviderService {
536
537 CountDownLatch calls = new CountDownLatch(1);
538 Object arg = null;
539
540 public void reset() {
541 calls = new CountDownLatch(1);
542 arg = null;
543 }
544
545 public ServerSideLinkProviderService(LinkProvider provider) {
546 super(provider);
547 }
548
549 @Override
550 public void linksVanished(DeviceId deviceId) {
551 log.info("linksVanished({})", deviceId);
552 arg = deviceId;
553 calls.countDown();
554 }
555
556 @Override
557 public void linksVanished(ConnectPoint connectPoint) {
558 log.info("linksVanished({})", connectPoint);
559 arg = connectPoint;
560 calls.countDown();
561 }
562
563 @Override
564 public void linkVanished(LinkDescription linkDescription) {
565 log.info("linksVanished({})", linkDescription);
566 arg = linkDescription;
567 calls.countDown();
568 }
569
570 @Override
571 public void linkDetected(LinkDescription linkDescription) {
572 log.info("linkDetected({})", linkDescription);
573 arg = linkDescription;
574 calls.countDown();
575 }
576 }
577
HIGUCHI Yuta15653fd2015-11-09 11:05:09 -0800578}