blob: 2583b8a310bc9b20b9f56058d2901530c49e0693 [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;
toma1d16b62014-10-02 23:45:11 -070019import com.google.common.base.MoreObjects;
Pier Ventre27d42572016-08-29 17:37:08 -070020import com.google.common.collect.ImmutableList;
Ray Milkeyebc5d222015-03-18 15:45:36 -070021import com.google.common.collect.ImmutableSet;
Michele Santuari4a338072014-11-05 18:38:55 +010022
Pier Ventre27d42572016-08-29 17:37:08 -070023import com.google.common.collect.Sets;
Brian O'Connorabafb502014-12-02 22:26:20 -080024import org.onosproject.core.ApplicationId;
25import org.onosproject.net.ConnectPoint;
Yi Tseng2a81c9d2016-09-14 10:14:24 -070026import org.onosproject.net.FilteredConnectPoint;
Luca Prete670ac5d2017-02-03 15:55:43 -080027import org.onosproject.net.ResourceGroup;
Brian O'Connorabafb502014-12-02 22:26:20 -080028import org.onosproject.net.flow.TrafficSelector;
29import org.onosproject.net.flow.TrafficTreatment;
Yi Tseng2a81c9d2016-09-14 10:14:24 -070030import org.slf4j.Logger;
Brian O'Connorb876bf12014-10-02 14:59:37 -070031
toma1d16b62014-10-02 23:45:11 -070032import java.util.Set;
Michele Santuari4a338072014-11-05 18:38:55 +010033import java.util.List;
Yi Tseng2a81c9d2016-09-14 10:14:24 -070034import java.util.stream.Collectors;
toma1d16b62014-10-02 23:45:11 -070035
36import static com.google.common.base.Preconditions.checkArgument;
37import static com.google.common.base.Preconditions.checkNotNull;
Yi Tseng2a81c9d2016-09-14 10:14:24 -070038import static org.slf4j.LoggerFactory.getLogger;
Brian O'Connorb876bf12014-10-02 14:59:37 -070039
40/**
41 * Abstraction of single source, multiple destination connectivity intent.
42 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040043@Beta
Ray Milkeybd4f0112015-03-02 17:07:09 -080044public final class SinglePointToMultiPointIntent extends ConnectivityIntent {
Yi Tseng2a81c9d2016-09-14 10:14:24 -070045 private final FilteredConnectPoint ingressPoint;
46 private final Set<FilteredConnectPoint> egressPoints;
Brian O'Connorb876bf12014-10-02 14:59:37 -070047
48 /**
49 * Creates a new single-to-multi point connectivity intent.
50 *
Michele Santuari4a338072014-11-05 18:38:55 +010051 * @param appId application identifier
Ray Milkey5b3717e2015-02-05 11:44:08 -080052 * @param key intent key
Michele Santuari4a338072014-11-05 18:38:55 +010053 * @param selector traffic selector
54 * @param treatment treatment
55 * @param ingressPoint port on which traffic will ingress
56 * @param egressPoints set of ports on which traffic will egress
57 * @param constraints constraints to apply to the intent
Ray Milkeyc24cde32015-03-10 18:20:18 -070058 * @param priority priority to use for flows generated by this intent
Michele Santuari4a338072014-11-05 18:38:55 +010059 * @throws NullPointerException if {@code ingressPoint} or
60 * {@code egressPoints} is null
61 * @throws IllegalArgumentException if the size of {@code egressPoints} is
62 * not more than 1
63 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070064 private SinglePointToMultiPointIntent(ApplicationId appId,
Pier Ventre27d42572016-08-29 17:37:08 -070065 Key key,
66 TrafficSelector selector,
67 TrafficTreatment treatment,
Yi Tseng2a81c9d2016-09-14 10:14:24 -070068 FilteredConnectPoint ingressPoint,
69 Set<FilteredConnectPoint> egressPoints,
Pier Ventre27d42572016-08-29 17:37:08 -070070 List<Constraint> constraints,
Luca Prete670ac5d2017-02-03 15:55:43 -080071 int priority,
72 ResourceGroup resourceGroup) {
Pier Ventre27d42572016-08-29 17:37:08 -070073 super(appId, key, ImmutableList.of(), selector, treatment, constraints,
Luca Prete670ac5d2017-02-03 15:55:43 -080074 priority, resourceGroup);
tom85258ee2014-10-07 00:10:02 -070075 checkNotNull(egressPoints);
Sho SHIMIZU2e660802014-11-21 14:55:32 -080076 checkNotNull(ingressPoint);
Thomas Vachuskac96058a2014-10-20 23:00:16 -070077 checkArgument(!egressPoints.isEmpty(), "Egress point set cannot be empty");
Sho SHIMIZU2e660802014-11-21 14:55:32 -080078 checkArgument(!egressPoints.contains(ingressPoint),
Yi Tseng2a81c9d2016-09-14 10:14:24 -070079 "Set of egresses should not contain ingress (ingress: %s)", ingressPoint);
Sho SHIMIZU2e660802014-11-21 14:55:32 -080080
Pier Ventre27d42572016-08-29 17:37:08 -070081 this.ingressPoint = ingressPoint;
82 this.egressPoints = Sets.newHashSet(egressPoints);
Ray Milkeyebc5d222015-03-18 15:45:36 -070083 }
84
85 /**
86 * Returns a new single point to multi point intent builder. The application id,
87 * ingress point and egress points are required fields. If they are
88 * not set by calls to the appropriate methods, an exception will
89 * be thrown.
90 *
91 * @return single point to multi point builder
92 */
93 public static Builder builder() {
94 return new Builder();
95 }
96
97 /**
Yi Tseng2a81c9d2016-09-14 10:14:24 -070098 * Creates a new builder pre-populated with the information in the given
99 * intent.
100 *
101 * @param intent initial intent
102 * @return intent builder
103 */
104 public static Builder builder(SinglePointToMultiPointIntent intent) {
105 return new Builder(intent);
106 }
107
108 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -0700109 * Builder of a single point to multi point intent.
110 */
111 public static final class Builder extends ConnectivityIntent.Builder {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700112 private final Logger log = getLogger(getClass());
113 private FilteredConnectPoint ingressPoint;
114 private Set<FilteredConnectPoint> egressPoints;
Ray Milkeyebc5d222015-03-18 15:45:36 -0700115
116 private Builder() {
117 // Hide constructor
118 }
119
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700120 /**
121 * Creates a new builder pre-populated with information from the given
122 * intent.
123 *
124 * @param intent initial intent
125 */
126 protected Builder(SinglePointToMultiPointIntent intent) {
127 super(intent);
128
129 this.filteredEgressPoints(intent.filteredEgressPoints())
130 .filteredIngressPoint(intent.filteredIngressPoint());
131
132 }
133
Ray Milkeyebc5d222015-03-18 15:45:36 -0700134 @Override
135 public Builder appId(ApplicationId appId) {
136 return (Builder) super.appId(appId);
137 }
138
139 @Override
140 public Builder key(Key key) {
141 return (Builder) super.key(key);
142 }
143
144 @Override
145 public Builder selector(TrafficSelector selector) {
146 return (Builder) super.selector(selector);
147 }
148
149 @Override
150 public Builder treatment(TrafficTreatment treatment) {
151 return (Builder) super.treatment(treatment);
152 }
153
154 @Override
155 public Builder constraints(List<Constraint> constraints) {
156 return (Builder) super.constraints(constraints);
157 }
158
159 @Override
160 public Builder priority(int priority) {
161 return (Builder) super.priority(priority);
162 }
163
Luca Prete670ac5d2017-02-03 15:55:43 -0800164 @Override
165 public Builder resourceGroup(ResourceGroup resourceGroup) {
166 return (Builder) super.resourceGroup(resourceGroup);
167 }
168
Ray Milkeyebc5d222015-03-18 15:45:36 -0700169 /**
170 * Sets the ingress point of the single point to multi point intent
171 * that will be built.
172 *
173 * @param ingressPoint ingress connect point
174 * @return this builder
175 */
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700176 @Deprecated
Ray Milkeyebc5d222015-03-18 15:45:36 -0700177 public Builder ingressPoint(ConnectPoint ingressPoint) {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700178 if (this.ingressPoint != null) {
179 log.warn("Ingress point is already set, " +
180 "this will override original ingress point.");
181 }
182 this.ingressPoint = new FilteredConnectPoint(ingressPoint);
Ray Milkeyebc5d222015-03-18 15:45:36 -0700183 return this;
184 }
185
186 /**
187 * Sets the egress points of the single point to multi point intent
188 * that will be built.
189 *
190 * @param egressPoints egress connect points
191 * @return this builder
192 */
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700193 @Deprecated
Ray Milkeyebc5d222015-03-18 15:45:36 -0700194 public Builder egressPoints(Set<ConnectPoint> egressPoints) {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700195 if (this.egressPoints != null) {
196 log.warn("Egress points are already set, " +
197 "this will override original egress points.");
198 }
199 Set<FilteredConnectPoint> filteredConnectPoints =
200 egressPoints.stream()
201 .map(FilteredConnectPoint::new)
202 .collect(Collectors.toSet());
203 this.egressPoints = ImmutableSet.copyOf(filteredConnectPoints);
Ray Milkeyebc5d222015-03-18 15:45:36 -0700204 return this;
205 }
206
207 /**
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700208 * Sets the filtered ingress point of the single point to
209 * multi point intent that will be built.
Pier Ventre27d42572016-08-29 17:37:08 -0700210 *
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700211 * @param ingressPoint ingress connect point
Pier Ventre27d42572016-08-29 17:37:08 -0700212 * @return this builder
213 */
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700214 public Builder filteredIngressPoint(FilteredConnectPoint ingressPoint) {
215 this.ingressPoint = ingressPoint;
Pier Ventre27d42572016-08-29 17:37:08 -0700216 return this;
217 }
218
219 /**
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700220 * Sets the filtered egress points of the single point to
221 * multi point intent that will be built.
222 *
223 * @param egressPoints egress connect points
224 * @return this builder
225 */
226 public Builder filteredEgressPoints(Set<FilteredConnectPoint> egressPoints) {
227 this.egressPoints = ImmutableSet.copyOf(egressPoints);
228 return this;
229 }
230
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700231 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -0700232 * Builds a single point to multi point intent from the
233 * accumulated parameters.
234 *
235 * @return point to point intent
236 */
237 public SinglePointToMultiPointIntent build() {
238
239 return new SinglePointToMultiPointIntent(
240 appId,
241 key,
242 selector,
243 treatment,
244 ingressPoint,
245 egressPoints,
246 constraints,
Luca Prete670ac5d2017-02-03 15:55:43 -0800247 priority,
248 resourceGroup
Ray Milkeyebc5d222015-03-18 15:45:36 -0700249 );
250 }
Brian O'Connorb876bf12014-10-02 14:59:37 -0700251 }
252
253 /**
254 * Constructor for serializer.
255 */
256 protected SinglePointToMultiPointIntent() {
257 super();
tom85258ee2014-10-07 00:10:02 -0700258 this.ingressPoint = null;
259 this.egressPoints = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700260 }
261
262 /**
Michele Santuari4a338072014-11-05 18:38:55 +0100263 * Returns the port on which the ingress traffic should be connected to the
264 * egress.
Brian O'Connorb876bf12014-10-02 14:59:37 -0700265 *
266 * @return ingress port
267 */
tom85258ee2014-10-07 00:10:02 -0700268 public ConnectPoint ingressPoint() {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700269 return ingressPoint.connectPoint();
Brian O'Connorb876bf12014-10-02 14:59:37 -0700270 }
271
272 /**
273 * Returns the set of ports on which the traffic should egress.
274 *
275 * @return set of egress ports
276 */
tom85258ee2014-10-07 00:10:02 -0700277 public Set<ConnectPoint> egressPoints() {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700278 return egressPoints.stream()
279 .map(FilteredConnectPoint::connectPoint)
280 .collect(Collectors.toSet());
Brian O'Connorb876bf12014-10-02 14:59:37 -0700281 }
282
Pier Ventre27d42572016-08-29 17:37:08 -0700283 /**
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700284 * Returns the filtered port on which the ingress traffic should be connected to the
285 * egress.
286 *
287 * @return ingress port
Pier Ventre27d42572016-08-29 17:37:08 -0700288 */
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700289 public FilteredConnectPoint filteredIngressPoint() {
290 return ingressPoint;
Pier Ventre27d42572016-08-29 17:37:08 -0700291 }
292
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700293 /**
294 * Returns the set of filtered ports on which the traffic should egress.
295 *
296 * @return set of egress ports
297 */
298 public Set<FilteredConnectPoint> filteredEgressPoints() {
299 return egressPoints;
300 }
301
302
Brian O'Connorb876bf12014-10-02 14:59:37 -0700303 @Override
Brian O'Connorb876bf12014-10-02 14:59:37 -0700304 public String toString() {
305 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700306 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800307 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700308 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700309 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800310 .add("resources", resources())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700311 .add("selector", selector())
312 .add("treatment", treatment())
313 .add("ingress", ingressPoint)
314 .add("egress", egressPoints)
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700315 .add("filteredIngressCPs", filteredIngressPoint())
316 .add("filteredEgressCP", filteredEgressPoints())
Michele Santuari4a338072014-11-05 18:38:55 +0100317 .add("constraints", constraints())
Luca Prete670ac5d2017-02-03 15:55:43 -0800318 .add("resourceGroup", resourceGroup())
Brian O'Connorb876bf12014-10-02 14:59:37 -0700319 .toString();
320 }
321
322}