blob: 1625f58be166b477ddaabef4db1781c8295d7de2 [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
7import org.onlab.packet.MplsLabel;
8import org.onosproject.core.ApplicationId;
9import org.onosproject.net.ConnectPoint;
Michele Santuari4b6019e2014-12-19 11:31:45 +010010import org.onosproject.net.flow.TrafficSelector;
11import org.onosproject.net.flow.TrafficTreatment;
Michele Santuari4b6019e2014-12-19 11:31:45 +010012
13import com.google.common.base.MoreObjects;
Ray Milkeyebc5d222015-03-18 15:45:36 -070014
15import static com.google.common.base.Preconditions.checkArgument;
16import static com.google.common.base.Preconditions.checkNotNull;
Michele Santuari4b6019e2014-12-19 11:31:45 +010017
18
19/**
20 * Abstraction of MPLS label-switched connectivity.
21 */
Ray Milkeybd4f0112015-03-02 17:07:09 -080022public final class MplsIntent extends ConnectivityIntent {
Michele Santuari4b6019e2014-12-19 11:31:45 +010023
24 private final ConnectPoint ingressPoint;
25 private final Optional<MplsLabel> ingressLabel;
26 private final ConnectPoint egressPoint;
27 private final Optional<MplsLabel> egressLabel;
28
29 /**
Michele Santuari4b6019e2014-12-19 11:31:45 +010030 * Creates a new point-to-point intent with the supplied ingress/egress
31 * ports, labels and constraints.
32 *
33 * @param appId application identifier
34 * @param selector traffic selector
35 * @param treatment treatment
36 * @param ingressPoint ingress port
37 * @param ingressLabel ingress MPLS label
38 * @param egressPoint egress port
39 * @param egressLabel egress MPLS label
40 * @param constraints optional list of constraints
Ray Milkey50a9b722015-03-12 10:38:55 -070041 * @param priority priority to use for flows generated by this intent
Michele Santuari4b6019e2014-12-19 11:31:45 +010042 * @throws NullPointerException if {@code ingressPoint} or {@code egressPoints} is null.
43 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070044 private MplsIntent(ApplicationId appId,
45 Key key,
46 TrafficSelector selector,
47 TrafficTreatment treatment,
48 ConnectPoint ingressPoint,
49 Optional<MplsLabel> ingressLabel,
50 ConnectPoint egressPoint,
51 Optional<MplsLabel> egressLabel,
52 List<Constraint> constraints,
53 int priority) {
Michele Santuari4b6019e2014-12-19 11:31:45 +010054
Ray Milkeyebc5d222015-03-18 15:45:36 -070055 super(appId, key, Collections.emptyList(), selector, treatment, constraints,
Ray Milkey50a9b722015-03-12 10:38:55 -070056 priority);
Michele Santuari4b6019e2014-12-19 11:31:45 +010057
Ray Milkeyebc5d222015-03-18 15:45:36 -070058 this.ingressPoint = checkNotNull(ingressPoint);
59 this.ingressLabel = checkNotNull(ingressLabel);
60 this.egressPoint = checkNotNull(egressPoint);
61 this.egressLabel = checkNotNull(egressLabel);
Michele Santuari4b6019e2014-12-19 11:31:45 +010062
Ray Milkeyebc5d222015-03-18 15:45:36 -070063 checkArgument(!ingressPoint.equals(egressPoint),
64 "ingress and egress should be different (ingress: %s, egress: %s)",
65 ingressPoint, egressPoint);
Michele Santuari4b6019e2014-12-19 11:31:45 +010066 }
67
68 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -070069 * Returns a new MPLS intent builder. The application id,
70 * ingress point, egress point, ingress label and egress label are
71 * required fields. If they are not set by calls to the appropriate
72 * methods, an exception will be thrown.
73 *
74 * @return point to point builder
75 */
76 public static Builder builder() {
77 return new Builder();
78 }
79
80 /**
81 * Builder of an MPLS intent.
82 */
83 public static final class Builder extends ConnectivityIntent.Builder {
84 ConnectPoint ingressPoint;
85 ConnectPoint egressPoint;
86 Optional<MplsLabel> ingressLabel;
87 Optional<MplsLabel> egressLabel;
88
89 private Builder() {
90 // Hide constructor
91 }
92
93 @Override
94 public Builder appId(ApplicationId appId) {
95 return (Builder) super.appId(appId);
96 }
97
98 @Override
99 public Builder key(Key key) {
100 return (Builder) super.key(key);
101 }
102
103 @Override
104 public Builder selector(TrafficSelector selector) {
105 return (Builder) super.selector(selector);
106 }
107
108 @Override
109 public Builder treatment(TrafficTreatment treatment) {
110 return (Builder) super.treatment(treatment);
111 }
112
113 @Override
114 public Builder constraints(List<Constraint> constraints) {
115 return (Builder) super.constraints(constraints);
116 }
117
118 @Override
119 public Builder priority(int priority) {
120 return (Builder) super.priority(priority);
121 }
122
123 /**
124 * Sets the ingress point of the point to point intent that will be built.
125 *
126 * @param ingressPoint ingress connect point
127 * @return this builder
128 */
129 public Builder ingressPoint(ConnectPoint ingressPoint) {
130 this.ingressPoint = ingressPoint;
131 return this;
132 }
133
134 /**
135 * Sets the egress point of the point to point intent that will be built.
136 *
137 * @param egressPoint egress connect point
138 * @return this builder
139 */
140 public Builder egressPoint(ConnectPoint egressPoint) {
141 this.egressPoint = egressPoint;
142 return this;
143 }
144
145 /**
146 * Sets the ingress label of the intent that will be built.
147 *
148 * @param ingressLabel ingress label
149 * @return this builder
150 */
151 public Builder ingressLabel(Optional<MplsLabel> ingressLabel) {
152 this.ingressLabel = ingressLabel;
153 return this;
154 }
155
156 /**
157 * Sets the ingress label of the intent that will be built.
158 *
159 * @param egressLabel ingress label
160 * @return this builder
161 */
162 public Builder egressLabel(Optional<MplsLabel> egressLabel) {
163 this.egressLabel = egressLabel;
164 return this;
165 }
166
167 /**
168 * Builds a point to point intent from the accumulated parameters.
169 *
170 * @return point to point intent
171 */
172 public MplsIntent build() {
173
174 return new MplsIntent(
175 appId,
176 key,
177 selector,
178 treatment,
179 ingressPoint,
180 ingressLabel,
181 egressPoint,
182 egressLabel,
183 constraints,
184 priority
185 );
186 }
187 }
188
189
190
191 /**
Michele Santuari4b6019e2014-12-19 11:31:45 +0100192 * Constructor for serializer.
193 */
194 protected MplsIntent() {
195 super();
196 this.ingressPoint = null;
197 this.ingressLabel = null;
198 this.egressPoint = null;
199 this.egressLabel = null;
Michele Santuari4b6019e2014-12-19 11:31:45 +0100200 }
201
202 /**
203 * Returns the port on which the ingress traffic should be connected to
204 * the egress.
205 *
206 * @return ingress switch port
207 */
208 public ConnectPoint ingressPoint() {
209 return ingressPoint;
210 }
211
212 /**
213 * Returns the port on which the traffic should egress.
214 *
215 * @return egress switch port
216 */
217 public ConnectPoint egressPoint() {
218 return egressPoint;
219 }
220
221
222 /**
223 * Returns the MPLS label which the ingress traffic should tagged.
224 *
225 * @return ingress MPLS label
226 */
227 public Optional<MplsLabel> ingressLabel() {
228 return ingressLabel;
229 }
230
231 /**
232 * Returns the MPLS label which the egress traffic should tagged.
233 *
234 * @return egress MPLS label
235 */
236 public Optional<MplsLabel> egressLabel() {
237 return egressLabel;
238 }
239
240 @Override
241 public String toString() {
242 return MoreObjects.toStringHelper(getClass())
243 .add("id", id())
244 .add("appId", appId())
Ray Milkeyebc5d222015-03-18 15:45:36 -0700245 .add("key", key())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700246 .add("priority", priority())
Michele Santuari4b6019e2014-12-19 11:31:45 +0100247 .add("selector", selector())
248 .add("treatment", treatment())
249 .add("ingressPoint", ingressPoint)
250 .add("ingressLabel", ingressLabel)
251 .add("egressPoint", egressPoint)
252 .add("egressLabel", egressLabel)
253 .add("constraints", constraints())
254 .toString();
255 }
256
257
258
259}