blob: d1fe61219bf0f7ca16313fe5cb6997a486aefe9f [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;
Pier Ventre647138f2016-08-26 17:32:44 -070020import com.google.common.collect.ImmutableMap;
Ray Milkeyebc5d222015-03-18 15:45:36 -070021import com.google.common.collect.ImmutableSet;
tom85258ee2014-10-07 00:10:02 -070022import com.google.common.collect.Sets;
Brian O'Connorabafb502014-12-02 22:26:20 -080023import org.onosproject.core.ApplicationId;
24import org.onosproject.net.ConnectPoint;
25import org.onosproject.net.flow.TrafficSelector;
26import org.onosproject.net.flow.TrafficTreatment;
Brian O'Connorb876bf12014-10-02 14:59:37 -070027
Sho SHIMIZUc3df36b2014-11-11 18:19:29 -080028import java.util.Collections;
Ray Milkey460f4022014-11-05 15:41:43 -080029import java.util.List;
Pier Ventre647138f2016-08-26 17:32:44 -070030import java.util.Map;
tom85258ee2014-10-07 00:10:02 -070031import java.util.Set;
32
33import static com.google.common.base.Preconditions.checkArgument;
34import static com.google.common.base.Preconditions.checkNotNull;
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
tom85258ee2014-10-07 00:10:02 -070042 private final Set<ConnectPoint> ingressPoints;
43 private final ConnectPoint egressPoint;
Pier Ventre647138f2016-08-26 17:32:44 -070044 /**
45 * To manage multiple selectors use case.
46 */
47 private final Map<ConnectPoint, TrafficSelector> ingressSelectors;
Brian O'Connorb876bf12014-10-02 14:59:37 -070048
49 /**
50 * Creates a new multi-to-single point connectivity intent for the specified
Thomas Vachuskac96058a2014-10-20 23:00:16 -070051 * traffic selector and treatment.
Brian O'Connorb876bf12014-10-02 14:59:37 -070052 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070053 * @param appId application identifier
Jonathan Hartd0ba2172015-02-11 13:54:33 -080054 * @param key intent key
Ray Milkey460f4022014-11-05 15:41:43 -080055 * @param selector traffic selector
56 * @param treatment treatment
57 * @param ingressPoints set of ports from which ingress traffic originates
58 * @param egressPoint port to which traffic will egress
59 * @param constraints constraints to apply to the intent
Ray Milkeyc24cde32015-03-10 18:20:18 -070060 * @param priority priority to use for flows generated by this intent
Pier Ventre647138f2016-08-26 17:32:44 -070061 * @param ingressSelectors map to store the association ingress to selector
Ray Milkey460f4022014-11-05 15:41:43 -080062 * @throws NullPointerException if {@code ingressPoints} or
63 * {@code egressPoint} is null.
64 * @throws IllegalArgumentException if the size of {@code ingressPoints} is
65 * not more than 1
66 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070067 private MultiPointToSinglePointIntent(ApplicationId appId,
Pier Ventre647138f2016-08-26 17:32:44 -070068 Key key,
69 TrafficSelector selector,
70 TrafficTreatment treatment,
71 Set<ConnectPoint> ingressPoints,
72 ConnectPoint egressPoint,
73 List<Constraint> constraints,
74 int priority,
75 Map<ConnectPoint, TrafficSelector> ingressSelectors
76 ) {
Ray Milkeyc24cde32015-03-10 18:20:18 -070077 super(appId, key, Collections.emptyList(), selector, treatment, constraints,
78 priority);
Ray Milkey460f4022014-11-05 15:41:43 -080079
80 checkNotNull(ingressPoints);
81 checkArgument(!ingressPoints.isEmpty(), "Ingress point set cannot be empty");
Sho SHIMIZU2e660802014-11-21 14:55:32 -080082 checkNotNull(egressPoint);
83 checkArgument(!ingressPoints.contains(egressPoint),
84 "Set of ingresses should not contain egress (egress: %s)", egressPoint);
Ray Milkey460f4022014-11-05 15:41:43 -080085
86 this.ingressPoints = Sets.newHashSet(ingressPoints);
Sho SHIMIZU2e660802014-11-21 14:55:32 -080087 this.egressPoint = egressPoint;
Pier Ventre647138f2016-08-26 17:32:44 -070088 this.ingressSelectors = ingressSelectors;
Ray Milkey460f4022014-11-05 15:41:43 -080089 }
90
91 /**
Brian O'Connorb876bf12014-10-02 14:59:37 -070092 * Constructor for serializer.
93 */
94 protected MultiPointToSinglePointIntent() {
95 super();
tom85258ee2014-10-07 00:10:02 -070096 this.ingressPoints = null;
97 this.egressPoint = null;
Pier Ventre647138f2016-08-26 17:32:44 -070098 this.ingressSelectors = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -070099 }
100
101 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -0700102 * Returns a new multi point to single point intent builder. The application id,
103 * ingress points and egress point are required fields. If they are
104 * not set by calls to the appropriate methods, an exception will
105 * be thrown.
106 *
107 * @return single point to multi point builder
108 */
109 public static Builder builder() {
110 return new Builder();
111 }
112
113 /**
Jonathan Hartb14221c2016-03-07 09:55:50 -0800114 * Creates a new builder pre-populated with the information in the given
115 * intent.
116 *
117 * @param intent initial intent
118 * @return intent builder
119 */
120 public static Builder builder(MultiPointToSinglePointIntent intent) {
121 return new Builder(intent);
122 }
123
124 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -0700125 * Builder of a multi point to single point intent.
126 */
127 public static final class Builder extends ConnectivityIntent.Builder {
128 Set<ConnectPoint> ingressPoints;
129 ConnectPoint egressPoint;
Pier Ventre647138f2016-08-26 17:32:44 -0700130 Map<ConnectPoint, TrafficSelector> ingressSelectors = Collections.emptyMap();
Ray Milkeyebc5d222015-03-18 15:45:36 -0700131
132 private Builder() {
133 // Hide constructor
134 }
135
Jonathan Hartb14221c2016-03-07 09:55:50 -0800136 /**
137 * Creates a new builder pre-populated with information from the given
138 * intent.
139 *
140 * @param intent initial intent
141 */
142 protected Builder(MultiPointToSinglePointIntent intent) {
143 super(intent);
144
145 this.ingressPoints(intent.ingressPoints())
146 .egressPoint(intent.egressPoint());
147 }
148
Ray Milkeyebc5d222015-03-18 15:45:36 -0700149 @Override
150 public Builder appId(ApplicationId appId) {
151 return (Builder) super.appId(appId);
152 }
153
154 @Override
155 public Builder key(Key key) {
156 return (Builder) super.key(key);
157 }
158
159 @Override
160 public Builder selector(TrafficSelector selector) {
161 return (Builder) super.selector(selector);
162 }
163
164 @Override
165 public Builder treatment(TrafficTreatment treatment) {
166 return (Builder) super.treatment(treatment);
167 }
168
169 @Override
170 public Builder constraints(List<Constraint> constraints) {
171 return (Builder) super.constraints(constraints);
172 }
173
174 @Override
175 public Builder priority(int priority) {
176 return (Builder) super.priority(priority);
177 }
178
179 /**
180 * Sets the ingress point of the single point to multi point intent
181 * that will be built.
182 *
183 * @param ingressPoints ingress connect points
184 * @return this builder
185 */
186 public Builder ingressPoints(Set<ConnectPoint> ingressPoints) {
187 this.ingressPoints = ImmutableSet.copyOf(ingressPoints);
188 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 */
198 public Builder egressPoint(ConnectPoint egressPoint) {
199 this.egressPoint = egressPoint;
200 return this;
201 }
202
203 /**
Pier Ventre647138f2016-08-26 17:32:44 -0700204 * Sets the selectors of the multi point to single point intent
205 * that will be built.
206 *
207 * @param ingressSelectors the multiple selectos
208 * @return this builder
209 */
210 public Builder selectors(Map<ConnectPoint, TrafficSelector> ingressSelectors) {
211 this.ingressSelectors = ImmutableMap.copyOf(ingressSelectors);
212 return this;
213 }
214
215 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -0700216 * Builds a multi point to single point intent from the
217 * accumulated parameters.
218 *
Pier Ventre647138f2016-08-26 17:32:44 -0700219 * @return multi point to single point intent
Ray Milkeyebc5d222015-03-18 15:45:36 -0700220 */
221 public MultiPointToSinglePointIntent build() {
222
Pier Ventre647138f2016-08-26 17:32:44 -0700223 if (selector != null && !selector.criteria().isEmpty() &&
224 ingressSelectors != null && !ingressSelectors.isEmpty()) {
225 throw new IllegalArgumentException("Selector and Multiple Selectors are both set");
226 }
227
Ray Milkeyebc5d222015-03-18 15:45:36 -0700228 return new MultiPointToSinglePointIntent(
229 appId,
230 key,
231 selector,
232 treatment,
233 ingressPoints,
234 egressPoint,
235 constraints,
Pier Ventre647138f2016-08-26 17:32:44 -0700236 priority,
237 ingressSelectors
Ray Milkeyebc5d222015-03-18 15:45:36 -0700238 );
239 }
240 }
241
242
243 /**
Brian O'Connorb876bf12014-10-02 14:59:37 -0700244 * Returns the set of ports on which ingress traffic should be connected to
245 * the egress port.
246 *
247 * @return set of ingress ports
248 */
tom85258ee2014-10-07 00:10:02 -0700249 public Set<ConnectPoint> ingressPoints() {
250 return ingressPoints;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700251 }
252
253 /**
254 * Returns the port on which the traffic should egress.
255 *
256 * @return egress port
257 */
tom85258ee2014-10-07 00:10:02 -0700258 public ConnectPoint egressPoint() {
259 return egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700260 }
261
Pier Ventre647138f2016-08-26 17:32:44 -0700262 /**
263 * Returns the multiple selectors jointly with their connection points.
264 * @return multiple selectors
265 */
266 public Map<ConnectPoint, TrafficSelector> ingressSelectors() {
267 return ingressSelectors;
268 }
269
Brian O'Connorb876bf12014-10-02 14:59:37 -0700270 @Override
Brian O'Connorb876bf12014-10-02 14:59:37 -0700271 public String toString() {
272 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700273 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800274 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700275 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700276 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800277 .add("resources", resources())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700278 .add("selector", selector())
279 .add("treatment", treatment())
280 .add("ingress", ingressPoints())
281 .add("egress", egressPoint())
Pier Ventre647138f2016-08-26 17:32:44 -0700282 .add("selectors", ingressSelectors())
Ray Milkey460f4022014-11-05 15:41:43 -0800283 .add("constraints", constraints())
Brian O'Connorb876bf12014-10-02 14:59:37 -0700284 .toString();
285 }
286}