blob: 85bd5df45f9dc56d8a06b63feef5c515c9fec6d0 [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;
20import java.util.Map;
21import java.util.Set;
22
Brian O'Connor9476fa12015-06-25 15:17:17 -040023import com.google.common.annotations.Beta;
Pier Ventre647138f2016-08-26 17:32:44 -070024import com.google.common.collect.ImmutableMap;
Brian O'Connorabafb502014-12-02 22:26:20 -080025import org.onosproject.core.ApplicationId;
26import org.onosproject.net.ConnectPoint;
27import 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;
Ray Milkey0742ec92014-10-13 08:39:55 -070033
34/**
35 * Abstraction of a connectivity intent that is implemented by a set of path
36 * segments.
37 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040038@Beta
Thomas Vachuskac96058a2014-10-20 23:00:16 -070039public final class LinkCollectionIntent extends ConnectivityIntent {
Ray Milkey0742ec92014-10-13 08:39:55 -070040
41 private final Set<Link> links;
42
Pavlin Radoslavov2811c402015-02-25 14:30:17 -080043 private final Set<ConnectPoint> ingressPoints;
Michele Santuari4a338072014-11-05 18:38:55 +010044 private final Set<ConnectPoint> egressPoints;
Pier Ventre27d42572016-08-29 17:37:08 -070045 private final boolean egressTreatmentFlag;
Pier Ventre647138f2016-08-26 17:32:44 -070046 /**
47 * To manage multiple selectors use case.
48 */
49 private final Map<ConnectPoint, TrafficSelector> ingressSelectors;
Pier Ventre27d42572016-08-29 17:37:08 -070050 /**
51 * To manage multiple treatments use case.
52 */
53 private final Map<ConnectPoint, TrafficTreatment> egressTreatments;
Jonathan Hart6b2ffc32014-10-18 02:09:22 -070054
Ray Milkey0742ec92014-10-13 08:39:55 -070055 /**
Pavlin Radoslavov2811c402015-02-25 14:30:17 -080056 * Creates a new actionable intent capable of funneling the selected
57 * traffic along the specified convergent tree and out the given egress
Pavlin Radoslavov2811c402015-02-25 14:30:17 -080058 * point satisfying the specified constraints.
Sho SHIMIZUac8f3522014-11-10 12:14:50 -080059 *
60 * @param appId application identifier
Ray Milkeyebc5d222015-03-18 15:45:36 -070061 * @param key key to use for the intent
Sho SHIMIZUac8f3522014-11-10 12:14:50 -080062 * @param selector traffic match
63 * @param treatment action
64 * @param links traversed links
Ray Milkeyebc5d222015-03-18 15:45:36 -070065 * @param ingressPoints ingress points
66 * @param egressPoints egress points
Sho SHIMIZUac8f3522014-11-10 12:14:50 -080067 * @param constraints optional list of constraints
Ray Milkeyc24cde32015-03-10 18:20:18 -070068 * @param priority priority to use for the flows generated by this intent
Nicholas Dean126b8af2016-07-18 14:43:13 -070069 * @param egressTreatment true if treatment should be applied by the egress device
Pier Ventre647138f2016-08-26 17:32:44 -070070 * @param ingressSelectors map to store the association ingress to selector
Pier Ventre27d42572016-08-29 17:37:08 -070071 * @param egressTreatments map to store the association egress to treatment
Sho SHIMIZUac8f3522014-11-10 12:14:50 -080072 * @throws NullPointerException {@code path} is null
73 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070074 private LinkCollectionIntent(ApplicationId appId,
Nicholas Dean126b8af2016-07-18 14:43:13 -070075 Key key,
76 TrafficSelector selector,
77 TrafficTreatment treatment,
78 Set<Link> links,
79 Set<ConnectPoint> ingressPoints,
80 Set<ConnectPoint> egressPoints,
81 List<Constraint> constraints,
Pier Ventre647138f2016-08-26 17:32:44 -070082 int priority,
83 boolean egressTreatment,
Pier Ventre27d42572016-08-29 17:37:08 -070084 Map<ConnectPoint, TrafficSelector> ingressSelectors,
85 Map<ConnectPoint, TrafficTreatment> egressTreatments) {
Ray Milkeyebc5d222015-03-18 15:45:36 -070086 super(appId, key, resources(links), selector, treatment, constraints, priority);
Michele Santuari4a338072014-11-05 18:38:55 +010087 this.links = links;
Ray Milkeyebc5d222015-03-18 15:45:36 -070088 this.ingressPoints = ingressPoints;
89 this.egressPoints = egressPoints;
Nicholas Dean126b8af2016-07-18 14:43:13 -070090 this.egressTreatmentFlag = egressTreatment;
Pier Ventre647138f2016-08-26 17:32:44 -070091 this.ingressSelectors = ingressSelectors;
Pier Ventre27d42572016-08-29 17:37:08 -070092 this.egressTreatments = egressTreatments;
Ray Milkey0742ec92014-10-13 08:39:55 -070093 }
94
Thomas Vachuskac96058a2014-10-20 23:00:16 -070095 /**
96 * Constructor for serializer.
97 */
Ray Milkey0742ec92014-10-13 08:39:55 -070098 protected LinkCollectionIntent() {
99 super();
100 this.links = null;
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800101 this.ingressPoints = null;
Michele Santuari4a338072014-11-05 18:38:55 +0100102 this.egressPoints = null;
Nicholas Dean126b8af2016-07-18 14:43:13 -0700103 this.egressTreatmentFlag = false;
Pier Ventre647138f2016-08-26 17:32:44 -0700104 this.ingressSelectors = null;
Pier Ventre27d42572016-08-29 17:37:08 -0700105 this.egressTreatments = null;
Ray Milkey0742ec92014-10-13 08:39:55 -0700106 }
107
Ray Milkeye6684082014-10-16 16:59:47 -0700108 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -0700109 * Returns a new link collection intent builder. The application id,
110 * ingress point and egress points are required fields. If they are
111 * not set by calls to the appropriate methods, an exception will
112 * be thrown.
113 *
114 * @return single point to multi point builder
115 */
116 public static Builder builder() {
117 return new Builder();
118 }
119
120 /**
121 * Builder of a single point to multi point intent.
122 */
123 public static final class Builder extends ConnectivityIntent.Builder {
124 Set<Link> links;
125 Set<ConnectPoint> ingressPoints;
126 Set<ConnectPoint> egressPoints;
Thomas Vachuskae45ab442016-08-31 14:21:33 -0700127 Map<ConnectPoint, TrafficSelector> ingressSelectors = ImmutableMap.of();
Pier Ventre27d42572016-08-29 17:37:08 -0700128 Map<ConnectPoint, TrafficTreatment> egressTreatments = ImmutableMap.of();
Nicholas Dean126b8af2016-07-18 14:43:13 -0700129 boolean egressTreatmentFlag;
Ray Milkeyebc5d222015-03-18 15:45:36 -0700130
131 private Builder() {
132 // Hide constructor
133 }
134
135 @Override
136 public Builder appId(ApplicationId appId) {
137 return (Builder) super.appId(appId);
138 }
139
140 @Override
141 public Builder key(Key key) {
142 return (Builder) super.key(key);
143 }
144
145 @Override
146 public Builder selector(TrafficSelector selector) {
147 return (Builder) super.selector(selector);
148 }
149
150 @Override
151 public Builder treatment(TrafficTreatment treatment) {
152 return (Builder) super.treatment(treatment);
153 }
154
155 @Override
156 public Builder constraints(List<Constraint> constraints) {
157 return (Builder) super.constraints(constraints);
158 }
159
160 @Override
161 public Builder priority(int priority) {
162 return (Builder) super.priority(priority);
163 }
164
165 /**
166 * Sets the ingress point of the single point to multi point intent
167 * that will be built.
168 *
169 * @param ingressPoints ingress connect points
170 * @return this builder
171 */
172 public Builder ingressPoints(Set<ConnectPoint> ingressPoints) {
173 this.ingressPoints = ImmutableSet.copyOf(ingressPoints);
174 return this;
175 }
176
177 /**
178 * Sets the egress points of the single point to multi point intent
179 * that will be built.
180 *
181 * @param egressPoints egress connect points
182 * @return this builder
183 */
184 public Builder egressPoints(Set<ConnectPoint> egressPoints) {
185 this.egressPoints = ImmutableSet.copyOf(egressPoints);
186 return this;
187 }
188
189 /**
Pier Ventre647138f2016-08-26 17:32:44 -0700190 * Sets the map ingress selectors to connection points of the intent.
191 *
192 * @param ingressSelectors maps connection point to traffic selector
193 * @return this builder
194 */
195 public Builder ingressSelectors(Map<ConnectPoint, TrafficSelector> ingressSelectors) {
196 this.ingressSelectors = ImmutableMap.copyOf(ingressSelectors);
197 return this;
198 }
199
200 /**
Pier Ventre27d42572016-08-29 17:37:08 -0700201 * Sets the map egress treatments to connection points of the intent.
202 *
203 * @param egressTreatments maps connection point to traffic treatment
204 * @return this builder
205 */
206 public Builder egressTreatments(Map<ConnectPoint, TrafficTreatment> egressTreatments) {
207 this.egressTreatments = ImmutableMap.copyOf(egressTreatments);
208 return this;
209 }
210
211 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -0700212 * Sets the links of the link collection intent
213 * that will be built.
214 *
215 * @param links links for the intent
216 * @return this builder
217 */
218 public Builder links(Set<Link> links) {
219 this.links = ImmutableSet.copyOf(links);
220 return this;
221 }
222
Nicholas Dean126b8af2016-07-18 14:43:13 -0700223 /**
224 * Sets the intent to apply treatment at the egress rather than the
225 * ingress.
226 *
227 * @param treatmentOnEgress true applies treatment on egress device
228 * @return this builder
229 */
230 public Builder applyTreatmentOnEgress(boolean treatmentOnEgress) {
231 this.egressTreatmentFlag = treatmentOnEgress;
232 return this;
233 }
Ray Milkeyebc5d222015-03-18 15:45:36 -0700234
235 /**
236 * Builds a single point to multi point intent from the
237 * accumulated parameters.
238 *
239 * @return point to point intent
240 */
241 public LinkCollectionIntent build() {
242
243 return new LinkCollectionIntent(
244 appId,
245 key,
246 selector,
247 treatment,
248 links,
249 ingressPoints,
250 egressPoints,
251 constraints,
Nicholas Dean126b8af2016-07-18 14:43:13 -0700252 priority,
Pier Ventre647138f2016-08-26 17:32:44 -0700253 egressTreatmentFlag,
Pier Ventre27d42572016-08-29 17:37:08 -0700254 ingressSelectors,
255 egressTreatments
Ray Milkeyebc5d222015-03-18 15:45:36 -0700256 );
257 }
258 }
259
Ray Milkeyebc5d222015-03-18 15:45:36 -0700260 /**
Ray Milkeye6684082014-10-16 16:59:47 -0700261 * Returns the set of links that represent the network connections needed
262 * by this intent.
263 *
264 * @return Set of links for the network hops needed by this intent
265 */
Ray Milkey0742ec92014-10-13 08:39:55 -0700266 public Set<Link> links() {
267 return links;
268 }
269
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700270 /**
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800271 * Returns the ingress points of the intent.
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700272 *
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800273 * @return the ingress points
274 */
275 public Set<ConnectPoint> ingressPoints() {
276 return ingressPoints;
277 }
278
279 /**
280 * Returns the egress points of the intent.
281 *
282 * @return the egress points
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700283 */
Michele Santuari4a338072014-11-05 18:38:55 +0100284 public Set<ConnectPoint> egressPoints() {
285 return egressPoints;
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700286 }
287
Nicholas Dean126b8af2016-07-18 14:43:13 -0700288 /**
Pier Ventre647138f2016-08-26 17:32:44 -0700289 * Returns the multiple selectors jointly with their connection points.
290 * @return multiple selectors
291 */
292 public Map<ConnectPoint, TrafficSelector> ingressSelectors() {
293 return ingressSelectors;
294 }
295
296 /**
Pier Ventre27d42572016-08-29 17:37:08 -0700297 * Returns the multiple treatments jointly with their connection points.
298 * @return multiple treatments
299 */
300 public Map<ConnectPoint, TrafficTreatment> egressTreatments() {
301 return egressTreatments;
302 }
303
304 /**
Nicholas Dean126b8af2016-07-18 14:43:13 -0700305 * Returns whether treatment should be applied on egress.
306 *
307 * @return the egress treatment flag
308 */
309 public boolean applyTreatmentOnEgress() {
310 return egressTreatmentFlag;
311 }
312
Ray Milkey0742ec92014-10-13 08:39:55 -0700313 @Override
Ray Milkey0742ec92014-10-13 08:39:55 -0700314 public String toString() {
315 return MoreObjects.toStringHelper(getClass())
316 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800317 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700318 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700319 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800320 .add("resources", resources())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700321 .add("selector", selector())
322 .add("treatment", treatment())
Ray Milkey0742ec92014-10-13 08:39:55 -0700323 .add("links", links())
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800324 .add("ingress", ingressPoints())
Michele Santuari4a338072014-11-05 18:38:55 +0100325 .add("egress", egressPoints())
Pier Ventre647138f2016-08-26 17:32:44 -0700326 .add("selectors", ingressSelectors())
Pier Ventre27d42572016-08-29 17:37:08 -0700327 .add("treatments", egressTreatments())
328 .add("treatementOnEgress", applyTreatmentOnEgress())
Ray Milkey0742ec92014-10-13 08:39:55 -0700329 .toString();
330 }
Pier Ventre647138f2016-08-26 17:32:44 -0700331}