blob: 1ea58295ff6bfd80d0c66efe7db024fe05af923a [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.List;
4import java.util.Optional;
5
Michele Santuari4b6019e2014-12-19 11:31:45 +01006import org.onlab.packet.MplsLabel;
7import org.onosproject.core.ApplicationId;
8import org.onosproject.net.Path;
9import org.onosproject.net.flow.TrafficSelector;
10import org.onosproject.net.flow.TrafficTreatment;
11
Ray Milkeyebc5d222015-03-18 15:45:36 -070012import static com.google.common.base.Preconditions.checkNotNull;
13
Michele Santuari4b6019e2014-12-19 11:31:45 +010014
15/**
16 * Abstraction of explicit MPLS label-switched path.
17 */
18
Ray Milkeybd4f0112015-03-02 17:07:09 -080019public final class MplsPathIntent extends PathIntent {
Michele Santuari4b6019e2014-12-19 11:31:45 +010020
Ray Milkeybd4f0112015-03-02 17:07:09 -080021 private final Optional<MplsLabel> ingressLabel;
22 private final Optional<MplsLabel> egressLabel;
Michele Santuari4b6019e2014-12-19 11:31:45 +010023
24 /**
25 * Creates a new point-to-point intent with the supplied ingress/egress
26 * ports and using the specified explicit path.
27 *
28 * @param appId application identifier
29 * @param selector traffic selector
30 * @param treatment treatment
31 * @param path traversed links
32 * @param ingressLabel MPLS egress label
33 * @param egressLabel MPLS ingress label
Michele Santuari4b6019e2014-12-19 11:31:45 +010034 * @param constraints optional list of constraints
Ray Milkey50a9b722015-03-12 10:38:55 -070035 * @param priority priority to use for flows generated by this intent
Michele Santuari4b6019e2014-12-19 11:31:45 +010036 * @throws NullPointerException {@code path} is null
37 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070038 private MplsPathIntent(ApplicationId appId, TrafficSelector selector,
Michele Santuari4b6019e2014-12-19 11:31:45 +010039 TrafficTreatment treatment, Path path, Optional<MplsLabel> ingressLabel,
Ray Milkey50a9b722015-03-12 10:38:55 -070040 Optional<MplsLabel> egressLabel, List<Constraint> constraints,
41 int priority) {
Ray Milkeyc24cde32015-03-10 18:20:18 -070042 super(appId, selector, treatment, path, constraints,
Ray Milkey50a9b722015-03-12 10:38:55 -070043 priority);
Michele Santuari4b6019e2014-12-19 11:31:45 +010044
Ray Milkeyebc5d222015-03-18 15:45:36 -070045 this.ingressLabel = checkNotNull(ingressLabel);
46 this.egressLabel = checkNotNull(egressLabel);
Michele Santuari4b6019e2014-12-19 11:31:45 +010047 }
48
49 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -070050 * Returns a new host to host intent builder.
51 *
52 * @return host to host intent builder
53 */
54 public static Builder builder() {
55 return new Builder();
56 }
57
58 /**
59 * Builder of a host to host intent.
60 */
61 public static final class Builder extends PathIntent.Builder {
62 private Optional<MplsLabel> ingressLabel = Optional.empty();
63 private Optional<MplsLabel> egressLabel = Optional.empty();
64
65 private Builder() {
66 // Hide constructor
67 }
68
69 @Override
70 public Builder appId(ApplicationId appId) {
71 return (Builder) super.appId(appId);
72 }
73
74 @Override
75 public Builder key(Key key) {
76 return (Builder) super.key(key);
77 }
78
79 @Override
80 public Builder selector(TrafficSelector selector) {
81 return (Builder) super.selector(selector);
82 }
83
84 @Override
85 public Builder treatment(TrafficTreatment treatment) {
86 return (Builder) super.treatment(treatment);
87 }
88
89 @Override
90 public Builder constraints(List<Constraint> constraints) {
91 return (Builder) super.constraints(constraints);
92 }
93
94 @Override
95 public Builder priority(int priority) {
96 return (Builder) super.priority(priority);
97 }
98
99 @Override
100 public Builder path(Path path) {
101 return (Builder) super.path(path);
102 }
103
104 /**
105 * Sets the ingress label of the intent that will be built.
106 *
107 * @param ingressLabel ingress label
108 * @return this builder
109 */
110 public Builder ingressLabel(Optional<MplsLabel> ingressLabel) {
111 this.ingressLabel = ingressLabel;
112 return this;
113 }
114
115 /**
116 * Sets the ingress label of the intent that will be built.
117 *
118 * @param egressLabel ingress label
119 * @return this builder
120 */
121 public Builder egressLabel(Optional<MplsLabel> egressLabel) {
122 this.egressLabel = egressLabel;
123 return this;
124 }
125
126
127 /**
128 * Builds a host to host intent from the accumulated parameters.
129 *
130 * @return point to point intent
131 */
132 public MplsPathIntent build() {
133
134 return new MplsPathIntent(
135 appId,
136 selector,
137 treatment,
138 path,
139 ingressLabel,
140 egressLabel,
141 constraints,
142 priority
143 );
144 }
145 }
146
147
148 /**
Michele Santuari4b6019e2014-12-19 11:31:45 +0100149 * Returns the MPLS label which the ingress traffic should tagged.
150 *
151 * @return ingress MPLS label
152 */
153 public Optional<MplsLabel> ingressLabel() {
154 return ingressLabel;
155 }
156
157 /**
158 * Returns the MPLS label which the egress traffic should tagged.
159 *
160 * @return egress MPLS label
161 */
162 public Optional<MplsLabel> egressLabel() {
163 return egressLabel;
164 }
165
166}