blob: bf469dbe8eda535d4688ccae0d4f209aca443025 [file] [log] [blame]
Michele Santuari4b6019e2014-12-19 11:31:45 +01001package org.onosproject.net.intent;
2
Michele Santuari4b6019e2014-12-19 11:31:45 +01003import java.util.Collections;
4import java.util.List;
5import java.util.Optional;
6
Brian O'Connor9476fa12015-06-25 15:17:17 -04007import com.google.common.annotations.Beta;
Michele Santuari4b6019e2014-12-19 11:31:45 +01008import org.onlab.packet.MplsLabel;
9import org.onosproject.core.ApplicationId;
10import org.onosproject.net.ConnectPoint;
Michele Santuari4b6019e2014-12-19 11:31:45 +010011import org.onosproject.net.flow.TrafficSelector;
12import org.onosproject.net.flow.TrafficTreatment;
Michele Santuari4b6019e2014-12-19 11:31:45 +010013
14import com.google.common.base.MoreObjects;
Ray Milkeyebc5d222015-03-18 15:45:36 -070015
16import static com.google.common.base.Preconditions.checkArgument;
17import static com.google.common.base.Preconditions.checkNotNull;
Michele Santuari4b6019e2014-12-19 11:31:45 +010018
19
20/**
21 * Abstraction of MPLS label-switched connectivity.
22 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040023@Beta
Ray Milkeybd4f0112015-03-02 17:07:09 -080024public final class MplsIntent extends ConnectivityIntent {
Michele Santuari4b6019e2014-12-19 11:31:45 +010025
26 private final ConnectPoint ingressPoint;
27 private final Optional<MplsLabel> ingressLabel;
28 private final ConnectPoint egressPoint;
29 private final Optional<MplsLabel> egressLabel;
30
31 /**
Michele Santuari4b6019e2014-12-19 11:31:45 +010032 * Creates a new point-to-point intent with the supplied ingress/egress
33 * ports, labels and constraints.
34 *
35 * @param appId application identifier
36 * @param selector traffic selector
37 * @param treatment treatment
38 * @param ingressPoint ingress port
39 * @param ingressLabel ingress MPLS label
40 * @param egressPoint egress port
41 * @param egressLabel egress MPLS label
42 * @param constraints optional list of constraints
Ray Milkey50a9b722015-03-12 10:38:55 -070043 * @param priority priority to use for flows generated by this intent
Michele Santuari4b6019e2014-12-19 11:31:45 +010044 * @throws NullPointerException if {@code ingressPoint} or {@code egressPoints} is null.
45 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070046 private MplsIntent(ApplicationId appId,
47 Key key,
48 TrafficSelector selector,
49 TrafficTreatment treatment,
50 ConnectPoint ingressPoint,
51 Optional<MplsLabel> ingressLabel,
52 ConnectPoint egressPoint,
53 Optional<MplsLabel> egressLabel,
54 List<Constraint> constraints,
55 int priority) {
Michele Santuari4b6019e2014-12-19 11:31:45 +010056
Ray Milkeyebc5d222015-03-18 15:45:36 -070057 super(appId, key, Collections.emptyList(), selector, treatment, constraints,
Ray Milkey50a9b722015-03-12 10:38:55 -070058 priority);
Michele Santuari4b6019e2014-12-19 11:31:45 +010059
Ray Milkeyebc5d222015-03-18 15:45:36 -070060 this.ingressPoint = checkNotNull(ingressPoint);
61 this.ingressLabel = checkNotNull(ingressLabel);
62 this.egressPoint = checkNotNull(egressPoint);
63 this.egressLabel = checkNotNull(egressLabel);
Michele Santuari4b6019e2014-12-19 11:31:45 +010064
Ray Milkeyebc5d222015-03-18 15:45:36 -070065 checkArgument(!ingressPoint.equals(egressPoint),
66 "ingress and egress should be different (ingress: %s, egress: %s)",
67 ingressPoint, egressPoint);
Michele Santuari4b6019e2014-12-19 11:31:45 +010068 }
69
70 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -070071 * Returns a new MPLS intent builder. The application id,
72 * ingress point, egress point, ingress label and egress label are
73 * required fields. If they are not set by calls to the appropriate
74 * methods, an exception will be thrown.
75 *
76 * @return point to point builder
77 */
78 public static Builder builder() {
79 return new Builder();
80 }
81
82 /**
83 * Builder of an MPLS intent.
84 */
85 public static final class Builder extends ConnectivityIntent.Builder {
86 ConnectPoint ingressPoint;
87 ConnectPoint egressPoint;
88 Optional<MplsLabel> ingressLabel;
89 Optional<MplsLabel> egressLabel;
90
91 private Builder() {
92 // Hide constructor
93 }
94
95 @Override
96 public Builder appId(ApplicationId appId) {
97 return (Builder) super.appId(appId);
98 }
99
100 @Override
101 public Builder key(Key key) {
102 return (Builder) super.key(key);
103 }
104
105 @Override
106 public Builder selector(TrafficSelector selector) {
107 return (Builder) super.selector(selector);
108 }
109
110 @Override
111 public Builder treatment(TrafficTreatment treatment) {
112 return (Builder) super.treatment(treatment);
113 }
114
115 @Override
116 public Builder constraints(List<Constraint> constraints) {
117 return (Builder) super.constraints(constraints);
118 }
119
120 @Override
121 public Builder priority(int priority) {
122 return (Builder) super.priority(priority);
123 }
124
125 /**
126 * Sets the ingress point of the point to point intent that will be built.
127 *
128 * @param ingressPoint ingress connect point
129 * @return this builder
130 */
131 public Builder ingressPoint(ConnectPoint ingressPoint) {
132 this.ingressPoint = ingressPoint;
133 return this;
134 }
135
136 /**
137 * Sets the egress point of the point to point intent that will be built.
138 *
139 * @param egressPoint egress connect point
140 * @return this builder
141 */
142 public Builder egressPoint(ConnectPoint egressPoint) {
143 this.egressPoint = egressPoint;
144 return this;
145 }
146
147 /**
148 * Sets the ingress label of the intent that will be built.
149 *
150 * @param ingressLabel ingress label
151 * @return this builder
152 */
153 public Builder ingressLabel(Optional<MplsLabel> ingressLabel) {
154 this.ingressLabel = ingressLabel;
155 return this;
156 }
157
158 /**
159 * Sets the ingress label of the intent that will be built.
160 *
161 * @param egressLabel ingress label
162 * @return this builder
163 */
164 public Builder egressLabel(Optional<MplsLabel> egressLabel) {
165 this.egressLabel = egressLabel;
166 return this;
167 }
168
169 /**
170 * Builds a point to point intent from the accumulated parameters.
171 *
172 * @return point to point intent
173 */
174 public MplsIntent build() {
175
176 return new MplsIntent(
177 appId,
178 key,
179 selector,
180 treatment,
181 ingressPoint,
182 ingressLabel,
183 egressPoint,
184 egressLabel,
185 constraints,
186 priority
187 );
188 }
189 }
190
191
192
193 /**
Michele Santuari4b6019e2014-12-19 11:31:45 +0100194 * Constructor for serializer.
195 */
196 protected MplsIntent() {
197 super();
198 this.ingressPoint = null;
199 this.ingressLabel = null;
200 this.egressPoint = null;
201 this.egressLabel = null;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100202 }
203
204 /**
205 * Returns the port on which the ingress traffic should be connected to
206 * the egress.
207 *
208 * @return ingress switch port
209 */
210 public ConnectPoint ingressPoint() {
211 return ingressPoint;
212 }
213
214 /**
215 * Returns the port on which the traffic should egress.
216 *
217 * @return egress switch port
218 */
219 public ConnectPoint egressPoint() {
220 return egressPoint;
221 }
222
223
224 /**
225 * Returns the MPLS label which the ingress traffic should tagged.
226 *
227 * @return ingress MPLS label
228 */
229 public Optional<MplsLabel> ingressLabel() {
230 return ingressLabel;
231 }
232
233 /**
234 * Returns the MPLS label which the egress traffic should tagged.
235 *
236 * @return egress MPLS label
237 */
238 public Optional<MplsLabel> egressLabel() {
239 return egressLabel;
240 }
241
242 @Override
243 public String toString() {
244 return MoreObjects.toStringHelper(getClass())
245 .add("id", id())
246 .add("appId", appId())
Ray Milkeyebc5d222015-03-18 15:45:36 -0700247 .add("key", key())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700248 .add("priority", priority())
Michele Santuari4b6019e2014-12-19 11:31:45 +0100249 .add("selector", selector())
250 .add("treatment", treatment())
251 .add("ingressPoint", ingressPoint)
252 .add("ingressLabel", ingressLabel)
253 .add("egressPoint", egressPoint)
254 .add("egressLabel", egressLabel)
255 .add("constraints", constraints())
256 .toString();
257 }
258
259
260
261}