blob: 3048aac4eedfd4d183331dca806303316b2ed2a8 [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;
Brian O'Connorabafb502014-12-02 22:26:20 -080024import org.onosproject.net.flow.TrafficSelector;
25import org.onosproject.net.flow.TrafficTreatment;
Yi Tseng2a81c9d2016-09-14 10:14:24 -070026import org.slf4j.Logger;
Brian O'Connorb876bf12014-10-02 14:59:37 -070027
Ray Milkey460f4022014-11-05 15:41:43 -080028import java.util.List;
tom85258ee2014-10-07 00:10:02 -070029import java.util.Set;
Yi Tseng2a81c9d2016-09-14 10:14:24 -070030import java.util.stream.Collectors;
tom85258ee2014-10-07 00:10:02 -070031
32import static com.google.common.base.Preconditions.checkArgument;
33import static com.google.common.base.Preconditions.checkNotNull;
Yi Tseng2a81c9d2016-09-14 10:14:24 -070034import static org.slf4j.LoggerFactory.getLogger;
Brian O'Connorb876bf12014-10-02 14:59:37 -070035
36/**
37 * Abstraction of multiple source to single destination connectivity intent.
38 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040039@Beta
Ray Milkeye6684082014-10-16 16:59:47 -070040public final class MultiPointToSinglePointIntent extends ConnectivityIntent {
Brian O'Connorb876bf12014-10-02 14:59:37 -070041
Yi Tseng2a81c9d2016-09-14 10:14:24 -070042 private final Set<FilteredConnectPoint> ingressPoints;
43 private final FilteredConnectPoint egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070044
45 /**
46 * Creates a new multi-to-single point connectivity intent for the specified
Yi Tseng2a81c9d2016-09-14 10:14:24 -070047 * traffic selector and treatment with filtered connect point.
Brian O'Connorb876bf12014-10-02 14:59:37 -070048 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070049 * @param appId application identifier
Jonathan Hartd0ba2172015-02-11 13:54:33 -080050 * @param key intent key
Ray Milkey460f4022014-11-05 15:41:43 -080051 * @param selector traffic selector
52 * @param treatment treatment
Yi Tseng2a81c9d2016-09-14 10:14:24 -070053 * @param ingressPoints set of filtered ports from which ingress traffic originates
54 * @param egressPoint filtered port to which traffic will egress
Ray Milkey460f4022014-11-05 15:41:43 -080055 * @param constraints constraints to apply to the intent
Ray Milkeyc24cde32015-03-10 18:20:18 -070056 * @param priority priority to use for flows generated by this intent
Ray Milkey460f4022014-11-05 15:41:43 -080057 * @throws NullPointerException if {@code ingressPoints} or
58 * {@code egressPoint} is null.
59 * @throws IllegalArgumentException if the size of {@code ingressPoints} is
60 * not more than 1
61 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070062 private MultiPointToSinglePointIntent(ApplicationId appId,
Pier Ventre647138f2016-08-26 17:32:44 -070063 Key key,
64 TrafficSelector selector,
65 TrafficTreatment treatment,
Yi Tseng2a81c9d2016-09-14 10:14:24 -070066 Set<FilteredConnectPoint> ingressPoints,
67 FilteredConnectPoint egressPoint,
Pier Ventre647138f2016-08-26 17:32:44 -070068 List<Constraint> constraints,
Yi Tseng2a81c9d2016-09-14 10:14:24 -070069 int priority
70 ) {
Thomas Vachuskae45ab442016-08-31 14:21:33 -070071 super(appId, key, ImmutableSet.of(), selector, treatment, constraints,
Yi Tseng2a81c9d2016-09-14 10:14:24 -070072 priority);
Ray Milkey460f4022014-11-05 15:41:43 -080073
74 checkNotNull(ingressPoints);
75 checkArgument(!ingressPoints.isEmpty(), "Ingress point set cannot be empty");
Sho SHIMIZU2e660802014-11-21 14:55:32 -080076 checkNotNull(egressPoint);
77 checkArgument(!ingressPoints.contains(egressPoint),
Yi Tseng2a81c9d2016-09-14 10:14:24 -070078 "Set of ingresses should not contain egress (egress: %s)", egressPoint);
Ray Milkey460f4022014-11-05 15:41:43 -080079
Yi Tseng2a81c9d2016-09-14 10:14:24 -070080 this.ingressPoints = ImmutableSet.copyOf(ingressPoints);
Sho SHIMIZU2e660802014-11-21 14:55:32 -080081 this.egressPoint = egressPoint;
Ray Milkey460f4022014-11-05 15:41:43 -080082 }
83
84 /**
Brian O'Connorb876bf12014-10-02 14:59:37 -070085 * Constructor for serializer.
86 */
87 protected MultiPointToSinglePointIntent() {
88 super();
tom85258ee2014-10-07 00:10:02 -070089 this.ingressPoints = null;
90 this.egressPoint = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -070091 }
92
93 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -070094 * Returns a new multi point to single point intent builder. The application id,
95 * ingress points and egress point are required fields. If they are
96 * not set by calls to the appropriate methods, an exception will
97 * be thrown.
98 *
99 * @return single point to multi point builder
100 */
101 public static Builder builder() {
102 return new Builder();
103 }
104
105 /**
Jonathan Hartb14221c2016-03-07 09:55:50 -0800106 * Creates a new builder pre-populated with the information in the given
107 * intent.
108 *
109 * @param intent initial intent
110 * @return intent builder
111 */
112 public static Builder builder(MultiPointToSinglePointIntent intent) {
113 return new Builder(intent);
114 }
115
116 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -0700117 * Builder of a multi point to single point intent.
118 */
119 public static final class Builder extends ConnectivityIntent.Builder {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700120 private final Logger log = getLogger(getClass());
121 private Set<FilteredConnectPoint> ingressPoints;
122 private FilteredConnectPoint egressPoint;
Ray Milkeyebc5d222015-03-18 15:45:36 -0700123
124 private Builder() {
125 // Hide constructor
126 }
127
Jonathan Hartb14221c2016-03-07 09:55:50 -0800128 /**
129 * Creates a new builder pre-populated with information from the given
130 * intent.
131 *
132 * @param intent initial intent
133 */
134 protected Builder(MultiPointToSinglePointIntent intent) {
135 super(intent);
136
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700137 this.filteredIngressPoints(intent.filteredIngressPoints())
138 .filteredEgressPoint(intent.filteredEgressPoint());
139
Jonathan Hartb14221c2016-03-07 09:55:50 -0800140 }
141
Ray Milkeyebc5d222015-03-18 15:45:36 -0700142 @Override
143 public Builder appId(ApplicationId appId) {
144 return (Builder) super.appId(appId);
145 }
146
147 @Override
148 public Builder key(Key key) {
149 return (Builder) super.key(key);
150 }
151
152 @Override
153 public Builder selector(TrafficSelector selector) {
154 return (Builder) super.selector(selector);
155 }
156
157 @Override
158 public Builder treatment(TrafficTreatment treatment) {
159 return (Builder) super.treatment(treatment);
160 }
161
162 @Override
163 public Builder constraints(List<Constraint> constraints) {
164 return (Builder) super.constraints(constraints);
165 }
166
167 @Override
168 public Builder priority(int priority) {
169 return (Builder) super.priority(priority);
170 }
171
172 /**
173 * Sets the ingress point of the single point to multi point intent
174 * that will be built.
175 *
176 * @param ingressPoints ingress connect points
177 * @return this builder
178 */
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700179 @Deprecated
Ray Milkeyebc5d222015-03-18 15:45:36 -0700180 public Builder ingressPoints(Set<ConnectPoint> ingressPoints) {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700181 if (this.ingressPoints != null) {
182 log.warn("Ingress points are already set, " +
183 "this will override original ingress points.");
184 }
185 this.ingressPoints = ingressPoints.stream()
186 .map(FilteredConnectPoint::new)
187 .collect(Collectors.toSet());
Ray Milkeyebc5d222015-03-18 15:45:36 -0700188 return this;
189 }
190
191 /**
192 * Sets the egress point of the multi point to single point intent
193 * that will be built.
194 *
195 * @param egressPoint egress connect point
196 * @return this builder
197 */
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700198 @Deprecated
Ray Milkeyebc5d222015-03-18 15:45:36 -0700199 public Builder egressPoint(ConnectPoint egressPoint) {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700200 if (this.egressPoint != null) {
201 log.warn("Egress point is already set, " +
202 "this will override original egress point.");
203 }
204 this.egressPoint = new FilteredConnectPoint(egressPoint);
Ray Milkeyebc5d222015-03-18 15:45:36 -0700205 return this;
206 }
207
208 /**
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700209 * Sets the filtered ingress point of the single point to multi point intent
Pier Ventre647138f2016-08-26 17:32:44 -0700210 * that will be built.
211 *
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700212 * @param ingressPoints filtered ingress connect points
Pier Ventre647138f2016-08-26 17:32:44 -0700213 * @return this builder
214 */
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700215 public Builder filteredIngressPoints(Set<FilteredConnectPoint> ingressPoints) {
216 this.ingressPoints = ImmutableSet.copyOf(ingressPoints);
217 return this;
218 }
219
220 /**
221 * Sets the filtered egress point of the multi point to single point intent
222 * that will be built.
223 *
224 * @param egressPoint filtered egress connect point
225 * @return this builder
226 */
227 public Builder filteredEgressPoint(FilteredConnectPoint egressPoint) {
228 this.egressPoint = egressPoint;
Pier Ventre647138f2016-08-26 17:32:44 -0700229 return this;
230 }
231
232 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -0700233 * Builds a multi point to single point intent from the
234 * accumulated parameters.
235 *
Pier Ventre647138f2016-08-26 17:32:44 -0700236 * @return multi point to single point intent
Ray Milkeyebc5d222015-03-18 15:45:36 -0700237 */
238 public MultiPointToSinglePointIntent build() {
239
240 return new MultiPointToSinglePointIntent(
241 appId,
242 key,
243 selector,
244 treatment,
245 ingressPoints,
246 egressPoint,
247 constraints,
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700248 priority
Ray Milkeyebc5d222015-03-18 15:45:36 -0700249 );
250 }
251 }
252
253
254 /**
Brian O'Connorb876bf12014-10-02 14:59:37 -0700255 * Returns the set of ports on which ingress traffic should be connected to
256 * the egress port.
257 *
258 * @return set of ingress ports
259 */
tom85258ee2014-10-07 00:10:02 -0700260 public Set<ConnectPoint> ingressPoints() {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700261 return ingressPoints.stream()
262 .map(FilteredConnectPoint::connectPoint)
263 .collect(Collectors.toSet());
Brian O'Connorb876bf12014-10-02 14:59:37 -0700264 }
265
266 /**
267 * Returns the port on which the traffic should egress.
268 *
269 * @return egress port
270 */
tom85258ee2014-10-07 00:10:02 -0700271 public ConnectPoint egressPoint() {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700272 return egressPoint.connectPoint();
Brian O'Connorb876bf12014-10-02 14:59:37 -0700273 }
274
Pier Ventre647138f2016-08-26 17:32:44 -0700275 /**
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700276 * Returns the set of ports on which ingress traffic should be connected to
277 * the egress port.
278 *
279 * @return set of ingress ports
Pier Ventre647138f2016-08-26 17:32:44 -0700280 */
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700281 public Set<FilteredConnectPoint> filteredIngressPoints() {
282 return ingressPoints;
Pier Ventre647138f2016-08-26 17:32:44 -0700283 }
284
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700285 /**
286 * Returns the port on which the traffic should egress.
287 *
288 * @return egress port
289 */
290 public FilteredConnectPoint filteredEgressPoint() {
291 return egressPoint;
292 }
293
294
Brian O'Connorb876bf12014-10-02 14:59:37 -0700295 @Override
Brian O'Connorb876bf12014-10-02 14:59:37 -0700296 public String toString() {
297 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700298 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800299 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700300 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700301 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800302 .add("resources", resources())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700303 .add("selector", selector())
304 .add("treatment", treatment())
305 .add("ingress", ingressPoints())
306 .add("egress", egressPoint())
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700307 .add("filteredIngressCPs", filteredIngressPoints())
308 .add("filteredEgressCP", filteredEgressPoint())
Ray Milkey460f4022014-11-05 15:41:43 -0800309 .add("constraints", constraints())
Brian O'Connorb876bf12014-10-02 14:59:37 -0700310 .toString();
311 }
312}