blob: 0dfb77f095582cbc547ea7ef14e944b93a302ed6 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 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'Connorabafb502014-12-02 22:26:20 -080018import org.onosproject.core.ApplicationId;
19import org.onosproject.net.ConnectPoint;
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070020import org.onosproject.net.OchSignal;
Marc De Leenheerd24420f2015-05-27 09:40:59 -070021import org.onosproject.net.OchSignalType;
Brian O'Connorabafb502014-12-02 22:26:20 -080022import org.onosproject.net.Path;
weibitf32383b2014-10-22 10:17:31 -070023
Ray Milkeye076c792015-03-24 09:38:30 -070024import com.google.common.base.MoreObjects;
25import com.google.common.collect.ImmutableSet;
weibitf32383b2014-10-22 10:17:31 -070026
Ray Milkeyebc5d222015-03-18 15:45:36 -070027import static com.google.common.base.Preconditions.checkNotNull;
28
Ray Milkeybd4f0112015-03-02 17:07:09 -080029public final class OpticalPathIntent extends Intent {
Brian O'Connor086724e2014-10-23 15:47:32 -070030
31 private final ConnectPoint src;
32 private final ConnectPoint dst;
weibitf32383b2014-10-22 10:17:31 -070033 private final Path path;
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070034 private final OchSignal lambda;
Marc De Leenheerd24420f2015-05-27 09:40:59 -070035 private final OchSignalType signalType;
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -070036 private final boolean isBidirectional;
weibitf32383b2014-10-22 10:17:31 -070037
Ray Milkeye076c792015-03-24 09:38:30 -070038 private OpticalPathIntent(ApplicationId appId,
39 Key key,
40 ConnectPoint src,
41 ConnectPoint dst,
42 Path path,
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070043 OchSignal lambda,
Marc De Leenheerd24420f2015-05-27 09:40:59 -070044 OchSignalType signalType,
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -070045 boolean isBidirectional,
Ray Milkeye076c792015-03-24 09:38:30 -070046 int priority) {
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070047 super(appId, key, ImmutableSet.copyOf(path.links()), priority);
Ray Milkeyebc5d222015-03-18 15:45:36 -070048 this.src = checkNotNull(src);
49 this.dst = checkNotNull(dst);
50 this.path = checkNotNull(path);
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070051 this.lambda = checkNotNull(lambda);
Marc De Leenheerd24420f2015-05-27 09:40:59 -070052 this.signalType = checkNotNull(signalType);
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -070053 this.isBidirectional = isBidirectional;
weibitf32383b2014-10-22 10:17:31 -070054 }
55
weibit9e622ac2014-10-23 13:45:44 -070056 protected OpticalPathIntent() {
Brian O'Connor086724e2014-10-23 15:47:32 -070057 this.src = null;
58 this.dst = null;
weibitf32383b2014-10-22 10:17:31 -070059 this.path = null;
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070060 this.lambda = null;
Marc De Leenheerd24420f2015-05-27 09:40:59 -070061 this.signalType = null;
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -070062 this.isBidirectional = true;
weibitf32383b2014-10-22 10:17:31 -070063 }
64
Ray Milkeye076c792015-03-24 09:38:30 -070065 /**
66 * Returns a new optical connectivity intent builder.
67 *
68 * @return host to host intent builder
69 */
70 public static Builder builder() {
71 return new Builder();
72 }
73
74
75 /**
76 * Builder for optical path intents.
77 */
78 public static class Builder extends Intent.Builder {
79 private ConnectPoint src;
80 private ConnectPoint dst;
81 private Path path;
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070082 private OchSignal lambda;
Marc De Leenheerd24420f2015-05-27 09:40:59 -070083 private OchSignalType signalType;
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -070084 private boolean isBidirectional;
Ray Milkeye076c792015-03-24 09:38:30 -070085 Key key;
86
87 @Override
88 public Builder appId(ApplicationId appId) {
89 return (Builder) super.appId(appId);
90 }
91
92 @Override
93 public Builder key(Key key) {
94 return (Builder) super.key(key);
95 }
96
97 @Override
98 public Builder priority(int priority) {
99 return (Builder) super.priority(priority);
100 }
101
102 /**
103 * Sets the source for the intent that will be built.
104 *
105 * @param src source to use for built intent
106 * @return this builder
107 */
108 public Builder src(ConnectPoint src) {
109 this.src = src;
110 return this;
111 }
112
113 /**
114 * Sets the destination for the intent that will be built.
115 *
116 * @param dst dest to use for built intent
117 * @return this builder
118 */
119 public Builder dst(ConnectPoint dst) {
120 this.dst = dst;
121 return this;
122 }
123
124 /**
125 * Sets the path for the intent that will be built.
126 *
127 * @param path path to use for built intent
128 * @return this builder
129 */
130 public Builder path(Path path) {
131 this.path = path;
132 return this;
133 }
134
135 /**
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700136 * Sets the optical channel (lambda) for the intent that will be built.
137 *
138 * @param lambda the optical channel
139 * @return this builder
140 */
141 public Builder lambda(OchSignal lambda) {
142 this.lambda = lambda;
143 return this;
144 }
145
146 /**
Marc De Leenheerd24420f2015-05-27 09:40:59 -0700147 * Sets the optical signal type for the intent that will be built.
148 *
149 * @param signalType the optical signal type
150 * @return this builder
151 */
152 public Builder signalType(OchSignalType signalType) {
153 this.signalType = signalType;
154 return this;
155 }
156
157 /**
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -0700158 * Sets the intent's direction.
159 * @return this builder
160 */
161 public Builder bidirectional(boolean isBidirectional) {
162 this.isBidirectional = isBidirectional;
163 return this;
164 }
165
166 /**
Ray Milkeye076c792015-03-24 09:38:30 -0700167 * Builds an optical path intent from the accumulated parameters.
168 *
169 * @return optical path intent
170 */
171 public OpticalPathIntent build() {
172
173 return new OpticalPathIntent(
174 appId,
175 key,
176 src,
177 dst,
178 path,
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700179 lambda,
Marc De Leenheerd24420f2015-05-27 09:40:59 -0700180 signalType,
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -0700181 isBidirectional,
Ray Milkeye076c792015-03-24 09:38:30 -0700182 priority
183 );
184 }
185 }
186
187
Brian O'Connor086724e2014-10-23 15:47:32 -0700188 public ConnectPoint src() {
189 return src;
190 }
191
192 public ConnectPoint dst() {
193 return dst;
194 }
195
weibitf32383b2014-10-22 10:17:31 -0700196 public Path path() {
197 return path;
198 }
weibitf32383b2014-10-22 10:17:31 -0700199
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700200 public OchSignal lambda() {
201 return lambda;
202 }
203
Marc De Leenheerd24420f2015-05-27 09:40:59 -0700204 public OchSignalType signalType() {
205 return signalType;
206 }
207
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -0700208 public boolean isBidirectional() {
209 return isBidirectional;
210 }
211
weibitf32383b2014-10-22 10:17:31 -0700212 @Override
weibitf32383b2014-10-22 10:17:31 -0700213 public String toString() {
214 return MoreObjects.toStringHelper(getClass())
215 .add("id", id())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800216 .add("appId", appId())
Ray Milkeyebc5d222015-03-18 15:45:36 -0700217 .add("key", key())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800218 .add("resources", resources())
Brian O'Connor086724e2014-10-23 15:47:32 -0700219 .add("ingressPort", src)
220 .add("egressPort", dst)
weibitf32383b2014-10-22 10:17:31 -0700221 .add("path", path)
Marc De Leenheer1afa2a02015-05-13 09:18:07 -0700222 .add("lambda", lambda)
Marc De Leenheerd24420f2015-05-27 09:40:59 -0700223 .add("signalType", signalType)
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -0700224 .add("isBidirectional", isBidirectional)
weibitf32383b2014-10-22 10:17:31 -0700225 .toString();
226 }
weibitf32383b2014-10-22 10:17:31 -0700227}