blob: 9197ce69234df6182228c8495d84f193acfe1d69 [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
Sho SHIMIZUf1fa96c2015-04-22 15:21:53 +090018import com.google.common.base.MoreObjects;
Brian O'Connorabafb502014-12-02 22:26:20 -080019import org.onosproject.core.ApplicationId;
20import org.onosproject.net.ConnectPoint;
Marc De Leenheer8c2caac2015-05-28 16:37:33 -070021import org.onosproject.net.OduSignalType;
weibitf32383b2014-10-22 10:17:31 -070022
Sho SHIMIZUf1fa96c2015-04-22 15:21:53 +090023import java.util.Collections;
24
Ray Milkeye076c792015-03-24 09:38:30 -070025import static com.google.common.base.Preconditions.checkNotNull;
Sho SHIMIZUd7d18002015-01-21 14:37:14 -080026
weibitf32383b2014-10-22 10:17:31 -070027/**
Marc De Leenheer1afa2a02015-05-13 09:18:07 -070028 * An optical layer intent for connectivity between two OCh ports.
29 * No traffic selector or traffic treatment are needed.
weibitf32383b2014-10-22 10:17:31 -070030 */
Ray Milkeybd4f0112015-03-02 17:07:09 -080031public final class OpticalConnectivityIntent extends Intent {
32 private final ConnectPoint src;
33 private final ConnectPoint dst;
Marc De Leenheer8c2caac2015-05-28 16:37:33 -070034 private final OduSignalType signalType;
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -070035 private final boolean isBidirectional;
weibitf32383b2014-10-22 10:17:31 -070036
37 /**
Thomas Vachuska4b420772014-10-30 16:46:17 -070038 * Creates an optical connectivity intent between the specified
39 * connection points.
weibitf32383b2014-10-22 10:17:31 -070040 *
Thomas Vachuska4b420772014-10-30 16:46:17 -070041 * @param appId application identification
Ray Milkey5b3717e2015-02-05 11:44:08 -080042 * @param key intent key
43 * @param src the source transponder port
44 * @param dst the destination transponder port
Brian O'Connor85cf4da2015-06-05 23:44:28 -070045 * @param signalType signal type
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -070046 * @param isBidirectional indicates if intent is unidirectional
Ray Milkey22083ae2015-03-25 13:02:07 -070047 * @param priority priority to use for flows from this intent
Ray Milkey5b3717e2015-02-05 11:44:08 -080048 */
Ray Milkeye076c792015-03-24 09:38:30 -070049 protected OpticalConnectivityIntent(ApplicationId appId,
Marc De Leenheer8c2caac2015-05-28 16:37:33 -070050 Key key,
51 ConnectPoint src,
52 ConnectPoint dst,
53 OduSignalType signalType,
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -070054 boolean isBidirectional,
Marc De Leenheer8c2caac2015-05-28 16:37:33 -070055 int priority) {
Ray Milkeye076c792015-03-24 09:38:30 -070056 super(appId, key, Collections.emptyList(), priority);
57 this.src = checkNotNull(src);
58 this.dst = checkNotNull(dst);
Marc De Leenheer8c2caac2015-05-28 16:37:33 -070059 this.signalType = checkNotNull(signalType);
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -070060 this.isBidirectional = isBidirectional;
weibitf32383b2014-10-22 10:17:31 -070061 }
62
Ray Milkeye076c792015-03-24 09:38:30 -070063 /**
64 * Returns a new optical connectivity intent builder.
65 *
66 * @return host to host intent builder
67 */
68 public static Builder builder() {
69 return new Builder();
70 }
71
72
73 /**
74 * Builder for optical connectivity intents.
75 */
76 public static class Builder extends Intent.Builder {
77 private ConnectPoint src;
78 private ConnectPoint dst;
Marc De Leenheer8c2caac2015-05-28 16:37:33 -070079 private OduSignalType signalType;
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -070080 private boolean isBidirectional;
Ray Milkeye076c792015-03-24 09:38:30 -070081
82 @Override
83 public Builder appId(ApplicationId appId) {
84 return (Builder) super.appId(appId);
85 }
86
87 @Override
88 public Builder key(Key key) {
89 return (Builder) super.key(key);
90 }
91
92 @Override
93 public Builder priority(int priority) {
94 return (Builder) super.priority(priority);
95 }
96
97 /**
98 * Sets the source for the intent that will be built.
99 *
100 * @param src source to use for built intent
101 * @return this builder
102 */
103 public Builder src(ConnectPoint src) {
104 this.src = src;
105 return this;
106 }
107
108 /**
109 * Sets the destination for the intent that will be built.
110 *
111 * @param dst dest to use for built intent
112 * @return this builder
113 */
114 public Builder dst(ConnectPoint dst) {
115 this.dst = dst;
116 return this;
117 }
118
119 /**
Marc De Leenheer8c2caac2015-05-28 16:37:33 -0700120 * Sets the ODU signal type for the intent that will be built.
121 *
122 * @param signalType ODU signal type
123 * @return this builder
124 */
125 public Builder signalType(OduSignalType signalType) {
126 this.signalType = signalType;
127 return this;
128 }
129
130 /**
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -0700131 * Sets the directionality of the intent.
132 *
133 * @param isBidirectional true if bidirectional, false if unidirectional
134 * @return this builder
135 */
136 public Builder bidirectional(boolean isBidirectional) {
137 this.isBidirectional = isBidirectional;
138 return this;
139 }
140
141 /**
Ray Milkeye076c792015-03-24 09:38:30 -0700142 * Builds an optical connectivity intent from the accumulated parameters.
143 *
144 * @return point to point intent
145 */
146 public OpticalConnectivityIntent build() {
147
148 return new OpticalConnectivityIntent(
149 appId,
150 key,
151 src,
152 dst,
Marc De Leenheer8c2caac2015-05-28 16:37:33 -0700153 signalType,
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -0700154 isBidirectional,
Ray Milkeye076c792015-03-24 09:38:30 -0700155 priority
156 );
157 }
158 }
Ray Milkey5b3717e2015-02-05 11:44:08 -0800159
weibitf32383b2014-10-22 10:17:31 -0700160 /**
161 * Constructor for serializer.
162 */
163 protected OpticalConnectivityIntent() {
164 super();
165 this.src = null;
166 this.dst = null;
Marc De Leenheer8c2caac2015-05-28 16:37:33 -0700167 this.signalType = null;
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -0700168 this.isBidirectional = false;
weibitf32383b2014-10-22 10:17:31 -0700169 }
170
171 /**
Thomas Vachuska4b420772014-10-30 16:46:17 -0700172 * Returns the source transponder port.
weibitf32383b2014-10-22 10:17:31 -0700173 *
Thomas Vachuska4b420772014-10-30 16:46:17 -0700174 * @return source transponder port
weibitf32383b2014-10-22 10:17:31 -0700175 */
Jonathan Hartc9d76732014-11-18 10:52:20 -0800176 public ConnectPoint getSrc() {
weibitf32383b2014-10-22 10:17:31 -0700177 return src;
178 }
179
180 /**
Thomas Vachuska4b420772014-10-30 16:46:17 -0700181 * Returns the destination transponder port.
weibitf32383b2014-10-22 10:17:31 -0700182 *
Thomas Vachuska4b420772014-10-30 16:46:17 -0700183 * @return source transponder port
weibitf32383b2014-10-22 10:17:31 -0700184 */
185 public ConnectPoint getDst() {
186 return dst;
187 }
Sho SHIMIZUf1fa96c2015-04-22 15:21:53 +0900188
Marc De Leenheer8c2caac2015-05-28 16:37:33 -0700189 /**
190 * Returns the ODU signal type.
191 *
192 * @return ODU signal type
193 */
194 public OduSignalType getSignalType() {
195 return signalType;
196 }
197
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -0700198 /**
199 * Returns the directionality of the intent.
200 *
201 * @return true if bidirectional, false if unidirectional
202 */
203 public boolean isBidirectional() {
204 return isBidirectional;
205 }
206
Sho SHIMIZUf1fa96c2015-04-22 15:21:53 +0900207 @Override
208 public String toString() {
209 return MoreObjects.toStringHelper(this)
210 .add("id", id())
211 .add("key", key())
212 .add("appId", appId())
213 .add("priority", priority())
214 .add("resources", resources())
215 .add("src", src)
216 .add("dst", dst)
Marc De Leenheer8c2caac2015-05-28 16:37:33 -0700217 .add("signalType", signalType)
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -0700218 .add("isBidirectional", isBidirectional)
Sho SHIMIZUf1fa96c2015-04-22 15:21:53 +0900219 .toString();
220 }
weibitf32383b2014-10-22 10:17:31 -0700221}