Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [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.openstacknode.impl; |
| 17 | |
Ray Milkey | 0d47a55 | 2017-08-22 10:16:31 -0700 | [diff] [blame] | 18 | import java.util.Collection; |
| 19 | import java.util.List; |
| 20 | import java.util.Map; |
| 21 | import java.util.Objects; |
| 22 | import java.util.Set; |
| 23 | import java.util.stream.Collectors; |
| 24 | |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 25 | import org.junit.After; |
| 26 | import org.junit.Before; |
| 27 | import org.junit.Test; |
| 28 | import org.onlab.junit.TestUtils; |
| 29 | import org.onlab.packet.ChassisId; |
| 30 | import org.onlab.packet.Ip4Address; |
| 31 | import org.onlab.packet.IpAddress; |
| 32 | import org.onlab.packet.MacAddress; |
| 33 | import org.onlab.packet.VlanId; |
| 34 | import org.onosproject.cfg.ComponentConfigAdapter; |
| 35 | import org.onosproject.cluster.ClusterServiceAdapter; |
| 36 | import org.onosproject.cluster.ControllerNode; |
| 37 | import org.onosproject.cluster.DefaultControllerNode; |
| 38 | import org.onosproject.cluster.LeadershipServiceAdapter; |
| 39 | import org.onosproject.cluster.NodeId; |
| 40 | import org.onosproject.core.ApplicationId; |
| 41 | import org.onosproject.core.CoreServiceAdapter; |
| 42 | import org.onosproject.core.DefaultApplicationId; |
| 43 | import org.onosproject.core.GroupId; |
| 44 | import org.onosproject.net.Annotations; |
| 45 | import org.onosproject.net.DefaultAnnotations; |
| 46 | import org.onosproject.net.DefaultDevice; |
| 47 | import org.onosproject.net.DefaultPort; |
| 48 | import org.onosproject.net.Device; |
| 49 | import org.onosproject.net.DeviceId; |
| 50 | import org.onosproject.net.Port; |
| 51 | import org.onosproject.net.PortNumber; |
| 52 | import org.onosproject.net.behaviour.BridgeConfig; |
| 53 | import org.onosproject.net.behaviour.BridgeDescription; |
| 54 | import org.onosproject.net.behaviour.BridgeName; |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 55 | import org.onosproject.net.behaviour.DefaultBridgeDescription; |
| 56 | import org.onosproject.net.behaviour.ExtensionTreatmentResolver; |
| 57 | import org.onosproject.net.behaviour.InterfaceConfig; |
| 58 | import org.onosproject.net.behaviour.PatchDescription; |
| 59 | import org.onosproject.net.behaviour.TunnelDescription; |
| 60 | import org.onosproject.net.device.DefaultPortDescription; |
| 61 | import org.onosproject.net.device.DeviceAdminService; |
| 62 | import org.onosproject.net.device.DeviceEvent; |
| 63 | import org.onosproject.net.device.DeviceInterfaceDescription; |
| 64 | import org.onosproject.net.device.DeviceListener; |
| 65 | import org.onosproject.net.device.DeviceServiceAdapter; |
| 66 | import org.onosproject.net.device.PortDescription; |
| 67 | import org.onosproject.net.driver.Behaviour; |
| 68 | import org.onosproject.net.driver.DriverData; |
| 69 | import org.onosproject.net.driver.DriverHandler; |
| 70 | import org.onosproject.net.flow.instructions.ExtensionPropertyException; |
| 71 | import org.onosproject.net.flow.instructions.ExtensionTreatment; |
| 72 | import org.onosproject.net.flow.instructions.ExtensionTreatmentType; |
| 73 | import org.onosproject.net.group.DefaultGroup; |
| 74 | import org.onosproject.net.group.Group; |
| 75 | import org.onosproject.net.group.GroupBuckets; |
| 76 | import org.onosproject.net.group.GroupDescription; |
| 77 | import org.onosproject.net.group.GroupEvent; |
| 78 | import org.onosproject.net.group.GroupKey; |
| 79 | import org.onosproject.net.group.GroupListener; |
| 80 | import org.onosproject.net.group.GroupService; |
| 81 | import org.onosproject.net.provider.ProviderId; |
| 82 | import org.onosproject.openstacknode.api.NodeState; |
| 83 | import org.onosproject.openstacknode.api.OpenstackNode; |
| 84 | import org.onosproject.openstacknode.api.OpenstackNodeAdminService; |
| 85 | import org.onosproject.openstacknode.api.OpenstackNodeListener; |
| 86 | import org.onosproject.openstacknode.api.OpenstackNodeService; |
| 87 | import org.onosproject.ovsdb.controller.OvsdbClientService; |
| 88 | import org.onosproject.ovsdb.controller.OvsdbController; |
| 89 | |
Ray Milkey | 0d47a55 | 2017-08-22 10:16:31 -0700 | [diff] [blame] | 90 | import com.google.common.collect.ImmutableSet; |
| 91 | import com.google.common.collect.Lists; |
| 92 | import com.google.common.collect.Maps; |
| 93 | import com.google.common.util.concurrent.MoreExecutors; |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 94 | |
Ray Milkey | 0d47a55 | 2017-08-22 10:16:31 -0700 | [diff] [blame] | 95 | import static org.easymock.EasyMock.anyObject; |
| 96 | import static org.easymock.EasyMock.createMock; |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 97 | import static org.easymock.EasyMock.expect; |
Ray Milkey | 0d47a55 | 2017-08-22 10:16:31 -0700 | [diff] [blame] | 98 | import static org.easymock.EasyMock.replay; |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 99 | import static org.junit.Assert.assertEquals; |
| 100 | import static org.onosproject.net.AnnotationKeys.PORT_NAME; |
| 101 | import static org.onosproject.net.Device.Type.CONTROLLER; |
| 102 | import static org.onosproject.net.Device.Type.SWITCH; |
Ray Milkey | 0d47a55 | 2017-08-22 10:16:31 -0700 | [diff] [blame] | 103 | import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_ADDED; |
| 104 | import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED; |
| 105 | import static org.onosproject.net.device.DeviceEvent.Type.PORT_ADDED; |
| 106 | import static org.onosproject.net.device.DeviceEvent.Type.PORT_REMOVED; |
| 107 | import static org.onosproject.openstacknode.api.Constants.DEFAULT_TUNNEL; |
| 108 | import static org.onosproject.openstacknode.api.Constants.INTEGRATION_BRIDGE; |
| 109 | import static org.onosproject.openstacknode.api.Constants.PATCH_INTG_BRIDGE; |
| 110 | import static org.onosproject.openstacknode.api.Constants.PATCH_ROUT_BRIDGE; |
| 111 | import static org.onosproject.openstacknode.api.Constants.ROUTER_BRIDGE; |
| 112 | import static org.onosproject.openstacknode.api.NodeState.COMPLETE; |
| 113 | import static org.onosproject.openstacknode.api.NodeState.DEVICE_CREATED; |
| 114 | import static org.onosproject.openstacknode.api.NodeState.INCOMPLETE; |
| 115 | import static org.onosproject.openstacknode.api.NodeState.INIT; |
| 116 | import static org.onosproject.openstacknode.api.NodeState.PORT_CREATED; |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 117 | import static org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE; |
| 118 | import static org.onosproject.openstacknode.api.OpenstackNode.NodeType.GATEWAY; |
| 119 | |
| 120 | /** |
| 121 | * Unit test for DefaultOpenstackNodeHandler. |
| 122 | */ |
| 123 | public class DefaultOpenstackNodeHandlerTest { |
| 124 | |
| 125 | private static final ApplicationId TEST_APP_ID = new DefaultApplicationId(1, "test"); |
| 126 | private static final String ERR_STATE_NOT_MATCH = "Node state did not match"; |
| 127 | private static final NodeId LOCAL_NODE_ID = new NodeId("local"); |
| 128 | private static final ControllerNode LOCAL_CTRL = |
| 129 | new DefaultControllerNode(LOCAL_NODE_ID, IpAddress.valueOf("127.0.0.1")); |
| 130 | |
| 131 | private static final BridgeDescription ROUT_BRIDGE = DefaultBridgeDescription.builder() |
| 132 | .name(ROUTER_BRIDGE) |
| 133 | .failMode(BridgeDescription.FailMode.SECURE) |
| 134 | .disableInBand() |
| 135 | .build(); |
| 136 | |
| 137 | private static final PortDescription PATCH_ROUT = new DefaultPortDescription( |
| 138 | PortNumber.portNumber(1), |
| 139 | true, |
| 140 | DefaultAnnotations.builder() |
| 141 | .set(PORT_NAME, PATCH_ROUT_BRIDGE) |
| 142 | .build() |
| 143 | ); |
| 144 | |
| 145 | private static final String COMPUTE_1_HOSTNAME = "compute_1"; |
| 146 | private static final String COMPUTE_2_HOSTNAME = "compute_2"; |
| 147 | private static final String COMPUTE_3_HOSTNAME = "compute_3"; |
| 148 | private static final String COMPUTE_4_HOSTNAME = "compute_4"; |
| 149 | private static final String GATEWAY_1_HOSTNAME = "gateway_1"; |
| 150 | private static final String GATEWAY_2_HOSTNAME = "gateway_2"; |
| 151 | private static final String GATEWAY_3_HOSTNAME = "gateway_3"; |
| 152 | private static final String GATEWAY_4_HOSTNAME = "gateway_4"; |
| 153 | |
| 154 | private static final IpAddress COMPUTE_1_IP = IpAddress.valueOf("10.100.0.1"); |
| 155 | private static final IpAddress COMPUTE_2_IP = IpAddress.valueOf("10.100.0.2"); |
| 156 | private static final IpAddress COMPUTE_3_IP = IpAddress.valueOf("10.100.0.3"); |
| 157 | private static final IpAddress COMPUTE_4_IP = IpAddress.valueOf("10.100.0.4"); |
| 158 | private static final IpAddress GATEWAY_1_IP = IpAddress.valueOf("10.100.0.5"); |
| 159 | private static final IpAddress GATEWAY_2_IP = IpAddress.valueOf("10.100.0.6"); |
| 160 | private static final IpAddress GATEWAY_3_IP = IpAddress.valueOf("10.100.0.7"); |
| 161 | private static final IpAddress GATEWAY_4_IP = IpAddress.valueOf("10.100.0.8"); |
| 162 | |
| 163 | private static final Device COMPUTE_1_INTG_DEVICE = createOpenFlowDevice(1, INTEGRATION_BRIDGE); |
| 164 | private static final Device COMPUTE_2_INTG_DEVICE = createOpenFlowDevice(2, INTEGRATION_BRIDGE); |
| 165 | private static final Device COMPUTE_3_INTG_DEVICE = createOpenFlowDevice(3, INTEGRATION_BRIDGE); |
| 166 | private static final Device COMPUTE_4_INTG_DEVICE = createOpenFlowDevice(4, INTEGRATION_BRIDGE); |
| 167 | private static final Device GATEWAY_1_INTG_DEVICE = createOpenFlowDevice(5, INTEGRATION_BRIDGE); |
| 168 | private static final Device GATEWAY_1_ROUT_DEVICE = createOpenFlowDevice(6, ROUTER_BRIDGE); |
| 169 | private static final Device GATEWAY_2_INTG_DEVICE = createOpenFlowDevice(7, INTEGRATION_BRIDGE); |
| 170 | private static final Device GATEWAY_2_ROUT_DEVICE = createOpenFlowDevice(8, ROUTER_BRIDGE); |
| 171 | private static final Device GATEWAY_3_INTG_DEVICE = createOpenFlowDevice(9, INTEGRATION_BRIDGE); |
| 172 | private static final Device GATEWAY_3_ROUT_DEVICE = createOpenFlowDevice(10, ROUTER_BRIDGE); |
| 173 | private static final Device GATEWAY_4_INTG_DEVICE = createOpenFlowDevice(11, INTEGRATION_BRIDGE); |
| 174 | private static final Device GATEWAY_4_ROUT_DEVICE = createOpenFlowDevice(12, ROUTER_BRIDGE); |
| 175 | |
| 176 | private static final Device COMPUTE_1_OVSDB_DEVICE = createOvsdbDevice(COMPUTE_1_IP); |
| 177 | private static final Device COMPUTE_2_OVSDB_DEVICE = createOvsdbDevice(COMPUTE_2_IP); |
| 178 | private static final Device COMPUTE_3_OVSDB_DEVICE = createOvsdbDevice(COMPUTE_3_IP); |
| 179 | private static final Device COMPUTE_4_OVSDB_DEVICE = createOvsdbDevice(COMPUTE_4_IP); |
| 180 | private static final Device GATEWAY_1_OVSDB_DEVICE = createOvsdbDevice(GATEWAY_1_IP); |
| 181 | private static final Device GATEWAY_2_OVSDB_DEVICE = createOvsdbDevice(GATEWAY_2_IP); |
| 182 | |
| 183 | private static final OpenstackNode COMPUTE_1 = createNode( |
| 184 | COMPUTE_1_HOSTNAME, |
| 185 | COMPUTE, |
| 186 | COMPUTE_1_INTG_DEVICE, |
| 187 | COMPUTE_1_IP, |
| 188 | INIT |
| 189 | ); |
| 190 | |
| 191 | private static final OpenstackNode COMPUTE_2 = createNode( |
| 192 | COMPUTE_2_HOSTNAME, |
| 193 | COMPUTE, |
| 194 | COMPUTE_2_INTG_DEVICE, |
| 195 | COMPUTE_2_IP, |
| 196 | DEVICE_CREATED |
| 197 | ); |
| 198 | |
| 199 | private static final OpenstackNode COMPUTE_3 = createNode( |
| 200 | COMPUTE_3_HOSTNAME, |
| 201 | COMPUTE, |
| 202 | COMPUTE_3_INTG_DEVICE, |
| 203 | COMPUTE_3_IP, |
| 204 | PORT_CREATED |
| 205 | ); |
| 206 | |
| 207 | private static final OpenstackNode COMPUTE_4 = createNode( |
| 208 | COMPUTE_4_HOSTNAME, |
| 209 | COMPUTE, |
| 210 | COMPUTE_4_INTG_DEVICE, |
| 211 | COMPUTE_4_IP, |
| 212 | COMPLETE |
| 213 | ); |
| 214 | |
| 215 | private static final OpenstackNode GATEWAY_1 = createNode( |
| 216 | GATEWAY_1_HOSTNAME, |
| 217 | GATEWAY, |
| 218 | GATEWAY_1_INTG_DEVICE, |
| 219 | GATEWAY_1_ROUT_DEVICE, |
| 220 | GATEWAY_1_IP, |
| 221 | INIT |
| 222 | ); |
| 223 | |
| 224 | private static final OpenstackNode GATEWAY_2 = createNode( |
| 225 | GATEWAY_2_HOSTNAME, |
| 226 | GATEWAY, |
| 227 | GATEWAY_2_INTG_DEVICE, |
| 228 | GATEWAY_2_ROUT_DEVICE, |
| 229 | GATEWAY_2_IP, |
| 230 | DEVICE_CREATED |
| 231 | ); |
| 232 | |
| 233 | private static final OpenstackNode GATEWAY_3 = createNode( |
| 234 | GATEWAY_3_HOSTNAME, |
| 235 | GATEWAY, |
| 236 | GATEWAY_3_INTG_DEVICE, |
| 237 | GATEWAY_3_ROUT_DEVICE, |
| 238 | GATEWAY_3_IP, |
| 239 | PORT_CREATED |
| 240 | ); |
| 241 | |
| 242 | private static final OpenstackNode GATEWAY_4 = createNode( |
| 243 | GATEWAY_4_HOSTNAME, |
| 244 | GATEWAY, |
| 245 | GATEWAY_4_INTG_DEVICE, |
| 246 | GATEWAY_4_ROUT_DEVICE, |
| 247 | GATEWAY_4_IP, |
| 248 | COMPLETE |
| 249 | ); |
| 250 | |
| 251 | private static final TestDeviceService TEST_DEVICE_SERVICE = new TestDeviceService(); |
| 252 | |
| 253 | private TestOpenstackNodeManager testNodeManager; |
| 254 | private DefaultOpenstackNodeHandler target; |
| 255 | |
| 256 | @Before |
| 257 | public void setUp() throws Exception { |
| 258 | DeviceAdminService mockDeviceAdminService = createMock(DeviceAdminService.class); |
| 259 | mockDeviceAdminService.removeDevice(anyObject()); |
| 260 | replay(mockDeviceAdminService); |
| 261 | |
| 262 | OvsdbClientService mockOvsdbClient = createMock(OvsdbClientService.class); |
| 263 | expect(mockOvsdbClient.isConnected()) |
| 264 | .andReturn(true) |
| 265 | .anyTimes(); |
| 266 | replay(mockOvsdbClient); |
| 267 | |
| 268 | OvsdbController mockOvsdbController = createMock(OvsdbController.class); |
| 269 | expect(mockOvsdbController.getOvsdbClient(anyObject())) |
| 270 | .andReturn(mockOvsdbClient) |
| 271 | .anyTimes(); |
| 272 | replay(mockOvsdbController); |
| 273 | |
| 274 | testNodeManager = new TestOpenstackNodeManager(); |
| 275 | target = new DefaultOpenstackNodeHandler(); |
| 276 | |
| 277 | target.coreService = new TestCoreService(); |
| 278 | target.leadershipService = new TestLeadershipService(); |
| 279 | target.clusterService = new TestClusterService(); |
| 280 | target.deviceService = TEST_DEVICE_SERVICE; |
| 281 | target.deviceAdminService = mockDeviceAdminService; |
| 282 | target.ovsdbController = mockOvsdbController; |
| 283 | target.groupService = new TestGroupService(); |
| 284 | target.osNodeService = testNodeManager; |
| 285 | target.osNodeAdminService = testNodeManager; |
| 286 | target.componentConfigService = new TestComponentConfigService(); |
| 287 | TestUtils.setField(target, "eventExecutor", MoreExecutors.newDirectExecutorService()); |
| 288 | target.activate(); |
| 289 | } |
| 290 | |
| 291 | @After |
| 292 | public void tearDown() { |
| 293 | TEST_DEVICE_SERVICE.clear(); |
| 294 | target.deactivate(); |
| 295 | target = null; |
| 296 | testNodeManager = null; |
| 297 | } |
| 298 | |
| 299 | /** |
| 300 | * Checks if the compute node state changes from INIT to DEVICE_CREATED |
| 301 | * after processing INIT state. |
| 302 | */ |
| 303 | @Test |
| 304 | public void testComputeNodeProcessNodeInitState() { |
| 305 | testNodeManager.createNode(COMPUTE_1); |
| 306 | TEST_DEVICE_SERVICE.devMap.put(COMPUTE_1_OVSDB_DEVICE.id(), COMPUTE_1_OVSDB_DEVICE); |
| 307 | |
| 308 | assertEquals(ERR_STATE_NOT_MATCH, INIT, |
| 309 | testNodeManager.node(COMPUTE_1_HOSTNAME).state()); |
| 310 | target.processInitState(COMPUTE_1); |
| 311 | assertEquals(ERR_STATE_NOT_MATCH, DEVICE_CREATED, |
| 312 | testNodeManager.node(COMPUTE_1_HOSTNAME).state()); |
| 313 | } |
| 314 | |
| 315 | /** |
| 316 | * Checks if the gateway node state changes from INIT to DEVICE_CREATED |
| 317 | * after processing INIT state. |
| 318 | */ |
| 319 | @Test |
| 320 | public void testGatewayNodeProcessNodeInitState() { |
| 321 | testNodeManager.createNode(GATEWAY_1); |
| 322 | TEST_DEVICE_SERVICE.devMap.put(GATEWAY_1_OVSDB_DEVICE.id(), GATEWAY_1_OVSDB_DEVICE); |
| 323 | |
| 324 | assertEquals(ERR_STATE_NOT_MATCH, INIT, |
| 325 | testNodeManager.node(GATEWAY_1_HOSTNAME).state()); |
| 326 | target.processInitState(GATEWAY_1); |
| 327 | assertEquals(ERR_STATE_NOT_MATCH, DEVICE_CREATED, |
| 328 | testNodeManager.node(GATEWAY_1_HOSTNAME).state()); |
| 329 | } |
| 330 | |
| 331 | /** |
| 332 | * Checks if the compute node state changes from DEVICE_CREATED to |
| 333 | * PORT_CREATED after processing DEVICE_CREATED state. |
| 334 | */ |
| 335 | @Test |
| 336 | public void testComputeNodeProcessDeviceCreatedState() { |
| 337 | testNodeManager.createNode(COMPUTE_2); |
| 338 | TEST_DEVICE_SERVICE.devMap.put(COMPUTE_2_OVSDB_DEVICE.id(), COMPUTE_2_OVSDB_DEVICE); |
| 339 | TEST_DEVICE_SERVICE.devMap.put(COMPUTE_2_INTG_DEVICE.id(), COMPUTE_2_INTG_DEVICE); |
| 340 | |
| 341 | assertEquals(ERR_STATE_NOT_MATCH, DEVICE_CREATED, |
| 342 | testNodeManager.node(COMPUTE_2_HOSTNAME).state()); |
| 343 | target.processDeviceCreatedState(COMPUTE_2); |
| 344 | assertEquals(ERR_STATE_NOT_MATCH, PORT_CREATED, |
| 345 | testNodeManager.node(COMPUTE_2_HOSTNAME).state()); |
| 346 | } |
| 347 | |
| 348 | /** |
| 349 | * Checks if the gateway node state changes from DEVICE_CREATED to |
| 350 | * PORT_CREATED after processing DEVICE_CREATED state. |
| 351 | */ |
| 352 | @Test |
| 353 | public void testGatewayNodeProcessDeviceCreatedState() { |
| 354 | testNodeManager.createNode(GATEWAY_2); |
| 355 | TEST_DEVICE_SERVICE.devMap.put(GATEWAY_2_OVSDB_DEVICE.id(), GATEWAY_2_OVSDB_DEVICE); |
| 356 | TEST_DEVICE_SERVICE.devMap.put(GATEWAY_2_INTG_DEVICE.id(), GATEWAY_2_INTG_DEVICE); |
| 357 | |
| 358 | assertEquals(ERR_STATE_NOT_MATCH, DEVICE_CREATED, |
| 359 | testNodeManager.node(GATEWAY_2_HOSTNAME).state()); |
| 360 | target.processDeviceCreatedState(GATEWAY_2); |
| 361 | assertEquals(ERR_STATE_NOT_MATCH, PORT_CREATED, |
| 362 | testNodeManager.node(GATEWAY_2_HOSTNAME).state()); |
| 363 | } |
| 364 | |
| 365 | /** |
| 366 | * Checks if the compute node state changes from PORT_CREATED to |
| 367 | * COMPLETE after processing PORT_CREATED state. |
| 368 | */ |
| 369 | @Test |
| 370 | public void testComputeNodeProcessPortCreatedState() { |
| 371 | testNodeManager.createNode(COMPUTE_3); |
| 372 | TEST_DEVICE_SERVICE.devMap.put(COMPUTE_3_OVSDB_DEVICE.id(), COMPUTE_3_OVSDB_DEVICE); |
| 373 | TEST_DEVICE_SERVICE.devMap.put(COMPUTE_3_INTG_DEVICE.id(), COMPUTE_3_INTG_DEVICE); |
| 374 | TEST_DEVICE_SERVICE.portList.add(createPort(COMPUTE_3_INTG_DEVICE, DEFAULT_TUNNEL)); |
| 375 | |
| 376 | testNodeManager.createNode(GATEWAY_4); |
| 377 | TEST_DEVICE_SERVICE.devMap.put(GATEWAY_4_INTG_DEVICE.id(), GATEWAY_4_INTG_DEVICE); |
| 378 | |
| 379 | assertEquals(ERR_STATE_NOT_MATCH, PORT_CREATED, |
| 380 | testNodeManager.node(COMPUTE_3_HOSTNAME).state()); |
| 381 | target.processPortCreatedState(COMPUTE_3); |
| 382 | assertEquals(ERR_STATE_NOT_MATCH, COMPLETE, |
| 383 | testNodeManager.node(COMPUTE_3_HOSTNAME).state()); |
| 384 | } |
| 385 | |
| 386 | /** |
| 387 | * Checks if the gateway node state changes from PORT_CREATED to |
| 388 | * COMPLETE after processing PORT_CREATED state. |
| 389 | */ |
| 390 | @Test |
| 391 | public void testGatewayNodeProcessPortCreatedState() { |
| 392 | testNodeManager.createNode(COMPUTE_4); |
| 393 | TEST_DEVICE_SERVICE.devMap.put(COMPUTE_4_OVSDB_DEVICE.id(), COMPUTE_4_OVSDB_DEVICE); |
| 394 | TEST_DEVICE_SERVICE.devMap.put(COMPUTE_4_INTG_DEVICE.id(), COMPUTE_4_INTG_DEVICE); |
| 395 | TEST_DEVICE_SERVICE.portList.add(createPort(COMPUTE_4_INTG_DEVICE, DEFAULT_TUNNEL)); |
| 396 | |
| 397 | testNodeManager.createNode(GATEWAY_3); |
| 398 | TEST_DEVICE_SERVICE.devMap.put(GATEWAY_3_INTG_DEVICE.id(), GATEWAY_4_INTG_DEVICE); |
| 399 | |
| 400 | assertEquals(ERR_STATE_NOT_MATCH, PORT_CREATED, |
| 401 | testNodeManager.node(GATEWAY_3_HOSTNAME).state()); |
| 402 | target.processPortCreatedState(GATEWAY_3); |
| 403 | assertEquals(ERR_STATE_NOT_MATCH, COMPLETE, |
| 404 | testNodeManager.node(GATEWAY_3_HOSTNAME).state()); |
| 405 | } |
| 406 | |
| 407 | /** |
| 408 | * Checks if the compute node state changes from COMPLETE to INCOMPLETE |
| 409 | * when integration bridge is disconnected. |
| 410 | */ |
| 411 | @Test |
| 412 | public void testBackToIncompleteWhenBrIntDisconnected() { |
| 413 | testNodeManager.createNode(COMPUTE_4); |
| 414 | |
| 415 | assertEquals(ERR_STATE_NOT_MATCH, COMPLETE, |
| 416 | testNodeManager.node(COMPUTE_4_HOSTNAME).state()); |
| 417 | TEST_DEVICE_SERVICE.removeDevice(COMPUTE_4_INTG_DEVICE); |
| 418 | assertEquals(ERR_STATE_NOT_MATCH, INCOMPLETE, |
| 419 | testNodeManager.node(COMPUTE_4_HOSTNAME).state()); |
| 420 | } |
| 421 | |
| 422 | /** |
| 423 | * Checks if the compute node state changes from COMPLETE to INCOMPLETE |
| 424 | * when vxlan port is removed from integration bridge. |
| 425 | */ |
| 426 | @Test |
| 427 | public void testBackToIncompleteWhenVxlanRemoved() { |
| 428 | testNodeManager.createNode(COMPUTE_4); |
| 429 | |
| 430 | assertEquals(ERR_STATE_NOT_MATCH, COMPLETE, |
| 431 | testNodeManager.node(COMPUTE_4_HOSTNAME).state()); |
| 432 | TEST_DEVICE_SERVICE.removePort(COMPUTE_4_INTG_DEVICE, createPort( |
| 433 | COMPUTE_4_INTG_DEVICE, DEFAULT_TUNNEL)); |
| 434 | assertEquals(ERR_STATE_NOT_MATCH, INCOMPLETE, |
| 435 | testNodeManager.node(COMPUTE_4_HOSTNAME).state()); |
| 436 | |
| 437 | } |
| 438 | |
| 439 | private static Device createOvsdbDevice(IpAddress ovsdbIp) { |
| 440 | return new TestDevice(new ProviderId("of", "foo"), |
| 441 | DeviceId.deviceId("ovsdb:" + ovsdbIp.toString()), |
| 442 | CONTROLLER, |
| 443 | "manufacturer", |
| 444 | "hwVersion", |
| 445 | "swVersion", |
| 446 | "serialNumber", |
| 447 | new ChassisId(1)); |
| 448 | } |
| 449 | |
| 450 | private static Device createOpenFlowDevice(long devIdNum, String type) { |
| 451 | return new TestDevice(new ProviderId("of", "foo"), |
| 452 | DeviceId.deviceId(String.format("of:%016d", devIdNum)), |
| 453 | SWITCH, |
| 454 | type, |
| 455 | "hwVersion", |
| 456 | "swVersion", |
| 457 | "serialNumber", |
| 458 | new ChassisId(1)); |
| 459 | } |
| 460 | |
| 461 | private static Port createPort(Device device, String portName) { |
| 462 | return new DefaultPort(device, |
| 463 | PortNumber.portNumber(1), |
| 464 | true, |
| 465 | DefaultAnnotations.builder().set(PORT_NAME, portName).build()); |
| 466 | } |
| 467 | |
| 468 | private static OpenstackNode createNode(String hostname, |
| 469 | OpenstackNode.NodeType type, |
| 470 | Device intgBridge, |
| 471 | IpAddress ipAddr, |
| 472 | NodeState state) { |
| 473 | return new TestOpenstackNode( |
| 474 | hostname, |
| 475 | type, |
| 476 | intgBridge.id(), |
| 477 | null, |
| 478 | ipAddr, |
| 479 | ipAddr, |
| 480 | null, state); |
| 481 | } |
| 482 | |
| 483 | private static OpenstackNode createNode(String hostname, |
| 484 | OpenstackNode.NodeType type, |
| 485 | Device intgBridge, |
| 486 | Device routerBridge, |
| 487 | IpAddress ipAddr, |
| 488 | NodeState state) { |
| 489 | return new TestOpenstackNode( |
| 490 | hostname, |
| 491 | type, |
| 492 | intgBridge.id(), |
| 493 | routerBridge.id(), |
| 494 | ipAddr, |
| 495 | ipAddr, |
| 496 | null, state); |
| 497 | } |
| 498 | |
| 499 | private static final class TestDevice extends DefaultDevice { |
| 500 | private TestDevice(ProviderId providerId, |
| 501 | DeviceId id, |
| 502 | Type type, |
| 503 | String manufacturer, |
| 504 | String hwVersion, |
| 505 | String swVersion, |
| 506 | String serialNumber, |
| 507 | ChassisId chassisId, |
| 508 | Annotations... annotations) { |
| 509 | super(providerId, |
| 510 | id, |
| 511 | type, |
| 512 | manufacturer, |
| 513 | hwVersion, |
| 514 | swVersion, |
| 515 | serialNumber, |
| 516 | chassisId, |
| 517 | annotations); |
| 518 | } |
| 519 | |
| 520 | @Override |
| 521 | @SuppressWarnings("unchecked") |
| 522 | public <B extends Behaviour> B as(Class<B> projectionClass) { |
| 523 | if (projectionClass.equals(BridgeConfig.class)) { |
| 524 | return (B) new TestBridgeConfig(); |
| 525 | } else if (projectionClass.equals(InterfaceConfig.class)) { |
| 526 | return (B) new TestInterfaceConfig(); |
| 527 | } else if (projectionClass.equals(ExtensionTreatmentResolver.class)) { |
| 528 | ExtensionTreatmentResolver treatmentResolver = createMock(ExtensionTreatmentResolver.class); |
| 529 | expect(treatmentResolver.getExtensionInstruction(anyObject())) |
| 530 | .andReturn(new TestExtensionTreatment()) |
| 531 | .anyTimes(); |
| 532 | replay(treatmentResolver); |
| 533 | return (B) treatmentResolver; |
| 534 | } else { |
| 535 | return null; |
| 536 | } |
| 537 | } |
| 538 | |
| 539 | @Override |
| 540 | public <B extends Behaviour> boolean is(Class<B> projectionClass) { |
| 541 | return true; |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | private static final class TestOpenstackNode extends DefaultOpenstackNode { |
| 546 | private TestOpenstackNode(String hostname, |
| 547 | NodeType type, |
| 548 | DeviceId intgBridge, |
| 549 | DeviceId routerBridge, |
| 550 | IpAddress managementIp, |
| 551 | IpAddress dataIp, |
| 552 | String vlanIntf, |
| 553 | NodeState state) { |
| 554 | super(hostname, |
| 555 | type, |
| 556 | intgBridge, |
| 557 | routerBridge, |
| 558 | managementIp, |
| 559 | dataIp, |
| 560 | vlanIntf, |
| 561 | state); |
| 562 | } |
| 563 | |
| 564 | @Override |
| 565 | public PortNumber tunnelPortNum() { |
| 566 | return PortNumber.portNumber(1); |
| 567 | } |
| 568 | |
| 569 | @Override |
| 570 | public PortNumber vlanPortNum() { |
| 571 | return PortNumber.portNumber(1); |
| 572 | } |
| 573 | |
| 574 | @Override |
| 575 | public PortNumber patchPortNum() { |
| 576 | return PortNumber.portNumber(1); |
| 577 | } |
| 578 | |
| 579 | @Override |
| 580 | public MacAddress vlanPortMac() { |
| 581 | return MacAddress.NONE; |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | private static class TestOpenstackNodeManager implements OpenstackNodeService, OpenstackNodeAdminService { |
| 586 | Map<String, OpenstackNode> osNodeMap = Maps.newHashMap(); |
| 587 | List<OpenstackNodeListener> listeners = Lists.newArrayList(); |
| 588 | |
| 589 | @Override |
| 590 | public Set<OpenstackNode> nodes() { |
| 591 | return ImmutableSet.copyOf(osNodeMap.values()); |
| 592 | } |
| 593 | |
| 594 | @Override |
| 595 | public Set<OpenstackNode> nodes(OpenstackNode.NodeType type) { |
| 596 | return osNodeMap.values().stream() |
| 597 | .filter(osNode -> osNode.type() == type) |
| 598 | .collect(Collectors.toSet()); |
| 599 | } |
| 600 | |
| 601 | @Override |
| 602 | public Set<OpenstackNode> completeNodes() { |
| 603 | return osNodeMap.values().stream() |
| 604 | .filter(osNode -> osNode.state() == COMPLETE) |
| 605 | .collect(Collectors.toSet()); |
| 606 | } |
| 607 | |
| 608 | @Override |
| 609 | public Set<OpenstackNode> completeNodes(OpenstackNode.NodeType type) { |
| 610 | return osNodeMap.values().stream() |
| 611 | .filter(osNode -> osNode.type() == type && osNode.state() == COMPLETE) |
| 612 | .collect(Collectors.toSet()); |
| 613 | } |
| 614 | |
| 615 | @Override |
| 616 | public OpenstackNode node(String hostname) { |
| 617 | return osNodeMap.get(hostname); |
| 618 | } |
| 619 | |
| 620 | @Override |
| 621 | public OpenstackNode node(DeviceId deviceId) { |
| 622 | return osNodeMap.values().stream() |
| 623 | .filter(osNode -> Objects.equals(osNode.intgBridge(), deviceId) || |
| 624 | Objects.equals(osNode.ovsdb(), deviceId) || |
| 625 | Objects.equals(osNode.routerBridge(), deviceId)) |
| 626 | .findFirst().orElse(null); |
| 627 | } |
| 628 | |
| 629 | @Override |
| 630 | public void addListener(OpenstackNodeListener listener) { |
| 631 | listeners.add(listener); |
| 632 | } |
| 633 | |
| 634 | @Override |
| 635 | public void removeListener(OpenstackNodeListener listener) { |
| 636 | listeners.remove(listener); |
| 637 | } |
| 638 | |
| 639 | @Override |
| 640 | public void createNode(OpenstackNode osNode) { |
| 641 | osNodeMap.put(osNode.hostname(), osNode); |
| 642 | } |
| 643 | |
| 644 | @Override |
| 645 | public void updateNode(OpenstackNode osNode) { |
| 646 | osNodeMap.put(osNode.hostname(), osNode); |
| 647 | } |
| 648 | |
| 649 | @Override |
| 650 | public OpenstackNode removeNode(String hostname) { |
| 651 | return null; |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | private static class TestDeviceService extends DeviceServiceAdapter { |
| 656 | Map<DeviceId, Device> devMap = Maps.newHashMap(); |
| 657 | List<Port> portList = Lists.newArrayList(); |
| 658 | List<DeviceListener> listeners = Lists.newArrayList(); |
| 659 | |
| 660 | @Override |
| 661 | public void addListener(DeviceListener listener) { |
| 662 | listeners.add(listener); |
| 663 | } |
| 664 | |
| 665 | @Override |
| 666 | public void removeListener(DeviceListener listener) { |
| 667 | listeners.remove(listener); |
| 668 | } |
| 669 | |
| 670 | @Override |
| 671 | public Device getDevice(DeviceId deviceId) { |
| 672 | return devMap.get(deviceId); |
| 673 | } |
| 674 | |
| 675 | @Override |
| 676 | public List<Port> getPorts(DeviceId deviceId) { |
| 677 | return this.portList.stream() |
| 678 | .filter(p -> p.element().id().equals(deviceId)) |
| 679 | .collect(Collectors.toList()); |
| 680 | } |
| 681 | |
| 682 | @Override |
| 683 | public boolean isAvailable(DeviceId deviceId) { |
| 684 | return devMap.containsKey(deviceId); |
| 685 | } |
| 686 | |
| 687 | void addDevice(Device device) { |
| 688 | devMap.put(device.id(), device); |
| 689 | DeviceEvent event = new DeviceEvent(DEVICE_ADDED, device); |
| 690 | listeners.stream().filter(l -> l.isRelevant(event)).forEach(l -> l.event(event)); |
| 691 | } |
| 692 | |
| 693 | void removeDevice(Device device) { |
| 694 | devMap.remove(device.id()); |
| 695 | DeviceEvent event = new DeviceEvent(DEVICE_AVAILABILITY_CHANGED, device); |
| 696 | listeners.stream().filter(l -> l.isRelevant(event)).forEach(l -> l.event(event)); |
| 697 | } |
| 698 | |
| 699 | void addPort(Device device, Port port) { |
| 700 | portList.add(port); |
| 701 | DeviceEvent event = new DeviceEvent(PORT_ADDED, device, port); |
| 702 | listeners.stream().filter(l -> l.isRelevant(event)).forEach(l -> l.event(event)); |
| 703 | } |
| 704 | |
| 705 | void removePort(Device device, Port port) { |
| 706 | portList.remove(port); |
| 707 | DeviceEvent event = new DeviceEvent(PORT_REMOVED, device, port); |
| 708 | listeners.stream().filter(l -> l.isRelevant(event)).forEach(l -> l.event(event)); |
| 709 | } |
| 710 | |
| 711 | void clear() { |
| 712 | this.listeners.clear(); |
| 713 | this.devMap.clear(); |
| 714 | this.portList.clear(); |
| 715 | } |
| 716 | } |
| 717 | |
| 718 | private static class TestBridgeConfig implements BridgeConfig { |
| 719 | |
| 720 | @Override |
| 721 | public DriverData data() { |
| 722 | return null; |
| 723 | } |
| 724 | |
| 725 | @Override |
| 726 | public void setData(DriverData data) { |
| 727 | |
| 728 | } |
| 729 | |
| 730 | @Override |
| 731 | public DriverHandler handler() { |
| 732 | return null; |
| 733 | } |
| 734 | |
| 735 | @Override |
| 736 | public void setHandler(DriverHandler handler) { |
| 737 | |
| 738 | } |
| 739 | |
| 740 | @Override |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 741 | public boolean addBridge(BridgeDescription bridge) { |
| 742 | TEST_DEVICE_SERVICE.addDevice(new DefaultDevice(new ProviderId("of", "foo"), |
| 743 | DeviceId.deviceId("of:" + bridge.datapathId().get()), |
| 744 | SWITCH, |
| 745 | bridge.name(), |
| 746 | "hwVersion", |
| 747 | "swVersion", |
| 748 | "serialNumber", |
| 749 | new ChassisId(1))); |
| 750 | return true; |
| 751 | } |
| 752 | |
| 753 | @Override |
| 754 | public void deleteBridge(BridgeName bridgeName) { |
| 755 | |
| 756 | } |
| 757 | |
| 758 | @Override |
| 759 | public Collection<BridgeDescription> getBridges() { |
| 760 | return ImmutableSet.of(ROUT_BRIDGE); |
| 761 | } |
| 762 | |
| 763 | @Override |
| 764 | public void addPort(BridgeName bridgeName, String portName) { |
| 765 | |
| 766 | } |
| 767 | |
| 768 | @Override |
| 769 | public void deletePort(BridgeName bridgeName, String portName) { |
| 770 | |
| 771 | } |
| 772 | |
| 773 | @Override |
| 774 | public Collection<PortDescription> getPorts() { |
| 775 | return ImmutableSet.of(PATCH_ROUT); |
| 776 | } |
| 777 | |
| 778 | @Override |
| 779 | public Set<PortNumber> getPortNumbers() { |
| 780 | return null; |
| 781 | } |
| 782 | |
| 783 | @Override |
| 784 | public List<PortNumber> getLocalPorts(Iterable<String> ifaceIds) { |
| 785 | return null; |
| 786 | } |
| 787 | } |
| 788 | |
| 789 | private static class TestInterfaceConfig implements InterfaceConfig { |
| 790 | |
| 791 | @Override |
| 792 | public DriverData data() { |
| 793 | return null; |
| 794 | } |
| 795 | |
| 796 | @Override |
| 797 | public void setData(DriverData data) { |
| 798 | |
| 799 | } |
| 800 | |
| 801 | @Override |
| 802 | public DriverHandler handler() { |
| 803 | return null; |
| 804 | } |
| 805 | |
| 806 | @Override |
| 807 | public void setHandler(DriverHandler handler) { |
| 808 | |
| 809 | } |
| 810 | |
| 811 | @Override |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 812 | public boolean addAccessMode(String intf, VlanId vlanId) { |
| 813 | return false; |
| 814 | } |
| 815 | |
| 816 | @Override |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 817 | public boolean removeAccessMode(String intf) { |
| 818 | return false; |
| 819 | } |
| 820 | |
| 821 | @Override |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 822 | public boolean addTrunkMode(String intf, List<VlanId> vlanIds) { |
| 823 | return false; |
| 824 | } |
| 825 | |
| 826 | @Override |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 827 | public boolean removeTrunkMode(String intf) { |
| 828 | return false; |
| 829 | } |
| 830 | |
| 831 | @Override |
| 832 | public boolean addRateLimit(String intf, short limit) { |
| 833 | return false; |
| 834 | } |
| 835 | |
| 836 | @Override |
| 837 | public boolean removeRateLimit(String intf) { |
| 838 | return false; |
| 839 | } |
| 840 | |
| 841 | @Override |
| 842 | public boolean addTunnelMode(String intf, TunnelDescription tunnelDesc) { |
| 843 | TEST_DEVICE_SERVICE.devMap.values().stream() |
| 844 | .filter(device -> device.type() == SWITCH && |
| 845 | device.manufacturer().equals(INTEGRATION_BRIDGE)) |
| 846 | .forEach(device -> { |
| 847 | TEST_DEVICE_SERVICE.addPort(device, createPort(device, intf)); |
| 848 | }); |
| 849 | return true; |
| 850 | } |
| 851 | |
| 852 | @Override |
| 853 | public boolean removeTunnelMode(String intf) { |
| 854 | return false; |
| 855 | } |
| 856 | |
| 857 | @Override |
| 858 | public boolean addPatchMode(String ifaceName, PatchDescription patchInterface) { |
| 859 | if (ifaceName.equals(PATCH_INTG_BRIDGE)) { |
| 860 | TEST_DEVICE_SERVICE.devMap.values().stream() |
| 861 | .filter(device -> device.type() == SWITCH && |
| 862 | device.manufacturer().equals(INTEGRATION_BRIDGE)) |
| 863 | .forEach(device -> { |
| 864 | TEST_DEVICE_SERVICE.addPort(device, createPort(device, ifaceName)); |
| 865 | }); |
| 866 | } else if (ifaceName.equals(PATCH_ROUT_BRIDGE)) { |
| 867 | TEST_DEVICE_SERVICE.devMap.values().stream() |
| 868 | .filter(device -> device.type() == SWITCH && |
| 869 | device.manufacturer().equals(ROUTER_BRIDGE)) |
| 870 | .forEach(device -> { |
| 871 | TEST_DEVICE_SERVICE.addPort(device, createPort(device, ifaceName)); |
| 872 | }); |
| 873 | } |
| 874 | return true; |
| 875 | } |
| 876 | |
| 877 | @Override |
| 878 | public boolean removePatchMode(String ifaceName) { |
| 879 | return false; |
| 880 | } |
| 881 | |
| 882 | @Override |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 883 | public List<DeviceInterfaceDescription> getInterfaces() { |
| 884 | return null; |
| 885 | } |
| 886 | } |
| 887 | |
| 888 | private static class TestGroupService implements GroupService { |
| 889 | Map<GroupKey, Group> groupMap = Maps.newHashMap(); |
| 890 | Map<GroupKey, GroupBuckets> groupBucketsMap = Maps.newHashMap(); |
| 891 | List<GroupListener> listeners = Lists.newArrayList(); |
| 892 | |
| 893 | @Override |
| 894 | public void addListener(GroupListener listener) { |
| 895 | listeners.add(listener); |
| 896 | } |
| 897 | |
| 898 | @Override |
| 899 | public void removeListener(GroupListener listener) { |
| 900 | listeners.remove(listener); |
| 901 | } |
| 902 | |
| 903 | @Override |
| 904 | public void addGroup(GroupDescription groupDesc) { |
| 905 | DefaultGroup group = new DefaultGroup(GroupId.valueOf(groupDesc.givenGroupId()), groupDesc); |
| 906 | group.setState(Group.GroupState.ADDED); |
| 907 | groupMap.put(groupDesc.appCookie(), group); |
| 908 | groupBucketsMap.put(groupDesc.appCookie(), groupDesc.buckets()); |
| 909 | |
| 910 | GroupEvent event = new GroupEvent(GroupEvent.Type.GROUP_ADDED, group); |
| 911 | listeners.stream().filter(listener -> listener.isRelevant(event)) |
| 912 | .forEach(listener -> listener.event(event)); |
| 913 | } |
| 914 | |
| 915 | @Override |
| 916 | public Group getGroup(DeviceId deviceId, GroupKey appCookie) { |
| 917 | return groupMap.get(appCookie); |
| 918 | } |
| 919 | |
| 920 | @Override |
| 921 | public void addBucketsToGroup(DeviceId deviceId, GroupKey oldCookie, GroupBuckets buckets, |
| 922 | GroupKey newCookie, ApplicationId appId) { |
| 923 | |
| 924 | } |
| 925 | |
| 926 | @Override |
| 927 | public void removeBucketsFromGroup(DeviceId deviceId, GroupKey oldCookie, GroupBuckets buckets, |
| 928 | GroupKey newCookie, ApplicationId appId) { |
| 929 | |
| 930 | } |
| 931 | |
| 932 | @Override |
| 933 | public void purgeGroupEntries(DeviceId deviceId) { |
| 934 | |
| 935 | } |
| 936 | |
| 937 | @Override |
| 938 | public void removeGroup(DeviceId deviceId, GroupKey appCookie, ApplicationId appId) { |
| 939 | |
| 940 | } |
| 941 | |
| 942 | @Override |
| 943 | public Iterable<Group> getGroups(DeviceId deviceId, ApplicationId appId) { |
| 944 | return null; |
| 945 | } |
| 946 | |
| 947 | @Override |
| 948 | public Iterable<Group> getGroups(DeviceId deviceId) { |
| 949 | return null; |
| 950 | } |
| 951 | |
| 952 | @Override |
| 953 | public void setBucketsForGroup(DeviceId deviceId, GroupKey oldCookie, GroupBuckets buckets, |
| 954 | GroupKey newCookie, ApplicationId appId) { |
| 955 | groupBucketsMap.put(newCookie, buckets); |
| 956 | GroupEvent event = new GroupEvent(GroupEvent.Type.GROUP_UPDATED, groupMap.get(newCookie)); |
| 957 | listeners.stream().filter(listener -> listener.isRelevant(event)) |
| 958 | .forEach(listener -> listener.event(event)); |
| 959 | } |
| 960 | |
| 961 | } |
| 962 | |
| 963 | private static class TestExtensionTreatment implements ExtensionTreatment { |
| 964 | Ip4Address tunnelDst; |
| 965 | |
| 966 | @Override |
| 967 | public ExtensionTreatmentType type() { |
| 968 | return null; |
| 969 | } |
| 970 | |
| 971 | @Override |
| 972 | public <T> void setPropertyValue(String key, T value) throws ExtensionPropertyException { |
| 973 | tunnelDst = (Ip4Address) value; |
| 974 | } |
| 975 | |
| 976 | @Override |
| 977 | public <T> T getPropertyValue(String key) throws ExtensionPropertyException { |
| 978 | return null; |
| 979 | } |
| 980 | |
| 981 | @Override |
| 982 | public List<String> getProperties() { |
| 983 | return null; |
| 984 | } |
| 985 | |
| 986 | @Override |
| 987 | public byte[] serialize() { |
| 988 | return new byte[0]; |
| 989 | } |
| 990 | |
| 991 | @Override |
| 992 | public void deserialize(byte[] data) { |
| 993 | |
| 994 | } |
| 995 | |
| 996 | @Override |
| 997 | public boolean equals(Object obj) { |
| 998 | TestExtensionTreatment that = (TestExtensionTreatment) obj; |
| 999 | return Objects.equals(tunnelDst, that.tunnelDst); |
| 1000 | } |
| 1001 | |
| 1002 | @Override |
| 1003 | public int hashCode() { |
| 1004 | return Objects.hash(tunnelDst); |
| 1005 | } |
| 1006 | } |
| 1007 | |
| 1008 | private static class TestCoreService extends CoreServiceAdapter { |
| 1009 | |
| 1010 | @Override |
| 1011 | public ApplicationId getAppId(String name) { |
| 1012 | return TEST_APP_ID; |
| 1013 | } |
| 1014 | } |
| 1015 | |
| 1016 | private static class TestLeadershipService extends LeadershipServiceAdapter { |
| 1017 | |
| 1018 | @Override |
| 1019 | public NodeId getLeader(String path) { |
| 1020 | return LOCAL_NODE_ID; |
| 1021 | } |
| 1022 | } |
| 1023 | |
| 1024 | private static class TestClusterService extends ClusterServiceAdapter { |
| 1025 | |
| 1026 | @Override |
| 1027 | public ControllerNode getLocalNode() { |
| 1028 | return LOCAL_CTRL; |
| 1029 | } |
| 1030 | } |
| 1031 | |
| 1032 | private class TestComponentConfigService extends ComponentConfigAdapter { |
| 1033 | |
| 1034 | } |
| 1035 | } |