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