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 | |
daniel park | 04c40cc | 2018-02-19 17:48:30 +0900 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableSet; |
| 19 | import com.google.common.collect.Lists; |
| 20 | import com.google.common.collect.Maps; |
| 21 | import com.google.common.util.concurrent.MoreExecutors; |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 22 | import org.junit.After; |
| 23 | import org.junit.Before; |
| 24 | import org.junit.Test; |
| 25 | import org.onlab.junit.TestUtils; |
| 26 | import org.onlab.packet.ChassisId; |
| 27 | import org.onlab.packet.Ip4Address; |
| 28 | import org.onlab.packet.IpAddress; |
| 29 | import org.onlab.packet.MacAddress; |
| 30 | import org.onlab.packet.VlanId; |
| 31 | import org.onosproject.cfg.ComponentConfigAdapter; |
| 32 | import org.onosproject.cluster.ClusterServiceAdapter; |
| 33 | import org.onosproject.cluster.ControllerNode; |
| 34 | import org.onosproject.cluster.DefaultControllerNode; |
| 35 | import org.onosproject.cluster.LeadershipServiceAdapter; |
| 36 | import org.onosproject.cluster.NodeId; |
| 37 | import org.onosproject.core.ApplicationId; |
| 38 | import org.onosproject.core.CoreServiceAdapter; |
| 39 | import org.onosproject.core.DefaultApplicationId; |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 40 | import org.onosproject.net.Annotations; |
| 41 | import org.onosproject.net.DefaultAnnotations; |
| 42 | import org.onosproject.net.DefaultDevice; |
| 43 | import org.onosproject.net.DefaultPort; |
| 44 | import org.onosproject.net.Device; |
| 45 | import org.onosproject.net.DeviceId; |
| 46 | import org.onosproject.net.Port; |
| 47 | import org.onosproject.net.PortNumber; |
| 48 | import org.onosproject.net.behaviour.BridgeConfig; |
| 49 | import org.onosproject.net.behaviour.BridgeDescription; |
| 50 | import org.onosproject.net.behaviour.BridgeName; |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 51 | import org.onosproject.net.behaviour.DefaultBridgeDescription; |
| 52 | import org.onosproject.net.behaviour.ExtensionTreatmentResolver; |
| 53 | import org.onosproject.net.behaviour.InterfaceConfig; |
| 54 | import org.onosproject.net.behaviour.PatchDescription; |
| 55 | import org.onosproject.net.behaviour.TunnelDescription; |
| 56 | import org.onosproject.net.device.DefaultPortDescription; |
| 57 | import org.onosproject.net.device.DeviceAdminService; |
| 58 | import org.onosproject.net.device.DeviceEvent; |
| 59 | import org.onosproject.net.device.DeviceInterfaceDescription; |
| 60 | import org.onosproject.net.device.DeviceListener; |
| 61 | import org.onosproject.net.device.DeviceServiceAdapter; |
| 62 | import org.onosproject.net.device.PortDescription; |
| 63 | import org.onosproject.net.driver.Behaviour; |
| 64 | import org.onosproject.net.driver.DriverData; |
| 65 | import org.onosproject.net.driver.DriverHandler; |
| 66 | import org.onosproject.net.flow.instructions.ExtensionPropertyException; |
| 67 | import org.onosproject.net.flow.instructions.ExtensionTreatment; |
| 68 | import org.onosproject.net.flow.instructions.ExtensionTreatmentType; |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 69 | import org.onosproject.net.provider.ProviderId; |
| 70 | import org.onosproject.openstacknode.api.NodeState; |
| 71 | import org.onosproject.openstacknode.api.OpenstackNode; |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 72 | import org.onosproject.ovsdb.controller.OvsdbClientService; |
| 73 | import org.onosproject.ovsdb.controller.OvsdbController; |
| 74 | |
daniel park | 04c40cc | 2018-02-19 17:48:30 +0900 | [diff] [blame] | 75 | import java.util.Collection; |
| 76 | import java.util.List; |
| 77 | import java.util.Map; |
| 78 | import java.util.Objects; |
| 79 | import java.util.Set; |
| 80 | import java.util.stream.Collectors; |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 81 | |
Ray Milkey | 0d47a55 | 2017-08-22 10:16:31 -0700 | [diff] [blame] | 82 | import static org.easymock.EasyMock.anyObject; |
| 83 | import static org.easymock.EasyMock.createMock; |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 84 | import static org.easymock.EasyMock.expect; |
Ray Milkey | 0d47a55 | 2017-08-22 10:16:31 -0700 | [diff] [blame] | 85 | import static org.easymock.EasyMock.replay; |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 86 | import static org.junit.Assert.assertEquals; |
| 87 | import static org.onosproject.net.AnnotationKeys.PORT_NAME; |
| 88 | import static org.onosproject.net.Device.Type.CONTROLLER; |
| 89 | import static org.onosproject.net.Device.Type.SWITCH; |
Ray Milkey | 0d47a55 | 2017-08-22 10:16:31 -0700 | [diff] [blame] | 90 | import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_ADDED; |
| 91 | import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED; |
| 92 | import static org.onosproject.net.device.DeviceEvent.Type.PORT_ADDED; |
| 93 | import static org.onosproject.net.device.DeviceEvent.Type.PORT_REMOVED; |
| 94 | import static org.onosproject.openstacknode.api.Constants.DEFAULT_TUNNEL; |
| 95 | import static org.onosproject.openstacknode.api.Constants.INTEGRATION_BRIDGE; |
| 96 | import static org.onosproject.openstacknode.api.Constants.PATCH_INTG_BRIDGE; |
| 97 | import static org.onosproject.openstacknode.api.Constants.PATCH_ROUT_BRIDGE; |
| 98 | import static org.onosproject.openstacknode.api.Constants.ROUTER_BRIDGE; |
| 99 | import static org.onosproject.openstacknode.api.NodeState.COMPLETE; |
| 100 | import static org.onosproject.openstacknode.api.NodeState.DEVICE_CREATED; |
| 101 | import static org.onosproject.openstacknode.api.NodeState.INCOMPLETE; |
| 102 | import static org.onosproject.openstacknode.api.NodeState.INIT; |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 103 | import static org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE; |
| 104 | import static org.onosproject.openstacknode.api.OpenstackNode.NodeType.GATEWAY; |
| 105 | |
| 106 | /** |
| 107 | * Unit test for DefaultOpenstackNodeHandler. |
| 108 | */ |
| 109 | public class DefaultOpenstackNodeHandlerTest { |
| 110 | |
| 111 | private static final ApplicationId TEST_APP_ID = new DefaultApplicationId(1, "test"); |
| 112 | private static final String ERR_STATE_NOT_MATCH = "Node state did not match"; |
| 113 | private static final NodeId LOCAL_NODE_ID = new NodeId("local"); |
| 114 | private static final ControllerNode LOCAL_CTRL = |
| 115 | new DefaultControllerNode(LOCAL_NODE_ID, IpAddress.valueOf("127.0.0.1")); |
| 116 | |
| 117 | private static final BridgeDescription ROUT_BRIDGE = DefaultBridgeDescription.builder() |
| 118 | .name(ROUTER_BRIDGE) |
| 119 | .failMode(BridgeDescription.FailMode.SECURE) |
| 120 | .disableInBand() |
| 121 | .build(); |
| 122 | |
Yuta HIGUCHI | 53e4796 | 2018-03-01 23:50:48 -0800 | [diff] [blame] | 123 | private static final PortDescription PATCH_ROUT = DefaultPortDescription.builder() |
| 124 | .withPortNumber(PortNumber.portNumber(1)) |
| 125 | .isEnabled(true) |
| 126 | .annotations(DefaultAnnotations.builder() |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 127 | .set(PORT_NAME, PATCH_ROUT_BRIDGE) |
Yuta HIGUCHI | 53e4796 | 2018-03-01 23:50:48 -0800 | [diff] [blame] | 128 | .build()) |
| 129 | .build(); |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 130 | |
| 131 | private static final String COMPUTE_1_HOSTNAME = "compute_1"; |
| 132 | private static final String COMPUTE_2_HOSTNAME = "compute_2"; |
| 133 | private static final String COMPUTE_3_HOSTNAME = "compute_3"; |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 134 | private static final String GATEWAY_1_HOSTNAME = "gateway_1"; |
| 135 | private static final String GATEWAY_2_HOSTNAME = "gateway_2"; |
| 136 | private static final String GATEWAY_3_HOSTNAME = "gateway_3"; |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 137 | |
| 138 | private static final IpAddress COMPUTE_1_IP = IpAddress.valueOf("10.100.0.1"); |
| 139 | private static final IpAddress COMPUTE_2_IP = IpAddress.valueOf("10.100.0.2"); |
| 140 | private static final IpAddress COMPUTE_3_IP = IpAddress.valueOf("10.100.0.3"); |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 141 | private static final IpAddress GATEWAY_1_IP = IpAddress.valueOf("10.100.0.5"); |
| 142 | private static final IpAddress GATEWAY_2_IP = IpAddress.valueOf("10.100.0.6"); |
| 143 | private static final IpAddress GATEWAY_3_IP = IpAddress.valueOf("10.100.0.7"); |
daniel park | b18424c | 2018-02-05 15:43:43 +0900 | [diff] [blame] | 144 | |
| 145 | private static final String GATEWAY_UPLINK_PORT = "eth0"; |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 146 | |
| 147 | private static final Device COMPUTE_1_INTG_DEVICE = createOpenFlowDevice(1, INTEGRATION_BRIDGE); |
| 148 | private static final Device COMPUTE_2_INTG_DEVICE = createOpenFlowDevice(2, INTEGRATION_BRIDGE); |
| 149 | private static final Device COMPUTE_3_INTG_DEVICE = createOpenFlowDevice(3, INTEGRATION_BRIDGE); |
daniel park | b18424c | 2018-02-05 15:43:43 +0900 | [diff] [blame] | 150 | private static final Device GATEWAY_1_INTG_DEVICE = createOpenFlowDevice(4, INTEGRATION_BRIDGE); |
| 151 | private static final Device GATEWAY_2_INTG_DEVICE = createOpenFlowDevice(5, INTEGRATION_BRIDGE); |
| 152 | private static final Device GATEWAY_3_INTG_DEVICE = createOpenFlowDevice(6, INTEGRATION_BRIDGE); |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 153 | |
| 154 | private static final Device COMPUTE_1_OVSDB_DEVICE = createOvsdbDevice(COMPUTE_1_IP); |
| 155 | private static final Device COMPUTE_2_OVSDB_DEVICE = createOvsdbDevice(COMPUTE_2_IP); |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 156 | private static final Device GATEWAY_1_OVSDB_DEVICE = createOvsdbDevice(GATEWAY_1_IP); |
| 157 | private static final Device GATEWAY_2_OVSDB_DEVICE = createOvsdbDevice(GATEWAY_2_IP); |
| 158 | |
| 159 | private static final OpenstackNode COMPUTE_1 = createNode( |
| 160 | COMPUTE_1_HOSTNAME, |
| 161 | COMPUTE, |
| 162 | COMPUTE_1_INTG_DEVICE, |
| 163 | COMPUTE_1_IP, |
| 164 | INIT |
| 165 | ); |
| 166 | |
| 167 | private static final OpenstackNode COMPUTE_2 = createNode( |
| 168 | COMPUTE_2_HOSTNAME, |
| 169 | COMPUTE, |
| 170 | COMPUTE_2_INTG_DEVICE, |
| 171 | COMPUTE_2_IP, |
| 172 | DEVICE_CREATED |
| 173 | ); |
| 174 | |
| 175 | private static final OpenstackNode COMPUTE_3 = createNode( |
| 176 | COMPUTE_3_HOSTNAME, |
| 177 | COMPUTE, |
| 178 | COMPUTE_3_INTG_DEVICE, |
| 179 | COMPUTE_3_IP, |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 180 | COMPLETE |
| 181 | ); |
| 182 | |
| 183 | private static final OpenstackNode GATEWAY_1 = createNode( |
| 184 | GATEWAY_1_HOSTNAME, |
| 185 | GATEWAY, |
| 186 | GATEWAY_1_INTG_DEVICE, |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 187 | GATEWAY_1_IP, |
daniel park | b18424c | 2018-02-05 15:43:43 +0900 | [diff] [blame] | 188 | GATEWAY_UPLINK_PORT, |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 189 | INIT |
| 190 | ); |
| 191 | |
| 192 | private static final OpenstackNode GATEWAY_2 = createNode( |
| 193 | GATEWAY_2_HOSTNAME, |
| 194 | GATEWAY, |
| 195 | GATEWAY_2_INTG_DEVICE, |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 196 | GATEWAY_2_IP, |
daniel park | b18424c | 2018-02-05 15:43:43 +0900 | [diff] [blame] | 197 | GATEWAY_UPLINK_PORT, |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 198 | DEVICE_CREATED |
| 199 | ); |
| 200 | |
| 201 | private static final OpenstackNode GATEWAY_3 = createNode( |
| 202 | GATEWAY_3_HOSTNAME, |
| 203 | GATEWAY, |
| 204 | GATEWAY_3_INTG_DEVICE, |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 205 | GATEWAY_3_IP, |
daniel park | b18424c | 2018-02-05 15:43:43 +0900 | [diff] [blame] | 206 | GATEWAY_UPLINK_PORT, |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 207 | COMPLETE |
| 208 | ); |
| 209 | |
| 210 | private static final TestDeviceService TEST_DEVICE_SERVICE = new TestDeviceService(); |
| 211 | |
| 212 | private TestOpenstackNodeManager testNodeManager; |
| 213 | private DefaultOpenstackNodeHandler target; |
| 214 | |
| 215 | @Before |
| 216 | public void setUp() throws Exception { |
| 217 | DeviceAdminService mockDeviceAdminService = createMock(DeviceAdminService.class); |
| 218 | mockDeviceAdminService.removeDevice(anyObject()); |
| 219 | replay(mockDeviceAdminService); |
| 220 | |
| 221 | OvsdbClientService mockOvsdbClient = createMock(OvsdbClientService.class); |
| 222 | expect(mockOvsdbClient.isConnected()) |
| 223 | .andReturn(true) |
| 224 | .anyTimes(); |
| 225 | replay(mockOvsdbClient); |
| 226 | |
| 227 | OvsdbController mockOvsdbController = createMock(OvsdbController.class); |
| 228 | expect(mockOvsdbController.getOvsdbClient(anyObject())) |
| 229 | .andReturn(mockOvsdbClient) |
| 230 | .anyTimes(); |
| 231 | replay(mockOvsdbController); |
| 232 | |
| 233 | testNodeManager = new TestOpenstackNodeManager(); |
| 234 | target = new DefaultOpenstackNodeHandler(); |
| 235 | |
| 236 | target.coreService = new TestCoreService(); |
| 237 | target.leadershipService = new TestLeadershipService(); |
| 238 | target.clusterService = new TestClusterService(); |
| 239 | target.deviceService = TEST_DEVICE_SERVICE; |
| 240 | target.deviceAdminService = mockDeviceAdminService; |
| 241 | target.ovsdbController = mockOvsdbController; |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 242 | target.osNodeService = testNodeManager; |
| 243 | target.osNodeAdminService = testNodeManager; |
| 244 | target.componentConfigService = new TestComponentConfigService(); |
| 245 | TestUtils.setField(target, "eventExecutor", MoreExecutors.newDirectExecutorService()); |
| 246 | target.activate(); |
| 247 | } |
| 248 | |
| 249 | @After |
| 250 | public void tearDown() { |
| 251 | TEST_DEVICE_SERVICE.clear(); |
| 252 | target.deactivate(); |
| 253 | target = null; |
| 254 | testNodeManager = null; |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * Checks if the compute node state changes from INIT to DEVICE_CREATED |
| 259 | * after processing INIT state. |
| 260 | */ |
| 261 | @Test |
| 262 | public void testComputeNodeProcessNodeInitState() { |
| 263 | testNodeManager.createNode(COMPUTE_1); |
| 264 | TEST_DEVICE_SERVICE.devMap.put(COMPUTE_1_OVSDB_DEVICE.id(), COMPUTE_1_OVSDB_DEVICE); |
| 265 | |
| 266 | assertEquals(ERR_STATE_NOT_MATCH, INIT, |
| 267 | testNodeManager.node(COMPUTE_1_HOSTNAME).state()); |
| 268 | target.processInitState(COMPUTE_1); |
| 269 | assertEquals(ERR_STATE_NOT_MATCH, DEVICE_CREATED, |
| 270 | testNodeManager.node(COMPUTE_1_HOSTNAME).state()); |
| 271 | } |
| 272 | |
| 273 | /** |
| 274 | * Checks if the gateway node state changes from INIT to DEVICE_CREATED |
| 275 | * after processing INIT state. |
| 276 | */ |
| 277 | @Test |
| 278 | public void testGatewayNodeProcessNodeInitState() { |
| 279 | testNodeManager.createNode(GATEWAY_1); |
| 280 | TEST_DEVICE_SERVICE.devMap.put(GATEWAY_1_OVSDB_DEVICE.id(), GATEWAY_1_OVSDB_DEVICE); |
| 281 | |
| 282 | assertEquals(ERR_STATE_NOT_MATCH, INIT, |
| 283 | testNodeManager.node(GATEWAY_1_HOSTNAME).state()); |
| 284 | target.processInitState(GATEWAY_1); |
| 285 | assertEquals(ERR_STATE_NOT_MATCH, DEVICE_CREATED, |
| 286 | testNodeManager.node(GATEWAY_1_HOSTNAME).state()); |
| 287 | } |
| 288 | |
| 289 | /** |
| 290 | * Checks if the compute node state changes from DEVICE_CREATED to |
| 291 | * PORT_CREATED after processing DEVICE_CREATED state. |
| 292 | */ |
| 293 | @Test |
| 294 | public void testComputeNodeProcessDeviceCreatedState() { |
| 295 | testNodeManager.createNode(COMPUTE_2); |
| 296 | TEST_DEVICE_SERVICE.devMap.put(COMPUTE_2_OVSDB_DEVICE.id(), COMPUTE_2_OVSDB_DEVICE); |
| 297 | TEST_DEVICE_SERVICE.devMap.put(COMPUTE_2_INTG_DEVICE.id(), COMPUTE_2_INTG_DEVICE); |
| 298 | |
| 299 | assertEquals(ERR_STATE_NOT_MATCH, DEVICE_CREATED, |
| 300 | testNodeManager.node(COMPUTE_2_HOSTNAME).state()); |
| 301 | target.processDeviceCreatedState(COMPUTE_2); |
daniel park | b18424c | 2018-02-05 15:43:43 +0900 | [diff] [blame] | 302 | assertEquals(ERR_STATE_NOT_MATCH, COMPLETE, |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 303 | testNodeManager.node(COMPUTE_2_HOSTNAME).state()); |
| 304 | } |
| 305 | |
| 306 | /** |
| 307 | * Checks if the gateway node state changes from DEVICE_CREATED to |
| 308 | * PORT_CREATED after processing DEVICE_CREATED state. |
| 309 | */ |
| 310 | @Test |
| 311 | public void testGatewayNodeProcessDeviceCreatedState() { |
| 312 | testNodeManager.createNode(GATEWAY_2); |
| 313 | TEST_DEVICE_SERVICE.devMap.put(GATEWAY_2_OVSDB_DEVICE.id(), GATEWAY_2_OVSDB_DEVICE); |
| 314 | TEST_DEVICE_SERVICE.devMap.put(GATEWAY_2_INTG_DEVICE.id(), GATEWAY_2_INTG_DEVICE); |
daniel park | b18424c | 2018-02-05 15:43:43 +0900 | [diff] [blame] | 315 | TEST_DEVICE_SERVICE.portList.add(createPort(GATEWAY_2_INTG_DEVICE, GATEWAY_UPLINK_PORT)); |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 316 | |
| 317 | assertEquals(ERR_STATE_NOT_MATCH, DEVICE_CREATED, |
| 318 | testNodeManager.node(GATEWAY_2_HOSTNAME).state()); |
| 319 | target.processDeviceCreatedState(GATEWAY_2); |
daniel park | b18424c | 2018-02-05 15:43:43 +0900 | [diff] [blame] | 320 | assertEquals(ERR_STATE_NOT_MATCH, COMPLETE, |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 321 | testNodeManager.node(GATEWAY_2_HOSTNAME).state()); |
| 322 | } |
| 323 | |
| 324 | /** |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 325 | * Checks if the compute node state changes from COMPLETE to INCOMPLETE |
| 326 | * when integration bridge is disconnected. |
| 327 | */ |
| 328 | @Test |
| 329 | public void testBackToIncompleteWhenBrIntDisconnected() { |
daniel park | b18424c | 2018-02-05 15:43:43 +0900 | [diff] [blame] | 330 | testNodeManager.createNode(COMPUTE_3); |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 331 | |
| 332 | assertEquals(ERR_STATE_NOT_MATCH, COMPLETE, |
daniel park | b18424c | 2018-02-05 15:43:43 +0900 | [diff] [blame] | 333 | testNodeManager.node(COMPUTE_3_HOSTNAME).state()); |
| 334 | TEST_DEVICE_SERVICE.removeDevice(COMPUTE_3_INTG_DEVICE); |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 335 | assertEquals(ERR_STATE_NOT_MATCH, INCOMPLETE, |
daniel park | b18424c | 2018-02-05 15:43:43 +0900 | [diff] [blame] | 336 | testNodeManager.node(COMPUTE_3_HOSTNAME).state()); |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | /** |
| 340 | * Checks if the compute node state changes from COMPLETE to INCOMPLETE |
| 341 | * when vxlan port is removed from integration bridge. |
| 342 | */ |
| 343 | @Test |
| 344 | public void testBackToIncompleteWhenVxlanRemoved() { |
daniel park | b18424c | 2018-02-05 15:43:43 +0900 | [diff] [blame] | 345 | testNodeManager.createNode(COMPUTE_3); |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 346 | |
| 347 | assertEquals(ERR_STATE_NOT_MATCH, COMPLETE, |
daniel park | b18424c | 2018-02-05 15:43:43 +0900 | [diff] [blame] | 348 | testNodeManager.node(COMPUTE_3_HOSTNAME).state()); |
| 349 | TEST_DEVICE_SERVICE.removePort(COMPUTE_3_INTG_DEVICE, createPort( |
| 350 | COMPUTE_3_INTG_DEVICE, DEFAULT_TUNNEL)); |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 351 | assertEquals(ERR_STATE_NOT_MATCH, INCOMPLETE, |
daniel park | b18424c | 2018-02-05 15:43:43 +0900 | [diff] [blame] | 352 | testNodeManager.node(COMPUTE_3_HOSTNAME).state()); |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 353 | |
| 354 | } |
| 355 | |
| 356 | private static Device createOvsdbDevice(IpAddress ovsdbIp) { |
| 357 | return new TestDevice(new ProviderId("of", "foo"), |
| 358 | DeviceId.deviceId("ovsdb:" + ovsdbIp.toString()), |
| 359 | CONTROLLER, |
| 360 | "manufacturer", |
| 361 | "hwVersion", |
| 362 | "swVersion", |
| 363 | "serialNumber", |
| 364 | new ChassisId(1)); |
| 365 | } |
| 366 | |
| 367 | private static Device createOpenFlowDevice(long devIdNum, String type) { |
| 368 | return new TestDevice(new ProviderId("of", "foo"), |
| 369 | DeviceId.deviceId(String.format("of:%016d", devIdNum)), |
| 370 | SWITCH, |
| 371 | type, |
| 372 | "hwVersion", |
| 373 | "swVersion", |
| 374 | "serialNumber", |
| 375 | new ChassisId(1)); |
| 376 | } |
| 377 | |
| 378 | private static Port createPort(Device device, String portName) { |
| 379 | return new DefaultPort(device, |
| 380 | PortNumber.portNumber(1), |
| 381 | true, |
| 382 | DefaultAnnotations.builder().set(PORT_NAME, portName).build()); |
| 383 | } |
| 384 | |
| 385 | private static OpenstackNode createNode(String hostname, |
| 386 | OpenstackNode.NodeType type, |
| 387 | Device intgBridge, |
| 388 | IpAddress ipAddr, |
| 389 | NodeState state) { |
| 390 | return new TestOpenstackNode( |
| 391 | hostname, |
| 392 | type, |
| 393 | intgBridge.id(), |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 394 | ipAddr, |
| 395 | ipAddr, |
daniel park | b18424c | 2018-02-05 15:43:43 +0900 | [diff] [blame] | 396 | null, null, state); |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | private static OpenstackNode createNode(String hostname, |
| 400 | OpenstackNode.NodeType type, |
| 401 | Device intgBridge, |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 402 | IpAddress ipAddr, |
daniel park | b18424c | 2018-02-05 15:43:43 +0900 | [diff] [blame] | 403 | String uplinkPort, |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 404 | NodeState state) { |
| 405 | return new TestOpenstackNode( |
| 406 | hostname, |
| 407 | type, |
| 408 | intgBridge.id(), |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 409 | ipAddr, |
| 410 | ipAddr, |
daniel park | b18424c | 2018-02-05 15:43:43 +0900 | [diff] [blame] | 411 | null, uplinkPort, state); |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | private static final class TestDevice extends DefaultDevice { |
| 415 | private TestDevice(ProviderId providerId, |
| 416 | DeviceId id, |
| 417 | Type type, |
| 418 | String manufacturer, |
| 419 | String hwVersion, |
| 420 | String swVersion, |
| 421 | String serialNumber, |
| 422 | ChassisId chassisId, |
| 423 | Annotations... annotations) { |
| 424 | super(providerId, |
| 425 | id, |
| 426 | type, |
| 427 | manufacturer, |
| 428 | hwVersion, |
| 429 | swVersion, |
| 430 | serialNumber, |
| 431 | chassisId, |
| 432 | annotations); |
| 433 | } |
| 434 | |
| 435 | @Override |
| 436 | @SuppressWarnings("unchecked") |
| 437 | public <B extends Behaviour> B as(Class<B> projectionClass) { |
| 438 | if (projectionClass.equals(BridgeConfig.class)) { |
| 439 | return (B) new TestBridgeConfig(); |
| 440 | } else if (projectionClass.equals(InterfaceConfig.class)) { |
| 441 | return (B) new TestInterfaceConfig(); |
| 442 | } else if (projectionClass.equals(ExtensionTreatmentResolver.class)) { |
| 443 | ExtensionTreatmentResolver treatmentResolver = createMock(ExtensionTreatmentResolver.class); |
| 444 | expect(treatmentResolver.getExtensionInstruction(anyObject())) |
| 445 | .andReturn(new TestExtensionTreatment()) |
| 446 | .anyTimes(); |
| 447 | replay(treatmentResolver); |
| 448 | return (B) treatmentResolver; |
| 449 | } else { |
| 450 | return null; |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | @Override |
| 455 | public <B extends Behaviour> boolean is(Class<B> projectionClass) { |
| 456 | return true; |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | private static final class TestOpenstackNode extends DefaultOpenstackNode { |
| 461 | private TestOpenstackNode(String hostname, |
| 462 | NodeType type, |
| 463 | DeviceId intgBridge, |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 464 | IpAddress managementIp, |
| 465 | IpAddress dataIp, |
| 466 | String vlanIntf, |
daniel park | b18424c | 2018-02-05 15:43:43 +0900 | [diff] [blame] | 467 | String uplinkPort, |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 468 | NodeState state) { |
| 469 | super(hostname, |
| 470 | type, |
| 471 | intgBridge, |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 472 | managementIp, |
| 473 | dataIp, |
| 474 | vlanIntf, |
daniel park | b18424c | 2018-02-05 15:43:43 +0900 | [diff] [blame] | 475 | uplinkPort, |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 476 | state); |
| 477 | } |
| 478 | |
| 479 | @Override |
| 480 | public PortNumber tunnelPortNum() { |
| 481 | return PortNumber.portNumber(1); |
| 482 | } |
| 483 | |
| 484 | @Override |
| 485 | public PortNumber vlanPortNum() { |
| 486 | return PortNumber.portNumber(1); |
| 487 | } |
| 488 | |
| 489 | @Override |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 490 | public MacAddress vlanPortMac() { |
| 491 | return MacAddress.NONE; |
| 492 | } |
| 493 | } |
| 494 | |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 495 | private static class TestDeviceService extends DeviceServiceAdapter { |
| 496 | Map<DeviceId, Device> devMap = Maps.newHashMap(); |
| 497 | List<Port> portList = Lists.newArrayList(); |
| 498 | List<DeviceListener> listeners = Lists.newArrayList(); |
| 499 | |
| 500 | @Override |
| 501 | public void addListener(DeviceListener listener) { |
| 502 | listeners.add(listener); |
| 503 | } |
| 504 | |
| 505 | @Override |
| 506 | public void removeListener(DeviceListener listener) { |
| 507 | listeners.remove(listener); |
| 508 | } |
| 509 | |
| 510 | @Override |
| 511 | public Device getDevice(DeviceId deviceId) { |
| 512 | return devMap.get(deviceId); |
| 513 | } |
| 514 | |
| 515 | @Override |
| 516 | public List<Port> getPorts(DeviceId deviceId) { |
| 517 | return this.portList.stream() |
| 518 | .filter(p -> p.element().id().equals(deviceId)) |
| 519 | .collect(Collectors.toList()); |
| 520 | } |
| 521 | |
| 522 | @Override |
| 523 | public boolean isAvailable(DeviceId deviceId) { |
| 524 | return devMap.containsKey(deviceId); |
| 525 | } |
| 526 | |
| 527 | void addDevice(Device device) { |
| 528 | devMap.put(device.id(), device); |
| 529 | DeviceEvent event = new DeviceEvent(DEVICE_ADDED, device); |
| 530 | listeners.stream().filter(l -> l.isRelevant(event)).forEach(l -> l.event(event)); |
| 531 | } |
| 532 | |
| 533 | void removeDevice(Device device) { |
| 534 | devMap.remove(device.id()); |
| 535 | DeviceEvent event = new DeviceEvent(DEVICE_AVAILABILITY_CHANGED, device); |
| 536 | listeners.stream().filter(l -> l.isRelevant(event)).forEach(l -> l.event(event)); |
| 537 | } |
| 538 | |
| 539 | void addPort(Device device, Port port) { |
| 540 | portList.add(port); |
| 541 | DeviceEvent event = new DeviceEvent(PORT_ADDED, device, port); |
| 542 | listeners.stream().filter(l -> l.isRelevant(event)).forEach(l -> l.event(event)); |
| 543 | } |
| 544 | |
| 545 | void removePort(Device device, Port port) { |
| 546 | portList.remove(port); |
| 547 | DeviceEvent event = new DeviceEvent(PORT_REMOVED, device, port); |
| 548 | listeners.stream().filter(l -> l.isRelevant(event)).forEach(l -> l.event(event)); |
| 549 | } |
| 550 | |
| 551 | void clear() { |
| 552 | this.listeners.clear(); |
| 553 | this.devMap.clear(); |
| 554 | this.portList.clear(); |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | private static class TestBridgeConfig implements BridgeConfig { |
| 559 | |
| 560 | @Override |
| 561 | public DriverData data() { |
| 562 | return null; |
| 563 | } |
| 564 | |
| 565 | @Override |
| 566 | public void setData(DriverData data) { |
| 567 | |
| 568 | } |
| 569 | |
| 570 | @Override |
| 571 | public DriverHandler handler() { |
| 572 | return null; |
| 573 | } |
| 574 | |
| 575 | @Override |
| 576 | public void setHandler(DriverHandler handler) { |
| 577 | |
| 578 | } |
| 579 | |
| 580 | @Override |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 581 | public boolean addBridge(BridgeDescription bridge) { |
| 582 | TEST_DEVICE_SERVICE.addDevice(new DefaultDevice(new ProviderId("of", "foo"), |
| 583 | DeviceId.deviceId("of:" + bridge.datapathId().get()), |
| 584 | SWITCH, |
| 585 | bridge.name(), |
| 586 | "hwVersion", |
| 587 | "swVersion", |
| 588 | "serialNumber", |
| 589 | new ChassisId(1))); |
| 590 | return true; |
| 591 | } |
| 592 | |
| 593 | @Override |
| 594 | public void deleteBridge(BridgeName bridgeName) { |
| 595 | |
| 596 | } |
| 597 | |
| 598 | @Override |
| 599 | public Collection<BridgeDescription> getBridges() { |
| 600 | return ImmutableSet.of(ROUT_BRIDGE); |
| 601 | } |
| 602 | |
| 603 | @Override |
| 604 | public void addPort(BridgeName bridgeName, String portName) { |
| 605 | |
| 606 | } |
| 607 | |
| 608 | @Override |
| 609 | public void deletePort(BridgeName bridgeName, String portName) { |
| 610 | |
| 611 | } |
| 612 | |
| 613 | @Override |
| 614 | public Collection<PortDescription> getPorts() { |
| 615 | return ImmutableSet.of(PATCH_ROUT); |
| 616 | } |
| 617 | |
| 618 | @Override |
| 619 | public Set<PortNumber> getPortNumbers() { |
| 620 | return null; |
| 621 | } |
| 622 | |
| 623 | @Override |
| 624 | public List<PortNumber> getLocalPorts(Iterable<String> ifaceIds) { |
| 625 | return null; |
| 626 | } |
| 627 | } |
| 628 | |
| 629 | private static class TestInterfaceConfig implements InterfaceConfig { |
| 630 | |
| 631 | @Override |
| 632 | public DriverData data() { |
| 633 | return null; |
| 634 | } |
| 635 | |
| 636 | @Override |
| 637 | public void setData(DriverData data) { |
| 638 | |
| 639 | } |
| 640 | |
| 641 | @Override |
| 642 | public DriverHandler handler() { |
| 643 | return null; |
| 644 | } |
| 645 | |
| 646 | @Override |
| 647 | public void setHandler(DriverHandler handler) { |
| 648 | |
| 649 | } |
| 650 | |
| 651 | @Override |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 652 | public boolean addAccessMode(String intf, VlanId vlanId) { |
| 653 | return false; |
| 654 | } |
| 655 | |
| 656 | @Override |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 657 | public boolean removeAccessMode(String intf) { |
| 658 | return false; |
| 659 | } |
| 660 | |
| 661 | @Override |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 662 | public boolean addTrunkMode(String intf, List<VlanId> vlanIds) { |
| 663 | return false; |
| 664 | } |
| 665 | |
| 666 | @Override |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 667 | public boolean removeTrunkMode(String intf) { |
| 668 | return false; |
| 669 | } |
| 670 | |
| 671 | @Override |
| 672 | public boolean addRateLimit(String intf, short limit) { |
| 673 | return false; |
| 674 | } |
| 675 | |
| 676 | @Override |
| 677 | public boolean removeRateLimit(String intf) { |
| 678 | return false; |
| 679 | } |
| 680 | |
| 681 | @Override |
| 682 | public boolean addTunnelMode(String intf, TunnelDescription tunnelDesc) { |
| 683 | TEST_DEVICE_SERVICE.devMap.values().stream() |
| 684 | .filter(device -> device.type() == SWITCH && |
| 685 | device.manufacturer().equals(INTEGRATION_BRIDGE)) |
| 686 | .forEach(device -> { |
| 687 | TEST_DEVICE_SERVICE.addPort(device, createPort(device, intf)); |
| 688 | }); |
| 689 | return true; |
| 690 | } |
| 691 | |
| 692 | @Override |
| 693 | public boolean removeTunnelMode(String intf) { |
| 694 | return false; |
| 695 | } |
| 696 | |
| 697 | @Override |
| 698 | public boolean addPatchMode(String ifaceName, PatchDescription patchInterface) { |
| 699 | if (ifaceName.equals(PATCH_INTG_BRIDGE)) { |
| 700 | TEST_DEVICE_SERVICE.devMap.values().stream() |
| 701 | .filter(device -> device.type() == SWITCH && |
| 702 | device.manufacturer().equals(INTEGRATION_BRIDGE)) |
| 703 | .forEach(device -> { |
| 704 | TEST_DEVICE_SERVICE.addPort(device, createPort(device, ifaceName)); |
| 705 | }); |
| 706 | } else if (ifaceName.equals(PATCH_ROUT_BRIDGE)) { |
| 707 | TEST_DEVICE_SERVICE.devMap.values().stream() |
| 708 | .filter(device -> device.type() == SWITCH && |
| 709 | device.manufacturer().equals(ROUTER_BRIDGE)) |
| 710 | .forEach(device -> { |
| 711 | TEST_DEVICE_SERVICE.addPort(device, createPort(device, ifaceName)); |
| 712 | }); |
| 713 | } |
| 714 | return true; |
| 715 | } |
| 716 | |
| 717 | @Override |
| 718 | public boolean removePatchMode(String ifaceName) { |
| 719 | return false; |
| 720 | } |
| 721 | |
| 722 | @Override |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 723 | public List<DeviceInterfaceDescription> getInterfaces() { |
| 724 | return null; |
| 725 | } |
| 726 | } |
| 727 | |
Hyunsun Moon | 090d77d | 2017-07-05 17:48:37 +0900 | [diff] [blame] | 728 | private static class TestExtensionTreatment implements ExtensionTreatment { |
| 729 | Ip4Address tunnelDst; |
| 730 | |
| 731 | @Override |
| 732 | public ExtensionTreatmentType type() { |
| 733 | return null; |
| 734 | } |
| 735 | |
| 736 | @Override |
| 737 | public <T> void setPropertyValue(String key, T value) throws ExtensionPropertyException { |
| 738 | tunnelDst = (Ip4Address) value; |
| 739 | } |
| 740 | |
| 741 | @Override |
| 742 | public <T> T getPropertyValue(String key) throws ExtensionPropertyException { |
| 743 | return null; |
| 744 | } |
| 745 | |
| 746 | @Override |
| 747 | public List<String> getProperties() { |
| 748 | return null; |
| 749 | } |
| 750 | |
| 751 | @Override |
| 752 | public byte[] serialize() { |
| 753 | return new byte[0]; |
| 754 | } |
| 755 | |
| 756 | @Override |
| 757 | public void deserialize(byte[] data) { |
| 758 | |
| 759 | } |
| 760 | |
| 761 | @Override |
| 762 | public boolean equals(Object obj) { |
| 763 | TestExtensionTreatment that = (TestExtensionTreatment) obj; |
| 764 | return Objects.equals(tunnelDst, that.tunnelDst); |
| 765 | } |
| 766 | |
| 767 | @Override |
| 768 | public int hashCode() { |
| 769 | return Objects.hash(tunnelDst); |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | private static class TestCoreService extends CoreServiceAdapter { |
| 774 | |
| 775 | @Override |
| 776 | public ApplicationId getAppId(String name) { |
| 777 | return TEST_APP_ID; |
| 778 | } |
| 779 | } |
| 780 | |
| 781 | private static class TestLeadershipService extends LeadershipServiceAdapter { |
| 782 | |
| 783 | @Override |
| 784 | public NodeId getLeader(String path) { |
| 785 | return LOCAL_NODE_ID; |
| 786 | } |
| 787 | } |
| 788 | |
| 789 | private static class TestClusterService extends ClusterServiceAdapter { |
| 790 | |
| 791 | @Override |
| 792 | public ControllerNode getLocalNode() { |
| 793 | return LOCAL_CTRL; |
| 794 | } |
| 795 | } |
| 796 | |
| 797 | private class TestComponentConfigService extends ComponentConfigAdapter { |
| 798 | |
| 799 | } |
| 800 | } |