blob: d7d3f33b060e002e90bd8c1eb9fd305072acb115 [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 Campanella01e886e2017-12-15 15:27:31 +0100275 private StaticPacketTrace testSuccess(TrafficSelector packet, ConnectPoint in, DeviceId deviceId, ConnectPoint out,
Andrea Campanellae04aac92018-01-31 14:59:03 +0100276 int paths, int outputs) {
Andrea Campanella01e886e2017-12-15 15:27:31 +0100277 StaticPacketTrace traceSuccess = mngr.trace(packet, in);
278
279 log.info("trace {}", traceSuccess);
280
281 log.info("trace {}", traceSuccess.resultMessage());
282
283 assertNotNull("trace should not be null", traceSuccess);
Andrea Campanellae04aac92018-01-31 14:59:03 +0100284 assertEquals("Trace should have " + outputs + " output", outputs,
285 traceSuccess.getGroupOuputs(deviceId).size());
Andrea Campanella01e886e2017-12-15 15:27:31 +0100286 assertEquals("Trace should only have " + paths + "output", paths, traceSuccess.getCompletePaths().size());
287 assertTrue("Trace should be successful",
288 traceSuccess.resultMessage().contains("Reached required destination Host"));
289 assertEquals("Incorrect Output CP", out,
290 traceSuccess.getGroupOuputs(deviceId).get(0).getOutput());
291
292 return traceSuccess;
293 }
294
Andrea Campanellae04aac92018-01-31 14:59:03 +0100295 private void testFailure(TrafficSelector packet, ConnectPoint in, DeviceId deviceId) {
Andrea Campanella01e886e2017-12-15 15:27:31 +0100296 StaticPacketTrace traceFail = mngr.trace(packet, in);
297
298 log.info("trace {}", traceFail.resultMessage());
299
300 assertNotNull("Trace should not be null", traceFail);
301 assertNull("Trace should have 0 output", traceFail.getGroupOuputs(deviceId));
302 }
303
304 private class TestFlowRuleService extends FlowRuleServiceAdapter {
305 @Override
306 public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) {
307 if (deviceId.equals(SINGLE_FLOW_DEVICE)) {
308 return ImmutableList.of(SINGLE_FLOW_ENTRY);
309 } else if (deviceId.equals(DUAL_FLOW_DEVICE)) {
310 return ImmutableList.of(FIRST_FLOW_ENTRY, SECOND_FLOW_ENTRY);
311 } else if (deviceId.equals(GROUP_FLOW_DEVICE)) {
312 return ImmutableList.of(GROUP_FLOW_ENTRY);
313 } else if (deviceId.equals(TOPO_FLOW_DEVICE) ||
314 deviceId.equals(TOPO_FLOW_2_DEVICE) ||
315 deviceId.equals(TOPO_FLOW_3_DEVICE) ||
316 deviceId.equals(TOPO_FLOW_4_DEVICE)) {
317 return ImmutableList.of(TOPO_SINGLE_FLOW_ENTRY, TOPO_SECOND_INPUT_FLOW_ENTRY);
318 } else if (deviceId.equals(TOPO_GROUP_FLOW_DEVICE)) {
319 return ImmutableList.of(TOPO_GROUP_FLOW_ENTRY);
Andrea Campanella2bc55dd2018-01-18 16:54:34 +0100320 } else if (deviceId.equals(HARDWARE_DEVICE)) {
Andrea Campanella01e886e2017-12-15 15:27:31 +0100321 return ImmutableList.of(HARDWARE_ETH_FLOW_ENTRY, HARDWARE_FLOW_ENTRY);
Andrea Campanellabb9d3fb2018-01-22 15:10:30 +0100322 } else if (deviceId.equals(SAME_OUTPUT_FLOW_DEVICE)) {
323 return ImmutableList.of(SAME_OUTPUT_FLOW_ENTRY);
Andrea Campanella7c8e7912018-01-23 12:46:04 +0100324 } else if (deviceId.equals(ARP_FLOW_DEVICE)) {
325 return ImmutableList.of(ARP_FLOW_ENTRY);
Andrea Campanellae04aac92018-01-31 14:59:03 +0100326 } else if (deviceId.equals(DUAL_LINK_1)) {
327 return ImmutableList.of(DUAL_LINK_1_GROUP_FLOW_ENTRY);
328 } else if (deviceId.equals(DUAL_LINK_2)) {
329 return ImmutableList.of(DUAL_LINK_1_GROUP_FLOW_ENTRY, DUAL_LINK_2_GROUP_FLOW_ENTRY);
330 } else if (deviceId.equals(DUAL_LINK_3)) {
331 return ImmutableList.of(DUAL_LINK_3_FLOW_ENTRY, DUAL_LINK_3_FLOW_ENTRY_2);
Andrea Campanella01e886e2017-12-15 15:27:31 +0100332 }
333 return ImmutableList.of();
334 }
335 }
336
337 private class TestDriverService extends DriverServiceAdapter {
338 @Override
339 public Driver getDriver(DeviceId deviceId) {
Andrea Campanella2bc55dd2018-01-18 16:54:34 +0100340 if (deviceId.equals(HARDWARE_DEVICE)) {
Andrea Campanella01e886e2017-12-15 15:27:31 +0100341 return new DefaultDriver("ofdpa", ImmutableList.of(),
342 "test", "test", "test", new HashMap<>(), new HashMap<>());
343 }
344 return new DefaultDriver("NotHWDriver", ImmutableList.of(),
345 "test", "test", "test", new HashMap<>(), new HashMap<>());
346 }
347 }
348
349 private class TestGroupService extends GroupServiceAdapter {
350 @Override
351 public Iterable<Group> getGroups(DeviceId deviceId) {
352 if (deviceId.equals(GROUP_FLOW_DEVICE)) {
353 return ImmutableList.of(GROUP);
354 } else if (deviceId.equals(TOPO_GROUP_FLOW_DEVICE)) {
355 return ImmutableList.of(TOPO_GROUP);
Andrea Campanellae04aac92018-01-31 14:59:03 +0100356 } else if (deviceId.equals(DUAL_LINK_1) || deviceId.equals(DUAL_LINK_2)) {
357 return ImmutableList.of(DUAL_LINK_GROUP);
Andrea Campanella01e886e2017-12-15 15:27:31 +0100358 }
359 return ImmutableList.of();
360 }
361 }
362
363 private class TestHostService extends HostServiceAdapter {
364 @Override
365 public Set<Host> getConnectedHosts(ConnectPoint connectPoint) {
366 if (connectPoint.equals(TOPO_FLOW_3_OUT_CP)) {
367 return ImmutableSet.of(H2);
Andrea Campanellae04aac92018-01-31 14:59:03 +0100368 } else if (connectPoint.equals(DUAL_LINK_1_CP_2_OUT) || connectPoint.equals(DUAL_LINK_1_CP_3_OUT) ||
369 connectPoint.equals(DUAL_LINK_2_CP_2_OUT) || connectPoint.equals(DUAL_LINK_2_CP_3_OUT)) {
370 return ImmutableSet.of();
Andrea Campanella01e886e2017-12-15 15:27:31 +0100371 }
372 return ImmutableSet.of(H1);
373 }
374
375 @Override
376 public Set<Host> getHostsByMac(MacAddress mac) {
377 if (mac.equals(H1.mac())) {
378 return ImmutableSet.of(H1);
379 } else if (mac.equals(H2.mac())) {
380 return ImmutableSet.of(H2);
381 }
382 return ImmutableSet.of();
383 }
384
385 @Override
386 public Set<Host> getHostsByIp(IpAddress ip) {
387 if ((H1.ipAddresses().contains(ip))) {
388 return ImmutableSet.of(H1);
389 } else if ((H2.ipAddresses().contains(ip))) {
390 return ImmutableSet.of(H2);
391 }
392 return ImmutableSet.of();
393 }
394 }
395
396 private class TestLinkService extends LinkServiceAdapter {
397 @Override
398 public Set<Link> getEgressLinks(ConnectPoint connectPoint) {
399 if (connectPoint.equals(TOPO_FLOW_1_OUT_CP)
400 || connectPoint.equals(TOPO_FLOW_OUT_CP_1)) {
401 return ImmutableSet.of(DefaultLink.builder()
402 .providerId(ProviderId.NONE)
403 .type(Link.Type.DIRECT)
404 .src(connectPoint)
405 .dst(TOPO_FLOW_2_IN_CP)
406 .build());
407 } else if (connectPoint.equals(TOPO_FLOW_2_OUT_CP)) {
408 return ImmutableSet.of(DefaultLink.builder()
409 .providerId(ProviderId.NONE)
410 .type(Link.Type.DIRECT)
411 .src(TOPO_FLOW_2_OUT_CP)
412 .dst(TOPO_FLOW_3_IN_CP)
413 .build());
414 } else if (connectPoint.equals(TOPO_FLOW_OUT_CP_2)) {
415 return ImmutableSet.of(DefaultLink.builder()
416 .providerId(ProviderId.NONE)
417 .type(Link.Type.DIRECT)
418 .src(TOPO_FLOW_OUT_CP_2)
419 .dst(TOPO_FLOW_4_IN_CP)
420 .build());
421 } else if (connectPoint.equals(TOPO_FLOW_4_OUT_CP)) {
422 return ImmutableSet.of(DefaultLink.builder()
423 .providerId(ProviderId.NONE)
424 .type(Link.Type.DIRECT)
425 .src(TOPO_FLOW_4_OUT_CP)
426 .dst(TOPO_FLOW_3_IN_2_CP)
427 .build());
Andrea Campanellae04aac92018-01-31 14:59:03 +0100428 } else if (connectPoint.equals(DUAL_LINK_1_CP_2_OUT)) {
429 return ImmutableSet.of(DefaultLink.builder()
430 .providerId(ProviderId.NONE)
431 .type(Link.Type.DIRECT)
432 .src(DUAL_LINK_1_CP_2_OUT)
433 .dst(DUAL_LINK_2_CP_1_IN)
434 .build());
435 } else if (connectPoint.equals(DUAL_LINK_1_CP_3_OUT)) {
436 return ImmutableSet.of(DefaultLink.builder()
437 .providerId(ProviderId.NONE)
438 .type(Link.Type.DIRECT)
439 .src(DUAL_LINK_1_CP_3_OUT)
440 .dst(DUAL_LINK_2_CP_4_IN)
441 .build());
442 } else if (connectPoint.equals(DUAL_LINK_2_CP_2_OUT)) {
443 return ImmutableSet.of(DefaultLink.builder()
444 .providerId(ProviderId.NONE)
445 .type(Link.Type.DIRECT)
446 .src(DUAL_LINK_2_CP_2_OUT)
447 .dst(DUAL_LINK_3_CP_1_IN)
448 .build());
449 } else if (connectPoint.equals(DUAL_LINK_2_CP_3_OUT)) {
450 return ImmutableSet.of(DefaultLink.builder()
451 .providerId(ProviderId.NONE)
452 .type(Link.Type.DIRECT)
453 .src(DUAL_LINK_2_CP_3_OUT)
454 .dst(DUAL_LINK_3_CP_2_IN)
455 .build());
Andrea Campanella01e886e2017-12-15 15:27:31 +0100456 }
457 return ImmutableSet.of();
458 }
459 }
Andrea Campanella37d10622018-01-18 17:11:42 +0100460
461 private class TestDeviceService extends DeviceServiceAdapter {
462 @Override
463 public Device getDevice(DeviceId deviceId) {
464 if (deviceId.equals(DeviceId.deviceId("nonexistent"))) {
465 return null;
466 }
467 return new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("test"), SWITCH,
468 "test", "test", "test", "test", new ChassisId(),
469 DefaultAnnotations.builder().set("foo", "bar").build());
470 }
471
472 @Override
473 public boolean isAvailable(DeviceId deviceId) {
474 if (deviceId.equals(OFFLINE_DEVICE)) {
475 return false;
476 }
477 return true;
478 }
479 }
Andrea Campanella7c8e7912018-01-23 12:46:04 +0100480
481 private class TestMastershipService extends MastershipServiceAdapter {
482 @Override
483 public NodeId getMasterFor(DeviceId deviceId) {
484 return NodeId.nodeId(MASTER_1);
485 }
486 }
Andrea Campanella01e886e2017-12-15 15:27:31 +0100487}