blob: 7b6c5709ee40ec26f84a0f941fa95e4de67fb7ee [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 Campanella17d45192018-01-18 17:11:42 +010033import org.onosproject.net.Device;
Andrea Campanellae4084402017-12-15 15:27:31 +010034import org.onosproject.net.DeviceId;
35import org.onosproject.net.Host;
36import org.onosproject.net.Link;
Andrea Campanella54923d62018-01-23 12:46:04 +010037import org.onosproject.net.PortNumber;
Andrea Campanella17d45192018-01-18 17:11:42 +010038import org.onosproject.net.device.DeviceServiceAdapter;
Andrea Campanellae4084402017-12-15 15:27:31 +010039import org.onosproject.net.driver.DefaultDriver;
40import org.onosproject.net.driver.Driver;
41import org.onosproject.net.driver.DriverServiceAdapter;
42import org.onosproject.net.flow.FlowEntry;
43import org.onosproject.net.flow.FlowRuleServiceAdapter;
44import org.onosproject.net.flow.TrafficSelector;
45import org.onosproject.net.flow.criteria.Criterion;
46import org.onosproject.net.flow.criteria.EthTypeCriterion;
47import org.onosproject.net.flow.criteria.VlanIdCriterion;
48import org.onosproject.net.group.Group;
49import org.onosproject.net.group.GroupServiceAdapter;
50import org.onosproject.net.host.HostServiceAdapter;
51import org.onosproject.net.link.LinkServiceAdapter;
52import org.onosproject.net.provider.ProviderId;
53import org.onosproject.t3.api.StaticPacketTrace;
54import org.slf4j.Logger;
55
56import java.util.HashMap;
57import java.util.Set;
58
59import static org.junit.Assert.assertEquals;
60import static org.junit.Assert.assertNotNull;
61import static org.junit.Assert.assertNull;
62import static org.junit.Assert.assertTrue;
Andrea Campanella17d45192018-01-18 17:11:42 +010063import static org.onosproject.net.Device.Type.SWITCH;
Andrea Campanellae4084402017-12-15 15:27:31 +010064import static org.onosproject.t3.impl.T3TestObjects.*;
Andrea Campanella1445f7a2018-02-07 12:00:12 +010065import static org.onosproject.t3.impl.TroubleshootManager.PACKET_TO_CONTROLLER;
Andrea Campanellae4084402017-12-15 15:27:31 +010066import static org.slf4j.LoggerFactory.getLogger;
67
68/**
69 * Test Class for Troubleshoot Manager.
70 */
71public class TroubleshootManagerTest {
72
73 private static final Logger log = getLogger(TroubleshootManager.class);
74
75 private TroubleshootManager mngr;
76
77 @Before
78 public void setUp() throws Exception {
79 mngr = new TroubleshootManager();
80 mngr.flowRuleService = new TestFlowRuleService();
81 mngr.hostService = new TestHostService();
82 mngr.linkService = new TestLinkService();
83 mngr.driverService = new TestDriverService();
84 mngr.groupService = new TestGroupService();
Andrea Campanella17d45192018-01-18 17:11:42 +010085 mngr.deviceService = new TestDeviceService();
Andrea Campanella54923d62018-01-23 12:46:04 +010086 mngr.mastershipService = new TestMastershipService();
Andrea Campanellae4084402017-12-15 15:27:31 +010087
88 assertNotNull("Manager should not be null", mngr);
89
90 assertNotNull("Flow rule Service should not be null", mngr.flowRuleService);
91 assertNotNull("Host Service should not be null", mngr.hostService);
92 assertNotNull("Group Service should not be null", mngr.groupService);
93 assertNotNull("Driver Service should not be null", mngr.driverService);
94 assertNotNull("Link Service should not be null", mngr.linkService);
Andrea Campanella17d45192018-01-18 17:11:42 +010095 assertNotNull("Device Service should not be null", mngr.deviceService);
96 }
97
98 /**
99 * Tests failure on non existent device.
100 */
101 @Test(expected = NullPointerException.class)
102 public void nonExistentDevice() {
103 StaticPacketTrace traceFail = mngr.trace(PACKET_OK, ConnectPoint.deviceConnectPoint("nonexistent" + "/1"));
104 }
105
106 /**
107 * Tests failure on offline device.
108 */
109 @Test
110 public void offlineDevice() {
111 StaticPacketTrace traceFail = mngr.trace(PACKET_OK, ConnectPoint.deviceConnectPoint(OFFLINE_DEVICE + "/1"));
112 assertNotNull("Trace should not be null", traceFail);
113 assertNull("Trace should have 0 output", traceFail.getGroupOuputs(SINGLE_FLOW_DEVICE));
Andrea Campanella7d3cf652018-01-22 15:10:30 +0100114 }
115
116 /**
117 * Tests failure on same output.
118 */
119 @Test
120 public void sameOutput() {
121 StaticPacketTrace traceFail = mngr.trace(PACKET_OK, SAME_OUTPUT_FLOW_CP);
122 assertNotNull("Trace should not be null", traceFail);
123 assertTrue("Trace should be unsuccessful",
124 traceFail.resultMessage().contains("is same as initial input"));
Andrea Campanella17d45192018-01-18 17:11:42 +0100125 log.info("trace {}", traceFail.resultMessage());
Andrea Campanellae4084402017-12-15 15:27:31 +0100126 }
127
Andrea Campanella54923d62018-01-23 12:46:04 +0100128 /**
129 * Tests ARP to controller.
130 */
131 @Test
132 public void arpToController() {
133 StaticPacketTrace traceSuccess = mngr.trace(PACKET_ARP, ARP_FLOW_CP);
134 assertNotNull("Trace should not be null", traceSuccess);
135 assertTrue("Trace should be successful",
Andrea Campanella1445f7a2018-02-07 12:00:12 +0100136 traceSuccess.resultMessage().contains(PACKET_TO_CONTROLLER));
Andrea Campanella54923d62018-01-23 12:46:04 +0100137 assertTrue("Master should be Master1",
138 traceSuccess.resultMessage().contains(MASTER_1));
139 ConnectPoint connectPoint = traceSuccess.getGroupOuputs(ARP_FLOW_DEVICE).get(0).getOutput();
140 assertEquals("Packet Should go to CONTROLLER", PortNumber.CONTROLLER, connectPoint.port());
Andrea Campanellae6798012018-02-06 15:46:52 +0100141 assertNull("VlanId should be null", traceSuccess.getGroupOuputs(ARP_FLOW_DEVICE).get(0)
142 .getFinalPacket().getCriterion(Criterion.Type.VLAN_VID));
Andrea Campanella54923d62018-01-23 12:46:04 +0100143 log.info("trace {}", traceSuccess.resultMessage());
144 }
145
Andrea Campanella7d3cf652018-01-22 15:10:30 +0100146
Andrea Campanellae4084402017-12-15 15:27:31 +0100147 /**
Andrea Campanella4401bd72018-01-18 16:54:34 +0100148 * Tests failure on device with no flows.
Andrea Campanellae4084402017-12-15 15:27:31 +0100149 */
150 @Test
151 public void noFlows() {
152 StaticPacketTrace traceFail = mngr.trace(PACKET_OK, ConnectPoint.deviceConnectPoint("test/1"));
153 assertNotNull("Trace should not be null", traceFail);
154 assertNull("Trace should have 0 output", traceFail.getGroupOuputs(SINGLE_FLOW_DEVICE));
155 log.info("trace {}", traceFail.resultMessage());
156 }
157
158 /**
159 * Test a single flow rule that has output port in it.
160 */
161 @Test
162 public void testSingleFlowRule() {
163
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100164 testSuccess(PACKET_OK, SINGLE_FLOW_IN_CP, SINGLE_FLOW_DEVICE, SINGLE_FLOW_OUT_CP, 1, 1);
Andrea Campanellae4084402017-12-15 15:27:31 +0100165
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100166 testFailure(PACKET_FAIL, SINGLE_FLOW_IN_CP, SINGLE_FLOW_DEVICE);
Andrea Campanellae4084402017-12-15 15:27:31 +0100167 }
168
169 /**
170 * Tests two flow rule the last one of which has output port in it.
171 */
172 @Test
173 public void testDualFlowRule() {
174
175 //Test Success
176
Andrea Campanella4401bd72018-01-18 16:54:34 +0100177 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, DUAL_FLOW_IN_CP, DUAL_FLOW_DEVICE,
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100178 DUAL_FLOW_OUT_CP, 1, 1);
Andrea Campanellae4084402017-12-15 15:27:31 +0100179
180 //Testing Vlan
181 Criterion criterion = traceSuccess.getGroupOuputs(DUAL_FLOW_DEVICE).get(0).
182 getFinalPacket().getCriterion(Criterion.Type.VLAN_VID);
183 assertNotNull("Packet Should have Vlan", criterion);
184
185 VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) criterion;
186
187 assertEquals("Vlan should be 100", VlanId.vlanId((short) 100), vlanIdCriterion.vlanId());
188
189 //Test Faliure
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100190 testFailure(PACKET_FAIL, DUAL_FLOW_IN_CP, DUAL_FLOW_DEVICE);
Andrea Campanellae4084402017-12-15 15:27:31 +0100191
192 }
193
194 /**
195 * Test a single flow rule that points to a group with output port in it.
196 */
197 @Test
198 public void flowAndGroup() throws Exception {
199
Andrea Campanella4401bd72018-01-18 16:54:34 +0100200 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, GROUP_FLOW_IN_CP, GROUP_FLOW_DEVICE,
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100201 GROUP_FLOW_OUT_CP, 1, 1);
Andrea Campanellae4084402017-12-15 15:27:31 +0100202
203 assertTrue("Wrong Output Group", traceSuccess.getGroupOuputs(GROUP_FLOW_DEVICE)
204 .get(0).getGroups().contains(GROUP));
Andrea Campanella3970e472018-01-25 16:44:04 +0100205 assertEquals("Packet should not have MPLS Label", EthType.EtherType.IPV4.ethType(),
206 ((EthTypeCriterion) traceSuccess.getGroupOuputs(GROUP_FLOW_DEVICE)
207 .get(0).getFinalPacket().getCriterion(Criterion.Type.ETH_TYPE)).ethType());
208 assertNull("Packet should not have MPLS Label", traceSuccess.getGroupOuputs(GROUP_FLOW_DEVICE)
209 .get(0).getFinalPacket().getCriterion(Criterion.Type.MPLS_LABEL));
210 assertNull("Packet should not have MPLS Label", traceSuccess.getGroupOuputs(GROUP_FLOW_DEVICE)
211 .get(0).getFinalPacket().getCriterion(Criterion.Type.MPLS_BOS));
Andrea Campanellae4084402017-12-15 15:27:31 +0100212
213 }
214
215 /**
216 * Test path through a 3 device topology.
217 */
218 @Test
219 public void singlePathTopology() throws Exception {
220
221 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK_TOPO, TOPO_FLOW_1_IN_CP,
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100222 TOPO_FLOW_3_DEVICE, TOPO_FLOW_3_OUT_CP, 1, 1);
Andrea Campanellae4084402017-12-15 15:27:31 +0100223
224 assertTrue("Incorrect path",
225 traceSuccess.getCompletePaths().get(0).contains(TOPO_FLOW_2_IN_CP));
226 assertTrue("Incorrect path",
227 traceSuccess.getCompletePaths().get(0).contains(TOPO_FLOW_2_OUT_CP));
228 assertTrue("Incorrect path",
229 traceSuccess.getCompletePaths().get(0).contains(TOPO_FLOW_3_IN_CP));
230
231 }
232
233 /**
234 * Test path through a 4 device topology with first device that has groups with multiple output buckets.
235 */
236 @Test
237 public void testGroupTopo() throws Exception {
238
239 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK_TOPO, TOPO_FLOW_IN_CP,
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100240 TOPO_FLOW_3_DEVICE, TOPO_FLOW_3_OUT_CP, 2, 1);
241
242 log.info("{}", traceSuccess);
Andrea Campanellae4084402017-12-15 15:27:31 +0100243
244 assertTrue("Incorrect groups",
245 traceSuccess.getGroupOuputs(TOPO_GROUP_FLOW_DEVICE).get(0).getGroups().contains(TOPO_GROUP));
246 assertTrue("Incorrect bucket",
247 traceSuccess.getGroupOuputs(TOPO_GROUP_FLOW_DEVICE).get(1).getGroups().contains(TOPO_GROUP));
248 }
249
250 /**
251 * Test HW support in a single device with 2 flow rules to check hit of static HW rules.
252 */
253 @Test
254 public void hardwareTest() throws Exception {
255
256 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, HARDWARE_DEVICE_IN_CP,
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100257 HARDWARE_DEVICE, HARDWARE_DEVICE_OUT_CP, 1, 1);
Andrea Campanellae4084402017-12-15 15:27:31 +0100258
259 assertEquals("wrong ETH type", EthType.EtherType.IPV4.ethType(),
260 ((EthTypeCriterion) traceSuccess.getGroupOuputs(HARDWARE_DEVICE).get(0).getFinalPacket()
261 .getCriterion(Criterion.Type.ETH_TYPE)).ethType());
262
263 }
264
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100265 /**
Andrea Campanella94c594a2018-02-06 18:58:40 +0100266 * Test that HW has two rules on table 10 for untagged packets.
267 */
268 @Test
269 public void hardwareTable10Test() throws Exception {
270
271 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, HARDWARE_DEVICE_10_IN_CP,
272 HARDWARE_DEVICE_10, HARDWARE_DEVICE_10_OUT_CP, 1, 1);
273
274 assertTrue("Second flow rule is absent", traceSuccess.getFlowsForDevice(HARDWARE_DEVICE_10)
275 .contains(HARDWARE_10_SECOND_FLOW_ENTRY));
276
277 }
278
279 /**
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100280 * Test dual links between 3 topology elements.
281 */
282 @Test
283 public void dualLinks() throws Exception {
284
285 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, DUAL_LINK_1_CP_1_IN,
286 DUAL_LINK_3, DUAL_LINK_3_CP_3_OUT, 4, 1);
287
288 //TODO tests
289
290 }
291
Andrea Campanella8292ba62018-01-31 16:43:23 +0100292 /**
293 * Test proper clear deferred behaviour.
294 */
295 @Test
296 public void clearDeferred() throws Exception {
297
298 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, DEFERRED_CP_1_IN,
299 DEFERRED_1, DEFERRED_CP_2_OUT, 1, 1);
300
301 assertNull("MPLS should have been not applied due to clear deferred", traceSuccess
302 .getGroupOuputs(DEFERRED_1).get(0).getFinalPacket().getCriterion(Criterion.Type.MPLS_LABEL));
303
304 }
305
306
Andrea Campanella1445f7a2018-02-07 12:00:12 +0100307 /**
308 * Test LLDP output to controller.
309 */
310 @Test
311 public void lldpToController() {
312 StaticPacketTrace traceSuccess = mngr.trace(PACKET_LLDP, LLDP_FLOW_CP);
313 assertNotNull("Trace should not be null", traceSuccess);
314 assertTrue("Trace should be successful",
315 traceSuccess.resultMessage().contains("Packet goes to the controller"));
316 assertTrue("Master should be Master1",
317 traceSuccess.resultMessage().contains(MASTER_1));
318 ConnectPoint connectPoint = traceSuccess.getGroupOuputs(LLDP_FLOW_DEVICE).get(0).getOutput();
319 assertEquals("Packet Should go to CONTROLLER", PortNumber.CONTROLLER, connectPoint.port());
320 log.info("trace {}", traceSuccess.resultMessage());
321 }
322
Andrea Campanellae4084402017-12-15 15:27:31 +0100323 private StaticPacketTrace testSuccess(TrafficSelector packet, ConnectPoint in, DeviceId deviceId, ConnectPoint out,
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100324 int paths, int outputs) {
Andrea Campanellae4084402017-12-15 15:27:31 +0100325 StaticPacketTrace traceSuccess = mngr.trace(packet, in);
326
327 log.info("trace {}", traceSuccess);
328
329 log.info("trace {}", traceSuccess.resultMessage());
330
331 assertNotNull("trace should not be null", traceSuccess);
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100332 assertEquals("Trace should have " + outputs + " output", outputs,
333 traceSuccess.getGroupOuputs(deviceId).size());
Andrea Campanellae4084402017-12-15 15:27:31 +0100334 assertEquals("Trace should only have " + paths + "output", paths, traceSuccess.getCompletePaths().size());
335 assertTrue("Trace should be successful",
336 traceSuccess.resultMessage().contains("Reached required destination Host"));
337 assertEquals("Incorrect Output CP", out,
338 traceSuccess.getGroupOuputs(deviceId).get(0).getOutput());
339
340 return traceSuccess;
341 }
342
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100343 private void testFailure(TrafficSelector packet, ConnectPoint in, DeviceId deviceId) {
Andrea Campanellae4084402017-12-15 15:27:31 +0100344 StaticPacketTrace traceFail = mngr.trace(packet, in);
345
346 log.info("trace {}", traceFail.resultMessage());
347
348 assertNotNull("Trace should not be null", traceFail);
349 assertNull("Trace should have 0 output", traceFail.getGroupOuputs(deviceId));
350 }
351
352 private class TestFlowRuleService extends FlowRuleServiceAdapter {
353 @Override
354 public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) {
355 if (deviceId.equals(SINGLE_FLOW_DEVICE)) {
356 return ImmutableList.of(SINGLE_FLOW_ENTRY);
357 } else if (deviceId.equals(DUAL_FLOW_DEVICE)) {
358 return ImmutableList.of(FIRST_FLOW_ENTRY, SECOND_FLOW_ENTRY);
359 } else if (deviceId.equals(GROUP_FLOW_DEVICE)) {
360 return ImmutableList.of(GROUP_FLOW_ENTRY);
361 } else if (deviceId.equals(TOPO_FLOW_DEVICE) ||
362 deviceId.equals(TOPO_FLOW_2_DEVICE) ||
363 deviceId.equals(TOPO_FLOW_3_DEVICE) ||
364 deviceId.equals(TOPO_FLOW_4_DEVICE)) {
365 return ImmutableList.of(TOPO_SINGLE_FLOW_ENTRY, TOPO_SECOND_INPUT_FLOW_ENTRY);
366 } else if (deviceId.equals(TOPO_GROUP_FLOW_DEVICE)) {
367 return ImmutableList.of(TOPO_GROUP_FLOW_ENTRY);
Andrea Campanella4401bd72018-01-18 16:54:34 +0100368 } else if (deviceId.equals(HARDWARE_DEVICE)) {
Andrea Campanellae4084402017-12-15 15:27:31 +0100369 return ImmutableList.of(HARDWARE_ETH_FLOW_ENTRY, HARDWARE_FLOW_ENTRY);
Andrea Campanella7d3cf652018-01-22 15:10:30 +0100370 } else if (deviceId.equals(SAME_OUTPUT_FLOW_DEVICE)) {
371 return ImmutableList.of(SAME_OUTPUT_FLOW_ENTRY);
Andrea Campanella54923d62018-01-23 12:46:04 +0100372 } else if (deviceId.equals(ARP_FLOW_DEVICE)) {
373 return ImmutableList.of(ARP_FLOW_ENTRY);
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100374 } else if (deviceId.equals(DUAL_LINK_1)) {
375 return ImmutableList.of(DUAL_LINK_1_GROUP_FLOW_ENTRY);
376 } else if (deviceId.equals(DUAL_LINK_2)) {
377 return ImmutableList.of(DUAL_LINK_1_GROUP_FLOW_ENTRY, DUAL_LINK_2_GROUP_FLOW_ENTRY);
378 } else if (deviceId.equals(DUAL_LINK_3)) {
379 return ImmutableList.of(DUAL_LINK_3_FLOW_ENTRY, DUAL_LINK_3_FLOW_ENTRY_2);
Andrea Campanella8292ba62018-01-31 16:43:23 +0100380 } else if (deviceId.equals(DEFERRED_1)) {
381 return ImmutableList.of(DEFERRED_FLOW_ENTRY, DEFERRED_CLEAR_FLOW_ENTRY);
Andrea Campanella94c594a2018-02-06 18:58:40 +0100382 } else if (deviceId.equals(HARDWARE_DEVICE_10)) {
383 return ImmutableList.of(HARDWARE_10_FLOW_ENTRY, HARDWARE_10_SECOND_FLOW_ENTRY,
384 HARDWARE_10_OUTPUT_FLOW_ENTRY);
Andrea Campanella1445f7a2018-02-07 12:00:12 +0100385 } else if (deviceId.equals(LLDP_FLOW_DEVICE)) {
386 return ImmutableList.of(LLDP_FLOW_ENTRY);
Andrea Campanellae4084402017-12-15 15:27:31 +0100387 }
388 return ImmutableList.of();
389 }
390 }
391
392 private class TestDriverService extends DriverServiceAdapter {
393 @Override
394 public Driver getDriver(DeviceId deviceId) {
Andrea Campanella94c594a2018-02-06 18:58:40 +0100395 if (deviceId.equals(HARDWARE_DEVICE) || deviceId.equals(HARDWARE_DEVICE_10)) {
Andrea Campanellae4084402017-12-15 15:27:31 +0100396 return new DefaultDriver("ofdpa", ImmutableList.of(),
397 "test", "test", "test", new HashMap<>(), new HashMap<>());
398 }
399 return new DefaultDriver("NotHWDriver", ImmutableList.of(),
400 "test", "test", "test", new HashMap<>(), new HashMap<>());
401 }
402 }
403
404 private class TestGroupService extends GroupServiceAdapter {
405 @Override
406 public Iterable<Group> getGroups(DeviceId deviceId) {
407 if (deviceId.equals(GROUP_FLOW_DEVICE)) {
408 return ImmutableList.of(GROUP);
409 } else if (deviceId.equals(TOPO_GROUP_FLOW_DEVICE)) {
410 return ImmutableList.of(TOPO_GROUP);
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100411 } else if (deviceId.equals(DUAL_LINK_1) || deviceId.equals(DUAL_LINK_2)) {
412 return ImmutableList.of(DUAL_LINK_GROUP);
Andrea Campanellae4084402017-12-15 15:27:31 +0100413 }
414 return ImmutableList.of();
415 }
416 }
417
418 private class TestHostService extends HostServiceAdapter {
419 @Override
420 public Set<Host> getConnectedHosts(ConnectPoint connectPoint) {
421 if (connectPoint.equals(TOPO_FLOW_3_OUT_CP)) {
422 return ImmutableSet.of(H2);
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100423 } else if (connectPoint.equals(DUAL_LINK_1_CP_2_OUT) || connectPoint.equals(DUAL_LINK_1_CP_3_OUT) ||
424 connectPoint.equals(DUAL_LINK_2_CP_2_OUT) || connectPoint.equals(DUAL_LINK_2_CP_3_OUT)) {
425 return ImmutableSet.of();
Andrea Campanellae4084402017-12-15 15:27:31 +0100426 }
427 return ImmutableSet.of(H1);
428 }
429
430 @Override
431 public Set<Host> getHostsByMac(MacAddress mac) {
432 if (mac.equals(H1.mac())) {
433 return ImmutableSet.of(H1);
434 } else if (mac.equals(H2.mac())) {
435 return ImmutableSet.of(H2);
436 }
437 return ImmutableSet.of();
438 }
439
440 @Override
441 public Set<Host> getHostsByIp(IpAddress ip) {
442 if ((H1.ipAddresses().contains(ip))) {
443 return ImmutableSet.of(H1);
444 } else if ((H2.ipAddresses().contains(ip))) {
445 return ImmutableSet.of(H2);
446 }
447 return ImmutableSet.of();
448 }
449 }
450
451 private class TestLinkService extends LinkServiceAdapter {
452 @Override
453 public Set<Link> getEgressLinks(ConnectPoint connectPoint) {
454 if (connectPoint.equals(TOPO_FLOW_1_OUT_CP)
455 || connectPoint.equals(TOPO_FLOW_OUT_CP_1)) {
456 return ImmutableSet.of(DefaultLink.builder()
457 .providerId(ProviderId.NONE)
458 .type(Link.Type.DIRECT)
459 .src(connectPoint)
460 .dst(TOPO_FLOW_2_IN_CP)
461 .build());
462 } else if (connectPoint.equals(TOPO_FLOW_2_OUT_CP)) {
463 return ImmutableSet.of(DefaultLink.builder()
464 .providerId(ProviderId.NONE)
465 .type(Link.Type.DIRECT)
466 .src(TOPO_FLOW_2_OUT_CP)
467 .dst(TOPO_FLOW_3_IN_CP)
468 .build());
469 } else if (connectPoint.equals(TOPO_FLOW_OUT_CP_2)) {
470 return ImmutableSet.of(DefaultLink.builder()
471 .providerId(ProviderId.NONE)
472 .type(Link.Type.DIRECT)
473 .src(TOPO_FLOW_OUT_CP_2)
474 .dst(TOPO_FLOW_4_IN_CP)
475 .build());
476 } else if (connectPoint.equals(TOPO_FLOW_4_OUT_CP)) {
477 return ImmutableSet.of(DefaultLink.builder()
478 .providerId(ProviderId.NONE)
479 .type(Link.Type.DIRECT)
480 .src(TOPO_FLOW_4_OUT_CP)
481 .dst(TOPO_FLOW_3_IN_2_CP)
482 .build());
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100483 } else if (connectPoint.equals(DUAL_LINK_1_CP_2_OUT)) {
484 return ImmutableSet.of(DefaultLink.builder()
485 .providerId(ProviderId.NONE)
486 .type(Link.Type.DIRECT)
487 .src(DUAL_LINK_1_CP_2_OUT)
488 .dst(DUAL_LINK_2_CP_1_IN)
489 .build());
490 } else if (connectPoint.equals(DUAL_LINK_1_CP_3_OUT)) {
491 return ImmutableSet.of(DefaultLink.builder()
492 .providerId(ProviderId.NONE)
493 .type(Link.Type.DIRECT)
494 .src(DUAL_LINK_1_CP_3_OUT)
495 .dst(DUAL_LINK_2_CP_4_IN)
496 .build());
497 } else if (connectPoint.equals(DUAL_LINK_2_CP_2_OUT)) {
498 return ImmutableSet.of(DefaultLink.builder()
499 .providerId(ProviderId.NONE)
500 .type(Link.Type.DIRECT)
501 .src(DUAL_LINK_2_CP_2_OUT)
502 .dst(DUAL_LINK_3_CP_1_IN)
503 .build());
504 } else if (connectPoint.equals(DUAL_LINK_2_CP_3_OUT)) {
505 return ImmutableSet.of(DefaultLink.builder()
506 .providerId(ProviderId.NONE)
507 .type(Link.Type.DIRECT)
508 .src(DUAL_LINK_2_CP_3_OUT)
509 .dst(DUAL_LINK_3_CP_2_IN)
510 .build());
Andrea Campanellae4084402017-12-15 15:27:31 +0100511 }
512 return ImmutableSet.of();
513 }
514 }
Andrea Campanella17d45192018-01-18 17:11:42 +0100515
516 private class TestDeviceService extends DeviceServiceAdapter {
517 @Override
518 public Device getDevice(DeviceId deviceId) {
519 if (deviceId.equals(DeviceId.deviceId("nonexistent"))) {
520 return null;
521 }
522 return new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("test"), SWITCH,
523 "test", "test", "test", "test", new ChassisId(),
524 DefaultAnnotations.builder().set("foo", "bar").build());
525 }
526
527 @Override
528 public boolean isAvailable(DeviceId deviceId) {
529 if (deviceId.equals(OFFLINE_DEVICE)) {
530 return false;
531 }
532 return true;
533 }
534 }
Andrea Campanella54923d62018-01-23 12:46:04 +0100535
536 private class TestMastershipService extends MastershipServiceAdapter {
537 @Override
538 public NodeId getMasterFor(DeviceId deviceId) {
539 return NodeId.nodeId(MASTER_1);
540 }
541 }
Andrea Campanellae4084402017-12-15 15:27:31 +0100542}