blob: 40f13d055230d2ca29e3105d924bbd621069e650 [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 /**
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700175 * Sets the filtered 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 */
181 public Builder filteredIngressPoints(Set<FilteredConnectPoint> ingressPoints) {
182 this.ingressPoints = ImmutableSet.copyOf(ingressPoints);
183 return this;
184 }
185
186 /**
187 * Sets the filtered egress points of the single point to multi point intent
188 * that will be built.
189 *
190 * @param egressPoints egress connect points
191 * @return this builder
192 */
193 public Builder filteredEgressPoints(Set<FilteredConnectPoint> egressPoints) {
Ray Milkeyebc5d222015-03-18 15:45:36 -0700194 this.egressPoints = ImmutableSet.copyOf(egressPoints);
195 return this;
196 }
197
198 /**
199 * Sets the links of the link collection intent
200 * that will be built.
201 *
202 * @param links links for the intent
203 * @return this builder
204 */
205 public Builder links(Set<Link> links) {
206 this.links = ImmutableSet.copyOf(links);
207 return this;
208 }
209
Nicholas Dean126b8af2016-07-18 14:43:13 -0700210 /**
211 * Sets the intent to apply treatment at the egress rather than the
212 * ingress.
213 *
214 * @param treatmentOnEgress true applies treatment on egress device
215 * @return this builder
216 */
217 public Builder applyTreatmentOnEgress(boolean treatmentOnEgress) {
218 this.egressTreatmentFlag = treatmentOnEgress;
219 return this;
220 }
Ray Milkeyebc5d222015-03-18 15:45:36 -0700221
222 /**
Pier Ventreffe88d62016-10-13 14:34:40 -0700223 * Sets the cost for the links of the Intent.
224 *
225 * @param cost the cost of the links
226 * @return this builder
227 */
228 public Builder cost(double cost) {
229 this.cost = cost;
230 return this;
231 }
232
233 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -0700234 * Builds a single point to multi point intent from the
235 * accumulated parameters.
236 *
237 * @return point to point intent
238 */
239 public LinkCollectionIntent build() {
240
241 return new LinkCollectionIntent(
242 appId,
243 key,
244 selector,
245 treatment,
Yuta HIGUCHI051be022017-01-13 18:11:33 -0800246 resources,
Ray Milkeyebc5d222015-03-18 15:45:36 -0700247 links,
248 ingressPoints,
249 egressPoints,
250 constraints,
Nicholas Dean126b8af2016-07-18 14:43:13 -0700251 priority,
Pier Ventreffe88d62016-10-13 14:34:40 -0700252 egressTreatmentFlag,
Luca Prete670ac5d2017-02-03 15:55:43 -0800253 cost,
254 resourceGroup
Ray Milkeyebc5d222015-03-18 15:45:36 -0700255 );
256 }
257 }
258
Ray Milkeyebc5d222015-03-18 15:45:36 -0700259 /**
Ray Milkeye6684082014-10-16 16:59:47 -0700260 * Returns the set of links that represent the network connections needed
261 * by this intent.
262 *
263 * @return Set of links for the network hops needed by this intent
264 */
Ray Milkey0742ec92014-10-13 08:39:55 -0700265 public Set<Link> links() {
266 return links;
267 }
268
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700269 /**
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800270 * Returns the ingress points of the intent.
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700271 *
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800272 * @return the ingress points
273 */
274 public Set<ConnectPoint> ingressPoints() {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700275 if (this.ingressPoints == null) {
276 return null;
277 }
278 return ingressPoints.stream()
279 .map(FilteredConnectPoint::connectPoint)
280 .collect(Collectors.toSet());
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800281 }
282
283 /**
284 * Returns the egress points of the intent.
285 *
286 * @return the egress points
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700287 */
Michele Santuari4a338072014-11-05 18:38:55 +0100288 public Set<ConnectPoint> egressPoints() {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700289 if (this.egressPoints == null) {
290 return null;
291 }
292 return egressPoints.stream()
293 .map(FilteredConnectPoint::connectPoint)
294 .collect(Collectors.toSet());
295 }
296
297 /**
298 * Returns the filtered ingress points of the intent.
299 *
300 * @return the ingress points
301 */
302 public Set<FilteredConnectPoint> filteredIngressPoints() {
303 return ingressPoints;
304 }
305
306 /**
307 * Returns the egress points of the intent.
308 *
309 * @return the egress points
310 */
311 public Set<FilteredConnectPoint> filteredEgressPoints() {
Michele Santuari4a338072014-11-05 18:38:55 +0100312 return egressPoints;
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700313 }
314
Nicholas Dean126b8af2016-07-18 14:43:13 -0700315 /**
316 * Returns whether treatment should be applied on egress.
317 *
318 * @return the egress treatment flag
319 */
320 public boolean applyTreatmentOnEgress() {
321 return egressTreatmentFlag;
322 }
323
Pier Ventreffe88d62016-10-13 14:34:40 -0700324 /**
325 * Returns the cost of the links of this intent.
326 *
327 * @return the cost of the links
328 */
329 public double cost() {
330 return cost;
331 }
332
Ray Milkey0742ec92014-10-13 08:39:55 -0700333 @Override
Ray Milkey0742ec92014-10-13 08:39:55 -0700334 public String toString() {
335 return MoreObjects.toStringHelper(getClass())
336 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800337 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700338 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700339 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800340 .add("resources", resources())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700341 .add("selector", selector())
342 .add("treatment", treatment())
Ray Milkey0742ec92014-10-13 08:39:55 -0700343 .add("links", links())
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800344 .add("ingress", ingressPoints())
Michele Santuari4a338072014-11-05 18:38:55 +0100345 .add("egress", egressPoints())
Luca Prete670ac5d2017-02-03 15:55:43 -0800346 .add("treatmentOnEgress", applyTreatmentOnEgress())
347 .add("resourceGroup", resourceGroup())
Pier Ventreffe88d62016-10-13 14:34:40 -0700348 .add("cost", cost())
Ray Milkey0742ec92014-10-13 08:39:55 -0700349 .toString();
350 }
Pier Ventre647138f2016-08-26 17:32:44 -0700351}