blob: 8431a0a935fdd6b1292d311bfc0c384f3ace672d [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;
Brian O'Connorabafb502014-12-02 22:26:20 -080027import org.onosproject.net.flow.TrafficSelector;
28import org.onosproject.net.flow.TrafficTreatment;
Yi Tseng2a81c9d2016-09-14 10:14:24 -070029import org.slf4j.Logger;
Brian O'Connorb876bf12014-10-02 14:59:37 -070030
toma1d16b62014-10-02 23:45:11 -070031import java.util.Set;
Michele Santuari4a338072014-11-05 18:38:55 +010032import java.util.List;
Yi Tseng2a81c9d2016-09-14 10:14:24 -070033import java.util.stream.Collectors;
toma1d16b62014-10-02 23:45:11 -070034
35import static com.google.common.base.Preconditions.checkArgument;
36import static com.google.common.base.Preconditions.checkNotNull;
Yi Tseng2a81c9d2016-09-14 10:14:24 -070037import static org.slf4j.LoggerFactory.getLogger;
Brian O'Connorb876bf12014-10-02 14:59:37 -070038
39/**
40 * Abstraction of single source, multiple destination connectivity intent.
41 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040042@Beta
Ray Milkeybd4f0112015-03-02 17:07:09 -080043public final class SinglePointToMultiPointIntent extends ConnectivityIntent {
Yi Tseng2a81c9d2016-09-14 10:14:24 -070044 private final FilteredConnectPoint ingressPoint;
45 private final Set<FilteredConnectPoint> egressPoints;
Brian O'Connorb876bf12014-10-02 14:59:37 -070046
47 /**
48 * Creates a new single-to-multi point connectivity intent.
49 *
Michele Santuari4a338072014-11-05 18:38:55 +010050 * @param appId application identifier
Ray Milkey5b3717e2015-02-05 11:44:08 -080051 * @param key intent key
Michele Santuari4a338072014-11-05 18:38:55 +010052 * @param selector traffic selector
53 * @param treatment treatment
54 * @param ingressPoint port on which traffic will ingress
55 * @param egressPoints set of ports on which traffic will egress
56 * @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
Michele Santuari4a338072014-11-05 18:38:55 +010058 * @throws NullPointerException if {@code ingressPoint} or
59 * {@code egressPoints} is null
60 * @throws IllegalArgumentException if the size of {@code egressPoints} is
61 * not more than 1
62 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070063 private SinglePointToMultiPointIntent(ApplicationId appId,
Pier Ventre27d42572016-08-29 17:37:08 -070064 Key key,
65 TrafficSelector selector,
66 TrafficTreatment treatment,
Yi Tseng2a81c9d2016-09-14 10:14:24 -070067 FilteredConnectPoint ingressPoint,
68 Set<FilteredConnectPoint> egressPoints,
Pier Ventre27d42572016-08-29 17:37:08 -070069 List<Constraint> constraints,
Yi Tseng2a81c9d2016-09-14 10:14:24 -070070 int priority) {
Pier Ventre27d42572016-08-29 17:37:08 -070071 super(appId, key, ImmutableList.of(), selector, treatment, constraints,
72 priority);
tom85258ee2014-10-07 00:10:02 -070073 checkNotNull(egressPoints);
Sho SHIMIZU2e660802014-11-21 14:55:32 -080074 checkNotNull(ingressPoint);
Thomas Vachuskac96058a2014-10-20 23:00:16 -070075 checkArgument(!egressPoints.isEmpty(), "Egress point set cannot be empty");
Sho SHIMIZU2e660802014-11-21 14:55:32 -080076 checkArgument(!egressPoints.contains(ingressPoint),
Yi Tseng2a81c9d2016-09-14 10:14:24 -070077 "Set of egresses should not contain ingress (ingress: %s)", ingressPoint);
Sho SHIMIZU2e660802014-11-21 14:55:32 -080078
Pier Ventre27d42572016-08-29 17:37:08 -070079 this.ingressPoint = ingressPoint;
80 this.egressPoints = Sets.newHashSet(egressPoints);
Ray Milkeyebc5d222015-03-18 15:45:36 -070081 }
82
83 /**
84 * Returns a new single point to multi point intent builder. The application id,
85 * ingress point and egress points are required fields. If they are
86 * not set by calls to the appropriate methods, an exception will
87 * be thrown.
88 *
89 * @return single point to multi point builder
90 */
91 public static Builder builder() {
92 return new Builder();
93 }
94
95 /**
Yi Tseng2a81c9d2016-09-14 10:14:24 -070096 * Creates a new builder pre-populated with the information in the given
97 * intent.
98 *
99 * @param intent initial intent
100 * @return intent builder
101 */
102 public static Builder builder(SinglePointToMultiPointIntent intent) {
103 return new Builder(intent);
104 }
105
106 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -0700107 * Builder of a single point to multi point intent.
108 */
109 public static final class Builder extends ConnectivityIntent.Builder {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700110 private final Logger log = getLogger(getClass());
111 private FilteredConnectPoint ingressPoint;
112 private Set<FilteredConnectPoint> egressPoints;
Ray Milkeyebc5d222015-03-18 15:45:36 -0700113
114 private Builder() {
115 // Hide constructor
116 }
117
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700118 /**
119 * Creates a new builder pre-populated with information from the given
120 * intent.
121 *
122 * @param intent initial intent
123 */
124 protected Builder(SinglePointToMultiPointIntent intent) {
125 super(intent);
126
127 this.filteredEgressPoints(intent.filteredEgressPoints())
128 .filteredIngressPoint(intent.filteredIngressPoint());
129
130 }
131
Ray Milkeyebc5d222015-03-18 15:45:36 -0700132 @Override
133 public Builder appId(ApplicationId appId) {
134 return (Builder) super.appId(appId);
135 }
136
137 @Override
138 public Builder key(Key key) {
139 return (Builder) super.key(key);
140 }
141
142 @Override
143 public Builder selector(TrafficSelector selector) {
144 return (Builder) super.selector(selector);
145 }
146
147 @Override
148 public Builder treatment(TrafficTreatment treatment) {
149 return (Builder) super.treatment(treatment);
150 }
151
152 @Override
153 public Builder constraints(List<Constraint> constraints) {
154 return (Builder) super.constraints(constraints);
155 }
156
157 @Override
158 public Builder priority(int priority) {
159 return (Builder) super.priority(priority);
160 }
161
162 /**
163 * Sets the ingress point of the single point to multi point intent
164 * that will be built.
165 *
166 * @param ingressPoint ingress connect point
167 * @return this builder
168 */
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700169 @Deprecated
Ray Milkeyebc5d222015-03-18 15:45:36 -0700170 public Builder ingressPoint(ConnectPoint ingressPoint) {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700171 if (this.ingressPoint != null) {
172 log.warn("Ingress point is already set, " +
173 "this will override original ingress point.");
174 }
175 this.ingressPoint = new FilteredConnectPoint(ingressPoint);
Ray Milkeyebc5d222015-03-18 15:45:36 -0700176 return this;
177 }
178
179 /**
180 * Sets the egress points of the single point to multi point intent
181 * that will be built.
182 *
183 * @param egressPoints egress connect points
184 * @return this builder
185 */
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700186 @Deprecated
Ray Milkeyebc5d222015-03-18 15:45:36 -0700187 public Builder egressPoints(Set<ConnectPoint> egressPoints) {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700188 if (this.egressPoints != null) {
189 log.warn("Egress points are already set, " +
190 "this will override original egress points.");
191 }
192 Set<FilteredConnectPoint> filteredConnectPoints =
193 egressPoints.stream()
194 .map(FilteredConnectPoint::new)
195 .collect(Collectors.toSet());
196 this.egressPoints = ImmutableSet.copyOf(filteredConnectPoints);
Ray Milkeyebc5d222015-03-18 15:45:36 -0700197 return this;
198 }
199
200 /**
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700201 * Sets the filtered ingress point of the single point to
202 * multi point intent that will be built.
Pier Ventre27d42572016-08-29 17:37:08 -0700203 *
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700204 * @param ingressPoint ingress connect point
Pier Ventre27d42572016-08-29 17:37:08 -0700205 * @return this builder
206 */
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700207 public Builder filteredIngressPoint(FilteredConnectPoint ingressPoint) {
208 this.ingressPoint = ingressPoint;
Pier Ventre27d42572016-08-29 17:37:08 -0700209 return this;
210 }
211
212 /**
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700213 * Sets the filtered egress points of the single point to
214 * multi point intent that will be built.
215 *
216 * @param egressPoints egress connect points
217 * @return this builder
218 */
219 public Builder filteredEgressPoints(Set<FilteredConnectPoint> egressPoints) {
220 this.egressPoints = ImmutableSet.copyOf(egressPoints);
221 return this;
222 }
223
224
225 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -0700226 * Builds a single point to multi point intent from the
227 * accumulated parameters.
228 *
229 * @return point to point intent
230 */
231 public SinglePointToMultiPointIntent build() {
232
233 return new SinglePointToMultiPointIntent(
234 appId,
235 key,
236 selector,
237 treatment,
238 ingressPoint,
239 egressPoints,
240 constraints,
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700241 priority
Ray Milkeyebc5d222015-03-18 15:45:36 -0700242 );
243 }
Brian O'Connorb876bf12014-10-02 14:59:37 -0700244 }
245
246 /**
247 * Constructor for serializer.
248 */
249 protected SinglePointToMultiPointIntent() {
250 super();
tom85258ee2014-10-07 00:10:02 -0700251 this.ingressPoint = null;
252 this.egressPoints = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700253 }
254
255 /**
Michele Santuari4a338072014-11-05 18:38:55 +0100256 * Returns the port on which the ingress traffic should be connected to the
257 * egress.
Brian O'Connorb876bf12014-10-02 14:59:37 -0700258 *
259 * @return ingress port
260 */
tom85258ee2014-10-07 00:10:02 -0700261 public ConnectPoint ingressPoint() {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700262 return ingressPoint.connectPoint();
Brian O'Connorb876bf12014-10-02 14:59:37 -0700263 }
264
265 /**
266 * Returns the set of ports on which the traffic should egress.
267 *
268 * @return set of egress ports
269 */
tom85258ee2014-10-07 00:10:02 -0700270 public Set<ConnectPoint> egressPoints() {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700271 return egressPoints.stream()
272 .map(FilteredConnectPoint::connectPoint)
273 .collect(Collectors.toSet());
Brian O'Connorb876bf12014-10-02 14:59:37 -0700274 }
275
Pier Ventre27d42572016-08-29 17:37:08 -0700276 /**
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700277 * Returns the filtered port on which the ingress traffic should be connected to the
278 * egress.
279 *
280 * @return ingress port
Pier Ventre27d42572016-08-29 17:37:08 -0700281 */
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700282 public FilteredConnectPoint filteredIngressPoint() {
283 return ingressPoint;
Pier Ventre27d42572016-08-29 17:37:08 -0700284 }
285
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700286 /**
287 * Returns the set of filtered ports on which the traffic should egress.
288 *
289 * @return set of egress ports
290 */
291 public Set<FilteredConnectPoint> filteredEgressPoints() {
292 return egressPoints;
293 }
294
295
Brian O'Connorb876bf12014-10-02 14:59:37 -0700296 @Override
Brian O'Connorb876bf12014-10-02 14:59:37 -0700297 public String toString() {
298 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700299 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800300 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700301 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700302 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800303 .add("resources", resources())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700304 .add("selector", selector())
305 .add("treatment", treatment())
306 .add("ingress", ingressPoint)
307 .add("egress", egressPoints)
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700308 .add("filteredIngressCPs", filteredIngressPoint())
309 .add("filteredEgressCP", filteredEgressPoints())
Michele Santuari4a338072014-11-05 18:38:55 +0100310 .add("constraints", constraints())
Brian O'Connorb876bf12014-10-02 14:59:37 -0700311 .toString();
312 }
313
314}