Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -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 | */ |
| 16 | package org.onosproject.net.intent; |
| 17 | |
Brian O'Connor | 9476fa1 | 2015-06-25 15:17:17 -0400 | [diff] [blame] | 18 | import com.google.common.annotations.Beta; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 19 | import com.google.common.base.MoreObjects; |
| 20 | import org.onosproject.core.ApplicationId; |
Toru Furusawa | 72ee30c | 2016-01-08 13:29:04 -0800 | [diff] [blame] | 21 | import org.onosproject.net.CltSignalType; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 22 | import org.onosproject.net.ConnectPoint; |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 23 | import org.onosproject.net.ResourceGroup; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 24 | |
| 25 | import java.util.Collections; |
| 26 | |
| 27 | import static com.google.common.base.Preconditions.checkNotNull; |
| 28 | |
| 29 | /** |
| 30 | * An optical layer intent for circuits between two OduClt ports. |
| 31 | * No traffic selector or traffic treatment are needed. |
| 32 | */ |
Brian O'Connor | 9476fa1 | 2015-06-25 15:17:17 -0400 | [diff] [blame] | 33 | @Beta |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 34 | public class OpticalCircuitIntent extends Intent { |
| 35 | private final ConnectPoint src; |
| 36 | private final ConnectPoint dst; |
Toru Furusawa | 72ee30c | 2016-01-08 13:29:04 -0800 | [diff] [blame] | 37 | private final CltSignalType signalType; |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 38 | private final boolean isBidirectional; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 39 | |
| 40 | /** |
| 41 | * Creates an optical circuit intent between the specified |
| 42 | * connection points. |
| 43 | * |
| 44 | * @param appId application identification |
| 45 | * @param key intent key |
| 46 | * @param src the source transponder port |
| 47 | * @param dst the destination transponder port |
| 48 | * @param signalType ODU signal type |
Brian O'Connor | 85cf4da | 2015-06-05 23:44:28 -0700 | [diff] [blame] | 49 | * @param isBidirectional indicate if intent is bidirectional |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 50 | * @param priority priority to use for flows from this intent |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 51 | * @param resourceGroup resource group for this intent |
| 52 | */ |
| 53 | protected OpticalCircuitIntent(ApplicationId appId, Key key, ConnectPoint src, ConnectPoint dst, |
| 54 | CltSignalType signalType, boolean isBidirectional, int priority, |
| 55 | ResourceGroup resourceGroup) { |
| 56 | super(appId, key, Collections.emptyList(), priority, resourceGroup); |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 57 | this.src = checkNotNull(src); |
| 58 | this.dst = checkNotNull(dst); |
| 59 | this.signalType = checkNotNull(signalType); |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 60 | this.isBidirectional = isBidirectional; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Returns a new optical circuit 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 circuit intents. |
| 75 | */ |
| 76 | public static class Builder extends Intent.Builder { |
| 77 | private ConnectPoint src; |
| 78 | private ConnectPoint dst; |
Toru Furusawa | 72ee30c | 2016-01-08 13:29:04 -0800 | [diff] [blame] | 79 | private CltSignalType signalType; |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 80 | private boolean isBidirectional; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 81 | |
| 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 | |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 97 | @Override |
| 98 | public Builder resourceGroup(ResourceGroup resourceGroup) { |
| 99 | return (Builder) super.resourceGroup(resourceGroup); |
| 100 | } |
| 101 | |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 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 ODU signal type for the intent that will be built. |
| 126 | * |
| 127 | * @param signalType signal type to use for built intent |
| 128 | * @return this builder |
| 129 | */ |
Toru Furusawa | 72ee30c | 2016-01-08 13:29:04 -0800 | [diff] [blame] | 130 | public Builder signalType(CltSignalType signalType) { |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 131 | this.signalType = signalType; |
| 132 | return this; |
| 133 | } |
| 134 | |
| 135 | /** |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 136 | * Sets the directionality of the intent. |
| 137 | * |
| 138 | * @param isBidirectional true if bidirectional, false if unidirectional |
| 139 | * @return this builder |
| 140 | */ |
| 141 | public Builder bidirectional(boolean isBidirectional) { |
| 142 | this.isBidirectional = isBidirectional; |
| 143 | return this; |
| 144 | } |
| 145 | |
| 146 | /** |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 147 | * Builds an optical circuit intent from the accumulated parameters. |
| 148 | * |
| 149 | * @return point to point intent |
| 150 | */ |
| 151 | public OpticalCircuitIntent build() { |
| 152 | |
| 153 | return new OpticalCircuitIntent( |
| 154 | appId, |
| 155 | key, |
| 156 | src, |
| 157 | dst, |
| 158 | signalType, |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 159 | isBidirectional, |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 160 | priority, |
| 161 | resourceGroup |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 162 | ); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Constructor for serializer. |
| 168 | */ |
| 169 | protected OpticalCircuitIntent() { |
| 170 | super(); |
| 171 | this.src = null; |
| 172 | this.dst = null; |
| 173 | this.signalType = null; |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 174 | this.isBidirectional = false; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Returns the source transponder port. |
| 179 | * |
| 180 | * @return source transponder port |
| 181 | */ |
| 182 | public ConnectPoint getSrc() { |
| 183 | return src; |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * Returns the destination transponder port. |
| 188 | * |
| 189 | * @return source transponder port |
| 190 | */ |
| 191 | public ConnectPoint getDst() { |
| 192 | return dst; |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * Returns the ODU signal type. |
| 197 | * |
| 198 | * @return ODU signal type |
| 199 | */ |
Toru Furusawa | 72ee30c | 2016-01-08 13:29:04 -0800 | [diff] [blame] | 200 | public CltSignalType getSignalType() { |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 201 | return signalType; |
| 202 | } |
| 203 | |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 204 | /** |
| 205 | * Returns the directionality of the intent. |
| 206 | * |
| 207 | * @return true if bidirectional, false if unidirectional |
| 208 | */ |
| 209 | public boolean isBidirectional() { |
| 210 | return isBidirectional; |
| 211 | } |
| 212 | |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 213 | @Override |
| 214 | public String toString() { |
| 215 | return MoreObjects.toStringHelper(this) |
| 216 | .add("id", id()) |
| 217 | .add("key", key()) |
| 218 | .add("appId", appId()) |
| 219 | .add("priority", priority()) |
| 220 | .add("resources", resources()) |
| 221 | .add("src", src) |
| 222 | .add("dst", dst) |
| 223 | .add("signalType", signalType) |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 224 | .add("isBidirectional", isBidirectional) |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 225 | .add("resourceGroup", resourceGroup()) |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 226 | .toString(); |
| 227 | } |
| 228 | |
| 229 | } |