blob: f72354d1f4f4ded4e20630756078cf9f294af2a1 [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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.intent;
Ray Milkey0742ec92014-10-13 08:39:55 -070017
Ray Milkeyebc5d222015-03-18 15:45:36 -070018import java.util.List;
19import java.util.Set;
Michele Santuari4a338072014-11-05 18:38:55 +010020
Brian O'Connor9476fa12015-06-25 15:17:17 -040021import com.google.common.annotations.Beta;
Brian O'Connorabafb502014-12-02 22:26:20 -080022import org.onosproject.core.ApplicationId;
23import org.onosproject.net.ConnectPoint;
24import org.onosproject.net.Link;
25import org.onosproject.net.flow.TrafficSelector;
26import org.onosproject.net.flow.TrafficTreatment;
Ray Milkey0742ec92014-10-13 08:39:55 -070027
Ray Milkeyebc5d222015-03-18 15:45:36 -070028import com.google.common.base.MoreObjects;
29import com.google.common.collect.ImmutableSet;
Ray Milkey0742ec92014-10-13 08:39:55 -070030
31/**
32 * Abstraction of a connectivity intent that is implemented by a set of path
33 * segments.
34 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040035@Beta
Thomas Vachuskac96058a2014-10-20 23:00:16 -070036public final class LinkCollectionIntent extends ConnectivityIntent {
Ray Milkey0742ec92014-10-13 08:39:55 -070037
38 private final Set<Link> links;
39
Pavlin Radoslavov2811c402015-02-25 14:30:17 -080040 private final Set<ConnectPoint> ingressPoints;
Michele Santuari4a338072014-11-05 18:38:55 +010041 private final Set<ConnectPoint> egressPoints;
Nicholas Dean126b8af2016-07-18 14:43:13 -070042 private final boolean egressTreatmentFlag;
Jonathan Hart6b2ffc32014-10-18 02:09:22 -070043
Ray Milkey0742ec92014-10-13 08:39:55 -070044 /**
Pavlin Radoslavov2811c402015-02-25 14:30:17 -080045 * Creates a new actionable intent capable of funneling the selected
46 * traffic along the specified convergent tree and out the given egress
Pavlin Radoslavov2811c402015-02-25 14:30:17 -080047 * point satisfying the specified constraints.
Sho SHIMIZUac8f3522014-11-10 12:14:50 -080048 *
49 * @param appId application identifier
Ray Milkeyebc5d222015-03-18 15:45:36 -070050 * @param key key to use for the intent
Sho SHIMIZUac8f3522014-11-10 12:14:50 -080051 * @param selector traffic match
52 * @param treatment action
53 * @param links traversed links
Ray Milkeyebc5d222015-03-18 15:45:36 -070054 * @param ingressPoints ingress points
55 * @param egressPoints egress points
Sho SHIMIZUac8f3522014-11-10 12:14:50 -080056 * @param constraints optional list of constraints
Ray Milkeyc24cde32015-03-10 18:20:18 -070057 * @param priority priority to use for the flows generated by this intent
Nicholas Dean126b8af2016-07-18 14:43:13 -070058 * @param egressTreatment true if treatment should be applied by the egress device
Sho SHIMIZUac8f3522014-11-10 12:14:50 -080059 * @throws NullPointerException {@code path} is null
60 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070061 private LinkCollectionIntent(ApplicationId appId,
Nicholas Dean126b8af2016-07-18 14:43:13 -070062 Key key,
63 TrafficSelector selector,
64 TrafficTreatment treatment,
65 Set<Link> links,
66 Set<ConnectPoint> ingressPoints,
67 Set<ConnectPoint> egressPoints,
68 List<Constraint> constraints,
69 int priority, boolean egressTreatment) {
Ray Milkeyebc5d222015-03-18 15:45:36 -070070 super(appId, key, resources(links), selector, treatment, constraints, priority);
Michele Santuari4a338072014-11-05 18:38:55 +010071 this.links = links;
Ray Milkeyebc5d222015-03-18 15:45:36 -070072 this.ingressPoints = ingressPoints;
73 this.egressPoints = egressPoints;
Nicholas Dean126b8af2016-07-18 14:43:13 -070074 this.egressTreatmentFlag = egressTreatment;
Ray Milkey0742ec92014-10-13 08:39:55 -070075 }
76
Thomas Vachuskac96058a2014-10-20 23:00:16 -070077 /**
78 * Constructor for serializer.
79 */
Ray Milkey0742ec92014-10-13 08:39:55 -070080 protected LinkCollectionIntent() {
81 super();
82 this.links = null;
Pavlin Radoslavov2811c402015-02-25 14:30:17 -080083 this.ingressPoints = null;
Michele Santuari4a338072014-11-05 18:38:55 +010084 this.egressPoints = null;
Nicholas Dean126b8af2016-07-18 14:43:13 -070085 this.egressTreatmentFlag = false;
Ray Milkey0742ec92014-10-13 08:39:55 -070086 }
87
Ray Milkeye6684082014-10-16 16:59:47 -070088 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -070089 * Returns a new link collection intent builder. The application id,
90 * ingress point and egress points are required fields. If they are
91 * not set by calls to the appropriate methods, an exception will
92 * be thrown.
93 *
94 * @return single point to multi point builder
95 */
96 public static Builder builder() {
97 return new Builder();
98 }
99
100 /**
101 * Builder of a single point to multi point intent.
102 */
103 public static final class Builder extends ConnectivityIntent.Builder {
104 Set<Link> links;
105 Set<ConnectPoint> ingressPoints;
106 Set<ConnectPoint> egressPoints;
Nicholas Dean126b8af2016-07-18 14:43:13 -0700107 boolean egressTreatmentFlag;
Ray Milkeyebc5d222015-03-18 15:45:36 -0700108
109 private Builder() {
110 // Hide constructor
111 }
112
113 @Override
114 public Builder appId(ApplicationId appId) {
115 return (Builder) super.appId(appId);
116 }
117
118 @Override
119 public Builder key(Key key) {
120 return (Builder) super.key(key);
121 }
122
123 @Override
124 public Builder selector(TrafficSelector selector) {
125 return (Builder) super.selector(selector);
126 }
127
128 @Override
129 public Builder treatment(TrafficTreatment treatment) {
130 return (Builder) super.treatment(treatment);
131 }
132
133 @Override
134 public Builder constraints(List<Constraint> constraints) {
135 return (Builder) super.constraints(constraints);
136 }
137
138 @Override
139 public Builder priority(int priority) {
140 return (Builder) super.priority(priority);
141 }
142
143 /**
144 * Sets the ingress point of the single point to multi point intent
145 * that will be built.
146 *
147 * @param ingressPoints ingress connect points
148 * @return this builder
149 */
150 public Builder ingressPoints(Set<ConnectPoint> ingressPoints) {
151 this.ingressPoints = ImmutableSet.copyOf(ingressPoints);
152 return this;
153 }
154
155 /**
156 * Sets the egress points of the single point to multi point intent
157 * that will be built.
158 *
159 * @param egressPoints egress connect points
160 * @return this builder
161 */
162 public Builder egressPoints(Set<ConnectPoint> egressPoints) {
163 this.egressPoints = ImmutableSet.copyOf(egressPoints);
164 return this;
165 }
166
167 /**
168 * Sets the links of the link collection intent
169 * that will be built.
170 *
171 * @param links links for the intent
172 * @return this builder
173 */
174 public Builder links(Set<Link> links) {
175 this.links = ImmutableSet.copyOf(links);
176 return this;
177 }
178
Nicholas Dean126b8af2016-07-18 14:43:13 -0700179 /**
180 * Sets the intent to apply treatment at the egress rather than the
181 * ingress.
182 *
183 * @param treatmentOnEgress true applies treatment on egress device
184 * @return this builder
185 */
186 public Builder applyTreatmentOnEgress(boolean treatmentOnEgress) {
187 this.egressTreatmentFlag = treatmentOnEgress;
188 return this;
189 }
Ray Milkeyebc5d222015-03-18 15:45:36 -0700190
191 /**
192 * Builds a single point to multi point intent from the
193 * accumulated parameters.
194 *
195 * @return point to point intent
196 */
197 public LinkCollectionIntent build() {
198
199 return new LinkCollectionIntent(
200 appId,
201 key,
202 selector,
203 treatment,
204 links,
205 ingressPoints,
206 egressPoints,
207 constraints,
Nicholas Dean126b8af2016-07-18 14:43:13 -0700208 priority,
209 egressTreatmentFlag
Ray Milkeyebc5d222015-03-18 15:45:36 -0700210 );
211 }
212 }
213
214
215 /**
Ray Milkeye6684082014-10-16 16:59:47 -0700216 * Returns the set of links that represent the network connections needed
217 * by this intent.
218 *
219 * @return Set of links for the network hops needed by this intent
220 */
Ray Milkey0742ec92014-10-13 08:39:55 -0700221 public Set<Link> links() {
222 return links;
223 }
224
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700225 /**
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800226 * Returns the ingress points of the intent.
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700227 *
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800228 * @return the ingress points
229 */
230 public Set<ConnectPoint> ingressPoints() {
231 return ingressPoints;
232 }
233
234 /**
235 * Returns the egress points of the intent.
236 *
237 * @return the egress points
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700238 */
Michele Santuari4a338072014-11-05 18:38:55 +0100239 public Set<ConnectPoint> egressPoints() {
240 return egressPoints;
Jonathan Hart6b2ffc32014-10-18 02:09:22 -0700241 }
242
Nicholas Dean126b8af2016-07-18 14:43:13 -0700243 /**
244 * Returns whether treatment should be applied on egress.
245 *
246 * @return the egress treatment flag
247 */
248 public boolean applyTreatmentOnEgress() {
249 return egressTreatmentFlag;
250 }
251
Ray Milkey0742ec92014-10-13 08:39:55 -0700252 @Override
Ray Milkey0742ec92014-10-13 08:39:55 -0700253 public String toString() {
254 return MoreObjects.toStringHelper(getClass())
255 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800256 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700257 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700258 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800259 .add("resources", resources())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700260 .add("selector", selector())
261 .add("treatment", treatment())
Ray Milkey0742ec92014-10-13 08:39:55 -0700262 .add("links", links())
Pavlin Radoslavov2811c402015-02-25 14:30:17 -0800263 .add("ingress", ingressPoints())
Michele Santuari4a338072014-11-05 18:38:55 +0100264 .add("egress", egressPoints())
Nicholas Dean126b8af2016-07-18 14:43:13 -0700265 .add("treatementOnEgress", applyTreatmentOnEgress())
Ray Milkey0742ec92014-10-13 08:39:55 -0700266 .toString();
267 }
Nicholas Dean126b8af2016-07-18 14:43:13 -0700268}