blob: 7df3c81ec77b4625920e045bd6c0c089ffcdc199 [file] [log] [blame]
Thomas Vachuska58de4162015-09-10 16:15:33 -07001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * 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
7 *
8 * 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.
15 */
Michele Santuari4b6019e2014-12-19 11:31:45 +010016package org.onosproject.net.intent;
17
Michele Santuari4b6019e2014-12-19 11:31:45 +010018import java.util.Collections;
19import java.util.List;
20import java.util.Optional;
21
Brian O'Connor9476fa12015-06-25 15:17:17 -040022import com.google.common.annotations.Beta;
Michele Santuari4b6019e2014-12-19 11:31:45 +010023import org.onlab.packet.MplsLabel;
24import org.onosproject.core.ApplicationId;
25import org.onosproject.net.ConnectPoint;
Michele Santuari4b6019e2014-12-19 11:31:45 +010026import org.onosproject.net.flow.TrafficSelector;
27import org.onosproject.net.flow.TrafficTreatment;
Michele Santuari4b6019e2014-12-19 11:31:45 +010028
29import com.google.common.base.MoreObjects;
Ray Milkeyebc5d222015-03-18 15:45:36 -070030
31import static com.google.common.base.Preconditions.checkArgument;
32import static com.google.common.base.Preconditions.checkNotNull;
Michele Santuari4b6019e2014-12-19 11:31:45 +010033
34
35/**
36 * Abstraction of MPLS label-switched connectivity.
37 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040038@Beta
Ray Milkeybd4f0112015-03-02 17:07:09 -080039public final class MplsIntent extends ConnectivityIntent {
Michele Santuari4b6019e2014-12-19 11:31:45 +010040
41 private final ConnectPoint ingressPoint;
42 private final Optional<MplsLabel> ingressLabel;
43 private final ConnectPoint egressPoint;
44 private final Optional<MplsLabel> egressLabel;
45
46 /**
Michele Santuari4b6019e2014-12-19 11:31:45 +010047 * Creates a new point-to-point intent with the supplied ingress/egress
48 * ports, labels and constraints.
49 *
50 * @param appId application identifier
51 * @param selector traffic selector
52 * @param treatment treatment
53 * @param ingressPoint ingress port
54 * @param ingressLabel ingress MPLS label
55 * @param egressPoint egress port
56 * @param egressLabel egress MPLS label
57 * @param constraints optional list of constraints
Ray Milkey50a9b722015-03-12 10:38:55 -070058 * @param priority priority to use for flows generated by this intent
Michele Santuari4b6019e2014-12-19 11:31:45 +010059 * @throws NullPointerException if {@code ingressPoint} or {@code egressPoints} is null.
60 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070061 private MplsIntent(ApplicationId appId,
62 Key key,
63 TrafficSelector selector,
64 TrafficTreatment treatment,
65 ConnectPoint ingressPoint,
66 Optional<MplsLabel> ingressLabel,
67 ConnectPoint egressPoint,
68 Optional<MplsLabel> egressLabel,
69 List<Constraint> constraints,
70 int priority) {
Michele Santuari4b6019e2014-12-19 11:31:45 +010071
Ray Milkeyebc5d222015-03-18 15:45:36 -070072 super(appId, key, Collections.emptyList(), selector, treatment, constraints,
Ray Milkey50a9b722015-03-12 10:38:55 -070073 priority);
Michele Santuari4b6019e2014-12-19 11:31:45 +010074
Ray Milkeyebc5d222015-03-18 15:45:36 -070075 this.ingressPoint = checkNotNull(ingressPoint);
76 this.ingressLabel = checkNotNull(ingressLabel);
77 this.egressPoint = checkNotNull(egressPoint);
78 this.egressLabel = checkNotNull(egressLabel);
Michele Santuari4b6019e2014-12-19 11:31:45 +010079
Ray Milkeyebc5d222015-03-18 15:45:36 -070080 checkArgument(!ingressPoint.equals(egressPoint),
81 "ingress and egress should be different (ingress: %s, egress: %s)",
82 ingressPoint, egressPoint);
Michele Santuari4b6019e2014-12-19 11:31:45 +010083 }
84
85 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -070086 * Returns a new MPLS intent builder. The application id,
87 * ingress point, egress point, ingress label and egress label are
88 * required fields. If they are not set by calls to the appropriate
89 * methods, an exception will be thrown.
90 *
91 * @return point to point builder
92 */
93 public static Builder builder() {
94 return new Builder();
95 }
96
97 /**
98 * Builder of an MPLS intent.
99 */
100 public static final class Builder extends ConnectivityIntent.Builder {
101 ConnectPoint ingressPoint;
102 ConnectPoint egressPoint;
103 Optional<MplsLabel> ingressLabel;
104 Optional<MplsLabel> egressLabel;
105
106 private Builder() {
107 // Hide constructor
108 }
109
110 @Override
111 public Builder appId(ApplicationId appId) {
112 return (Builder) super.appId(appId);
113 }
114
115 @Override
116 public Builder key(Key key) {
117 return (Builder) super.key(key);
118 }
119
120 @Override
121 public Builder selector(TrafficSelector selector) {
122 return (Builder) super.selector(selector);
123 }
124
125 @Override
126 public Builder treatment(TrafficTreatment treatment) {
127 return (Builder) super.treatment(treatment);
128 }
129
130 @Override
131 public Builder constraints(List<Constraint> constraints) {
132 return (Builder) super.constraints(constraints);
133 }
134
135 @Override
136 public Builder priority(int priority) {
137 return (Builder) super.priority(priority);
138 }
139
140 /**
141 * Sets the ingress point of the point to point intent that will be built.
142 *
143 * @param ingressPoint ingress connect point
144 * @return this builder
145 */
146 public Builder ingressPoint(ConnectPoint ingressPoint) {
147 this.ingressPoint = ingressPoint;
148 return this;
149 }
150
151 /**
152 * Sets the egress point of the point to point intent that will be built.
153 *
154 * @param egressPoint egress connect point
155 * @return this builder
156 */
157 public Builder egressPoint(ConnectPoint egressPoint) {
158 this.egressPoint = egressPoint;
159 return this;
160 }
161
162 /**
163 * Sets the ingress label of the intent that will be built.
164 *
165 * @param ingressLabel ingress label
166 * @return this builder
167 */
168 public Builder ingressLabel(Optional<MplsLabel> ingressLabel) {
169 this.ingressLabel = ingressLabel;
170 return this;
171 }
172
173 /**
174 * Sets the ingress label of the intent that will be built.
175 *
176 * @param egressLabel ingress label
177 * @return this builder
178 */
179 public Builder egressLabel(Optional<MplsLabel> egressLabel) {
180 this.egressLabel = egressLabel;
181 return this;
182 }
183
184 /**
185 * Builds a point to point intent from the accumulated parameters.
186 *
187 * @return point to point intent
188 */
189 public MplsIntent build() {
190
191 return new MplsIntent(
192 appId,
193 key,
194 selector,
195 treatment,
196 ingressPoint,
197 ingressLabel,
198 egressPoint,
199 egressLabel,
200 constraints,
201 priority
202 );
203 }
204 }
205
206
207
208 /**
Michele Santuari4b6019e2014-12-19 11:31:45 +0100209 * Constructor for serializer.
210 */
211 protected MplsIntent() {
212 super();
213 this.ingressPoint = null;
214 this.ingressLabel = null;
215 this.egressPoint = null;
216 this.egressLabel = null;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100217 }
218
219 /**
220 * Returns the port on which the ingress traffic should be connected to
221 * the egress.
222 *
223 * @return ingress switch port
224 */
225 public ConnectPoint ingressPoint() {
226 return ingressPoint;
227 }
228
229 /**
230 * Returns the port on which the traffic should egress.
231 *
232 * @return egress switch port
233 */
234 public ConnectPoint egressPoint() {
235 return egressPoint;
236 }
237
238
239 /**
240 * Returns the MPLS label which the ingress traffic should tagged.
241 *
242 * @return ingress MPLS label
243 */
244 public Optional<MplsLabel> ingressLabel() {
245 return ingressLabel;
246 }
247
248 /**
249 * Returns the MPLS label which the egress traffic should tagged.
250 *
251 * @return egress MPLS label
252 */
253 public Optional<MplsLabel> egressLabel() {
254 return egressLabel;
255 }
256
257 @Override
258 public String toString() {
259 return MoreObjects.toStringHelper(getClass())
260 .add("id", id())
261 .add("appId", appId())
Ray Milkeyebc5d222015-03-18 15:45:36 -0700262 .add("key", key())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700263 .add("priority", priority())
Michele Santuari4b6019e2014-12-19 11:31:45 +0100264 .add("selector", selector())
265 .add("treatment", treatment())
266 .add("ingressPoint", ingressPoint)
267 .add("ingressLabel", ingressLabel)
268 .add("egressPoint", egressPoint)
269 .add("egressLabel", egressLabel)
270 .add("constraints", constraints())
271 .toString();
272 }
273
274
275
276}