blob: 1a6ee30533c6516949e5980a86019e0b15c3bc77 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
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;
weibitf32383b2014-10-22 10:17:31 -070027
Ray Milkeyebc5d222015-03-18 15:45:36 -070028import static com.google.common.base.Preconditions.checkNotNull;
29
Brian O'Connor9476fa12015-06-25 15:17:17 -040030/**
31 * An optical layer intent with explicitly selected path.
32 */
33@Beta
Ray Milkeybd4f0112015-03-02 17:07:09 -080034public final class OpticalPathIntent extends Intent {
Brian O'Connor086724e2014-10-23 15:47:32 -070035
36 private final ConnectPoint src;
37 private final ConnectPoint dst;
weibitf32383b2014-10-22 10:17:31 -070038 private final Path path;
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070039 private final OchSignal lambda;
Marc De Leenheerd24420f2015-05-27 09:40:59 -070040 private final OchSignalType signalType;
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -070041 private final boolean isBidirectional;
weibitf32383b2014-10-22 10:17:31 -070042
Ray Milkeye076c792015-03-24 09:38:30 -070043 private OpticalPathIntent(ApplicationId appId,
44 Key key,
45 ConnectPoint src,
46 ConnectPoint dst,
47 Path path,
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070048 OchSignal lambda,
Marc De Leenheerd24420f2015-05-27 09:40:59 -070049 OchSignalType signalType,
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -070050 boolean isBidirectional,
Ray Milkeye076c792015-03-24 09:38:30 -070051 int priority) {
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070052 super(appId, key, ImmutableSet.copyOf(path.links()), priority);
Ray Milkeyebc5d222015-03-18 15:45:36 -070053 this.src = checkNotNull(src);
54 this.dst = checkNotNull(dst);
55 this.path = checkNotNull(path);
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070056 this.lambda = checkNotNull(lambda);
Marc De Leenheerd24420f2015-05-27 09:40:59 -070057 this.signalType = checkNotNull(signalType);
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -070058 this.isBidirectional = isBidirectional;
weibitf32383b2014-10-22 10:17:31 -070059 }
60
weibit9e622ac2014-10-23 13:45:44 -070061 protected OpticalPathIntent() {
Brian O'Connor086724e2014-10-23 15:47:32 -070062 this.src = null;
63 this.dst = null;
weibitf32383b2014-10-22 10:17:31 -070064 this.path = null;
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070065 this.lambda = null;
Marc De Leenheerd24420f2015-05-27 09:40:59 -070066 this.signalType = null;
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -070067 this.isBidirectional = true;
weibitf32383b2014-10-22 10:17:31 -070068 }
69
Ray Milkeye076c792015-03-24 09:38:30 -070070 /**
71 * Returns a new optical connectivity intent builder.
72 *
73 * @return host to host intent builder
74 */
75 public static Builder builder() {
76 return new Builder();
77 }
78
79
80 /**
81 * Builder for optical path intents.
82 */
83 public static class Builder extends Intent.Builder {
84 private ConnectPoint src;
85 private ConnectPoint dst;
86 private Path path;
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070087 private OchSignal lambda;
Marc De Leenheerd24420f2015-05-27 09:40:59 -070088 private OchSignalType signalType;
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -070089 private boolean isBidirectional;
Ray Milkeye076c792015-03-24 09:38:30 -070090 Key key;
91
92 @Override
93 public Builder appId(ApplicationId appId) {
94 return (Builder) super.appId(appId);
95 }
96
97 @Override
98 public Builder key(Key key) {
99 return (Builder) super.key(key);
100 }
101
102 @Override
103 public Builder priority(int priority) {
104 return (Builder) super.priority(priority);
105 }
106
107 /**
108 * Sets the source for the intent that will be built.
109 *
110 * @param src source to use for built intent
111 * @return this builder
112 */
113 public Builder src(ConnectPoint src) {
114 this.src = src;
115 return this;
116 }
117
118 /**
119 * Sets the destination for the intent that will be built.
120 *
121 * @param dst dest to use for built intent
122 * @return this builder
123 */
124 public Builder dst(ConnectPoint dst) {
125 this.dst = dst;
126 return this;
127 }
128
129 /**
130 * Sets the path for the intent that will be built.
131 *
132 * @param path path to use for built intent
133 * @return this builder
134 */
135 public Builder path(Path path) {
136 this.path = path;
137 return this;
138 }
139
140 /**
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700141 * Sets the optical channel (lambda) for the intent that will be built.
142 *
143 * @param lambda the optical channel
144 * @return this builder
145 */
146 public Builder lambda(OchSignal lambda) {
147 this.lambda = lambda;
148 return this;
149 }
150
151 /**
Marc De Leenheerd24420f2015-05-27 09:40:59 -0700152 * Sets the optical signal type for the intent that will be built.
153 *
154 * @param signalType the optical signal type
155 * @return this builder
156 */
157 public Builder signalType(OchSignalType signalType) {
158 this.signalType = signalType;
159 return this;
160 }
161
162 /**
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -0700163 * Sets the intent's direction.
Brian O'Connor85cf4da2015-06-05 23:44:28 -0700164 *
165 * @param isBidirectional indicates if intent is bidirectional
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -0700166 * @return this builder
167 */
168 public Builder bidirectional(boolean isBidirectional) {
169 this.isBidirectional = isBidirectional;
170 return this;
171 }
172
173 /**
Ray Milkeye076c792015-03-24 09:38:30 -0700174 * Builds an optical path intent from the accumulated parameters.
175 *
176 * @return optical path intent
177 */
178 public OpticalPathIntent build() {
179
180 return new OpticalPathIntent(
181 appId,
182 key,
183 src,
184 dst,
185 path,
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700186 lambda,
Marc De Leenheerd24420f2015-05-27 09:40:59 -0700187 signalType,
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -0700188 isBidirectional,
Ray Milkeye076c792015-03-24 09:38:30 -0700189 priority
190 );
191 }
192 }
193
194
Brian O'Connor086724e2014-10-23 15:47:32 -0700195 public ConnectPoint src() {
196 return src;
197 }
198
199 public ConnectPoint dst() {
200 return dst;
201 }
202
weibitf32383b2014-10-22 10:17:31 -0700203 public Path path() {
204 return path;
205 }
weibitf32383b2014-10-22 10:17:31 -0700206
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700207 public OchSignal lambda() {
208 return lambda;
209 }
210
Marc De Leenheerd24420f2015-05-27 09:40:59 -0700211 public OchSignalType signalType() {
212 return signalType;
213 }
214
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -0700215 public boolean isBidirectional() {
216 return isBidirectional;
217 }
218
weibitf32383b2014-10-22 10:17:31 -0700219 @Override
weibitf32383b2014-10-22 10:17:31 -0700220 public String toString() {
221 return MoreObjects.toStringHelper(getClass())
222 .add("id", id())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800223 .add("appId", appId())
Ray Milkeyebc5d222015-03-18 15:45:36 -0700224 .add("key", key())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800225 .add("resources", resources())
Brian O'Connor086724e2014-10-23 15:47:32 -0700226 .add("ingressPort", src)
227 .add("egressPort", dst)
weibitf32383b2014-10-22 10:17:31 -0700228 .add("path", path)
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700229 .add("lambda", lambda)
Marc De Leenheerd24420f2015-05-27 09:40:59 -0700230 .add("signalType", signalType)
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -0700231 .add("isBidirectional", isBidirectional)
weibitf32383b2014-10-22 10:17:31 -0700232 .toString();
233 }
weibitf32383b2014-10-22 10:17:31 -0700234}