[ONOS-5264] [ONOS-5242] Intents w/ FilteredConnectPoint
Change-Id: Ibe9062c904ad9a6c3ba001fe57be7cec49eb8a4d
Showing
18 changed files
with
650 additions
and
318 deletions
1 | +/* | ||
2 | + * Copyright 2016-present 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 | + */ | ||
16 | + | ||
17 | +package org.onosproject.net; | ||
18 | + | ||
19 | +import com.google.common.base.MoreObjects; | ||
20 | +import org.onosproject.net.flow.DefaultTrafficSelector; | ||
21 | +import org.onosproject.net.flow.TrafficSelector; | ||
22 | + | ||
23 | +import java.util.Objects; | ||
24 | + | ||
25 | +/** | ||
26 | + * Connection point with TrafficSelector field. | ||
27 | + */ | ||
28 | +public class FilteredConnectPoint { | ||
29 | + private final ConnectPoint connectPoint; | ||
30 | + private final TrafficSelector trafficSelector; | ||
31 | + | ||
32 | + /** | ||
33 | + * Creates filtered connect point with default traffic selector. | ||
34 | + * | ||
35 | + * @param connectPoint | ||
36 | + */ | ||
37 | + public FilteredConnectPoint(ConnectPoint connectPoint) { | ||
38 | + this.connectPoint = connectPoint; | ||
39 | + this.trafficSelector = DefaultTrafficSelector.emptySelector(); | ||
40 | + } | ||
41 | + | ||
42 | + /** | ||
43 | + * Creates new filtered connection point. | ||
44 | + * | ||
45 | + * @param connectPoint connect point | ||
46 | + * @param trafficSelector traffic selector for this connect point | ||
47 | + */ | ||
48 | + public FilteredConnectPoint(ConnectPoint connectPoint, TrafficSelector trafficSelector) { | ||
49 | + this.connectPoint = connectPoint; | ||
50 | + this.trafficSelector = trafficSelector; | ||
51 | + } | ||
52 | + | ||
53 | + /** | ||
54 | + * Returns the traffic selector for this connect point. | ||
55 | + * | ||
56 | + * @return Traffic selector for this connect point | ||
57 | + */ | ||
58 | + public TrafficSelector trafficSelector() { | ||
59 | + return trafficSelector; | ||
60 | + } | ||
61 | + | ||
62 | + /** | ||
63 | + * Returns the connection point. | ||
64 | + * @return | ||
65 | + */ | ||
66 | + public ConnectPoint connectPoint() { | ||
67 | + return connectPoint; | ||
68 | + } | ||
69 | + | ||
70 | + @Override | ||
71 | + public int hashCode() { | ||
72 | + return Objects.hash(connectPoint, trafficSelector); | ||
73 | + } | ||
74 | + | ||
75 | + @Override | ||
76 | + public String toString() { | ||
77 | + return MoreObjects.toStringHelper(getClass()) | ||
78 | + .add("connectPoint", connectPoint) | ||
79 | + .add("trafficSelector", trafficSelector) | ||
80 | + .toString(); | ||
81 | + } | ||
82 | + | ||
83 | + @Override | ||
84 | + public boolean equals(Object obj) { | ||
85 | + if (obj == null) { | ||
86 | + return false; | ||
87 | + } | ||
88 | + | ||
89 | + if (this == obj) { | ||
90 | + return true; | ||
91 | + } | ||
92 | + | ||
93 | + if (obj instanceof FilteredConnectPoint) { | ||
94 | + FilteredConnectPoint other = (FilteredConnectPoint) obj; | ||
95 | + return other.connectPoint().equals(connectPoint) && | ||
96 | + other.trafficSelector().equals(trafficSelector()); | ||
97 | + } else { | ||
98 | + return false; | ||
99 | + } | ||
100 | + } | ||
101 | +} |
... | @@ -475,6 +475,23 @@ public final class DefaultTrafficTreatment implements TrafficTreatment { | ... | @@ -475,6 +475,23 @@ public final class DefaultTrafficTreatment implements TrafficTreatment { |
475 | } | 475 | } |
476 | 476 | ||
477 | @Override | 477 | @Override |
478 | + public TrafficTreatment.Builder addTreatment(TrafficTreatment treatment) { | ||
479 | + List<Instruction> previous = current; | ||
480 | + deferred(); | ||
481 | + treatment.deferred().forEach(i -> add(i)); | ||
482 | + | ||
483 | + immediate(); | ||
484 | + treatment.immediate().stream() | ||
485 | + // NOACTION will get re-added if there are no other actions | ||
486 | + .filter(i -> i.type() != Instruction.Type.NOACTION) | ||
487 | + .forEach(i -> add(i)); | ||
488 | + | ||
489 | + clear = treatment.clearedDeferred(); | ||
490 | + current = previous; | ||
491 | + return this; | ||
492 | + } | ||
493 | + | ||
494 | + @Override | ||
478 | public TrafficTreatment build() { | 495 | public TrafficTreatment build() { |
479 | if (deferred.size() == 0 && immediate.size() == 0 | 496 | if (deferred.size() == 0 && immediate.size() == 0 |
480 | && table == null && !clear) { | 497 | && table == null && !clear) { | ... | ... |
... | @@ -397,6 +397,14 @@ public interface TrafficTreatment { | ... | @@ -397,6 +397,14 @@ public interface TrafficTreatment { |
397 | Builder extension(ExtensionTreatment extension, DeviceId deviceId); | 397 | Builder extension(ExtensionTreatment extension, DeviceId deviceId); |
398 | 398 | ||
399 | /** | 399 | /** |
400 | + * Add all instructions from another treatment. | ||
401 | + * | ||
402 | + * @param treatment another treatment | ||
403 | + * @return a treatment builder | ||
404 | + */ | ||
405 | + Builder addTreatment(TrafficTreatment treatment); | ||
406 | + | ||
407 | + /** | ||
400 | * Builds an immutable traffic treatment descriptor. | 408 | * Builds an immutable traffic treatment descriptor. |
401 | * <p> | 409 | * <p> |
402 | * If the treatment is empty when build() is called, it will add a default | 410 | * If the treatment is empty when build() is called, it will add a default | ... | ... |
... | @@ -57,19 +57,19 @@ public final class IntentUtils { | ... | @@ -57,19 +57,19 @@ public final class IntentUtils { |
57 | SinglePointToMultiPointIntent intent2 = (SinglePointToMultiPointIntent) two; | 57 | SinglePointToMultiPointIntent intent2 = (SinglePointToMultiPointIntent) two; |
58 | 58 | ||
59 | return Objects.equals(intent1.selector(), intent2.selector()) && | 59 | return Objects.equals(intent1.selector(), intent2.selector()) && |
60 | - Objects.equals(intent1.treatment(), intent2.treatment()) && | 60 | + Objects.equals(intent1.treatment(), intent2.treatment()) && |
61 | - Objects.equals(intent1.constraints(), intent2.constraints()) && | 61 | + Objects.equals(intent1.filteredIngressPoint(), intent2.filteredIngressPoint()) && |
62 | - Objects.equals(intent1.ingressPoint(), intent2.ingressPoint()) && | 62 | + Objects.equals(intent1.filteredEgressPoints(), intent2.filteredEgressPoints()) && |
63 | - Objects.equals(intent1.egressPoints(), intent2.egressPoints()); | 63 | + Objects.equals(intent1.constraints(), intent2.constraints()); |
64 | } else if (one instanceof MultiPointToSinglePointIntent) { | 64 | } else if (one instanceof MultiPointToSinglePointIntent) { |
65 | MultiPointToSinglePointIntent intent1 = (MultiPointToSinglePointIntent) one; | 65 | MultiPointToSinglePointIntent intent1 = (MultiPointToSinglePointIntent) one; |
66 | MultiPointToSinglePointIntent intent2 = (MultiPointToSinglePointIntent) two; | 66 | MultiPointToSinglePointIntent intent2 = (MultiPointToSinglePointIntent) two; |
67 | 67 | ||
68 | return Objects.equals(intent1.selector(), intent2.selector()) && | 68 | return Objects.equals(intent1.selector(), intent2.selector()) && |
69 | - Objects.equals(intent1.treatment(), intent2.treatment()) && | 69 | + Objects.equals(intent1.filteredIngressPoints(), intent2.filteredIngressPoints()) && |
70 | - Objects.equals(intent1.constraints(), intent2.constraints()) && | 70 | + Objects.equals(intent1.filteredEgressPoint(), intent2.filteredEgressPoint()) && |
71 | - Objects.equals(intent1.ingressPoints(), intent2.ingressPoints()) && | 71 | + Objects.equals(intent1.treatment(), intent2.treatment()) && |
72 | - Objects.equals(intent1.egressPoint(), intent2.egressPoint()); | 72 | + Objects.equals(intent1.constraints(), intent2.constraints()); |
73 | } else if (one instanceof PointToPointIntent) { | 73 | } else if (one instanceof PointToPointIntent) { |
74 | PointToPointIntent intent1 = (PointToPointIntent) one; | 74 | PointToPointIntent intent1 = (PointToPointIntent) one; |
75 | PointToPointIntent intent2 = (PointToPointIntent) two; | 75 | PointToPointIntent intent2 = (PointToPointIntent) two; | ... | ... |
... | @@ -17,19 +17,22 @@ | ... | @@ -17,19 +17,22 @@ |
17 | package org.onosproject.net.intent; | 17 | package org.onosproject.net.intent; |
18 | 18 | ||
19 | import java.util.List; | 19 | import java.util.List; |
20 | -import java.util.Map; | ||
21 | import java.util.Set; | 20 | import java.util.Set; |
21 | +import java.util.stream.Collectors; | ||
22 | 22 | ||
23 | import com.google.common.annotations.Beta; | 23 | import com.google.common.annotations.Beta; |
24 | -import com.google.common.collect.ImmutableMap; | ||
25 | import org.onosproject.core.ApplicationId; | 24 | import org.onosproject.core.ApplicationId; |
26 | import org.onosproject.net.ConnectPoint; | 25 | import org.onosproject.net.ConnectPoint; |
26 | +import org.onosproject.net.FilteredConnectPoint; | ||
27 | import org.onosproject.net.Link; | 27 | import org.onosproject.net.Link; |
28 | import org.onosproject.net.flow.TrafficSelector; | 28 | import org.onosproject.net.flow.TrafficSelector; |
29 | import org.onosproject.net.flow.TrafficTreatment; | 29 | import org.onosproject.net.flow.TrafficTreatment; |
30 | 30 | ||
31 | import com.google.common.base.MoreObjects; | 31 | import com.google.common.base.MoreObjects; |
32 | import com.google.common.collect.ImmutableSet; | 32 | import com.google.common.collect.ImmutableSet; |
33 | +import org.slf4j.Logger; | ||
34 | + | ||
35 | +import static org.slf4j.LoggerFactory.getLogger; | ||
33 | 36 | ||
34 | /** | 37 | /** |
35 | * Abstraction of a connectivity intent that is implemented by a set of path | 38 | * Abstraction of a connectivity intent that is implemented by a set of path |
... | @@ -40,17 +43,11 @@ public final class LinkCollectionIntent extends ConnectivityIntent { | ... | @@ -40,17 +43,11 @@ public final class LinkCollectionIntent extends ConnectivityIntent { |
40 | 43 | ||
41 | private final Set<Link> links; | 44 | private final Set<Link> links; |
42 | 45 | ||
43 | - private final Set<ConnectPoint> ingressPoints; | 46 | + private final Set<FilteredConnectPoint> ingressPoints; |
44 | - private final Set<ConnectPoint> egressPoints; | 47 | + private final Set<FilteredConnectPoint> egressPoints; |
45 | private final boolean egressTreatmentFlag; | 48 | private final boolean egressTreatmentFlag; |
46 | - /** | 49 | + |
47 | - * To manage multiple selectors use case. | 50 | + |
48 | - */ | ||
49 | - private final Map<ConnectPoint, TrafficSelector> ingressSelectors; | ||
50 | - /** | ||
51 | - * To manage multiple treatments use case. | ||
52 | - */ | ||
53 | - private final Map<ConnectPoint, TrafficTreatment> egressTreatments; | ||
54 | 51 | ||
55 | /** | 52 | /** |
56 | * Creates a new actionable intent capable of funneling the selected | 53 | * Creates a new actionable intent capable of funneling the selected |
... | @@ -62,13 +59,11 @@ public final class LinkCollectionIntent extends ConnectivityIntent { | ... | @@ -62,13 +59,11 @@ public final class LinkCollectionIntent extends ConnectivityIntent { |
62 | * @param selector traffic match | 59 | * @param selector traffic match |
63 | * @param treatment action | 60 | * @param treatment action |
64 | * @param links traversed links | 61 | * @param links traversed links |
65 | - * @param ingressPoints ingress points | 62 | + * @param ingressPoints filtered ingress points |
66 | - * @param egressPoints egress points | 63 | + * @param egressPoints filtered egress points |
67 | * @param constraints optional list of constraints | 64 | * @param constraints optional list of constraints |
68 | * @param priority priority to use for the flows generated by this intent | 65 | * @param priority priority to use for the flows generated by this intent |
69 | * @param egressTreatment true if treatment should be applied by the egress device | 66 | * @param egressTreatment true if treatment should be applied by the egress device |
70 | - * @param ingressSelectors map to store the association ingress to selector | ||
71 | - * @param egressTreatments map to store the association egress to treatment | ||
72 | * @throws NullPointerException {@code path} is null | 67 | * @throws NullPointerException {@code path} is null |
73 | */ | 68 | */ |
74 | private LinkCollectionIntent(ApplicationId appId, | 69 | private LinkCollectionIntent(ApplicationId appId, |
... | @@ -76,20 +71,16 @@ public final class LinkCollectionIntent extends ConnectivityIntent { | ... | @@ -76,20 +71,16 @@ public final class LinkCollectionIntent extends ConnectivityIntent { |
76 | TrafficSelector selector, | 71 | TrafficSelector selector, |
77 | TrafficTreatment treatment, | 72 | TrafficTreatment treatment, |
78 | Set<Link> links, | 73 | Set<Link> links, |
79 | - Set<ConnectPoint> ingressPoints, | 74 | + Set<FilteredConnectPoint> ingressPoints, |
80 | - Set<ConnectPoint> egressPoints, | 75 | + Set<FilteredConnectPoint> egressPoints, |
81 | List<Constraint> constraints, | 76 | List<Constraint> constraints, |
82 | int priority, | 77 | int priority, |
83 | - boolean egressTreatment, | 78 | + boolean egressTreatment) { |
84 | - Map<ConnectPoint, TrafficSelector> ingressSelectors, | ||
85 | - Map<ConnectPoint, TrafficTreatment> egressTreatments) { | ||
86 | super(appId, key, resources(links), selector, treatment, constraints, priority); | 79 | super(appId, key, resources(links), selector, treatment, constraints, priority); |
87 | this.links = links; | 80 | this.links = links; |
88 | this.ingressPoints = ingressPoints; | 81 | this.ingressPoints = ingressPoints; |
89 | this.egressPoints = egressPoints; | 82 | this.egressPoints = egressPoints; |
90 | this.egressTreatmentFlag = egressTreatment; | 83 | this.egressTreatmentFlag = egressTreatment; |
91 | - this.ingressSelectors = ingressSelectors; | ||
92 | - this.egressTreatments = egressTreatments; | ||
93 | } | 84 | } |
94 | 85 | ||
95 | /** | 86 | /** |
... | @@ -101,8 +92,6 @@ public final class LinkCollectionIntent extends ConnectivityIntent { | ... | @@ -101,8 +92,6 @@ public final class LinkCollectionIntent extends ConnectivityIntent { |
101 | this.ingressPoints = null; | 92 | this.ingressPoints = null; |
102 | this.egressPoints = null; | 93 | this.egressPoints = null; |
103 | this.egressTreatmentFlag = false; | 94 | this.egressTreatmentFlag = false; |
104 | - this.ingressSelectors = null; | ||
105 | - this.egressTreatments = null; | ||
106 | } | 95 | } |
107 | 96 | ||
108 | /** | 97 | /** |
... | @@ -121,12 +110,11 @@ public final class LinkCollectionIntent extends ConnectivityIntent { | ... | @@ -121,12 +110,11 @@ public final class LinkCollectionIntent extends ConnectivityIntent { |
121 | * Builder of a single point to multi point intent. | 110 | * Builder of a single point to multi point intent. |
122 | */ | 111 | */ |
123 | public static final class Builder extends ConnectivityIntent.Builder { | 112 | public static final class Builder extends ConnectivityIntent.Builder { |
124 | - Set<Link> links; | 113 | + private final Logger log = getLogger(getClass()); |
125 | - Set<ConnectPoint> ingressPoints; | 114 | + private Set<Link> links; |
126 | - Set<ConnectPoint> egressPoints; | 115 | + private Set<FilteredConnectPoint> ingressPoints; |
127 | - Map<ConnectPoint, TrafficSelector> ingressSelectors = ImmutableMap.of(); | 116 | + private Set<FilteredConnectPoint> egressPoints; |
128 | - Map<ConnectPoint, TrafficTreatment> egressTreatments = ImmutableMap.of(); | 117 | + private boolean egressTreatmentFlag; |
129 | - boolean egressTreatmentFlag; | ||
130 | 118 | ||
131 | private Builder() { | 119 | private Builder() { |
132 | // Hide constructor | 120 | // Hide constructor |
... | @@ -169,8 +157,15 @@ public final class LinkCollectionIntent extends ConnectivityIntent { | ... | @@ -169,8 +157,15 @@ public final class LinkCollectionIntent extends ConnectivityIntent { |
169 | * @param ingressPoints ingress connect points | 157 | * @param ingressPoints ingress connect points |
170 | * @return this builder | 158 | * @return this builder |
171 | */ | 159 | */ |
160 | + @Deprecated | ||
172 | public Builder ingressPoints(Set<ConnectPoint> ingressPoints) { | 161 | public Builder ingressPoints(Set<ConnectPoint> ingressPoints) { |
173 | - this.ingressPoints = ImmutableSet.copyOf(ingressPoints); | 162 | + if (this.ingressPoints != null) { |
163 | + log.warn("Ingress points are already set, " + | ||
164 | + "this will override original ingress points."); | ||
165 | + } | ||
166 | + this.ingressPoints = ingressPoints.stream() | ||
167 | + .map(FilteredConnectPoint::new) | ||
168 | + .collect(Collectors.toSet()); | ||
174 | return this; | 169 | return this; |
175 | } | 170 | } |
176 | 171 | ||
... | @@ -181,30 +176,39 @@ public final class LinkCollectionIntent extends ConnectivityIntent { | ... | @@ -181,30 +176,39 @@ public final class LinkCollectionIntent extends ConnectivityIntent { |
181 | * @param egressPoints egress connect points | 176 | * @param egressPoints egress connect points |
182 | * @return this builder | 177 | * @return this builder |
183 | */ | 178 | */ |
179 | + @Deprecated | ||
184 | public Builder egressPoints(Set<ConnectPoint> egressPoints) { | 180 | public Builder egressPoints(Set<ConnectPoint> egressPoints) { |
185 | - this.egressPoints = ImmutableSet.copyOf(egressPoints); | 181 | + if (this.egressPoints != null) { |
182 | + log.warn("Egress points are already set, " + | ||
183 | + "this will override original egress points."); | ||
184 | + } | ||
185 | + this.egressPoints = egressPoints.stream() | ||
186 | + .map(FilteredConnectPoint::new) | ||
187 | + .collect(Collectors.toSet()); | ||
186 | return this; | 188 | return this; |
187 | } | 189 | } |
188 | 190 | ||
189 | /** | 191 | /** |
190 | - * Sets the map ingress selectors to connection points of the intent. | 192 | + * Sets the filtered ingress point of the single point to multi point intent |
193 | + * that will be built. | ||
191 | * | 194 | * |
192 | - * @param ingressSelectors maps connection point to traffic selector | 195 | + * @param ingressPoints ingress connect points |
193 | * @return this builder | 196 | * @return this builder |
194 | */ | 197 | */ |
195 | - public Builder ingressSelectors(Map<ConnectPoint, TrafficSelector> ingressSelectors) { | 198 | + public Builder filteredIngressPoints(Set<FilteredConnectPoint> ingressPoints) { |
196 | - this.ingressSelectors = ImmutableMap.copyOf(ingressSelectors); | 199 | + this.ingressPoints = ImmutableSet.copyOf(ingressPoints); |
197 | return this; | 200 | return this; |
198 | } | 201 | } |
199 | 202 | ||
200 | /** | 203 | /** |
201 | - * Sets the map egress treatments to connection points of the intent. | 204 | + * Sets the filtered egress points of the single point to multi point intent |
205 | + * that will be built. | ||
202 | * | 206 | * |
203 | - * @param egressTreatments maps connection point to traffic treatment | 207 | + * @param egressPoints egress connect points |
204 | * @return this builder | 208 | * @return this builder |
205 | */ | 209 | */ |
206 | - public Builder egressTreatments(Map<ConnectPoint, TrafficTreatment> egressTreatments) { | 210 | + public Builder filteredEgressPoints(Set<FilteredConnectPoint> egressPoints) { |
207 | - this.egressTreatments = ImmutableMap.copyOf(egressTreatments); | 211 | + this.egressPoints = ImmutableSet.copyOf(egressPoints); |
208 | return this; | 212 | return this; |
209 | } | 213 | } |
210 | 214 | ||
... | @@ -250,9 +254,7 @@ public final class LinkCollectionIntent extends ConnectivityIntent { | ... | @@ -250,9 +254,7 @@ public final class LinkCollectionIntent extends ConnectivityIntent { |
250 | egressPoints, | 254 | egressPoints, |
251 | constraints, | 255 | constraints, |
252 | priority, | 256 | priority, |
253 | - egressTreatmentFlag, | 257 | + egressTreatmentFlag |
254 | - ingressSelectors, | ||
255 | - egressTreatments | ||
256 | ); | 258 | ); |
257 | } | 259 | } |
258 | } | 260 | } |
... | @@ -273,7 +275,12 @@ public final class LinkCollectionIntent extends ConnectivityIntent { | ... | @@ -273,7 +275,12 @@ public final class LinkCollectionIntent extends ConnectivityIntent { |
273 | * @return the ingress points | 275 | * @return the ingress points |
274 | */ | 276 | */ |
275 | public Set<ConnectPoint> ingressPoints() { | 277 | public Set<ConnectPoint> ingressPoints() { |
276 | - return ingressPoints; | 278 | + if (this.ingressPoints == null) { |
279 | + return null; | ||
280 | + } | ||
281 | + return ingressPoints.stream() | ||
282 | + .map(FilteredConnectPoint::connectPoint) | ||
283 | + .collect(Collectors.toSet()); | ||
277 | } | 284 | } |
278 | 285 | ||
279 | /** | 286 | /** |
... | @@ -282,23 +289,30 @@ public final class LinkCollectionIntent extends ConnectivityIntent { | ... | @@ -282,23 +289,30 @@ public final class LinkCollectionIntent extends ConnectivityIntent { |
282 | * @return the egress points | 289 | * @return the egress points |
283 | */ | 290 | */ |
284 | public Set<ConnectPoint> egressPoints() { | 291 | public Set<ConnectPoint> egressPoints() { |
285 | - return egressPoints; | 292 | + if (this.egressPoints == null) { |
293 | + return null; | ||
294 | + } | ||
295 | + return egressPoints.stream() | ||
296 | + .map(FilteredConnectPoint::connectPoint) | ||
297 | + .collect(Collectors.toSet()); | ||
286 | } | 298 | } |
287 | 299 | ||
288 | /** | 300 | /** |
289 | - * Returns the multiple selectors jointly with their connection points. | 301 | + * Returns the filtered ingress points of the intent. |
290 | - * @return multiple selectors | 302 | + * |
303 | + * @return the ingress points | ||
291 | */ | 304 | */ |
292 | - public Map<ConnectPoint, TrafficSelector> ingressSelectors() { | 305 | + public Set<FilteredConnectPoint> filteredIngressPoints() { |
293 | - return ingressSelectors; | 306 | + return ingressPoints; |
294 | } | 307 | } |
295 | 308 | ||
296 | /** | 309 | /** |
297 | - * Returns the multiple treatments jointly with their connection points. | 310 | + * Returns the egress points of the intent. |
298 | - * @return multiple treatments | 311 | + * |
312 | + * @return the egress points | ||
299 | */ | 313 | */ |
300 | - public Map<ConnectPoint, TrafficTreatment> egressTreatments() { | 314 | + public Set<FilteredConnectPoint> filteredEgressPoints() { |
301 | - return egressTreatments; | 315 | + return egressPoints; |
302 | } | 316 | } |
303 | 317 | ||
304 | /** | 318 | /** |
... | @@ -323,8 +337,6 @@ public final class LinkCollectionIntent extends ConnectivityIntent { | ... | @@ -323,8 +337,6 @@ public final class LinkCollectionIntent extends ConnectivityIntent { |
323 | .add("links", links()) | 337 | .add("links", links()) |
324 | .add("ingress", ingressPoints()) | 338 | .add("ingress", ingressPoints()) |
325 | .add("egress", egressPoints()) | 339 | .add("egress", egressPoints()) |
326 | - .add("selectors", ingressSelectors()) | ||
327 | - .add("treatments", egressTreatments()) | ||
328 | .add("treatementOnEgress", applyTreatmentOnEgress()) | 340 | .add("treatementOnEgress", applyTreatmentOnEgress()) |
329 | .toString(); | 341 | .toString(); |
330 | } | 342 | } | ... | ... |
... | @@ -17,20 +17,21 @@ package org.onosproject.net.intent; | ... | @@ -17,20 +17,21 @@ package org.onosproject.net.intent; |
17 | 17 | ||
18 | import com.google.common.annotations.Beta; | 18 | import com.google.common.annotations.Beta; |
19 | import com.google.common.base.MoreObjects; | 19 | import com.google.common.base.MoreObjects; |
20 | -import com.google.common.collect.ImmutableMap; | ||
21 | import com.google.common.collect.ImmutableSet; | 20 | import com.google.common.collect.ImmutableSet; |
22 | -import com.google.common.collect.Sets; | ||
23 | import org.onosproject.core.ApplicationId; | 21 | import org.onosproject.core.ApplicationId; |
24 | import org.onosproject.net.ConnectPoint; | 22 | import org.onosproject.net.ConnectPoint; |
23 | +import org.onosproject.net.FilteredConnectPoint; | ||
25 | import org.onosproject.net.flow.TrafficSelector; | 24 | import org.onosproject.net.flow.TrafficSelector; |
26 | import org.onosproject.net.flow.TrafficTreatment; | 25 | import org.onosproject.net.flow.TrafficTreatment; |
26 | +import org.slf4j.Logger; | ||
27 | 27 | ||
28 | import java.util.List; | 28 | import java.util.List; |
29 | -import java.util.Map; | ||
30 | import java.util.Set; | 29 | import java.util.Set; |
30 | +import java.util.stream.Collectors; | ||
31 | 31 | ||
32 | import static com.google.common.base.Preconditions.checkArgument; | 32 | import static com.google.common.base.Preconditions.checkArgument; |
33 | import static com.google.common.base.Preconditions.checkNotNull; | 33 | import static com.google.common.base.Preconditions.checkNotNull; |
34 | +import static org.slf4j.LoggerFactory.getLogger; | ||
34 | 35 | ||
35 | /** | 36 | /** |
36 | * Abstraction of multiple source to single destination connectivity intent. | 37 | * Abstraction of multiple source to single destination connectivity intent. |
... | @@ -38,26 +39,21 @@ import static com.google.common.base.Preconditions.checkNotNull; | ... | @@ -38,26 +39,21 @@ import static com.google.common.base.Preconditions.checkNotNull; |
38 | @Beta | 39 | @Beta |
39 | public final class MultiPointToSinglePointIntent extends ConnectivityIntent { | 40 | public final class MultiPointToSinglePointIntent extends ConnectivityIntent { |
40 | 41 | ||
41 | - private final Set<ConnectPoint> ingressPoints; | 42 | + private final Set<FilteredConnectPoint> ingressPoints; |
42 | - private final ConnectPoint egressPoint; | 43 | + private final FilteredConnectPoint egressPoint; |
43 | - /** | ||
44 | - * To manage multiple selectors use case. | ||
45 | - */ | ||
46 | - private final Map<ConnectPoint, TrafficSelector> ingressSelectors; | ||
47 | 44 | ||
48 | /** | 45 | /** |
49 | * Creates a new multi-to-single point connectivity intent for the specified | 46 | * Creates a new multi-to-single point connectivity intent for the specified |
50 | - * traffic selector and treatment. | 47 | + * traffic selector and treatment with filtered connect point. |
51 | * | 48 | * |
52 | * @param appId application identifier | 49 | * @param appId application identifier |
53 | * @param key intent key | 50 | * @param key intent key |
54 | * @param selector traffic selector | 51 | * @param selector traffic selector |
55 | * @param treatment treatment | 52 | * @param treatment treatment |
56 | - * @param ingressPoints set of ports from which ingress traffic originates | 53 | + * @param ingressPoints set of filtered ports from which ingress traffic originates |
57 | - * @param egressPoint port to which traffic will egress | 54 | + * @param egressPoint filtered port to which traffic will egress |
58 | * @param constraints constraints to apply to the intent | 55 | * @param constraints constraints to apply to the intent |
59 | * @param priority priority to use for flows generated by this intent | 56 | * @param priority priority to use for flows generated by this intent |
60 | - * @param ingressSelectors map to store the association ingress to selector | ||
61 | * @throws NullPointerException if {@code ingressPoints} or | 57 | * @throws NullPointerException if {@code ingressPoints} or |
62 | * {@code egressPoint} is null. | 58 | * {@code egressPoint} is null. |
63 | * @throws IllegalArgumentException if the size of {@code ingressPoints} is | 59 | * @throws IllegalArgumentException if the size of {@code ingressPoints} is |
... | @@ -67,24 +63,22 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { | ... | @@ -67,24 +63,22 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { |
67 | Key key, | 63 | Key key, |
68 | TrafficSelector selector, | 64 | TrafficSelector selector, |
69 | TrafficTreatment treatment, | 65 | TrafficTreatment treatment, |
70 | - Set<ConnectPoint> ingressPoints, | 66 | + Set<FilteredConnectPoint> ingressPoints, |
71 | - ConnectPoint egressPoint, | 67 | + FilteredConnectPoint egressPoint, |
72 | List<Constraint> constraints, | 68 | List<Constraint> constraints, |
73 | - int priority, | 69 | + int priority |
74 | - Map<ConnectPoint, TrafficSelector> ingressSelectors | 70 | + ) { |
75 | - ) { | ||
76 | super(appId, key, ImmutableSet.of(), selector, treatment, constraints, | 71 | super(appId, key, ImmutableSet.of(), selector, treatment, constraints, |
77 | - priority); | 72 | + priority); |
78 | 73 | ||
79 | checkNotNull(ingressPoints); | 74 | checkNotNull(ingressPoints); |
80 | checkArgument(!ingressPoints.isEmpty(), "Ingress point set cannot be empty"); | 75 | checkArgument(!ingressPoints.isEmpty(), "Ingress point set cannot be empty"); |
81 | checkNotNull(egressPoint); | 76 | checkNotNull(egressPoint); |
82 | checkArgument(!ingressPoints.contains(egressPoint), | 77 | checkArgument(!ingressPoints.contains(egressPoint), |
83 | - "Set of ingresses should not contain egress (egress: %s)", egressPoint); | 78 | + "Set of ingresses should not contain egress (egress: %s)", egressPoint); |
84 | 79 | ||
85 | - this.ingressPoints = Sets.newHashSet(ingressPoints); | 80 | + this.ingressPoints = ImmutableSet.copyOf(ingressPoints); |
86 | this.egressPoint = egressPoint; | 81 | this.egressPoint = egressPoint; |
87 | - this.ingressSelectors = ingressSelectors; | ||
88 | } | 82 | } |
89 | 83 | ||
90 | /** | 84 | /** |
... | @@ -94,7 +88,6 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { | ... | @@ -94,7 +88,6 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { |
94 | super(); | 88 | super(); |
95 | this.ingressPoints = null; | 89 | this.ingressPoints = null; |
96 | this.egressPoint = null; | 90 | this.egressPoint = null; |
97 | - this.ingressSelectors = null; | ||
98 | } | 91 | } |
99 | 92 | ||
100 | /** | 93 | /** |
... | @@ -124,9 +117,9 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { | ... | @@ -124,9 +117,9 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { |
124 | * Builder of a multi point to single point intent. | 117 | * Builder of a multi point to single point intent. |
125 | */ | 118 | */ |
126 | public static final class Builder extends ConnectivityIntent.Builder { | 119 | public static final class Builder extends ConnectivityIntent.Builder { |
127 | - Set<ConnectPoint> ingressPoints; | 120 | + private final Logger log = getLogger(getClass()); |
128 | - ConnectPoint egressPoint; | 121 | + private Set<FilteredConnectPoint> ingressPoints; |
129 | - Map<ConnectPoint, TrafficSelector> ingressSelectors = ImmutableMap.of(); | 122 | + private FilteredConnectPoint egressPoint; |
130 | 123 | ||
131 | private Builder() { | 124 | private Builder() { |
132 | // Hide constructor | 125 | // Hide constructor |
... | @@ -141,8 +134,9 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { | ... | @@ -141,8 +134,9 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { |
141 | protected Builder(MultiPointToSinglePointIntent intent) { | 134 | protected Builder(MultiPointToSinglePointIntent intent) { |
142 | super(intent); | 135 | super(intent); |
143 | 136 | ||
144 | - this.ingressPoints(intent.ingressPoints()) | 137 | + this.filteredIngressPoints(intent.filteredIngressPoints()) |
145 | - .egressPoint(intent.egressPoint()); | 138 | + .filteredEgressPoint(intent.filteredEgressPoint()); |
139 | + | ||
146 | } | 140 | } |
147 | 141 | ||
148 | @Override | 142 | @Override |
... | @@ -182,8 +176,15 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { | ... | @@ -182,8 +176,15 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { |
182 | * @param ingressPoints ingress connect points | 176 | * @param ingressPoints ingress connect points |
183 | * @return this builder | 177 | * @return this builder |
184 | */ | 178 | */ |
179 | + @Deprecated | ||
185 | public Builder ingressPoints(Set<ConnectPoint> ingressPoints) { | 180 | public Builder ingressPoints(Set<ConnectPoint> ingressPoints) { |
186 | - this.ingressPoints = ImmutableSet.copyOf(ingressPoints); | 181 | + if (this.ingressPoints != null) { |
182 | + log.warn("Ingress points are already set, " + | ||
183 | + "this will override original ingress points."); | ||
184 | + } | ||
185 | + this.ingressPoints = ingressPoints.stream() | ||
186 | + .map(FilteredConnectPoint::new) | ||
187 | + .collect(Collectors.toSet()); | ||
187 | return this; | 188 | return this; |
188 | } | 189 | } |
189 | 190 | ||
... | @@ -194,20 +195,37 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { | ... | @@ -194,20 +195,37 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { |
194 | * @param egressPoint egress connect point | 195 | * @param egressPoint egress connect point |
195 | * @return this builder | 196 | * @return this builder |
196 | */ | 197 | */ |
198 | + @Deprecated | ||
197 | public Builder egressPoint(ConnectPoint egressPoint) { | 199 | public Builder egressPoint(ConnectPoint egressPoint) { |
198 | - this.egressPoint = egressPoint; | 200 | + if (this.egressPoint != null) { |
201 | + log.warn("Egress point is already set, " + | ||
202 | + "this will override original egress point."); | ||
203 | + } | ||
204 | + this.egressPoint = new FilteredConnectPoint(egressPoint); | ||
205 | + return this; | ||
206 | + } | ||
207 | + | ||
208 | + /** | ||
209 | + * Sets the filtered ingress point of the single point to multi point intent | ||
210 | + * that will be built. | ||
211 | + * | ||
212 | + * @param ingressPoints filtered ingress connect points | ||
213 | + * @return this builder | ||
214 | + */ | ||
215 | + public Builder filteredIngressPoints(Set<FilteredConnectPoint> ingressPoints) { | ||
216 | + this.ingressPoints = ImmutableSet.copyOf(ingressPoints); | ||
199 | return this; | 217 | return this; |
200 | } | 218 | } |
201 | 219 | ||
202 | /** | 220 | /** |
203 | - * Sets the selectors of the multi point to single point intent | 221 | + * Sets the filtered egress point of the multi point to single point intent |
204 | * that will be built. | 222 | * that will be built. |
205 | * | 223 | * |
206 | - * @param ingressSelectors the multiple selectos | 224 | + * @param egressPoint filtered egress connect point |
207 | * @return this builder | 225 | * @return this builder |
208 | */ | 226 | */ |
209 | - public Builder selectors(Map<ConnectPoint, TrafficSelector> ingressSelectors) { | 227 | + public Builder filteredEgressPoint(FilteredConnectPoint egressPoint) { |
210 | - this.ingressSelectors = ImmutableMap.copyOf(ingressSelectors); | 228 | + this.egressPoint = egressPoint; |
211 | return this; | 229 | return this; |
212 | } | 230 | } |
213 | 231 | ||
... | @@ -219,11 +237,6 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { | ... | @@ -219,11 +237,6 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { |
219 | */ | 237 | */ |
220 | public MultiPointToSinglePointIntent build() { | 238 | public MultiPointToSinglePointIntent build() { |
221 | 239 | ||
222 | - if (selector != null && !selector.criteria().isEmpty() && | ||
223 | - ingressSelectors != null && !ingressSelectors.isEmpty()) { | ||
224 | - throw new IllegalArgumentException("Selector and Multiple Selectors are both set"); | ||
225 | - } | ||
226 | - | ||
227 | return new MultiPointToSinglePointIntent( | 240 | return new MultiPointToSinglePointIntent( |
228 | appId, | 241 | appId, |
229 | key, | 242 | key, |
... | @@ -232,8 +245,7 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { | ... | @@ -232,8 +245,7 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { |
232 | ingressPoints, | 245 | ingressPoints, |
233 | egressPoint, | 246 | egressPoint, |
234 | constraints, | 247 | constraints, |
235 | - priority, | 248 | + priority |
236 | - ingressSelectors | ||
237 | ); | 249 | ); |
238 | } | 250 | } |
239 | } | 251 | } |
... | @@ -246,7 +258,9 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { | ... | @@ -246,7 +258,9 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { |
246 | * @return set of ingress ports | 258 | * @return set of ingress ports |
247 | */ | 259 | */ |
248 | public Set<ConnectPoint> ingressPoints() { | 260 | public Set<ConnectPoint> ingressPoints() { |
249 | - return ingressPoints; | 261 | + return ingressPoints.stream() |
262 | + .map(FilteredConnectPoint::connectPoint) | ||
263 | + .collect(Collectors.toSet()); | ||
250 | } | 264 | } |
251 | 265 | ||
252 | /** | 266 | /** |
... | @@ -255,17 +269,29 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { | ... | @@ -255,17 +269,29 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { |
255 | * @return egress port | 269 | * @return egress port |
256 | */ | 270 | */ |
257 | public ConnectPoint egressPoint() { | 271 | public ConnectPoint egressPoint() { |
258 | - return egressPoint; | 272 | + return egressPoint.connectPoint(); |
259 | } | 273 | } |
260 | 274 | ||
261 | /** | 275 | /** |
262 | - * Returns the multiple selectors jointly with their connection points. | 276 | + * Returns the set of ports on which ingress traffic should be connected to |
263 | - * @return multiple selectors | 277 | + * the egress port. |
278 | + * | ||
279 | + * @return set of ingress ports | ||
264 | */ | 280 | */ |
265 | - public Map<ConnectPoint, TrafficSelector> ingressSelectors() { | 281 | + public Set<FilteredConnectPoint> filteredIngressPoints() { |
266 | - return ingressSelectors; | 282 | + return ingressPoints; |
267 | } | 283 | } |
268 | 284 | ||
285 | + /** | ||
286 | + * Returns the port on which the traffic should egress. | ||
287 | + * | ||
288 | + * @return egress port | ||
289 | + */ | ||
290 | + public FilteredConnectPoint filteredEgressPoint() { | ||
291 | + return egressPoint; | ||
292 | + } | ||
293 | + | ||
294 | + | ||
269 | @Override | 295 | @Override |
270 | public String toString() { | 296 | public String toString() { |
271 | return MoreObjects.toStringHelper(getClass()) | 297 | return MoreObjects.toStringHelper(getClass()) |
... | @@ -278,7 +304,8 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { | ... | @@ -278,7 +304,8 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { |
278 | .add("treatment", treatment()) | 304 | .add("treatment", treatment()) |
279 | .add("ingress", ingressPoints()) | 305 | .add("ingress", ingressPoints()) |
280 | .add("egress", egressPoint()) | 306 | .add("egress", egressPoint()) |
281 | - .add("selectors", ingressSelectors()) | 307 | + .add("filteredIngressCPs", filteredIngressPoints()) |
308 | + .add("filteredEgressCP", filteredEgressPoint()) | ||
282 | .add("constraints", constraints()) | 309 | .add("constraints", constraints()) |
283 | .toString(); | 310 | .toString(); |
284 | } | 311 | } | ... | ... |
... | @@ -18,35 +18,31 @@ package org.onosproject.net.intent; | ... | @@ -18,35 +18,31 @@ package org.onosproject.net.intent; |
18 | import com.google.common.annotations.Beta; | 18 | import com.google.common.annotations.Beta; |
19 | import com.google.common.base.MoreObjects; | 19 | import com.google.common.base.MoreObjects; |
20 | import com.google.common.collect.ImmutableList; | 20 | import com.google.common.collect.ImmutableList; |
21 | -import com.google.common.collect.ImmutableMap; | ||
22 | import com.google.common.collect.ImmutableSet; | 21 | import com.google.common.collect.ImmutableSet; |
23 | 22 | ||
24 | import com.google.common.collect.Sets; | 23 | import com.google.common.collect.Sets; |
25 | import org.onosproject.core.ApplicationId; | 24 | import org.onosproject.core.ApplicationId; |
26 | import org.onosproject.net.ConnectPoint; | 25 | import org.onosproject.net.ConnectPoint; |
27 | -import org.onosproject.net.flow.DefaultTrafficTreatment; | 26 | +import org.onosproject.net.FilteredConnectPoint; |
28 | import org.onosproject.net.flow.TrafficSelector; | 27 | import org.onosproject.net.flow.TrafficSelector; |
29 | import org.onosproject.net.flow.TrafficTreatment; | 28 | import org.onosproject.net.flow.TrafficTreatment; |
29 | +import org.slf4j.Logger; | ||
30 | 30 | ||
31 | -import java.util.Map; | ||
32 | import java.util.Set; | 31 | import java.util.Set; |
33 | import java.util.List; | 32 | import java.util.List; |
33 | +import java.util.stream.Collectors; | ||
34 | 34 | ||
35 | import static com.google.common.base.Preconditions.checkArgument; | 35 | import static com.google.common.base.Preconditions.checkArgument; |
36 | import static com.google.common.base.Preconditions.checkNotNull; | 36 | import static com.google.common.base.Preconditions.checkNotNull; |
37 | +import static org.slf4j.LoggerFactory.getLogger; | ||
37 | 38 | ||
38 | /** | 39 | /** |
39 | * Abstraction of single source, multiple destination connectivity intent. | 40 | * Abstraction of single source, multiple destination connectivity intent. |
40 | */ | 41 | */ |
41 | @Beta | 42 | @Beta |
42 | public final class SinglePointToMultiPointIntent extends ConnectivityIntent { | 43 | public final class SinglePointToMultiPointIntent extends ConnectivityIntent { |
43 | - | 44 | + private final FilteredConnectPoint ingressPoint; |
44 | - private final ConnectPoint ingressPoint; | 45 | + private final Set<FilteredConnectPoint> egressPoints; |
45 | - private final Set<ConnectPoint> egressPoints; | ||
46 | - /** | ||
47 | - * To manage multiple treatments use case. | ||
48 | - */ | ||
49 | - private final Map<ConnectPoint, TrafficTreatment> egressTreatments; | ||
50 | 46 | ||
51 | /** | 47 | /** |
52 | * Creates a new single-to-multi point connectivity intent. | 48 | * Creates a new single-to-multi point connectivity intent. |
... | @@ -59,7 +55,6 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent { | ... | @@ -59,7 +55,6 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent { |
59 | * @param egressPoints set of ports on which traffic will egress | 55 | * @param egressPoints set of ports on which traffic will egress |
60 | * @param constraints constraints to apply to the intent | 56 | * @param constraints constraints to apply to the intent |
61 | * @param priority priority to use for flows generated by this intent | 57 | * @param priority priority to use for flows generated by this intent |
62 | - * @param egressTreatments map to store the association egress to treatment | ||
63 | * @throws NullPointerException if {@code ingressPoint} or | 58 | * @throws NullPointerException if {@code ingressPoint} or |
64 | * {@code egressPoints} is null | 59 | * {@code egressPoints} is null |
65 | * @throws IllegalArgumentException if the size of {@code egressPoints} is | 60 | * @throws IllegalArgumentException if the size of {@code egressPoints} is |
... | @@ -69,22 +64,20 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent { | ... | @@ -69,22 +64,20 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent { |
69 | Key key, | 64 | Key key, |
70 | TrafficSelector selector, | 65 | TrafficSelector selector, |
71 | TrafficTreatment treatment, | 66 | TrafficTreatment treatment, |
72 | - ConnectPoint ingressPoint, | 67 | + FilteredConnectPoint ingressPoint, |
73 | - Set<ConnectPoint> egressPoints, | 68 | + Set<FilteredConnectPoint> egressPoints, |
74 | List<Constraint> constraints, | 69 | List<Constraint> constraints, |
75 | - int priority, | 70 | + int priority) { |
76 | - Map<ConnectPoint, TrafficTreatment> egressTreatments) { | ||
77 | super(appId, key, ImmutableList.of(), selector, treatment, constraints, | 71 | super(appId, key, ImmutableList.of(), selector, treatment, constraints, |
78 | priority); | 72 | priority); |
79 | checkNotNull(egressPoints); | 73 | checkNotNull(egressPoints); |
80 | checkNotNull(ingressPoint); | 74 | checkNotNull(ingressPoint); |
81 | checkArgument(!egressPoints.isEmpty(), "Egress point set cannot be empty"); | 75 | checkArgument(!egressPoints.isEmpty(), "Egress point set cannot be empty"); |
82 | checkArgument(!egressPoints.contains(ingressPoint), | 76 | checkArgument(!egressPoints.contains(ingressPoint), |
83 | - "Set of egresses should not contain ingress (ingress: %s)", ingressPoint); | 77 | + "Set of egresses should not contain ingress (ingress: %s)", ingressPoint); |
84 | 78 | ||
85 | this.ingressPoint = ingressPoint; | 79 | this.ingressPoint = ingressPoint; |
86 | this.egressPoints = Sets.newHashSet(egressPoints); | 80 | this.egressPoints = Sets.newHashSet(egressPoints); |
87 | - this.egressTreatments = egressTreatments; | ||
88 | } | 81 | } |
89 | 82 | ||
90 | /** | 83 | /** |
... | @@ -100,17 +93,42 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent { | ... | @@ -100,17 +93,42 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent { |
100 | } | 93 | } |
101 | 94 | ||
102 | /** | 95 | /** |
96 | + * Creates a new builder pre-populated with the information in the given | ||
97 | + * intent. | ||
98 | + * | ||
99 | + * @param intent initial intent | ||
100 | + * @return intent builder | ||
101 | + */ | ||
102 | + public static Builder builder(SinglePointToMultiPointIntent intent) { | ||
103 | + return new Builder(intent); | ||
104 | + } | ||
105 | + | ||
106 | + /** | ||
103 | * Builder of a single point to multi point intent. | 107 | * Builder of a single point to multi point intent. |
104 | */ | 108 | */ |
105 | public static final class Builder extends ConnectivityIntent.Builder { | 109 | public static final class Builder extends ConnectivityIntent.Builder { |
106 | - ConnectPoint ingressPoint; | 110 | + private final Logger log = getLogger(getClass()); |
107 | - Set<ConnectPoint> egressPoints; | 111 | + private FilteredConnectPoint ingressPoint; |
108 | - Map<ConnectPoint, TrafficTreatment> egressTreatments = ImmutableMap.of(); | 112 | + private Set<FilteredConnectPoint> egressPoints; |
109 | 113 | ||
110 | private Builder() { | 114 | private Builder() { |
111 | // Hide constructor | 115 | // Hide constructor |
112 | } | 116 | } |
113 | 117 | ||
118 | + /** | ||
119 | + * Creates a new builder pre-populated with information from the given | ||
120 | + * intent. | ||
121 | + * | ||
122 | + * @param intent initial intent | ||
123 | + */ | ||
124 | + protected Builder(SinglePointToMultiPointIntent intent) { | ||
125 | + super(intent); | ||
126 | + | ||
127 | + this.filteredEgressPoints(intent.filteredEgressPoints()) | ||
128 | + .filteredIngressPoint(intent.filteredIngressPoint()); | ||
129 | + | ||
130 | + } | ||
131 | + | ||
114 | @Override | 132 | @Override |
115 | public Builder appId(ApplicationId appId) { | 133 | public Builder appId(ApplicationId appId) { |
116 | return (Builder) super.appId(appId); | 134 | return (Builder) super.appId(appId); |
... | @@ -148,8 +166,13 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent { | ... | @@ -148,8 +166,13 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent { |
148 | * @param ingressPoint ingress connect point | 166 | * @param ingressPoint ingress connect point |
149 | * @return this builder | 167 | * @return this builder |
150 | */ | 168 | */ |
169 | + @Deprecated | ||
151 | public Builder ingressPoint(ConnectPoint ingressPoint) { | 170 | public Builder ingressPoint(ConnectPoint ingressPoint) { |
152 | - this.ingressPoint = ingressPoint; | 171 | + if (this.ingressPoint != null) { |
172 | + log.warn("Ingress point is already set, " + | ||
173 | + "this will override original ingress point."); | ||
174 | + } | ||
175 | + this.ingressPoint = new FilteredConnectPoint(ingressPoint); | ||
153 | return this; | 176 | return this; |
154 | } | 177 | } |
155 | 178 | ||
... | @@ -160,23 +183,45 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent { | ... | @@ -160,23 +183,45 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent { |
160 | * @param egressPoints egress connect points | 183 | * @param egressPoints egress connect points |
161 | * @return this builder | 184 | * @return this builder |
162 | */ | 185 | */ |
186 | + @Deprecated | ||
163 | public Builder egressPoints(Set<ConnectPoint> egressPoints) { | 187 | public Builder egressPoints(Set<ConnectPoint> egressPoints) { |
164 | - this.egressPoints = ImmutableSet.copyOf(egressPoints); | 188 | + if (this.egressPoints != null) { |
189 | + log.warn("Egress points are already set, " + | ||
190 | + "this will override original egress points."); | ||
191 | + } | ||
192 | + Set<FilteredConnectPoint> filteredConnectPoints = | ||
193 | + egressPoints.stream() | ||
194 | + .map(FilteredConnectPoint::new) | ||
195 | + .collect(Collectors.toSet()); | ||
196 | + this.egressPoints = ImmutableSet.copyOf(filteredConnectPoints); | ||
165 | return this; | 197 | return this; |
166 | } | 198 | } |
167 | 199 | ||
168 | /** | 200 | /** |
169 | - * Sets the treatments of the single point to multi point intent | 201 | + * Sets the filtered ingress point of the single point to |
170 | - * that will be built. | 202 | + * multi point intent that will be built. |
203 | + * | ||
204 | + * @param ingressPoint ingress connect point | ||
205 | + * @return this builder | ||
206 | + */ | ||
207 | + public Builder filteredIngressPoint(FilteredConnectPoint ingressPoint) { | ||
208 | + this.ingressPoint = ingressPoint; | ||
209 | + return this; | ||
210 | + } | ||
211 | + | ||
212 | + /** | ||
213 | + * Sets the filtered egress points of the single point to | ||
214 | + * multi point intent that will be built. | ||
171 | * | 215 | * |
172 | - * @param egressTreatments the multiple treatments | 216 | + * @param egressPoints egress connect points |
173 | * @return this builder | 217 | * @return this builder |
174 | */ | 218 | */ |
175 | - public Builder treatments(Map<ConnectPoint, TrafficTreatment> egressTreatments) { | 219 | + public Builder filteredEgressPoints(Set<FilteredConnectPoint> egressPoints) { |
176 | - this.egressTreatments = ImmutableMap.copyOf(egressTreatments); | 220 | + this.egressPoints = ImmutableSet.copyOf(egressPoints); |
177 | return this; | 221 | return this; |
178 | } | 222 | } |
179 | 223 | ||
224 | + | ||
180 | /** | 225 | /** |
181 | * Builds a single point to multi point intent from the | 226 | * Builds a single point to multi point intent from the |
182 | * accumulated parameters. | 227 | * accumulated parameters. |
... | @@ -185,12 +230,6 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent { | ... | @@ -185,12 +230,6 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent { |
185 | */ | 230 | */ |
186 | public SinglePointToMultiPointIntent build() { | 231 | public SinglePointToMultiPointIntent build() { |
187 | 232 | ||
188 | - if (treatment != null && !treatment.allInstructions().isEmpty() && | ||
189 | - !treatment.equals(DefaultTrafficTreatment.emptyTreatment()) && | ||
190 | - egressTreatments != null && !egressTreatments.isEmpty()) { | ||
191 | - throw new IllegalArgumentException("Treatment and Multiple Treatments are both set"); | ||
192 | - } | ||
193 | - | ||
194 | return new SinglePointToMultiPointIntent( | 233 | return new SinglePointToMultiPointIntent( |
195 | appId, | 234 | appId, |
196 | key, | 235 | key, |
... | @@ -199,8 +238,7 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent { | ... | @@ -199,8 +238,7 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent { |
199 | ingressPoint, | 238 | ingressPoint, |
200 | egressPoints, | 239 | egressPoints, |
201 | constraints, | 240 | constraints, |
202 | - priority, | 241 | + priority |
203 | - egressTreatments | ||
204 | ); | 242 | ); |
205 | } | 243 | } |
206 | } | 244 | } |
... | @@ -212,7 +250,6 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent { | ... | @@ -212,7 +250,6 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent { |
212 | super(); | 250 | super(); |
213 | this.ingressPoint = null; | 251 | this.ingressPoint = null; |
214 | this.egressPoints = null; | 252 | this.egressPoints = null; |
215 | - this.egressTreatments = null; | ||
216 | } | 253 | } |
217 | 254 | ||
218 | /** | 255 | /** |
... | @@ -222,7 +259,7 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent { | ... | @@ -222,7 +259,7 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent { |
222 | * @return ingress port | 259 | * @return ingress port |
223 | */ | 260 | */ |
224 | public ConnectPoint ingressPoint() { | 261 | public ConnectPoint ingressPoint() { |
225 | - return ingressPoint; | 262 | + return ingressPoint.connectPoint(); |
226 | } | 263 | } |
227 | 264 | ||
228 | /** | 265 | /** |
... | @@ -231,17 +268,31 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent { | ... | @@ -231,17 +268,31 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent { |
231 | * @return set of egress ports | 268 | * @return set of egress ports |
232 | */ | 269 | */ |
233 | public Set<ConnectPoint> egressPoints() { | 270 | public Set<ConnectPoint> egressPoints() { |
234 | - return egressPoints; | 271 | + return egressPoints.stream() |
272 | + .map(FilteredConnectPoint::connectPoint) | ||
273 | + .collect(Collectors.toSet()); | ||
235 | } | 274 | } |
236 | 275 | ||
237 | /** | 276 | /** |
238 | - * Returns the multiple treatments jointly with their connection points. | 277 | + * Returns the filtered port on which the ingress traffic should be connected to the |
239 | - * @return multiple treatments | 278 | + * egress. |
279 | + * | ||
280 | + * @return ingress port | ||
281 | + */ | ||
282 | + public FilteredConnectPoint filteredIngressPoint() { | ||
283 | + return ingressPoint; | ||
284 | + } | ||
285 | + | ||
286 | + /** | ||
287 | + * Returns the set of filtered ports on which the traffic should egress. | ||
288 | + * | ||
289 | + * @return set of egress ports | ||
240 | */ | 290 | */ |
241 | - public Map<ConnectPoint, TrafficTreatment> egressTreatments() { | 291 | + public Set<FilteredConnectPoint> filteredEgressPoints() { |
242 | - return egressTreatments; | 292 | + return egressPoints; |
243 | } | 293 | } |
244 | 294 | ||
295 | + | ||
245 | @Override | 296 | @Override |
246 | public String toString() { | 297 | public String toString() { |
247 | return MoreObjects.toStringHelper(getClass()) | 298 | return MoreObjects.toStringHelper(getClass()) |
... | @@ -254,7 +305,8 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent { | ... | @@ -254,7 +305,8 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent { |
254 | .add("treatment", treatment()) | 305 | .add("treatment", treatment()) |
255 | .add("ingress", ingressPoint) | 306 | .add("ingress", ingressPoint) |
256 | .add("egress", egressPoints) | 307 | .add("egress", egressPoints) |
257 | - .add("treatments", egressTreatments) | 308 | + .add("filteredIngressCPs", filteredIngressPoint()) |
309 | + .add("filteredEgressCP", filteredEgressPoints()) | ||
258 | .add("constraints", constraints()) | 310 | .add("constraints", constraints()) |
259 | .toString(); | 311 | .toString(); |
260 | } | 312 | } | ... | ... |
... | @@ -15,7 +15,6 @@ | ... | @@ -15,7 +15,6 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.intent; | 16 | package org.onosproject.net.intent; |
17 | 17 | ||
18 | -import java.util.Collections; | ||
19 | import java.util.Map; | 18 | import java.util.Map; |
20 | import java.util.Set; | 19 | import java.util.Set; |
21 | 20 | ||
... | @@ -25,6 +24,7 @@ import org.onosproject.core.ApplicationId; | ... | @@ -25,6 +24,7 @@ import org.onosproject.core.ApplicationId; |
25 | import org.onosproject.TestApplicationId; | 24 | import org.onosproject.TestApplicationId; |
26 | import org.onosproject.net.ConnectPoint; | 25 | import org.onosproject.net.ConnectPoint; |
27 | import org.onosproject.net.DeviceId; | 26 | import org.onosproject.net.DeviceId; |
27 | +import org.onosproject.net.FilteredConnectPoint; | ||
28 | import org.onosproject.net.PortNumber; | 28 | import org.onosproject.net.PortNumber; |
29 | import org.onosproject.net.flow.DefaultTrafficSelector; | 29 | import org.onosproject.net.flow.DefaultTrafficSelector; |
30 | import org.onosproject.net.flow.DefaultTrafficTreatment; | 30 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
... | @@ -42,8 +42,6 @@ public abstract class ConnectivityIntentTest extends IntentTest { | ... | @@ -42,8 +42,6 @@ public abstract class ConnectivityIntentTest extends IntentTest { |
42 | public static final IntentId IID = new IntentId(123); | 42 | public static final IntentId IID = new IntentId(123); |
43 | public static final TrafficSelector MATCH = DefaultTrafficSelector.emptySelector(); | 43 | public static final TrafficSelector MATCH = DefaultTrafficSelector.emptySelector(); |
44 | public static final TrafficTreatment NOP = DefaultTrafficTreatment.emptyTreatment(); | 44 | public static final TrafficTreatment NOP = DefaultTrafficTreatment.emptyTreatment(); |
45 | - public static final Map<ConnectPoint, TrafficSelector> MATCHES = Collections.emptyMap(); | ||
46 | - public static final Map<ConnectPoint, TrafficTreatment> TREATMENTS = Collections.emptyMap(); | ||
47 | 45 | ||
48 | public static final ConnectPoint P1 = new ConnectPoint(DeviceId.deviceId("111"), PortNumber.portNumber(0x1)); | 46 | public static final ConnectPoint P1 = new ConnectPoint(DeviceId.deviceId("111"), PortNumber.portNumber(0x1)); |
49 | public static final ConnectPoint P2 = new ConnectPoint(DeviceId.deviceId("222"), PortNumber.portNumber(0x2)); | 47 | public static final ConnectPoint P2 = new ConnectPoint(DeviceId.deviceId("222"), PortNumber.portNumber(0x2)); |
... | @@ -52,6 +50,7 @@ public abstract class ConnectivityIntentTest extends IntentTest { | ... | @@ -52,6 +50,7 @@ public abstract class ConnectivityIntentTest extends IntentTest { |
52 | public static final Set<ConnectPoint> PS1 = itemSet(new ConnectPoint[]{P1, P3}); | 50 | public static final Set<ConnectPoint> PS1 = itemSet(new ConnectPoint[]{P1, P3}); |
53 | public static final Set<ConnectPoint> PS2 = itemSet(new ConnectPoint[]{P2, P3}); | 51 | public static final Set<ConnectPoint> PS2 = itemSet(new ConnectPoint[]{P2, P3}); |
54 | 52 | ||
53 | + | ||
55 | public static final TrafficSelector VLANMATCH1 = DefaultTrafficSelector.builder() | 54 | public static final TrafficSelector VLANMATCH1 = DefaultTrafficSelector.builder() |
56 | .matchVlanId(VlanId.vlanId("2")) | 55 | .matchVlanId(VlanId.vlanId("2")) |
57 | .build(); | 56 | .build(); |
... | @@ -59,6 +58,13 @@ public abstract class ConnectivityIntentTest extends IntentTest { | ... | @@ -59,6 +58,13 @@ public abstract class ConnectivityIntentTest extends IntentTest { |
59 | .matchVlanId(VlanId.vlanId("3")) | 58 | .matchVlanId(VlanId.vlanId("3")) |
60 | .build(); | 59 | .build(); |
61 | 60 | ||
61 | + public static final FilteredConnectPoint FP1 = new FilteredConnectPoint(P1, VLANMATCH1); | ||
62 | + public static final FilteredConnectPoint FP2 = new FilteredConnectPoint(P2, VLANMATCH1); | ||
63 | + public static final FilteredConnectPoint FP3 = new FilteredConnectPoint(P3, VLANMATCH2); | ||
64 | + | ||
65 | + public static final Set<FilteredConnectPoint> FPS1 = itemSet(new FilteredConnectPoint[]{FP1, FP3}); | ||
66 | + public static final Set<FilteredConnectPoint> FPS2 = itemSet(new FilteredConnectPoint[]{FP2, FP3}); | ||
67 | + | ||
62 | public static final Map<ConnectPoint, TrafficSelector> VLANMATCHES = Maps.newHashMap(); | 68 | public static final Map<ConnectPoint, TrafficSelector> VLANMATCHES = Maps.newHashMap(); |
63 | static { | 69 | static { |
64 | VLANMATCHES.put(P1, VLANMATCH1); | 70 | VLANMATCHES.put(P1, VLANMATCH1); | ... | ... |
... | @@ -26,7 +26,7 @@ import org.onosproject.net.Link; | ... | @@ -26,7 +26,7 @@ import org.onosproject.net.Link; |
26 | import org.onosproject.net.NetTestTools; | 26 | import org.onosproject.net.NetTestTools; |
27 | import org.onosproject.net.NetworkResource; | 27 | import org.onosproject.net.NetworkResource; |
28 | import org.onosproject.net.Path; | 28 | import org.onosproject.net.Path; |
29 | -import org.onosproject.net.flow.FlowRule.FlowRemoveReason; | 29 | +import org.onosproject.net.device.DeviceServiceAdapter; |
30 | import org.onosproject.net.flow.FlowId; | 30 | import org.onosproject.net.flow.FlowId; |
31 | import org.onosproject.net.flow.FlowRule; | 31 | import org.onosproject.net.flow.FlowRule; |
32 | import org.onosproject.net.flow.FlowRuleExtPayLoad; | 32 | import org.onosproject.net.flow.FlowRuleExtPayLoad; |
... | @@ -180,6 +180,67 @@ public class IntentTestsMocks { | ... | @@ -180,6 +180,67 @@ public class IntentTestsMocks { |
180 | } | 180 | } |
181 | } | 181 | } |
182 | 182 | ||
183 | + /** | ||
184 | + * Mock path service for creating paths within the test. | ||
185 | + * | ||
186 | + */ | ||
187 | + public static class Mp2MpMockPathService | ||
188 | + extends PathServiceAdapter { | ||
189 | + | ||
190 | + final String[] pathHops; | ||
191 | + final String[] reversePathHops; | ||
192 | + | ||
193 | + /** | ||
194 | + * Constructor that provides a set of hops to mock. | ||
195 | + * | ||
196 | + * @param pathHops path hops to mock | ||
197 | + */ | ||
198 | + public Mp2MpMockPathService(String[] pathHops) { | ||
199 | + this.pathHops = pathHops; | ||
200 | + String[] reversed = pathHops.clone(); | ||
201 | + Collections.reverse(Arrays.asList(reversed)); | ||
202 | + reversePathHops = reversed; | ||
203 | + } | ||
204 | + | ||
205 | + @Override | ||
206 | + public Set<Path> getPaths(ElementId src, ElementId dst) { | ||
207 | + Set<Path> result = new HashSet<>(); | ||
208 | + | ||
209 | + String[] allHops = new String[pathHops.length + 2]; | ||
210 | + allHops[0] = src.toString(); | ||
211 | + allHops[allHops.length - 1] = dst.toString(); | ||
212 | + | ||
213 | + if (pathHops.length != 0) { | ||
214 | + System.arraycopy(pathHops, 0, allHops, 1, pathHops.length); | ||
215 | + } | ||
216 | + | ||
217 | + result.add(createPath(allHops)); | ||
218 | + | ||
219 | + return result; | ||
220 | + } | ||
221 | + | ||
222 | + @Override | ||
223 | + public Set<Path> getPaths(ElementId src, ElementId dst, LinkWeight weight) { | ||
224 | + final Set<Path> paths = getPaths(src, dst); | ||
225 | + | ||
226 | + for (Path path : paths) { | ||
227 | + final DeviceId srcDevice = path.src().elementId() instanceof DeviceId ? path.src().deviceId() : null; | ||
228 | + final DeviceId dstDevice = path.dst().elementId() instanceof DeviceId ? path.dst().deviceId() : null; | ||
229 | + if (srcDevice != null && dstDevice != null) { | ||
230 | + final TopologyVertex srcVertex = new DefaultTopologyVertex(srcDevice); | ||
231 | + final TopologyVertex dstVertex = new DefaultTopologyVertex(dstDevice); | ||
232 | + final Link link = link(src.toString(), 1, dst.toString(), 1); | ||
233 | + | ||
234 | + final double weightValue = weight.weight(new DefaultTopologyEdge(srcVertex, dstVertex, link)); | ||
235 | + if (weightValue < 0) { | ||
236 | + return new HashSet<>(); | ||
237 | + } | ||
238 | + } | ||
239 | + } | ||
240 | + return paths; | ||
241 | + } | ||
242 | + } | ||
243 | + | ||
183 | public static final class MockResourceService implements ResourceService { | 244 | public static final class MockResourceService implements ResourceService { |
184 | 245 | ||
185 | private final double bandwidth; | 246 | private final double bandwidth; |
... | @@ -429,4 +490,14 @@ public class IntentTestsMocks { | ... | @@ -429,4 +490,14 @@ public class IntentTestsMocks { |
429 | } | 490 | } |
430 | } | 491 | } |
431 | 492 | ||
493 | + /** | ||
494 | + * Mocks the device service so that a device appears available in the test. | ||
495 | + */ | ||
496 | + public static class MockDeviceService extends DeviceServiceAdapter { | ||
497 | + @Override | ||
498 | + public boolean isAvailable(DeviceId deviceId) { | ||
499 | + return true; | ||
500 | + } | ||
501 | + } | ||
502 | + | ||
432 | } | 503 | } | ... | ... |
... | @@ -21,8 +21,10 @@ import java.util.LinkedList; | ... | @@ -21,8 +21,10 @@ import java.util.LinkedList; |
21 | import java.util.List; | 21 | import java.util.List; |
22 | import java.util.Set; | 22 | import java.util.Set; |
23 | 23 | ||
24 | +import com.google.common.collect.Sets; | ||
24 | import org.junit.Test; | 25 | import org.junit.Test; |
25 | import org.onosproject.net.ConnectPoint; | 26 | import org.onosproject.net.ConnectPoint; |
27 | +import org.onosproject.net.FilteredConnectPoint; | ||
26 | import org.onosproject.net.Link; | 28 | import org.onosproject.net.Link; |
27 | import org.onosproject.net.NetTestTools; | 29 | import org.onosproject.net.NetTestTools; |
28 | import org.onosproject.net.flow.TrafficSelector; | 30 | import org.onosproject.net.flow.TrafficSelector; |
... | @@ -49,6 +51,8 @@ public class LinkCollectionIntentTest extends IntentTest { | ... | @@ -49,6 +51,8 @@ public class LinkCollectionIntentTest extends IntentTest { |
49 | final ConnectPoint egress = NetTestTools.connectPoint("egress", 3); | 51 | final ConnectPoint egress = NetTestTools.connectPoint("egress", 3); |
50 | final TrafficSelector selector = new IntentTestsMocks.MockSelector(); | 52 | final TrafficSelector selector = new IntentTestsMocks.MockSelector(); |
51 | final IntentTestsMocks.MockTreatment treatment = new IntentTestsMocks.MockTreatment(); | 53 | final IntentTestsMocks.MockTreatment treatment = new IntentTestsMocks.MockTreatment(); |
54 | + final FilteredConnectPoint filteredIngress = new FilteredConnectPoint(ingress); | ||
55 | + final FilteredConnectPoint filteredEgress = new FilteredConnectPoint(egress); | ||
52 | 56 | ||
53 | /** | 57 | /** |
54 | * Checks that the LinkCollectionIntent class is immutable. | 58 | * Checks that the LinkCollectionIntent class is immutable. |
... | @@ -179,6 +183,39 @@ public class LinkCollectionIntentTest extends IntentTest { | ... | @@ -179,6 +183,39 @@ public class LinkCollectionIntentTest extends IntentTest { |
179 | assertThat(createdConstraints, hasSize(0)); | 183 | assertThat(createdConstraints, hasSize(0)); |
180 | } | 184 | } |
181 | 185 | ||
186 | + /** | ||
187 | + * Test filtered connection point for LinkCollection intent. | ||
188 | + */ | ||
189 | + @Test | ||
190 | + public void testFilteredConnectedPoint() { | ||
191 | + LinkCollectionIntent intent = createFilteredOne(); | ||
192 | + Set<Link> links = Sets.newHashSet(); | ||
193 | + links.add(link("A", 1, "B", 1)); | ||
194 | + links.add(link("A", 2, "C", 1)); | ||
195 | + | ||
196 | + assertThat(intent.appId(), is(APP_ID)); | ||
197 | + assertThat(intent.treatment(), is(treatment)); | ||
198 | + assertThat(intent.links(), is(links)); | ||
199 | + assertThat(intent.applyTreatmentOnEgress(), is(false)); | ||
200 | + assertThat(intent.filteredIngressPoints(), is(ImmutableSet.of(filteredIngress))); | ||
201 | + assertThat(intent.filteredEgressPoints(), is(ImmutableSet.of(filteredEgress))); | ||
202 | + | ||
203 | + intent = createAnotherFiltered(); | ||
204 | + links = Sets.newHashSet(); | ||
205 | + links.add(link("A", 1, "B", 1)); | ||
206 | + links.add(link("A", 2, "C", 1)); | ||
207 | + links.add(link("B", 2, "D", 1)); | ||
208 | + links.add(link("B", 3, "E", 1)); | ||
209 | + | ||
210 | + assertThat(intent.appId(), is(APP_ID)); | ||
211 | + assertThat(intent.treatment(), is(treatment)); | ||
212 | + assertThat(intent.links(), is(links)); | ||
213 | + assertThat(intent.applyTreatmentOnEgress(), is(true)); | ||
214 | + assertThat(intent.filteredIngressPoints(), is(ImmutableSet.of(filteredIngress))); | ||
215 | + assertThat(intent.filteredEgressPoints(), is(ImmutableSet.of(filteredEgress))); | ||
216 | + | ||
217 | + } | ||
218 | + | ||
182 | @Override | 219 | @Override |
183 | protected Intent createOne() { | 220 | protected Intent createOne() { |
184 | HashSet<Link> links1 = new HashSet<>(); | 221 | HashSet<Link> links1 = new HashSet<>(); |
... | @@ -206,4 +243,33 @@ public class LinkCollectionIntentTest extends IntentTest { | ... | @@ -206,4 +243,33 @@ public class LinkCollectionIntentTest extends IntentTest { |
206 | .egressPoints(ImmutableSet.of(egress)) | 243 | .egressPoints(ImmutableSet.of(egress)) |
207 | .build(); | 244 | .build(); |
208 | } | 245 | } |
246 | + | ||
247 | + protected LinkCollectionIntent createFilteredOne() { | ||
248 | + Set<Link> links = Sets.newHashSet(); | ||
249 | + links.add(link("A", 1, "B", 1)); | ||
250 | + links.add(link("A", 2, "C", 1)); | ||
251 | + return LinkCollectionIntent.builder() | ||
252 | + .appId(APP_ID) | ||
253 | + .treatment(treatment) | ||
254 | + .links(links) | ||
255 | + .filteredIngressPoints(ImmutableSet.of(filteredIngress)) | ||
256 | + .filteredEgressPoints(ImmutableSet.of(filteredEgress)) | ||
257 | + .build(); | ||
258 | + } | ||
259 | + | ||
260 | + protected LinkCollectionIntent createAnotherFiltered() { | ||
261 | + Set<Link> links = Sets.newHashSet(); | ||
262 | + links.add(link("A", 1, "B", 1)); | ||
263 | + links.add(link("A", 2, "C", 1)); | ||
264 | + links.add(link("B", 2, "D", 1)); | ||
265 | + links.add(link("B", 3, "E", 1)); | ||
266 | + return LinkCollectionIntent.builder() | ||
267 | + .appId(APP_ID) | ||
268 | + .treatment(treatment) | ||
269 | + .links(links) | ||
270 | + .applyTreatmentOnEgress(true) | ||
271 | + .filteredIngressPoints(ImmutableSet.of(filteredIngress)) | ||
272 | + .filteredEgressPoints(ImmutableSet.of(filteredEgress)) | ||
273 | + .build(); | ||
274 | + } | ||
209 | } | 275 | } | ... | ... |
... | @@ -16,9 +16,7 @@ | ... | @@ -16,9 +16,7 @@ |
16 | 16 | ||
17 | package org.onosproject.net.intent; | 17 | package org.onosproject.net.intent; |
18 | 18 | ||
19 | -import org.junit.Rule; | ||
20 | import org.junit.Test; | 19 | import org.junit.Test; |
21 | -import org.junit.rules.ExpectedException; | ||
22 | 20 | ||
23 | import static org.junit.Assert.assertEquals; | 21 | import static org.junit.Assert.assertEquals; |
24 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; | 22 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
... | @@ -36,6 +34,9 @@ public class MultiPointToSinglePointIntentTest extends ConnectivityIntentTest { | ... | @@ -36,6 +34,9 @@ public class MultiPointToSinglePointIntentTest extends ConnectivityIntentTest { |
36 | assertThatClassIsImmutable(MultiPointToSinglePointIntent.class); | 34 | assertThatClassIsImmutable(MultiPointToSinglePointIntent.class); |
37 | } | 35 | } |
38 | 36 | ||
37 | + /** | ||
38 | + * Create three intents with normal connect points. | ||
39 | + */ | ||
39 | @Test | 40 | @Test |
40 | public void basics() { | 41 | public void basics() { |
41 | MultiPointToSinglePointIntent intent = createOne(); | 42 | MultiPointToSinglePointIntent intent = createOne(); |
... | @@ -43,40 +44,38 @@ public class MultiPointToSinglePointIntentTest extends ConnectivityIntentTest { | ... | @@ -43,40 +44,38 @@ public class MultiPointToSinglePointIntentTest extends ConnectivityIntentTest { |
43 | assertEquals("incorrect match", MATCH, intent.selector()); | 44 | assertEquals("incorrect match", MATCH, intent.selector()); |
44 | assertEquals("incorrect ingress", PS1, intent.ingressPoints()); | 45 | assertEquals("incorrect ingress", PS1, intent.ingressPoints()); |
45 | assertEquals("incorrect egress", P2, intent.egressPoint()); | 46 | assertEquals("incorrect egress", P2, intent.egressPoint()); |
46 | - } | ||
47 | - | ||
48 | - @Rule | ||
49 | - public ExpectedException wrongMultiple = ExpectedException.none(); | ||
50 | 47 | ||
51 | - @Test | 48 | + intent = createAnother(); |
52 | - public void multipleSelectors() { | ||
53 | - | ||
54 | - MultiPointToSinglePointIntent intent = createFirstMultiple(); | ||
55 | assertEquals("incorrect id", APPID, intent.appId()); | 49 | assertEquals("incorrect id", APPID, intent.appId()); |
56 | assertEquals("incorrect match", MATCH, intent.selector()); | 50 | assertEquals("incorrect match", MATCH, intent.selector()); |
57 | - assertEquals("incorrect ingress", PS1, intent.ingressPoints()); | 51 | + assertEquals("incorrect ingress", PS2, intent.ingressPoints()); |
58 | - assertEquals("incorrect egress", P2, intent.egressPoint()); | 52 | + assertEquals("incorrect egress", P1, intent.egressPoint()); |
59 | - assertEquals("incorrect selectors", MATCHES, intent.ingressSelectors()); | ||
60 | 53 | ||
61 | - intent = createSecondMultiple(); | 54 | + intent = createVlanMatch(); |
62 | assertEquals("incorrect id", APPID, intent.appId()); | 55 | assertEquals("incorrect id", APPID, intent.appId()); |
63 | assertEquals("incorrect match", VLANMATCH1, intent.selector()); | 56 | assertEquals("incorrect match", VLANMATCH1, intent.selector()); |
64 | assertEquals("incorrect ingress", PS1, intent.ingressPoints()); | 57 | assertEquals("incorrect ingress", PS1, intent.ingressPoints()); |
65 | assertEquals("incorrect egress", P2, intent.egressPoint()); | 58 | assertEquals("incorrect egress", P2, intent.egressPoint()); |
66 | - assertEquals("incorrect selectors", MATCHES, intent.ingressSelectors()); | 59 | + } |
67 | 60 | ||
68 | - intent = createThirdMultiple(); | 61 | + /** |
62 | + * Create two intents with filtered connect points. | ||
63 | + */ | ||
64 | + @Test | ||
65 | + public void filteredIntent() { | ||
66 | + MultiPointToSinglePointIntent intent = createFilteredOne(); | ||
69 | assertEquals("incorrect id", APPID, intent.appId()); | 67 | assertEquals("incorrect id", APPID, intent.appId()); |
70 | assertEquals("incorrect match", MATCH, intent.selector()); | 68 | assertEquals("incorrect match", MATCH, intent.selector()); |
71 | - assertEquals("incorrect ingress", PS1, intent.ingressPoints()); | 69 | + assertEquals("incorrect filtered ingress", FPS1, intent.filteredIngressPoints()); |
72 | - assertEquals("incorrect egress", P2, intent.egressPoint()); | 70 | + assertEquals("incorrect filtered egress", FP2, intent.filteredEgressPoint()); |
73 | - assertEquals("incorrect selectors", VLANMATCHES, intent.ingressSelectors()); | ||
74 | 71 | ||
75 | - wrongMultiple.expect(IllegalArgumentException.class); | 72 | + intent = createAnotherFiltered(); |
76 | - wrongMultiple.expectMessage("Selector and Multiple Selectors are both set"); | 73 | + assertEquals("incorrect id", APPID, intent.appId()); |
77 | - intent = createWrongMultiple(); | 74 | + assertEquals("incorrect match", MATCH, intent.selector()); |
78 | - } | 75 | + assertEquals("incorrect filtered ingress", FPS2, intent.filteredIngressPoints()); |
76 | + assertEquals("incorrect filtered egress", FP1, intent.filteredEgressPoint()); | ||
79 | 77 | ||
78 | + } | ||
80 | 79 | ||
81 | @Override | 80 | @Override |
82 | protected MultiPointToSinglePointIntent createOne() { | 81 | protected MultiPointToSinglePointIntent createOne() { |
... | @@ -100,47 +99,42 @@ public class MultiPointToSinglePointIntentTest extends ConnectivityIntentTest { | ... | @@ -100,47 +99,42 @@ public class MultiPointToSinglePointIntentTest extends ConnectivityIntentTest { |
100 | .build(); | 99 | .build(); |
101 | } | 100 | } |
102 | 101 | ||
103 | - protected MultiPointToSinglePointIntent createFirstMultiple() { | 102 | + protected MultiPointToSinglePointIntent createVlanMatch() { |
104 | return MultiPointToSinglePointIntent.builder() | 103 | return MultiPointToSinglePointIntent.builder() |
105 | .appId(APPID) | 104 | .appId(APPID) |
106 | - .selector(MATCH) | 105 | + .selector(VLANMATCH1) |
107 | .treatment(NOP) | 106 | .treatment(NOP) |
108 | .ingressPoints(PS1) | 107 | .ingressPoints(PS1) |
109 | .egressPoint(P2) | 108 | .egressPoint(P2) |
110 | - .selectors(MATCHES) | ||
111 | .build(); | 109 | .build(); |
112 | } | 110 | } |
113 | 111 | ||
114 | - protected MultiPointToSinglePointIntent createSecondMultiple() { | 112 | + |
113 | + protected MultiPointToSinglePointIntent createFilteredOne() { | ||
115 | return MultiPointToSinglePointIntent.builder() | 114 | return MultiPointToSinglePointIntent.builder() |
116 | .appId(APPID) | 115 | .appId(APPID) |
117 | - .selector(VLANMATCH1) | ||
118 | .treatment(NOP) | 116 | .treatment(NOP) |
119 | - .ingressPoints(PS1) | 117 | + .filteredIngressPoints(FPS1) |
120 | - .egressPoint(P2) | 118 | + .filteredEgressPoint(FP2) |
121 | - .selectors(MATCHES) | ||
122 | .build(); | 119 | .build(); |
123 | } | 120 | } |
124 | 121 | ||
125 | - protected MultiPointToSinglePointIntent createThirdMultiple() { | 122 | + protected MultiPointToSinglePointIntent createAnotherFiltered() { |
126 | return MultiPointToSinglePointIntent.builder() | 123 | return MultiPointToSinglePointIntent.builder() |
127 | .appId(APPID) | 124 | .appId(APPID) |
128 | - .selector(MATCH) | ||
129 | .treatment(NOP) | 125 | .treatment(NOP) |
130 | - .ingressPoints(PS1) | 126 | + .filteredIngressPoints(FPS2) |
131 | - .egressPoint(P2) | 127 | + .filteredEgressPoint(FP1) |
132 | - .selectors(VLANMATCHES) | ||
133 | .build(); | 128 | .build(); |
134 | } | 129 | } |
135 | 130 | ||
136 | - protected MultiPointToSinglePointIntent createWrongMultiple() { | 131 | + protected MultiPointToSinglePointIntent createWrongIntent() { |
137 | return MultiPointToSinglePointIntent.builder() | 132 | return MultiPointToSinglePointIntent.builder() |
138 | .appId(APPID) | 133 | .appId(APPID) |
139 | .selector(VLANMATCH1) | 134 | .selector(VLANMATCH1) |
140 | .treatment(NOP) | 135 | .treatment(NOP) |
141 | - .ingressPoints(PS1) | 136 | + .filteredIngressPoints(FPS1) |
142 | - .egressPoint(P2) | 137 | + .filteredEgressPoint(FP2) |
143 | - .selectors(VLANMATCHES) | ||
144 | .build(); | 138 | .build(); |
145 | } | 139 | } |
146 | 140 | ... | ... |
... | @@ -15,9 +15,7 @@ | ... | @@ -15,9 +15,7 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.intent; | 16 | package org.onosproject.net.intent; |
17 | 17 | ||
18 | -import org.junit.Rule; | ||
19 | import org.junit.Test; | 18 | import org.junit.Test; |
20 | -import org.junit.rules.ExpectedException; | ||
21 | 19 | ||
22 | import static org.junit.Assert.assertEquals; | 20 | import static org.junit.Assert.assertEquals; |
23 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; | 21 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
... | @@ -42,41 +40,28 @@ public class SinglePointToMultiPointIntentTest extends ConnectivityIntentTest { | ... | @@ -42,41 +40,28 @@ public class SinglePointToMultiPointIntentTest extends ConnectivityIntentTest { |
42 | assertEquals("incorrect match", MATCH, intent.selector()); | 40 | assertEquals("incorrect match", MATCH, intent.selector()); |
43 | assertEquals("incorrect ingress", P1, intent.ingressPoint()); | 41 | assertEquals("incorrect ingress", P1, intent.ingressPoint()); |
44 | assertEquals("incorrect egress", PS2, intent.egressPoints()); | 42 | assertEquals("incorrect egress", PS2, intent.egressPoints()); |
45 | - } | ||
46 | - | ||
47 | - @Rule | ||
48 | - public ExpectedException wrongMultiple = ExpectedException.none(); | ||
49 | - | ||
50 | - @Test | ||
51 | - public void multipleTreatments() { | ||
52 | 43 | ||
53 | - SinglePointToMultiPointIntent intent = createFirstMultiple(); | 44 | + intent = createAnother(); |
54 | assertEquals("incorrect id", APPID, intent.appId()); | 45 | assertEquals("incorrect id", APPID, intent.appId()); |
55 | assertEquals("incorrect match", MATCH, intent.selector()); | 46 | assertEquals("incorrect match", MATCH, intent.selector()); |
56 | - assertEquals("incorrect ingress", P1, intent.ingressPoint()); | 47 | + assertEquals("incorrect ingress", P2, intent.ingressPoint()); |
57 | - assertEquals("incorrect egress", PS2, intent.egressPoints()); | 48 | + assertEquals("incorrect egress", PS1, intent.egressPoints()); |
58 | - assertEquals("incorrect treatment", NOP, intent.treatment()); | 49 | + } |
59 | - assertEquals("incorrect treatments", TREATMENTS, intent.egressTreatments()); | ||
60 | 50 | ||
61 | - intent = createSecondMultiple(); | 51 | + @Test |
52 | + public void filteredIntent() { | ||
53 | + SinglePointToMultiPointIntent intent = createFilteredOne(); | ||
62 | assertEquals("incorrect id", APPID, intent.appId()); | 54 | assertEquals("incorrect id", APPID, intent.appId()); |
63 | assertEquals("incorrect match", MATCH, intent.selector()); | 55 | assertEquals("incorrect match", MATCH, intent.selector()); |
64 | - assertEquals("incorrect ingress", P1, intent.ingressPoint()); | 56 | + assertEquals("incorrect filtered ingress", FP2, intent.filteredIngressPoint()); |
65 | - assertEquals("incorrect egress", PS2, intent.egressPoints()); | 57 | + assertEquals("incorrect filtered egress", FPS1, intent.filteredEgressPoints()); |
66 | - assertEquals("incorrect treatment", VLANACTION1, intent.treatment()); | ||
67 | - assertEquals("incorrect selectors", TREATMENTS, intent.egressTreatments()); | ||
68 | 58 | ||
69 | - intent = createThirdMultiple(); | 59 | + intent = createAnotherFiltered(); |
70 | assertEquals("incorrect id", APPID, intent.appId()); | 60 | assertEquals("incorrect id", APPID, intent.appId()); |
71 | assertEquals("incorrect match", MATCH, intent.selector()); | 61 | assertEquals("incorrect match", MATCH, intent.selector()); |
72 | - assertEquals("incorrect ingress", P1, intent.ingressPoint()); | 62 | + assertEquals("incorrect filtered ingress", FP1, intent.filteredIngressPoint()); |
73 | - assertEquals("incorrect egress", PS2, intent.egressPoints()); | 63 | + assertEquals("incorrect filtered egress", FPS2, intent.filteredEgressPoints()); |
74 | - assertEquals("incorrect treatment", NOP, intent.treatment()); | ||
75 | - assertEquals("incorrect selectors", VLANACTIONS, intent.egressTreatments()); | ||
76 | 64 | ||
77 | - wrongMultiple.expect(IllegalArgumentException.class); | ||
78 | - wrongMultiple.expectMessage("Treatment and Multiple Treatments are both set"); | ||
79 | - intent = createWrongMultiple(); | ||
80 | } | 65 | } |
81 | 66 | ||
82 | @Override | 67 | @Override |
... | @@ -101,48 +86,31 @@ public class SinglePointToMultiPointIntentTest extends ConnectivityIntentTest { | ... | @@ -101,48 +86,31 @@ public class SinglePointToMultiPointIntentTest extends ConnectivityIntentTest { |
101 | .build(); | 86 | .build(); |
102 | } | 87 | } |
103 | 88 | ||
104 | - | 89 | + protected SinglePointToMultiPointIntent createFilteredOne() { |
105 | - protected SinglePointToMultiPointIntent createFirstMultiple() { | ||
106 | return SinglePointToMultiPointIntent.builder() | 90 | return SinglePointToMultiPointIntent.builder() |
107 | .appId(APPID) | 91 | .appId(APPID) |
108 | - .selector(MATCH) | ||
109 | .treatment(NOP) | 92 | .treatment(NOP) |
110 | - .ingressPoint(P1) | 93 | + .filteredEgressPoints(FPS1) |
111 | - .egressPoints(PS2) | 94 | + .filteredIngressPoint(FP2) |
112 | - .treatments(TREATMENTS) | ||
113 | .build(); | 95 | .build(); |
114 | } | 96 | } |
115 | 97 | ||
116 | - protected SinglePointToMultiPointIntent createSecondMultiple() { | 98 | + protected SinglePointToMultiPointIntent createAnotherFiltered() { |
117 | return SinglePointToMultiPointIntent.builder() | 99 | return SinglePointToMultiPointIntent.builder() |
118 | .appId(APPID) | 100 | .appId(APPID) |
119 | - .selector(MATCH) | ||
120 | - .treatment(VLANACTION1) | ||
121 | - .ingressPoint(P1) | ||
122 | - .egressPoints(PS2) | ||
123 | - .treatments(TREATMENTS) | ||
124 | - .build(); | ||
125 | - } | ||
126 | - | ||
127 | - protected SinglePointToMultiPointIntent createThirdMultiple() { | ||
128 | - return SinglePointToMultiPointIntent.builder() | ||
129 | - .appId(APPID) | ||
130 | - .selector(MATCH) | ||
131 | .treatment(NOP) | 101 | .treatment(NOP) |
132 | - .ingressPoint(P1) | 102 | + .filteredEgressPoints(FPS2) |
133 | - .egressPoints(PS2) | 103 | + .filteredIngressPoint(FP1) |
134 | - .treatments(VLANACTIONS) | ||
135 | .build(); | 104 | .build(); |
136 | } | 105 | } |
137 | 106 | ||
138 | - protected SinglePointToMultiPointIntent createWrongMultiple() { | 107 | + protected SinglePointToMultiPointIntent createWrongIntent() { |
139 | return SinglePointToMultiPointIntent.builder() | 108 | return SinglePointToMultiPointIntent.builder() |
140 | .appId(APPID) | 109 | .appId(APPID) |
141 | - .selector(MATCH) | 110 | + .treatment(NOP) |
142 | - .treatment(VLANACTION1) | 111 | + .selector(VLANMATCH1) |
143 | - .ingressPoint(P1) | 112 | + .filteredEgressPoints(FPS2) |
144 | - .egressPoints(PS2) | 113 | + .filteredIngressPoint(FP1) |
145 | - .treatments(VLANACTIONS) | ||
146 | .build(); | 114 | .build(); |
147 | } | 115 | } |
148 | 116 | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -119,12 +119,10 @@ public class MultiPointToSinglePointIntentCompiler | ... | @@ -119,12 +119,10 @@ public class MultiPointToSinglePointIntentCompiler |
119 | 119 | ||
120 | Intent result = LinkCollectionIntent.builder() | 120 | Intent result = LinkCollectionIntent.builder() |
121 | .appId(intent.appId()) | 121 | .appId(intent.appId()) |
122 | - .selector(intent.selector()) | ||
123 | .treatment(intent.treatment()) | 122 | .treatment(intent.treatment()) |
124 | .links(Sets.newHashSet(links.values())) | 123 | .links(Sets.newHashSet(links.values())) |
125 | - .ingressPoints(intent.ingressPoints()) | 124 | + .filteredIngressPoints(intent.filteredIngressPoints()) |
126 | - .egressPoints(ImmutableSet.of(intent.egressPoint())) | 125 | + .filteredEgressPoints(ImmutableSet.of(intent.filteredEgressPoint())) |
127 | - .ingressSelectors(intent.ingressSelectors()) | ||
128 | .priority(intent.priority()) | 126 | .priority(intent.priority()) |
129 | .constraints(intent.constraints()) | 127 | .constraints(intent.constraints()) |
130 | .build(); | 128 | .build(); | ... | ... |
... | @@ -69,15 +69,13 @@ public class SinglePointToMultiPointIntentCompiler | ... | @@ -69,15 +69,13 @@ public class SinglePointToMultiPointIntentCompiler |
69 | Intent result = LinkCollectionIntent.builder() | 69 | Intent result = LinkCollectionIntent.builder() |
70 | .appId(intent.appId()) | 70 | .appId(intent.appId()) |
71 | .key(intent.key()) | 71 | .key(intent.key()) |
72 | - .selector(intent.selector()) | ||
73 | .treatment(intent.treatment()) | 72 | .treatment(intent.treatment()) |
74 | .links(links) | 73 | .links(links) |
75 | - .ingressPoints(ImmutableSet.of(intent.ingressPoint())) | 74 | + .filteredIngressPoints(ImmutableSet.of(intent.filteredIngressPoint())) |
76 | - .egressPoints(intent.egressPoints()) | 75 | + .filteredEgressPoints(intent.filteredEgressPoints()) |
77 | .priority(intent.priority()) | 76 | .priority(intent.priority()) |
78 | .applyTreatmentOnEgress(true) | 77 | .applyTreatmentOnEgress(true) |
79 | .constraints(intent.constraints()) | 78 | .constraints(intent.constraints()) |
80 | - .egressTreatments(intent.egressTreatments()) | ||
81 | .build(); | 79 | .build(); |
82 | 80 | ||
83 | return Collections.singletonList(result); | 81 | return Collections.singletonList(result); | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -15,15 +15,15 @@ | ... | @@ -15,15 +15,15 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.intent.impl.compiler; | 16 | package org.onosproject.net.intent.impl.compiler; |
17 | 17 | ||
18 | +import com.google.common.collect.ImmutableSet; | ||
18 | import org.hamcrest.Matchers; | 19 | import org.hamcrest.Matchers; |
19 | import org.junit.Test; | 20 | import org.junit.Test; |
21 | +import org.onlab.packet.VlanId; | ||
20 | import org.onosproject.TestApplicationId; | 22 | import org.onosproject.TestApplicationId; |
21 | import org.onosproject.core.ApplicationId; | 23 | import org.onosproject.core.ApplicationId; |
22 | import org.onosproject.net.ConnectPoint; | 24 | import org.onosproject.net.ConnectPoint; |
23 | -import org.onosproject.net.DeviceId; | 25 | +import org.onosproject.net.FilteredConnectPoint; |
24 | -import org.onosproject.net.ElementId; | 26 | +import org.onosproject.net.flow.DefaultTrafficSelector; |
25 | -import org.onosproject.net.Path; | ||
26 | -import org.onosproject.net.device.DeviceServiceAdapter; | ||
27 | import org.onosproject.net.flow.TrafficSelector; | 27 | import org.onosproject.net.flow.TrafficSelector; |
28 | import org.onosproject.net.flow.TrafficTreatment; | 28 | import org.onosproject.net.flow.TrafficTreatment; |
29 | import org.onosproject.net.intent.AbstractIntentTest; | 29 | import org.onosproject.net.intent.AbstractIntentTest; |
... | @@ -31,7 +31,6 @@ import org.onosproject.net.intent.Intent; | ... | @@ -31,7 +31,6 @@ import org.onosproject.net.intent.Intent; |
31 | import org.onosproject.net.intent.IntentTestsMocks; | 31 | import org.onosproject.net.intent.IntentTestsMocks; |
32 | import org.onosproject.net.intent.LinkCollectionIntent; | 32 | import org.onosproject.net.intent.LinkCollectionIntent; |
33 | import org.onosproject.net.intent.MultiPointToSinglePointIntent; | 33 | import org.onosproject.net.intent.MultiPointToSinglePointIntent; |
34 | -import org.onosproject.net.topology.PathServiceAdapter; | ||
35 | 34 | ||
36 | import java.util.HashSet; | 35 | import java.util.HashSet; |
37 | import java.util.List; | 36 | import java.util.List; |
... | @@ -43,7 +42,6 @@ import static org.hamcrest.MatcherAssert.assertThat; | ... | @@ -43,7 +42,6 @@ import static org.hamcrest.MatcherAssert.assertThat; |
43 | import static org.hamcrest.Matchers.hasSize; | 42 | import static org.hamcrest.Matchers.hasSize; |
44 | import static org.hamcrest.Matchers.is; | 43 | import static org.hamcrest.Matchers.is; |
45 | import static org.onosproject.net.NetTestTools.connectPoint; | 44 | import static org.onosproject.net.NetTestTools.connectPoint; |
46 | -import static org.onosproject.net.NetTestTools.createPath; | ||
47 | import static org.onosproject.net.intent.LinksHaveEntryWithSourceDestinationPairMatcher.linksHasPath; | 45 | import static org.onosproject.net.intent.LinksHaveEntryWithSourceDestinationPairMatcher.linksHasPath; |
48 | 46 | ||
49 | /** | 47 | /** |
... | @@ -57,47 +55,6 @@ public class MultiPointToSinglePointIntentCompilerTest extends AbstractIntentTes | ... | @@ -57,47 +55,6 @@ public class MultiPointToSinglePointIntentCompilerTest extends AbstractIntentTes |
57 | private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment(); | 55 | private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment(); |
58 | 56 | ||
59 | /** | 57 | /** |
60 | - * Mock path service for creating paths within the test. | ||
61 | - */ | ||
62 | - private static class MockPathService extends PathServiceAdapter { | ||
63 | - | ||
64 | - final String[] pathHops; | ||
65 | - | ||
66 | - /** | ||
67 | - * Constructor that provides a set of hops to mock. | ||
68 | - * | ||
69 | - * @param pathHops path hops to mock | ||
70 | - */ | ||
71 | - MockPathService(String[] pathHops) { | ||
72 | - this.pathHops = pathHops; | ||
73 | - } | ||
74 | - | ||
75 | - @Override | ||
76 | - public Set<Path> getPaths(ElementId src, ElementId dst) { | ||
77 | - Set<Path> result = new HashSet<>(); | ||
78 | - | ||
79 | - String[] allHops = new String[pathHops.length + 1]; | ||
80 | - allHops[0] = src.toString(); | ||
81 | - if (pathHops.length != 0) { | ||
82 | - System.arraycopy(pathHops, 0, allHops, 1, pathHops.length); | ||
83 | - } | ||
84 | - result.add(createPath(allHops)); | ||
85 | - | ||
86 | - return result; | ||
87 | - } | ||
88 | - } | ||
89 | - | ||
90 | - /** | ||
91 | - * Mocks the device service so that a device appears available in the test. | ||
92 | - */ | ||
93 | - private static class MockDeviceService extends DeviceServiceAdapter { | ||
94 | - @Override | ||
95 | - public boolean isAvailable(DeviceId deviceId) { | ||
96 | - return true; | ||
97 | - } | ||
98 | - } | ||
99 | - | ||
100 | - /** | ||
101 | * Creates a MultiPointToSinglePoint intent for a group of ingress points | 58 | * Creates a MultiPointToSinglePoint intent for a group of ingress points |
102 | * and an egress point. | 59 | * and an egress point. |
103 | * | 60 | * |
... | @@ -123,6 +80,23 @@ public class MultiPointToSinglePointIntentCompilerTest extends AbstractIntentTes | ... | @@ -123,6 +80,23 @@ public class MultiPointToSinglePointIntentCompilerTest extends AbstractIntentTes |
123 | } | 80 | } |
124 | 81 | ||
125 | /** | 82 | /** |
83 | + * Generate MultiPointToSinglePointIntent with filtered connection point. | ||
84 | + * | ||
85 | + * @param ingress filtered ingress points | ||
86 | + * @param egress filtered egress point | ||
87 | + * @return | ||
88 | + */ | ||
89 | + private MultiPointToSinglePointIntent makeFilteredConnectPointIntent(Set<FilteredConnectPoint> ingress, | ||
90 | + FilteredConnectPoint egress) { | ||
91 | + return MultiPointToSinglePointIntent.builder() | ||
92 | + .appId(APPID) | ||
93 | + .treatment(treatment) | ||
94 | + .filteredIngressPoints(ingress) | ||
95 | + .filteredEgressPoint(egress) | ||
96 | + .build(); | ||
97 | + } | ||
98 | + | ||
99 | + /** | ||
126 | * Creates a compiler for MultiPointToSinglePoint intents. | 100 | * Creates a compiler for MultiPointToSinglePoint intents. |
127 | * | 101 | * |
128 | * @param hops hops to use while computing paths for this intent | 102 | * @param hops hops to use while computing paths for this intent |
... | @@ -131,8 +105,8 @@ public class MultiPointToSinglePointIntentCompilerTest extends AbstractIntentTes | ... | @@ -131,8 +105,8 @@ public class MultiPointToSinglePointIntentCompilerTest extends AbstractIntentTes |
131 | private MultiPointToSinglePointIntentCompiler makeCompiler(String[] hops) { | 105 | private MultiPointToSinglePointIntentCompiler makeCompiler(String[] hops) { |
132 | MultiPointToSinglePointIntentCompiler compiler = | 106 | MultiPointToSinglePointIntentCompiler compiler = |
133 | new MultiPointToSinglePointIntentCompiler(); | 107 | new MultiPointToSinglePointIntentCompiler(); |
134 | - compiler.pathService = new MockPathService(hops); | 108 | + compiler.pathService = new IntentTestsMocks.Mp2MpMockPathService(hops); |
135 | - compiler.deviceService = new MockDeviceService(); | 109 | + compiler.deviceService = new IntentTestsMocks.MockDeviceService(); |
136 | return compiler; | 110 | return compiler; |
137 | } | 111 | } |
138 | 112 | ||
... | @@ -148,8 +122,7 @@ public class MultiPointToSinglePointIntentCompilerTest extends AbstractIntentTes | ... | @@ -148,8 +122,7 @@ public class MultiPointToSinglePointIntentCompilerTest extends AbstractIntentTes |
148 | MultiPointToSinglePointIntent intent = makeIntent(ingress, egress); | 122 | MultiPointToSinglePointIntent intent = makeIntent(ingress, egress); |
149 | assertThat(intent, is(notNullValue())); | 123 | assertThat(intent, is(notNullValue())); |
150 | 124 | ||
151 | - String[] hops = {"h1", "h2", "h3", "h4", "h5", "h6", "h7", "h8", | 125 | + String[] hops = {"h1", "h2", "h3", "h4", "h5", "h6", "h7", "h8"}; |
152 | - egress}; | ||
153 | MultiPointToSinglePointIntentCompiler compiler = makeCompiler(hops); | 126 | MultiPointToSinglePointIntentCompiler compiler = makeCompiler(hops); |
154 | assertThat(compiler, is(notNullValue())); | 127 | assertThat(compiler, is(notNullValue())); |
155 | 128 | ||
... | @@ -184,7 +157,7 @@ public class MultiPointToSinglePointIntentCompilerTest extends AbstractIntentTes | ... | @@ -184,7 +157,7 @@ public class MultiPointToSinglePointIntentCompilerTest extends AbstractIntentTes |
184 | MultiPointToSinglePointIntent intent = makeIntent(ingress, egress); | 157 | MultiPointToSinglePointIntent intent = makeIntent(ingress, egress); |
185 | assertThat(intent, is(notNullValue())); | 158 | assertThat(intent, is(notNullValue())); |
186 | 159 | ||
187 | - final String[] hops = {"inner1", "inner2", egress}; | 160 | + final String[] hops = {"inner1", "inner2"}; |
188 | MultiPointToSinglePointIntentCompiler compiler = makeCompiler(hops); | 161 | MultiPointToSinglePointIntentCompiler compiler = makeCompiler(hops); |
189 | assertThat(compiler, is(notNullValue())); | 162 | assertThat(compiler, is(notNullValue())); |
190 | 163 | ||
... | @@ -217,7 +190,7 @@ public class MultiPointToSinglePointIntentCompilerTest extends AbstractIntentTes | ... | @@ -217,7 +190,7 @@ public class MultiPointToSinglePointIntentCompilerTest extends AbstractIntentTes |
217 | MultiPointToSinglePointIntent intent = makeIntent(ingress, egress); | 190 | MultiPointToSinglePointIntent intent = makeIntent(ingress, egress); |
218 | assertThat(intent, is(notNullValue())); | 191 | assertThat(intent, is(notNullValue())); |
219 | 192 | ||
220 | - final String[] hops = {"n1", egress}; | 193 | + final String[] hops = {"n1"}; |
221 | MultiPointToSinglePointIntentCompiler compiler = makeCompiler(hops); | 194 | MultiPointToSinglePointIntentCompiler compiler = makeCompiler(hops); |
222 | assertThat(compiler, is(notNullValue())); | 195 | assertThat(compiler, is(notNullValue())); |
223 | 196 | ||
... | @@ -245,12 +218,12 @@ public class MultiPointToSinglePointIntentCompilerTest extends AbstractIntentTes | ... | @@ -245,12 +218,12 @@ public class MultiPointToSinglePointIntentCompilerTest extends AbstractIntentTes |
245 | @Test | 218 | @Test |
246 | public void testSameDeviceCompilation() { | 219 | public void testSameDeviceCompilation() { |
247 | String[] ingress = {"i1", "i2"}; | 220 | String[] ingress = {"i1", "i2"}; |
248 | - String egress = "i1"; | 221 | + String egress = "i3"; |
249 | 222 | ||
250 | MultiPointToSinglePointIntent intent = makeIntent(ingress, egress); | 223 | MultiPointToSinglePointIntent intent = makeIntent(ingress, egress); |
251 | assertThat(intent, is(notNullValue())); | 224 | assertThat(intent, is(notNullValue())); |
252 | 225 | ||
253 | - final String[] hops = {"i1", "i2"}; | 226 | + final String[] hops = {}; |
254 | MultiPointToSinglePointIntentCompiler compiler = makeCompiler(hops); | 227 | MultiPointToSinglePointIntentCompiler compiler = makeCompiler(hops); |
255 | assertThat(compiler, is(notNullValue())); | 228 | assertThat(compiler, is(notNullValue())); |
256 | 229 | ||
... | @@ -264,7 +237,48 @@ public class MultiPointToSinglePointIntentCompilerTest extends AbstractIntentTes | ... | @@ -264,7 +237,48 @@ public class MultiPointToSinglePointIntentCompilerTest extends AbstractIntentTes |
264 | LinkCollectionIntent linkIntent = (LinkCollectionIntent) resultIntent; | 237 | LinkCollectionIntent linkIntent = (LinkCollectionIntent) resultIntent; |
265 | assertThat(linkIntent.links(), hasSize(ingress.length)); | 238 | assertThat(linkIntent.links(), hasSize(ingress.length)); |
266 | 239 | ||
267 | - assertThat(linkIntent.links(), linksHasPath("i2", "i1")); | 240 | + assertThat(linkIntent.links(), linksHasPath("i1", "i3")); |
241 | + assertThat(linkIntent.links(), linksHasPath("i2", "i3")); | ||
268 | } | 242 | } |
269 | } | 243 | } |
244 | + | ||
245 | + /** | ||
246 | + * Tests filtered ingress and egress. | ||
247 | + */ | ||
248 | + @Test | ||
249 | + public void testFilteredConnectPointIntent() { | ||
250 | + | ||
251 | + Set<FilteredConnectPoint> ingress = ImmutableSet.of( | ||
252 | + new FilteredConnectPoint(connectPoint("of1", 1), | ||
253 | + DefaultTrafficSelector.builder().matchVlanId(VlanId.vlanId("100")).build()), | ||
254 | + new FilteredConnectPoint(connectPoint("of2", 1), | ||
255 | + DefaultTrafficSelector.builder().matchVlanId(VlanId.vlanId("200")).build()) | ||
256 | + ); | ||
257 | + | ||
258 | + FilteredConnectPoint egress = new FilteredConnectPoint(connectPoint("of4", 1)); | ||
259 | + | ||
260 | + MultiPointToSinglePointIntent intent = makeFilteredConnectPointIntent(ingress, egress); | ||
261 | + String[] hops = {"of3"}; | ||
262 | + | ||
263 | + MultiPointToSinglePointIntentCompiler compiler = makeCompiler(hops); | ||
264 | + assertThat(compiler, is(notNullValue())); | ||
265 | + | ||
266 | + List<Intent> result = compiler.compile(intent, null); | ||
267 | + assertThat(result, is(notNullValue())); | ||
268 | + assertThat(result, hasSize(1)); | ||
269 | + | ||
270 | + Intent resultIntent = result.get(0); | ||
271 | + assertThat(resultIntent, instanceOf(LinkCollectionIntent.class)); | ||
272 | + | ||
273 | + if (resultIntent instanceof LinkCollectionIntent) { | ||
274 | + LinkCollectionIntent linkIntent = (LinkCollectionIntent) resultIntent; | ||
275 | + assertThat(linkIntent.links(), hasSize(3)); | ||
276 | + assertThat(linkIntent.links(), linksHasPath("of1", "of3")); | ||
277 | + assertThat(linkIntent.links(), linksHasPath("of2", "of3")); | ||
278 | + assertThat(linkIntent.links(), linksHasPath("of3", "of4")); | ||
279 | + } | ||
280 | + | ||
281 | + } | ||
282 | + | ||
283 | + | ||
270 | } | 284 | } | ... | ... |
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment