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