blob: 91db96dc26e6177319bb808c7be8f21fabbdd21c [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2014-present Open Networking Foundation
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
Yuta HIGUCHI051be022017-01-13 18:11:33 -080019import java.util.Collection;
Pier Ventre27d42572016-08-29 17:37:08 -070020import java.util.List;
Pier Ventre27d42572016-08-29 17:37:08 -070021import java.util.Set;
Yi Tseng2a81c9d2016-09-14 10:14:24 -070022import java.util.stream.Collectors;
Pier Ventre27d42572016-08-29 17:37:08 -070023
Brian O'Connor9476fa12015-06-25 15:17:17 -040024import com.google.common.annotations.Beta;
Brian O'Connorabafb502014-12-02 22:26:20 -080025import org.onosproject.core.ApplicationId;
26import org.onosproject.net.ConnectPoint;
Yi Tseng2a81c9d2016-09-14 10:14:24 -070027import org.onosproject.net.FilteredConnectPoint;
Brian O'Connorabafb502014-12-02 22:26:20 -080028import org.onosproject.net.Link;
Yuta HIGUCHI051be022017-01-13 18:11:33 -080029import org.onosproject.net.NetworkResource;
Luca Prete670ac5d2017-02-03 15:55:43 -080030import org.onosproject.net.ResourceGroup;
Brian O'Connorabafb502014-12-02 22:26:20 -080031import org.onosproject.net.flow.TrafficSelector;
32import org.onosproject.net.flow.TrafficTreatment;
Ray Milkey0742ec92014-10-13 08:39:55 -070033
Pier Ventre27d42572016-08-29 17:37:08 -070034import com.google.common.base.MoreObjects;
35import com.google.common.collect.ImmutableSet;
Yi Tseng2a81c9d2016-09-14 10:14:24 -070036import org.slf4j.Logger;
37
38import static org.slf4j.LoggerFactory.getLogger;
Ray Milkey0742ec92014-10-13 08:39:55 -070039
40/**
41 * Abstraction of a connectivity intent that is implemented by a set of path
42 * segments.
43 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040044@Beta
Thomas Vachuskac96058a2014-10-20 23:00:16 -070045public final class LinkCollectionIntent extends ConnectivityIntent {
Ray Milkey0742ec92014-10-13 08:39:55 -070046
47 private final Set<Link> links;
48
Yi Tseng2a81c9d2016-09-14 10:14:24 -070049 private final Set<FilteredConnectPoint> ingressPoints;
50 private final Set<FilteredConnectPoint> egressPoints;
Pier Ventre27d42572016-08-29 17:37:08 -070051 private final boolean egressTreatmentFlag;
Pier Ventreffe88d62016-10-13 14:34:40 -070052 private final double cost;
53 private static final int DEFAULT_COST = 1;
Yi Tseng2a81c9d2016-09-14 10:14:24 -070054
Pier Ventreffe88d62016-10-13 14:34:40 -070055 /**
56 * Creates a new actionable intent capable of funneling the selected
57 * traffic along the specified convergent tree and out the given egress
58 * point satisfying the specified constraints.
59 *
60 * @param appId application identifier
61 * @param key key to use for the intent
62 * @param selector traffic match
63 * @param treatment action
64 * @param links traversed links
65 * @param ingressPoints filtered ingress points
66 * @param egressPoints filtered egress points
67 * @param constraints optional list of constraints
68 * @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
70 * @param cost the cost of the links
Luca Prete670ac5d2017-02-03 15:55:43 -080071 * @param resourceGroup resource group for this intent
Pier Ventreffe88d62016-10-13 14:34:40 -070072 * @throws NullPointerException {@code path} is null
73 */
74 private LinkCollectionIntent(ApplicationId appId,
75 Key key,
76 TrafficSelector selector,
77 TrafficTreatment treatment,
Yuta HIGUCHI051be022017-01-13 18:11:33 -080078 Collection<NetworkResource> resources,
Pier Ventreffe88d62016-10-13 14:34:40 -070079 Set<Link> links,
80 Set<FilteredConnectPoint> ingressPoints,
81 Set<FilteredConnectPoint> egressPoints,
82 List<Constraint> constraints,
83 int priority,
84 boolean egressTreatment,
Luca Prete670ac5d2017-02-03 15:55:43 -080085 double cost,
86 ResourceGroup resourceGroup) {
87 super(appId, key, resources(resources, links), selector, treatment, constraints, priority, resourceGroup);
Pier Ventreffe88d62016-10-13 14:34:40 -070088 this.links = links;
89 this.ingressPoints = ingressPoints;
90 this.egressPoints = egressPoints;
91 this.egressTreatmentFlag = egressTreatment;
92 this.cost = cost;
93 }
Jonathan Hart6b2ffc32014-10-18 02:09:22 -070094
Ray Milkey0742ec92014-10-13 08:39:55 -070095 /**
Thomas Vachuskac96058a2014-10-20 23:00:16 -070096 * Constructor for serializer.
97 */
Ray Milkey0742ec92014-10-13 08:39:55 -070098 protected LinkCollectionIntent() {
Ray Milkey0742ec92014-10-13 08:39:55 -070099 this.links = null;
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800100 this.ingressPoints = null;
Michele Santuari4a338072014-11-05 18:38:55 +0100101 this.egressPoints = null;
Nicholas Dean126b8af2016-07-18 14:43:13 -0700102 this.egressTreatmentFlag = false;
Pier Ventreffe88d62016-10-13 14:34:40 -0700103 this.cost = DEFAULT_COST;
Ray Milkey0742ec92014-10-13 08:39:55 -0700104 }
105
Ray Milkeye6684082014-10-16 16:59:47 -0700106 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -0700107 * Returns a new link collection intent builder. The application id,
108 * ingress point and egress points are required fields. If they are
109 * not set by calls to the appropriate methods, an exception will
110 * be thrown.
111 *
112 * @return single point to multi point builder
113 */
114 public static Builder builder() {
115 return new Builder();
116 }
117
118 /**
119 * Builder of a single point to multi point intent.
120 */
121 public static final class Builder extends ConnectivityIntent.Builder {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700122 private final Logger log = getLogger(getClass());
123 private Set<Link> links;
124 private Set<FilteredConnectPoint> ingressPoints;
125 private Set<FilteredConnectPoint> egressPoints;
126 private boolean egressTreatmentFlag;
Pier Ventreffe88d62016-10-13 14:34:40 -0700127 private double cost;
128
Ray Milkeyebc5d222015-03-18 15:45:36 -0700129
130 private Builder() {
131 // Hide constructor
132 }
133
134 @Override
135 public Builder appId(ApplicationId appId) {
136 return (Builder) super.appId(appId);
137 }
138
139 @Override
140 public Builder key(Key key) {
141 return (Builder) super.key(key);
142 }
143
144 @Override
145 public Builder selector(TrafficSelector selector) {
146 return (Builder) super.selector(selector);
147 }
148
149 @Override
150 public Builder treatment(TrafficTreatment treatment) {
151 return (Builder) super.treatment(treatment);
152 }
153
154 @Override
155 public Builder constraints(List<Constraint> constraints) {
156 return (Builder) super.constraints(constraints);
157 }
158
159 @Override
160 public Builder priority(int priority) {
161 return (Builder) super.priority(priority);
162 }
163
Yuta HIGUCHI051be022017-01-13 18:11:33 -0800164 @Override
165 public Builder resources(Collection<NetworkResource> resources) {
166 return (Builder) super.resources(resources);
167 }
168
Luca Prete670ac5d2017-02-03 15:55:43 -0800169 @Override
170 public Builder resourceGroup(ResourceGroup resourceGroup) {
171 return (Builder) super.resourceGroup(resourceGroup);
172 }
173
Ray Milkeyebc5d222015-03-18 15:45:36 -0700174 /**
175 * Sets the ingress point of the single point to multi point intent
176 * that will be built.
177 *
178 * @param ingressPoints ingress connect points
179 * @return this builder
180 */
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700181 @Deprecated
Ray Milkeyebc5d222015-03-18 15:45:36 -0700182 public Builder ingressPoints(Set<ConnectPoint> ingressPoints) {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700183 if (this.ingressPoints != null) {
184 log.warn("Ingress points are already set, " +
185 "this will override original ingress points.");
186 }
187 this.ingressPoints = ingressPoints.stream()
188 .map(FilteredConnectPoint::new)
189 .collect(Collectors.toSet());
Ray Milkeyebc5d222015-03-18 15:45:36 -0700190 return this;
191 }
192
193 /**
194 * Sets the egress points of the single point to multi point intent
195 * that will be built.
196 *
197 * @param egressPoints egress connect points
198 * @return this builder
199 */
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700200 @Deprecated
Ray Milkeyebc5d222015-03-18 15:45:36 -0700201 public Builder egressPoints(Set<ConnectPoint> egressPoints) {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700202 if (this.egressPoints != null) {
203 log.warn("Egress points are already set, " +
204 "this will override original egress points.");
205 }
206 this.egressPoints = egressPoints.stream()
207 .map(FilteredConnectPoint::new)
208 .collect(Collectors.toSet());
209 return this;
210 }
211
212 /**
213 * Sets the filtered ingress point of the single point to multi point intent
214 * that will be built.
215 *
216 * @param ingressPoints ingress connect points
217 * @return this builder
218 */
219 public Builder filteredIngressPoints(Set<FilteredConnectPoint> ingressPoints) {
220 this.ingressPoints = ImmutableSet.copyOf(ingressPoints);
221 return this;
222 }
223
224 /**
225 * Sets the filtered egress points of the single point to multi point intent
226 * that will be built.
227 *
228 * @param egressPoints egress connect points
229 * @return this builder
230 */
231 public Builder filteredEgressPoints(Set<FilteredConnectPoint> egressPoints) {
Ray Milkeyebc5d222015-03-18 15:45:36 -0700232 this.egressPoints = ImmutableSet.copyOf(egressPoints);
233 return this;
234 }
235
236 /**
237 * Sets the links of the link collection intent
238 * that will be built.
239 *
240 * @param links links for the intent
241 * @return this builder
242 */
243 public Builder links(Set<Link> links) {
244 this.links = ImmutableSet.copyOf(links);
245 return this;
246 }
247
Nicholas Dean126b8af2016-07-18 14:43:13 -0700248 /**
249 * Sets the intent to apply treatment at the egress rather than the
250 * ingress.
251 *
252 * @param treatmentOnEgress true applies treatment on egress device
253 * @return this builder
254 */
255 public Builder applyTreatmentOnEgress(boolean treatmentOnEgress) {
256 this.egressTreatmentFlag = treatmentOnEgress;
257 return this;
258 }
Ray Milkeyebc5d222015-03-18 15:45:36 -0700259
260 /**
Pier Ventreffe88d62016-10-13 14:34:40 -0700261 * Sets the cost for the links of the Intent.
262 *
263 * @param cost the cost of the links
264 * @return this builder
265 */
266 public Builder cost(double cost) {
267 this.cost = cost;
268 return this;
269 }
270
271 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -0700272 * Builds a single point to multi point intent from the
273 * accumulated parameters.
274 *
275 * @return point to point intent
276 */
277 public LinkCollectionIntent build() {
278
279 return new LinkCollectionIntent(
280 appId,
281 key,
282 selector,
283 treatment,
Yuta HIGUCHI051be022017-01-13 18:11:33 -0800284 resources,
Ray Milkeyebc5d222015-03-18 15:45:36 -0700285 links,
286 ingressPoints,
287 egressPoints,
288 constraints,
Nicholas Dean126b8af2016-07-18 14:43:13 -0700289 priority,
Pier Ventreffe88d62016-10-13 14:34:40 -0700290 egressTreatmentFlag,
Luca Prete670ac5d2017-02-03 15:55:43 -0800291 cost,
292 resourceGroup
Ray Milkeyebc5d222015-03-18 15:45:36 -0700293 );
294 }
295 }
296
Ray Milkeyebc5d222015-03-18 15:45:36 -0700297 /**
Ray Milkeye6684082014-10-16 16:59:47 -0700298 * Returns the set of links that represent the network connections needed
299 * by this intent.
300 *
301 * @return Set of links for the network hops needed by this intent
302 */
Ray Milkey0742ec92014-10-13 08:39:55 -0700303 public Set<Link> links() {
304 return links;
305 }
306
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700307 /**
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800308 * Returns the ingress points of the intent.
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700309 *
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800310 * @return the ingress points
311 */
312 public Set<ConnectPoint> ingressPoints() {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700313 if (this.ingressPoints == null) {
314 return null;
315 }
316 return ingressPoints.stream()
317 .map(FilteredConnectPoint::connectPoint)
318 .collect(Collectors.toSet());
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800319 }
320
321 /**
322 * Returns the egress points of the intent.
323 *
324 * @return the egress points
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700325 */
Michele Santuari4a338072014-11-05 18:38:55 +0100326 public Set<ConnectPoint> egressPoints() {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700327 if (this.egressPoints == null) {
328 return null;
329 }
330 return egressPoints.stream()
331 .map(FilteredConnectPoint::connectPoint)
332 .collect(Collectors.toSet());
333 }
334
335 /**
336 * Returns the filtered ingress points of the intent.
337 *
338 * @return the ingress points
339 */
340 public Set<FilteredConnectPoint> filteredIngressPoints() {
341 return ingressPoints;
342 }
343
344 /**
345 * Returns the egress points of the intent.
346 *
347 * @return the egress points
348 */
349 public Set<FilteredConnectPoint> filteredEgressPoints() {
Michele Santuari4a338072014-11-05 18:38:55 +0100350 return egressPoints;
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700351 }
352
Nicholas Dean126b8af2016-07-18 14:43:13 -0700353 /**
354 * Returns whether treatment should be applied on egress.
355 *
356 * @return the egress treatment flag
357 */
358 public boolean applyTreatmentOnEgress() {
359 return egressTreatmentFlag;
360 }
361
Pier Ventreffe88d62016-10-13 14:34:40 -0700362 /**
363 * Returns the cost of the links of this intent.
364 *
365 * @return the cost of the links
366 */
367 public double cost() {
368 return cost;
369 }
370
Ray Milkey0742ec92014-10-13 08:39:55 -0700371 @Override
Ray Milkey0742ec92014-10-13 08:39:55 -0700372 public String toString() {
373 return MoreObjects.toStringHelper(getClass())
374 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800375 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700376 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700377 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800378 .add("resources", resources())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700379 .add("selector", selector())
380 .add("treatment", treatment())
Ray Milkey0742ec92014-10-13 08:39:55 -0700381 .add("links", links())
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800382 .add("ingress", ingressPoints())
Michele Santuari4a338072014-11-05 18:38:55 +0100383 .add("egress", egressPoints())
Luca Prete670ac5d2017-02-03 15:55:43 -0800384 .add("treatmentOnEgress", applyTreatmentOnEgress())
385 .add("resourceGroup", resourceGroup())
Pier Ventreffe88d62016-10-13 14:34:40 -0700386 .add("cost", cost())
Ray Milkey0742ec92014-10-13 08:39:55 -0700387 .toString();
388 }
Pier Ventre647138f2016-08-26 17:32:44 -0700389}