blob: 9767730d9a0c5ff15106a8d58ced3d813706abdc [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());
Andrea Campanella58b3b522018-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 Campanella7c8e7912018-01-23 12:46:04 +0100142 log.info("trace {}", traceSuccess.resultMessage());
143 }
144
Andrea Campanellabb9d3fb2018-01-22 15:10:30 +0100145
Andrea Campanella01e886e2017-12-15 15:27:31 +0100146 /**
Andrea Campanella2bc55dd2018-01-18 16:54:34 +0100147 * Tests failure on device with no flows.
Andrea Campanella01e886e2017-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 Campanellae04aac92018-01-31 14:59:03 +0100163 testSuccess(PACKET_OK, SINGLE_FLOW_IN_CP, SINGLE_FLOW_DEVICE, SINGLE_FLOW_OUT_CP, 1, 1);
Andrea Campanella01e886e2017-12-15 15:27:31 +0100164
Andrea Campanellae04aac92018-01-31 14:59:03 +0100165 testFailure(PACKET_FAIL, SINGLE_FLOW_IN_CP, SINGLE_FLOW_DEVICE);
Andrea Campanella01e886e2017-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 Campanella2bc55dd2018-01-18 16:54:34 +0100176 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, DUAL_FLOW_IN_CP, DUAL_FLOW_DEVICE,
Andrea Campanellae04aac92018-01-31 14:59:03 +0100177 DUAL_FLOW_OUT_CP, 1, 1);
Andrea Campanella01e886e2017-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 Campanellae04aac92018-01-31 14:59:03 +0100189 testFailure(PACKET_FAIL, DUAL_FLOW_IN_CP, DUAL_FLOW_DEVICE);
Andrea Campanella01e886e2017-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 Campanella2bc55dd2018-01-18 16:54:34 +0100199 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, GROUP_FLOW_IN_CP, GROUP_FLOW_DEVICE,
Andrea Campanellae04aac92018-01-31 14:59:03 +0100200 GROUP_FLOW_OUT_CP, 1, 1);
Andrea Campanella01e886e2017-12-15 15:27:31 +0100201
202 assertTrue("Wrong Output Group", traceSuccess.getGroupOuputs(GROUP_FLOW_DEVICE)
203 .get(0).getGroups().contains(GROUP));
Andrea Campanella09ca07a2018-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 Campanella01e886e2017-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 Campanellae04aac92018-01-31 14:59:03 +0100221 TOPO_FLOW_3_DEVICE, TOPO_FLOW_3_OUT_CP, 1, 1);
Andrea Campanella01e886e2017-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 Campanellae04aac92018-01-31 14:59:03 +0100239 TOPO_FLOW_3_DEVICE, TOPO_FLOW_3_OUT_CP, 2, 1);
240
241 log.info("{}", traceSuccess);
Andrea Campanella01e886e2017-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 Campanellae04aac92018-01-31 14:59:03 +0100256 HARDWARE_DEVICE, HARDWARE_DEVICE_OUT_CP, 1, 1);
Andrea Campanella01e886e2017-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 Campanellae04aac92018-01-31 14:59:03 +0100264 /**
Andrea Campanella97f9d4c2018-02-06 18:58:40 +0100265 * Test that HW has two rules on table 10 for untagged packets.
266 */
267 @Test
268 public void hardwareTable10Test() throws Exception {
269
270 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, HARDWARE_DEVICE_10_IN_CP,
271 HARDWARE_DEVICE_10, HARDWARE_DEVICE_10_OUT_CP, 1, 1);
272
273 assertTrue("Second flow rule is absent", traceSuccess.getFlowsForDevice(HARDWARE_DEVICE_10)
274 .contains(HARDWARE_10_SECOND_FLOW_ENTRY));
275
276 }
277
278 /**
Andrea Campanellae04aac92018-01-31 14:59:03 +0100279 * Test dual links between 3 topology elements.
280 */
281 @Test
282 public void dualLinks() throws Exception {
283
284 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, DUAL_LINK_1_CP_1_IN,
285 DUAL_LINK_3, DUAL_LINK_3_CP_3_OUT, 4, 1);
286
287 //TODO tests
288
289 }
290
Andrea Campanellad5bb2ef2018-01-31 16:43:23 +0100291 /**
292 * Test proper clear deferred behaviour.
293 */
294 @Test
295 public void clearDeferred() throws Exception {
296
297 StaticPacketTrace traceSuccess = testSuccess(PACKET_OK, DEFERRED_CP_1_IN,
298 DEFERRED_1, DEFERRED_CP_2_OUT, 1, 1);
299
300 assertNull("MPLS should have been not applied due to clear deferred", traceSuccess
301 .getGroupOuputs(DEFERRED_1).get(0).getFinalPacket().getCriterion(Criterion.Type.MPLS_LABEL));
302
303 }
304
305
Andrea Campanella01e886e2017-12-15 15:27:31 +0100306 private StaticPacketTrace testSuccess(TrafficSelector packet, ConnectPoint in, DeviceId deviceId, ConnectPoint out,
Andrea Campanellae04aac92018-01-31 14:59:03 +0100307 int paths, int outputs) {
Andrea Campanella01e886e2017-12-15 15:27:31 +0100308 StaticPacketTrace traceSuccess = mngr.trace(packet, in);
309
310 log.info("trace {}", traceSuccess);
311
312 log.info("trace {}", traceSuccess.resultMessage());
313
314 assertNotNull("trace should not be null", traceSuccess);
Andrea Campanellae04aac92018-01-31 14:59:03 +0100315 assertEquals("Trace should have " + outputs + " output", outputs,
316 traceSuccess.getGroupOuputs(deviceId).size());
Andrea Campanella01e886e2017-12-15 15:27:31 +0100317 assertEquals("Trace should only have " + paths + "output", paths, traceSuccess.getCompletePaths().size());
318 assertTrue("Trace should be successful",
319 traceSuccess.resultMessage().contains("Reached required destination Host"));
320 assertEquals("Incorrect Output CP", out,
321 traceSuccess.getGroupOuputs(deviceId).get(0).getOutput());
322
323 return traceSuccess;
324 }
325
Andrea Campanellae04aac92018-01-31 14:59:03 +0100326 private void testFailure(TrafficSelector packet, ConnectPoint in, DeviceId deviceId) {
Andrea Campanella01e886e2017-12-15 15:27:31 +0100327 StaticPacketTrace traceFail = mngr.trace(packet, in);
328
329 log.info("trace {}", traceFail.resultMessage());
330
331 assertNotNull("Trace should not be null", traceFail);
332 assertNull("Trace should have 0 output", traceFail.getGroupOuputs(deviceId));
333 }
334
335 private class TestFlowRuleService extends FlowRuleServiceAdapter {
336 @Override
337 public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) {
338 if (deviceId.equals(SINGLE_FLOW_DEVICE)) {
339 return ImmutableList.of(SINGLE_FLOW_ENTRY);
340 } else if (deviceId.equals(DUAL_FLOW_DEVICE)) {
341 return ImmutableList.of(FIRST_FLOW_ENTRY, SECOND_FLOW_ENTRY);
342 } else if (deviceId.equals(GROUP_FLOW_DEVICE)) {
343 return ImmutableList.of(GROUP_FLOW_ENTRY);
344 } else if (deviceId.equals(TOPO_FLOW_DEVICE) ||
345 deviceId.equals(TOPO_FLOW_2_DEVICE) ||
346 deviceId.equals(TOPO_FLOW_3_DEVICE) ||
347 deviceId.equals(TOPO_FLOW_4_DEVICE)) {
348 return ImmutableList.of(TOPO_SINGLE_FLOW_ENTRY, TOPO_SECOND_INPUT_FLOW_ENTRY);
349 } else if (deviceId.equals(TOPO_GROUP_FLOW_DEVICE)) {
350 return ImmutableList.of(TOPO_GROUP_FLOW_ENTRY);
Andrea Campanella2bc55dd2018-01-18 16:54:34 +0100351 } else if (deviceId.equals(HARDWARE_DEVICE)) {
Andrea Campanella01e886e2017-12-15 15:27:31 +0100352 return ImmutableList.of(HARDWARE_ETH_FLOW_ENTRY, HARDWARE_FLOW_ENTRY);
Andrea Campanellabb9d3fb2018-01-22 15:10:30 +0100353 } else if (deviceId.equals(SAME_OUTPUT_FLOW_DEVICE)) {
354 return ImmutableList.of(SAME_OUTPUT_FLOW_ENTRY);
Andrea Campanella7c8e7912018-01-23 12:46:04 +0100355 } else if (deviceId.equals(ARP_FLOW_DEVICE)) {
356 return ImmutableList.of(ARP_FLOW_ENTRY);
Andrea Campanellae04aac92018-01-31 14:59:03 +0100357 } else if (deviceId.equals(DUAL_LINK_1)) {
358 return ImmutableList.of(DUAL_LINK_1_GROUP_FLOW_ENTRY);
359 } else if (deviceId.equals(DUAL_LINK_2)) {
360 return ImmutableList.of(DUAL_LINK_1_GROUP_FLOW_ENTRY, DUAL_LINK_2_GROUP_FLOW_ENTRY);
361 } else if (deviceId.equals(DUAL_LINK_3)) {
362 return ImmutableList.of(DUAL_LINK_3_FLOW_ENTRY, DUAL_LINK_3_FLOW_ENTRY_2);
Andrea Campanellad5bb2ef2018-01-31 16:43:23 +0100363 } else if (deviceId.equals(DEFERRED_1)) {
364 return ImmutableList.of(DEFERRED_FLOW_ENTRY, DEFERRED_CLEAR_FLOW_ENTRY);
Andrea Campanella97f9d4c2018-02-06 18:58:40 +0100365 } else if (deviceId.equals(HARDWARE_DEVICE_10)) {
366 return ImmutableList.of(HARDWARE_10_FLOW_ENTRY, HARDWARE_10_SECOND_FLOW_ENTRY,
367 HARDWARE_10_OUTPUT_FLOW_ENTRY);
Andrea Campanella01e886e2017-12-15 15:27:31 +0100368 }
369 return ImmutableList.of();
370 }
371 }
372
373 private class TestDriverService extends DriverServiceAdapter {
374 @Override
375 public Driver getDriver(DeviceId deviceId) {
Andrea Campanella97f9d4c2018-02-06 18:58:40 +0100376 if (deviceId.equals(HARDWARE_DEVICE) || deviceId.equals(HARDWARE_DEVICE_10)) {
Andrea Campanella01e886e2017-12-15 15:27:31 +0100377 return new DefaultDriver("ofdpa", ImmutableList.of(),
378 "test", "test", "test", new HashMap<>(), new HashMap<>());
379 }
380 return new DefaultDriver("NotHWDriver", ImmutableList.of(),
381 "test", "test", "test", new HashMap<>(), new HashMap<>());
382 }
383 }
384
385 private class TestGroupService extends GroupServiceAdapter {
386 @Override
387 public Iterable<Group> getGroups(DeviceId deviceId) {
388 if (deviceId.equals(GROUP_FLOW_DEVICE)) {
389 return ImmutableList.of(GROUP);
390 } else if (deviceId.equals(TOPO_GROUP_FLOW_DEVICE)) {
391 return ImmutableList.of(TOPO_GROUP);
Andrea Campanellae04aac92018-01-31 14:59:03 +0100392 } else if (deviceId.equals(DUAL_LINK_1) || deviceId.equals(DUAL_LINK_2)) {
393 return ImmutableList.of(DUAL_LINK_GROUP);
Andrea Campanella01e886e2017-12-15 15:27:31 +0100394 }
395 return ImmutableList.of();
396 }
397 }
398
399 private class TestHostService extends HostServiceAdapter {
400 @Override
401 public Set<Host> getConnectedHosts(ConnectPoint connectPoint) {
402 if (connectPoint.equals(TOPO_FLOW_3_OUT_CP)) {
403 return ImmutableSet.of(H2);
Andrea Campanellae04aac92018-01-31 14:59:03 +0100404 } else if (connectPoint.equals(DUAL_LINK_1_CP_2_OUT) || connectPoint.equals(DUAL_LINK_1_CP_3_OUT) ||
405 connectPoint.equals(DUAL_LINK_2_CP_2_OUT) || connectPoint.equals(DUAL_LINK_2_CP_3_OUT)) {
406 return ImmutableSet.of();
Andrea Campanella01e886e2017-12-15 15:27:31 +0100407 }
408 return ImmutableSet.of(H1);
409 }
410
411 @Override
412 public Set<Host> getHostsByMac(MacAddress mac) {
413 if (mac.equals(H1.mac())) {
414 return ImmutableSet.of(H1);
415 } else if (mac.equals(H2.mac())) {
416 return ImmutableSet.of(H2);
417 }
418 return ImmutableSet.of();
419 }
420
421 @Override
422 public Set<Host> getHostsByIp(IpAddress ip) {
423 if ((H1.ipAddresses().contains(ip))) {
424 return ImmutableSet.of(H1);
425 } else if ((H2.ipAddresses().contains(ip))) {
426 return ImmutableSet.of(H2);
427 }
428 return ImmutableSet.of();
429 }
430 }
431
432 private class TestLinkService extends LinkServiceAdapter {
433 @Override
434 public Set<Link> getEgressLinks(ConnectPoint connectPoint) {
435 if (connectPoint.equals(TOPO_FLOW_1_OUT_CP)
436 || connectPoint.equals(TOPO_FLOW_OUT_CP_1)) {
437 return ImmutableSet.of(DefaultLink.builder()
438 .providerId(ProviderId.NONE)
439 .type(Link.Type.DIRECT)
440 .src(connectPoint)
441 .dst(TOPO_FLOW_2_IN_CP)
442 .build());
443 } else if (connectPoint.equals(TOPO_FLOW_2_OUT_CP)) {
444 return ImmutableSet.of(DefaultLink.builder()
445 .providerId(ProviderId.NONE)
446 .type(Link.Type.DIRECT)
447 .src(TOPO_FLOW_2_OUT_CP)
448 .dst(TOPO_FLOW_3_IN_CP)
449 .build());
450 } else if (connectPoint.equals(TOPO_FLOW_OUT_CP_2)) {
451 return ImmutableSet.of(DefaultLink.builder()
452 .providerId(ProviderId.NONE)
453 .type(Link.Type.DIRECT)
454 .src(TOPO_FLOW_OUT_CP_2)
455 .dst(TOPO_FLOW_4_IN_CP)
456 .build());
457 } else if (connectPoint.equals(TOPO_FLOW_4_OUT_CP)) {
458 return ImmutableSet.of(DefaultLink.builder()
459 .providerId(ProviderId.NONE)
460 .type(Link.Type.DIRECT)
461 .src(TOPO_FLOW_4_OUT_CP)
462 .dst(TOPO_FLOW_3_IN_2_CP)
463 .build());
Andrea Campanellae04aac92018-01-31 14:59:03 +0100464 } else if (connectPoint.equals(DUAL_LINK_1_CP_2_OUT)) {
465 return ImmutableSet.of(DefaultLink.builder()
466 .providerId(ProviderId.NONE)
467 .type(Link.Type.DIRECT)
468 .src(DUAL_LINK_1_CP_2_OUT)
469 .dst(DUAL_LINK_2_CP_1_IN)
470 .build());
471 } else if (connectPoint.equals(DUAL_LINK_1_CP_3_OUT)) {
472 return ImmutableSet.of(DefaultLink.builder()
473 .providerId(ProviderId.NONE)
474 .type(Link.Type.DIRECT)
475 .src(DUAL_LINK_1_CP_3_OUT)
476 .dst(DUAL_LINK_2_CP_4_IN)
477 .build());
478 } else if (connectPoint.equals(DUAL_LINK_2_CP_2_OUT)) {
479 return ImmutableSet.of(DefaultLink.builder()
480 .providerId(ProviderId.NONE)
481 .type(Link.Type.DIRECT)
482 .src(DUAL_LINK_2_CP_2_OUT)
483 .dst(DUAL_LINK_3_CP_1_IN)
484 .build());
485 } else if (connectPoint.equals(DUAL_LINK_2_CP_3_OUT)) {
486 return ImmutableSet.of(DefaultLink.builder()
487 .providerId(ProviderId.NONE)
488 .type(Link.Type.DIRECT)
489 .src(DUAL_LINK_2_CP_3_OUT)
490 .dst(DUAL_LINK_3_CP_2_IN)
491 .build());
Andrea Campanella01e886e2017-12-15 15:27:31 +0100492 }
493 return ImmutableSet.of();
494 }
495 }
Andrea Campanella37d10622018-01-18 17:11:42 +0100496
497 private class TestDeviceService extends DeviceServiceAdapter {
498 @Override
499 public Device getDevice(DeviceId deviceId) {
500 if (deviceId.equals(DeviceId.deviceId("nonexistent"))) {
501 return null;
502 }
503 return new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("test"), SWITCH,
504 "test", "test", "test", "test", new ChassisId(),
505 DefaultAnnotations.builder().set("foo", "bar").build());
506 }
507
508 @Override
509 public boolean isAvailable(DeviceId deviceId) {
510 if (deviceId.equals(OFFLINE_DEVICE)) {
511 return false;
512 }
513 return true;
514 }
515 }
Andrea Campanella7c8e7912018-01-23 12:46:04 +0100516
517 private class TestMastershipService extends MastershipServiceAdapter {
518 @Override
519 public NodeId getMasterFor(DeviceId deviceId) {
520 return NodeId.nodeId(MASTER_1);
521 }
522 }
Andrea Campanella01e886e2017-12-15 15:27:31 +0100523}