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