blob: 8745ecb84f6f29c9fab72e4216a2cdb1aea95554 [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2014-present Open Networking Foundation
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;
Luca Prete670ac5d2017-02-03 15:55:43 -080024import org.onosproject.net.ResourceGroup;
Brian O'Connorabafb502014-12-02 22:26:20 -080025import org.onosproject.net.flow.TrafficSelector;
26import org.onosproject.net.flow.TrafficTreatment;
Yi Tseng2a81c9d2016-09-14 10:14:24 -070027import org.slf4j.Logger;
Brian O'Connorb876bf12014-10-02 14:59:37 -070028
Ray Milkey460f4022014-11-05 15:41:43 -080029import java.util.List;
tom85258ee2014-10-07 00:10:02 -070030import java.util.Set;
Yi Tseng2a81c9d2016-09-14 10:14:24 -070031import java.util.stream.Collectors;
tom85258ee2014-10-07 00:10:02 -070032
33import static com.google.common.base.Preconditions.checkArgument;
34import static com.google.common.base.Preconditions.checkNotNull;
Yi Tseng2a81c9d2016-09-14 10:14:24 -070035import static org.slf4j.LoggerFactory.getLogger;
Brian O'Connorb876bf12014-10-02 14:59:37 -070036
37/**
38 * Abstraction of multiple source to single destination connectivity intent.
39 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040040@Beta
Ray Milkeye6684082014-10-16 16:59:47 -070041public final class MultiPointToSinglePointIntent extends ConnectivityIntent {
Brian O'Connorb876bf12014-10-02 14:59:37 -070042
Yi Tseng2a81c9d2016-09-14 10:14:24 -070043 private final Set<FilteredConnectPoint> ingressPoints;
44 private final FilteredConnectPoint egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070045
46 /**
47 * Creates a new multi-to-single point connectivity intent for the specified
Yi Tseng2a81c9d2016-09-14 10:14:24 -070048 * traffic selector and treatment with filtered connect point.
Brian O'Connorb876bf12014-10-02 14:59:37 -070049 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070050 * @param appId application identifier
Jonathan Hartd0ba2172015-02-11 13:54:33 -080051 * @param key intent key
Ray Milkey460f4022014-11-05 15:41:43 -080052 * @param selector traffic selector
53 * @param treatment treatment
Yi Tseng2a81c9d2016-09-14 10:14:24 -070054 * @param ingressPoints set of filtered ports from which ingress traffic originates
55 * @param egressPoint filtered port to which traffic will egress
Ray Milkey460f4022014-11-05 15:41:43 -080056 * @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
Ray Milkey460f4022014-11-05 15:41:43 -080058 * @throws NullPointerException if {@code ingressPoints} or
59 * {@code egressPoint} is null.
60 * @throws IllegalArgumentException if the size of {@code ingressPoints} is
61 * not more than 1
62 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070063 private MultiPointToSinglePointIntent(ApplicationId appId,
Pier Ventre647138f2016-08-26 17:32:44 -070064 Key key,
65 TrafficSelector selector,
66 TrafficTreatment treatment,
Yi Tseng2a81c9d2016-09-14 10:14:24 -070067 Set<FilteredConnectPoint> ingressPoints,
68 FilteredConnectPoint egressPoint,
Pier Ventre647138f2016-08-26 17:32:44 -070069 List<Constraint> constraints,
Luca Prete670ac5d2017-02-03 15:55:43 -080070 int priority,
71 ResourceGroup resourceGroup) {
Thomas Vachuskae45ab442016-08-31 14:21:33 -070072 super(appId, key, ImmutableSet.of(), selector, treatment, constraints,
Luca Prete670ac5d2017-02-03 15:55:43 -080073 priority, resourceGroup);
Ray Milkey460f4022014-11-05 15:41:43 -080074
75 checkNotNull(ingressPoints);
76 checkArgument(!ingressPoints.isEmpty(), "Ingress point set cannot be empty");
Sho SHIMIZU2e660802014-11-21 14:55:32 -080077 checkNotNull(egressPoint);
78 checkArgument(!ingressPoints.contains(egressPoint),
Yi Tseng2a81c9d2016-09-14 10:14:24 -070079 "Set of ingresses should not contain egress (egress: %s)", egressPoint);
Ray Milkey460f4022014-11-05 15:41:43 -080080
Yi Tseng2a81c9d2016-09-14 10:14:24 -070081 this.ingressPoints = ImmutableSet.copyOf(ingressPoints);
Sho SHIMIZU2e660802014-11-21 14:55:32 -080082 this.egressPoint = egressPoint;
Ray Milkey460f4022014-11-05 15:41:43 -080083 }
84
85 /**
Brian O'Connorb876bf12014-10-02 14:59:37 -070086 * Constructor for serializer.
87 */
88 protected MultiPointToSinglePointIntent() {
89 super();
tom85258ee2014-10-07 00:10:02 -070090 this.ingressPoints = null;
91 this.egressPoint = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -070092 }
93
94 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -070095 * Returns a new multi point to single point intent builder. The application id,
96 * ingress points and egress point are required fields. If they are
97 * not set by calls to the appropriate methods, an exception will
98 * be thrown.
99 *
100 * @return single point to multi point builder
101 */
102 public static Builder builder() {
103 return new Builder();
104 }
105
106 /**
Jonathan Hartb14221c2016-03-07 09:55:50 -0800107 * Creates a new builder pre-populated with the information in the given
108 * intent.
109 *
110 * @param intent initial intent
111 * @return intent builder
112 */
113 public static Builder builder(MultiPointToSinglePointIntent intent) {
114 return new Builder(intent);
115 }
116
117 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -0700118 * Builder of a multi point to single point intent.
119 */
120 public static final class Builder extends ConnectivityIntent.Builder {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700121 private final Logger log = getLogger(getClass());
122 private Set<FilteredConnectPoint> ingressPoints;
123 private FilteredConnectPoint egressPoint;
Ray Milkeyebc5d222015-03-18 15:45:36 -0700124
125 private Builder() {
126 // Hide constructor
127 }
128
Jonathan Hartb14221c2016-03-07 09:55:50 -0800129 /**
130 * Creates a new builder pre-populated with information from the given
131 * intent.
132 *
133 * @param intent initial intent
134 */
135 protected Builder(MultiPointToSinglePointIntent intent) {
136 super(intent);
137
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700138 this.filteredIngressPoints(intent.filteredIngressPoints())
139 .filteredEgressPoint(intent.filteredEgressPoint());
140
Jonathan Hartb14221c2016-03-07 09:55:50 -0800141 }
142
Ray Milkeyebc5d222015-03-18 15:45:36 -0700143 @Override
144 public Builder appId(ApplicationId appId) {
145 return (Builder) super.appId(appId);
146 }
147
148 @Override
149 public Builder key(Key key) {
150 return (Builder) super.key(key);
151 }
152
153 @Override
154 public Builder selector(TrafficSelector selector) {
155 return (Builder) super.selector(selector);
156 }
157
158 @Override
159 public Builder treatment(TrafficTreatment treatment) {
160 return (Builder) super.treatment(treatment);
161 }
162
163 @Override
164 public Builder constraints(List<Constraint> constraints) {
165 return (Builder) super.constraints(constraints);
166 }
167
168 @Override
169 public Builder priority(int priority) {
170 return (Builder) super.priority(priority);
171 }
172
Luca Prete670ac5d2017-02-03 15:55:43 -0800173 @Override
174 public Builder resourceGroup(ResourceGroup resourceGroup) {
175 return (Builder) super.resourceGroup(resourceGroup);
176 }
177
Ray Milkeyebc5d222015-03-18 15:45:36 -0700178 /**
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700179 * Sets the filtered ingress point of the single point to multi point intent
Pier Ventre647138f2016-08-26 17:32:44 -0700180 * that will be built.
181 *
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700182 * @param ingressPoints filtered ingress connect points
Pier Ventre647138f2016-08-26 17:32:44 -0700183 * @return this builder
184 */
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700185 public Builder filteredIngressPoints(Set<FilteredConnectPoint> ingressPoints) {
186 this.ingressPoints = ImmutableSet.copyOf(ingressPoints);
187 return this;
188 }
189
190 /**
191 * Sets the filtered egress point of the multi point to single point intent
192 * that will be built.
193 *
194 * @param egressPoint filtered egress connect point
195 * @return this builder
196 */
197 public Builder filteredEgressPoint(FilteredConnectPoint egressPoint) {
198 this.egressPoint = egressPoint;
Pier Ventre647138f2016-08-26 17:32:44 -0700199 return this;
200 }
201
202 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -0700203 * Builds a multi point to single point intent from the
204 * accumulated parameters.
205 *
Pier Ventre647138f2016-08-26 17:32:44 -0700206 * @return multi point to single point intent
Ray Milkeyebc5d222015-03-18 15:45:36 -0700207 */
208 public MultiPointToSinglePointIntent build() {
209
210 return new MultiPointToSinglePointIntent(
211 appId,
212 key,
213 selector,
214 treatment,
215 ingressPoints,
216 egressPoint,
217 constraints,
Luca Prete670ac5d2017-02-03 15:55:43 -0800218 priority,
219 resourceGroup
Ray Milkeyebc5d222015-03-18 15:45:36 -0700220 );
221 }
222 }
223
224
225 /**
Brian O'Connorb876bf12014-10-02 14:59:37 -0700226 * Returns the set of ports on which ingress traffic should be connected to
227 * the egress port.
228 *
229 * @return set of ingress ports
230 */
tom85258ee2014-10-07 00:10:02 -0700231 public Set<ConnectPoint> ingressPoints() {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700232 return ingressPoints.stream()
233 .map(FilteredConnectPoint::connectPoint)
234 .collect(Collectors.toSet());
Brian O'Connorb876bf12014-10-02 14:59:37 -0700235 }
236
237 /**
238 * Returns the port on which the traffic should egress.
239 *
240 * @return egress port
241 */
tom85258ee2014-10-07 00:10:02 -0700242 public ConnectPoint egressPoint() {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700243 return egressPoint.connectPoint();
Brian O'Connorb876bf12014-10-02 14:59:37 -0700244 }
245
Pier Ventre647138f2016-08-26 17:32:44 -0700246 /**
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700247 * Returns the set of ports on which ingress traffic should be connected to
248 * the egress port.
249 *
250 * @return set of ingress ports
Pier Ventre647138f2016-08-26 17:32:44 -0700251 */
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700252 public Set<FilteredConnectPoint> filteredIngressPoints() {
253 return ingressPoints;
Pier Ventre647138f2016-08-26 17:32:44 -0700254 }
255
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700256 /**
257 * Returns the port on which the traffic should egress.
258 *
259 * @return egress port
260 */
261 public FilteredConnectPoint filteredEgressPoint() {
262 return egressPoint;
263 }
264
265
Brian O'Connorb876bf12014-10-02 14:59:37 -0700266 @Override
Brian O'Connorb876bf12014-10-02 14:59:37 -0700267 public String toString() {
268 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700269 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800270 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700271 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700272 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800273 .add("resources", resources())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700274 .add("selector", selector())
275 .add("treatment", treatment())
276 .add("ingress", ingressPoints())
277 .add("egress", egressPoint())
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700278 .add("filteredIngressCPs", filteredIngressPoints())
279 .add("filteredEgressCP", filteredEgressPoint())
Ray Milkey460f4022014-11-05 15:41:43 -0800280 .add("constraints", constraints())
Luca Prete670ac5d2017-02-03 15:55:43 -0800281 .add("resourceGroup", resourceGroup())
Brian O'Connorb876bf12014-10-02 14:59:37 -0700282 .toString();
283 }
284}