Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
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; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 27 | |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 28 | import static com.google.common.base.Preconditions.checkNotNull; |
| 29 | |
Brian O'Connor | 9476fa1 | 2015-06-25 15:17:17 -0400 | [diff] [blame] | 30 | /** |
| 31 | * An optical layer intent with explicitly selected path. |
| 32 | */ |
| 33 | @Beta |
Ray Milkey | bd4f011 | 2015-03-02 17:07:09 -0800 | [diff] [blame] | 34 | public final class OpticalPathIntent extends Intent { |
Brian O'Connor | 086724e | 2014-10-23 15:47:32 -0700 | [diff] [blame] | 35 | |
| 36 | private final ConnectPoint src; |
| 37 | private final ConnectPoint dst; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 38 | private final Path path; |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 39 | private final OchSignal lambda; |
Marc De Leenheer | d24420f | 2015-05-27 09:40:59 -0700 | [diff] [blame] | 40 | private final OchSignalType signalType; |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 41 | private final boolean isBidirectional; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 42 | |
Ray Milkey | e076c79 | 2015-03-24 09:38:30 -0700 | [diff] [blame] | 43 | private OpticalPathIntent(ApplicationId appId, |
| 44 | Key key, |
| 45 | ConnectPoint src, |
| 46 | ConnectPoint dst, |
| 47 | Path path, |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 48 | OchSignal lambda, |
Marc De Leenheer | d24420f | 2015-05-27 09:40:59 -0700 | [diff] [blame] | 49 | OchSignalType signalType, |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 50 | boolean isBidirectional, |
Ray Milkey | e076c79 | 2015-03-24 09:38:30 -0700 | [diff] [blame] | 51 | int priority) { |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 52 | super(appId, key, ImmutableSet.copyOf(path.links()), priority); |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 53 | this.src = checkNotNull(src); |
| 54 | this.dst = checkNotNull(dst); |
| 55 | this.path = checkNotNull(path); |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 56 | this.lambda = checkNotNull(lambda); |
Marc De Leenheer | d24420f | 2015-05-27 09:40:59 -0700 | [diff] [blame] | 57 | this.signalType = checkNotNull(signalType); |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 58 | this.isBidirectional = isBidirectional; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 59 | } |
| 60 | |
weibit | 9e622ac | 2014-10-23 13:45:44 -0700 | [diff] [blame] | 61 | protected OpticalPathIntent() { |
Brian O'Connor | 086724e | 2014-10-23 15:47:32 -0700 | [diff] [blame] | 62 | this.src = null; |
| 63 | this.dst = null; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 64 | this.path = null; |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 65 | this.lambda = null; |
Marc De Leenheer | d24420f | 2015-05-27 09:40:59 -0700 | [diff] [blame] | 66 | this.signalType = null; |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 67 | this.isBidirectional = true; |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Ray Milkey | e076c79 | 2015-03-24 09:38:30 -0700 | [diff] [blame] | 70 | /** |
| 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 Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 87 | private OchSignal lambda; |
Marc De Leenheer | d24420f | 2015-05-27 09:40:59 -0700 | [diff] [blame] | 88 | private OchSignalType signalType; |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 89 | private boolean isBidirectional; |
Ray Milkey | e076c79 | 2015-03-24 09:38:30 -0700 | [diff] [blame] | 90 | 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 Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 141 | * 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 Leenheer | d24420f | 2015-05-27 09:40:59 -0700 | [diff] [blame] | 152 | * 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 Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 163 | * Sets the intent's direction. |
Brian O'Connor | 85cf4da | 2015-06-05 23:44:28 -0700 | [diff] [blame] | 164 | * |
| 165 | * @param isBidirectional indicates if intent is bidirectional |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 166 | * @return this builder |
| 167 | */ |
| 168 | public Builder bidirectional(boolean isBidirectional) { |
| 169 | this.isBidirectional = isBidirectional; |
| 170 | return this; |
| 171 | } |
| 172 | |
| 173 | /** |
Ray Milkey | e076c79 | 2015-03-24 09:38:30 -0700 | [diff] [blame] | 174 | * 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 Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 186 | lambda, |
Marc De Leenheer | d24420f | 2015-05-27 09:40:59 -0700 | [diff] [blame] | 187 | signalType, |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 188 | isBidirectional, |
Ray Milkey | e076c79 | 2015-03-24 09:38:30 -0700 | [diff] [blame] | 189 | priority |
| 190 | ); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | |
Brian O'Connor | 086724e | 2014-10-23 15:47:32 -0700 | [diff] [blame] | 195 | public ConnectPoint src() { |
| 196 | return src; |
| 197 | } |
| 198 | |
| 199 | public ConnectPoint dst() { |
| 200 | return dst; |
| 201 | } |
| 202 | |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 203 | public Path path() { |
| 204 | return path; |
| 205 | } |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 206 | |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 207 | public OchSignal lambda() { |
| 208 | return lambda; |
| 209 | } |
| 210 | |
Marc De Leenheer | d24420f | 2015-05-27 09:40:59 -0700 | [diff] [blame] | 211 | public OchSignalType signalType() { |
| 212 | return signalType; |
| 213 | } |
| 214 | |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 215 | public boolean isBidirectional() { |
| 216 | return isBidirectional; |
| 217 | } |
| 218 | |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 219 | @Override |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 220 | public String toString() { |
| 221 | return MoreObjects.toStringHelper(getClass()) |
| 222 | .add("id", id()) |
Jonathan Hart | 23b5a76 | 2015-01-26 14:47:33 -0800 | [diff] [blame] | 223 | .add("appId", appId()) |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 224 | .add("key", key()) |
Jonathan Hart | 23b5a76 | 2015-01-26 14:47:33 -0800 | [diff] [blame] | 225 | .add("resources", resources()) |
Brian O'Connor | 086724e | 2014-10-23 15:47:32 -0700 | [diff] [blame] | 226 | .add("ingressPort", src) |
| 227 | .add("egressPort", dst) |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 228 | .add("path", path) |
Marc De Leenheer | 1afa2a0 | 2015-05-13 09:18:07 -0700 | [diff] [blame] | 229 | .add("lambda", lambda) |
Marc De Leenheer | d24420f | 2015-05-27 09:40:59 -0700 | [diff] [blame] | 230 | .add("signalType", signalType) |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 231 | .add("isBidirectional", isBidirectional) |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 232 | .toString(); |
| 233 | } |
weibit | f32383b | 2014-10-22 10:17:31 -0700 | [diff] [blame] | 234 | } |