blob: 5426278a1e697c0e36c6e88b519ce7060b4b7700 [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.*;
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 Campanella17d45192018-01-18 17:11:42 +010084 mngr.deviceService = new TestDeviceService();
Andrea Campanella54923d62018-01-23 12:46:04 +010085 mngr.mastershipService = new TestMastershipService();
Andrea Campanellae4084402017-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 Campanella17d45192018-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 Campanella7d3cf652018-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 Campanella17d45192018-01-18 17:11:42 +0100124 log.info("trace {}", traceFail.resultMessage());
Andrea Campanellae4084402017-12-15 15:27:31 +0100125 }
126
Andrea Campanella54923d62018-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());
Andrea Campanellae6798012018-02-06 15:46:52 +0100140 assertNull("VlanId should be null", traceSuccess.getGroupOuputs(ARP_FLOW_DEVICE).get(0)
141 .getFinalPacket().getCriterion(Criterion.Type.VLAN_VID));
Andrea Campanella54923d62018-01-23 12:46:04 +0100142 log.info("trace {}", traceSuccess.resultMessage());
143 }
144
Andrea Campanella7d3cf652018-01-22 15:10:30 +0100145
Andrea Campanellae4084402017-12-15 15:27:31 +0100146 /**
Andrea Campanella4401bd72018-01-18 16:54:34 +0100147 * Tests failure on device with no flows.
Andrea Campanellae4084402017-12-15 15:27:31 +0100148 */
149 @Test
150 public void noFlows() {
151 StaticPacketTrace traceFail = mngr.trace(PACKET_OK, ConnectPoint.deviceConnectPoint("test/1"));
152 assertNotNull("Trace should not be null", traceFail);
153 assertNull("Trace should have 0 output", traceFail.getGroupOuputs(SINGLE_FLOW_DEVICE));
154 log.info("trace {}", traceFail.resultMessage());
155 }
156
157 /**
158 * Test a single flow rule that has output port in it.
159 */
160 @Test
161 public void testSingleFlowRule() {
162
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100163 testSuccess(PACKET_OK, SINGLE_FLOW_IN_CP, SINGLE_FLOW_DEVICE, SINGLE_FLOW_OUT_CP, 1, 1);
Andrea Campanellae4084402017-12-15 15:27:31 +0100164
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100165 testFailure(PACKET_FAIL, SINGLE_FLOW_IN_CP, SINGLE_FLOW_DEVICE);
Andrea Campanellae4084402017-12-15 15:27:31 +0100166 }
167
168 /**
169 * Tests two flow rule the last one of which has output port in it.
170 */
171 @Test
172 public void testDualFlowRule() {
173
174 //Test Success
175
Andrea Campanella4401bd72018-01-18 16:54:34 +0100176 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, DUAL_FLOW_IN_CP, DUAL_FLOW_DEVICE,
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100177 DUAL_FLOW_OUT_CP, 1, 1);
Andrea Campanellae4084402017-12-15 15:27:31 +0100178
179 //Testing Vlan
180 Criterion criterion = traceSuccess.getGroupOuputs(DUAL_FLOW_DEVICE).get(0).
181 getFinalPacket().getCriterion(Criterion.Type.VLAN_VID);
182 assertNotNull("Packet Should have Vlan", criterion);
183
184 VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) criterion;
185
186 assertEquals("Vlan should be 100", VlanId.vlanId((short) 100), vlanIdCriterion.vlanId());
187
188 //Test Faliure
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100189 testFailure(PACKET_FAIL, DUAL_FLOW_IN_CP, DUAL_FLOW_DEVICE);
Andrea Campanellae4084402017-12-15 15:27:31 +0100190
191 }
192
193 /**
194 * Test a single flow rule that points to a group with output port in it.
195 */
196 @Test
197 public void flowAndGroup() throws Exception {
198
Andrea Campanella4401bd72018-01-18 16:54:34 +0100199 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, GROUP_FLOW_IN_CP, GROUP_FLOW_DEVICE,
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100200 GROUP_FLOW_OUT_CP, 1, 1);
Andrea Campanellae4084402017-12-15 15:27:31 +0100201
202 assertTrue("Wrong Output Group", traceSuccess.getGroupOuputs(GROUP_FLOW_DEVICE)
203 .get(0).getGroups().contains(GROUP));
Andrea Campanella3970e472018-01-25 16:44:04 +0100204 assertEquals("Packet should not have MPLS Label", EthType.EtherType.IPV4.ethType(),
205 ((EthTypeCriterion) traceSuccess.getGroupOuputs(GROUP_FLOW_DEVICE)
206 .get(0).getFinalPacket().getCriterion(Criterion.Type.ETH_TYPE)).ethType());
207 assertNull("Packet should not have MPLS Label", traceSuccess.getGroupOuputs(GROUP_FLOW_DEVICE)
208 .get(0).getFinalPacket().getCriterion(Criterion.Type.MPLS_LABEL));
209 assertNull("Packet should not have MPLS Label", traceSuccess.getGroupOuputs(GROUP_FLOW_DEVICE)
210 .get(0).getFinalPacket().getCriterion(Criterion.Type.MPLS_BOS));
Andrea Campanellae4084402017-12-15 15:27:31 +0100211
212 }
213
214 /**
215 * Test path through a 3 device topology.
216 */
217 @Test
218 public void singlePathTopology() throws Exception {
219
220 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK_TOPO, TOPO_FLOW_1_IN_CP,
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100221 TOPO_FLOW_3_DEVICE, TOPO_FLOW_3_OUT_CP, 1, 1);
Andrea Campanellae4084402017-12-15 15:27:31 +0100222
223 assertTrue("Incorrect path",
224 traceSuccess.getCompletePaths().get(0).contains(TOPO_FLOW_2_IN_CP));
225 assertTrue("Incorrect path",
226 traceSuccess.getCompletePaths().get(0).contains(TOPO_FLOW_2_OUT_CP));
227 assertTrue("Incorrect path",
228 traceSuccess.getCompletePaths().get(0).contains(TOPO_FLOW_3_IN_CP));
229
230 }
231
232 /**
233 * Test path through a 4 device topology with first device that has groups with multiple output buckets.
234 */
235 @Test
236 public void testGroupTopo() throws Exception {
237
238 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK_TOPO, TOPO_FLOW_IN_CP,
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100239 TOPO_FLOW_3_DEVICE, TOPO_FLOW_3_OUT_CP, 2, 1);
240
241 log.info("{}", traceSuccess);
Andrea Campanellae4084402017-12-15 15:27:31 +0100242
243 assertTrue("Incorrect groups",
244 traceSuccess.getGroupOuputs(TOPO_GROUP_FLOW_DEVICE).get(0).getGroups().contains(TOPO_GROUP));
245 assertTrue("Incorrect bucket",
246 traceSuccess.getGroupOuputs(TOPO_GROUP_FLOW_DEVICE).get(1).getGroups().contains(TOPO_GROUP));
247 }
248
249 /**
250 * Test HW support in a single device with 2 flow rules to check hit of static HW rules.
251 */
252 @Test
253 public void hardwareTest() throws Exception {
254
255 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, HARDWARE_DEVICE_IN_CP,
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100256 HARDWARE_DEVICE, HARDWARE_DEVICE_OUT_CP, 1, 1);
Andrea Campanellae4084402017-12-15 15:27:31 +0100257
258 assertEquals("wrong ETH type", EthType.EtherType.IPV4.ethType(),
259 ((EthTypeCriterion) traceSuccess.getGroupOuputs(HARDWARE_DEVICE).get(0).getFinalPacket()
260 .getCriterion(Criterion.Type.ETH_TYPE)).ethType());
261
262 }
263
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100264 /**
265 * Test dual links between 3 topology elements.
266 */
267 @Test
268 public void dualLinks() throws Exception {
269
270 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, DUAL_LINK_1_CP_1_IN,
271 DUAL_LINK_3, DUAL_LINK_3_CP_3_OUT, 4, 1);
272
273 //TODO tests
274
275 }
276
Andrea Campanella8292ba62018-01-31 16:43:23 +0100277 /**
278 * Test proper clear deferred behaviour.
279 */
280 @Test
281 public void clearDeferred() throws Exception {
282
283 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, DEFERRED_CP_1_IN,
284 DEFERRED_1, DEFERRED_CP_2_OUT, 1, 1);
285
286 assertNull("MPLS should have been not applied due to clear deferred", traceSuccess
287 .getGroupOuputs(DEFERRED_1).get(0).getFinalPacket().getCriterion(Criterion.Type.MPLS_LABEL));
288
289 }
290
291
Andrea Campanellae4084402017-12-15 15:27:31 +0100292 private StaticPacketTrace testSuccess(TrafficSelector packet, ConnectPoint in, DeviceId deviceId, ConnectPoint out,
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100293 int paths, int outputs) {
Andrea Campanellae4084402017-12-15 15:27:31 +0100294 StaticPacketTrace traceSuccess = mngr.trace(packet, in);
295
296 log.info("trace {}", traceSuccess);
297
298 log.info("trace {}", traceSuccess.resultMessage());
299
300 assertNotNull("trace should not be null", traceSuccess);
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100301 assertEquals("Trace should have " + outputs + " output", outputs,
302 traceSuccess.getGroupOuputs(deviceId).size());
Andrea Campanellae4084402017-12-15 15:27:31 +0100303 assertEquals("Trace should only have " + paths + "output", paths, traceSuccess.getCompletePaths().size());
304 assertTrue("Trace should be successful",
305 traceSuccess.resultMessage().contains("Reached required destination Host"));
306 assertEquals("Incorrect Output CP", out,
307 traceSuccess.getGroupOuputs(deviceId).get(0).getOutput());
308
309 return traceSuccess;
310 }
311
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100312 private void testFailure(TrafficSelector packet, ConnectPoint in, DeviceId deviceId) {
Andrea Campanellae4084402017-12-15 15:27:31 +0100313 StaticPacketTrace traceFail = mngr.trace(packet, in);
314
315 log.info("trace {}", traceFail.resultMessage());
316
317 assertNotNull("Trace should not be null", traceFail);
318 assertNull("Trace should have 0 output", traceFail.getGroupOuputs(deviceId));
319 }
320
321 private class TestFlowRuleService extends FlowRuleServiceAdapter {
322 @Override
323 public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) {
324 if (deviceId.equals(SINGLE_FLOW_DEVICE)) {
325 return ImmutableList.of(SINGLE_FLOW_ENTRY);
326 } else if (deviceId.equals(DUAL_FLOW_DEVICE)) {
327 return ImmutableList.of(FIRST_FLOW_ENTRY, SECOND_FLOW_ENTRY);
328 } else if (deviceId.equals(GROUP_FLOW_DEVICE)) {
329 return ImmutableList.of(GROUP_FLOW_ENTRY);
330 } else if (deviceId.equals(TOPO_FLOW_DEVICE) ||
331 deviceId.equals(TOPO_FLOW_2_DEVICE) ||
332 deviceId.equals(TOPO_FLOW_3_DEVICE) ||
333 deviceId.equals(TOPO_FLOW_4_DEVICE)) {
334 return ImmutableList.of(TOPO_SINGLE_FLOW_ENTRY, TOPO_SECOND_INPUT_FLOW_ENTRY);
335 } else if (deviceId.equals(TOPO_GROUP_FLOW_DEVICE)) {
336 return ImmutableList.of(TOPO_GROUP_FLOW_ENTRY);
Andrea Campanella4401bd72018-01-18 16:54:34 +0100337 } else if (deviceId.equals(HARDWARE_DEVICE)) {
Andrea Campanellae4084402017-12-15 15:27:31 +0100338 return ImmutableList.of(HARDWARE_ETH_FLOW_ENTRY, HARDWARE_FLOW_ENTRY);
Andrea Campanella7d3cf652018-01-22 15:10:30 +0100339 } else if (deviceId.equals(SAME_OUTPUT_FLOW_DEVICE)) {
340 return ImmutableList.of(SAME_OUTPUT_FLOW_ENTRY);
Andrea Campanella54923d62018-01-23 12:46:04 +0100341 } else if (deviceId.equals(ARP_FLOW_DEVICE)) {
342 return ImmutableList.of(ARP_FLOW_ENTRY);
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100343 } else if (deviceId.equals(DUAL_LINK_1)) {
344 return ImmutableList.of(DUAL_LINK_1_GROUP_FLOW_ENTRY);
345 } else if (deviceId.equals(DUAL_LINK_2)) {
346 return ImmutableList.of(DUAL_LINK_1_GROUP_FLOW_ENTRY, DUAL_LINK_2_GROUP_FLOW_ENTRY);
347 } else if (deviceId.equals(DUAL_LINK_3)) {
348 return ImmutableList.of(DUAL_LINK_3_FLOW_ENTRY, DUAL_LINK_3_FLOW_ENTRY_2);
Andrea Campanella8292ba62018-01-31 16:43:23 +0100349 } else if (deviceId.equals(DEFERRED_1)) {
350 return ImmutableList.of(DEFERRED_FLOW_ENTRY, DEFERRED_CLEAR_FLOW_ENTRY);
Andrea Campanellae4084402017-12-15 15:27:31 +0100351 }
352 return ImmutableList.of();
353 }
354 }
355
356 private class TestDriverService extends DriverServiceAdapter {
357 @Override
358 public Driver getDriver(DeviceId deviceId) {
Andrea Campanella4401bd72018-01-18 16:54:34 +0100359 if (deviceId.equals(HARDWARE_DEVICE)) {
Andrea Campanellae4084402017-12-15 15:27:31 +0100360 return new DefaultDriver("ofdpa", ImmutableList.of(),
361 "test", "test", "test", new HashMap<>(), new HashMap<>());
362 }
363 return new DefaultDriver("NotHWDriver", ImmutableList.of(),
364 "test", "test", "test", new HashMap<>(), new HashMap<>());
365 }
366 }
367
368 private class TestGroupService extends GroupServiceAdapter {
369 @Override
370 public Iterable<Group> getGroups(DeviceId deviceId) {
371 if (deviceId.equals(GROUP_FLOW_DEVICE)) {
372 return ImmutableList.of(GROUP);
373 } else if (deviceId.equals(TOPO_GROUP_FLOW_DEVICE)) {
374 return ImmutableList.of(TOPO_GROUP);
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100375 } else if (deviceId.equals(DUAL_LINK_1) || deviceId.equals(DUAL_LINK_2)) {
376 return ImmutableList.of(DUAL_LINK_GROUP);
Andrea Campanellae4084402017-12-15 15:27:31 +0100377 }
378 return ImmutableList.of();
379 }
380 }
381
382 private class TestHostService extends HostServiceAdapter {
383 @Override
384 public Set<Host> getConnectedHosts(ConnectPoint connectPoint) {
385 if (connectPoint.equals(TOPO_FLOW_3_OUT_CP)) {
386 return ImmutableSet.of(H2);
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100387 } else if (connectPoint.equals(DUAL_LINK_1_CP_2_OUT) || connectPoint.equals(DUAL_LINK_1_CP_3_OUT) ||
388 connectPoint.equals(DUAL_LINK_2_CP_2_OUT) || connectPoint.equals(DUAL_LINK_2_CP_3_OUT)) {
389 return ImmutableSet.of();
Andrea Campanellae4084402017-12-15 15:27:31 +0100390 }
391 return ImmutableSet.of(H1);
392 }
393
394 @Override
395 public Set<Host> getHostsByMac(MacAddress mac) {
396 if (mac.equals(H1.mac())) {
397 return ImmutableSet.of(H1);
398 } else if (mac.equals(H2.mac())) {
399 return ImmutableSet.of(H2);
400 }
401 return ImmutableSet.of();
402 }
403
404 @Override
405 public Set<Host> getHostsByIp(IpAddress ip) {
406 if ((H1.ipAddresses().contains(ip))) {
407 return ImmutableSet.of(H1);
408 } else if ((H2.ipAddresses().contains(ip))) {
409 return ImmutableSet.of(H2);
410 }
411 return ImmutableSet.of();
412 }
413 }
414
415 private class TestLinkService extends LinkServiceAdapter {
416 @Override
417 public Set<Link> getEgressLinks(ConnectPoint connectPoint) {
418 if (connectPoint.equals(TOPO_FLOW_1_OUT_CP)
419 || connectPoint.equals(TOPO_FLOW_OUT_CP_1)) {
420 return ImmutableSet.of(DefaultLink.builder()
421 .providerId(ProviderId.NONE)
422 .type(Link.Type.DIRECT)
423 .src(connectPoint)
424 .dst(TOPO_FLOW_2_IN_CP)
425 .build());
426 } else if (connectPoint.equals(TOPO_FLOW_2_OUT_CP)) {
427 return ImmutableSet.of(DefaultLink.builder()
428 .providerId(ProviderId.NONE)
429 .type(Link.Type.DIRECT)
430 .src(TOPO_FLOW_2_OUT_CP)
431 .dst(TOPO_FLOW_3_IN_CP)
432 .build());
433 } else if (connectPoint.equals(TOPO_FLOW_OUT_CP_2)) {
434 return ImmutableSet.of(DefaultLink.builder()
435 .providerId(ProviderId.NONE)
436 .type(Link.Type.DIRECT)
437 .src(TOPO_FLOW_OUT_CP_2)
438 .dst(TOPO_FLOW_4_IN_CP)
439 .build());
440 } else if (connectPoint.equals(TOPO_FLOW_4_OUT_CP)) {
441 return ImmutableSet.of(DefaultLink.builder()
442 .providerId(ProviderId.NONE)
443 .type(Link.Type.DIRECT)
444 .src(TOPO_FLOW_4_OUT_CP)
445 .dst(TOPO_FLOW_3_IN_2_CP)
446 .build());
Andrea Campanellab022b5e2018-01-31 14:59:03 +0100447 } else if (connectPoint.equals(DUAL_LINK_1_CP_2_OUT)) {
448 return ImmutableSet.of(DefaultLink.builder()
449 .providerId(ProviderId.NONE)
450 .type(Link.Type.DIRECT)
451 .src(DUAL_LINK_1_CP_2_OUT)
452 .dst(DUAL_LINK_2_CP_1_IN)
453 .build());
454 } else if (connectPoint.equals(DUAL_LINK_1_CP_3_OUT)) {
455 return ImmutableSet.of(DefaultLink.builder()
456 .providerId(ProviderId.NONE)
457 .type(Link.Type.DIRECT)
458 .src(DUAL_LINK_1_CP_3_OUT)
459 .dst(DUAL_LINK_2_CP_4_IN)
460 .build());
461 } else if (connectPoint.equals(DUAL_LINK_2_CP_2_OUT)) {
462 return ImmutableSet.of(DefaultLink.builder()
463 .providerId(ProviderId.NONE)
464 .type(Link.Type.DIRECT)
465 .src(DUAL_LINK_2_CP_2_OUT)
466 .dst(DUAL_LINK_3_CP_1_IN)
467 .build());
468 } else if (connectPoint.equals(DUAL_LINK_2_CP_3_OUT)) {
469 return ImmutableSet.of(DefaultLink.builder()
470 .providerId(ProviderId.NONE)
471 .type(Link.Type.DIRECT)
472 .src(DUAL_LINK_2_CP_3_OUT)
473 .dst(DUAL_LINK_3_CP_2_IN)
474 .build());
Andrea Campanellae4084402017-12-15 15:27:31 +0100475 }
476 return ImmutableSet.of();
477 }
478 }
Andrea Campanella17d45192018-01-18 17:11:42 +0100479
480 private class TestDeviceService extends DeviceServiceAdapter {
481 @Override
482 public Device getDevice(DeviceId deviceId) {
483 if (deviceId.equals(DeviceId.deviceId("nonexistent"))) {
484 return null;
485 }
486 return new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("test"), SWITCH,
487 "test", "test", "test", "test", new ChassisId(),
488 DefaultAnnotations.builder().set("foo", "bar").build());
489 }
490
491 @Override
492 public boolean isAvailable(DeviceId deviceId) {
493 if (deviceId.equals(OFFLINE_DEVICE)) {
494 return false;
495 }
496 return true;
497 }
498 }
Andrea Campanella54923d62018-01-23 12:46:04 +0100499
500 private class TestMastershipService extends MastershipServiceAdapter {
501 @Override
502 public NodeId getMasterFor(DeviceId deviceId) {
503 return NodeId.nodeId(MASTER_1);
504 }
505 }
Andrea Campanellae4084402017-12-15 15:27:31 +0100506}