blob: fa19d2212888f4c2a2aa433e1b60c102fa2f5e49 [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 Campanellae4084402017-12-15 15:27:31 +0100367 private StaticPacketTrace testSuccess(TrafficSelector packet, ConnectPoint in, DeviceId deviceId, ConnectPoint out,
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100368 int paths, int outputs) {
Andrea Campanellae4084402017-12-15 15:27:31 +0100369 StaticPacketTrace traceSuccess = mngr.trace(packet, in);
370
371 log.info("trace {}", traceSuccess);
372
373 log.info("trace {}", traceSuccess.resultMessage());
374
375 assertNotNull("trace should not be null", traceSuccess);
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100376 assertEquals("Trace should have " + outputs + " output", outputs,
377 traceSuccess.getGroupOuputs(deviceId).size());
Andrea Campanellae4084402017-12-15 15:27:31 +0100378 assertEquals("Trace should only have " + paths + "output", paths, traceSuccess.getCompletePaths().size());
379 assertTrue("Trace should be successful",
380 traceSuccess.resultMessage().contains("Reached required destination Host"));
381 assertEquals("Incorrect Output CP", out,
382 traceSuccess.getGroupOuputs(deviceId).get(0).getOutput());
383
384 return traceSuccess;
385 }
386
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100387 private void testFailure(TrafficSelector packet, ConnectPoint in, DeviceId deviceId) {
Andrea Campanellae4084402017-12-15 15:27:31 +0100388 StaticPacketTrace traceFail = mngr.trace(packet, in);
389
390 log.info("trace {}", traceFail.resultMessage());
391
392 assertNotNull("Trace should not be null", traceFail);
393 assertNull("Trace should have 0 output", traceFail.getGroupOuputs(deviceId));
394 }
395
396 private class TestFlowRuleService extends FlowRuleServiceAdapter {
397 @Override
398 public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) {
399 if (deviceId.equals(SINGLE_FLOW_DEVICE)) {
400 return ImmutableList.of(SINGLE_FLOW_ENTRY);
401 } else if (deviceId.equals(DUAL_FLOW_DEVICE)) {
402 return ImmutableList.of(FIRST_FLOW_ENTRY, SECOND_FLOW_ENTRY);
403 } else if (deviceId.equals(GROUP_FLOW_DEVICE)) {
404 return ImmutableList.of(GROUP_FLOW_ENTRY);
405 } else if (deviceId.equals(TOPO_FLOW_DEVICE) ||
406 deviceId.equals(TOPO_FLOW_2_DEVICE) ||
407 deviceId.equals(TOPO_FLOW_3_DEVICE) ||
408 deviceId.equals(TOPO_FLOW_4_DEVICE)) {
409 return ImmutableList.of(TOPO_SINGLE_FLOW_ENTRY, TOPO_SECOND_INPUT_FLOW_ENTRY);
410 } else if (deviceId.equals(TOPO_GROUP_FLOW_DEVICE)) {
411 return ImmutableList.of(TOPO_GROUP_FLOW_ENTRY);
Andrea Campanella4401bd72018-01-18 16:54:34 +0100412 } else if (deviceId.equals(HARDWARE_DEVICE)) {
Andrea Campanellae4084402017-12-15 15:27:31 +0100413 return ImmutableList.of(HARDWARE_ETH_FLOW_ENTRY, HARDWARE_FLOW_ENTRY);
Andrea Campanella7d3cf652018-01-22 15:10:30 +0100414 } else if (deviceId.equals(SAME_OUTPUT_FLOW_DEVICE)) {
415 return ImmutableList.of(SAME_OUTPUT_FLOW_ENTRY);
Andrea Campanella54923d62018-01-23 12:46:04 +0100416 } else if (deviceId.equals(ARP_FLOW_DEVICE)) {
417 return ImmutableList.of(ARP_FLOW_ENTRY);
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100418 } else if (deviceId.equals(DUAL_LINK_1)) {
419 return ImmutableList.of(DUAL_LINK_1_GROUP_FLOW_ENTRY);
420 } else if (deviceId.equals(DUAL_LINK_2)) {
421 return ImmutableList.of(DUAL_LINK_1_GROUP_FLOW_ENTRY, DUAL_LINK_2_GROUP_FLOW_ENTRY);
422 } else if (deviceId.equals(DUAL_LINK_3)) {
423 return ImmutableList.of(DUAL_LINK_3_FLOW_ENTRY, DUAL_LINK_3_FLOW_ENTRY_2);
Andrea Campanella8292ba62018-01-31 16:43:23 +0100424 } else if (deviceId.equals(DEFERRED_1)) {
425 return ImmutableList.of(DEFERRED_FLOW_ENTRY, DEFERRED_CLEAR_FLOW_ENTRY);
Andrea Campanella94c594a2018-02-06 18:58:40 +0100426 } else if (deviceId.equals(HARDWARE_DEVICE_10)) {
427 return ImmutableList.of(HARDWARE_10_FLOW_ENTRY, HARDWARE_10_SECOND_FLOW_ENTRY,
428 HARDWARE_10_OUTPUT_FLOW_ENTRY);
Andrea Campanella1445f7a2018-02-07 12:00:12 +0100429 } else if (deviceId.equals(LLDP_FLOW_DEVICE)) {
430 return ImmutableList.of(LLDP_FLOW_ENTRY);
Andrea Campanella4c6170a2018-01-17 16:34:51 +0100431 } else if (deviceId.equals(MULTICAST_GROUP_FLOW_DEVICE)) {
432 return ImmutableList.of(MULTICAST_GROUP_FLOW_ENTRY);
Andrea Campanella94dfb9e2018-02-27 12:36:00 +0100433 } else if (deviceId.equals(NO_BUCKET_DEVICE)) {
434 return ImmutableList.of(NO_BUCKET_ENTRY);
Andrea Campanellae4084402017-12-15 15:27:31 +0100435 }
436 return ImmutableList.of();
437 }
438 }
439
440 private class TestDriverService extends DriverServiceAdapter {
441 @Override
442 public Driver getDriver(DeviceId deviceId) {
Andrea Campanella94c594a2018-02-06 18:58:40 +0100443 if (deviceId.equals(HARDWARE_DEVICE) || deviceId.equals(HARDWARE_DEVICE_10)) {
Andrea Campanellae4084402017-12-15 15:27:31 +0100444 return new DefaultDriver("ofdpa", ImmutableList.of(),
445 "test", "test", "test", new HashMap<>(), new HashMap<>());
446 }
447 return new DefaultDriver("NotHWDriver", ImmutableList.of(),
448 "test", "test", "test", new HashMap<>(), new HashMap<>());
449 }
450 }
451
452 private class TestGroupService extends GroupServiceAdapter {
453 @Override
454 public Iterable<Group> getGroups(DeviceId deviceId) {
455 if (deviceId.equals(GROUP_FLOW_DEVICE)) {
456 return ImmutableList.of(GROUP);
457 } else if (deviceId.equals(TOPO_GROUP_FLOW_DEVICE)) {
458 return ImmutableList.of(TOPO_GROUP);
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100459 } else if (deviceId.equals(DUAL_LINK_1) || deviceId.equals(DUAL_LINK_2)) {
460 return ImmutableList.of(DUAL_LINK_GROUP);
Andrea Campanella4c6170a2018-01-17 16:34:51 +0100461 } else if (deviceId.equals(MULTICAST_GROUP_FLOW_DEVICE)) {
462 return ImmutableList.of(MULTICAST_GROUP);
Andrea Campanella94dfb9e2018-02-27 12:36:00 +0100463 } else if (deviceId.equals(NO_BUCKET_DEVICE)) {
464 return ImmutableList.of(NO_BUCKET_GROUP);
Andrea Campanellae4084402017-12-15 15:27:31 +0100465 }
466 return ImmutableList.of();
467 }
468 }
469
470 private class TestHostService extends HostServiceAdapter {
471 @Override
472 public Set<Host> getConnectedHosts(ConnectPoint connectPoint) {
473 if (connectPoint.equals(TOPO_FLOW_3_OUT_CP)) {
474 return ImmutableSet.of(H2);
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100475 } else if (connectPoint.equals(DUAL_LINK_1_CP_2_OUT) || connectPoint.equals(DUAL_LINK_1_CP_3_OUT) ||
476 connectPoint.equals(DUAL_LINK_2_CP_2_OUT) || connectPoint.equals(DUAL_LINK_2_CP_3_OUT)) {
477 return ImmutableSet.of();
Andrea Campanellae4084402017-12-15 15:27:31 +0100478 }
Andrea Campanella4c6170a2018-01-17 16:34:51 +0100479 if (connectPoint.equals(SINGLE_FLOW_OUT_CP) ||
480 connectPoint.equals(DUAL_FLOW_OUT_CP) ||
481 connectPoint.equals(GROUP_FLOW_OUT_CP) ||
482 connectPoint.equals(HARDWARE_DEVICE_OUT_CP) ||
483 connectPoint.equals(HARDWARE_DEVICE_10_OUT_CP) ||
484 connectPoint.equals(DEFERRED_CP_2_OUT) ||
485 connectPoint.equals(DUAL_LINK_3_CP_3_OUT)) {
486 return ImmutableSet.of(H1);
487 }
488 return ImmutableSet.of();
Andrea Campanellae4084402017-12-15 15:27:31 +0100489 }
490
491 @Override
492 public Set<Host> getHostsByMac(MacAddress mac) {
493 if (mac.equals(H1.mac())) {
494 return ImmutableSet.of(H1);
495 } else if (mac.equals(H2.mac())) {
496 return ImmutableSet.of(H2);
497 }
498 return ImmutableSet.of();
499 }
500
501 @Override
502 public Set<Host> getHostsByIp(IpAddress ip) {
503 if ((H1.ipAddresses().contains(ip))) {
504 return ImmutableSet.of(H1);
505 } else if ((H2.ipAddresses().contains(ip))) {
506 return ImmutableSet.of(H2);
507 }
508 return ImmutableSet.of();
509 }
510 }
511
512 private class TestLinkService extends LinkServiceAdapter {
513 @Override
514 public Set<Link> getEgressLinks(ConnectPoint connectPoint) {
515 if (connectPoint.equals(TOPO_FLOW_1_OUT_CP)
516 || connectPoint.equals(TOPO_FLOW_OUT_CP_1)) {
517 return ImmutableSet.of(DefaultLink.builder()
518 .providerId(ProviderId.NONE)
519 .type(Link.Type.DIRECT)
520 .src(connectPoint)
521 .dst(TOPO_FLOW_2_IN_CP)
522 .build());
523 } else if (connectPoint.equals(TOPO_FLOW_2_OUT_CP)) {
524 return ImmutableSet.of(DefaultLink.builder()
525 .providerId(ProviderId.NONE)
526 .type(Link.Type.DIRECT)
527 .src(TOPO_FLOW_2_OUT_CP)
528 .dst(TOPO_FLOW_3_IN_CP)
529 .build());
530 } else if (connectPoint.equals(TOPO_FLOW_OUT_CP_2)) {
531 return ImmutableSet.of(DefaultLink.builder()
532 .providerId(ProviderId.NONE)
533 .type(Link.Type.DIRECT)
534 .src(TOPO_FLOW_OUT_CP_2)
535 .dst(TOPO_FLOW_4_IN_CP)
536 .build());
537 } else if (connectPoint.equals(TOPO_FLOW_4_OUT_CP)) {
538 return ImmutableSet.of(DefaultLink.builder()
539 .providerId(ProviderId.NONE)
540 .type(Link.Type.DIRECT)
541 .src(TOPO_FLOW_4_OUT_CP)
542 .dst(TOPO_FLOW_3_IN_2_CP)
543 .build());
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100544 } else if (connectPoint.equals(DUAL_LINK_1_CP_2_OUT)) {
545 return ImmutableSet.of(DefaultLink.builder()
546 .providerId(ProviderId.NONE)
547 .type(Link.Type.DIRECT)
548 .src(DUAL_LINK_1_CP_2_OUT)
549 .dst(DUAL_LINK_2_CP_1_IN)
550 .build());
551 } else if (connectPoint.equals(DUAL_LINK_1_CP_3_OUT)) {
552 return ImmutableSet.of(DefaultLink.builder()
553 .providerId(ProviderId.NONE)
554 .type(Link.Type.DIRECT)
555 .src(DUAL_LINK_1_CP_3_OUT)
556 .dst(DUAL_LINK_2_CP_4_IN)
557 .build());
558 } else if (connectPoint.equals(DUAL_LINK_2_CP_2_OUT)) {
559 return ImmutableSet.of(DefaultLink.builder()
560 .providerId(ProviderId.NONE)
561 .type(Link.Type.DIRECT)
562 .src(DUAL_LINK_2_CP_2_OUT)
563 .dst(DUAL_LINK_3_CP_1_IN)
564 .build());
565 } else if (connectPoint.equals(DUAL_LINK_2_CP_3_OUT)) {
566 return ImmutableSet.of(DefaultLink.builder()
567 .providerId(ProviderId.NONE)
568 .type(Link.Type.DIRECT)
569 .src(DUAL_LINK_2_CP_3_OUT)
570 .dst(DUAL_LINK_3_CP_2_IN)
571 .build());
Andrea Campanellae4084402017-12-15 15:27:31 +0100572 }
573 return ImmutableSet.of();
574 }
575 }
Andrea Campanella17d45192018-01-18 17:11:42 +0100576
577 private class TestDeviceService extends DeviceServiceAdapter {
578 @Override
579 public Device getDevice(DeviceId deviceId) {
580 if (deviceId.equals(DeviceId.deviceId("nonexistent"))) {
581 return null;
582 }
583 return new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("test"), SWITCH,
584 "test", "test", "test", "test", new ChassisId(),
585 DefaultAnnotations.builder().set("foo", "bar").build());
586 }
587
588 @Override
Andrea Campanella4c6170a2018-01-17 16:34:51 +0100589 public Port getPort(ConnectPoint cp) {
590 return new DefaultPort(null, cp.port(), true, DefaultAnnotations.builder().build());
591 }
592
593 @Override
Andrea Campanella17d45192018-01-18 17:11:42 +0100594 public boolean isAvailable(DeviceId deviceId) {
Andrea Campanella4c6170a2018-01-17 16:34:51 +0100595 return !deviceId.equals(OFFLINE_DEVICE);
596 }
597 }
598
599 private class TestEdgePortService extends EdgePortServiceAdapter {
600
601 @Override
602 public boolean isEdgePoint(ConnectPoint point) {
603 return point.equals(MULTICAST_OUT_CP) ||
604 point.equals(MULTICAST_OUT_CP_2);
Andrea Campanella17d45192018-01-18 17:11:42 +0100605 }
606 }
Andrea Campanella54923d62018-01-23 12:46:04 +0100607
608 private class TestMastershipService extends MastershipServiceAdapter {
609 @Override
610 public NodeId getMasterFor(DeviceId deviceId) {
611 return NodeId.nodeId(MASTER_1);
612 }
613 }
Andrea Campanellae4084402017-12-15 15:27:31 +0100614}