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 | |
Yuta HIGUCHI | 53e4796 | 2018-03-01 23:50:48 -0800 | [diff] [blame] | 163 | PortDescription portDescription = DefaultPortDescription.builder().withPortNumber(PORT) |
| 164 | .isEnabled(true).annotations(ANON).build(); |
HIGUCHI Yuta | 15653fd | 2015-11-09 11:05:09 -0800 | [diff] [blame] | 165 | 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 Yuta | 7c1583c | 2015-12-03 23:08:54 -0800 | [diff] [blame] | 219 | @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 Yuta | 15653fd | 2015-11-09 11:05:09 -0800 | [diff] [blame] | 329 | /** |
| 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 Das | a2d3750 | 2016-03-25 17:50:40 -0700 | [diff] [blame] | 345 | final CountDownLatch portStateChanged = new CountDownLatch(1); |
| 346 | DeviceId portStateChangedDid; |
| 347 | PortNumber portStateChangedPort; |
| 348 | |
HIGUCHI Yuta | 15653fd | 2015-11-09 11:05:09 -0800 | [diff] [blame] | 349 | @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 Das | a2d3750 | 2016-03-25 17:50:40 -0700 | [diff] [blame] | 377 | @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 Yuta | 15653fd | 2015-11-09 11:05:09 -0800 | [diff] [blame] | 388 | } |
| 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 Yuta | 15653fd | 2015-11-09 11:05:09 -0800 | [diff] [blame] | 454 | 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 Yuta | 7c1583c | 2015-12-03 23:08:54 -0800 | [diff] [blame] | 521 | 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 Yuta | 15653fd | 2015-11-09 11:05:09 -0800 | [diff] [blame] | 578 | } |