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