blob: 3c3c45cee29f4195a08b62941de528c9affad289 [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
Brian O'Connor9476fa12015-06-25 15:17:17 -04006import com.google.common.annotations.Beta;
Michele Santuari4b6019e2014-12-19 11:31:45 +01007import org.onlab.packet.MplsLabel;
8import org.onosproject.core.ApplicationId;
9import org.onosproject.net.Path;
10import org.onosproject.net.flow.TrafficSelector;
11import org.onosproject.net.flow.TrafficTreatment;
12
Ray Milkeyebc5d222015-03-18 15:45:36 -070013import static com.google.common.base.Preconditions.checkNotNull;
14
Michele Santuari4b6019e2014-12-19 11:31:45 +010015
16/**
17 * Abstraction of explicit MPLS label-switched path.
18 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040019@Beta
Ray Milkeybd4f0112015-03-02 17:07:09 -080020public final class MplsPathIntent extends PathIntent {
Michele Santuari4b6019e2014-12-19 11:31:45 +010021
Ray Milkeybd4f0112015-03-02 17:07:09 -080022 private final Optional<MplsLabel> ingressLabel;
23 private final Optional<MplsLabel> egressLabel;
Michele Santuari4b6019e2014-12-19 11:31:45 +010024
25 /**
26 * Creates a new point-to-point intent with the supplied ingress/egress
27 * ports and using the specified explicit path.
28 *
29 * @param appId application identifier
30 * @param selector traffic selector
31 * @param treatment treatment
32 * @param path traversed links
33 * @param ingressLabel MPLS egress label
34 * @param egressLabel MPLS ingress label
Michele Santuari4b6019e2014-12-19 11:31:45 +010035 * @param constraints optional list of constraints
Ray Milkey50a9b722015-03-12 10:38:55 -070036 * @param priority priority to use for flows generated by this intent
Michele Santuari4b6019e2014-12-19 11:31:45 +010037 * @throws NullPointerException {@code path} is null
38 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070039 private MplsPathIntent(ApplicationId appId, TrafficSelector selector,
Michele Santuari4b6019e2014-12-19 11:31:45 +010040 TrafficTreatment treatment, Path path, Optional<MplsLabel> ingressLabel,
Ray Milkey50a9b722015-03-12 10:38:55 -070041 Optional<MplsLabel> egressLabel, List<Constraint> constraints,
42 int priority) {
Ray Milkeyc24cde32015-03-10 18:20:18 -070043 super(appId, selector, treatment, path, constraints,
Ray Milkey50a9b722015-03-12 10:38:55 -070044 priority);
Michele Santuari4b6019e2014-12-19 11:31:45 +010045
Ray Milkeyebc5d222015-03-18 15:45:36 -070046 this.ingressLabel = checkNotNull(ingressLabel);
47 this.egressLabel = checkNotNull(egressLabel);
Michele Santuari4b6019e2014-12-19 11:31:45 +010048 }
49
50 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -070051 * Returns a new host to host intent builder.
52 *
53 * @return host to host intent builder
54 */
55 public static Builder builder() {
56 return new Builder();
57 }
58
59 /**
60 * Builder of a host to host intent.
61 */
62 public static final class Builder extends PathIntent.Builder {
63 private Optional<MplsLabel> ingressLabel = Optional.empty();
64 private Optional<MplsLabel> egressLabel = Optional.empty();
65
66 private Builder() {
67 // Hide constructor
68 }
69
70 @Override
71 public Builder appId(ApplicationId appId) {
72 return (Builder) super.appId(appId);
73 }
74
75 @Override
76 public Builder key(Key key) {
77 return (Builder) super.key(key);
78 }
79
80 @Override
81 public Builder selector(TrafficSelector selector) {
82 return (Builder) super.selector(selector);
83 }
84
85 @Override
86 public Builder treatment(TrafficTreatment treatment) {
87 return (Builder) super.treatment(treatment);
88 }
89
90 @Override
91 public Builder constraints(List<Constraint> constraints) {
92 return (Builder) super.constraints(constraints);
93 }
94
95 @Override
96 public Builder priority(int priority) {
97 return (Builder) super.priority(priority);
98 }
99
100 @Override
101 public Builder path(Path path) {
102 return (Builder) super.path(path);
103 }
104
105 /**
106 * Sets the ingress label of the intent that will be built.
107 *
108 * @param ingressLabel ingress label
109 * @return this builder
110 */
111 public Builder ingressLabel(Optional<MplsLabel> ingressLabel) {
112 this.ingressLabel = ingressLabel;
113 return this;
114 }
115
116 /**
117 * Sets the ingress label of the intent that will be built.
118 *
119 * @param egressLabel ingress label
120 * @return this builder
121 */
122 public Builder egressLabel(Optional<MplsLabel> egressLabel) {
123 this.egressLabel = egressLabel;
124 return this;
125 }
126
127
128 /**
129 * Builds a host to host intent from the accumulated parameters.
130 *
131 * @return point to point intent
132 */
133 public MplsPathIntent build() {
134
135 return new MplsPathIntent(
136 appId,
137 selector,
138 treatment,
139 path,
140 ingressLabel,
141 egressLabel,
142 constraints,
143 priority
144 );
145 }
146 }
147
148
149 /**
Michele Santuari4b6019e2014-12-19 11:31:45 +0100150 * Returns the MPLS label which the ingress traffic should tagged.
151 *
152 * @return ingress MPLS label
153 */
154 public Optional<MplsLabel> ingressLabel() {
155 return ingressLabel;
156 }
157
158 /**
159 * Returns the MPLS label which the egress traffic should tagged.
160 *
161 * @return egress MPLS label
162 */
163 public Optional<MplsLabel> egressLabel() {
164 return egressLabel;
165 }
166
167}