blob: b2e7a3ce0d2c014b76da975d054c38882192a06e [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2014-present Open Networking Foundation
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.intent;
weibitf32383b2014-10-22 10:17:31 -070017
Brian O'Connor9476fa12015-06-25 15:17:17 -040018import com.google.common.annotations.Beta;
Brian O'Connorabafb502014-12-02 22:26:20 -080019import org.onosproject.core.ApplicationId;
20import org.onosproject.net.ConnectPoint;
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070021import org.onosproject.net.OchSignal;
Marc De Leenheerd24420f2015-05-27 09:40:59 -070022import org.onosproject.net.OchSignalType;
Brian O'Connorabafb502014-12-02 22:26:20 -080023import org.onosproject.net.Path;
weibitf32383b2014-10-22 10:17:31 -070024
Ray Milkeye076c792015-03-24 09:38:30 -070025import com.google.common.base.MoreObjects;
26import com.google.common.collect.ImmutableSet;
Luca Prete670ac5d2017-02-03 15:55:43 -080027import org.onosproject.net.ResourceGroup;
weibitf32383b2014-10-22 10:17:31 -070028
Ray Milkeyebc5d222015-03-18 15:45:36 -070029import static com.google.common.base.Preconditions.checkNotNull;
30
Brian O'Connor9476fa12015-06-25 15:17:17 -040031/**
32 * An optical layer intent with explicitly selected path.
33 */
34@Beta
Ray Milkeybd4f0112015-03-02 17:07:09 -080035public final class OpticalPathIntent extends Intent {
Brian O'Connor086724e2014-10-23 15:47:32 -070036
37 private final ConnectPoint src;
38 private final ConnectPoint dst;
weibitf32383b2014-10-22 10:17:31 -070039 private final Path path;
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070040 private final OchSignal lambda;
Marc De Leenheerd24420f2015-05-27 09:40:59 -070041 private final OchSignalType signalType;
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -070042 private final boolean isBidirectional;
weibitf32383b2014-10-22 10:17:31 -070043
alessiod4a2b842019-04-30 18:43:17 +020044 public static final String REVERSE_PORT_ANNOTATION_KEY = "reverse-port";
45
Ray Milkeye076c792015-03-24 09:38:30 -070046 private OpticalPathIntent(ApplicationId appId,
47 Key key,
48 ConnectPoint src,
49 ConnectPoint dst,
50 Path path,
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070051 OchSignal lambda,
Marc De Leenheerd24420f2015-05-27 09:40:59 -070052 OchSignalType signalType,
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -070053 boolean isBidirectional,
Luca Prete670ac5d2017-02-03 15:55:43 -080054 int priority,
55 ResourceGroup resourceGroup) {
56 super(appId, key, ImmutableSet.copyOf(path.links()), priority, resourceGroup);
Ray Milkeyebc5d222015-03-18 15:45:36 -070057 this.src = checkNotNull(src);
58 this.dst = checkNotNull(dst);
59 this.path = checkNotNull(path);
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070060 this.lambda = checkNotNull(lambda);
Marc De Leenheerd24420f2015-05-27 09:40:59 -070061 this.signalType = checkNotNull(signalType);
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -070062 this.isBidirectional = isBidirectional;
weibitf32383b2014-10-22 10:17:31 -070063 }
64
weibit9e622ac2014-10-23 13:45:44 -070065 protected OpticalPathIntent() {
Brian O'Connor086724e2014-10-23 15:47:32 -070066 this.src = null;
67 this.dst = null;
weibitf32383b2014-10-22 10:17:31 -070068 this.path = null;
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070069 this.lambda = null;
Marc De Leenheerd24420f2015-05-27 09:40:59 -070070 this.signalType = null;
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -070071 this.isBidirectional = true;
weibitf32383b2014-10-22 10:17:31 -070072 }
73
Ray Milkeye076c792015-03-24 09:38:30 -070074 /**
75 * Returns a new optical connectivity intent builder.
76 *
77 * @return host to host intent builder
78 */
79 public static Builder builder() {
80 return new Builder();
81 }
82
83
84 /**
85 * Builder for optical path intents.
86 */
87 public static class Builder extends Intent.Builder {
88 private ConnectPoint src;
89 private ConnectPoint dst;
90 private Path path;
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070091 private OchSignal lambda;
Marc De Leenheerd24420f2015-05-27 09:40:59 -070092 private OchSignalType signalType;
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -070093 private boolean isBidirectional;
Yuta HIGUCHIb7a1f8e2017-03-01 17:11:52 -080094 private Key key;
Ray Milkeye076c792015-03-24 09:38:30 -070095
96 @Override
97 public Builder appId(ApplicationId appId) {
98 return (Builder) super.appId(appId);
99 }
100
101 @Override
102 public Builder key(Key key) {
103 return (Builder) super.key(key);
104 }
105
106 @Override
107 public Builder priority(int priority) {
108 return (Builder) super.priority(priority);
109 }
110
Luca Prete670ac5d2017-02-03 15:55:43 -0800111 @Override
112 public Builder resourceGroup(ResourceGroup resourceGroup) {
113 return (Builder) super.resourceGroup(resourceGroup);
114 }
115
Ray Milkeye076c792015-03-24 09:38:30 -0700116 /**
117 * Sets the source for the intent that will be built.
118 *
119 * @param src source to use for built intent
120 * @return this builder
121 */
122 public Builder src(ConnectPoint src) {
123 this.src = src;
124 return this;
125 }
126
127 /**
128 * Sets the destination for the intent that will be built.
129 *
130 * @param dst dest to use for built intent
131 * @return this builder
132 */
133 public Builder dst(ConnectPoint dst) {
134 this.dst = dst;
135 return this;
136 }
137
138 /**
139 * Sets the path for the intent that will be built.
140 *
141 * @param path path to use for built intent
142 * @return this builder
143 */
144 public Builder path(Path path) {
145 this.path = path;
146 return this;
147 }
148
149 /**
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700150 * Sets the optical channel (lambda) for the intent that will be built.
151 *
152 * @param lambda the optical channel
153 * @return this builder
154 */
155 public Builder lambda(OchSignal lambda) {
156 this.lambda = lambda;
157 return this;
158 }
159
160 /**
Marc De Leenheerd24420f2015-05-27 09:40:59 -0700161 * Sets the optical signal type for the intent that will be built.
162 *
163 * @param signalType the optical signal type
164 * @return this builder
165 */
166 public Builder signalType(OchSignalType signalType) {
167 this.signalType = signalType;
168 return this;
169 }
170
171 /**
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -0700172 * Sets the intent's direction.
Brian O'Connor85cf4da2015-06-05 23:44:28 -0700173 *
174 * @param isBidirectional indicates if intent is bidirectional
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -0700175 * @return this builder
176 */
177 public Builder bidirectional(boolean isBidirectional) {
178 this.isBidirectional = isBidirectional;
179 return this;
180 }
181
182 /**
Ray Milkeye076c792015-03-24 09:38:30 -0700183 * Builds an optical path intent from the accumulated parameters.
184 *
185 * @return optical path intent
186 */
187 public OpticalPathIntent build() {
188
189 return new OpticalPathIntent(
190 appId,
191 key,
192 src,
193 dst,
194 path,
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700195 lambda,
Marc De Leenheerd24420f2015-05-27 09:40:59 -0700196 signalType,
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -0700197 isBidirectional,
Luca Prete670ac5d2017-02-03 15:55:43 -0800198 priority,
199 resourceGroup
Ray Milkeye076c792015-03-24 09:38:30 -0700200 );
201 }
202 }
203
204
Brian O'Connor086724e2014-10-23 15:47:32 -0700205 public ConnectPoint src() {
206 return src;
207 }
208
209 public ConnectPoint dst() {
210 return dst;
211 }
212
weibitf32383b2014-10-22 10:17:31 -0700213 public Path path() {
214 return path;
215 }
weibitf32383b2014-10-22 10:17:31 -0700216
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700217 public OchSignal lambda() {
218 return lambda;
219 }
220
Marc De Leenheerd24420f2015-05-27 09:40:59 -0700221 public OchSignalType signalType() {
222 return signalType;
223 }
224
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -0700225 public boolean isBidirectional() {
226 return isBidirectional;
227 }
228
weibitf32383b2014-10-22 10:17:31 -0700229 @Override
weibitf32383b2014-10-22 10:17:31 -0700230 public String toString() {
231 return MoreObjects.toStringHelper(getClass())
232 .add("id", id())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800233 .add("appId", appId())
Ray Milkeyebc5d222015-03-18 15:45:36 -0700234 .add("key", key())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800235 .add("resources", resources())
Brian O'Connor086724e2014-10-23 15:47:32 -0700236 .add("ingressPort", src)
237 .add("egressPort", dst)
weibitf32383b2014-10-22 10:17:31 -0700238 .add("path", path)
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700239 .add("lambda", lambda)
Marc De Leenheerd24420f2015-05-27 09:40:59 -0700240 .add("signalType", signalType)
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -0700241 .add("isBidirectional", isBidirectional)
weibitf32383b2014-10-22 10:17:31 -0700242 .toString();
243 }
weibitf32383b2014-10-22 10:17:31 -0700244}