blob: 6a58b80e28003b56f9e478eda67c509f3de0bbe3 [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
Brian O'Connor9476fa12015-06-25 15:17:17 -040019import com.google.common.annotations.Beta;
Thomas Vachuskae45ab442016-08-31 14:21:33 -070020import com.google.common.base.MoreObjects;
Pier Ventre647138f2016-08-26 17:32:44 -070021import com.google.common.collect.ImmutableMap;
Thomas Vachuskae45ab442016-08-31 14:21:33 -070022import com.google.common.collect.ImmutableSet;
Brian O'Connorabafb502014-12-02 22:26:20 -080023import org.onosproject.core.ApplicationId;
24import org.onosproject.net.ConnectPoint;
25import org.onosproject.net.Link;
26import org.onosproject.net.flow.TrafficSelector;
27import org.onosproject.net.flow.TrafficTreatment;
Ray Milkey0742ec92014-10-13 08:39:55 -070028
Thomas Vachuskae45ab442016-08-31 14:21:33 -070029import java.util.List;
30import java.util.Map;
31import java.util.Set;
Ray Milkey0742ec92014-10-13 08:39:55 -070032
33/**
34 * Abstraction of a connectivity intent that is implemented by a set of path
35 * segments.
36 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040037@Beta
Thomas Vachuskac96058a2014-10-20 23:00:16 -070038public final class LinkCollectionIntent extends ConnectivityIntent {
Ray Milkey0742ec92014-10-13 08:39:55 -070039
40 private final Set<Link> links;
41
Pavlin Radoslavov2811c402015-02-25 14:30:17 -080042 private final Set<ConnectPoint> ingressPoints;
Michele Santuari4a338072014-11-05 18:38:55 +010043 private final Set<ConnectPoint> egressPoints;
Pier Ventre647138f2016-08-26 17:32:44 -070044 /**
45 * To manage multiple selectors use case.
46 */
47 private final Map<ConnectPoint, TrafficSelector> ingressSelectors;
48
Nicholas Dean126b8af2016-07-18 14:43:13 -070049 private final boolean egressTreatmentFlag;
Jonathan Hart6b2ffc32014-10-18 02:09:22 -070050
Ray Milkey0742ec92014-10-13 08:39:55 -070051 /**
Pavlin Radoslavov2811c402015-02-25 14:30:17 -080052 * Creates a new actionable intent capable of funneling the selected
53 * traffic along the specified convergent tree and out the given egress
Pavlin Radoslavov2811c402015-02-25 14:30:17 -080054 * point satisfying the specified constraints.
Sho SHIMIZUac8f3522014-11-10 12:14:50 -080055 *
56 * @param appId application identifier
Ray Milkeyebc5d222015-03-18 15:45:36 -070057 * @param key key to use for the intent
Sho SHIMIZUac8f3522014-11-10 12:14:50 -080058 * @param selector traffic match
59 * @param treatment action
60 * @param links traversed links
Ray Milkeyebc5d222015-03-18 15:45:36 -070061 * @param ingressPoints ingress points
62 * @param egressPoints egress points
Sho SHIMIZUac8f3522014-11-10 12:14:50 -080063 * @param constraints optional list of constraints
Ray Milkeyc24cde32015-03-10 18:20:18 -070064 * @param priority priority to use for the flows generated by this intent
Nicholas Dean126b8af2016-07-18 14:43:13 -070065 * @param egressTreatment true if treatment should be applied by the egress device
Pier Ventre647138f2016-08-26 17:32:44 -070066 * @param ingressSelectors map to store the association ingress to selector
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,
74 Set<ConnectPoint> ingressPoints,
75 Set<ConnectPoint> egressPoints,
76 List<Constraint> constraints,
Pier Ventre647138f2016-08-26 17:32:44 -070077 int priority,
78 boolean egressTreatment,
79 Map<ConnectPoint, TrafficSelector> ingressSelectors) {
Ray Milkeyebc5d222015-03-18 15:45:36 -070080 super(appId, key, resources(links), selector, treatment, constraints, priority);
Michele Santuari4a338072014-11-05 18:38:55 +010081 this.links = links;
Ray Milkeyebc5d222015-03-18 15:45:36 -070082 this.ingressPoints = ingressPoints;
83 this.egressPoints = egressPoints;
Nicholas Dean126b8af2016-07-18 14:43:13 -070084 this.egressTreatmentFlag = egressTreatment;
Pier Ventre647138f2016-08-26 17:32:44 -070085 this.ingressSelectors = ingressSelectors;
Ray Milkey0742ec92014-10-13 08:39:55 -070086 }
87
Thomas Vachuskac96058a2014-10-20 23:00:16 -070088 /**
89 * Constructor for serializer.
90 */
Ray Milkey0742ec92014-10-13 08:39:55 -070091 protected LinkCollectionIntent() {
92 super();
93 this.links = null;
Pavlin Radoslavov2811c402015-02-25 14:30:17 -080094 this.ingressPoints = null;
Michele Santuari4a338072014-11-05 18:38:55 +010095 this.egressPoints = null;
Nicholas Dean126b8af2016-07-18 14:43:13 -070096 this.egressTreatmentFlag = false;
Pier Ventre647138f2016-08-26 17:32:44 -070097 this.ingressSelectors = null;
Ray Milkey0742ec92014-10-13 08:39:55 -070098 }
99
Ray Milkeye6684082014-10-16 16:59:47 -0700100 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -0700101 * Returns a new link collection intent builder. The application id,
102 * ingress point and egress points are required fields. If they are
103 * not set by calls to the appropriate methods, an exception will
104 * be thrown.
105 *
106 * @return single point to multi point builder
107 */
108 public static Builder builder() {
109 return new Builder();
110 }
111
112 /**
113 * Builder of a single point to multi point intent.
114 */
115 public static final class Builder extends ConnectivityIntent.Builder {
116 Set<Link> links;
117 Set<ConnectPoint> ingressPoints;
118 Set<ConnectPoint> egressPoints;
Thomas Vachuskae45ab442016-08-31 14:21:33 -0700119 Map<ConnectPoint, TrafficSelector> ingressSelectors = ImmutableMap.of();
Nicholas Dean126b8af2016-07-18 14:43:13 -0700120 boolean egressTreatmentFlag;
Ray Milkeyebc5d222015-03-18 15:45:36 -0700121
122 private Builder() {
123 // Hide constructor
124 }
125
126 @Override
127 public Builder appId(ApplicationId appId) {
128 return (Builder) super.appId(appId);
129 }
130
131 @Override
132 public Builder key(Key key) {
133 return (Builder) super.key(key);
134 }
135
136 @Override
137 public Builder selector(TrafficSelector selector) {
138 return (Builder) super.selector(selector);
139 }
140
141 @Override
142 public Builder treatment(TrafficTreatment treatment) {
143 return (Builder) super.treatment(treatment);
144 }
145
146 @Override
147 public Builder constraints(List<Constraint> constraints) {
148 return (Builder) super.constraints(constraints);
149 }
150
151 @Override
152 public Builder priority(int priority) {
153 return (Builder) super.priority(priority);
154 }
155
156 /**
157 * Sets the ingress point of the single point to multi point intent
158 * that will be built.
159 *
160 * @param ingressPoints ingress connect points
161 * @return this builder
162 */
163 public Builder ingressPoints(Set<ConnectPoint> ingressPoints) {
164 this.ingressPoints = ImmutableSet.copyOf(ingressPoints);
165 return this;
166 }
167
168 /**
169 * Sets the egress points of the single point to multi point intent
170 * that will be built.
171 *
172 * @param egressPoints egress connect points
173 * @return this builder
174 */
175 public Builder egressPoints(Set<ConnectPoint> egressPoints) {
176 this.egressPoints = ImmutableSet.copyOf(egressPoints);
177 return this;
178 }
179
180 /**
Pier Ventre647138f2016-08-26 17:32:44 -0700181 * Sets the map ingress selectors to connection points of the intent.
182 *
183 * @param ingressSelectors maps connection point to traffic selector
184 * @return this builder
185 */
186 public Builder ingressSelectors(Map<ConnectPoint, TrafficSelector> ingressSelectors) {
187 this.ingressSelectors = ImmutableMap.copyOf(ingressSelectors);
188 return this;
189 }
190
191 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -0700192 * Sets the links of the link collection intent
193 * that will be built.
194 *
195 * @param links links for the intent
196 * @return this builder
197 */
198 public Builder links(Set<Link> links) {
199 this.links = ImmutableSet.copyOf(links);
200 return this;
201 }
202
Nicholas Dean126b8af2016-07-18 14:43:13 -0700203 /**
204 * Sets the intent to apply treatment at the egress rather than the
205 * ingress.
206 *
207 * @param treatmentOnEgress true applies treatment on egress device
208 * @return this builder
209 */
210 public Builder applyTreatmentOnEgress(boolean treatmentOnEgress) {
211 this.egressTreatmentFlag = treatmentOnEgress;
212 return this;
213 }
Ray Milkeyebc5d222015-03-18 15:45:36 -0700214
215 /**
216 * Builds a single point to multi point intent from the
217 * accumulated parameters.
218 *
219 * @return point to point intent
220 */
221 public LinkCollectionIntent build() {
222
223 return new LinkCollectionIntent(
224 appId,
225 key,
226 selector,
227 treatment,
228 links,
229 ingressPoints,
230 egressPoints,
231 constraints,
Nicholas Dean126b8af2016-07-18 14:43:13 -0700232 priority,
Pier Ventre647138f2016-08-26 17:32:44 -0700233 egressTreatmentFlag,
234 ingressSelectors
Ray Milkeyebc5d222015-03-18 15:45:36 -0700235 );
236 }
237 }
238
239
240 /**
Ray Milkeye6684082014-10-16 16:59:47 -0700241 * Returns the set of links that represent the network connections needed
242 * by this intent.
243 *
244 * @return Set of links for the network hops needed by this intent
245 */
Ray Milkey0742ec92014-10-13 08:39:55 -0700246 public Set<Link> links() {
247 return links;
248 }
249
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700250 /**
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800251 * Returns the ingress points of the intent.
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700252 *
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800253 * @return the ingress points
254 */
255 public Set<ConnectPoint> ingressPoints() {
256 return ingressPoints;
257 }
258
259 /**
260 * Returns the egress points of the intent.
261 *
262 * @return the egress points
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700263 */
Michele Santuari4a338072014-11-05 18:38:55 +0100264 public Set<ConnectPoint> egressPoints() {
265 return egressPoints;
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700266 }
267
Nicholas Dean126b8af2016-07-18 14:43:13 -0700268 /**
Pier Ventre647138f2016-08-26 17:32:44 -0700269 * Returns the multiple selectors jointly with their connection points.
270 * @return multiple selectors
271 */
272 public Map<ConnectPoint, TrafficSelector> ingressSelectors() {
273 return ingressSelectors;
274 }
275
276 /**
Nicholas Dean126b8af2016-07-18 14:43:13 -0700277 * Returns whether treatment should be applied on egress.
278 *
279 * @return the egress treatment flag
280 */
281 public boolean applyTreatmentOnEgress() {
282 return egressTreatmentFlag;
283 }
284
Ray Milkey0742ec92014-10-13 08:39:55 -0700285 @Override
Ray Milkey0742ec92014-10-13 08:39:55 -0700286 public String toString() {
287 return MoreObjects.toStringHelper(getClass())
288 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800289 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700290 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700291 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800292 .add("resources", resources())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700293 .add("selector", selector())
294 .add("treatment", treatment())
Ray Milkey0742ec92014-10-13 08:39:55 -0700295 .add("links", links())
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800296 .add("ingress", ingressPoints())
Michele Santuari4a338072014-11-05 18:38:55 +0100297 .add("egress", egressPoints())
Pier Ventre647138f2016-08-26 17:32:44 -0700298 .add("selectors", ingressSelectors())
299 .add("treatmentOnEgress", applyTreatmentOnEgress())
Ray Milkey0742ec92014-10-13 08:39:55 -0700300 .toString();
301 }
Pier Ventre647138f2016-08-26 17:32:44 -0700302}