blob: 4548c44d21f95716606dd60b5183cbe069e7a56e [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.List;
19import java.util.Optional;
20
Brian O'Connor9476fa12015-06-25 15:17:17 -040021import com.google.common.annotations.Beta;
Michele Santuari4b6019e2014-12-19 11:31:45 +010022import org.onlab.packet.MplsLabel;
23import org.onosproject.core.ApplicationId;
24import org.onosproject.net.Path;
25import org.onosproject.net.flow.TrafficSelector;
26import org.onosproject.net.flow.TrafficTreatment;
27
Ray Milkeyebc5d222015-03-18 15:45:36 -070028import static com.google.common.base.Preconditions.checkNotNull;
29
Michele Santuari4b6019e2014-12-19 11:31:45 +010030
31/**
32 * Abstraction of explicit MPLS label-switched path.
33 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040034@Beta
Ray Milkeybd4f0112015-03-02 17:07:09 -080035public final class MplsPathIntent extends PathIntent {
Michele Santuari4b6019e2014-12-19 11:31:45 +010036
Ray Milkeybd4f0112015-03-02 17:07:09 -080037 private final Optional<MplsLabel> ingressLabel;
38 private final Optional<MplsLabel> egressLabel;
Michele Santuari4b6019e2014-12-19 11:31:45 +010039
40 /**
41 * Creates a new point-to-point intent with the supplied ingress/egress
42 * ports and using the specified explicit path.
43 *
44 * @param appId application identifier
ilhem fajjarib0a06842015-11-02 18:59:02 +010045 * @param key intent key
Michele Santuari4b6019e2014-12-19 11:31:45 +010046 * @param selector traffic selector
47 * @param treatment treatment
48 * @param path traversed links
49 * @param ingressLabel MPLS egress label
50 * @param egressLabel MPLS ingress label
Michele Santuari4b6019e2014-12-19 11:31:45 +010051 * @param constraints optional list of constraints
Ray Milkey50a9b722015-03-12 10:38:55 -070052 * @param priority priority to use for flows generated by this intent
Michele Santuari4b6019e2014-12-19 11:31:45 +010053 * @throws NullPointerException {@code path} is null
54 */
ilhem fajjarib0a06842015-11-02 18:59:02 +010055 private MplsPathIntent(ApplicationId appId, Key key, TrafficSelector selector,
Michele Santuari4b6019e2014-12-19 11:31:45 +010056 TrafficTreatment treatment, Path path, Optional<MplsLabel> ingressLabel,
Ray Milkey50a9b722015-03-12 10:38:55 -070057 Optional<MplsLabel> egressLabel, List<Constraint> constraints,
58 int priority) {
ilhem fajjarib0a06842015-11-02 18:59:02 +010059 super(appId, key, selector, treatment, path, constraints,
Ray Milkey50a9b722015-03-12 10:38:55 -070060 priority);
Michele Santuari4b6019e2014-12-19 11:31:45 +010061
Ray Milkeyebc5d222015-03-18 15:45:36 -070062 this.ingressLabel = checkNotNull(ingressLabel);
63 this.egressLabel = checkNotNull(egressLabel);
Michele Santuari4b6019e2014-12-19 11:31:45 +010064 }
65
66 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -070067 * Returns a new host to host intent builder.
68 *
69 * @return host to host intent builder
70 */
71 public static Builder builder() {
72 return new Builder();
73 }
74
75 /**
76 * Builder of a host to host intent.
77 */
78 public static final class Builder extends PathIntent.Builder {
79 private Optional<MplsLabel> ingressLabel = Optional.empty();
80 private Optional<MplsLabel> egressLabel = Optional.empty();
81
82 private Builder() {
83 // Hide constructor
84 }
85
86 @Override
87 public Builder appId(ApplicationId appId) {
88 return (Builder) super.appId(appId);
89 }
90
91 @Override
92 public Builder key(Key key) {
93 return (Builder) super.key(key);
94 }
95
96 @Override
97 public Builder selector(TrafficSelector selector) {
98 return (Builder) super.selector(selector);
99 }
100
101 @Override
102 public Builder treatment(TrafficTreatment treatment) {
103 return (Builder) super.treatment(treatment);
104 }
105
106 @Override
107 public Builder constraints(List<Constraint> constraints) {
108 return (Builder) super.constraints(constraints);
109 }
110
111 @Override
112 public Builder priority(int priority) {
113 return (Builder) super.priority(priority);
114 }
115
116 @Override
117 public Builder path(Path path) {
118 return (Builder) super.path(path);
119 }
120
121 /**
122 * Sets the ingress label of the intent that will be built.
123 *
124 * @param ingressLabel ingress label
125 * @return this builder
126 */
127 public Builder ingressLabel(Optional<MplsLabel> ingressLabel) {
128 this.ingressLabel = ingressLabel;
129 return this;
130 }
131
132 /**
133 * Sets the ingress label of the intent that will be built.
134 *
135 * @param egressLabel ingress label
136 * @return this builder
137 */
138 public Builder egressLabel(Optional<MplsLabel> egressLabel) {
139 this.egressLabel = egressLabel;
140 return this;
141 }
142
143
144 /**
145 * Builds a host to host intent from the accumulated parameters.
146 *
147 * @return point to point intent
148 */
149 public MplsPathIntent build() {
150
151 return new MplsPathIntent(
152 appId,
ilhem fajjarib0a06842015-11-02 18:59:02 +0100153 key,
Ray Milkeyebc5d222015-03-18 15:45:36 -0700154 selector,
155 treatment,
156 path,
157 ingressLabel,
158 egressLabel,
159 constraints,
160 priority
161 );
162 }
163 }
164
165
166 /**
Michele Santuari4b6019e2014-12-19 11:31:45 +0100167 * Returns the MPLS label which the ingress traffic should tagged.
168 *
169 * @return ingress MPLS label
170 */
171 public Optional<MplsLabel> ingressLabel() {
172 return ingressLabel;
173 }
174
175 /**
176 * Returns the MPLS label which the egress traffic should tagged.
177 *
178 * @return egress MPLS label
179 */
180 public Optional<MplsLabel> egressLabel() {
181 return egressLabel;
182 }
183
184}