blob: f5c1c43bb496e95f11a4fd129a47dbc8c5be9576 [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.
Michele Santuari6096acd2016-02-09 17:00:37 +010037 *
38 * @deprecated in Goldeneye Release, in favour of encapsulation
39 * constraint {@link org.onosproject.net.intent.constraint.EncapsulationConstraint}
40 * with Encasulation type {@link org.onosproject.net.EncapsulationType} MPLS.
41 *
Michele Santuari4b6019e2014-12-19 11:31:45 +010042 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040043@Beta
Michele Santuari6096acd2016-02-09 17:00:37 +010044@Deprecated
Ray Milkeybd4f0112015-03-02 17:07:09 -080045public final class MplsIntent extends ConnectivityIntent {
Michele Santuari4b6019e2014-12-19 11:31:45 +010046
47 private final ConnectPoint ingressPoint;
48 private final Optional<MplsLabel> ingressLabel;
49 private final ConnectPoint egressPoint;
50 private final Optional<MplsLabel> egressLabel;
51
52 /**
Michele Santuari4b6019e2014-12-19 11:31:45 +010053 * Creates a new point-to-point intent with the supplied ingress/egress
54 * ports, labels and constraints.
55 *
56 * @param appId application identifier
57 * @param selector traffic selector
58 * @param treatment treatment
59 * @param ingressPoint ingress port
60 * @param ingressLabel ingress MPLS label
61 * @param egressPoint egress port
62 * @param egressLabel egress MPLS label
63 * @param constraints optional list of constraints
Ray Milkey50a9b722015-03-12 10:38:55 -070064 * @param priority priority to use for flows generated by this intent
Michele Santuari4b6019e2014-12-19 11:31:45 +010065 * @throws NullPointerException if {@code ingressPoint} or {@code egressPoints} is null.
66 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070067 private MplsIntent(ApplicationId appId,
68 Key key,
69 TrafficSelector selector,
70 TrafficTreatment treatment,
71 ConnectPoint ingressPoint,
72 Optional<MplsLabel> ingressLabel,
73 ConnectPoint egressPoint,
74 Optional<MplsLabel> egressLabel,
75 List<Constraint> constraints,
76 int priority) {
Michele Santuari4b6019e2014-12-19 11:31:45 +010077
Ray Milkeyebc5d222015-03-18 15:45:36 -070078 super(appId, key, Collections.emptyList(), selector, treatment, constraints,
Ray Milkey50a9b722015-03-12 10:38:55 -070079 priority);
Michele Santuari4b6019e2014-12-19 11:31:45 +010080
Ray Milkeyebc5d222015-03-18 15:45:36 -070081 this.ingressPoint = checkNotNull(ingressPoint);
82 this.ingressLabel = checkNotNull(ingressLabel);
83 this.egressPoint = checkNotNull(egressPoint);
84 this.egressLabel = checkNotNull(egressLabel);
Michele Santuari4b6019e2014-12-19 11:31:45 +010085
Ray Milkeyebc5d222015-03-18 15:45:36 -070086 checkArgument(!ingressPoint.equals(egressPoint),
87 "ingress and egress should be different (ingress: %s, egress: %s)",
88 ingressPoint, egressPoint);
Michele Santuari4b6019e2014-12-19 11:31:45 +010089 }
90
91 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -070092 * Returns a new MPLS intent builder. The application id,
93 * ingress point, egress point, ingress label and egress label are
94 * required fields. If they are not set by calls to the appropriate
95 * methods, an exception will be thrown.
96 *
97 * @return point to point builder
98 */
99 public static Builder builder() {
100 return new Builder();
101 }
102
103 /**
104 * Builder of an MPLS intent.
105 */
106 public static final class Builder extends ConnectivityIntent.Builder {
107 ConnectPoint ingressPoint;
108 ConnectPoint egressPoint;
109 Optional<MplsLabel> ingressLabel;
110 Optional<MplsLabel> egressLabel;
111
112 private Builder() {
113 // Hide constructor
114 }
115
116 @Override
117 public Builder appId(ApplicationId appId) {
118 return (Builder) super.appId(appId);
119 }
120
121 @Override
122 public Builder key(Key key) {
123 return (Builder) super.key(key);
124 }
125
126 @Override
127 public Builder selector(TrafficSelector selector) {
128 return (Builder) super.selector(selector);
129 }
130
131 @Override
132 public Builder treatment(TrafficTreatment treatment) {
133 return (Builder) super.treatment(treatment);
134 }
135
136 @Override
137 public Builder constraints(List<Constraint> constraints) {
138 return (Builder) super.constraints(constraints);
139 }
140
141 @Override
142 public Builder priority(int priority) {
143 return (Builder) super.priority(priority);
144 }
145
146 /**
147 * Sets the ingress point of the point to point intent that will be built.
148 *
149 * @param ingressPoint ingress connect point
150 * @return this builder
151 */
152 public Builder ingressPoint(ConnectPoint ingressPoint) {
153 this.ingressPoint = ingressPoint;
154 return this;
155 }
156
157 /**
158 * Sets the egress point of the point to point intent that will be built.
159 *
160 * @param egressPoint egress connect point
161 * @return this builder
162 */
163 public Builder egressPoint(ConnectPoint egressPoint) {
164 this.egressPoint = egressPoint;
165 return this;
166 }
167
168 /**
169 * Sets the ingress label of the intent that will be built.
170 *
171 * @param ingressLabel ingress label
172 * @return this builder
173 */
174 public Builder ingressLabel(Optional<MplsLabel> ingressLabel) {
175 this.ingressLabel = ingressLabel;
176 return this;
177 }
178
179 /**
180 * Sets the ingress label of the intent that will be built.
181 *
182 * @param egressLabel ingress label
183 * @return this builder
184 */
185 public Builder egressLabel(Optional<MplsLabel> egressLabel) {
186 this.egressLabel = egressLabel;
187 return this;
188 }
189
190 /**
191 * Builds a point to point intent from the accumulated parameters.
192 *
193 * @return point to point intent
194 */
195 public MplsIntent build() {
196
197 return new MplsIntent(
198 appId,
199 key,
200 selector,
201 treatment,
202 ingressPoint,
203 ingressLabel,
204 egressPoint,
205 egressLabel,
206 constraints,
207 priority
208 );
209 }
210 }
211
212
213
214 /**
Michele Santuari4b6019e2014-12-19 11:31:45 +0100215 * Constructor for serializer.
216 */
217 protected MplsIntent() {
218 super();
219 this.ingressPoint = null;
220 this.ingressLabel = null;
221 this.egressPoint = null;
222 this.egressLabel = null;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100223 }
224
225 /**
226 * Returns the port on which the ingress traffic should be connected to
227 * the egress.
228 *
229 * @return ingress switch port
230 */
231 public ConnectPoint ingressPoint() {
232 return ingressPoint;
233 }
234
235 /**
236 * Returns the port on which the traffic should egress.
237 *
238 * @return egress switch port
239 */
240 public ConnectPoint egressPoint() {
241 return egressPoint;
242 }
243
244
245 /**
246 * Returns the MPLS label which the ingress traffic should tagged.
247 *
248 * @return ingress MPLS label
249 */
250 public Optional<MplsLabel> ingressLabel() {
251 return ingressLabel;
252 }
253
254 /**
255 * Returns the MPLS label which the egress traffic should tagged.
256 *
257 * @return egress MPLS label
258 */
259 public Optional<MplsLabel> egressLabel() {
260 return egressLabel;
261 }
262
263 @Override
264 public String toString() {
265 return MoreObjects.toStringHelper(getClass())
266 .add("id", id())
267 .add("appId", appId())
Ray Milkeyebc5d222015-03-18 15:45:36 -0700268 .add("key", key())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700269 .add("priority", priority())
Michele Santuari4b6019e2014-12-19 11:31:45 +0100270 .add("selector", selector())
271 .add("treatment", treatment())
272 .add("ingressPoint", ingressPoint)
273 .add("ingressLabel", ingressLabel)
274 .add("egressPoint", egressPoint)
275 .add("egressLabel", egressLabel)
276 .add("constraints", constraints())
277 .toString();
278 }
279
280
281
282}