blob: 7c584c95d775511d344216dd574f1dae86712aef [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 Campanella37d10622018-01-18 17:11:42 +010033import org.onosproject.net.Device;
Andrea Campanella01e886e2017-12-15 15:27:31 +010034import org.onosproject.net.DeviceId;
35import org.onosproject.net.Host;
36import org.onosproject.net.Link;
Andrea Campanella7c8e7912018-01-23 12:46:04 +010037import org.onosproject.net.PortNumber;
Andrea Campanella37d10622018-01-18 17:11:42 +010038import org.onosproject.net.device.DeviceServiceAdapter;
Andrea Campanella01e886e2017-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 Campanella37d10622018-01-18 17:11:42 +010063import static org.onosproject.net.Device.Type.SWITCH;
Andrea Campanella01e886e2017-12-15 15:27:31 +010064import static org.onosproject.t3.impl.T3TestObjects.*;
65import static org.slf4j.LoggerFactory.getLogger;
66
67/**
68 * Test Class for Troubleshoot Manager.
69 */
70public class TroubleshootManagerTest {
71
72 private static final Logger log = getLogger(TroubleshootManager.class);
73
74 private TroubleshootManager mngr;
75
76 @Before
77 public void setUp() throws Exception {
78 mngr = new TroubleshootManager();
79 mngr.flowRuleService = new TestFlowRuleService();
80 mngr.hostService = new TestHostService();
81 mngr.linkService = new TestLinkService();
82 mngr.driverService = new TestDriverService();
83 mngr.groupService = new TestGroupService();
Andrea Campanella37d10622018-01-18 17:11:42 +010084 mngr.deviceService = new TestDeviceService();
Andrea Campanella7c8e7912018-01-23 12:46:04 +010085 mngr.mastershipService = new TestMastershipService();
Andrea Campanella01e886e2017-12-15 15:27:31 +010086
87 assertNotNull("Manager should not be null", mngr);
88
89 assertNotNull("Flow rule Service should not be null", mngr.flowRuleService);
90 assertNotNull("Host Service should not be null", mngr.hostService);
91 assertNotNull("Group Service should not be null", mngr.groupService);
92 assertNotNull("Driver Service should not be null", mngr.driverService);
93 assertNotNull("Link Service should not be null", mngr.linkService);
Andrea Campanella37d10622018-01-18 17:11:42 +010094 assertNotNull("Device Service should not be null", mngr.deviceService);
95 }
96
97 /**
98 * Tests failure on non existent device.
99 */
100 @Test(expected = NullPointerException.class)
101 public void nonExistentDevice() {
102 StaticPacketTrace traceFail = mngr.trace(PACKET_OK, ConnectPoint.deviceConnectPoint("nonexistent" + "/1"));
103 }
104
105 /**
106 * Tests failure on offline device.
107 */
108 @Test
109 public void offlineDevice() {
110 StaticPacketTrace traceFail = mngr.trace(PACKET_OK, ConnectPoint.deviceConnectPoint(OFFLINE_DEVICE + "/1"));
111 assertNotNull("Trace should not be null", traceFail);
112 assertNull("Trace should have 0 output", traceFail.getGroupOuputs(SINGLE_FLOW_DEVICE));
Andrea Campanellabb9d3fb2018-01-22 15:10:30 +0100113 }
114
115 /**
116 * Tests failure on same output.
117 */
118 @Test
119 public void sameOutput() {
120 StaticPacketTrace traceFail = mngr.trace(PACKET_OK, SAME_OUTPUT_FLOW_CP);
121 assertNotNull("Trace should not be null", traceFail);
122 assertTrue("Trace should be unsuccessful",
123 traceFail.resultMessage().contains("is same as initial input"));
Andrea Campanella37d10622018-01-18 17:11:42 +0100124 log.info("trace {}", traceFail.resultMessage());
Andrea Campanella01e886e2017-12-15 15:27:31 +0100125 }
126
Andrea Campanella7c8e7912018-01-23 12:46:04 +0100127 /**
128 * Tests ARP to controller.
129 */
130 @Test
131 public void arpToController() {
132 StaticPacketTrace traceSuccess = mngr.trace(PACKET_ARP, ARP_FLOW_CP);
133 assertNotNull("Trace should not be null", traceSuccess);
134 assertTrue("Trace should be successful",
135 traceSuccess.resultMessage().contains("Packet goes to the controller"));
136 assertTrue("Master should be Master1",
137 traceSuccess.resultMessage().contains(MASTER_1));
138 ConnectPoint connectPoint = traceSuccess.getGroupOuputs(ARP_FLOW_DEVICE).get(0).getOutput();
139 assertEquals("Packet Should go to CONTROLLER", PortNumber.CONTROLLER, connectPoint.port());
140 log.info("trace {}", traceSuccess.resultMessage());
141 }
142
Andrea Campanellabb9d3fb2018-01-22 15:10:30 +0100143
Andrea Campanella01e886e2017-12-15 15:27:31 +0100144 /**
Andrea Campanella2bc55dd2018-01-18 16:54:34 +0100145 * Tests failure on device with no flows.
Andrea Campanella01e886e2017-12-15 15:27:31 +0100146 */
147 @Test
148 public void noFlows() {
149 StaticPacketTrace traceFail = mngr.trace(PACKET_OK, ConnectPoint.deviceConnectPoint("test/1"));
150 assertNotNull("Trace should not be null", traceFail);
151 assertNull("Trace should have 0 output", traceFail.getGroupOuputs(SINGLE_FLOW_DEVICE));
152 log.info("trace {}", traceFail.resultMessage());
153 }
154
155 /**
156 * Test a single flow rule that has output port in it.
157 */
158 @Test
159 public void testSingleFlowRule() {
160
Andrea Campanellae04aac92018-01-31 14:59:03 +0100161 testSuccess(PACKET_OK, SINGLE_FLOW_IN_CP, SINGLE_FLOW_DEVICE, SINGLE_FLOW_OUT_CP, 1, 1);
Andrea Campanella01e886e2017-12-15 15:27:31 +0100162
Andrea Campanellae04aac92018-01-31 14:59:03 +0100163 testFailure(PACKET_FAIL, SINGLE_FLOW_IN_CP, SINGLE_FLOW_DEVICE);
Andrea Campanella01e886e2017-12-15 15:27:31 +0100164 }
165
166 /**
167 * Tests two flow rule the last one of which has output port in it.
168 */
169 @Test
170 public void testDualFlowRule() {
171
172 //Test Success
173
Andrea Campanella2bc55dd2018-01-18 16:54:34 +0100174 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, DUAL_FLOW_IN_CP, DUAL_FLOW_DEVICE,
Andrea Campanellae04aac92018-01-31 14:59:03 +0100175 DUAL_FLOW_OUT_CP, 1, 1);
Andrea Campanella01e886e2017-12-15 15:27:31 +0100176
177 //Testing Vlan
178 Criterion criterion = traceSuccess.getGroupOuputs(DUAL_FLOW_DEVICE).get(0).
179 getFinalPacket().getCriterion(Criterion.Type.VLAN_VID);
180 assertNotNull("Packet Should have Vlan", criterion);
181
182 VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) criterion;
183
184 assertEquals("Vlan should be 100", VlanId.vlanId((short) 100), vlanIdCriterion.vlanId());
185
186 //Test Faliure
Andrea Campanellae04aac92018-01-31 14:59:03 +0100187 testFailure(PACKET_FAIL, DUAL_FLOW_IN_CP, DUAL_FLOW_DEVICE);
Andrea Campanella01e886e2017-12-15 15:27:31 +0100188
189 }
190
191 /**
192 * Test a single flow rule that points to a group with output port in it.
193 */
194 @Test
195 public void flowAndGroup() throws Exception {
196
Andrea Campanella2bc55dd2018-01-18 16:54:34 +0100197 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, GROUP_FLOW_IN_CP, GROUP_FLOW_DEVICE,
Andrea Campanellae04aac92018-01-31 14:59:03 +0100198 GROUP_FLOW_OUT_CP, 1, 1);
Andrea Campanella01e886e2017-12-15 15:27:31 +0100199
200 assertTrue("Wrong Output Group", traceSuccess.getGroupOuputs(GROUP_FLOW_DEVICE)
201 .get(0).getGroups().contains(GROUP));
Andrea Campanella09ca07a2018-01-25 16:44:04 +0100202 assertEquals("Packet should not have MPLS Label", EthType.EtherType.IPV4.ethType(),
203 ((EthTypeCriterion) traceSuccess.getGroupOuputs(GROUP_FLOW_DEVICE)
204 .get(0).getFinalPacket().getCriterion(Criterion.Type.ETH_TYPE)).ethType());
205 assertNull("Packet should not have MPLS Label", traceSuccess.getGroupOuputs(GROUP_FLOW_DEVICE)
206 .get(0).getFinalPacket().getCriterion(Criterion.Type.MPLS_LABEL));
207 assertNull("Packet should not have MPLS Label", traceSuccess.getGroupOuputs(GROUP_FLOW_DEVICE)
208 .get(0).getFinalPacket().getCriterion(Criterion.Type.MPLS_BOS));
Andrea Campanella01e886e2017-12-15 15:27:31 +0100209
210 }
211
212 /**
213 * Test path through a 3 device topology.
214 */
215 @Test
216 public void singlePathTopology() throws Exception {
217
218 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK_TOPO, TOPO_FLOW_1_IN_CP,
Andrea Campanellae04aac92018-01-31 14:59:03 +0100219 TOPO_FLOW_3_DEVICE, TOPO_FLOW_3_OUT_CP, 1, 1);
Andrea Campanella01e886e2017-12-15 15:27:31 +0100220
221 assertTrue("Incorrect path",
222 traceSuccess.getCompletePaths().get(0).contains(TOPO_FLOW_2_IN_CP));
223 assertTrue("Incorrect path",
224 traceSuccess.getCompletePaths().get(0).contains(TOPO_FLOW_2_OUT_CP));
225 assertTrue("Incorrect path",
226 traceSuccess.getCompletePaths().get(0).contains(TOPO_FLOW_3_IN_CP));
227
228 }
229
230 /**
231 * Test path through a 4 device topology with first device that has groups with multiple output buckets.
232 */
233 @Test
234 public void testGroupTopo() throws Exception {
235
236 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK_TOPO, TOPO_FLOW_IN_CP,
Andrea Campanellae04aac92018-01-31 14:59:03 +0100237 TOPO_FLOW_3_DEVICE, TOPO_FLOW_3_OUT_CP, 2, 1);
238
239 log.info("{}", traceSuccess);
Andrea Campanella01e886e2017-12-15 15:27:31 +0100240
241 assertTrue("Incorrect groups",
242 traceSuccess.getGroupOuputs(TOPO_GROUP_FLOW_DEVICE).get(0).getGroups().contains(TOPO_GROUP));
243 assertTrue("Incorrect bucket",
244 traceSuccess.getGroupOuputs(TOPO_GROUP_FLOW_DEVICE).get(1).getGroups().contains(TOPO_GROUP));
245 }
246
247 /**
248 * Test HW support in a single device with 2 flow rules to check hit of static HW rules.
249 */
250 @Test
251 public void hardwareTest() throws Exception {
252
253 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, HARDWARE_DEVICE_IN_CP,
Andrea Campanellae04aac92018-01-31 14:59:03 +0100254 HARDWARE_DEVICE, HARDWARE_DEVICE_OUT_CP, 1, 1);
Andrea Campanella01e886e2017-12-15 15:27:31 +0100255
256 assertEquals("wrong ETH type", EthType.EtherType.IPV4.ethType(),
257 ((EthTypeCriterion) traceSuccess.getGroupOuputs(HARDWARE_DEVICE).get(0).getFinalPacket()
258 .getCriterion(Criterion.Type.ETH_TYPE)).ethType());
259
260 }
261
Andrea Campanellae04aac92018-01-31 14:59:03 +0100262 /**
263 * Test dual links between 3 topology elements.
264 */
265 @Test
266 public void dualLinks() throws Exception {
267
268 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, DUAL_LINK_1_CP_1_IN,
269 DUAL_LINK_3, DUAL_LINK_3_CP_3_OUT, 4, 1);
270
271 //TODO tests
272
273 }
274
Andrea Campanellad5bb2ef2018-01-31 16:43:23 +0100275 /**
276 * Test proper clear deferred behaviour.
277 */
278 @Test
279 public void clearDeferred() throws Exception {
280
281 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, DEFERRED_CP_1_IN,
282 DEFERRED_1, DEFERRED_CP_2_OUT, 1, 1);
283
284 assertNull("MPLS should have been not applied due to clear deferred", traceSuccess
285 .getGroupOuputs(DEFERRED_1).get(0).getFinalPacket().getCriterion(Criterion.Type.MPLS_LABEL));
286
287 }
288
289
Andrea Campanella01e886e2017-12-15 15:27:31 +0100290 private StaticPacketTrace testSuccess(TrafficSelector packet, ConnectPoint in, DeviceId deviceId, ConnectPoint out,
Andrea Campanellae04aac92018-01-31 14:59:03 +0100291 int paths, int outputs) {
Andrea Campanella01e886e2017-12-15 15:27:31 +0100292 StaticPacketTrace traceSuccess = mngr.trace(packet, in);
293
294 log.info("trace {}", traceSuccess);
295
296 log.info("trace {}", traceSuccess.resultMessage());
297
298 assertNotNull("trace should not be null", traceSuccess);
Andrea Campanellae04aac92018-01-31 14:59:03 +0100299 assertEquals("Trace should have " + outputs + " output", outputs,
300 traceSuccess.getGroupOuputs(deviceId).size());
Andrea Campanella01e886e2017-12-15 15:27:31 +0100301 assertEquals("Trace should only have " + paths + "output", paths, traceSuccess.getCompletePaths().size());
302 assertTrue("Trace should be successful",
303 traceSuccess.resultMessage().contains("Reached required destination Host"));
304 assertEquals("Incorrect Output CP", out,
305 traceSuccess.getGroupOuputs(deviceId).get(0).getOutput());
306
307 return traceSuccess;
308 }
309
Andrea Campanellae04aac92018-01-31 14:59:03 +0100310 private void testFailure(TrafficSelector packet, ConnectPoint in, DeviceId deviceId) {
Andrea Campanella01e886e2017-12-15 15:27:31 +0100311 StaticPacketTrace traceFail = mngr.trace(packet, in);
312
313 log.info("trace {}", traceFail.resultMessage());
314
315 assertNotNull("Trace should not be null", traceFail);
316 assertNull("Trace should have 0 output", traceFail.getGroupOuputs(deviceId));
317 }
318
319 private class TestFlowRuleService extends FlowRuleServiceAdapter {
320 @Override
321 public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) {
322 if (deviceId.equals(SINGLE_FLOW_DEVICE)) {
323 return ImmutableList.of(SINGLE_FLOW_ENTRY);
324 } else if (deviceId.equals(DUAL_FLOW_DEVICE)) {
325 return ImmutableList.of(FIRST_FLOW_ENTRY, SECOND_FLOW_ENTRY);
326 } else if (deviceId.equals(GROUP_FLOW_DEVICE)) {
327 return ImmutableList.of(GROUP_FLOW_ENTRY);
328 } else if (deviceId.equals(TOPO_FLOW_DEVICE) ||
329 deviceId.equals(TOPO_FLOW_2_DEVICE) ||
330 deviceId.equals(TOPO_FLOW_3_DEVICE) ||
331 deviceId.equals(TOPO_FLOW_4_DEVICE)) {
332 return ImmutableList.of(TOPO_SINGLE_FLOW_ENTRY, TOPO_SECOND_INPUT_FLOW_ENTRY);
333 } else if (deviceId.equals(TOPO_GROUP_FLOW_DEVICE)) {
334 return ImmutableList.of(TOPO_GROUP_FLOW_ENTRY);
Andrea Campanella2bc55dd2018-01-18 16:54:34 +0100335 } else if (deviceId.equals(HARDWARE_DEVICE)) {
Andrea Campanella01e886e2017-12-15 15:27:31 +0100336 return ImmutableList.of(HARDWARE_ETH_FLOW_ENTRY, HARDWARE_FLOW_ENTRY);
Andrea Campanellabb9d3fb2018-01-22 15:10:30 +0100337 } else if (deviceId.equals(SAME_OUTPUT_FLOW_DEVICE)) {
338 return ImmutableList.of(SAME_OUTPUT_FLOW_ENTRY);
Andrea Campanella7c8e7912018-01-23 12:46:04 +0100339 } else if (deviceId.equals(ARP_FLOW_DEVICE)) {
340 return ImmutableList.of(ARP_FLOW_ENTRY);
Andrea Campanellae04aac92018-01-31 14:59:03 +0100341 } else if (deviceId.equals(DUAL_LINK_1)) {
342 return ImmutableList.of(DUAL_LINK_1_GROUP_FLOW_ENTRY);
343 } else if (deviceId.equals(DUAL_LINK_2)) {
344 return ImmutableList.of(DUAL_LINK_1_GROUP_FLOW_ENTRY, DUAL_LINK_2_GROUP_FLOW_ENTRY);
345 } else if (deviceId.equals(DUAL_LINK_3)) {
346 return ImmutableList.of(DUAL_LINK_3_FLOW_ENTRY, DUAL_LINK_3_FLOW_ENTRY_2);
Andrea Campanellad5bb2ef2018-01-31 16:43:23 +0100347 } else if (deviceId.equals(DEFERRED_1)) {
348 return ImmutableList.of(DEFERRED_FLOW_ENTRY, DEFERRED_CLEAR_FLOW_ENTRY);
Andrea Campanella01e886e2017-12-15 15:27:31 +0100349 }
350 return ImmutableList.of();
351 }
352 }
353
354 private class TestDriverService extends DriverServiceAdapter {
355 @Override
356 public Driver getDriver(DeviceId deviceId) {
Andrea Campanella2bc55dd2018-01-18 16:54:34 +0100357 if (deviceId.equals(HARDWARE_DEVICE)) {
Andrea Campanella01e886e2017-12-15 15:27:31 +0100358 return new DefaultDriver("ofdpa", ImmutableList.of(),
359 "test", "test", "test", new HashMap<>(), new HashMap<>());
360 }
361 return new DefaultDriver("NotHWDriver", ImmutableList.of(),
362 "test", "test", "test", new HashMap<>(), new HashMap<>());
363 }
364 }
365
366 private class TestGroupService extends GroupServiceAdapter {
367 @Override
368 public Iterable<Group> getGroups(DeviceId deviceId) {
369 if (deviceId.equals(GROUP_FLOW_DEVICE)) {
370 return ImmutableList.of(GROUP);
371 } else if (deviceId.equals(TOPO_GROUP_FLOW_DEVICE)) {
372 return ImmutableList.of(TOPO_GROUP);
Andrea Campanellae04aac92018-01-31 14:59:03 +0100373 } else if (deviceId.equals(DUAL_LINK_1) || deviceId.equals(DUAL_LINK_2)) {
374 return ImmutableList.of(DUAL_LINK_GROUP);
Andrea Campanella01e886e2017-12-15 15:27:31 +0100375 }
376 return ImmutableList.of();
377 }
378 }
379
380 private class TestHostService extends HostServiceAdapter {
381 @Override
382 public Set<Host> getConnectedHosts(ConnectPoint connectPoint) {
383 if (connectPoint.equals(TOPO_FLOW_3_OUT_CP)) {
384 return ImmutableSet.of(H2);
Andrea Campanellae04aac92018-01-31 14:59:03 +0100385 } else if (connectPoint.equals(DUAL_LINK_1_CP_2_OUT) || connectPoint.equals(DUAL_LINK_1_CP_3_OUT) ||
386 connectPoint.equals(DUAL_LINK_2_CP_2_OUT) || connectPoint.equals(DUAL_LINK_2_CP_3_OUT)) {
387 return ImmutableSet.of();
Andrea Campanella01e886e2017-12-15 15:27:31 +0100388 }
389 return ImmutableSet.of(H1);
390 }
391
392 @Override
393 public Set<Host> getHostsByMac(MacAddress mac) {
394 if (mac.equals(H1.mac())) {
395 return ImmutableSet.of(H1);
396 } else if (mac.equals(H2.mac())) {
397 return ImmutableSet.of(H2);
398 }
399 return ImmutableSet.of();
400 }
401
402 @Override
403 public Set<Host> getHostsByIp(IpAddress ip) {
404 if ((H1.ipAddresses().contains(ip))) {
405 return ImmutableSet.of(H1);
406 } else if ((H2.ipAddresses().contains(ip))) {
407 return ImmutableSet.of(H2);
408 }
409 return ImmutableSet.of();
410 }
411 }
412
413 private class TestLinkService extends LinkServiceAdapter {
414 @Override
415 public Set<Link> getEgressLinks(ConnectPoint connectPoint) {
416 if (connectPoint.equals(TOPO_FLOW_1_OUT_CP)
417 || connectPoint.equals(TOPO_FLOW_OUT_CP_1)) {
418 return ImmutableSet.of(DefaultLink.builder()
419 .providerId(ProviderId.NONE)
420 .type(Link.Type.DIRECT)
421 .src(connectPoint)
422 .dst(TOPO_FLOW_2_IN_CP)
423 .build());
424 } else if (connectPoint.equals(TOPO_FLOW_2_OUT_CP)) {
425 return ImmutableSet.of(DefaultLink.builder()
426 .providerId(ProviderId.NONE)
427 .type(Link.Type.DIRECT)
428 .src(TOPO_FLOW_2_OUT_CP)
429 .dst(TOPO_FLOW_3_IN_CP)
430 .build());
431 } else if (connectPoint.equals(TOPO_FLOW_OUT_CP_2)) {
432 return ImmutableSet.of(DefaultLink.builder()
433 .providerId(ProviderId.NONE)
434 .type(Link.Type.DIRECT)
435 .src(TOPO_FLOW_OUT_CP_2)
436 .dst(TOPO_FLOW_4_IN_CP)
437 .build());
438 } else if (connectPoint.equals(TOPO_FLOW_4_OUT_CP)) {
439 return ImmutableSet.of(DefaultLink.builder()
440 .providerId(ProviderId.NONE)
441 .type(Link.Type.DIRECT)
442 .src(TOPO_FLOW_4_OUT_CP)
443 .dst(TOPO_FLOW_3_IN_2_CP)
444 .build());
Andrea Campanellae04aac92018-01-31 14:59:03 +0100445 } else if (connectPoint.equals(DUAL_LINK_1_CP_2_OUT)) {
446 return ImmutableSet.of(DefaultLink.builder()
447 .providerId(ProviderId.NONE)
448 .type(Link.Type.DIRECT)
449 .src(DUAL_LINK_1_CP_2_OUT)
450 .dst(DUAL_LINK_2_CP_1_IN)
451 .build());
452 } else if (connectPoint.equals(DUAL_LINK_1_CP_3_OUT)) {
453 return ImmutableSet.of(DefaultLink.builder()
454 .providerId(ProviderId.NONE)
455 .type(Link.Type.DIRECT)
456 .src(DUAL_LINK_1_CP_3_OUT)
457 .dst(DUAL_LINK_2_CP_4_IN)
458 .build());
459 } else if (connectPoint.equals(DUAL_LINK_2_CP_2_OUT)) {
460 return ImmutableSet.of(DefaultLink.builder()
461 .providerId(ProviderId.NONE)
462 .type(Link.Type.DIRECT)
463 .src(DUAL_LINK_2_CP_2_OUT)
464 .dst(DUAL_LINK_3_CP_1_IN)
465 .build());
466 } else if (connectPoint.equals(DUAL_LINK_2_CP_3_OUT)) {
467 return ImmutableSet.of(DefaultLink.builder()
468 .providerId(ProviderId.NONE)
469 .type(Link.Type.DIRECT)
470 .src(DUAL_LINK_2_CP_3_OUT)
471 .dst(DUAL_LINK_3_CP_2_IN)
472 .build());
Andrea Campanella01e886e2017-12-15 15:27:31 +0100473 }
474 return ImmutableSet.of();
475 }
476 }
Andrea Campanella37d10622018-01-18 17:11:42 +0100477
478 private class TestDeviceService extends DeviceServiceAdapter {
479 @Override
480 public Device getDevice(DeviceId deviceId) {
481 if (deviceId.equals(DeviceId.deviceId("nonexistent"))) {
482 return null;
483 }
484 return new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("test"), SWITCH,
485 "test", "test", "test", "test", new ChassisId(),
486 DefaultAnnotations.builder().set("foo", "bar").build());
487 }
488
489 @Override
490 public boolean isAvailable(DeviceId deviceId) {
491 if (deviceId.equals(OFFLINE_DEVICE)) {
492 return false;
493 }
494 return true;
495 }
496 }
Andrea Campanella7c8e7912018-01-23 12:46:04 +0100497
498 private class TestMastershipService extends MastershipServiceAdapter {
499 @Override
500 public NodeId getMasterFor(DeviceId deviceId) {
501 return NodeId.nodeId(MASTER_1);
502 }
503 }
Andrea Campanella01e886e2017-12-15 15:27:31 +0100504}