blob: d12702e3596353ce47e86ca924eb4a7d75eeac2d [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;
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 /**
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700170 * Sets the filtered ingress point of the single point to
171 * multi point intent that will be built.
Pier Ventre27d42572016-08-29 17:37:08 -0700172 *
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700173 * @param ingressPoint ingress connect point
Pier Ventre27d42572016-08-29 17:37:08 -0700174 * @return this builder
175 */
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700176 public Builder filteredIngressPoint(FilteredConnectPoint ingressPoint) {
177 this.ingressPoint = ingressPoint;
Pier Ventre27d42572016-08-29 17:37:08 -0700178 return this;
179 }
180
181 /**
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700182 * Sets the filtered egress points of the single point to
183 * multi point intent that will be built.
184 *
185 * @param egressPoints egress connect points
186 * @return this builder
187 */
188 public Builder filteredEgressPoints(Set<FilteredConnectPoint> egressPoints) {
189 this.egressPoints = ImmutableSet.copyOf(egressPoints);
190 return this;
191 }
192
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700193 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -0700194 * Builds a single point to multi point intent from the
195 * accumulated parameters.
196 *
197 * @return point to point intent
198 */
199 public SinglePointToMultiPointIntent build() {
200
201 return new SinglePointToMultiPointIntent(
202 appId,
203 key,
204 selector,
205 treatment,
206 ingressPoint,
207 egressPoints,
208 constraints,
Luca Prete670ac5d2017-02-03 15:55:43 -0800209 priority,
210 resourceGroup
Ray Milkeyebc5d222015-03-18 15:45:36 -0700211 );
212 }
Brian O'Connorb876bf12014-10-02 14:59:37 -0700213 }
214
215 /**
216 * Constructor for serializer.
217 */
218 protected SinglePointToMultiPointIntent() {
219 super();
tom85258ee2014-10-07 00:10:02 -0700220 this.ingressPoint = null;
221 this.egressPoints = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700222 }
223
224 /**
Michele Santuari4a338072014-11-05 18:38:55 +0100225 * Returns the port on which the ingress traffic should be connected to the
226 * egress.
Brian O'Connorb876bf12014-10-02 14:59:37 -0700227 *
228 * @return ingress port
229 */
tom85258ee2014-10-07 00:10:02 -0700230 public ConnectPoint ingressPoint() {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700231 return ingressPoint.connectPoint();
Brian O'Connorb876bf12014-10-02 14:59:37 -0700232 }
233
234 /**
235 * Returns the set of ports on which the traffic should egress.
236 *
237 * @return set of egress ports
238 */
tom85258ee2014-10-07 00:10:02 -0700239 public Set<ConnectPoint> egressPoints() {
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700240 return egressPoints.stream()
241 .map(FilteredConnectPoint::connectPoint)
242 .collect(Collectors.toSet());
Brian O'Connorb876bf12014-10-02 14:59:37 -0700243 }
244
Pier Ventre27d42572016-08-29 17:37:08 -0700245 /**
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700246 * Returns the filtered port on which the ingress traffic should be connected to the
247 * egress.
248 *
249 * @return ingress port
Pier Ventre27d42572016-08-29 17:37:08 -0700250 */
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700251 public FilteredConnectPoint filteredIngressPoint() {
252 return ingressPoint;
Pier Ventre27d42572016-08-29 17:37:08 -0700253 }
254
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700255 /**
256 * Returns the set of filtered ports on which the traffic should egress.
257 *
258 * @return set of egress ports
259 */
260 public Set<FilteredConnectPoint> filteredEgressPoints() {
261 return egressPoints;
262 }
263
264
Brian O'Connorb876bf12014-10-02 14:59:37 -0700265 @Override
Brian O'Connorb876bf12014-10-02 14:59:37 -0700266 public String toString() {
267 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700268 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800269 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700270 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700271 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800272 .add("resources", resources())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700273 .add("selector", selector())
274 .add("treatment", treatment())
275 .add("ingress", ingressPoint)
276 .add("egress", egressPoints)
Yi Tseng2a81c9d2016-09-14 10:14:24 -0700277 .add("filteredIngressCPs", filteredIngressPoint())
278 .add("filteredEgressCP", filteredEgressPoints())
Michele Santuari4a338072014-11-05 18:38:55 +0100279 .add("constraints", constraints())
Luca Prete670ac5d2017-02-03 15:55:43 -0800280 .add("resourceGroup", resourceGroup())
Brian O'Connorb876bf12014-10-02 14:59:37 -0700281 .toString();
282 }
283
284}