Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 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 | |
| 18 | import com.google.common.base.MoreObjects; |
| 19 | import org.onosproject.core.ApplicationId; |
| 20 | import org.onosproject.net.ConnectPoint; |
| 21 | import org.onosproject.net.OduCltPort; |
| 22 | |
| 23 | import java.util.Collections; |
| 24 | |
| 25 | import static com.google.common.base.Preconditions.checkNotNull; |
| 26 | |
| 27 | /** |
| 28 | * An optical layer intent for circuits between two OduClt ports. |
| 29 | * No traffic selector or traffic treatment are needed. |
| 30 | */ |
| 31 | public class OpticalCircuitIntent extends Intent { |
| 32 | private final ConnectPoint src; |
| 33 | private final ConnectPoint dst; |
| 34 | private final OduCltPort.SignalType signalType; |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 35 | private final boolean isBidirectional; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 36 | |
| 37 | /** |
| 38 | * Creates an optical circuit intent between the specified |
| 39 | * connection points. |
| 40 | * |
| 41 | * @param appId application identification |
| 42 | * @param key intent key |
| 43 | * @param src the source transponder port |
| 44 | * @param dst the destination transponder port |
| 45 | * @param signalType ODU signal type |
Brian O'Connor | 85cf4da | 2015-06-05 23:44:28 -0700 | [diff] [blame] | 46 | * @param isBidirectional indicate if intent is bidirectional |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 47 | * @param priority priority to use for flows from this intent |
| 48 | */ |
| 49 | protected OpticalCircuitIntent(ApplicationId appId, Key key, ConnectPoint src, ConnectPoint dst, |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 50 | OduCltPort.SignalType signalType, boolean isBidirectional, int priority) { |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 51 | super(appId, key, Collections.emptyList(), priority); |
| 52 | this.src = checkNotNull(src); |
| 53 | this.dst = checkNotNull(dst); |
| 54 | this.signalType = checkNotNull(signalType); |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 55 | this.isBidirectional = isBidirectional; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Returns a new optical circuit intent builder. |
| 60 | * |
| 61 | * @return host to host intent builder |
| 62 | */ |
| 63 | public static Builder builder() { |
| 64 | return new Builder(); |
| 65 | } |
| 66 | |
| 67 | |
| 68 | /** |
| 69 | * Builder for optical circuit intents. |
| 70 | */ |
| 71 | public static class Builder extends Intent.Builder { |
| 72 | private ConnectPoint src; |
| 73 | private ConnectPoint dst; |
| 74 | private OduCltPort.SignalType signalType; |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 75 | private boolean isBidirectional; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 76 | |
| 77 | @Override |
| 78 | public Builder appId(ApplicationId appId) { |
| 79 | return (Builder) super.appId(appId); |
| 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public Builder key(Key key) { |
| 84 | return (Builder) super.key(key); |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public Builder priority(int priority) { |
| 89 | return (Builder) super.priority(priority); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Sets the source for the intent that will be built. |
| 94 | * |
| 95 | * @param src source to use for built intent |
| 96 | * @return this builder |
| 97 | */ |
| 98 | public Builder src(ConnectPoint src) { |
| 99 | this.src = src; |
| 100 | return this; |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Sets the destination for the intent that will be built. |
| 105 | * |
| 106 | * @param dst dest to use for built intent |
| 107 | * @return this builder |
| 108 | */ |
| 109 | public Builder dst(ConnectPoint dst) { |
| 110 | this.dst = dst; |
| 111 | return this; |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Sets the ODU signal type for the intent that will be built. |
| 116 | * |
| 117 | * @param signalType signal type to use for built intent |
| 118 | * @return this builder |
| 119 | */ |
| 120 | public Builder signalType(OduCltPort.SignalType signalType) { |
| 121 | this.signalType = signalType; |
| 122 | return this; |
| 123 | } |
| 124 | |
| 125 | /** |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 126 | * Sets the directionality of the intent. |
| 127 | * |
| 128 | * @param isBidirectional true if bidirectional, false if unidirectional |
| 129 | * @return this builder |
| 130 | */ |
| 131 | public Builder bidirectional(boolean isBidirectional) { |
| 132 | this.isBidirectional = isBidirectional; |
| 133 | return this; |
| 134 | } |
| 135 | |
| 136 | /** |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 137 | * Builds an optical circuit intent from the accumulated parameters. |
| 138 | * |
| 139 | * @return point to point intent |
| 140 | */ |
| 141 | public OpticalCircuitIntent build() { |
| 142 | |
| 143 | return new OpticalCircuitIntent( |
| 144 | appId, |
| 145 | key, |
| 146 | src, |
| 147 | dst, |
| 148 | signalType, |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 149 | isBidirectional, |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 150 | priority |
| 151 | ); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Constructor for serializer. |
| 157 | */ |
| 158 | protected OpticalCircuitIntent() { |
| 159 | super(); |
| 160 | this.src = null; |
| 161 | this.dst = null; |
| 162 | this.signalType = null; |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 163 | this.isBidirectional = false; |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Returns the source transponder port. |
| 168 | * |
| 169 | * @return source transponder port |
| 170 | */ |
| 171 | public ConnectPoint getSrc() { |
| 172 | return src; |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Returns the destination transponder port. |
| 177 | * |
| 178 | * @return source transponder port |
| 179 | */ |
| 180 | public ConnectPoint getDst() { |
| 181 | return dst; |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * Returns the ODU signal type. |
| 186 | * |
| 187 | * @return ODU signal type |
| 188 | */ |
| 189 | public OduCltPort.SignalType getSignalType() { |
| 190 | return signalType; |
| 191 | } |
| 192 | |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 193 | /** |
| 194 | * Returns the directionality of the intent. |
| 195 | * |
| 196 | * @return true if bidirectional, false if unidirectional |
| 197 | */ |
| 198 | public boolean isBidirectional() { |
| 199 | return isBidirectional; |
| 200 | } |
| 201 | |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 202 | @Override |
| 203 | public String toString() { |
| 204 | return MoreObjects.toStringHelper(this) |
| 205 | .add("id", id()) |
| 206 | .add("key", key()) |
| 207 | .add("appId", appId()) |
| 208 | .add("priority", priority()) |
| 209 | .add("resources", resources()) |
| 210 | .add("src", src) |
| 211 | .add("dst", dst) |
| 212 | .add("signalType", signalType) |
Marc De Leenheer | 4a1c1fa | 2015-06-01 18:08:56 -0700 | [diff] [blame] | 213 | .add("isBidirectional", isBidirectional) |
Marc De Leenheer | 8c2caac | 2015-05-28 16:37:33 -0700 | [diff] [blame] | 214 | .toString(); |
| 215 | } |
| 216 | |
| 217 | } |