blob: e0e49ef3b53927cdeb439f949b4312c3c3c3bfc7 [file] [log] [blame]
Ray Milkeye6684082014-10-16 16:59:47 -07001package org.onlab.onos.net.intent;
2
Jonathan Hart936c49d2014-10-23 16:38:59 -07003import static org.onlab.onos.net.NetTestTools.createPath;
4
Ray Milkeye6684082014-10-16 16:59:47 -07005import java.util.ArrayList;
6import java.util.Arrays;
7import java.util.Collections;
8import java.util.HashSet;
9import java.util.List;
10import java.util.Set;
11
12import org.onlab.onos.net.ElementId;
13import org.onlab.onos.net.Path;
14import org.onlab.onos.net.flow.TrafficSelector;
15import org.onlab.onos.net.flow.TrafficTreatment;
16import org.onlab.onos.net.flow.criteria.Criterion;
Jonathan Hart936c49d2014-10-23 16:38:59 -070017import org.onlab.onos.net.flow.criteria.Criterion.Type;
Ray Milkeye6684082014-10-16 16:59:47 -070018import org.onlab.onos.net.flow.instructions.Instruction;
19import org.onlab.onos.net.topology.LinkWeight;
20import org.onlab.onos.net.topology.PathService;
21
Ray Milkeye6684082014-10-16 16:59:47 -070022/**
23 * Common mocks used by the intent framework tests.
24 */
25public class IntentTestsMocks {
26 /**
27 * Mock traffic selector class used for satisfying API requirements.
28 */
29 public static class MockSelector implements TrafficSelector {
30 @Override
31 public Set<Criterion> criteria() {
32 return new HashSet<>();
33 }
Jonathan Hart936c49d2014-10-23 16:38:59 -070034
35 @Override
36 public Criterion getCriterion(Type type) {
37 return null;
38 }
Ray Milkeye6684082014-10-16 16:59:47 -070039 }
40
41 /**
42 * Mock traffic treatment class used for satisfying API requirements.
43 */
44 public static class MockTreatment implements TrafficTreatment {
45 @Override
46 public List<Instruction> instructions() {
47 return new ArrayList<>();
48 }
49 }
50
51 /**
52 * Mock path service for creating paths within the test.
53 */
54 public static class MockPathService implements PathService {
55
56 final String[] pathHops;
57 final String[] reversePathHops;
58
59 /**
60 * Constructor that provides a set of hops to mock.
61 *
62 * @param pathHops path hops to mock
63 */
64 public MockPathService(String[] pathHops) {
65 this.pathHops = pathHops;
66 String[] reversed = pathHops.clone();
67 Collections.reverse(Arrays.asList(reversed));
68 reversePathHops = reversed;
69 }
70
71 @Override
72 public Set<Path> getPaths(ElementId src, ElementId dst) {
73 Set<Path> result = new HashSet<>();
74
75 String[] allHops = new String[pathHops.length];
76
77 if (src.toString().endsWith(pathHops[0])) {
78 System.arraycopy(pathHops, 0, allHops, 0, pathHops.length);
79 } else {
80 System.arraycopy(reversePathHops, 0, allHops, 0, pathHops.length);
81 }
82
83 result.add(createPath(allHops));
84 return result;
85 }
86
87 @Override
88 public Set<Path> getPaths(ElementId src, ElementId dst, LinkWeight weight) {
89 return getPaths(src, dst);
90 }
91 }
92}