blob: 11f9f771949eb7cd932555b91d18f37d1187fcc7 [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuska83e090e2014-10-22 14:25:35 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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
Thomas Vachuska83e090e2014-10-22 14:25:35 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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.
Thomas Vachuska83e090e2014-10-22 14:25:35 -070015 */
Pier Ventre647138f2016-08-26 17:32:44 -070016
Brian O'Connorabafb502014-12-02 22:26:20 -080017package org.onosproject.net.intent;
Ray Milkey0742ec92014-10-13 08:39:55 -070018
Pier Ventre27d42572016-08-29 17:37:08 -070019import java.util.List;
Pier Ventre27d42572016-08-29 17:37:08 -070020import java.util.Set;
Yi Tseng2a81c9d2016-09-14 10:14:24 -070021import java.util.stream.Collectors;
Pier Ventre27d42572016-08-29 17:37:08 -070022
Brian O'Connor9476fa12015-06-25 15:17:17 -040023import com.google.common.annotations.Beta;
Brian O'Connorabafb502014-12-02 22:26:20 -080024import org.onosproject.core.ApplicationId;
25import org.onosproject.net.ConnectPoint;
Yi Tseng2a81c9d2016-09-14 10:14:24 -070026import org.onosproject.net.FilteredConnectPoint;
Brian O'Connorabafb502014-12-02 22:26:20 -080027import org.onosproject.net.Link;
28import org.onosproject.net.flow.TrafficSelector;
29import org.onosproject.net.flow.TrafficTreatment;
Ray Milkey0742ec92014-10-13 08:39:55 -070030
Pier Ventre27d42572016-08-29 17:37:08 -070031import com.google.common.base.MoreObjects;
32import com.google.common.collect.ImmutableSet;
Yi Tseng2a81c9d2016-09-14 10:14:24 -070033import org.slf4j.Logger;
34
35import static org.slf4j.LoggerFactory.getLogger;
Ray Milkey0742ec92014-10-13 08:39:55 -070036
37/**
38 * Abstraction of a connectivity intent that is implemented by a set of path
39 * segments.
40 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040041@Beta
Thomas Vachuskac96058a2014-10-20 23:00:16 -070042public final class LinkCollectionIntent extends ConnectivityIntent {
Ray Milkey0742ec92014-10-13 08:39:55 -070043
44 private final Set<Link> links;
45
Yi Tseng2a81c9d2016-09-14 10:14:24 -070046 private final Set<FilteredConnectPoint> ingressPoints;
47 private final Set<FilteredConnectPoint> egressPoints;
Pier Ventre27d42572016-08-29 17:37:08 -070048 private final boolean egressTreatmentFlag;
Pier Ventreffe88d62016-10-13 14:34:40 -070049 private final double cost;
50 private static final int DEFAULT_COST = 1;
Yi Tseng2a81c9d2016-09-14 10:14:24 -070051
Pier Ventreffe88d62016-10-13 14:34:40 -070052 /**
53 * Creates a new actionable intent capable of funneling the selected
54 * traffic along the specified convergent tree and out the given egress
55 * point satisfying the specified constraints.
56 *
57 * @param appId application identifier
58 * @param key key to use for the intent
59 * @param selector traffic match
60 * @param treatment action
61 * @param links traversed links
62 * @param ingressPoints filtered ingress points
63 * @param egressPoints filtered egress points
64 * @param constraints optional list of constraints
65 * @param priority priority to use for the flows generated by this intent
66 * @param egressTreatment true if treatment should be applied by the egress device
67 * @param cost the cost of the links
68 * @throws NullPointerException {@code path} is null
69 */
70 private LinkCollectionIntent(ApplicationId appId,
71 Key key,
72 TrafficSelector selector,
73 TrafficTreatment treatment,
74 Set<Link> links,
75 Set<FilteredConnectPoint> ingressPoints,
76 Set<FilteredConnectPoint> egressPoints,
77 List<Constraint> constraints,
78 int priority,
79 boolean egressTreatment,
80 double cost) {
81 super(appId, key, resources(links), selector, treatment, constraints, priority);
82 this.links = links;
83 this.ingressPoints = ingressPoints;
84 this.egressPoints = egressPoints;
85 this.egressTreatmentFlag = egressTreatment;
86 this.cost = cost;
87 }
Jonathan Hart6b2ffc32014-10-18 02:09:22 -070088
Ray Milkey0742ec92014-10-13 08:39:55 -070089 /**
Pavlin Radoslavov2811c402015-02-25 14:30:17 -080090 * Creates a new actionable intent capable of funneling the selected
91 * traffic along the specified convergent tree and out the given egress
Pavlin Radoslavov2811c402015-02-25 14:30:17 -080092 * point satisfying the specified constraints.
Sho SHIMIZUac8f3522014-11-10 12:14:50 -080093 *
94 * @param appId application identifier
Ray Milkeyebc5d222015-03-18 15:45:36 -070095 * @param key key to use for the intent
Sho SHIMIZUac8f3522014-11-10 12:14:50 -080096 * @param selector traffic match
97 * @param treatment action
98 * @param links traversed links
Yi Tseng2a81c9d2016-09-14 10:14:24 -070099 * @param ingressPoints filtered ingress points
100 * @param egressPoints filtered egress points
Sho SHIMIZUac8f3522014-11-10 12:14:50 -0800101 * @param constraints optional list of constraints
Ray Milkeyc24cde32015-03-10 18:20:18 -0700102 * @param priority priority to use for the flows generated by this intent
Nicholas Dean126b8af2016-07-18 14:43:13 -0700103 * @param egressTreatment true if treatment should be applied by the egress device
Sho SHIMIZUac8f3522014-11-10 12:14:50 -0800104 * @throws NullPointerException {@code path} is null
105 */
Ray Milkeyebc5d222015-03-18 15:45:36 -0700106 private LinkCollectionIntent(ApplicationId appId,
Nicholas Dean126b8af2016-07-18 14:43:13 -0700107 Key key,
108 TrafficSelector selector,
109 TrafficTreatment treatment,
110 Set<Link> links,
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700111 Set<FilteredConnectPoint> ingressPoints,
112 Set<FilteredConnectPoint> egressPoints,
Nicholas Dean126b8af2016-07-18 14:43:13 -0700113 List<Constraint> constraints,
Pier Ventre647138f2016-08-26 17:32:44 -0700114 int priority,
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700115 boolean egressTreatment) {
Pier Ventreffe88d62016-10-13 14:34:40 -0700116 this(appId, key, selector, treatment, links, ingressPoints, egressPoints, constraints,
117 priority, egressTreatment, DEFAULT_COST);
Ray Milkey0742ec92014-10-13 08:39:55 -0700118 }
119
Thomas Vachuskac96058a2014-10-20 23:00:16 -0700120 /**
121 * Constructor for serializer.
122 */
Ray Milkey0742ec92014-10-13 08:39:55 -0700123 protected LinkCollectionIntent() {
Ray Milkey0742ec92014-10-13 08:39:55 -0700124 this.links = null;
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800125 this.ingressPoints = null;
Michele Santuari4a338072014-11-05 18:38:55 +0100126 this.egressPoints = null;
Nicholas Dean126b8af2016-07-18 14:43:13 -0700127 this.egressTreatmentFlag = false;
Pier Ventreffe88d62016-10-13 14:34:40 -0700128 this.cost = DEFAULT_COST;
Ray Milkey0742ec92014-10-13 08:39:55 -0700129 }
130
Ray Milkeye6684082014-10-16 16:59:47 -0700131 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -0700132 * Returns a new link collection intent builder. The application id,
133 * ingress point and egress points are required fields. If they are
134 * not set by calls to the appropriate methods, an exception will
135 * be thrown.
136 *
137 * @return single point to multi point builder
138 */
139 public static Builder builder() {
140 return new Builder();
141 }
142
143 /**
144 * Builder of a single point to multi point intent.
145 */
146 public static final class Builder extends ConnectivityIntent.Builder {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700147 private final Logger log = getLogger(getClass());
148 private Set<Link> links;
149 private Set<FilteredConnectPoint> ingressPoints;
150 private Set<FilteredConnectPoint> egressPoints;
151 private boolean egressTreatmentFlag;
Pier Ventreffe88d62016-10-13 14:34:40 -0700152 private double cost;
153
Ray Milkeyebc5d222015-03-18 15:45:36 -0700154
155 private Builder() {
156 // Hide constructor
157 }
158
159 @Override
160 public Builder appId(ApplicationId appId) {
161 return (Builder) super.appId(appId);
162 }
163
164 @Override
165 public Builder key(Key key) {
166 return (Builder) super.key(key);
167 }
168
169 @Override
170 public Builder selector(TrafficSelector selector) {
171 return (Builder) super.selector(selector);
172 }
173
174 @Override
175 public Builder treatment(TrafficTreatment treatment) {
176 return (Builder) super.treatment(treatment);
177 }
178
179 @Override
180 public Builder constraints(List<Constraint> constraints) {
181 return (Builder) super.constraints(constraints);
182 }
183
184 @Override
185 public Builder priority(int priority) {
186 return (Builder) super.priority(priority);
187 }
188
189 /**
190 * Sets the ingress point of the single point to multi point intent
191 * that will be built.
192 *
193 * @param ingressPoints ingress connect points
194 * @return this builder
195 */
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700196 @Deprecated
Ray Milkeyebc5d222015-03-18 15:45:36 -0700197 public Builder ingressPoints(Set<ConnectPoint> ingressPoints) {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700198 if (this.ingressPoints != null) {
199 log.warn("Ingress points are already set, " +
200 "this will override original ingress points.");
201 }
202 this.ingressPoints = ingressPoints.stream()
203 .map(FilteredConnectPoint::new)
204 .collect(Collectors.toSet());
Ray Milkeyebc5d222015-03-18 15:45:36 -0700205 return this;
206 }
207
208 /**
209 * Sets the egress points of the single point to multi point intent
210 * that will be built.
211 *
212 * @param egressPoints egress connect points
213 * @return this builder
214 */
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700215 @Deprecated
Ray Milkeyebc5d222015-03-18 15:45:36 -0700216 public Builder egressPoints(Set<ConnectPoint> egressPoints) {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700217 if (this.egressPoints != null) {
218 log.warn("Egress points are already set, " +
219 "this will override original egress points.");
220 }
221 this.egressPoints = egressPoints.stream()
222 .map(FilteredConnectPoint::new)
223 .collect(Collectors.toSet());
224 return this;
225 }
226
227 /**
228 * Sets the filtered ingress point of the single point to multi point intent
229 * that will be built.
230 *
231 * @param ingressPoints ingress connect points
232 * @return this builder
233 */
234 public Builder filteredIngressPoints(Set<FilteredConnectPoint> ingressPoints) {
235 this.ingressPoints = ImmutableSet.copyOf(ingressPoints);
236 return this;
237 }
238
239 /**
240 * Sets the filtered egress points of the single point to multi point intent
241 * that will be built.
242 *
243 * @param egressPoints egress connect points
244 * @return this builder
245 */
246 public Builder filteredEgressPoints(Set<FilteredConnectPoint> egressPoints) {
Ray Milkeyebc5d222015-03-18 15:45:36 -0700247 this.egressPoints = ImmutableSet.copyOf(egressPoints);
248 return this;
249 }
250
251 /**
252 * Sets the links of the link collection intent
253 * that will be built.
254 *
255 * @param links links for the intent
256 * @return this builder
257 */
258 public Builder links(Set<Link> links) {
259 this.links = ImmutableSet.copyOf(links);
260 return this;
261 }
262
Nicholas Dean126b8af2016-07-18 14:43:13 -0700263 /**
264 * Sets the intent to apply treatment at the egress rather than the
265 * ingress.
266 *
267 * @param treatmentOnEgress true applies treatment on egress device
268 * @return this builder
269 */
270 public Builder applyTreatmentOnEgress(boolean treatmentOnEgress) {
271 this.egressTreatmentFlag = treatmentOnEgress;
272 return this;
273 }
Ray Milkeyebc5d222015-03-18 15:45:36 -0700274
275 /**
Pier Ventreffe88d62016-10-13 14:34:40 -0700276 * Sets the cost for the links of the Intent.
277 *
278 * @param cost the cost of the links
279 * @return this builder
280 */
281 public Builder cost(double cost) {
282 this.cost = cost;
283 return this;
284 }
285
286 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -0700287 * Builds a single point to multi point intent from the
288 * accumulated parameters.
289 *
290 * @return point to point intent
291 */
292 public LinkCollectionIntent build() {
293
294 return new LinkCollectionIntent(
295 appId,
296 key,
297 selector,
298 treatment,
299 links,
300 ingressPoints,
301 egressPoints,
302 constraints,
Nicholas Dean126b8af2016-07-18 14:43:13 -0700303 priority,
Pier Ventreffe88d62016-10-13 14:34:40 -0700304 egressTreatmentFlag,
305 cost
Ray Milkeyebc5d222015-03-18 15:45:36 -0700306 );
307 }
308 }
309
Ray Milkeyebc5d222015-03-18 15:45:36 -0700310 /**
Ray Milkeye6684082014-10-16 16:59:47 -0700311 * Returns the set of links that represent the network connections needed
312 * by this intent.
313 *
314 * @return Set of links for the network hops needed by this intent
315 */
Ray Milkey0742ec92014-10-13 08:39:55 -0700316 public Set<Link> links() {
317 return links;
318 }
319
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700320 /**
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800321 * Returns the ingress points of the intent.
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700322 *
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800323 * @return the ingress points
324 */
325 public Set<ConnectPoint> ingressPoints() {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700326 if (this.ingressPoints == null) {
327 return null;
328 }
329 return ingressPoints.stream()
330 .map(FilteredConnectPoint::connectPoint)
331 .collect(Collectors.toSet());
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800332 }
333
334 /**
335 * Returns the egress points of the intent.
336 *
337 * @return the egress points
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700338 */
Michele Santuari4a338072014-11-05 18:38:55 +0100339 public Set<ConnectPoint> egressPoints() {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700340 if (this.egressPoints == null) {
341 return null;
342 }
343 return egressPoints.stream()
344 .map(FilteredConnectPoint::connectPoint)
345 .collect(Collectors.toSet());
346 }
347
348 /**
349 * Returns the filtered ingress points of the intent.
350 *
351 * @return the ingress points
352 */
353 public Set<FilteredConnectPoint> filteredIngressPoints() {
354 return ingressPoints;
355 }
356
357 /**
358 * Returns the egress points of the intent.
359 *
360 * @return the egress points
361 */
362 public Set<FilteredConnectPoint> filteredEgressPoints() {
Michele Santuari4a338072014-11-05 18:38:55 +0100363 return egressPoints;
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700364 }
365
Nicholas Dean126b8af2016-07-18 14:43:13 -0700366 /**
367 * Returns whether treatment should be applied on egress.
368 *
369 * @return the egress treatment flag
370 */
371 public boolean applyTreatmentOnEgress() {
372 return egressTreatmentFlag;
373 }
374
Pier Ventreffe88d62016-10-13 14:34:40 -0700375 /**
376 * Returns the cost of the links of this intent.
377 *
378 * @return the cost of the links
379 */
380 public double cost() {
381 return cost;
382 }
383
Ray Milkey0742ec92014-10-13 08:39:55 -0700384 @Override
Ray Milkey0742ec92014-10-13 08:39:55 -0700385 public String toString() {
386 return MoreObjects.toStringHelper(getClass())
387 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800388 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700389 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700390 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800391 .add("resources", resources())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700392 .add("selector", selector())
393 .add("treatment", treatment())
Ray Milkey0742ec92014-10-13 08:39:55 -0700394 .add("links", links())
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800395 .add("ingress", ingressPoints())
Michele Santuari4a338072014-11-05 18:38:55 +0100396 .add("egress", egressPoints())
Pier Ventre27d42572016-08-29 17:37:08 -0700397 .add("treatementOnEgress", applyTreatmentOnEgress())
Pier Ventreffe88d62016-10-13 14:34:40 -0700398 .add("cost", cost())
Ray Milkey0742ec92014-10-13 08:39:55 -0700399 .toString();
400 }
Pier Ventre647138f2016-08-26 17:32:44 -0700401}