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