Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.intent; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 17 | |
Brian O'Connor | 9476fa1 | 2015-06-25 15:17:17 -0400 | [diff] [blame] | 18 | import com.google.common.annotations.Beta; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 19 | import org.onosproject.core.ApplicationId; |
| 20 | import org.onosproject.net.ConnectPoint; |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 21 | import org.onosproject.net.OchSignal; |
Marc De Leenheer | d24420f | 2015-05-27 09:40:59 -0700 | [diff] [blame] | 22 | import org.onosproject.net.OchSignalType; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 23 | import org.onosproject.net.Path; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 24 | |
Ray Milkey | e076c79 | 2015-03-24 09:38:30 -0700 | [diff] [blame] | 25 | import com.google.common.base.MoreObjects; |
| 26 | import com.google.common.collect.ImmutableSet; |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 27 | import org.onosproject.net.ResourceGroup; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 28 | |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 29 | import static com.google.common.base.Preconditions.checkNotNull; |
| 30 | |
Brian O'Connor | 9476fa1 | 2015-06-25 15:17:17 -0400 | [diff] [blame] | 31 | /** |
| 32 | * An optical layer intent with explicitly selected path. |
| 33 | */ |
| 34 | @Beta |
Ray Milkey | bd4f011 | 2015-03-02 17:07:09 -0800 | [diff] [blame] | 35 | public final class OpticalPathIntent extends Intent { |
Brian O'Connor | 086724e | 2014-10-23 15:47:32 -0700 | [diff] [blame] | 36 | |
| 37 | private final ConnectPoint src; |
| 38 | private final ConnectPoint dst; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 39 | private final Path path; |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 40 | private final OchSignal lambda; |
Marc De Leenheer | d24420f | 2015-05-27 09:40:59 -0700 | [diff] [blame] | 41 | private final OchSignalType signalType; |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 42 | private final boolean isBidirectional; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 43 | |
alessio | d4a2b84 | 2019-04-30 18:43:17 +0200 | [diff] [blame] | 44 | public static final String REVERSE_PORT_ANNOTATION_KEY = "reverse-port"; |
| 45 | |
Ray Milkey | e076c79 | 2015-03-24 09:38:30 -0700 | [diff] [blame] | 46 | private OpticalPathIntent(ApplicationId appId, |
| 47 | Key key, |
| 48 | ConnectPoint src, |
| 49 | ConnectPoint dst, |
| 50 | Path path, |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 51 | OchSignal lambda, |
Marc De Leenheer | d24420f | 2015-05-27 09:40:59 -0700 | [diff] [blame] | 52 | OchSignalType signalType, |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 53 | boolean isBidirectional, |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 54 | int priority, |
| 55 | ResourceGroup resourceGroup) { |
| 56 | super(appId, key, ImmutableSet.copyOf(path.links()), priority, resourceGroup); |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 57 | this.src = checkNotNull(src); |
| 58 | this.dst = checkNotNull(dst); |
| 59 | this.path = checkNotNull(path); |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 60 | this.lambda = checkNotNull(lambda); |
Marc De Leenheer | d24420f | 2015-05-27 09:40:59 -0700 | [diff] [blame] | 61 | this.signalType = checkNotNull(signalType); |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 62 | this.isBidirectional = isBidirectional; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 63 | } |
| 64 | |
weibit | 9e622ac | 2014-10-23 13:45:44 -0700 | [diff] [blame] | 65 | protected OpticalPathIntent() { |
Brian O'Connor | 086724e | 2014-10-23 15:47:32 -0700 | [diff] [blame] | 66 | this.src = null; |
| 67 | this.dst = null; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 68 | this.path = null; |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 69 | this.lambda = null; |
Marc De Leenheer | d24420f | 2015-05-27 09:40:59 -0700 | [diff] [blame] | 70 | this.signalType = null; |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 71 | this.isBidirectional = true; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Ray Milkey | e076c79 | 2015-03-24 09:38:30 -0700 | [diff] [blame] | 74 | /** |
| 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 Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 91 | private OchSignal lambda; |
Marc De Leenheer | d24420f | 2015-05-27 09:40:59 -0700 | [diff] [blame] | 92 | private OchSignalType signalType; |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 93 | private boolean isBidirectional; |
Yuta HIGUCHI | b7a1f8e | 2017-03-01 17:11:52 -0800 | [diff] [blame] | 94 | private Key key; |
Ray Milkey | e076c79 | 2015-03-24 09:38:30 -0700 | [diff] [blame] | 95 | |
| 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 Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 111 | @Override |
| 112 | public Builder resourceGroup(ResourceGroup resourceGroup) { |
| 113 | return (Builder) super.resourceGroup(resourceGroup); |
| 114 | } |
| 115 | |
Ray Milkey | e076c79 | 2015-03-24 09:38:30 -0700 | [diff] [blame] | 116 | /** |
| 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 Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 150 | * 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 Leenheer | d24420f | 2015-05-27 09:40:59 -0700 | [diff] [blame] | 161 | * 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 Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 172 | * Sets the intent's direction. |
Brian O'Connor | 85cf4da | 2015-06-05 23:44:28 -0700 | [diff] [blame] | 173 | * |
| 174 | * @param isBidirectional indicates if intent is bidirectional |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 175 | * @return this builder |
| 176 | */ |
| 177 | public Builder bidirectional(boolean isBidirectional) { |
| 178 | this.isBidirectional = isBidirectional; |
| 179 | return this; |
| 180 | } |
| 181 | |
| 182 | /** |
Ray Milkey | e076c79 | 2015-03-24 09:38:30 -0700 | [diff] [blame] | 183 | * 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 Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 195 | lambda, |
Marc De Leenheer | d24420f | 2015-05-27 09:40:59 -0700 | [diff] [blame] | 196 | signalType, |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 197 | isBidirectional, |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 198 | priority, |
| 199 | resourceGroup |
Ray Milkey | e076c79 | 2015-03-24 09:38:30 -0700 | [diff] [blame] | 200 | ); |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | |
Brian O'Connor | 086724e | 2014-10-23 15:47:32 -0700 | [diff] [blame] | 205 | public ConnectPoint src() { |
| 206 | return src; |
| 207 | } |
| 208 | |
| 209 | public ConnectPoint dst() { |
| 210 | return dst; |
| 211 | } |
| 212 | |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 213 | public Path path() { |
| 214 | return path; |
| 215 | } |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 216 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 217 | public OchSignal lambda() { |
| 218 | return lambda; |
| 219 | } |
| 220 | |
Marc De Leenheer | d24420f | 2015-05-27 09:40:59 -0700 | [diff] [blame] | 221 | public OchSignalType signalType() { |
| 222 | return signalType; |
| 223 | } |
| 224 | |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 225 | public boolean isBidirectional() { |
| 226 | return isBidirectional; |
| 227 | } |
| 228 | |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 229 | @Override |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 230 | public String toString() { |
| 231 | return MoreObjects.toStringHelper(getClass()) |
| 232 | .add("id", id()) |
Jonathan Hart | 23b5a76 | 2015-01-26 14:47:33 -0800 | [diff] [blame] | 233 | .add("appId", appId()) |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 234 | .add("key", key()) |
Jonathan Hart | 23b5a76 | 2015-01-26 14:47:33 -0800 | [diff] [blame] | 235 | .add("resources", resources()) |
Brian O'Connor | 086724e | 2014-10-23 15:47:32 -0700 | [diff] [blame] | 236 | .add("ingressPort", src) |
| 237 | .add("egressPort", dst) |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 238 | .add("path", path) |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 239 | .add("lambda", lambda) |
Marc De Leenheer | d24420f | 2015-05-27 09:40:59 -0700 | [diff] [blame] | 240 | .add("signalType", signalType) |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 241 | .add("isBidirectional", isBidirectional) |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 242 | .toString(); |
| 243 | } |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 244 | } |