blob: 63317063d272aaea49cde6ffe6ede08d3db673be [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 Open Networking Laboratory
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 */
Ray Milkeye6684082014-10-16 16:59:47 -070016package org.onlab.onos.net.intent;
17
Jonathan Hart936c49d2014-10-23 16:38:59 -070018import static org.onlab.onos.net.NetTestTools.createPath;
19
Ray Milkeye6684082014-10-16 16:59:47 -070020import java.util.ArrayList;
21import java.util.Arrays;
22import java.util.Collections;
23import java.util.HashSet;
24import java.util.List;
25import java.util.Set;
26
27import org.onlab.onos.net.ElementId;
28import org.onlab.onos.net.Path;
29import org.onlab.onos.net.flow.TrafficSelector;
30import org.onlab.onos.net.flow.TrafficTreatment;
31import org.onlab.onos.net.flow.criteria.Criterion;
Jonathan Hart936c49d2014-10-23 16:38:59 -070032import org.onlab.onos.net.flow.criteria.Criterion.Type;
Ray Milkeye6684082014-10-16 16:59:47 -070033import org.onlab.onos.net.flow.instructions.Instruction;
34import org.onlab.onos.net.topology.LinkWeight;
35import org.onlab.onos.net.topology.PathService;
36
Ray Milkeye6684082014-10-16 16:59:47 -070037/**
38 * Common mocks used by the intent framework tests.
39 */
40public class IntentTestsMocks {
41 /**
42 * Mock traffic selector class used for satisfying API requirements.
43 */
44 public static class MockSelector implements TrafficSelector {
45 @Override
46 public Set<Criterion> criteria() {
47 return new HashSet<>();
48 }
Jonathan Hart936c49d2014-10-23 16:38:59 -070049
50 @Override
51 public Criterion getCriterion(Type type) {
52 return null;
53 }
Ray Milkeye6684082014-10-16 16:59:47 -070054 }
55
56 /**
57 * Mock traffic treatment class used for satisfying API requirements.
58 */
59 public static class MockTreatment implements TrafficTreatment {
60 @Override
61 public List<Instruction> instructions() {
62 return new ArrayList<>();
63 }
64 }
65
66 /**
67 * Mock path service for creating paths within the test.
68 */
69 public static class MockPathService implements PathService {
70
71 final String[] pathHops;
72 final String[] reversePathHops;
73
74 /**
75 * Constructor that provides a set of hops to mock.
76 *
77 * @param pathHops path hops to mock
78 */
79 public MockPathService(String[] pathHops) {
80 this.pathHops = pathHops;
81 String[] reversed = pathHops.clone();
82 Collections.reverse(Arrays.asList(reversed));
83 reversePathHops = reversed;
84 }
85
86 @Override
87 public Set<Path> getPaths(ElementId src, ElementId dst) {
88 Set<Path> result = new HashSet<>();
89
90 String[] allHops = new String[pathHops.length];
91
92 if (src.toString().endsWith(pathHops[0])) {
93 System.arraycopy(pathHops, 0, allHops, 0, pathHops.length);
94 } else {
95 System.arraycopy(reversePathHops, 0, allHops, 0, pathHops.length);
96 }
97
98 result.add(createPath(allHops));
99 return result;
100 }
101
102 @Override
103 public Set<Path> getPaths(ElementId src, ElementId dst, LinkWeight weight) {
104 return getPaths(src, dst);
105 }
106 }
107}