blob: 6a80c12552128ec68938e3b4df026706ad1b67ad [file] [log] [blame]
Andrea Campanella01e886e2017-12-15 15:27:31 +01001/*
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 */
16package org.onosproject.t3.impl;
17
18import com.google.common.collect.ImmutableList;
19import com.google.common.collect.ImmutableSet;
20import org.junit.Before;
21import org.junit.Test;
Andrea Campanella37d10622018-01-18 17:11:42 +010022import org.onlab.packet.ChassisId;
Andrea Campanella01e886e2017-12-15 15:27:31 +010023import org.onlab.packet.EthType;
24import org.onlab.packet.IpAddress;
25import org.onlab.packet.MacAddress;
26import org.onlab.packet.VlanId;
Andrea Campanella7c8e7912018-01-23 12:46:04 +010027import org.onosproject.cluster.NodeId;
28import org.onosproject.mastership.MastershipServiceAdapter;
Andrea Campanella01e886e2017-12-15 15:27:31 +010029import org.onosproject.net.ConnectPoint;
Andrea Campanella37d10622018-01-18 17:11:42 +010030import org.onosproject.net.DefaultAnnotations;
31import org.onosproject.net.DefaultDevice;
Andrea Campanella01e886e2017-12-15 15:27:31 +010032import org.onosproject.net.DefaultLink;
Andrea Campanella04924b92018-01-17 16:34:51 +010033import org.onosproject.net.DefaultPort;
Andrea Campanella37d10622018-01-18 17:11:42 +010034import org.onosproject.net.Device;
Andrea Campanella01e886e2017-12-15 15:27:31 +010035import org.onosproject.net.DeviceId;
36import org.onosproject.net.Host;
37import org.onosproject.net.Link;
Andrea Campanella7c8e7912018-01-23 12:46:04 +010038import org.onosproject.net.PortNumber;
Andrea Campanella04924b92018-01-17 16:34:51 +010039import org.onosproject.net.Port;
Andrea Campanella37d10622018-01-18 17:11:42 +010040import org.onosproject.net.device.DeviceServiceAdapter;
Andrea Campanella01e886e2017-12-15 15:27:31 +010041import org.onosproject.net.driver.DefaultDriver;
42import org.onosproject.net.driver.Driver;
43import org.onosproject.net.driver.DriverServiceAdapter;
Andrea Campanella04924b92018-01-17 16:34:51 +010044import org.onosproject.net.edge.EdgePortServiceAdapter;
Andrea Campanella01e886e2017-12-15 15:27:31 +010045import org.onosproject.net.flow.FlowEntry;
46import org.onosproject.net.flow.FlowRuleServiceAdapter;
47import org.onosproject.net.flow.TrafficSelector;
48import org.onosproject.net.flow.criteria.Criterion;
49import org.onosproject.net.flow.criteria.EthTypeCriterion;
50import org.onosproject.net.flow.criteria.VlanIdCriterion;
51import org.onosproject.net.group.Group;
52import org.onosproject.net.group.GroupServiceAdapter;
53import org.onosproject.net.host.HostServiceAdapter;
54import org.onosproject.net.link.LinkServiceAdapter;
55import org.onosproject.net.provider.ProviderId;
56import org.onosproject.t3.api.StaticPacketTrace;
57import org.slf4j.Logger;
58
59import java.util.HashMap;
60import java.util.Set;
61
62import static org.junit.Assert.assertEquals;
63import static org.junit.Assert.assertNotNull;
64import static org.junit.Assert.assertNull;
65import static org.junit.Assert.assertTrue;
Andrea Campanella37d10622018-01-18 17:11:42 +010066import static org.onosproject.net.Device.Type.SWITCH;
Andrea Campanella01e886e2017-12-15 15:27:31 +010067import static org.onosproject.t3.impl.T3TestObjects.*;
Andrea Campanella6f2d6742018-02-07 12:00:12 +010068import static org.onosproject.t3.impl.TroubleshootManager.PACKET_TO_CONTROLLER;
Andrea Campanella01e886e2017-12-15 15:27:31 +010069import static org.slf4j.LoggerFactory.getLogger;
70
71/**
72 * Test Class for Troubleshoot Manager.
73 */
74public class TroubleshootManagerTest {
75
76 private static final Logger log = getLogger(TroubleshootManager.class);
77
78 private TroubleshootManager mngr;
79
80 @Before
81 public void setUp() throws Exception {
82 mngr = new TroubleshootManager();
83 mngr.flowRuleService = new TestFlowRuleService();
84 mngr.hostService = new TestHostService();
85 mngr.linkService = new TestLinkService();
86 mngr.driverService = new TestDriverService();
87 mngr.groupService = new TestGroupService();
Andrea Campanella37d10622018-01-18 17:11:42 +010088 mngr.deviceService = new TestDeviceService();
Andrea Campanella7c8e7912018-01-23 12:46:04 +010089 mngr.mastershipService = new TestMastershipService();
Andrea Campanella04924b92018-01-17 16:34:51 +010090 mngr.edgePortService = new TestEdgePortService();
Andrea Campanella01e886e2017-12-15 15:27:31 +010091
92 assertNotNull("Manager should not be null", mngr);
93
94 assertNotNull("Flow rule Service should not be null", mngr.flowRuleService);
95 assertNotNull("Host Service should not be null", mngr.hostService);
96 assertNotNull("Group Service should not be null", mngr.groupService);
97 assertNotNull("Driver Service should not be null", mngr.driverService);
98 assertNotNull("Link Service should not be null", mngr.linkService);
Andrea Campanella37d10622018-01-18 17:11:42 +010099 assertNotNull("Device Service should not be null", mngr.deviceService);
100 }
101
102 /**
103 * Tests failure on non existent device.
104 */
105 @Test(expected = NullPointerException.class)
106 public void nonExistentDevice() {
107 StaticPacketTrace traceFail = mngr.trace(PACKET_OK, ConnectPoint.deviceConnectPoint("nonexistent" + "/1"));
108 }
109
110 /**
111 * Tests failure on offline device.
112 */
113 @Test
114 public void offlineDevice() {
115 StaticPacketTrace traceFail = mngr.trace(PACKET_OK, ConnectPoint.deviceConnectPoint(OFFLINE_DEVICE + "/1"));
116 assertNotNull("Trace should not be null", traceFail);
117 assertNull("Trace should have 0 output", traceFail.getGroupOuputs(SINGLE_FLOW_DEVICE));
Andrea Campanellabb9d3fb2018-01-22 15:10:30 +0100118 }
119
120 /**
121 * Tests failure on same output.
122 */
123 @Test
124 public void sameOutput() {
125 StaticPacketTrace traceFail = mngr.trace(PACKET_OK, SAME_OUTPUT_FLOW_CP);
126 assertNotNull("Trace should not be null", traceFail);
127 assertTrue("Trace should be unsuccessful",
128 traceFail.resultMessage().contains("is same as initial input"));
Andrea Campanella37d10622018-01-18 17:11:42 +0100129 log.info("trace {}", traceFail.resultMessage());
Andrea Campanella01e886e2017-12-15 15:27:31 +0100130 }
131
Andrea Campanella7c8e7912018-01-23 12:46:04 +0100132 /**
133 * Tests ARP to controller.
134 */
135 @Test
136 public void arpToController() {
137 StaticPacketTrace traceSuccess = mngr.trace(PACKET_ARP, ARP_FLOW_CP);
138 assertNotNull("Trace should not be null", traceSuccess);
139 assertTrue("Trace should be successful",
Andrea Campanella6f2d6742018-02-07 12:00:12 +0100140 traceSuccess.resultMessage().contains(PACKET_TO_CONTROLLER));
Andrea Campanella7c8e7912018-01-23 12:46:04 +0100141 assertTrue("Master should be Master1",
142 traceSuccess.resultMessage().contains(MASTER_1));
143 ConnectPoint connectPoint = traceSuccess.getGroupOuputs(ARP_FLOW_DEVICE).get(0).getOutput();
144 assertEquals("Packet Should go to CONTROLLER", PortNumber.CONTROLLER, connectPoint.port());
Andrea Campanella58b3b522018-02-06 15:46:52 +0100145 assertNull("VlanId should be null", traceSuccess.getGroupOuputs(ARP_FLOW_DEVICE).get(0)
146 .getFinalPacket().getCriterion(Criterion.Type.VLAN_VID));
Andrea Campanella7c8e7912018-01-23 12:46:04 +0100147 log.info("trace {}", traceSuccess.resultMessage());
148 }
149
Andrea Campanellabb9d3fb2018-01-22 15:10:30 +0100150
Andrea Campanella01e886e2017-12-15 15:27:31 +0100151 /**
Andrea Campanella2bc55dd2018-01-18 16:54:34 +0100152 * Tests failure on device with no flows.
Andrea Campanella01e886e2017-12-15 15:27:31 +0100153 */
154 @Test
155 public void noFlows() {
156 StaticPacketTrace traceFail = mngr.trace(PACKET_OK, ConnectPoint.deviceConnectPoint("test/1"));
157 assertNotNull("Trace should not be null", traceFail);
158 assertNull("Trace should have 0 output", traceFail.getGroupOuputs(SINGLE_FLOW_DEVICE));
159 log.info("trace {}", traceFail.resultMessage());
160 }
161
162 /**
163 * Test a single flow rule that has output port in it.
164 */
165 @Test
166 public void testSingleFlowRule() {
167
Andrea Campanellae04aac92018-01-31 14:59:03 +0100168 testSuccess(PACKET_OK, SINGLE_FLOW_IN_CP, SINGLE_FLOW_DEVICE, SINGLE_FLOW_OUT_CP, 1, 1);
Andrea Campanella01e886e2017-12-15 15:27:31 +0100169
Andrea Campanellae04aac92018-01-31 14:59:03 +0100170 testFailure(PACKET_FAIL, SINGLE_FLOW_IN_CP, SINGLE_FLOW_DEVICE);
Andrea Campanella01e886e2017-12-15 15:27:31 +0100171 }
172
173 /**
174 * Tests two flow rule the last one of which has output port in it.
175 */
176 @Test
177 public void testDualFlowRule() {
178
179 //Test Success
180
Andrea Campanella2bc55dd2018-01-18 16:54:34 +0100181 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, DUAL_FLOW_IN_CP, DUAL_FLOW_DEVICE,
Andrea Campanellae04aac92018-01-31 14:59:03 +0100182 DUAL_FLOW_OUT_CP, 1, 1);
Andrea Campanella01e886e2017-12-15 15:27:31 +0100183
184 //Testing Vlan
185 Criterion criterion = traceSuccess.getGroupOuputs(DUAL_FLOW_DEVICE).get(0).
186 getFinalPacket().getCriterion(Criterion.Type.VLAN_VID);
187 assertNotNull("Packet Should have Vlan", criterion);
188
189 VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) criterion;
190
191 assertEquals("Vlan should be 100", VlanId.vlanId((short) 100), vlanIdCriterion.vlanId());
192
193 //Test Faliure
Andrea Campanellae04aac92018-01-31 14:59:03 +0100194 testFailure(PACKET_FAIL, DUAL_FLOW_IN_CP, DUAL_FLOW_DEVICE);
Andrea Campanella01e886e2017-12-15 15:27:31 +0100195
196 }
197
198 /**
199 * Test a single flow rule that points to a group with output port in it.
200 */
201 @Test
202 public void flowAndGroup() throws Exception {
203
Andrea Campanella2bc55dd2018-01-18 16:54:34 +0100204 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, GROUP_FLOW_IN_CP, GROUP_FLOW_DEVICE,
Andrea Campanellae04aac92018-01-31 14:59:03 +0100205 GROUP_FLOW_OUT_CP, 1, 1);
Andrea Campanella01e886e2017-12-15 15:27:31 +0100206
207 assertTrue("Wrong Output Group", traceSuccess.getGroupOuputs(GROUP_FLOW_DEVICE)
208 .get(0).getGroups().contains(GROUP));
Andrea Campanella09ca07a2018-01-25 16:44:04 +0100209 assertEquals("Packet should not have MPLS Label", EthType.EtherType.IPV4.ethType(),
210 ((EthTypeCriterion) traceSuccess.getGroupOuputs(GROUP_FLOW_DEVICE)
211 .get(0).getFinalPacket().getCriterion(Criterion.Type.ETH_TYPE)).ethType());
212 assertNull("Packet should not have MPLS Label", traceSuccess.getGroupOuputs(GROUP_FLOW_DEVICE)
213 .get(0).getFinalPacket().getCriterion(Criterion.Type.MPLS_LABEL));
214 assertNull("Packet should not have MPLS Label", traceSuccess.getGroupOuputs(GROUP_FLOW_DEVICE)
215 .get(0).getFinalPacket().getCriterion(Criterion.Type.MPLS_BOS));
Andrea Campanella01e886e2017-12-15 15:27:31 +0100216
217 }
218
219 /**
220 * Test path through a 3 device topology.
221 */
222 @Test
223 public void singlePathTopology() throws Exception {
224
225 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK_TOPO, TOPO_FLOW_1_IN_CP,
Andrea Campanellae04aac92018-01-31 14:59:03 +0100226 TOPO_FLOW_3_DEVICE, TOPO_FLOW_3_OUT_CP, 1, 1);
Andrea Campanella01e886e2017-12-15 15:27:31 +0100227
228 assertTrue("Incorrect path",
229 traceSuccess.getCompletePaths().get(0).contains(TOPO_FLOW_2_IN_CP));
230 assertTrue("Incorrect path",
231 traceSuccess.getCompletePaths().get(0).contains(TOPO_FLOW_2_OUT_CP));
232 assertTrue("Incorrect path",
233 traceSuccess.getCompletePaths().get(0).contains(TOPO_FLOW_3_IN_CP));
234
235 }
236
237 /**
238 * Test path through a 4 device topology with first device that has groups with multiple output buckets.
239 */
240 @Test
241 public void testGroupTopo() throws Exception {
242
243 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK_TOPO, TOPO_FLOW_IN_CP,
Andrea Campanellae04aac92018-01-31 14:59:03 +0100244 TOPO_FLOW_3_DEVICE, TOPO_FLOW_3_OUT_CP, 2, 1);
245
246 log.info("{}", traceSuccess);
Andrea Campanella01e886e2017-12-15 15:27:31 +0100247
248 assertTrue("Incorrect groups",
249 traceSuccess.getGroupOuputs(TOPO_GROUP_FLOW_DEVICE).get(0).getGroups().contains(TOPO_GROUP));
250 assertTrue("Incorrect bucket",
251 traceSuccess.getGroupOuputs(TOPO_GROUP_FLOW_DEVICE).get(1).getGroups().contains(TOPO_GROUP));
252 }
253
254 /**
255 * Test HW support in a single device with 2 flow rules to check hit of static HW rules.
256 */
257 @Test
258 public void hardwareTest() throws Exception {
259
260 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, HARDWARE_DEVICE_IN_CP,
Andrea Campanellae04aac92018-01-31 14:59:03 +0100261 HARDWARE_DEVICE, HARDWARE_DEVICE_OUT_CP, 1, 1);
Andrea Campanella01e886e2017-12-15 15:27:31 +0100262
263 assertEquals("wrong ETH type", EthType.EtherType.IPV4.ethType(),
264 ((EthTypeCriterion) traceSuccess.getGroupOuputs(HARDWARE_DEVICE).get(0).getFinalPacket()
265 .getCriterion(Criterion.Type.ETH_TYPE)).ethType());
266
267 }
268
Andrea Campanellae04aac92018-01-31 14:59:03 +0100269 /**
Andrea Campanella97f9d4c2018-02-06 18:58:40 +0100270 * Test that HW has two rules on table 10 for untagged packets.
271 */
272 @Test
273 public void hardwareTable10Test() throws Exception {
274
275 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, HARDWARE_DEVICE_10_IN_CP,
276 HARDWARE_DEVICE_10, HARDWARE_DEVICE_10_OUT_CP, 1, 1);
277
278 assertTrue("Second flow rule is absent", traceSuccess.getFlowsForDevice(HARDWARE_DEVICE_10)
279 .contains(HARDWARE_10_SECOND_FLOW_ENTRY));
280
281 }
282
283 /**
Andrea Campanellae04aac92018-01-31 14:59:03 +0100284 * Test dual links between 3 topology elements.
285 */
286 @Test
287 public void dualLinks() throws Exception {
288
289 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, DUAL_LINK_1_CP_1_IN,
290 DUAL_LINK_3, DUAL_LINK_3_CP_3_OUT, 4, 1);
291
292 //TODO tests
293
294 }
295
Andrea Campanellad5bb2ef2018-01-31 16:43:23 +0100296 /**
297 * Test proper clear deferred behaviour.
298 */
299 @Test
300 public void clearDeferred() throws Exception {
301
302 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, DEFERRED_CP_1_IN,
303 DEFERRED_1, DEFERRED_CP_2_OUT, 1, 1);
304
305 assertNull("MPLS should have been not applied due to clear deferred", traceSuccess
306 .getGroupOuputs(DEFERRED_1).get(0).getFinalPacket().getCriterion(Criterion.Type.MPLS_LABEL));
307
308 }
309
310
Andrea Campanella6f2d6742018-02-07 12:00:12 +0100311 /**
312 * Test LLDP output to controller.
313 */
314 @Test
315 public void lldpToController() {
316 StaticPacketTrace traceSuccess = mngr.trace(PACKET_LLDP, LLDP_FLOW_CP);
317 assertNotNull("Trace should not be null", traceSuccess);
318 assertTrue("Trace should be successful",
319 traceSuccess.resultMessage().contains("Packet goes to the controller"));
320 assertTrue("Master should be Master1",
321 traceSuccess.resultMessage().contains(MASTER_1));
322 ConnectPoint connectPoint = traceSuccess.getGroupOuputs(LLDP_FLOW_DEVICE).get(0).getOutput();
323 assertEquals("Packet Should go to CONTROLLER", PortNumber.CONTROLLER, connectPoint.port());
324 log.info("trace {}", traceSuccess.resultMessage());
325 }
326
Andrea Campanella04924b92018-01-17 16:34:51 +0100327 /**
328 * Test multicast in single device.
329 */
330 @Test
331 public void multicastTest() throws Exception {
332
333 StaticPacketTrace traceSuccess = mngr.trace(PACKET_OK_MULTICAST, MULTICAST_IN_CP);
334
335 log.info("trace {}", traceSuccess);
336
337 log.info("trace {}", traceSuccess.resultMessage());
338
339 assertNotNull("trace should not be null", traceSuccess);
340 assertEquals("Trace should have " + 2 + " output", 2,
341 traceSuccess.getGroupOuputs(MULTICAST_GROUP_FLOW_DEVICE).size());
342 assertEquals("Trace should only have " + 2 + "output", 2,
343 traceSuccess.getCompletePaths().size());
344 assertTrue("Trace should be successful",
345 traceSuccess.resultMessage().contains("reached output"));
346 assertEquals("Incorrect Output CP", MULTICAST_OUT_CP_2,
347 traceSuccess.getGroupOuputs(MULTICAST_GROUP_FLOW_DEVICE).get(0).getOutput());
348 assertEquals("Incorrect Output CP", MULTICAST_OUT_CP,
349 traceSuccess.getGroupOuputs(MULTICAST_GROUP_FLOW_DEVICE).get(1).getOutput());
350
351 }
352
Andrea Campanella01e886e2017-12-15 15:27:31 +0100353 private StaticPacketTrace testSuccess(TrafficSelector packet, ConnectPoint in, DeviceId deviceId, ConnectPoint out,
Andrea Campanellae04aac92018-01-31 14:59:03 +0100354 int paths, int outputs) {
Andrea Campanella01e886e2017-12-15 15:27:31 +0100355 StaticPacketTrace traceSuccess = mngr.trace(packet, in);
356
357 log.info("trace {}", traceSuccess);
358
359 log.info("trace {}", traceSuccess.resultMessage());
360
361 assertNotNull("trace should not be null", traceSuccess);
Andrea Campanellae04aac92018-01-31 14:59:03 +0100362 assertEquals("Trace should have " + outputs + " output", outputs,
363 traceSuccess.getGroupOuputs(deviceId).size());
Andrea Campanella01e886e2017-12-15 15:27:31 +0100364 assertEquals("Trace should only have " + paths + "output", paths, traceSuccess.getCompletePaths().size());
365 assertTrue("Trace should be successful",
366 traceSuccess.resultMessage().contains("Reached required destination Host"));
367 assertEquals("Incorrect Output CP", out,
368 traceSuccess.getGroupOuputs(deviceId).get(0).getOutput());
369
370 return traceSuccess;
371 }
372
Andrea Campanellae04aac92018-01-31 14:59:03 +0100373 private void testFailure(TrafficSelector packet, ConnectPoint in, DeviceId deviceId) {
Andrea Campanella01e886e2017-12-15 15:27:31 +0100374 StaticPacketTrace traceFail = mngr.trace(packet, in);
375
376 log.info("trace {}", traceFail.resultMessage());
377
378 assertNotNull("Trace should not be null", traceFail);
379 assertNull("Trace should have 0 output", traceFail.getGroupOuputs(deviceId));
380 }
381
382 private class TestFlowRuleService extends FlowRuleServiceAdapter {
383 @Override
384 public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) {
385 if (deviceId.equals(SINGLE_FLOW_DEVICE)) {
386 return ImmutableList.of(SINGLE_FLOW_ENTRY);
387 } else if (deviceId.equals(DUAL_FLOW_DEVICE)) {
388 return ImmutableList.of(FIRST_FLOW_ENTRY, SECOND_FLOW_ENTRY);
389 } else if (deviceId.equals(GROUP_FLOW_DEVICE)) {
390 return ImmutableList.of(GROUP_FLOW_ENTRY);
391 } else if (deviceId.equals(TOPO_FLOW_DEVICE) ||
392 deviceId.equals(TOPO_FLOW_2_DEVICE) ||
393 deviceId.equals(TOPO_FLOW_3_DEVICE) ||
394 deviceId.equals(TOPO_FLOW_4_DEVICE)) {
395 return ImmutableList.of(TOPO_SINGLE_FLOW_ENTRY, TOPO_SECOND_INPUT_FLOW_ENTRY);
396 } else if (deviceId.equals(TOPO_GROUP_FLOW_DEVICE)) {
397 return ImmutableList.of(TOPO_GROUP_FLOW_ENTRY);
Andrea Campanella2bc55dd2018-01-18 16:54:34 +0100398 } else if (deviceId.equals(HARDWARE_DEVICE)) {
Andrea Campanella01e886e2017-12-15 15:27:31 +0100399 return ImmutableList.of(HARDWARE_ETH_FLOW_ENTRY, HARDWARE_FLOW_ENTRY);
Andrea Campanellabb9d3fb2018-01-22 15:10:30 +0100400 } else if (deviceId.equals(SAME_OUTPUT_FLOW_DEVICE)) {
401 return ImmutableList.of(SAME_OUTPUT_FLOW_ENTRY);
Andrea Campanella7c8e7912018-01-23 12:46:04 +0100402 } else if (deviceId.equals(ARP_FLOW_DEVICE)) {
403 return ImmutableList.of(ARP_FLOW_ENTRY);
Andrea Campanellae04aac92018-01-31 14:59:03 +0100404 } else if (deviceId.equals(DUAL_LINK_1)) {
405 return ImmutableList.of(DUAL_LINK_1_GROUP_FLOW_ENTRY);
406 } else if (deviceId.equals(DUAL_LINK_2)) {
407 return ImmutableList.of(DUAL_LINK_1_GROUP_FLOW_ENTRY, DUAL_LINK_2_GROUP_FLOW_ENTRY);
408 } else if (deviceId.equals(DUAL_LINK_3)) {
409 return ImmutableList.of(DUAL_LINK_3_FLOW_ENTRY, DUAL_LINK_3_FLOW_ENTRY_2);
Andrea Campanellad5bb2ef2018-01-31 16:43:23 +0100410 } else if (deviceId.equals(DEFERRED_1)) {
411 return ImmutableList.of(DEFERRED_FLOW_ENTRY, DEFERRED_CLEAR_FLOW_ENTRY);
Andrea Campanella97f9d4c2018-02-06 18:58:40 +0100412 } else if (deviceId.equals(HARDWARE_DEVICE_10)) {
413 return ImmutableList.of(HARDWARE_10_FLOW_ENTRY, HARDWARE_10_SECOND_FLOW_ENTRY,
414 HARDWARE_10_OUTPUT_FLOW_ENTRY);
Andrea Campanella6f2d6742018-02-07 12:00:12 +0100415 } else if (deviceId.equals(LLDP_FLOW_DEVICE)) {
416 return ImmutableList.of(LLDP_FLOW_ENTRY);
Andrea Campanella04924b92018-01-17 16:34:51 +0100417 } else if (deviceId.equals(MULTICAST_GROUP_FLOW_DEVICE)) {
418 return ImmutableList.of(MULTICAST_GROUP_FLOW_ENTRY);
Andrea Campanella01e886e2017-12-15 15:27:31 +0100419 }
420 return ImmutableList.of();
421 }
422 }
423
424 private class TestDriverService extends DriverServiceAdapter {
425 @Override
426 public Driver getDriver(DeviceId deviceId) {
Andrea Campanella97f9d4c2018-02-06 18:58:40 +0100427 if (deviceId.equals(HARDWARE_DEVICE) || deviceId.equals(HARDWARE_DEVICE_10)) {
Andrea Campanella01e886e2017-12-15 15:27:31 +0100428 return new DefaultDriver("ofdpa", ImmutableList.of(),
429 "test", "test", "test", new HashMap<>(), new HashMap<>());
430 }
431 return new DefaultDriver("NotHWDriver", ImmutableList.of(),
432 "test", "test", "test", new HashMap<>(), new HashMap<>());
433 }
434 }
435
436 private class TestGroupService extends GroupServiceAdapter {
437 @Override
438 public Iterable<Group> getGroups(DeviceId deviceId) {
439 if (deviceId.equals(GROUP_FLOW_DEVICE)) {
440 return ImmutableList.of(GROUP);
441 } else if (deviceId.equals(TOPO_GROUP_FLOW_DEVICE)) {
442 return ImmutableList.of(TOPO_GROUP);
Andrea Campanellae04aac92018-01-31 14:59:03 +0100443 } else if (deviceId.equals(DUAL_LINK_1) || deviceId.equals(DUAL_LINK_2)) {
444 return ImmutableList.of(DUAL_LINK_GROUP);
Andrea Campanella04924b92018-01-17 16:34:51 +0100445 } else if (deviceId.equals(MULTICAST_GROUP_FLOW_DEVICE)) {
446 return ImmutableList.of(MULTICAST_GROUP);
Andrea Campanella01e886e2017-12-15 15:27:31 +0100447 }
448 return ImmutableList.of();
449 }
450 }
451
452 private class TestHostService extends HostServiceAdapter {
453 @Override
454 public Set<Host> getConnectedHosts(ConnectPoint connectPoint) {
455 if (connectPoint.equals(TOPO_FLOW_3_OUT_CP)) {
456 return ImmutableSet.of(H2);
Andrea Campanellae04aac92018-01-31 14:59:03 +0100457 } else if (connectPoint.equals(DUAL_LINK_1_CP_2_OUT) || connectPoint.equals(DUAL_LINK_1_CP_3_OUT) ||
458 connectPoint.equals(DUAL_LINK_2_CP_2_OUT) || connectPoint.equals(DUAL_LINK_2_CP_3_OUT)) {
459 return ImmutableSet.of();
Andrea Campanella01e886e2017-12-15 15:27:31 +0100460 }
Andrea Campanella04924b92018-01-17 16:34:51 +0100461 if (connectPoint.equals(SINGLE_FLOW_OUT_CP) ||
462 connectPoint.equals(DUAL_FLOW_OUT_CP) ||
463 connectPoint.equals(GROUP_FLOW_OUT_CP) ||
464 connectPoint.equals(HARDWARE_DEVICE_OUT_CP) ||
465 connectPoint.equals(HARDWARE_DEVICE_10_OUT_CP) ||
466 connectPoint.equals(DEFERRED_CP_2_OUT) ||
467 connectPoint.equals(DUAL_LINK_3_CP_3_OUT)) {
468 return ImmutableSet.of(H1);
469 }
470 return ImmutableSet.of();
Andrea Campanella01e886e2017-12-15 15:27:31 +0100471 }
472
473 @Override
474 public Set<Host> getHostsByMac(MacAddress mac) {
475 if (mac.equals(H1.mac())) {
476 return ImmutableSet.of(H1);
477 } else if (mac.equals(H2.mac())) {
478 return ImmutableSet.of(H2);
479 }
480 return ImmutableSet.of();
481 }
482
483 @Override
484 public Set<Host> getHostsByIp(IpAddress ip) {
485 if ((H1.ipAddresses().contains(ip))) {
486 return ImmutableSet.of(H1);
487 } else if ((H2.ipAddresses().contains(ip))) {
488 return ImmutableSet.of(H2);
489 }
490 return ImmutableSet.of();
491 }
492 }
493
494 private class TestLinkService extends LinkServiceAdapter {
495 @Override
496 public Set<Link> getEgressLinks(ConnectPoint connectPoint) {
497 if (connectPoint.equals(TOPO_FLOW_1_OUT_CP)
498 || connectPoint.equals(TOPO_FLOW_OUT_CP_1)) {
499 return ImmutableSet.of(DefaultLink.builder()
500 .providerId(ProviderId.NONE)
501 .type(Link.Type.DIRECT)
502 .src(connectPoint)
503 .dst(TOPO_FLOW_2_IN_CP)
504 .build());
505 } else if (connectPoint.equals(TOPO_FLOW_2_OUT_CP)) {
506 return ImmutableSet.of(DefaultLink.builder()
507 .providerId(ProviderId.NONE)
508 .type(Link.Type.DIRECT)
509 .src(TOPO_FLOW_2_OUT_CP)
510 .dst(TOPO_FLOW_3_IN_CP)
511 .build());
512 } else if (connectPoint.equals(TOPO_FLOW_OUT_CP_2)) {
513 return ImmutableSet.of(DefaultLink.builder()
514 .providerId(ProviderId.NONE)
515 .type(Link.Type.DIRECT)
516 .src(TOPO_FLOW_OUT_CP_2)
517 .dst(TOPO_FLOW_4_IN_CP)
518 .build());
519 } else if (connectPoint.equals(TOPO_FLOW_4_OUT_CP)) {
520 return ImmutableSet.of(DefaultLink.builder()
521 .providerId(ProviderId.NONE)
522 .type(Link.Type.DIRECT)
523 .src(TOPO_FLOW_4_OUT_CP)
524 .dst(TOPO_FLOW_3_IN_2_CP)
525 .build());
Andrea Campanellae04aac92018-01-31 14:59:03 +0100526 } else if (connectPoint.equals(DUAL_LINK_1_CP_2_OUT)) {
527 return ImmutableSet.of(DefaultLink.builder()
528 .providerId(ProviderId.NONE)
529 .type(Link.Type.DIRECT)
530 .src(DUAL_LINK_1_CP_2_OUT)
531 .dst(DUAL_LINK_2_CP_1_IN)
532 .build());
533 } else if (connectPoint.equals(DUAL_LINK_1_CP_3_OUT)) {
534 return ImmutableSet.of(DefaultLink.builder()
535 .providerId(ProviderId.NONE)
536 .type(Link.Type.DIRECT)
537 .src(DUAL_LINK_1_CP_3_OUT)
538 .dst(DUAL_LINK_2_CP_4_IN)
539 .build());
540 } else if (connectPoint.equals(DUAL_LINK_2_CP_2_OUT)) {
541 return ImmutableSet.of(DefaultLink.builder()
542 .providerId(ProviderId.NONE)
543 .type(Link.Type.DIRECT)
544 .src(DUAL_LINK_2_CP_2_OUT)
545 .dst(DUAL_LINK_3_CP_1_IN)
546 .build());
547 } else if (connectPoint.equals(DUAL_LINK_2_CP_3_OUT)) {
548 return ImmutableSet.of(DefaultLink.builder()
549 .providerId(ProviderId.NONE)
550 .type(Link.Type.DIRECT)
551 .src(DUAL_LINK_2_CP_3_OUT)
552 .dst(DUAL_LINK_3_CP_2_IN)
553 .build());
Andrea Campanella01e886e2017-12-15 15:27:31 +0100554 }
555 return ImmutableSet.of();
556 }
557 }
Andrea Campanella37d10622018-01-18 17:11:42 +0100558
559 private class TestDeviceService extends DeviceServiceAdapter {
560 @Override
561 public Device getDevice(DeviceId deviceId) {
562 if (deviceId.equals(DeviceId.deviceId("nonexistent"))) {
563 return null;
564 }
565 return new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("test"), SWITCH,
566 "test", "test", "test", "test", new ChassisId(),
567 DefaultAnnotations.builder().set("foo", "bar").build());
568 }
569
570 @Override
Andrea Campanella04924b92018-01-17 16:34:51 +0100571 public Port getPort(ConnectPoint cp) {
572 return new DefaultPort(null, cp.port(), true, DefaultAnnotations.builder().build());
573 }
574
575 @Override
Andrea Campanella37d10622018-01-18 17:11:42 +0100576 public boolean isAvailable(DeviceId deviceId) {
Andrea Campanella04924b92018-01-17 16:34:51 +0100577 return !deviceId.equals(OFFLINE_DEVICE);
578 }
579 }
580
581 private class TestEdgePortService extends EdgePortServiceAdapter {
582
583 @Override
584 public boolean isEdgePoint(ConnectPoint point) {
585 return point.equals(MULTICAST_OUT_CP) ||
586 point.equals(MULTICAST_OUT_CP_2);
Andrea Campanella37d10622018-01-18 17:11:42 +0100587 }
588 }
Andrea Campanella7c8e7912018-01-23 12:46:04 +0100589
590 private class TestMastershipService extends MastershipServiceAdapter {
591 @Override
592 public NodeId getMasterFor(DeviceId deviceId) {
593 return NodeId.nodeId(MASTER_1);
594 }
595 }
Andrea Campanella01e886e2017-12-15 15:27:31 +0100596}