blob: bbf9fd5b524b4d233584c4c7d8e95e0cfe6f639f [file] [log] [blame]
Andrea Campanellae4084402017-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 Campanella17d45192018-01-18 17:11:42 +010022import org.onlab.packet.ChassisId;
Andrea Campanellae4084402017-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 Campanella54923d62018-01-23 12:46:04 +010027import org.onosproject.cluster.NodeId;
28import org.onosproject.mastership.MastershipServiceAdapter;
Andrea Campanellae4084402017-12-15 15:27:31 +010029import org.onosproject.net.ConnectPoint;
Andrea Campanella17d45192018-01-18 17:11:42 +010030import org.onosproject.net.DefaultAnnotations;
31import org.onosproject.net.DefaultDevice;
Andrea Campanellae4084402017-12-15 15:27:31 +010032import org.onosproject.net.DefaultLink;
Andrea Campanella4c6170a2018-01-17 16:34:51 +010033import org.onosproject.net.DefaultPort;
Andrea Campanella17d45192018-01-18 17:11:42 +010034import org.onosproject.net.Device;
Andrea Campanellae4084402017-12-15 15:27:31 +010035import org.onosproject.net.DeviceId;
36import org.onosproject.net.Host;
37import org.onosproject.net.Link;
Andrea Campanella4c6170a2018-01-17 16:34:51 +010038import org.onosproject.net.Port;
Andrea Campanella94dfb9e2018-02-27 12:36:00 +010039import org.onosproject.net.PortNumber;
Andrea Campanella17d45192018-01-18 17:11:42 +010040import org.onosproject.net.device.DeviceServiceAdapter;
Andrea Campanellae4084402017-12-15 15:27:31 +010041import org.onosproject.net.driver.DefaultDriver;
42import org.onosproject.net.driver.Driver;
43import org.onosproject.net.driver.DriverServiceAdapter;
Andrea Campanella4c6170a2018-01-17 16:34:51 +010044import org.onosproject.net.edge.EdgePortServiceAdapter;
Andrea Campanellae4084402017-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 Campanella17d45192018-01-18 17:11:42 +010066import static org.onosproject.net.Device.Type.SWITCH;
Andrea Campanellae4084402017-12-15 15:27:31 +010067import static org.onosproject.t3.impl.T3TestObjects.*;
Andrea Campanella1445f7a2018-02-07 12:00:12 +010068import static org.onosproject.t3.impl.TroubleshootManager.PACKET_TO_CONTROLLER;
Andrea Campanellae4084402017-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 Campanella17d45192018-01-18 17:11:42 +010088 mngr.deviceService = new TestDeviceService();
Andrea Campanella54923d62018-01-23 12:46:04 +010089 mngr.mastershipService = new TestMastershipService();
Andrea Campanella4c6170a2018-01-17 16:34:51 +010090 mngr.edgePortService = new TestEdgePortService();
Andrea Campanellae4084402017-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 Campanella17d45192018-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 Campanella7d3cf652018-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 Campanella17d45192018-01-18 17:11:42 +0100129 log.info("trace {}", traceFail.resultMessage());
Andrea Campanellae4084402017-12-15 15:27:31 +0100130 }
131
Andrea Campanella54923d62018-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 Campanella1445f7a2018-02-07 12:00:12 +0100140 traceSuccess.resultMessage().contains(PACKET_TO_CONTROLLER));
Andrea Campanella54923d62018-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 Campanellae6798012018-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 Campanella54923d62018-01-23 12:46:04 +0100147 log.info("trace {}", traceSuccess.resultMessage());
148 }
149
Andrea Campanella7d3cf652018-01-22 15:10:30 +0100150
Andrea Campanellae4084402017-12-15 15:27:31 +0100151 /**
Andrea Campanella4401bd72018-01-18 16:54:34 +0100152 * Tests failure on device with no flows.
Andrea Campanellae4084402017-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 /**
Andrea Campanella94dfb9e2018-02-27 12:36:00 +0100163 * Test group with no buckets.
164 */
165 @Test
166 public void noBucketsTest() throws Exception {
167
168 StaticPacketTrace traceFail = mngr.trace(PACKET_OK, NO_BUCKET_CP);
169 assertNotNull("Trace should not be null", traceFail);
170 assertTrue("Trace should be unsuccessful",
171 traceFail.resultMessage().contains("no buckets"));
172 log.info("trace {}", traceFail.resultMessage());
173
174 }
175
176 /**
Andrea Campanellae4084402017-12-15 15:27:31 +0100177 * Test a single flow rule that has output port in it.
178 */
179 @Test
180 public void testSingleFlowRule() {
181
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100182 testSuccess(PACKET_OK, SINGLE_FLOW_IN_CP, SINGLE_FLOW_DEVICE, SINGLE_FLOW_OUT_CP, 1, 1);
Andrea Campanellae4084402017-12-15 15:27:31 +0100183
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100184 testFailure(PACKET_FAIL, SINGLE_FLOW_IN_CP, SINGLE_FLOW_DEVICE);
Andrea Campanellae4084402017-12-15 15:27:31 +0100185 }
186
187 /**
188 * Tests two flow rule the last one of which has output port in it.
189 */
190 @Test
191 public void testDualFlowRule() {
192
193 //Test Success
194
Andrea Campanella4401bd72018-01-18 16:54:34 +0100195 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, DUAL_FLOW_IN_CP, DUAL_FLOW_DEVICE,
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100196 DUAL_FLOW_OUT_CP, 1, 1);
Andrea Campanellae4084402017-12-15 15:27:31 +0100197
198 //Testing Vlan
199 Criterion criterion = traceSuccess.getGroupOuputs(DUAL_FLOW_DEVICE).get(0).
200 getFinalPacket().getCriterion(Criterion.Type.VLAN_VID);
201 assertNotNull("Packet Should have Vlan", criterion);
202
203 VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) criterion;
204
205 assertEquals("Vlan should be 100", VlanId.vlanId((short) 100), vlanIdCriterion.vlanId());
206
207 //Test Faliure
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100208 testFailure(PACKET_FAIL, DUAL_FLOW_IN_CP, DUAL_FLOW_DEVICE);
Andrea Campanellae4084402017-12-15 15:27:31 +0100209
210 }
211
212 /**
213 * Test a single flow rule that points to a group with output port in it.
214 */
215 @Test
216 public void flowAndGroup() throws Exception {
217
Andrea Campanella4401bd72018-01-18 16:54:34 +0100218 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, GROUP_FLOW_IN_CP, GROUP_FLOW_DEVICE,
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100219 GROUP_FLOW_OUT_CP, 1, 1);
Andrea Campanellae4084402017-12-15 15:27:31 +0100220
221 assertTrue("Wrong Output Group", traceSuccess.getGroupOuputs(GROUP_FLOW_DEVICE)
222 .get(0).getGroups().contains(GROUP));
Andrea Campanella3970e472018-01-25 16:44:04 +0100223 assertEquals("Packet should not have MPLS Label", EthType.EtherType.IPV4.ethType(),
224 ((EthTypeCriterion) traceSuccess.getGroupOuputs(GROUP_FLOW_DEVICE)
225 .get(0).getFinalPacket().getCriterion(Criterion.Type.ETH_TYPE)).ethType());
226 assertNull("Packet should not have MPLS Label", traceSuccess.getGroupOuputs(GROUP_FLOW_DEVICE)
227 .get(0).getFinalPacket().getCriterion(Criterion.Type.MPLS_LABEL));
228 assertNull("Packet should not have MPLS Label", traceSuccess.getGroupOuputs(GROUP_FLOW_DEVICE)
229 .get(0).getFinalPacket().getCriterion(Criterion.Type.MPLS_BOS));
Andrea Campanellae4084402017-12-15 15:27:31 +0100230
231 }
232
233 /**
234 * Test path through a 3 device topology.
235 */
236 @Test
237 public void singlePathTopology() throws Exception {
238
239 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK_TOPO, TOPO_FLOW_1_IN_CP,
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100240 TOPO_FLOW_3_DEVICE, TOPO_FLOW_3_OUT_CP, 1, 1);
Andrea Campanellae4084402017-12-15 15:27:31 +0100241
242 assertTrue("Incorrect path",
243 traceSuccess.getCompletePaths().get(0).contains(TOPO_FLOW_2_IN_CP));
244 assertTrue("Incorrect path",
245 traceSuccess.getCompletePaths().get(0).contains(TOPO_FLOW_2_OUT_CP));
246 assertTrue("Incorrect path",
247 traceSuccess.getCompletePaths().get(0).contains(TOPO_FLOW_3_IN_CP));
248
249 }
250
251 /**
252 * Test path through a 4 device topology with first device that has groups with multiple output buckets.
253 */
254 @Test
255 public void testGroupTopo() throws Exception {
256
257 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK_TOPO, TOPO_FLOW_IN_CP,
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100258 TOPO_FLOW_3_DEVICE, TOPO_FLOW_3_OUT_CP, 2, 1);
259
260 log.info("{}", traceSuccess);
Andrea Campanellae4084402017-12-15 15:27:31 +0100261
262 assertTrue("Incorrect groups",
263 traceSuccess.getGroupOuputs(TOPO_GROUP_FLOW_DEVICE).get(0).getGroups().contains(TOPO_GROUP));
264 assertTrue("Incorrect bucket",
265 traceSuccess.getGroupOuputs(TOPO_GROUP_FLOW_DEVICE).get(1).getGroups().contains(TOPO_GROUP));
266 }
267
268 /**
269 * Test HW support in a single device with 2 flow rules to check hit of static HW rules.
270 */
271 @Test
272 public void hardwareTest() throws Exception {
273
274 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, HARDWARE_DEVICE_IN_CP,
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100275 HARDWARE_DEVICE, HARDWARE_DEVICE_OUT_CP, 1, 1);
Andrea Campanellae4084402017-12-15 15:27:31 +0100276
277 assertEquals("wrong ETH type", EthType.EtherType.IPV4.ethType(),
278 ((EthTypeCriterion) traceSuccess.getGroupOuputs(HARDWARE_DEVICE).get(0).getFinalPacket()
279 .getCriterion(Criterion.Type.ETH_TYPE)).ethType());
280
281 }
282
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100283 /**
Andrea Campanella94c594a2018-02-06 18:58:40 +0100284 * Test that HW has two rules on table 10 for untagged packets.
285 */
286 @Test
287 public void hardwareTable10Test() throws Exception {
288
289 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, HARDWARE_DEVICE_10_IN_CP,
290 HARDWARE_DEVICE_10, HARDWARE_DEVICE_10_OUT_CP, 1, 1);
291
292 assertTrue("Second flow rule is absent", traceSuccess.getFlowsForDevice(HARDWARE_DEVICE_10)
293 .contains(HARDWARE_10_SECOND_FLOW_ENTRY));
294
295 }
296
297 /**
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100298 * Test dual links between 3 topology elements.
299 */
300 @Test
301 public void dualLinks() throws Exception {
302
303 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, DUAL_LINK_1_CP_1_IN,
304 DUAL_LINK_3, DUAL_LINK_3_CP_3_OUT, 4, 1);
305
306 //TODO tests
307
308 }
309
Andrea Campanella8292ba62018-01-31 16:43:23 +0100310 /**
311 * Test proper clear deferred behaviour.
312 */
313 @Test
314 public void clearDeferred() throws Exception {
315
316 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, DEFERRED_CP_1_IN,
317 DEFERRED_1, DEFERRED_CP_2_OUT, 1, 1);
318
319 assertNull("MPLS should have been not applied due to clear deferred", traceSuccess
320 .getGroupOuputs(DEFERRED_1).get(0).getFinalPacket().getCriterion(Criterion.Type.MPLS_LABEL));
321
322 }
323
324
Andrea Campanella1445f7a2018-02-07 12:00:12 +0100325 /**
326 * Test LLDP output to controller.
327 */
328 @Test
329 public void lldpToController() {
330 StaticPacketTrace traceSuccess = mngr.trace(PACKET_LLDP, LLDP_FLOW_CP);
331 assertNotNull("Trace should not be null", traceSuccess);
332 assertTrue("Trace should be successful",
333 traceSuccess.resultMessage().contains("Packet goes to the controller"));
334 assertTrue("Master should be Master1",
335 traceSuccess.resultMessage().contains(MASTER_1));
336 ConnectPoint connectPoint = traceSuccess.getGroupOuputs(LLDP_FLOW_DEVICE).get(0).getOutput();
337 assertEquals("Packet Should go to CONTROLLER", PortNumber.CONTROLLER, connectPoint.port());
338 log.info("trace {}", traceSuccess.resultMessage());
339 }
340
Andrea Campanella4c6170a2018-01-17 16:34:51 +0100341 /**
342 * Test multicast in single device.
343 */
344 @Test
345 public void multicastTest() throws Exception {
346
347 StaticPacketTrace traceSuccess = mngr.trace(PACKET_OK_MULTICAST, MULTICAST_IN_CP);
348
349 log.info("trace {}", traceSuccess);
350
351 log.info("trace {}", traceSuccess.resultMessage());
352
353 assertNotNull("trace should not be null", traceSuccess);
354 assertEquals("Trace should have " + 2 + " output", 2,
355 traceSuccess.getGroupOuputs(MULTICAST_GROUP_FLOW_DEVICE).size());
356 assertEquals("Trace should only have " + 2 + "output", 2,
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,
361 traceSuccess.getGroupOuputs(MULTICAST_GROUP_FLOW_DEVICE).get(0).getOutput());
362 assertEquals("Incorrect Output CP", MULTICAST_OUT_CP,
363 traceSuccess.getGroupOuputs(MULTICAST_GROUP_FLOW_DEVICE).get(1).getOutput());
364
365 }
366
Andrea Campanella4906ba72018-03-01 16:22:21 +0100367 /**
368 * Tests dual homing of a host.
369 */
370 @Test
371 public void dualhomedTest() throws Exception {
372 StaticPacketTrace traceSuccess = mngr.trace(PACKET_DUAL_HOME, DUAL_HOME_CP_1_1);
373
374 assertNotNull("trace should not be null", traceSuccess);
375 assertTrue("Should have 2 output paths", traceSuccess.getCompletePaths().size() == 2);
376 assertTrue("Should contain proper path", traceSuccess.getCompletePaths()
377 .contains(ImmutableList.of(DUAL_HOME_CP_1_1, DUAL_HOME_CP_1_2, DUAL_HOME_CP_2_1, DUAL_HOME_CP_2_2)));
378 assertTrue("Should contain proper path", traceSuccess.getCompletePaths()
379 .contains(ImmutableList.of(DUAL_HOME_CP_1_1, DUAL_HOME_CP_1_3, DUAL_HOME_CP_3_1, DUAL_HOME_CP_3_2)));
380
381 }
382
383
Andrea Campanellae4084402017-12-15 15:27:31 +0100384 private StaticPacketTrace testSuccess(TrafficSelector packet, ConnectPoint in, DeviceId deviceId, ConnectPoint out,
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100385 int paths, int outputs) {
Andrea Campanellae4084402017-12-15 15:27:31 +0100386 StaticPacketTrace traceSuccess = mngr.trace(packet, in);
387
388 log.info("trace {}", traceSuccess);
389
390 log.info("trace {}", traceSuccess.resultMessage());
391
392 assertNotNull("trace should not be null", traceSuccess);
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100393 assertEquals("Trace should have " + outputs + " output", outputs,
394 traceSuccess.getGroupOuputs(deviceId).size());
Andrea Campanellae4084402017-12-15 15:27:31 +0100395 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,
399 traceSuccess.getGroupOuputs(deviceId).get(0).getOutput());
400
401 return traceSuccess;
402 }
403
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100404 private void testFailure(TrafficSelector packet, ConnectPoint in, DeviceId deviceId) {
Andrea Campanellae4084402017-12-15 15:27:31 +0100405 StaticPacketTrace traceFail = mngr.trace(packet, in);
406
407 log.info("trace {}", traceFail.resultMessage());
408
409 assertNotNull("Trace should not be null", traceFail);
410 assertNull("Trace should have 0 output", traceFail.getGroupOuputs(deviceId));
411 }
412
413 private class TestFlowRuleService extends FlowRuleServiceAdapter {
414 @Override
415 public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) {
416 if (deviceId.equals(SINGLE_FLOW_DEVICE)) {
417 return ImmutableList.of(SINGLE_FLOW_ENTRY);
418 } else if (deviceId.equals(DUAL_FLOW_DEVICE)) {
419 return ImmutableList.of(FIRST_FLOW_ENTRY, SECOND_FLOW_ENTRY);
420 } else if (deviceId.equals(GROUP_FLOW_DEVICE)) {
421 return ImmutableList.of(GROUP_FLOW_ENTRY);
422 } else if (deviceId.equals(TOPO_FLOW_DEVICE) ||
423 deviceId.equals(TOPO_FLOW_2_DEVICE) ||
424 deviceId.equals(TOPO_FLOW_3_DEVICE) ||
425 deviceId.equals(TOPO_FLOW_4_DEVICE)) {
426 return ImmutableList.of(TOPO_SINGLE_FLOW_ENTRY, TOPO_SECOND_INPUT_FLOW_ENTRY);
427 } else if (deviceId.equals(TOPO_GROUP_FLOW_DEVICE)) {
428 return ImmutableList.of(TOPO_GROUP_FLOW_ENTRY);
Andrea Campanella4401bd72018-01-18 16:54:34 +0100429 } else if (deviceId.equals(HARDWARE_DEVICE)) {
Andrea Campanellae4084402017-12-15 15:27:31 +0100430 return ImmutableList.of(HARDWARE_ETH_FLOW_ENTRY, HARDWARE_FLOW_ENTRY);
Andrea Campanella7d3cf652018-01-22 15:10:30 +0100431 } else if (deviceId.equals(SAME_OUTPUT_FLOW_DEVICE)) {
432 return ImmutableList.of(SAME_OUTPUT_FLOW_ENTRY);
Andrea Campanella54923d62018-01-23 12:46:04 +0100433 } else if (deviceId.equals(ARP_FLOW_DEVICE)) {
434 return ImmutableList.of(ARP_FLOW_ENTRY);
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100435 } else if (deviceId.equals(DUAL_LINK_1)) {
436 return ImmutableList.of(DUAL_LINK_1_GROUP_FLOW_ENTRY);
437 } else if (deviceId.equals(DUAL_LINK_2)) {
438 return ImmutableList.of(DUAL_LINK_1_GROUP_FLOW_ENTRY, DUAL_LINK_2_GROUP_FLOW_ENTRY);
439 } else if (deviceId.equals(DUAL_LINK_3)) {
440 return ImmutableList.of(DUAL_LINK_3_FLOW_ENTRY, DUAL_LINK_3_FLOW_ENTRY_2);
Andrea Campanella8292ba62018-01-31 16:43:23 +0100441 } else if (deviceId.equals(DEFERRED_1)) {
442 return ImmutableList.of(DEFERRED_FLOW_ENTRY, DEFERRED_CLEAR_FLOW_ENTRY);
Andrea Campanella94c594a2018-02-06 18:58:40 +0100443 } else if (deviceId.equals(HARDWARE_DEVICE_10)) {
444 return ImmutableList.of(HARDWARE_10_FLOW_ENTRY, HARDWARE_10_SECOND_FLOW_ENTRY,
445 HARDWARE_10_OUTPUT_FLOW_ENTRY);
Andrea Campanella1445f7a2018-02-07 12:00:12 +0100446 } else if (deviceId.equals(LLDP_FLOW_DEVICE)) {
447 return ImmutableList.of(LLDP_FLOW_ENTRY);
Andrea Campanella4c6170a2018-01-17 16:34:51 +0100448 } else if (deviceId.equals(MULTICAST_GROUP_FLOW_DEVICE)) {
449 return ImmutableList.of(MULTICAST_GROUP_FLOW_ENTRY);
Andrea Campanella94dfb9e2018-02-27 12:36:00 +0100450 } else if (deviceId.equals(NO_BUCKET_DEVICE)) {
451 return ImmutableList.of(NO_BUCKET_ENTRY);
Andrea Campanella4906ba72018-03-01 16:22:21 +0100452 } else if (deviceId.equals(DUAL_HOME_DEVICE_1)) {
453 return ImmutableList.of(DUAL_HOME_FLOW_ENTRY);
454 } else if (deviceId.equals(DUAL_HOME_DEVICE_2) || deviceId.equals(DUAL_HOME_DEVICE_3)) {
455 return ImmutableList.of(DUAL_HOME_OUT_FLOW_ENTRY);
Andrea Campanellae4084402017-12-15 15:27:31 +0100456 }
457 return ImmutableList.of();
458 }
459 }
460
461 private class TestDriverService extends DriverServiceAdapter {
462 @Override
463 public Driver getDriver(DeviceId deviceId) {
Andrea Campanella94c594a2018-02-06 18:58:40 +0100464 if (deviceId.equals(HARDWARE_DEVICE) || deviceId.equals(HARDWARE_DEVICE_10)) {
Andrea Campanellae4084402017-12-15 15:27:31 +0100465 return new DefaultDriver("ofdpa", ImmutableList.of(),
466 "test", "test", "test", new HashMap<>(), new HashMap<>());
467 }
468 return new DefaultDriver("NotHWDriver", ImmutableList.of(),
469 "test", "test", "test", new HashMap<>(), new HashMap<>());
470 }
471 }
472
473 private class TestGroupService extends GroupServiceAdapter {
474 @Override
475 public Iterable<Group> getGroups(DeviceId deviceId) {
476 if (deviceId.equals(GROUP_FLOW_DEVICE)) {
477 return ImmutableList.of(GROUP);
478 } else if (deviceId.equals(TOPO_GROUP_FLOW_DEVICE)) {
479 return ImmutableList.of(TOPO_GROUP);
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100480 } else if (deviceId.equals(DUAL_LINK_1) || deviceId.equals(DUAL_LINK_2)) {
481 return ImmutableList.of(DUAL_LINK_GROUP);
Andrea Campanella4c6170a2018-01-17 16:34:51 +0100482 } else if (deviceId.equals(MULTICAST_GROUP_FLOW_DEVICE)) {
483 return ImmutableList.of(MULTICAST_GROUP);
Andrea Campanella94dfb9e2018-02-27 12:36:00 +0100484 } else if (deviceId.equals(NO_BUCKET_DEVICE)) {
485 return ImmutableList.of(NO_BUCKET_GROUP);
Andrea Campanella4906ba72018-03-01 16:22:21 +0100486 } else if (deviceId.equals(DUAL_HOME_DEVICE_1)) {
487 return ImmutableList.of(DUAL_HOME_GROUP);
Andrea Campanellae4084402017-12-15 15:27:31 +0100488 }
489 return ImmutableList.of();
490 }
491 }
492
493 private class TestHostService extends HostServiceAdapter {
494 @Override
495 public Set<Host> getConnectedHosts(ConnectPoint connectPoint) {
496 if (connectPoint.equals(TOPO_FLOW_3_OUT_CP)) {
497 return ImmutableSet.of(H2);
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100498 } else if (connectPoint.equals(DUAL_LINK_1_CP_2_OUT) || connectPoint.equals(DUAL_LINK_1_CP_3_OUT) ||
499 connectPoint.equals(DUAL_LINK_2_CP_2_OUT) || connectPoint.equals(DUAL_LINK_2_CP_3_OUT)) {
500 return ImmutableSet.of();
Andrea Campanellae4084402017-12-15 15:27:31 +0100501 }
Andrea Campanella4c6170a2018-01-17 16:34:51 +0100502 if (connectPoint.equals(SINGLE_FLOW_OUT_CP) ||
503 connectPoint.equals(DUAL_FLOW_OUT_CP) ||
504 connectPoint.equals(GROUP_FLOW_OUT_CP) ||
505 connectPoint.equals(HARDWARE_DEVICE_OUT_CP) ||
506 connectPoint.equals(HARDWARE_DEVICE_10_OUT_CP) ||
507 connectPoint.equals(DEFERRED_CP_2_OUT) ||
508 connectPoint.equals(DUAL_LINK_3_CP_3_OUT)) {
509 return ImmutableSet.of(H1);
510 }
Andrea Campanella4906ba72018-03-01 16:22:21 +0100511 if (connectPoint.equals(DUAL_HOME_CP_2_2) || connectPoint.equals(DUAL_HOME_CP_3_2)) {
512 return ImmutableSet.of(DUAL_HOME_H);
513 }
Andrea Campanella4c6170a2018-01-17 16:34:51 +0100514 return ImmutableSet.of();
Andrea Campanellae4084402017-12-15 15:27:31 +0100515 }
516
517 @Override
518 public Set<Host> getHostsByMac(MacAddress mac) {
519 if (mac.equals(H1.mac())) {
520 return ImmutableSet.of(H1);
521 } else if (mac.equals(H2.mac())) {
522 return ImmutableSet.of(H2);
Andrea Campanella4906ba72018-03-01 16:22:21 +0100523 } else if (mac.equals(DUAL_HOME_H.mac())) {
524 return ImmutableSet.of(DUAL_HOME_H);
Andrea Campanellae4084402017-12-15 15:27:31 +0100525 }
526 return ImmutableSet.of();
527 }
528
529 @Override
530 public Set<Host> getHostsByIp(IpAddress ip) {
531 if ((H1.ipAddresses().contains(ip))) {
532 return ImmutableSet.of(H1);
533 } else if ((H2.ipAddresses().contains(ip))) {
534 return ImmutableSet.of(H2);
Andrea Campanella4906ba72018-03-01 16:22:21 +0100535 } else if ((DUAL_HOME_H.ipAddresses().contains(ip))) {
536 return ImmutableSet.of(DUAL_HOME_H);
Andrea Campanellae4084402017-12-15 15:27:31 +0100537 }
538 return ImmutableSet.of();
539 }
540 }
541
542 private class TestLinkService extends LinkServiceAdapter {
543 @Override
544 public Set<Link> getEgressLinks(ConnectPoint connectPoint) {
545 if (connectPoint.equals(TOPO_FLOW_1_OUT_CP)
546 || connectPoint.equals(TOPO_FLOW_OUT_CP_1)) {
547 return ImmutableSet.of(DefaultLink.builder()
548 .providerId(ProviderId.NONE)
549 .type(Link.Type.DIRECT)
550 .src(connectPoint)
551 .dst(TOPO_FLOW_2_IN_CP)
552 .build());
553 } else if (connectPoint.equals(TOPO_FLOW_2_OUT_CP)) {
554 return ImmutableSet.of(DefaultLink.builder()
555 .providerId(ProviderId.NONE)
556 .type(Link.Type.DIRECT)
557 .src(TOPO_FLOW_2_OUT_CP)
558 .dst(TOPO_FLOW_3_IN_CP)
559 .build());
560 } else if (connectPoint.equals(TOPO_FLOW_OUT_CP_2)) {
561 return ImmutableSet.of(DefaultLink.builder()
562 .providerId(ProviderId.NONE)
563 .type(Link.Type.DIRECT)
564 .src(TOPO_FLOW_OUT_CP_2)
565 .dst(TOPO_FLOW_4_IN_CP)
566 .build());
567 } else if (connectPoint.equals(TOPO_FLOW_4_OUT_CP)) {
568 return ImmutableSet.of(DefaultLink.builder()
569 .providerId(ProviderId.NONE)
570 .type(Link.Type.DIRECT)
571 .src(TOPO_FLOW_4_OUT_CP)
572 .dst(TOPO_FLOW_3_IN_2_CP)
573 .build());
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100574 } else if (connectPoint.equals(DUAL_LINK_1_CP_2_OUT)) {
575 return ImmutableSet.of(DefaultLink.builder()
576 .providerId(ProviderId.NONE)
577 .type(Link.Type.DIRECT)
578 .src(DUAL_LINK_1_CP_2_OUT)
579 .dst(DUAL_LINK_2_CP_1_IN)
580 .build());
581 } else if (connectPoint.equals(DUAL_LINK_1_CP_3_OUT)) {
582 return ImmutableSet.of(DefaultLink.builder()
583 .providerId(ProviderId.NONE)
584 .type(Link.Type.DIRECT)
585 .src(DUAL_LINK_1_CP_3_OUT)
586 .dst(DUAL_LINK_2_CP_4_IN)
587 .build());
588 } else if (connectPoint.equals(DUAL_LINK_2_CP_2_OUT)) {
589 return ImmutableSet.of(DefaultLink.builder()
590 .providerId(ProviderId.NONE)
591 .type(Link.Type.DIRECT)
592 .src(DUAL_LINK_2_CP_2_OUT)
593 .dst(DUAL_LINK_3_CP_1_IN)
594 .build());
595 } else if (connectPoint.equals(DUAL_LINK_2_CP_3_OUT)) {
596 return ImmutableSet.of(DefaultLink.builder()
597 .providerId(ProviderId.NONE)
598 .type(Link.Type.DIRECT)
599 .src(DUAL_LINK_2_CP_3_OUT)
600 .dst(DUAL_LINK_3_CP_2_IN)
601 .build());
Andrea Campanella4906ba72018-03-01 16:22:21 +0100602 } else if (connectPoint.equals(DUAL_HOME_CP_1_2)) {
603 return ImmutableSet.of(DefaultLink.builder()
604 .providerId(ProviderId.NONE)
605 .type(Link.Type.DIRECT)
606 .src(DUAL_HOME_CP_1_2)
607 .dst(DUAL_HOME_CP_2_1)
608 .build());
609 } else if (connectPoint.equals(DUAL_HOME_CP_1_3)) {
610 return ImmutableSet.of(DefaultLink.builder()
611 .providerId(ProviderId.NONE)
612 .type(Link.Type.DIRECT)
613 .src(DUAL_HOME_CP_1_3)
614 .dst(DUAL_HOME_CP_3_1)
615 .build());
Andrea Campanellae4084402017-12-15 15:27:31 +0100616 }
617 return ImmutableSet.of();
618 }
619 }
Andrea Campanella17d45192018-01-18 17:11:42 +0100620
621 private class TestDeviceService extends DeviceServiceAdapter {
622 @Override
623 public Device getDevice(DeviceId deviceId) {
624 if (deviceId.equals(DeviceId.deviceId("nonexistent"))) {
625 return null;
626 }
627 return new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("test"), SWITCH,
628 "test", "test", "test", "test", new ChassisId(),
629 DefaultAnnotations.builder().set("foo", "bar").build());
630 }
631
632 @Override
Andrea Campanella4c6170a2018-01-17 16:34:51 +0100633 public Port getPort(ConnectPoint cp) {
634 return new DefaultPort(null, cp.port(), true, DefaultAnnotations.builder().build());
635 }
636
637 @Override
Andrea Campanella17d45192018-01-18 17:11:42 +0100638 public boolean isAvailable(DeviceId deviceId) {
Andrea Campanella4c6170a2018-01-17 16:34:51 +0100639 return !deviceId.equals(OFFLINE_DEVICE);
640 }
641 }
642
643 private class TestEdgePortService extends EdgePortServiceAdapter {
644
645 @Override
646 public boolean isEdgePoint(ConnectPoint point) {
647 return point.equals(MULTICAST_OUT_CP) ||
648 point.equals(MULTICAST_OUT_CP_2);
Andrea Campanella17d45192018-01-18 17:11:42 +0100649 }
650 }
Andrea Campanella54923d62018-01-23 12:46:04 +0100651
652 private class TestMastershipService extends MastershipServiceAdapter {
653 @Override
654 public NodeId getMasterFor(DeviceId deviceId) {
655 return NodeId.nodeId(MASTER_1);
656 }
657 }
Andrea Campanellae4084402017-12-15 15:27:31 +0100658}