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