Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 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.t3.impl; |
| 17 | |
| 18 | import com.google.common.collect.ImmutableList; |
| 19 | import com.google.common.collect.ImmutableSet; |
| 20 | import org.junit.Before; |
| 21 | import org.junit.Test; |
Andrea Campanella | 37d1062 | 2018-01-18 17:11:42 +0100 | [diff] [blame] | 22 | import org.onlab.packet.ChassisId; |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 23 | import org.onlab.packet.EthType; |
| 24 | import org.onlab.packet.IpAddress; |
| 25 | import org.onlab.packet.MacAddress; |
| 26 | import org.onlab.packet.VlanId; |
Andrea Campanella | 7c8e791 | 2018-01-23 12:46:04 +0100 | [diff] [blame] | 27 | import org.onosproject.cluster.NodeId; |
| 28 | import org.onosproject.mastership.MastershipServiceAdapter; |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 29 | import org.onosproject.net.ConnectPoint; |
Andrea Campanella | 37d1062 | 2018-01-18 17:11:42 +0100 | [diff] [blame] | 30 | import org.onosproject.net.DefaultAnnotations; |
| 31 | import org.onosproject.net.DefaultDevice; |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 32 | import org.onosproject.net.DefaultLink; |
Andrea Campanella | 37d1062 | 2018-01-18 17:11:42 +0100 | [diff] [blame] | 33 | import org.onosproject.net.Device; |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 34 | import org.onosproject.net.DeviceId; |
| 35 | import org.onosproject.net.Host; |
| 36 | import org.onosproject.net.Link; |
Andrea Campanella | 7c8e791 | 2018-01-23 12:46:04 +0100 | [diff] [blame] | 37 | import org.onosproject.net.PortNumber; |
Andrea Campanella | 37d1062 | 2018-01-18 17:11:42 +0100 | [diff] [blame] | 38 | import org.onosproject.net.device.DeviceServiceAdapter; |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 39 | import org.onosproject.net.driver.DefaultDriver; |
| 40 | import org.onosproject.net.driver.Driver; |
| 41 | import org.onosproject.net.driver.DriverServiceAdapter; |
| 42 | import org.onosproject.net.flow.FlowEntry; |
| 43 | import org.onosproject.net.flow.FlowRuleServiceAdapter; |
| 44 | import org.onosproject.net.flow.TrafficSelector; |
| 45 | import org.onosproject.net.flow.criteria.Criterion; |
| 46 | import org.onosproject.net.flow.criteria.EthTypeCriterion; |
| 47 | import org.onosproject.net.flow.criteria.VlanIdCriterion; |
| 48 | import org.onosproject.net.group.Group; |
| 49 | import org.onosproject.net.group.GroupServiceAdapter; |
| 50 | import org.onosproject.net.host.HostServiceAdapter; |
| 51 | import org.onosproject.net.link.LinkServiceAdapter; |
| 52 | import org.onosproject.net.provider.ProviderId; |
| 53 | import org.onosproject.t3.api.StaticPacketTrace; |
| 54 | import org.slf4j.Logger; |
| 55 | |
| 56 | import java.util.HashMap; |
| 57 | import java.util.Set; |
| 58 | |
| 59 | import static org.junit.Assert.assertEquals; |
| 60 | import static org.junit.Assert.assertNotNull; |
| 61 | import static org.junit.Assert.assertNull; |
| 62 | import static org.junit.Assert.assertTrue; |
Andrea Campanella | 37d1062 | 2018-01-18 17:11:42 +0100 | [diff] [blame] | 63 | import static org.onosproject.net.Device.Type.SWITCH; |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 64 | import static org.onosproject.t3.impl.T3TestObjects.*; |
| 65 | import static org.slf4j.LoggerFactory.getLogger; |
| 66 | |
| 67 | /** |
| 68 | * Test Class for Troubleshoot Manager. |
| 69 | */ |
| 70 | public class TroubleshootManagerTest { |
| 71 | |
| 72 | private static final Logger log = getLogger(TroubleshootManager.class); |
| 73 | |
| 74 | private TroubleshootManager mngr; |
| 75 | |
| 76 | @Before |
| 77 | public void setUp() throws Exception { |
| 78 | mngr = new TroubleshootManager(); |
| 79 | mngr.flowRuleService = new TestFlowRuleService(); |
| 80 | mngr.hostService = new TestHostService(); |
| 81 | mngr.linkService = new TestLinkService(); |
| 82 | mngr.driverService = new TestDriverService(); |
| 83 | mngr.groupService = new TestGroupService(); |
Andrea Campanella | 37d1062 | 2018-01-18 17:11:42 +0100 | [diff] [blame] | 84 | mngr.deviceService = new TestDeviceService(); |
Andrea Campanella | 7c8e791 | 2018-01-23 12:46:04 +0100 | [diff] [blame] | 85 | mngr.mastershipService = new TestMastershipService(); |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 86 | |
| 87 | assertNotNull("Manager should not be null", mngr); |
| 88 | |
| 89 | assertNotNull("Flow rule Service should not be null", mngr.flowRuleService); |
| 90 | assertNotNull("Host Service should not be null", mngr.hostService); |
| 91 | assertNotNull("Group Service should not be null", mngr.groupService); |
| 92 | assertNotNull("Driver Service should not be null", mngr.driverService); |
| 93 | assertNotNull("Link Service should not be null", mngr.linkService); |
Andrea Campanella | 37d1062 | 2018-01-18 17:11:42 +0100 | [diff] [blame] | 94 | assertNotNull("Device Service should not be null", mngr.deviceService); |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Tests failure on non existent device. |
| 99 | */ |
| 100 | @Test(expected = NullPointerException.class) |
| 101 | public void nonExistentDevice() { |
| 102 | StaticPacketTrace traceFail = mngr.trace(PACKET_OK, ConnectPoint.deviceConnectPoint("nonexistent" + "/1")); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Tests failure on offline device. |
| 107 | */ |
| 108 | @Test |
| 109 | public void offlineDevice() { |
| 110 | StaticPacketTrace traceFail = mngr.trace(PACKET_OK, ConnectPoint.deviceConnectPoint(OFFLINE_DEVICE + "/1")); |
| 111 | assertNotNull("Trace should not be null", traceFail); |
| 112 | assertNull("Trace should have 0 output", traceFail.getGroupOuputs(SINGLE_FLOW_DEVICE)); |
Andrea Campanella | bb9d3fb | 2018-01-22 15:10:30 +0100 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Tests failure on same output. |
| 117 | */ |
| 118 | @Test |
| 119 | public void sameOutput() { |
| 120 | StaticPacketTrace traceFail = mngr.trace(PACKET_OK, SAME_OUTPUT_FLOW_CP); |
| 121 | assertNotNull("Trace should not be null", traceFail); |
| 122 | assertTrue("Trace should be unsuccessful", |
| 123 | traceFail.resultMessage().contains("is same as initial input")); |
Andrea Campanella | 37d1062 | 2018-01-18 17:11:42 +0100 | [diff] [blame] | 124 | log.info("trace {}", traceFail.resultMessage()); |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 125 | } |
| 126 | |
Andrea Campanella | 7c8e791 | 2018-01-23 12:46:04 +0100 | [diff] [blame] | 127 | /** |
| 128 | * Tests ARP to controller. |
| 129 | */ |
| 130 | @Test |
| 131 | public void arpToController() { |
| 132 | StaticPacketTrace traceSuccess = mngr.trace(PACKET_ARP, ARP_FLOW_CP); |
| 133 | assertNotNull("Trace should not be null", traceSuccess); |
| 134 | assertTrue("Trace should be successful", |
| 135 | traceSuccess.resultMessage().contains("Packet goes to the controller")); |
| 136 | assertTrue("Master should be Master1", |
| 137 | traceSuccess.resultMessage().contains(MASTER_1)); |
| 138 | ConnectPoint connectPoint = traceSuccess.getGroupOuputs(ARP_FLOW_DEVICE).get(0).getOutput(); |
| 139 | assertEquals("Packet Should go to CONTROLLER", PortNumber.CONTROLLER, connectPoint.port()); |
| 140 | log.info("trace {}", traceSuccess.resultMessage()); |
| 141 | } |
| 142 | |
Andrea Campanella | bb9d3fb | 2018-01-22 15:10:30 +0100 | [diff] [blame] | 143 | |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 144 | /** |
Andrea Campanella | 2bc55dd | 2018-01-18 16:54:34 +0100 | [diff] [blame] | 145 | * Tests failure on device with no flows. |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 146 | */ |
| 147 | @Test |
| 148 | public void noFlows() { |
| 149 | StaticPacketTrace traceFail = mngr.trace(PACKET_OK, ConnectPoint.deviceConnectPoint("test/1")); |
| 150 | assertNotNull("Trace should not be null", traceFail); |
| 151 | assertNull("Trace should have 0 output", traceFail.getGroupOuputs(SINGLE_FLOW_DEVICE)); |
| 152 | log.info("trace {}", traceFail.resultMessage()); |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Test a single flow rule that has output port in it. |
| 157 | */ |
| 158 | @Test |
| 159 | public void testSingleFlowRule() { |
| 160 | |
Andrea Campanella | e04aac9 | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 161 | testSuccess(PACKET_OK, SINGLE_FLOW_IN_CP, SINGLE_FLOW_DEVICE, SINGLE_FLOW_OUT_CP, 1, 1); |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 162 | |
Andrea Campanella | e04aac9 | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 163 | testFailure(PACKET_FAIL, SINGLE_FLOW_IN_CP, SINGLE_FLOW_DEVICE); |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Tests two flow rule the last one of which has output port in it. |
| 168 | */ |
| 169 | @Test |
| 170 | public void testDualFlowRule() { |
| 171 | |
| 172 | //Test Success |
| 173 | |
Andrea Campanella | 2bc55dd | 2018-01-18 16:54:34 +0100 | [diff] [blame] | 174 | StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, DUAL_FLOW_IN_CP, DUAL_FLOW_DEVICE, |
Andrea Campanella | e04aac9 | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 175 | DUAL_FLOW_OUT_CP, 1, 1); |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 176 | |
| 177 | //Testing Vlan |
| 178 | Criterion criterion = traceSuccess.getGroupOuputs(DUAL_FLOW_DEVICE).get(0). |
| 179 | getFinalPacket().getCriterion(Criterion.Type.VLAN_VID); |
| 180 | assertNotNull("Packet Should have Vlan", criterion); |
| 181 | |
| 182 | VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) criterion; |
| 183 | |
| 184 | assertEquals("Vlan should be 100", VlanId.vlanId((short) 100), vlanIdCriterion.vlanId()); |
| 185 | |
| 186 | //Test Faliure |
Andrea Campanella | e04aac9 | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 187 | testFailure(PACKET_FAIL, DUAL_FLOW_IN_CP, DUAL_FLOW_DEVICE); |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 188 | |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Test a single flow rule that points to a group with output port in it. |
| 193 | */ |
| 194 | @Test |
| 195 | public void flowAndGroup() throws Exception { |
| 196 | |
Andrea Campanella | 2bc55dd | 2018-01-18 16:54:34 +0100 | [diff] [blame] | 197 | StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, GROUP_FLOW_IN_CP, GROUP_FLOW_DEVICE, |
Andrea Campanella | e04aac9 | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 198 | GROUP_FLOW_OUT_CP, 1, 1); |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 199 | |
| 200 | assertTrue("Wrong Output Group", traceSuccess.getGroupOuputs(GROUP_FLOW_DEVICE) |
| 201 | .get(0).getGroups().contains(GROUP)); |
Andrea Campanella | 09ca07a | 2018-01-25 16:44:04 +0100 | [diff] [blame] | 202 | assertEquals("Packet should not have MPLS Label", EthType.EtherType.IPV4.ethType(), |
| 203 | ((EthTypeCriterion) traceSuccess.getGroupOuputs(GROUP_FLOW_DEVICE) |
| 204 | .get(0).getFinalPacket().getCriterion(Criterion.Type.ETH_TYPE)).ethType()); |
| 205 | assertNull("Packet should not have MPLS Label", traceSuccess.getGroupOuputs(GROUP_FLOW_DEVICE) |
| 206 | .get(0).getFinalPacket().getCriterion(Criterion.Type.MPLS_LABEL)); |
| 207 | assertNull("Packet should not have MPLS Label", traceSuccess.getGroupOuputs(GROUP_FLOW_DEVICE) |
| 208 | .get(0).getFinalPacket().getCriterion(Criterion.Type.MPLS_BOS)); |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 209 | |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * Test path through a 3 device topology. |
| 214 | */ |
| 215 | @Test |
| 216 | public void singlePathTopology() throws Exception { |
| 217 | |
| 218 | StaticPacketTrace traceSuccess = testSuccess(PACKET_OK_TOPO, TOPO_FLOW_1_IN_CP, |
Andrea Campanella | e04aac9 | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 219 | TOPO_FLOW_3_DEVICE, TOPO_FLOW_3_OUT_CP, 1, 1); |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 220 | |
| 221 | assertTrue("Incorrect path", |
| 222 | traceSuccess.getCompletePaths().get(0).contains(TOPO_FLOW_2_IN_CP)); |
| 223 | assertTrue("Incorrect path", |
| 224 | traceSuccess.getCompletePaths().get(0).contains(TOPO_FLOW_2_OUT_CP)); |
| 225 | assertTrue("Incorrect path", |
| 226 | traceSuccess.getCompletePaths().get(0).contains(TOPO_FLOW_3_IN_CP)); |
| 227 | |
| 228 | } |
| 229 | |
| 230 | /** |
| 231 | * Test path through a 4 device topology with first device that has groups with multiple output buckets. |
| 232 | */ |
| 233 | @Test |
| 234 | public void testGroupTopo() throws Exception { |
| 235 | |
| 236 | StaticPacketTrace traceSuccess = testSuccess(PACKET_OK_TOPO, TOPO_FLOW_IN_CP, |
Andrea Campanella | e04aac9 | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 237 | TOPO_FLOW_3_DEVICE, TOPO_FLOW_3_OUT_CP, 2, 1); |
| 238 | |
| 239 | log.info("{}", traceSuccess); |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 240 | |
| 241 | assertTrue("Incorrect groups", |
| 242 | traceSuccess.getGroupOuputs(TOPO_GROUP_FLOW_DEVICE).get(0).getGroups().contains(TOPO_GROUP)); |
| 243 | assertTrue("Incorrect bucket", |
| 244 | traceSuccess.getGroupOuputs(TOPO_GROUP_FLOW_DEVICE).get(1).getGroups().contains(TOPO_GROUP)); |
| 245 | } |
| 246 | |
| 247 | /** |
| 248 | * Test HW support in a single device with 2 flow rules to check hit of static HW rules. |
| 249 | */ |
| 250 | @Test |
| 251 | public void hardwareTest() throws Exception { |
| 252 | |
| 253 | StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, HARDWARE_DEVICE_IN_CP, |
Andrea Campanella | e04aac9 | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 254 | HARDWARE_DEVICE, HARDWARE_DEVICE_OUT_CP, 1, 1); |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 255 | |
| 256 | assertEquals("wrong ETH type", EthType.EtherType.IPV4.ethType(), |
| 257 | ((EthTypeCriterion) traceSuccess.getGroupOuputs(HARDWARE_DEVICE).get(0).getFinalPacket() |
| 258 | .getCriterion(Criterion.Type.ETH_TYPE)).ethType()); |
| 259 | |
| 260 | } |
| 261 | |
Andrea Campanella | e04aac9 | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 262 | /** |
| 263 | * Test dual links between 3 topology elements. |
| 264 | */ |
| 265 | @Test |
| 266 | public void dualLinks() throws Exception { |
| 267 | |
| 268 | StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, DUAL_LINK_1_CP_1_IN, |
| 269 | DUAL_LINK_3, DUAL_LINK_3_CP_3_OUT, 4, 1); |
| 270 | |
| 271 | //TODO tests |
| 272 | |
| 273 | } |
| 274 | |
Andrea Campanella | d5bb2ef | 2018-01-31 16:43:23 +0100 | [diff] [blame^] | 275 | /** |
| 276 | * Test proper clear deferred behaviour. |
| 277 | */ |
| 278 | @Test |
| 279 | public void clearDeferred() throws Exception { |
| 280 | |
| 281 | StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, DEFERRED_CP_1_IN, |
| 282 | DEFERRED_1, DEFERRED_CP_2_OUT, 1, 1); |
| 283 | |
| 284 | assertNull("MPLS should have been not applied due to clear deferred", traceSuccess |
| 285 | .getGroupOuputs(DEFERRED_1).get(0).getFinalPacket().getCriterion(Criterion.Type.MPLS_LABEL)); |
| 286 | |
| 287 | } |
| 288 | |
| 289 | |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 290 | private StaticPacketTrace testSuccess(TrafficSelector packet, ConnectPoint in, DeviceId deviceId, ConnectPoint out, |
Andrea Campanella | e04aac9 | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 291 | int paths, int outputs) { |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 292 | StaticPacketTrace traceSuccess = mngr.trace(packet, in); |
| 293 | |
| 294 | log.info("trace {}", traceSuccess); |
| 295 | |
| 296 | log.info("trace {}", traceSuccess.resultMessage()); |
| 297 | |
| 298 | assertNotNull("trace should not be null", traceSuccess); |
Andrea Campanella | e04aac9 | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 299 | assertEquals("Trace should have " + outputs + " output", outputs, |
| 300 | traceSuccess.getGroupOuputs(deviceId).size()); |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 301 | assertEquals("Trace should only have " + paths + "output", paths, traceSuccess.getCompletePaths().size()); |
| 302 | assertTrue("Trace should be successful", |
| 303 | traceSuccess.resultMessage().contains("Reached required destination Host")); |
| 304 | assertEquals("Incorrect Output CP", out, |
| 305 | traceSuccess.getGroupOuputs(deviceId).get(0).getOutput()); |
| 306 | |
| 307 | return traceSuccess; |
| 308 | } |
| 309 | |
Andrea Campanella | e04aac9 | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 310 | private void testFailure(TrafficSelector packet, ConnectPoint in, DeviceId deviceId) { |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 311 | StaticPacketTrace traceFail = mngr.trace(packet, in); |
| 312 | |
| 313 | log.info("trace {}", traceFail.resultMessage()); |
| 314 | |
| 315 | assertNotNull("Trace should not be null", traceFail); |
| 316 | assertNull("Trace should have 0 output", traceFail.getGroupOuputs(deviceId)); |
| 317 | } |
| 318 | |
| 319 | private class TestFlowRuleService extends FlowRuleServiceAdapter { |
| 320 | @Override |
| 321 | public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) { |
| 322 | if (deviceId.equals(SINGLE_FLOW_DEVICE)) { |
| 323 | return ImmutableList.of(SINGLE_FLOW_ENTRY); |
| 324 | } else if (deviceId.equals(DUAL_FLOW_DEVICE)) { |
| 325 | return ImmutableList.of(FIRST_FLOW_ENTRY, SECOND_FLOW_ENTRY); |
| 326 | } else if (deviceId.equals(GROUP_FLOW_DEVICE)) { |
| 327 | return ImmutableList.of(GROUP_FLOW_ENTRY); |
| 328 | } else if (deviceId.equals(TOPO_FLOW_DEVICE) || |
| 329 | deviceId.equals(TOPO_FLOW_2_DEVICE) || |
| 330 | deviceId.equals(TOPO_FLOW_3_DEVICE) || |
| 331 | deviceId.equals(TOPO_FLOW_4_DEVICE)) { |
| 332 | return ImmutableList.of(TOPO_SINGLE_FLOW_ENTRY, TOPO_SECOND_INPUT_FLOW_ENTRY); |
| 333 | } else if (deviceId.equals(TOPO_GROUP_FLOW_DEVICE)) { |
| 334 | return ImmutableList.of(TOPO_GROUP_FLOW_ENTRY); |
Andrea Campanella | 2bc55dd | 2018-01-18 16:54:34 +0100 | [diff] [blame] | 335 | } else if (deviceId.equals(HARDWARE_DEVICE)) { |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 336 | return ImmutableList.of(HARDWARE_ETH_FLOW_ENTRY, HARDWARE_FLOW_ENTRY); |
Andrea Campanella | bb9d3fb | 2018-01-22 15:10:30 +0100 | [diff] [blame] | 337 | } else if (deviceId.equals(SAME_OUTPUT_FLOW_DEVICE)) { |
| 338 | return ImmutableList.of(SAME_OUTPUT_FLOW_ENTRY); |
Andrea Campanella | 7c8e791 | 2018-01-23 12:46:04 +0100 | [diff] [blame] | 339 | } else if (deviceId.equals(ARP_FLOW_DEVICE)) { |
| 340 | return ImmutableList.of(ARP_FLOW_ENTRY); |
Andrea Campanella | e04aac9 | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 341 | } else if (deviceId.equals(DUAL_LINK_1)) { |
| 342 | return ImmutableList.of(DUAL_LINK_1_GROUP_FLOW_ENTRY); |
| 343 | } else if (deviceId.equals(DUAL_LINK_2)) { |
| 344 | return ImmutableList.of(DUAL_LINK_1_GROUP_FLOW_ENTRY, DUAL_LINK_2_GROUP_FLOW_ENTRY); |
| 345 | } else if (deviceId.equals(DUAL_LINK_3)) { |
| 346 | return ImmutableList.of(DUAL_LINK_3_FLOW_ENTRY, DUAL_LINK_3_FLOW_ENTRY_2); |
Andrea Campanella | d5bb2ef | 2018-01-31 16:43:23 +0100 | [diff] [blame^] | 347 | } else if (deviceId.equals(DEFERRED_1)) { |
| 348 | return ImmutableList.of(DEFERRED_FLOW_ENTRY, DEFERRED_CLEAR_FLOW_ENTRY); |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 349 | } |
| 350 | return ImmutableList.of(); |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | private class TestDriverService extends DriverServiceAdapter { |
| 355 | @Override |
| 356 | public Driver getDriver(DeviceId deviceId) { |
Andrea Campanella | 2bc55dd | 2018-01-18 16:54:34 +0100 | [diff] [blame] | 357 | if (deviceId.equals(HARDWARE_DEVICE)) { |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 358 | return new DefaultDriver("ofdpa", ImmutableList.of(), |
| 359 | "test", "test", "test", new HashMap<>(), new HashMap<>()); |
| 360 | } |
| 361 | return new DefaultDriver("NotHWDriver", ImmutableList.of(), |
| 362 | "test", "test", "test", new HashMap<>(), new HashMap<>()); |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | private class TestGroupService extends GroupServiceAdapter { |
| 367 | @Override |
| 368 | public Iterable<Group> getGroups(DeviceId deviceId) { |
| 369 | if (deviceId.equals(GROUP_FLOW_DEVICE)) { |
| 370 | return ImmutableList.of(GROUP); |
| 371 | } else if (deviceId.equals(TOPO_GROUP_FLOW_DEVICE)) { |
| 372 | return ImmutableList.of(TOPO_GROUP); |
Andrea Campanella | e04aac9 | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 373 | } else if (deviceId.equals(DUAL_LINK_1) || deviceId.equals(DUAL_LINK_2)) { |
| 374 | return ImmutableList.of(DUAL_LINK_GROUP); |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 375 | } |
| 376 | return ImmutableList.of(); |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | private class TestHostService extends HostServiceAdapter { |
| 381 | @Override |
| 382 | public Set<Host> getConnectedHosts(ConnectPoint connectPoint) { |
| 383 | if (connectPoint.equals(TOPO_FLOW_3_OUT_CP)) { |
| 384 | return ImmutableSet.of(H2); |
Andrea Campanella | e04aac9 | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 385 | } else if (connectPoint.equals(DUAL_LINK_1_CP_2_OUT) || connectPoint.equals(DUAL_LINK_1_CP_3_OUT) || |
| 386 | connectPoint.equals(DUAL_LINK_2_CP_2_OUT) || connectPoint.equals(DUAL_LINK_2_CP_3_OUT)) { |
| 387 | return ImmutableSet.of(); |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 388 | } |
| 389 | return ImmutableSet.of(H1); |
| 390 | } |
| 391 | |
| 392 | @Override |
| 393 | public Set<Host> getHostsByMac(MacAddress mac) { |
| 394 | if (mac.equals(H1.mac())) { |
| 395 | return ImmutableSet.of(H1); |
| 396 | } else if (mac.equals(H2.mac())) { |
| 397 | return ImmutableSet.of(H2); |
| 398 | } |
| 399 | return ImmutableSet.of(); |
| 400 | } |
| 401 | |
| 402 | @Override |
| 403 | public Set<Host> getHostsByIp(IpAddress ip) { |
| 404 | if ((H1.ipAddresses().contains(ip))) { |
| 405 | return ImmutableSet.of(H1); |
| 406 | } else if ((H2.ipAddresses().contains(ip))) { |
| 407 | return ImmutableSet.of(H2); |
| 408 | } |
| 409 | return ImmutableSet.of(); |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | private class TestLinkService extends LinkServiceAdapter { |
| 414 | @Override |
| 415 | public Set<Link> getEgressLinks(ConnectPoint connectPoint) { |
| 416 | if (connectPoint.equals(TOPO_FLOW_1_OUT_CP) |
| 417 | || connectPoint.equals(TOPO_FLOW_OUT_CP_1)) { |
| 418 | return ImmutableSet.of(DefaultLink.builder() |
| 419 | .providerId(ProviderId.NONE) |
| 420 | .type(Link.Type.DIRECT) |
| 421 | .src(connectPoint) |
| 422 | .dst(TOPO_FLOW_2_IN_CP) |
| 423 | .build()); |
| 424 | } else if (connectPoint.equals(TOPO_FLOW_2_OUT_CP)) { |
| 425 | return ImmutableSet.of(DefaultLink.builder() |
| 426 | .providerId(ProviderId.NONE) |
| 427 | .type(Link.Type.DIRECT) |
| 428 | .src(TOPO_FLOW_2_OUT_CP) |
| 429 | .dst(TOPO_FLOW_3_IN_CP) |
| 430 | .build()); |
| 431 | } else if (connectPoint.equals(TOPO_FLOW_OUT_CP_2)) { |
| 432 | return ImmutableSet.of(DefaultLink.builder() |
| 433 | .providerId(ProviderId.NONE) |
| 434 | .type(Link.Type.DIRECT) |
| 435 | .src(TOPO_FLOW_OUT_CP_2) |
| 436 | .dst(TOPO_FLOW_4_IN_CP) |
| 437 | .build()); |
| 438 | } else if (connectPoint.equals(TOPO_FLOW_4_OUT_CP)) { |
| 439 | return ImmutableSet.of(DefaultLink.builder() |
| 440 | .providerId(ProviderId.NONE) |
| 441 | .type(Link.Type.DIRECT) |
| 442 | .src(TOPO_FLOW_4_OUT_CP) |
| 443 | .dst(TOPO_FLOW_3_IN_2_CP) |
| 444 | .build()); |
Andrea Campanella | e04aac9 | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 445 | } else if (connectPoint.equals(DUAL_LINK_1_CP_2_OUT)) { |
| 446 | return ImmutableSet.of(DefaultLink.builder() |
| 447 | .providerId(ProviderId.NONE) |
| 448 | .type(Link.Type.DIRECT) |
| 449 | .src(DUAL_LINK_1_CP_2_OUT) |
| 450 | .dst(DUAL_LINK_2_CP_1_IN) |
| 451 | .build()); |
| 452 | } else if (connectPoint.equals(DUAL_LINK_1_CP_3_OUT)) { |
| 453 | return ImmutableSet.of(DefaultLink.builder() |
| 454 | .providerId(ProviderId.NONE) |
| 455 | .type(Link.Type.DIRECT) |
| 456 | .src(DUAL_LINK_1_CP_3_OUT) |
| 457 | .dst(DUAL_LINK_2_CP_4_IN) |
| 458 | .build()); |
| 459 | } else if (connectPoint.equals(DUAL_LINK_2_CP_2_OUT)) { |
| 460 | return ImmutableSet.of(DefaultLink.builder() |
| 461 | .providerId(ProviderId.NONE) |
| 462 | .type(Link.Type.DIRECT) |
| 463 | .src(DUAL_LINK_2_CP_2_OUT) |
| 464 | .dst(DUAL_LINK_3_CP_1_IN) |
| 465 | .build()); |
| 466 | } else if (connectPoint.equals(DUAL_LINK_2_CP_3_OUT)) { |
| 467 | return ImmutableSet.of(DefaultLink.builder() |
| 468 | .providerId(ProviderId.NONE) |
| 469 | .type(Link.Type.DIRECT) |
| 470 | .src(DUAL_LINK_2_CP_3_OUT) |
| 471 | .dst(DUAL_LINK_3_CP_2_IN) |
| 472 | .build()); |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 473 | } |
| 474 | return ImmutableSet.of(); |
| 475 | } |
| 476 | } |
Andrea Campanella | 37d1062 | 2018-01-18 17:11:42 +0100 | [diff] [blame] | 477 | |
| 478 | private class TestDeviceService extends DeviceServiceAdapter { |
| 479 | @Override |
| 480 | public Device getDevice(DeviceId deviceId) { |
| 481 | if (deviceId.equals(DeviceId.deviceId("nonexistent"))) { |
| 482 | return null; |
| 483 | } |
| 484 | return new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("test"), SWITCH, |
| 485 | "test", "test", "test", "test", new ChassisId(), |
| 486 | DefaultAnnotations.builder().set("foo", "bar").build()); |
| 487 | } |
| 488 | |
| 489 | @Override |
| 490 | public boolean isAvailable(DeviceId deviceId) { |
| 491 | if (deviceId.equals(OFFLINE_DEVICE)) { |
| 492 | return false; |
| 493 | } |
| 494 | return true; |
| 495 | } |
| 496 | } |
Andrea Campanella | 7c8e791 | 2018-01-23 12:46:04 +0100 | [diff] [blame] | 497 | |
| 498 | private class TestMastershipService extends MastershipServiceAdapter { |
| 499 | @Override |
| 500 | public NodeId getMasterFor(DeviceId deviceId) { |
| 501 | return NodeId.nodeId(MASTER_1); |
| 502 | } |
| 503 | } |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 504 | } |