blob: 2b0e7a8ad0a8f3efa8e7f4adf951b3fcaa91c44f [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;
Brian O'Connorb876bf12014-10-02 14:59:37 -070017
Brian O'Connor9476fa12015-06-25 15:17:17 -040018import com.google.common.annotations.Beta;
tom85258ee2014-10-07 00:10:02 -070019import com.google.common.base.MoreObjects;
Ray Milkeyebc5d222015-03-18 15:45:36 -070020import com.google.common.collect.ImmutableSet;
Brian O'Connorabafb502014-12-02 22:26:20 -080021import org.onosproject.core.ApplicationId;
22import org.onosproject.net.ConnectPoint;
Yi Tseng2a81c9d2016-09-14 10:14:24 -070023import org.onosproject.net.FilteredConnectPoint;
Luca Prete670ac5d2017-02-03 15:55:43 -080024import org.onosproject.net.ResourceGroup;
Brian O'Connorabafb502014-12-02 22:26:20 -080025import org.onosproject.net.flow.TrafficSelector;
26import org.onosproject.net.flow.TrafficTreatment;
Yi Tseng2a81c9d2016-09-14 10:14:24 -070027import org.slf4j.Logger;
Brian O'Connorb876bf12014-10-02 14:59:37 -070028
Ray Milkey460f4022014-11-05 15:41:43 -080029import java.util.List;
tom85258ee2014-10-07 00:10:02 -070030import java.util.Set;
Yi Tseng2a81c9d2016-09-14 10:14:24 -070031import java.util.stream.Collectors;
tom85258ee2014-10-07 00:10:02 -070032
33import static com.google.common.base.Preconditions.checkArgument;
34import static com.google.common.base.Preconditions.checkNotNull;
Yi Tseng2a81c9d2016-09-14 10:14:24 -070035import static org.slf4j.LoggerFactory.getLogger;
Brian O'Connorb876bf12014-10-02 14:59:37 -070036
37/**
38 * Abstraction of multiple source to single destination connectivity intent.
39 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040040@Beta
Ray Milkeye6684082014-10-16 16:59:47 -070041public final class MultiPointToSinglePointIntent extends ConnectivityIntent {
Brian O'Connorb876bf12014-10-02 14:59:37 -070042
Yi Tseng2a81c9d2016-09-14 10:14:24 -070043 private final Set<FilteredConnectPoint> ingressPoints;
44 private final FilteredConnectPoint egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070045
46 /**
47 * Creates a new multi-to-single point connectivity intent for the specified
Yi Tseng2a81c9d2016-09-14 10:14:24 -070048 * traffic selector and treatment with filtered connect point.
Brian O'Connorb876bf12014-10-02 14:59:37 -070049 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070050 * @param appId application identifier
Jonathan Hartd0ba2172015-02-11 13:54:33 -080051 * @param key intent key
Ray Milkey460f4022014-11-05 15:41:43 -080052 * @param selector traffic selector
53 * @param treatment treatment
Yi Tseng2a81c9d2016-09-14 10:14:24 -070054 * @param ingressPoints set of filtered ports from which ingress traffic originates
55 * @param egressPoint filtered port to which traffic will egress
Ray Milkey460f4022014-11-05 15:41:43 -080056 * @param constraints constraints to apply to the intent
Ray Milkeyc24cde32015-03-10 18:20:18 -070057 * @param priority priority to use for flows generated by this intent
Ray Milkey460f4022014-11-05 15:41:43 -080058 * @throws NullPointerException if {@code ingressPoints} or
59 * {@code egressPoint} is null.
60 * @throws IllegalArgumentException if the size of {@code ingressPoints} is
61 * not more than 1
62 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070063 private MultiPointToSinglePointIntent(ApplicationId appId,
Pier Ventre647138f2016-08-26 17:32:44 -070064 Key key,
65 TrafficSelector selector,
66 TrafficTreatment treatment,
Yi Tseng2a81c9d2016-09-14 10:14:24 -070067 Set<FilteredConnectPoint> ingressPoints,
68 FilteredConnectPoint egressPoint,
Pier Ventre647138f2016-08-26 17:32:44 -070069 List<Constraint> constraints,
Luca Prete670ac5d2017-02-03 15:55:43 -080070 int priority,
71 ResourceGroup resourceGroup) {
Thomas Vachuskae45ab442016-08-31 14:21:33 -070072 super(appId, key, ImmutableSet.of(), selector, treatment, constraints,
Luca Prete670ac5d2017-02-03 15:55:43 -080073 priority, resourceGroup);
Ray Milkey460f4022014-11-05 15:41:43 -080074
75 checkNotNull(ingressPoints);
76 checkArgument(!ingressPoints.isEmpty(), "Ingress point set cannot be empty");
Sho SHIMIZU2e660802014-11-21 14:55:32 -080077 checkNotNull(egressPoint);
78 checkArgument(!ingressPoints.contains(egressPoint),
Yi Tseng2a81c9d2016-09-14 10:14:24 -070079 "Set of ingresses should not contain egress (egress: %s)", egressPoint);
Ray Milkey460f4022014-11-05 15:41:43 -080080
Yi Tseng2a81c9d2016-09-14 10:14:24 -070081 this.ingressPoints = ImmutableSet.copyOf(ingressPoints);
Sho SHIMIZU2e660802014-11-21 14:55:32 -080082 this.egressPoint = egressPoint;
Ray Milkey460f4022014-11-05 15:41:43 -080083 }
84
85 /**
Brian O'Connorb876bf12014-10-02 14:59:37 -070086 * Constructor for serializer.
87 */
88 protected MultiPointToSinglePointIntent() {
89 super();
tom85258ee2014-10-07 00:10:02 -070090 this.ingressPoints = null;
91 this.egressPoint = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -070092 }
93
94 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -070095 * Returns a new multi point to single point intent builder. The application id,
96 * ingress points and egress point are required fields. If they are
97 * not set by calls to the appropriate methods, an exception will
98 * be thrown.
99 *
100 * @return single point to multi point builder
101 */
102 public static Builder builder() {
103 return new Builder();
104 }
105
106 /**
Jonathan Hartb14221c2016-03-07 09:55:50 -0800107 * Creates a new builder pre-populated with the information in the given
108 * intent.
109 *
110 * @param intent initial intent
111 * @return intent builder
112 */
113 public static Builder builder(MultiPointToSinglePointIntent intent) {
114 return new Builder(intent);
115 }
116
117 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -0700118 * Builder of a multi point to single point intent.
119 */
120 public static final class Builder extends ConnectivityIntent.Builder {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700121 private final Logger log = getLogger(getClass());
122 private Set<FilteredConnectPoint> ingressPoints;
123 private FilteredConnectPoint egressPoint;
Ray Milkeyebc5d222015-03-18 15:45:36 -0700124
125 private Builder() {
126 // Hide constructor
127 }
128
Jonathan Hartb14221c2016-03-07 09:55:50 -0800129 /**
130 * Creates a new builder pre-populated with information from the given
131 * intent.
132 *
133 * @param intent initial intent
134 */
135 protected Builder(MultiPointToSinglePointIntent intent) {
136 super(intent);
137
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700138 this.filteredIngressPoints(intent.filteredIngressPoints())
139 .filteredEgressPoint(intent.filteredEgressPoint());
140
Jonathan Hartb14221c2016-03-07 09:55:50 -0800141 }
142
Ray Milkeyebc5d222015-03-18 15:45:36 -0700143 @Override
144 public Builder appId(ApplicationId appId) {
145 return (Builder) super.appId(appId);
146 }
147
148 @Override
149 public Builder key(Key key) {
150 return (Builder) super.key(key);
151 }
152
153 @Override
154 public Builder selector(TrafficSelector selector) {
155 return (Builder) super.selector(selector);
156 }
157
158 @Override
159 public Builder treatment(TrafficTreatment treatment) {
160 return (Builder) super.treatment(treatment);
161 }
162
163 @Override
164 public Builder constraints(List<Constraint> constraints) {
165 return (Builder) super.constraints(constraints);
166 }
167
168 @Override
169 public Builder priority(int priority) {
170 return (Builder) super.priority(priority);
171 }
172
Luca Prete670ac5d2017-02-03 15:55:43 -0800173 @Override
174 public Builder resourceGroup(ResourceGroup resourceGroup) {
175 return (Builder) super.resourceGroup(resourceGroup);
176 }
177
Ray Milkeyebc5d222015-03-18 15:45:36 -0700178 /**
179 * Sets the ingress point of the single point to multi point intent
180 * that will be built.
181 *
182 * @param ingressPoints ingress connect points
183 * @return this builder
184 */
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700185 @Deprecated
Ray Milkeyebc5d222015-03-18 15:45:36 -0700186 public Builder ingressPoints(Set<ConnectPoint> ingressPoints) {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700187 if (this.ingressPoints != null) {
188 log.warn("Ingress points are already set, " +
189 "this will override original ingress points.");
190 }
191 this.ingressPoints = ingressPoints.stream()
192 .map(FilteredConnectPoint::new)
193 .collect(Collectors.toSet());
Ray Milkeyebc5d222015-03-18 15:45:36 -0700194 return this;
195 }
196
197 /**
198 * Sets the egress point of the multi point to single point intent
199 * that will be built.
200 *
201 * @param egressPoint egress connect point
202 * @return this builder
203 */
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700204 @Deprecated
Ray Milkeyebc5d222015-03-18 15:45:36 -0700205 public Builder egressPoint(ConnectPoint egressPoint) {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700206 if (this.egressPoint != null) {
207 log.warn("Egress point is already set, " +
208 "this will override original egress point.");
209 }
210 this.egressPoint = new FilteredConnectPoint(egressPoint);
Ray Milkeyebc5d222015-03-18 15:45:36 -0700211 return this;
212 }
213
214 /**
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700215 * Sets the filtered ingress point of the single point to multi point intent
Pier Ventre647138f2016-08-26 17:32:44 -0700216 * that will be built.
217 *
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700218 * @param ingressPoints filtered ingress connect points
Pier Ventre647138f2016-08-26 17:32:44 -0700219 * @return this builder
220 */
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700221 public Builder filteredIngressPoints(Set<FilteredConnectPoint> ingressPoints) {
222 this.ingressPoints = ImmutableSet.copyOf(ingressPoints);
223 return this;
224 }
225
226 /**
227 * Sets the filtered egress point of the multi point to single point intent
228 * that will be built.
229 *
230 * @param egressPoint filtered egress connect point
231 * @return this builder
232 */
233 public Builder filteredEgressPoint(FilteredConnectPoint egressPoint) {
234 this.egressPoint = egressPoint;
Pier Ventre647138f2016-08-26 17:32:44 -0700235 return this;
236 }
237
238 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -0700239 * Builds a multi point to single point intent from the
240 * accumulated parameters.
241 *
Pier Ventre647138f2016-08-26 17:32:44 -0700242 * @return multi point to single point intent
Ray Milkeyebc5d222015-03-18 15:45:36 -0700243 */
244 public MultiPointToSinglePointIntent build() {
245
246 return new MultiPointToSinglePointIntent(
247 appId,
248 key,
249 selector,
250 treatment,
251 ingressPoints,
252 egressPoint,
253 constraints,
Luca Prete670ac5d2017-02-03 15:55:43 -0800254 priority,
255 resourceGroup
Ray Milkeyebc5d222015-03-18 15:45:36 -0700256 );
257 }
258 }
259
260
261 /**
Brian O'Connorb876bf12014-10-02 14:59:37 -0700262 * Returns the set of ports on which ingress traffic should be connected to
263 * the egress port.
264 *
265 * @return set of ingress ports
266 */
tom85258ee2014-10-07 00:10:02 -0700267 public Set<ConnectPoint> ingressPoints() {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700268 return ingressPoints.stream()
269 .map(FilteredConnectPoint::connectPoint)
270 .collect(Collectors.toSet());
Brian O'Connorb876bf12014-10-02 14:59:37 -0700271 }
272
273 /**
274 * Returns the port on which the traffic should egress.
275 *
276 * @return egress port
277 */
tom85258ee2014-10-07 00:10:02 -0700278 public ConnectPoint egressPoint() {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700279 return egressPoint.connectPoint();
Brian O'Connorb876bf12014-10-02 14:59:37 -0700280 }
281
Pier Ventre647138f2016-08-26 17:32:44 -0700282 /**
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700283 * Returns the set of ports on which ingress traffic should be connected to
284 * the egress port.
285 *
286 * @return set of ingress ports
Pier Ventre647138f2016-08-26 17:32:44 -0700287 */
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700288 public Set<FilteredConnectPoint> filteredIngressPoints() {
289 return ingressPoints;
Pier Ventre647138f2016-08-26 17:32:44 -0700290 }
291
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700292 /**
293 * Returns the port on which the traffic should egress.
294 *
295 * @return egress port
296 */
297 public FilteredConnectPoint filteredEgressPoint() {
298 return egressPoint;
299 }
300
301
Brian O'Connorb876bf12014-10-02 14:59:37 -0700302 @Override
Brian O'Connorb876bf12014-10-02 14:59:37 -0700303 public String toString() {
304 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700305 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800306 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700307 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700308 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800309 .add("resources", resources())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700310 .add("selector", selector())
311 .add("treatment", treatment())
312 .add("ingress", ingressPoints())
313 .add("egress", egressPoint())
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700314 .add("filteredIngressCPs", filteredIngressPoints())
315 .add("filteredEgressCP", filteredEgressPoint())
Ray Milkey460f4022014-11-05 15:41:43 -0800316 .add("constraints", constraints())
Luca Prete670ac5d2017-02-03 15:55:43 -0800317 .add("resourceGroup", resourceGroup())
Brian O'Connorb876bf12014-10-02 14:59:37 -0700318 .toString();
319 }
320}