blob: 5a5345bd4e487d1dd518b642f6c26bfc4ad8600e [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 Ventre647138f2016-08-26 17:32:44 -070019import java.util.Collections;
Ray Milkeyebc5d222015-03-18 15:45:36 -070020import java.util.List;
Pier Ventre647138f2016-08-26 17:32:44 -070021import java.util.Map;
Ray Milkeyebc5d222015-03-18 15:45:36 -070022import java.util.Set;
Michele Santuari4a338072014-11-05 18:38:55 +010023
Brian O'Connor9476fa12015-06-25 15:17:17 -040024import com.google.common.annotations.Beta;
Pier Ventre647138f2016-08-26 17:32:44 -070025import com.google.common.collect.ImmutableMap;
Brian O'Connorabafb502014-12-02 22:26:20 -080026import org.onosproject.core.ApplicationId;
27import org.onosproject.net.ConnectPoint;
28import org.onosproject.net.Link;
29import org.onosproject.net.flow.TrafficSelector;
30import org.onosproject.net.flow.TrafficTreatment;
Ray Milkey0742ec92014-10-13 08:39:55 -070031
Ray Milkeyebc5d222015-03-18 15:45:36 -070032import com.google.common.base.MoreObjects;
33import com.google.common.collect.ImmutableSet;
Ray Milkey0742ec92014-10-13 08:39:55 -070034
35/**
36 * Abstraction of a connectivity intent that is implemented by a set of path
37 * segments.
38 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040039@Beta
Thomas Vachuskac96058a2014-10-20 23:00:16 -070040public final class LinkCollectionIntent extends ConnectivityIntent {
Ray Milkey0742ec92014-10-13 08:39:55 -070041
42 private final Set<Link> links;
43
Pavlin Radoslavov2811c402015-02-25 14:30:17 -080044 private final Set<ConnectPoint> ingressPoints;
Michele Santuari4a338072014-11-05 18:38:55 +010045 private final Set<ConnectPoint> egressPoints;
Pier Ventre647138f2016-08-26 17:32:44 -070046 /**
47 * To manage multiple selectors use case.
48 */
49 private final Map<ConnectPoint, TrafficSelector> ingressSelectors;
50
Nicholas Dean126b8af2016-07-18 14:43:13 -070051 private final boolean egressTreatmentFlag;
Jonathan Hart6b2ffc32014-10-18 02:09:22 -070052
Ray Milkey0742ec92014-10-13 08:39:55 -070053 /**
Pavlin Radoslavov2811c402015-02-25 14:30:17 -080054 * Creates a new actionable intent capable of funneling the selected
55 * traffic along the specified convergent tree and out the given egress
Pavlin Radoslavov2811c402015-02-25 14:30:17 -080056 * point satisfying the specified constraints.
Sho SHIMIZUac8f3522014-11-10 12:14:50 -080057 *
58 * @param appId application identifier
Ray Milkeyebc5d222015-03-18 15:45:36 -070059 * @param key key to use for the intent
Sho SHIMIZUac8f3522014-11-10 12:14:50 -080060 * @param selector traffic match
61 * @param treatment action
62 * @param links traversed links
Ray Milkeyebc5d222015-03-18 15:45:36 -070063 * @param ingressPoints ingress points
64 * @param egressPoints egress points
Sho SHIMIZUac8f3522014-11-10 12:14:50 -080065 * @param constraints optional list of constraints
Ray Milkeyc24cde32015-03-10 18:20:18 -070066 * @param priority priority to use for the flows generated by this intent
Nicholas Dean126b8af2016-07-18 14:43:13 -070067 * @param egressTreatment true if treatment should be applied by the egress device
Pier Ventre647138f2016-08-26 17:32:44 -070068 * @param ingressSelectors map to store the association ingress to selector
Sho SHIMIZUac8f3522014-11-10 12:14:50 -080069 * @throws NullPointerException {@code path} is null
70 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070071 private LinkCollectionIntent(ApplicationId appId,
Nicholas Dean126b8af2016-07-18 14:43:13 -070072 Key key,
73 TrafficSelector selector,
74 TrafficTreatment treatment,
75 Set<Link> links,
76 Set<ConnectPoint> ingressPoints,
77 Set<ConnectPoint> egressPoints,
78 List<Constraint> constraints,
Pier Ventre647138f2016-08-26 17:32:44 -070079 int priority,
80 boolean egressTreatment,
81 Map<ConnectPoint, TrafficSelector> ingressSelectors) {
Ray Milkeyebc5d222015-03-18 15:45:36 -070082 super(appId, key, resources(links), selector, treatment, constraints, priority);
Michele Santuari4a338072014-11-05 18:38:55 +010083 this.links = links;
Ray Milkeyebc5d222015-03-18 15:45:36 -070084 this.ingressPoints = ingressPoints;
85 this.egressPoints = egressPoints;
Nicholas Dean126b8af2016-07-18 14:43:13 -070086 this.egressTreatmentFlag = egressTreatment;
Pier Ventre647138f2016-08-26 17:32:44 -070087 this.ingressSelectors = ingressSelectors;
Ray Milkey0742ec92014-10-13 08:39:55 -070088 }
89
Thomas Vachuskac96058a2014-10-20 23:00:16 -070090 /**
91 * Constructor for serializer.
92 */
Ray Milkey0742ec92014-10-13 08:39:55 -070093 protected LinkCollectionIntent() {
94 super();
95 this.links = null;
Pavlin Radoslavov2811c402015-02-25 14:30:17 -080096 this.ingressPoints = null;
Michele Santuari4a338072014-11-05 18:38:55 +010097 this.egressPoints = null;
Nicholas Dean126b8af2016-07-18 14:43:13 -070098 this.egressTreatmentFlag = false;
Pier Ventre647138f2016-08-26 17:32:44 -070099 this.ingressSelectors = null;
Ray Milkey0742ec92014-10-13 08:39:55 -0700100 }
101
Ray Milkeye6684082014-10-16 16:59:47 -0700102 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -0700103 * Returns a new link collection intent builder. The application id,
104 * ingress point and egress points are required fields. If they are
105 * not set by calls to the appropriate methods, an exception will
106 * be thrown.
107 *
108 * @return single point to multi point builder
109 */
110 public static Builder builder() {
111 return new Builder();
112 }
113
114 /**
115 * Builder of a single point to multi point intent.
116 */
117 public static final class Builder extends ConnectivityIntent.Builder {
118 Set<Link> links;
119 Set<ConnectPoint> ingressPoints;
120 Set<ConnectPoint> egressPoints;
Pier Ventre647138f2016-08-26 17:32:44 -0700121 Map<ConnectPoint, TrafficSelector> ingressSelectors = Collections.emptyMap();
Nicholas Dean126b8af2016-07-18 14:43:13 -0700122 boolean egressTreatmentFlag;
Ray Milkeyebc5d222015-03-18 15:45:36 -0700123
124 private Builder() {
125 // Hide constructor
126 }
127
128 @Override
129 public Builder appId(ApplicationId appId) {
130 return (Builder) super.appId(appId);
131 }
132
133 @Override
134 public Builder key(Key key) {
135 return (Builder) super.key(key);
136 }
137
138 @Override
139 public Builder selector(TrafficSelector selector) {
140 return (Builder) super.selector(selector);
141 }
142
143 @Override
144 public Builder treatment(TrafficTreatment treatment) {
145 return (Builder) super.treatment(treatment);
146 }
147
148 @Override
149 public Builder constraints(List<Constraint> constraints) {
150 return (Builder) super.constraints(constraints);
151 }
152
153 @Override
154 public Builder priority(int priority) {
155 return (Builder) super.priority(priority);
156 }
157
158 /**
159 * Sets the ingress point of the single point to multi point intent
160 * that will be built.
161 *
162 * @param ingressPoints ingress connect points
163 * @return this builder
164 */
165 public Builder ingressPoints(Set<ConnectPoint> ingressPoints) {
166 this.ingressPoints = ImmutableSet.copyOf(ingressPoints);
167 return this;
168 }
169
170 /**
171 * Sets the egress points of the single point to multi point intent
172 * that will be built.
173 *
174 * @param egressPoints egress connect points
175 * @return this builder
176 */
177 public Builder egressPoints(Set<ConnectPoint> egressPoints) {
178 this.egressPoints = ImmutableSet.copyOf(egressPoints);
179 return this;
180 }
181
182 /**
Pier Ventre647138f2016-08-26 17:32:44 -0700183 * Sets the map ingress selectors to connection points of the intent.
184 *
185 * @param ingressSelectors maps connection point to traffic selector
186 * @return this builder
187 */
188 public Builder ingressSelectors(Map<ConnectPoint, TrafficSelector> ingressSelectors) {
189 this.ingressSelectors = ImmutableMap.copyOf(ingressSelectors);
190 return this;
191 }
192
193 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -0700194 * Sets the links of the link collection intent
195 * that will be built.
196 *
197 * @param links links for the intent
198 * @return this builder
199 */
200 public Builder links(Set<Link> links) {
201 this.links = ImmutableSet.copyOf(links);
202 return this;
203 }
204
Nicholas Dean126b8af2016-07-18 14:43:13 -0700205 /**
206 * Sets the intent to apply treatment at the egress rather than the
207 * ingress.
208 *
209 * @param treatmentOnEgress true applies treatment on egress device
210 * @return this builder
211 */
212 public Builder applyTreatmentOnEgress(boolean treatmentOnEgress) {
213 this.egressTreatmentFlag = treatmentOnEgress;
214 return this;
215 }
Ray Milkeyebc5d222015-03-18 15:45:36 -0700216
217 /**
218 * Builds a single point to multi point intent from the
219 * accumulated parameters.
220 *
221 * @return point to point intent
222 */
223 public LinkCollectionIntent build() {
224
225 return new LinkCollectionIntent(
226 appId,
227 key,
228 selector,
229 treatment,
230 links,
231 ingressPoints,
232 egressPoints,
233 constraints,
Nicholas Dean126b8af2016-07-18 14:43:13 -0700234 priority,
Pier Ventre647138f2016-08-26 17:32:44 -0700235 egressTreatmentFlag,
236 ingressSelectors
Ray Milkeyebc5d222015-03-18 15:45:36 -0700237 );
238 }
239 }
240
241
242 /**
Ray Milkeye6684082014-10-16 16:59:47 -0700243 * Returns the set of links that represent the network connections needed
244 * by this intent.
245 *
246 * @return Set of links for the network hops needed by this intent
247 */
Ray Milkey0742ec92014-10-13 08:39:55 -0700248 public Set<Link> links() {
249 return links;
250 }
251
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700252 /**
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800253 * Returns the ingress points of the intent.
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700254 *
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800255 * @return the ingress points
256 */
257 public Set<ConnectPoint> ingressPoints() {
258 return ingressPoints;
259 }
260
261 /**
262 * Returns the egress points of the intent.
263 *
264 * @return the egress points
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700265 */
Michele Santuari4a338072014-11-05 18:38:55 +0100266 public Set<ConnectPoint> egressPoints() {
267 return egressPoints;
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700268 }
269
Nicholas Dean126b8af2016-07-18 14:43:13 -0700270 /**
Pier Ventre647138f2016-08-26 17:32:44 -0700271 * Returns the multiple selectors jointly with their connection points.
272 * @return multiple selectors
273 */
274 public Map<ConnectPoint, TrafficSelector> ingressSelectors() {
275 return ingressSelectors;
276 }
277
278 /**
Nicholas Dean126b8af2016-07-18 14:43:13 -0700279 * Returns whether treatment should be applied on egress.
280 *
281 * @return the egress treatment flag
282 */
283 public boolean applyTreatmentOnEgress() {
284 return egressTreatmentFlag;
285 }
286
Ray Milkey0742ec92014-10-13 08:39:55 -0700287 @Override
Ray Milkey0742ec92014-10-13 08:39:55 -0700288 public String toString() {
289 return MoreObjects.toStringHelper(getClass())
290 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800291 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700292 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700293 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800294 .add("resources", resources())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700295 .add("selector", selector())
296 .add("treatment", treatment())
Ray Milkey0742ec92014-10-13 08:39:55 -0700297 .add("links", links())
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800298 .add("ingress", ingressPoints())
Michele Santuari4a338072014-11-05 18:38:55 +0100299 .add("egress", egressPoints())
Pier Ventre647138f2016-08-26 17:32:44 -0700300 .add("selectors", ingressSelectors())
301 .add("treatmentOnEgress", applyTreatmentOnEgress())
Ray Milkey0742ec92014-10-13 08:39:55 -0700302 .toString();
303 }
Pier Ventre647138f2016-08-26 17:32:44 -0700304}