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; |
| 35 | |
| 36 | /** |
| 37 | * Creates an optical circuit intent between the specified |
| 38 | * connection points. |
| 39 | * |
| 40 | * @param appId application identification |
| 41 | * @param key intent key |
| 42 | * @param src the source transponder port |
| 43 | * @param dst the destination transponder port |
| 44 | * @param signalType ODU signal type |
| 45 | * @param priority priority to use for flows from this intent |
| 46 | */ |
| 47 | protected OpticalCircuitIntent(ApplicationId appId, Key key, ConnectPoint src, ConnectPoint dst, |
| 48 | OduCltPort.SignalType signalType, int priority) { |
| 49 | super(appId, key, Collections.emptyList(), priority); |
| 50 | this.src = checkNotNull(src); |
| 51 | this.dst = checkNotNull(dst); |
| 52 | this.signalType = checkNotNull(signalType); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Returns a new optical circuit intent builder. |
| 57 | * |
| 58 | * @return host to host intent builder |
| 59 | */ |
| 60 | public static Builder builder() { |
| 61 | return new Builder(); |
| 62 | } |
| 63 | |
| 64 | |
| 65 | /** |
| 66 | * Builder for optical circuit intents. |
| 67 | */ |
| 68 | public static class Builder extends Intent.Builder { |
| 69 | private ConnectPoint src; |
| 70 | private ConnectPoint dst; |
| 71 | private OduCltPort.SignalType signalType; |
| 72 | |
| 73 | @Override |
| 74 | public Builder appId(ApplicationId appId) { |
| 75 | return (Builder) super.appId(appId); |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public Builder key(Key key) { |
| 80 | return (Builder) super.key(key); |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public Builder priority(int priority) { |
| 85 | return (Builder) super.priority(priority); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Sets the source for the intent that will be built. |
| 90 | * |
| 91 | * @param src source to use for built intent |
| 92 | * @return this builder |
| 93 | */ |
| 94 | public Builder src(ConnectPoint src) { |
| 95 | this.src = src; |
| 96 | return this; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Sets the destination for the intent that will be built. |
| 101 | * |
| 102 | * @param dst dest to use for built intent |
| 103 | * @return this builder |
| 104 | */ |
| 105 | public Builder dst(ConnectPoint dst) { |
| 106 | this.dst = dst; |
| 107 | return this; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Sets the ODU signal type for the intent that will be built. |
| 112 | * |
| 113 | * @param signalType signal type to use for built intent |
| 114 | * @return this builder |
| 115 | */ |
| 116 | public Builder signalType(OduCltPort.SignalType signalType) { |
| 117 | this.signalType = signalType; |
| 118 | return this; |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Builds an optical circuit intent from the accumulated parameters. |
| 123 | * |
| 124 | * @return point to point intent |
| 125 | */ |
| 126 | public OpticalCircuitIntent build() { |
| 127 | |
| 128 | return new OpticalCircuitIntent( |
| 129 | appId, |
| 130 | key, |
| 131 | src, |
| 132 | dst, |
| 133 | signalType, |
| 134 | priority |
| 135 | ); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Constructor for serializer. |
| 141 | */ |
| 142 | protected OpticalCircuitIntent() { |
| 143 | super(); |
| 144 | this.src = null; |
| 145 | this.dst = null; |
| 146 | this.signalType = null; |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Returns the source transponder port. |
| 151 | * |
| 152 | * @return source transponder port |
| 153 | */ |
| 154 | public ConnectPoint getSrc() { |
| 155 | return src; |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Returns the destination transponder port. |
| 160 | * |
| 161 | * @return source transponder port |
| 162 | */ |
| 163 | public ConnectPoint getDst() { |
| 164 | return dst; |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Returns the ODU signal type. |
| 169 | * |
| 170 | * @return ODU signal type |
| 171 | */ |
| 172 | public OduCltPort.SignalType getSignalType() { |
| 173 | return signalType; |
| 174 | } |
| 175 | |
| 176 | @Override |
| 177 | public String toString() { |
| 178 | return MoreObjects.toStringHelper(this) |
| 179 | .add("id", id()) |
| 180 | .add("key", key()) |
| 181 | .add("appId", appId()) |
| 182 | .add("priority", priority()) |
| 183 | .add("resources", resources()) |
| 184 | .add("src", src) |
| 185 | .add("dst", dst) |
| 186 | .add("signalType", signalType) |
| 187 | .toString(); |
| 188 | } |
| 189 | |
| 190 | } |