blob: 2b8398f8aeb7373a2bdbe07277e14837c6e1b12b [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
Ray Milkey460f4022014-11-05 15:41:43 -080028import java.util.List;
Pier Ventre647138f2016-08-26 17:32:44 -070029import java.util.Map;
tom85258ee2014-10-07 00:10:02 -070030import java.util.Set;
31
32import static com.google.common.base.Preconditions.checkArgument;
33import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connorb876bf12014-10-02 14:59:37 -070034
35/**
36 * Abstraction of multiple source to single destination connectivity intent.
37 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040038@Beta
Ray Milkeye6684082014-10-16 16:59:47 -070039public final class MultiPointToSinglePointIntent extends ConnectivityIntent {
Brian O'Connorb876bf12014-10-02 14:59:37 -070040
tom85258ee2014-10-07 00:10:02 -070041 private final Set<ConnectPoint> ingressPoints;
42 private final ConnectPoint egressPoint;
Pier Ventre647138f2016-08-26 17:32:44 -070043 /**
44 * To manage multiple selectors use case.
45 */
46 private final Map<ConnectPoint, TrafficSelector> ingressSelectors;
Brian O'Connorb876bf12014-10-02 14:59:37 -070047
48 /**
49 * Creates a new multi-to-single point connectivity intent for the specified
Thomas Vachuskac96058a2014-10-20 23:00:16 -070050 * traffic selector and treatment.
Brian O'Connorb876bf12014-10-02 14:59:37 -070051 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070052 * @param appId application identifier
Jonathan Hartd0ba2172015-02-11 13:54:33 -080053 * @param key intent key
Ray Milkey460f4022014-11-05 15:41:43 -080054 * @param selector traffic selector
55 * @param treatment treatment
56 * @param ingressPoints set of ports from which ingress traffic originates
57 * @param egressPoint port to which traffic will egress
58 * @param constraints constraints to apply to the intent
Ray Milkeyc24cde32015-03-10 18:20:18 -070059 * @param priority priority to use for flows generated by this intent
Pier Ventre647138f2016-08-26 17:32:44 -070060 * @param ingressSelectors map to store the association ingress to selector
Ray Milkey460f4022014-11-05 15:41:43 -080061 * @throws NullPointerException if {@code ingressPoints} or
62 * {@code egressPoint} is null.
63 * @throws IllegalArgumentException if the size of {@code ingressPoints} is
64 * not more than 1
65 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070066 private MultiPointToSinglePointIntent(ApplicationId appId,
Pier Ventre647138f2016-08-26 17:32:44 -070067 Key key,
68 TrafficSelector selector,
69 TrafficTreatment treatment,
70 Set<ConnectPoint> ingressPoints,
71 ConnectPoint egressPoint,
72 List<Constraint> constraints,
73 int priority,
74 Map<ConnectPoint, TrafficSelector> ingressSelectors
75 ) {
Thomas Vachuskae45ab442016-08-31 14:21:33 -070076 super(appId, key, ImmutableSet.of(), selector, treatment, constraints,
Ray Milkeyc24cde32015-03-10 18:20:18 -070077 priority);
Ray Milkey460f4022014-11-05 15:41:43 -080078
79 checkNotNull(ingressPoints);
80 checkArgument(!ingressPoints.isEmpty(), "Ingress point set cannot be empty");
Sho SHIMIZU2e660802014-11-21 14:55:32 -080081 checkNotNull(egressPoint);
82 checkArgument(!ingressPoints.contains(egressPoint),
83 "Set of ingresses should not contain egress (egress: %s)", egressPoint);
Ray Milkey460f4022014-11-05 15:41:43 -080084
85 this.ingressPoints = Sets.newHashSet(ingressPoints);
Sho SHIMIZU2e660802014-11-21 14:55:32 -080086 this.egressPoint = egressPoint;
Pier Ventre647138f2016-08-26 17:32:44 -070087 this.ingressSelectors = ingressSelectors;
Ray Milkey460f4022014-11-05 15:41:43 -080088 }
89
90 /**
Brian O'Connorb876bf12014-10-02 14:59:37 -070091 * Constructor for serializer.
92 */
93 protected MultiPointToSinglePointIntent() {
94 super();
tom85258ee2014-10-07 00:10:02 -070095 this.ingressPoints = null;
96 this.egressPoint = null;
Pier Ventre647138f2016-08-26 17:32:44 -070097 this.ingressSelectors = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -070098 }
99
100 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -0700101 * Returns a new multi point to single point intent builder. The application id,
102 * ingress points and egress point are required fields. If they are
103 * not set by calls to the appropriate methods, an exception will
104 * be thrown.
105 *
106 * @return single point to multi point builder
107 */
108 public static Builder builder() {
109 return new Builder();
110 }
111
112 /**
Jonathan Hartb14221c2016-03-07 09:55:50 -0800113 * Creates a new builder pre-populated with the information in the given
114 * intent.
115 *
116 * @param intent initial intent
117 * @return intent builder
118 */
119 public static Builder builder(MultiPointToSinglePointIntent intent) {
120 return new Builder(intent);
121 }
122
123 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -0700124 * Builder of a multi point to single point intent.
125 */
126 public static final class Builder extends ConnectivityIntent.Builder {
127 Set<ConnectPoint> ingressPoints;
128 ConnectPoint egressPoint;
Thomas Vachuskae45ab442016-08-31 14:21:33 -0700129 Map<ConnectPoint, TrafficSelector> ingressSelectors = ImmutableMap.of();
Ray Milkeyebc5d222015-03-18 15:45:36 -0700130
131 private Builder() {
132 // Hide constructor
133 }
134
Jonathan Hartb14221c2016-03-07 09:55:50 -0800135 /**
136 * Creates a new builder pre-populated with information from the given
137 * intent.
138 *
139 * @param intent initial intent
140 */
141 protected Builder(MultiPointToSinglePointIntent intent) {
142 super(intent);
143
144 this.ingressPoints(intent.ingressPoints())
145 .egressPoint(intent.egressPoint());
146 }
147
Ray Milkeyebc5d222015-03-18 15:45:36 -0700148 @Override
149 public Builder appId(ApplicationId appId) {
150 return (Builder) super.appId(appId);
151 }
152
153 @Override
154 public Builder key(Key key) {
155 return (Builder) super.key(key);
156 }
157
158 @Override
159 public Builder selector(TrafficSelector selector) {
160 return (Builder) super.selector(selector);
161 }
162
163 @Override
164 public Builder treatment(TrafficTreatment treatment) {
165 return (Builder) super.treatment(treatment);
166 }
167
168 @Override
169 public Builder constraints(List<Constraint> constraints) {
170 return (Builder) super.constraints(constraints);
171 }
172
173 @Override
174 public Builder priority(int priority) {
175 return (Builder) super.priority(priority);
176 }
177
178 /**
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 */
185 public Builder ingressPoints(Set<ConnectPoint> ingressPoints) {
186 this.ingressPoints = ImmutableSet.copyOf(ingressPoints);
187 return this;
188 }
189
190 /**
191 * Sets the egress point of the multi point to single point intent
192 * that will be built.
193 *
194 * @param egressPoint egress connect point
195 * @return this builder
196 */
197 public Builder egressPoint(ConnectPoint egressPoint) {
198 this.egressPoint = egressPoint;
199 return this;
200 }
201
202 /**
Pier Ventre647138f2016-08-26 17:32:44 -0700203 * Sets the selectors of the multi point to single point intent
204 * that will be built.
205 *
206 * @param ingressSelectors the multiple selectos
207 * @return this builder
208 */
209 public Builder selectors(Map<ConnectPoint, TrafficSelector> ingressSelectors) {
210 this.ingressSelectors = ImmutableMap.copyOf(ingressSelectors);
211 return this;
212 }
213
214 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -0700215 * Builds a multi point to single point intent from the
216 * accumulated parameters.
217 *
Pier Ventre647138f2016-08-26 17:32:44 -0700218 * @return multi point to single point intent
Ray Milkeyebc5d222015-03-18 15:45:36 -0700219 */
220 public MultiPointToSinglePointIntent build() {
221
Pier Ventre647138f2016-08-26 17:32:44 -0700222 if (selector != null && !selector.criteria().isEmpty() &&
223 ingressSelectors != null && !ingressSelectors.isEmpty()) {
224 throw new IllegalArgumentException("Selector and Multiple Selectors are both set");
225 }
226
Ray Milkeyebc5d222015-03-18 15:45:36 -0700227 return new MultiPointToSinglePointIntent(
228 appId,
229 key,
230 selector,
231 treatment,
232 ingressPoints,
233 egressPoint,
234 constraints,
Pier Ventre647138f2016-08-26 17:32:44 -0700235 priority,
236 ingressSelectors
Ray Milkeyebc5d222015-03-18 15:45:36 -0700237 );
238 }
239 }
240
241
242 /**
Brian O'Connorb876bf12014-10-02 14:59:37 -0700243 * Returns the set of ports on which ingress traffic should be connected to
244 * the egress port.
245 *
246 * @return set of ingress ports
247 */
tom85258ee2014-10-07 00:10:02 -0700248 public Set<ConnectPoint> ingressPoints() {
249 return ingressPoints;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700250 }
251
252 /**
253 * Returns the port on which the traffic should egress.
254 *
255 * @return egress port
256 */
tom85258ee2014-10-07 00:10:02 -0700257 public ConnectPoint egressPoint() {
258 return egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700259 }
260
Pier Ventre647138f2016-08-26 17:32:44 -0700261 /**
262 * Returns the multiple selectors jointly with their connection points.
263 * @return multiple selectors
264 */
265 public Map<ConnectPoint, TrafficSelector> ingressSelectors() {
266 return ingressSelectors;
267 }
268
Brian O'Connorb876bf12014-10-02 14:59:37 -0700269 @Override
Brian O'Connorb876bf12014-10-02 14:59:37 -0700270 public String toString() {
271 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700272 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800273 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700274 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700275 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800276 .add("resources", resources())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700277 .add("selector", selector())
278 .add("treatment", treatment())
279 .add("ingress", ingressPoints())
280 .add("egress", egressPoint())
Pier Ventre647138f2016-08-26 17:32:44 -0700281 .add("selectors", ingressSelectors())
Ray Milkey460f4022014-11-05 15:41:43 -0800282 .add("constraints", constraints())
Brian O'Connorb876bf12014-10-02 14:59:37 -0700283 .toString();
284 }
285}