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