blob: 0c015430e04676076fd1341a7fb429e665c77877 [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;
Ray Milkeyebc5d222015-03-18 15:45:36 -070020import com.google.common.collect.ImmutableSet;
tom85258ee2014-10-07 00:10:02 -070021import com.google.common.collect.Sets;
Brian O'Connorabafb502014-12-02 22:26:20 -080022import org.onosproject.core.ApplicationId;
23import org.onosproject.net.ConnectPoint;
24import org.onosproject.net.flow.TrafficSelector;
25import org.onosproject.net.flow.TrafficTreatment;
Brian O'Connorb876bf12014-10-02 14:59:37 -070026
Sho SHIMIZUc3df36b2014-11-11 18:19:29 -080027import java.util.Collections;
Ray Milkey460f4022014-11-05 15:41:43 -080028import java.util.List;
tom85258ee2014-10-07 00:10:02 -070029import java.util.Set;
30
31import static com.google.common.base.Preconditions.checkArgument;
32import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connorb876bf12014-10-02 14:59:37 -070033
34/**
35 * Abstraction of multiple source to single destination connectivity intent.
36 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040037@Beta
Ray Milkeye6684082014-10-16 16:59:47 -070038public final class MultiPointToSinglePointIntent extends ConnectivityIntent {
Brian O'Connorb876bf12014-10-02 14:59:37 -070039
tom85258ee2014-10-07 00:10:02 -070040 private final Set<ConnectPoint> ingressPoints;
41 private final ConnectPoint egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070042
43 /**
44 * Creates a new multi-to-single point connectivity intent for the specified
Thomas Vachuskac96058a2014-10-20 23:00:16 -070045 * traffic selector and treatment.
Brian O'Connorb876bf12014-10-02 14:59:37 -070046 *
Thomas Vachuskac96058a2014-10-20 23:00:16 -070047 * @param appId application identifier
Jonathan Hartd0ba2172015-02-11 13:54:33 -080048 * @param key intent key
Ray Milkey460f4022014-11-05 15:41:43 -080049 * @param selector traffic selector
50 * @param treatment treatment
51 * @param ingressPoints set of ports from which ingress traffic originates
52 * @param egressPoint port to which traffic will egress
53 * @param constraints constraints to apply to the intent
Ray Milkeyc24cde32015-03-10 18:20:18 -070054 * @param priority priority to use for flows generated by this intent
Ray Milkey460f4022014-11-05 15:41:43 -080055 * @throws NullPointerException if {@code ingressPoints} or
56 * {@code egressPoint} is null.
57 * @throws IllegalArgumentException if the size of {@code ingressPoints} is
58 * not more than 1
59 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070060 private MultiPointToSinglePointIntent(ApplicationId appId,
Ray Milkey5b3717e2015-02-05 11:44:08 -080061 Key key,
Ray Milkey460f4022014-11-05 15:41:43 -080062 TrafficSelector selector,
63 TrafficTreatment treatment,
64 Set<ConnectPoint> ingressPoints,
65 ConnectPoint egressPoint,
Ray Milkeyc24cde32015-03-10 18:20:18 -070066 List<Constraint> constraints,
67 int priority) {
68 super(appId, key, Collections.emptyList(), selector, treatment, constraints,
69 priority);
Ray Milkey460f4022014-11-05 15:41:43 -080070
71 checkNotNull(ingressPoints);
72 checkArgument(!ingressPoints.isEmpty(), "Ingress point set cannot be empty");
Sho SHIMIZU2e660802014-11-21 14:55:32 -080073 checkNotNull(egressPoint);
74 checkArgument(!ingressPoints.contains(egressPoint),
75 "Set of ingresses should not contain egress (egress: %s)", egressPoint);
Ray Milkey460f4022014-11-05 15:41:43 -080076
77 this.ingressPoints = Sets.newHashSet(ingressPoints);
Sho SHIMIZU2e660802014-11-21 14:55:32 -080078 this.egressPoint = egressPoint;
Ray Milkey460f4022014-11-05 15:41:43 -080079 }
80
81 /**
Brian O'Connorb876bf12014-10-02 14:59:37 -070082 * Constructor for serializer.
83 */
84 protected MultiPointToSinglePointIntent() {
85 super();
tom85258ee2014-10-07 00:10:02 -070086 this.ingressPoints = null;
87 this.egressPoint = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -070088 }
89
90 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -070091 * Returns a new multi point to single point intent builder. The application id,
92 * ingress points and egress point are required fields. If they are
93 * not set by calls to the appropriate methods, an exception will
94 * be thrown.
95 *
96 * @return single point to multi point builder
97 */
98 public static Builder builder() {
99 return new Builder();
100 }
101
102 /**
Jonathan Hartb14221c2016-03-07 09:55:50 -0800103 * Creates a new builder pre-populated with the information in the given
104 * intent.
105 *
106 * @param intent initial intent
107 * @return intent builder
108 */
109 public static Builder builder(MultiPointToSinglePointIntent intent) {
110 return new Builder(intent);
111 }
112
113 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -0700114 * Builder of a multi point to single point intent.
115 */
116 public static final class Builder extends ConnectivityIntent.Builder {
117 Set<ConnectPoint> ingressPoints;
118 ConnectPoint egressPoint;
119
120 private Builder() {
121 // Hide constructor
122 }
123
Jonathan Hartb14221c2016-03-07 09:55:50 -0800124 /**
125 * Creates a new builder pre-populated with information from the given
126 * intent.
127 *
128 * @param intent initial intent
129 */
130 protected Builder(MultiPointToSinglePointIntent intent) {
131 super(intent);
132
133 this.ingressPoints(intent.ingressPoints())
134 .egressPoint(intent.egressPoint());
135 }
136
Ray Milkeyebc5d222015-03-18 15:45:36 -0700137 @Override
138 public Builder appId(ApplicationId appId) {
139 return (Builder) super.appId(appId);
140 }
141
142 @Override
143 public Builder key(Key key) {
144 return (Builder) super.key(key);
145 }
146
147 @Override
148 public Builder selector(TrafficSelector selector) {
149 return (Builder) super.selector(selector);
150 }
151
152 @Override
153 public Builder treatment(TrafficTreatment treatment) {
154 return (Builder) super.treatment(treatment);
155 }
156
157 @Override
158 public Builder constraints(List<Constraint> constraints) {
159 return (Builder) super.constraints(constraints);
160 }
161
162 @Override
163 public Builder priority(int priority) {
164 return (Builder) super.priority(priority);
165 }
166
167 /**
168 * Sets the ingress point of the single point to multi point intent
169 * that will be built.
170 *
171 * @param ingressPoints ingress connect points
172 * @return this builder
173 */
174 public Builder ingressPoints(Set<ConnectPoint> ingressPoints) {
175 this.ingressPoints = ImmutableSet.copyOf(ingressPoints);
176 return this;
177 }
178
179 /**
180 * Sets the egress point of the multi point to single point intent
181 * that will be built.
182 *
183 * @param egressPoint egress connect point
184 * @return this builder
185 */
186 public Builder egressPoint(ConnectPoint egressPoint) {
187 this.egressPoint = egressPoint;
188 return this;
189 }
190
191 /**
192 * Builds a multi point to single point intent from the
193 * accumulated parameters.
194 *
195 * @return point to point intent
196 */
197 public MultiPointToSinglePointIntent build() {
198
199 return new MultiPointToSinglePointIntent(
200 appId,
201 key,
202 selector,
203 treatment,
204 ingressPoints,
205 egressPoint,
206 constraints,
207 priority
208 );
209 }
210 }
211
212
213 /**
Brian O'Connorb876bf12014-10-02 14:59:37 -0700214 * Returns the set of ports on which ingress traffic should be connected to
215 * the egress port.
216 *
217 * @return set of ingress ports
218 */
tom85258ee2014-10-07 00:10:02 -0700219 public Set<ConnectPoint> ingressPoints() {
220 return ingressPoints;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700221 }
222
223 /**
224 * Returns the port on which the traffic should egress.
225 *
226 * @return egress port
227 */
tom85258ee2014-10-07 00:10:02 -0700228 public ConnectPoint egressPoint() {
229 return egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700230 }
231
232 @Override
Brian O'Connorb876bf12014-10-02 14:59:37 -0700233 public String toString() {
234 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700235 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800236 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700237 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700238 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800239 .add("resources", resources())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700240 .add("selector", selector())
241 .add("treatment", treatment())
242 .add("ingress", ingressPoints())
243 .add("egress", egressPoint())
Ray Milkey460f4022014-11-05 15:41:43 -0800244 .add("constraints", constraints())
Brian O'Connorb876bf12014-10-02 14:59:37 -0700245 .toString();
246 }
247}