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.*; |
| 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 | 17d4519 | 2018-01-18 17:11:42 +0100 | [diff] [blame] | 84 | mngr.deviceService = new TestDeviceService(); |
Andrea Campanella | 54923d6 | 2018-01-23 12:46:04 +0100 | [diff] [blame] | 85 | mngr.mastershipService = new TestMastershipService(); |
Andrea Campanella | e408440 | 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 | 17d4519 | 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 | 7d3cf65 | 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 | 17d4519 | 2018-01-18 17:11:42 +0100 | [diff] [blame] | 124 | log.info("trace {}", traceFail.resultMessage()); |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 125 | } |
| 126 | |
Andrea Campanella | 54923d6 | 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()); |
Andrea Campanella | e679801 | 2018-02-06 15:46:52 +0100 | [diff] [blame^] | 140 | assertNull("VlanId should be null", traceSuccess.getGroupOuputs(ARP_FLOW_DEVICE).get(0) |
| 141 | .getFinalPacket().getCriterion(Criterion.Type.VLAN_VID)); |
Andrea Campanella | 54923d6 | 2018-01-23 12:46:04 +0100 | [diff] [blame] | 142 | log.info("trace {}", traceSuccess.resultMessage()); |
| 143 | } |
| 144 | |
Andrea Campanella | 7d3cf65 | 2018-01-22 15:10:30 +0100 | [diff] [blame] | 145 | |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 146 | /** |
Andrea Campanella | 4401bd7 | 2018-01-18 16:54:34 +0100 | [diff] [blame] | 147 | * Tests failure on device with no flows. |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 148 | */ |
| 149 | @Test |
| 150 | public void noFlows() { |
| 151 | StaticPacketTrace traceFail = mngr.trace(PACKET_OK, ConnectPoint.deviceConnectPoint("test/1")); |
| 152 | assertNotNull("Trace should not be null", traceFail); |
| 153 | assertNull("Trace should have 0 output", traceFail.getGroupOuputs(SINGLE_FLOW_DEVICE)); |
| 154 | log.info("trace {}", traceFail.resultMessage()); |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * Test a single flow rule that has output port in it. |
| 159 | */ |
| 160 | @Test |
| 161 | public void testSingleFlowRule() { |
| 162 | |
Andrea Campanella | b022b5e | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 163 | 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] | 164 | |
Andrea Campanella | b022b5e | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 165 | testFailure(PACKET_FAIL, SINGLE_FLOW_IN_CP, SINGLE_FLOW_DEVICE); |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Tests two flow rule the last one of which has output port in it. |
| 170 | */ |
| 171 | @Test |
| 172 | public void testDualFlowRule() { |
| 173 | |
| 174 | //Test Success |
| 175 | |
Andrea Campanella | 4401bd7 | 2018-01-18 16:54:34 +0100 | [diff] [blame] | 176 | StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, DUAL_FLOW_IN_CP, DUAL_FLOW_DEVICE, |
Andrea Campanella | b022b5e | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 177 | DUAL_FLOW_OUT_CP, 1, 1); |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 178 | |
| 179 | //Testing Vlan |
| 180 | Criterion criterion = traceSuccess.getGroupOuputs(DUAL_FLOW_DEVICE).get(0). |
| 181 | getFinalPacket().getCriterion(Criterion.Type.VLAN_VID); |
| 182 | assertNotNull("Packet Should have Vlan", criterion); |
| 183 | |
| 184 | VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) criterion; |
| 185 | |
| 186 | assertEquals("Vlan should be 100", VlanId.vlanId((short) 100), vlanIdCriterion.vlanId()); |
| 187 | |
| 188 | //Test Faliure |
Andrea Campanella | b022b5e | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 189 | testFailure(PACKET_FAIL, DUAL_FLOW_IN_CP, DUAL_FLOW_DEVICE); |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 190 | |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * Test a single flow rule that points to a group with output port in it. |
| 195 | */ |
| 196 | @Test |
| 197 | public void flowAndGroup() throws Exception { |
| 198 | |
Andrea Campanella | 4401bd7 | 2018-01-18 16:54:34 +0100 | [diff] [blame] | 199 | StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, GROUP_FLOW_IN_CP, GROUP_FLOW_DEVICE, |
Andrea Campanella | b022b5e | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 200 | GROUP_FLOW_OUT_CP, 1, 1); |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 201 | |
| 202 | assertTrue("Wrong Output Group", traceSuccess.getGroupOuputs(GROUP_FLOW_DEVICE) |
| 203 | .get(0).getGroups().contains(GROUP)); |
Andrea Campanella | 3970e47 | 2018-01-25 16:44:04 +0100 | [diff] [blame] | 204 | assertEquals("Packet should not have MPLS Label", EthType.EtherType.IPV4.ethType(), |
| 205 | ((EthTypeCriterion) traceSuccess.getGroupOuputs(GROUP_FLOW_DEVICE) |
| 206 | .get(0).getFinalPacket().getCriterion(Criterion.Type.ETH_TYPE)).ethType()); |
| 207 | assertNull("Packet should not have MPLS Label", traceSuccess.getGroupOuputs(GROUP_FLOW_DEVICE) |
| 208 | .get(0).getFinalPacket().getCriterion(Criterion.Type.MPLS_LABEL)); |
| 209 | assertNull("Packet should not have MPLS Label", traceSuccess.getGroupOuputs(GROUP_FLOW_DEVICE) |
| 210 | .get(0).getFinalPacket().getCriterion(Criterion.Type.MPLS_BOS)); |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 211 | |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * Test path through a 3 device topology. |
| 216 | */ |
| 217 | @Test |
| 218 | public void singlePathTopology() throws Exception { |
| 219 | |
| 220 | StaticPacketTrace traceSuccess = testSuccess(PACKET_OK_TOPO, TOPO_FLOW_1_IN_CP, |
Andrea Campanella | b022b5e | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 221 | TOPO_FLOW_3_DEVICE, TOPO_FLOW_3_OUT_CP, 1, 1); |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 222 | |
| 223 | assertTrue("Incorrect path", |
| 224 | traceSuccess.getCompletePaths().get(0).contains(TOPO_FLOW_2_IN_CP)); |
| 225 | assertTrue("Incorrect path", |
| 226 | traceSuccess.getCompletePaths().get(0).contains(TOPO_FLOW_2_OUT_CP)); |
| 227 | assertTrue("Incorrect path", |
| 228 | traceSuccess.getCompletePaths().get(0).contains(TOPO_FLOW_3_IN_CP)); |
| 229 | |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Test path through a 4 device topology with first device that has groups with multiple output buckets. |
| 234 | */ |
| 235 | @Test |
| 236 | public void testGroupTopo() throws Exception { |
| 237 | |
| 238 | StaticPacketTrace traceSuccess = testSuccess(PACKET_OK_TOPO, TOPO_FLOW_IN_CP, |
Andrea Campanella | b022b5e | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 239 | TOPO_FLOW_3_DEVICE, TOPO_FLOW_3_OUT_CP, 2, 1); |
| 240 | |
| 241 | log.info("{}", traceSuccess); |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 242 | |
| 243 | assertTrue("Incorrect groups", |
| 244 | traceSuccess.getGroupOuputs(TOPO_GROUP_FLOW_DEVICE).get(0).getGroups().contains(TOPO_GROUP)); |
| 245 | assertTrue("Incorrect bucket", |
| 246 | traceSuccess.getGroupOuputs(TOPO_GROUP_FLOW_DEVICE).get(1).getGroups().contains(TOPO_GROUP)); |
| 247 | } |
| 248 | |
| 249 | /** |
| 250 | * Test HW support in a single device with 2 flow rules to check hit of static HW rules. |
| 251 | */ |
| 252 | @Test |
| 253 | public void hardwareTest() throws Exception { |
| 254 | |
| 255 | StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, HARDWARE_DEVICE_IN_CP, |
Andrea Campanella | b022b5e | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 256 | HARDWARE_DEVICE, HARDWARE_DEVICE_OUT_CP, 1, 1); |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 257 | |
| 258 | assertEquals("wrong ETH type", EthType.EtherType.IPV4.ethType(), |
| 259 | ((EthTypeCriterion) traceSuccess.getGroupOuputs(HARDWARE_DEVICE).get(0).getFinalPacket() |
| 260 | .getCriterion(Criterion.Type.ETH_TYPE)).ethType()); |
| 261 | |
| 262 | } |
| 263 | |
Andrea Campanella | b022b5e | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 264 | /** |
| 265 | * Test dual links between 3 topology elements. |
| 266 | */ |
| 267 | @Test |
| 268 | public void dualLinks() throws Exception { |
| 269 | |
| 270 | StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, DUAL_LINK_1_CP_1_IN, |
| 271 | DUAL_LINK_3, DUAL_LINK_3_CP_3_OUT, 4, 1); |
| 272 | |
| 273 | //TODO tests |
| 274 | |
| 275 | } |
| 276 | |
Andrea Campanella | 8292ba6 | 2018-01-31 16:43:23 +0100 | [diff] [blame] | 277 | /** |
| 278 | * Test proper clear deferred behaviour. |
| 279 | */ |
| 280 | @Test |
| 281 | public void clearDeferred() throws Exception { |
| 282 | |
| 283 | StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, DEFERRED_CP_1_IN, |
| 284 | DEFERRED_1, DEFERRED_CP_2_OUT, 1, 1); |
| 285 | |
| 286 | assertNull("MPLS should have been not applied due to clear deferred", traceSuccess |
| 287 | .getGroupOuputs(DEFERRED_1).get(0).getFinalPacket().getCriterion(Criterion.Type.MPLS_LABEL)); |
| 288 | |
| 289 | } |
| 290 | |
| 291 | |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 292 | private StaticPacketTrace testSuccess(TrafficSelector packet, ConnectPoint in, DeviceId deviceId, ConnectPoint out, |
Andrea Campanella | b022b5e | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 293 | int paths, int outputs) { |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 294 | StaticPacketTrace traceSuccess = mngr.trace(packet, in); |
| 295 | |
| 296 | log.info("trace {}", traceSuccess); |
| 297 | |
| 298 | log.info("trace {}", traceSuccess.resultMessage()); |
| 299 | |
| 300 | assertNotNull("trace should not be null", traceSuccess); |
Andrea Campanella | b022b5e | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 301 | assertEquals("Trace should have " + outputs + " output", outputs, |
| 302 | traceSuccess.getGroupOuputs(deviceId).size()); |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 303 | assertEquals("Trace should only have " + paths + "output", paths, traceSuccess.getCompletePaths().size()); |
| 304 | assertTrue("Trace should be successful", |
| 305 | traceSuccess.resultMessage().contains("Reached required destination Host")); |
| 306 | assertEquals("Incorrect Output CP", out, |
| 307 | traceSuccess.getGroupOuputs(deviceId).get(0).getOutput()); |
| 308 | |
| 309 | return traceSuccess; |
| 310 | } |
| 311 | |
Andrea Campanella | b022b5e | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 312 | private void testFailure(TrafficSelector packet, ConnectPoint in, DeviceId deviceId) { |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 313 | StaticPacketTrace traceFail = mngr.trace(packet, in); |
| 314 | |
| 315 | log.info("trace {}", traceFail.resultMessage()); |
| 316 | |
| 317 | assertNotNull("Trace should not be null", traceFail); |
| 318 | assertNull("Trace should have 0 output", traceFail.getGroupOuputs(deviceId)); |
| 319 | } |
| 320 | |
| 321 | private class TestFlowRuleService extends FlowRuleServiceAdapter { |
| 322 | @Override |
| 323 | public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) { |
| 324 | if (deviceId.equals(SINGLE_FLOW_DEVICE)) { |
| 325 | return ImmutableList.of(SINGLE_FLOW_ENTRY); |
| 326 | } else if (deviceId.equals(DUAL_FLOW_DEVICE)) { |
| 327 | return ImmutableList.of(FIRST_FLOW_ENTRY, SECOND_FLOW_ENTRY); |
| 328 | } else if (deviceId.equals(GROUP_FLOW_DEVICE)) { |
| 329 | return ImmutableList.of(GROUP_FLOW_ENTRY); |
| 330 | } else if (deviceId.equals(TOPO_FLOW_DEVICE) || |
| 331 | deviceId.equals(TOPO_FLOW_2_DEVICE) || |
| 332 | deviceId.equals(TOPO_FLOW_3_DEVICE) || |
| 333 | deviceId.equals(TOPO_FLOW_4_DEVICE)) { |
| 334 | return ImmutableList.of(TOPO_SINGLE_FLOW_ENTRY, TOPO_SECOND_INPUT_FLOW_ENTRY); |
| 335 | } else if (deviceId.equals(TOPO_GROUP_FLOW_DEVICE)) { |
| 336 | return ImmutableList.of(TOPO_GROUP_FLOW_ENTRY); |
Andrea Campanella | 4401bd7 | 2018-01-18 16:54:34 +0100 | [diff] [blame] | 337 | } else if (deviceId.equals(HARDWARE_DEVICE)) { |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 338 | return ImmutableList.of(HARDWARE_ETH_FLOW_ENTRY, HARDWARE_FLOW_ENTRY); |
Andrea Campanella | 7d3cf65 | 2018-01-22 15:10:30 +0100 | [diff] [blame] | 339 | } else if (deviceId.equals(SAME_OUTPUT_FLOW_DEVICE)) { |
| 340 | return ImmutableList.of(SAME_OUTPUT_FLOW_ENTRY); |
Andrea Campanella | 54923d6 | 2018-01-23 12:46:04 +0100 | [diff] [blame] | 341 | } else if (deviceId.equals(ARP_FLOW_DEVICE)) { |
| 342 | return ImmutableList.of(ARP_FLOW_ENTRY); |
Andrea Campanella | b022b5e | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 343 | } else if (deviceId.equals(DUAL_LINK_1)) { |
| 344 | return ImmutableList.of(DUAL_LINK_1_GROUP_FLOW_ENTRY); |
| 345 | } else if (deviceId.equals(DUAL_LINK_2)) { |
| 346 | return ImmutableList.of(DUAL_LINK_1_GROUP_FLOW_ENTRY, DUAL_LINK_2_GROUP_FLOW_ENTRY); |
| 347 | } else if (deviceId.equals(DUAL_LINK_3)) { |
| 348 | 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] | 349 | } else if (deviceId.equals(DEFERRED_1)) { |
| 350 | return ImmutableList.of(DEFERRED_FLOW_ENTRY, DEFERRED_CLEAR_FLOW_ENTRY); |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 351 | } |
| 352 | return ImmutableList.of(); |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | private class TestDriverService extends DriverServiceAdapter { |
| 357 | @Override |
| 358 | public Driver getDriver(DeviceId deviceId) { |
Andrea Campanella | 4401bd7 | 2018-01-18 16:54:34 +0100 | [diff] [blame] | 359 | if (deviceId.equals(HARDWARE_DEVICE)) { |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 360 | return new DefaultDriver("ofdpa", ImmutableList.of(), |
| 361 | "test", "test", "test", new HashMap<>(), new HashMap<>()); |
| 362 | } |
| 363 | return new DefaultDriver("NotHWDriver", ImmutableList.of(), |
| 364 | "test", "test", "test", new HashMap<>(), new HashMap<>()); |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | private class TestGroupService extends GroupServiceAdapter { |
| 369 | @Override |
| 370 | public Iterable<Group> getGroups(DeviceId deviceId) { |
| 371 | if (deviceId.equals(GROUP_FLOW_DEVICE)) { |
| 372 | return ImmutableList.of(GROUP); |
| 373 | } else if (deviceId.equals(TOPO_GROUP_FLOW_DEVICE)) { |
| 374 | return ImmutableList.of(TOPO_GROUP); |
Andrea Campanella | b022b5e | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 375 | } else if (deviceId.equals(DUAL_LINK_1) || deviceId.equals(DUAL_LINK_2)) { |
| 376 | return ImmutableList.of(DUAL_LINK_GROUP); |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 377 | } |
| 378 | return ImmutableList.of(); |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | private class TestHostService extends HostServiceAdapter { |
| 383 | @Override |
| 384 | public Set<Host> getConnectedHosts(ConnectPoint connectPoint) { |
| 385 | if (connectPoint.equals(TOPO_FLOW_3_OUT_CP)) { |
| 386 | return ImmutableSet.of(H2); |
Andrea Campanella | b022b5e | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 387 | } else if (connectPoint.equals(DUAL_LINK_1_CP_2_OUT) || connectPoint.equals(DUAL_LINK_1_CP_3_OUT) || |
| 388 | connectPoint.equals(DUAL_LINK_2_CP_2_OUT) || connectPoint.equals(DUAL_LINK_2_CP_3_OUT)) { |
| 389 | return ImmutableSet.of(); |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 390 | } |
| 391 | return ImmutableSet.of(H1); |
| 392 | } |
| 393 | |
| 394 | @Override |
| 395 | public Set<Host> getHostsByMac(MacAddress mac) { |
| 396 | if (mac.equals(H1.mac())) { |
| 397 | return ImmutableSet.of(H1); |
| 398 | } else if (mac.equals(H2.mac())) { |
| 399 | return ImmutableSet.of(H2); |
| 400 | } |
| 401 | return ImmutableSet.of(); |
| 402 | } |
| 403 | |
| 404 | @Override |
| 405 | public Set<Host> getHostsByIp(IpAddress ip) { |
| 406 | if ((H1.ipAddresses().contains(ip))) { |
| 407 | return ImmutableSet.of(H1); |
| 408 | } else if ((H2.ipAddresses().contains(ip))) { |
| 409 | return ImmutableSet.of(H2); |
| 410 | } |
| 411 | return ImmutableSet.of(); |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | private class TestLinkService extends LinkServiceAdapter { |
| 416 | @Override |
| 417 | public Set<Link> getEgressLinks(ConnectPoint connectPoint) { |
| 418 | if (connectPoint.equals(TOPO_FLOW_1_OUT_CP) |
| 419 | || connectPoint.equals(TOPO_FLOW_OUT_CP_1)) { |
| 420 | return ImmutableSet.of(DefaultLink.builder() |
| 421 | .providerId(ProviderId.NONE) |
| 422 | .type(Link.Type.DIRECT) |
| 423 | .src(connectPoint) |
| 424 | .dst(TOPO_FLOW_2_IN_CP) |
| 425 | .build()); |
| 426 | } else if (connectPoint.equals(TOPO_FLOW_2_OUT_CP)) { |
| 427 | return ImmutableSet.of(DefaultLink.builder() |
| 428 | .providerId(ProviderId.NONE) |
| 429 | .type(Link.Type.DIRECT) |
| 430 | .src(TOPO_FLOW_2_OUT_CP) |
| 431 | .dst(TOPO_FLOW_3_IN_CP) |
| 432 | .build()); |
| 433 | } else if (connectPoint.equals(TOPO_FLOW_OUT_CP_2)) { |
| 434 | return ImmutableSet.of(DefaultLink.builder() |
| 435 | .providerId(ProviderId.NONE) |
| 436 | .type(Link.Type.DIRECT) |
| 437 | .src(TOPO_FLOW_OUT_CP_2) |
| 438 | .dst(TOPO_FLOW_4_IN_CP) |
| 439 | .build()); |
| 440 | } else if (connectPoint.equals(TOPO_FLOW_4_OUT_CP)) { |
| 441 | return ImmutableSet.of(DefaultLink.builder() |
| 442 | .providerId(ProviderId.NONE) |
| 443 | .type(Link.Type.DIRECT) |
| 444 | .src(TOPO_FLOW_4_OUT_CP) |
| 445 | .dst(TOPO_FLOW_3_IN_2_CP) |
| 446 | .build()); |
Andrea Campanella | b022b5e | 2018-01-31 14:59:03 +0100 | [diff] [blame] | 447 | } else if (connectPoint.equals(DUAL_LINK_1_CP_2_OUT)) { |
| 448 | return ImmutableSet.of(DefaultLink.builder() |
| 449 | .providerId(ProviderId.NONE) |
| 450 | .type(Link.Type.DIRECT) |
| 451 | .src(DUAL_LINK_1_CP_2_OUT) |
| 452 | .dst(DUAL_LINK_2_CP_1_IN) |
| 453 | .build()); |
| 454 | } else if (connectPoint.equals(DUAL_LINK_1_CP_3_OUT)) { |
| 455 | return ImmutableSet.of(DefaultLink.builder() |
| 456 | .providerId(ProviderId.NONE) |
| 457 | .type(Link.Type.DIRECT) |
| 458 | .src(DUAL_LINK_1_CP_3_OUT) |
| 459 | .dst(DUAL_LINK_2_CP_4_IN) |
| 460 | .build()); |
| 461 | } else if (connectPoint.equals(DUAL_LINK_2_CP_2_OUT)) { |
| 462 | return ImmutableSet.of(DefaultLink.builder() |
| 463 | .providerId(ProviderId.NONE) |
| 464 | .type(Link.Type.DIRECT) |
| 465 | .src(DUAL_LINK_2_CP_2_OUT) |
| 466 | .dst(DUAL_LINK_3_CP_1_IN) |
| 467 | .build()); |
| 468 | } else if (connectPoint.equals(DUAL_LINK_2_CP_3_OUT)) { |
| 469 | return ImmutableSet.of(DefaultLink.builder() |
| 470 | .providerId(ProviderId.NONE) |
| 471 | .type(Link.Type.DIRECT) |
| 472 | .src(DUAL_LINK_2_CP_3_OUT) |
| 473 | .dst(DUAL_LINK_3_CP_2_IN) |
| 474 | .build()); |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 475 | } |
| 476 | return ImmutableSet.of(); |
| 477 | } |
| 478 | } |
Andrea Campanella | 17d4519 | 2018-01-18 17:11:42 +0100 | [diff] [blame] | 479 | |
| 480 | private class TestDeviceService extends DeviceServiceAdapter { |
| 481 | @Override |
| 482 | public Device getDevice(DeviceId deviceId) { |
| 483 | if (deviceId.equals(DeviceId.deviceId("nonexistent"))) { |
| 484 | return null; |
| 485 | } |
| 486 | return new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("test"), SWITCH, |
| 487 | "test", "test", "test", "test", new ChassisId(), |
| 488 | DefaultAnnotations.builder().set("foo", "bar").build()); |
| 489 | } |
| 490 | |
| 491 | @Override |
| 492 | public boolean isAvailable(DeviceId deviceId) { |
| 493 | if (deviceId.equals(OFFLINE_DEVICE)) { |
| 494 | return false; |
| 495 | } |
| 496 | return true; |
| 497 | } |
| 498 | } |
Andrea Campanella | 54923d6 | 2018-01-23 12:46:04 +0100 | [diff] [blame] | 499 | |
| 500 | private class TestMastershipService extends MastershipServiceAdapter { |
| 501 | @Override |
| 502 | public NodeId getMasterFor(DeviceId deviceId) { |
| 503 | return NodeId.nodeId(MASTER_1); |
| 504 | } |
| 505 | } |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 506 | } |