blob: 0893528d2cec5ea5d9b8b87dea12bd227cd95a01 [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;
Yi Tseng2a81c9d2016-09-14 10:14:24 -070049
50
Jonathan Hart6b2ffc32014-10-18 02:09:22 -070051
Ray Milkey0742ec92014-10-13 08:39:55 -070052 /**
Pavlin Radoslavov2811c402015-02-25 14:30:17 -080053 * Creates a new actionable intent capable of funneling the selected
54 * traffic along the specified convergent tree and out the given egress
Pavlin Radoslavov2811c402015-02-25 14:30:17 -080055 * point satisfying the specified constraints.
Sho SHIMIZUac8f3522014-11-10 12:14:50 -080056 *
57 * @param appId application identifier
Ray Milkeyebc5d222015-03-18 15:45:36 -070058 * @param key key to use for the intent
Sho SHIMIZUac8f3522014-11-10 12:14:50 -080059 * @param selector traffic match
60 * @param treatment action
61 * @param links traversed links
Yi Tseng2a81c9d2016-09-14 10:14:24 -070062 * @param ingressPoints filtered ingress points
63 * @param egressPoints filtered egress points
Sho SHIMIZUac8f3522014-11-10 12:14:50 -080064 * @param constraints optional list of constraints
Ray Milkeyc24cde32015-03-10 18:20:18 -070065 * @param priority priority to use for the flows generated by this intent
Nicholas Dean126b8af2016-07-18 14:43:13 -070066 * @param egressTreatment true if treatment should be applied by the egress device
Sho SHIMIZUac8f3522014-11-10 12:14:50 -080067 * @throws NullPointerException {@code path} is null
68 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070069 private LinkCollectionIntent(ApplicationId appId,
Nicholas Dean126b8af2016-07-18 14:43:13 -070070 Key key,
71 TrafficSelector selector,
72 TrafficTreatment treatment,
73 Set<Link> links,
Yi Tseng2a81c9d2016-09-14 10:14:24 -070074 Set<FilteredConnectPoint> ingressPoints,
75 Set<FilteredConnectPoint> egressPoints,
Nicholas Dean126b8af2016-07-18 14:43:13 -070076 List<Constraint> constraints,
Pier Ventre647138f2016-08-26 17:32:44 -070077 int priority,
Yi Tseng2a81c9d2016-09-14 10:14:24 -070078 boolean egressTreatment) {
Ray Milkeyebc5d222015-03-18 15:45:36 -070079 super(appId, key, resources(links), selector, treatment, constraints, priority);
Michele Santuari4a338072014-11-05 18:38:55 +010080 this.links = links;
Ray Milkeyebc5d222015-03-18 15:45:36 -070081 this.ingressPoints = ingressPoints;
82 this.egressPoints = egressPoints;
Nicholas Dean126b8af2016-07-18 14:43:13 -070083 this.egressTreatmentFlag = egressTreatment;
Ray Milkey0742ec92014-10-13 08:39:55 -070084 }
85
Thomas Vachuskac96058a2014-10-20 23:00:16 -070086 /**
87 * Constructor for serializer.
88 */
Ray Milkey0742ec92014-10-13 08:39:55 -070089 protected LinkCollectionIntent() {
90 super();
91 this.links = null;
Pavlin Radoslavov2811c402015-02-25 14:30:17 -080092 this.ingressPoints = null;
Michele Santuari4a338072014-11-05 18:38:55 +010093 this.egressPoints = null;
Nicholas Dean126b8af2016-07-18 14:43:13 -070094 this.egressTreatmentFlag = false;
Ray Milkey0742ec92014-10-13 08:39:55 -070095 }
96
Ray Milkeye6684082014-10-16 16:59:47 -070097 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -070098 * Returns a new link collection intent builder. The application id,
99 * ingress point and egress points are required fields. If they are
100 * not set by calls to the appropriate methods, an exception will
101 * be thrown.
102 *
103 * @return single point to multi point builder
104 */
105 public static Builder builder() {
106 return new Builder();
107 }
108
109 /**
110 * Builder of a single point to multi point intent.
111 */
112 public static final class Builder extends ConnectivityIntent.Builder {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700113 private final Logger log = getLogger(getClass());
114 private Set<Link> links;
115 private Set<FilteredConnectPoint> ingressPoints;
116 private Set<FilteredConnectPoint> egressPoints;
117 private boolean egressTreatmentFlag;
Ray Milkeyebc5d222015-03-18 15:45:36 -0700118
119 private Builder() {
120 // Hide constructor
121 }
122
123 @Override
124 public Builder appId(ApplicationId appId) {
125 return (Builder) super.appId(appId);
126 }
127
128 @Override
129 public Builder key(Key key) {
130 return (Builder) super.key(key);
131 }
132
133 @Override
134 public Builder selector(TrafficSelector selector) {
135 return (Builder) super.selector(selector);
136 }
137
138 @Override
139 public Builder treatment(TrafficTreatment treatment) {
140 return (Builder) super.treatment(treatment);
141 }
142
143 @Override
144 public Builder constraints(List<Constraint> constraints) {
145 return (Builder) super.constraints(constraints);
146 }
147
148 @Override
149 public Builder priority(int priority) {
150 return (Builder) super.priority(priority);
151 }
152
153 /**
154 * Sets the ingress point of the single point to multi point intent
155 * that will be built.
156 *
157 * @param ingressPoints ingress connect points
158 * @return this builder
159 */
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700160 @Deprecated
Ray Milkeyebc5d222015-03-18 15:45:36 -0700161 public Builder ingressPoints(Set<ConnectPoint> ingressPoints) {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700162 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());
Ray Milkeyebc5d222015-03-18 15:45:36 -0700169 return this;
170 }
171
172 /**
173 * Sets the egress points of the single point to multi point intent
174 * that will be built.
175 *
176 * @param egressPoints egress connect points
177 * @return this builder
178 */
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700179 @Deprecated
Ray Milkeyebc5d222015-03-18 15:45:36 -0700180 public Builder egressPoints(Set<ConnectPoint> egressPoints) {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700181 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());
188 return this;
189 }
190
191 /**
192 * Sets the filtered ingress point of the single point to multi point intent
193 * that will be built.
194 *
195 * @param ingressPoints ingress connect points
196 * @return this builder
197 */
198 public Builder filteredIngressPoints(Set<FilteredConnectPoint> ingressPoints) {
199 this.ingressPoints = ImmutableSet.copyOf(ingressPoints);
200 return this;
201 }
202
203 /**
204 * Sets the filtered egress points of the single point to multi point intent
205 * that will be built.
206 *
207 * @param egressPoints egress connect points
208 * @return this builder
209 */
210 public Builder filteredEgressPoints(Set<FilteredConnectPoint> egressPoints) {
Ray Milkeyebc5d222015-03-18 15:45:36 -0700211 this.egressPoints = ImmutableSet.copyOf(egressPoints);
212 return this;
213 }
214
215 /**
216 * Sets the links of the link collection intent
217 * that will be built.
218 *
219 * @param links links for the intent
220 * @return this builder
221 */
222 public Builder links(Set<Link> links) {
223 this.links = ImmutableSet.copyOf(links);
224 return this;
225 }
226
Nicholas Dean126b8af2016-07-18 14:43:13 -0700227 /**
228 * Sets the intent to apply treatment at the egress rather than the
229 * ingress.
230 *
231 * @param treatmentOnEgress true applies treatment on egress device
232 * @return this builder
233 */
234 public Builder applyTreatmentOnEgress(boolean treatmentOnEgress) {
235 this.egressTreatmentFlag = treatmentOnEgress;
236 return this;
237 }
Ray Milkeyebc5d222015-03-18 15:45:36 -0700238
239 /**
240 * Builds a single point to multi point intent from the
241 * accumulated parameters.
242 *
243 * @return point to point intent
244 */
245 public LinkCollectionIntent build() {
246
247 return new LinkCollectionIntent(
248 appId,
249 key,
250 selector,
251 treatment,
252 links,
253 ingressPoints,
254 egressPoints,
255 constraints,
Nicholas Dean126b8af2016-07-18 14:43:13 -0700256 priority,
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700257 egressTreatmentFlag
Ray Milkeyebc5d222015-03-18 15:45:36 -0700258 );
259 }
260 }
261
Ray Milkeyebc5d222015-03-18 15:45:36 -0700262 /**
Ray Milkeye6684082014-10-16 16:59:47 -0700263 * Returns the set of links that represent the network connections needed
264 * by this intent.
265 *
266 * @return Set of links for the network hops needed by this intent
267 */
Ray Milkey0742ec92014-10-13 08:39:55 -0700268 public Set<Link> links() {
269 return links;
270 }
271
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700272 /**
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800273 * Returns the ingress points of the intent.
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700274 *
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800275 * @return the ingress points
276 */
277 public Set<ConnectPoint> ingressPoints() {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700278 if (this.ingressPoints == null) {
279 return null;
280 }
281 return ingressPoints.stream()
282 .map(FilteredConnectPoint::connectPoint)
283 .collect(Collectors.toSet());
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800284 }
285
286 /**
287 * Returns the egress points of the intent.
288 *
289 * @return the egress points
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700290 */
Michele Santuari4a338072014-11-05 18:38:55 +0100291 public Set<ConnectPoint> egressPoints() {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700292 if (this.egressPoints == null) {
293 return null;
294 }
295 return egressPoints.stream()
296 .map(FilteredConnectPoint::connectPoint)
297 .collect(Collectors.toSet());
298 }
299
300 /**
301 * Returns the filtered ingress points of the intent.
302 *
303 * @return the ingress points
304 */
305 public Set<FilteredConnectPoint> filteredIngressPoints() {
306 return ingressPoints;
307 }
308
309 /**
310 * Returns the egress points of the intent.
311 *
312 * @return the egress points
313 */
314 public Set<FilteredConnectPoint> filteredEgressPoints() {
Michele Santuari4a338072014-11-05 18:38:55 +0100315 return egressPoints;
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700316 }
317
Nicholas Dean126b8af2016-07-18 14:43:13 -0700318 /**
319 * Returns whether treatment should be applied on egress.
320 *
321 * @return the egress treatment flag
322 */
323 public boolean applyTreatmentOnEgress() {
324 return egressTreatmentFlag;
325 }
326
Ray Milkey0742ec92014-10-13 08:39:55 -0700327 @Override
Ray Milkey0742ec92014-10-13 08:39:55 -0700328 public String toString() {
329 return MoreObjects.toStringHelper(getClass())
330 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800331 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700332 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700333 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800334 .add("resources", resources())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700335 .add("selector", selector())
336 .add("treatment", treatment())
Ray Milkey0742ec92014-10-13 08:39:55 -0700337 .add("links", links())
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800338 .add("ingress", ingressPoints())
Michele Santuari4a338072014-11-05 18:38:55 +0100339 .add("egress", egressPoints())
Pier Ventre27d42572016-08-29 17:37:08 -0700340 .add("treatementOnEgress", applyTreatmentOnEgress())
Ray Milkey0742ec92014-10-13 08:39:55 -0700341 .toString();
342 }
Pier Ventre647138f2016-08-26 17:32:44 -0700343}