blob: caa5fbb95f6d8ed7f614577a3987b1ceb799d98c [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
45 * @param selector traffic selector
46 * @param treatment treatment
47 * @param path traversed links
48 * @param ingressLabel MPLS egress label
49 * @param egressLabel MPLS ingress label
Michele Santuari4b6019e2014-12-19 11:31:45 +010050 * @param constraints optional list of constraints
Ray Milkey50a9b722015-03-12 10:38:55 -070051 * @param priority priority to use for flows generated by this intent
Michele Santuari4b6019e2014-12-19 11:31:45 +010052 * @throws NullPointerException {@code path} is null
53 */
Ray Milkeyebc5d222015-03-18 15:45:36 -070054 private MplsPathIntent(ApplicationId appId, TrafficSelector selector,
Michele Santuari4b6019e2014-12-19 11:31:45 +010055 TrafficTreatment treatment, Path path, Optional<MplsLabel> ingressLabel,
Ray Milkey50a9b722015-03-12 10:38:55 -070056 Optional<MplsLabel> egressLabel, List<Constraint> constraints,
57 int priority) {
Ray Milkeyc24cde32015-03-10 18:20:18 -070058 super(appId, selector, treatment, path, constraints,
Ray Milkey50a9b722015-03-12 10:38:55 -070059 priority);
Michele Santuari4b6019e2014-12-19 11:31:45 +010060
Ray Milkeyebc5d222015-03-18 15:45:36 -070061 this.ingressLabel = checkNotNull(ingressLabel);
62 this.egressLabel = checkNotNull(egressLabel);
Michele Santuari4b6019e2014-12-19 11:31:45 +010063 }
64
65 /**
Ray Milkeyebc5d222015-03-18 15:45:36 -070066 * Returns a new host to host intent builder.
67 *
68 * @return host to host intent builder
69 */
70 public static Builder builder() {
71 return new Builder();
72 }
73
74 /**
75 * Builder of a host to host intent.
76 */
77 public static final class Builder extends PathIntent.Builder {
78 private Optional<MplsLabel> ingressLabel = Optional.empty();
79 private Optional<MplsLabel> egressLabel = Optional.empty();
80
81 private Builder() {
82 // Hide constructor
83 }
84
85 @Override
86 public Builder appId(ApplicationId appId) {
87 return (Builder) super.appId(appId);
88 }
89
90 @Override
91 public Builder key(Key key) {
92 return (Builder) super.key(key);
93 }
94
95 @Override
96 public Builder selector(TrafficSelector selector) {
97 return (Builder) super.selector(selector);
98 }
99
100 @Override
101 public Builder treatment(TrafficTreatment treatment) {
102 return (Builder) super.treatment(treatment);
103 }
104
105 @Override
106 public Builder constraints(List<Constraint> constraints) {
107 return (Builder) super.constraints(constraints);
108 }
109
110 @Override
111 public Builder priority(int priority) {
112 return (Builder) super.priority(priority);
113 }
114
115 @Override
116 public Builder path(Path path) {
117 return (Builder) super.path(path);
118 }
119
120 /**
121 * Sets the ingress label of the intent that will be built.
122 *
123 * @param ingressLabel ingress label
124 * @return this builder
125 */
126 public Builder ingressLabel(Optional<MplsLabel> ingressLabel) {
127 this.ingressLabel = ingressLabel;
128 return this;
129 }
130
131 /**
132 * Sets the ingress label of the intent that will be built.
133 *
134 * @param egressLabel ingress label
135 * @return this builder
136 */
137 public Builder egressLabel(Optional<MplsLabel> egressLabel) {
138 this.egressLabel = egressLabel;
139 return this;
140 }
141
142
143 /**
144 * Builds a host to host intent from the accumulated parameters.
145 *
146 * @return point to point intent
147 */
148 public MplsPathIntent build() {
149
150 return new MplsPathIntent(
151 appId,
152 selector,
153 treatment,
154 path,
155 ingressLabel,
156 egressLabel,
157 constraints,
158 priority
159 );
160 }
161 }
162
163
164 /**
Michele Santuari4b6019e2014-12-19 11:31:45 +0100165 * Returns the MPLS label which the ingress traffic should tagged.
166 *
167 * @return ingress MPLS label
168 */
169 public Optional<MplsLabel> ingressLabel() {
170 return ingressLabel;
171 }
172
173 /**
174 * Returns the MPLS label which the egress traffic should tagged.
175 *
176 * @return egress MPLS label
177 */
178 public Optional<MplsLabel> egressLabel() {
179 return egressLabel;
180 }
181
182}