Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [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 | |
| 17 | package org.onosproject.incubator.net.virtual; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
| 20 | import com.google.common.base.MoreObjects; |
| 21 | import org.onosproject.core.ApplicationId; |
| 22 | import org.onosproject.net.ConnectPoint; |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 23 | import org.onosproject.net.ResourceGroup; |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 24 | import org.onosproject.net.flow.TrafficSelector; |
| 25 | import org.onosproject.net.flow.TrafficTreatment; |
| 26 | import org.onosproject.net.intent.ConnectivityIntent; |
| 27 | import org.onosproject.net.intent.Constraint; |
| 28 | import org.onosproject.net.intent.Key; |
| 29 | |
| 30 | import java.util.Collections; |
| 31 | import java.util.List; |
| 32 | |
| 33 | import static com.google.common.base.Preconditions.checkArgument; |
| 34 | import static com.google.common.base.Preconditions.checkNotNull; |
| 35 | |
| 36 | /** |
| 37 | * Abstraction of VirtualNetworkIntent connectivity. |
| 38 | */ |
| 39 | @Beta |
| 40 | public final class VirtualNetworkIntent extends ConnectivityIntent { |
| 41 | |
| 42 | private final NetworkId networkId; |
| 43 | private final ConnectPoint ingressPoint; |
| 44 | private final ConnectPoint egressPoint; |
| 45 | |
| 46 | private static final String NETWORK_ID_NULL = "Network ID cannot be null"; |
| 47 | |
| 48 | /** |
| 49 | * Returns a new point to point intent builder. The application id, |
| 50 | * ingress point and egress point are required fields. If they are |
| 51 | * not set by calls to the appropriate methods, an exception will |
| 52 | * be thrown. |
| 53 | * |
| 54 | * @return point to point builder |
| 55 | */ |
| 56 | public static VirtualNetworkIntent.Builder builder() { |
| 57 | return new VirtualNetworkIntent.Builder(); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Builder of a point to point intent. |
| 62 | */ |
| 63 | public static final class Builder extends ConnectivityIntent.Builder { |
| 64 | NetworkId networkId; |
| 65 | ConnectPoint ingressPoint; |
| 66 | ConnectPoint egressPoint; |
| 67 | |
| 68 | /** |
| 69 | * Builder constructor. |
| 70 | */ |
| 71 | private Builder() { |
| 72 | // Hide constructor |
| 73 | } |
| 74 | |
| 75 | @Override |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 76 | public Builder appId(ApplicationId appId) { |
| 77 | return (Builder) super.appId(appId); |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | @Override |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 81 | public Builder key(Key key) { |
| 82 | return (Builder) super.key(key); |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | @Override |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 86 | public Builder selector(TrafficSelector selector) { |
| 87 | return (Builder) super.selector(selector); |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | @Override |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 91 | public Builder treatment(TrafficTreatment treatment) { |
| 92 | return (Builder) super.treatment(treatment); |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | @Override |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 96 | public Builder constraints(List<Constraint> constraints) { |
| 97 | return (Builder) super.constraints(constraints); |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | @Override |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 101 | public Builder priority(int priority) { |
| 102 | return (Builder) super.priority(priority); |
| 103 | } |
| 104 | |
| 105 | @Override |
| 106 | public Builder resourceGroup(ResourceGroup resourceGroup) { |
| 107 | return (Builder) super.resourceGroup(resourceGroup); |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Sets the virtual network of the virtual network intent. |
| 112 | * |
| 113 | * @param networkId virtual network identifier |
| 114 | * @return this builder |
| 115 | */ |
| 116 | public VirtualNetworkIntent.Builder networkId(NetworkId networkId) { |
| 117 | this.networkId = networkId; |
| 118 | return this; |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Sets the ingress point of the virtual network intent that will be built. |
| 123 | * |
| 124 | * @param ingressPoint ingress connect point |
| 125 | * @return this builder |
| 126 | */ |
| 127 | public VirtualNetworkIntent.Builder ingressPoint(ConnectPoint ingressPoint) { |
| 128 | this.ingressPoint = ingressPoint; |
| 129 | return this; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Sets the egress point of the virtual network intent that will be built. |
| 134 | * |
| 135 | * @param egressPoint egress connect point |
| 136 | * @return this builder |
| 137 | */ |
| 138 | public VirtualNetworkIntent.Builder egressPoint(ConnectPoint egressPoint) { |
| 139 | this.egressPoint = egressPoint; |
| 140 | return this; |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Builds a virtual network intent from the accumulated parameters. |
| 145 | * |
| 146 | * @return virtual network intent |
| 147 | */ |
| 148 | public VirtualNetworkIntent build() { |
| 149 | |
| 150 | return new VirtualNetworkIntent( |
| 151 | networkId, |
| 152 | appId, |
| 153 | key, |
| 154 | selector, |
| 155 | treatment, |
| 156 | ingressPoint, |
| 157 | egressPoint, |
| 158 | constraints, |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 159 | priority, |
| 160 | resourceGroup |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 161 | ); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | |
| 166 | /** |
| 167 | * Creates a new point-to-point intent with the supplied ingress/egress |
| 168 | * ports and constraints. |
| 169 | * |
| 170 | * @param networkId virtual network identifier |
| 171 | * @param appId application identifier |
| 172 | * @param key key of the intent |
| 173 | * @param selector traffic selector |
| 174 | * @param treatment treatment |
| 175 | * @param ingressPoint ingress port |
| 176 | * @param egressPoint egress port |
| 177 | * @param constraints optional list of constraints |
| 178 | * @param priority priority to use for flows generated by this intent |
| 179 | * @throws NullPointerException if {@code ingressPoint} or |
| 180 | * {@code egressPoints} or {@code appId} is null. |
| 181 | */ |
| 182 | private VirtualNetworkIntent(NetworkId networkId, |
| 183 | ApplicationId appId, |
| 184 | Key key, |
| 185 | TrafficSelector selector, |
| 186 | TrafficTreatment treatment, |
| 187 | ConnectPoint ingressPoint, |
| 188 | ConnectPoint egressPoint, |
| 189 | List<Constraint> constraints, |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 190 | int priority, |
| 191 | ResourceGroup resourceGroup) { |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 192 | super(appId, key, Collections.emptyList(), selector, treatment, constraints, |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 193 | priority, resourceGroup); |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 194 | |
| 195 | checkNotNull(networkId, NETWORK_ID_NULL); |
| 196 | checkArgument(!ingressPoint.equals(egressPoint), |
| 197 | "ingress and egress should be different (ingress: %s, egress: %s)", ingressPoint, egressPoint); |
| 198 | |
| 199 | this.networkId = networkId; |
| 200 | this.ingressPoint = checkNotNull(ingressPoint); |
| 201 | this.egressPoint = checkNotNull(egressPoint); |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * Constructor for serializer. |
| 206 | */ |
| 207 | protected VirtualNetworkIntent() { |
| 208 | super(); |
| 209 | this.networkId = null; |
| 210 | this.ingressPoint = null; |
| 211 | this.egressPoint = null; |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * Returns the virtual network identifier. |
| 216 | * |
| 217 | * @return network identifier |
| 218 | */ |
| 219 | public NetworkId networkId() { |
| 220 | return networkId; |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * Returns the port on which the ingress traffic should be connected to |
| 225 | * the egress. |
| 226 | * |
| 227 | * @return ingress port |
| 228 | */ |
| 229 | public ConnectPoint ingressPoint() { |
| 230 | return ingressPoint; |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * Returns the port on which the traffic should egress. |
| 235 | * |
| 236 | * @return egress port |
| 237 | */ |
| 238 | public ConnectPoint egressPoint() { |
| 239 | return egressPoint; |
| 240 | } |
| 241 | |
| 242 | @Override |
| 243 | public String toString() { |
| 244 | return MoreObjects.toStringHelper(getClass()) |
| 245 | .add("networkId", networkId) |
| 246 | .add("id", id()) |
| 247 | .add("key", key()) |
| 248 | .add("appId", appId()) |
| 249 | .add("priority", priority()) |
| 250 | .add("resources", resources()) |
| 251 | .add("selector", selector()) |
| 252 | .add("treatment", treatment()) |
| 253 | .add("ingress", ingressPoint) |
| 254 | .add("egress", egressPoint) |
| 255 | .add("constraints", constraints()) |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 256 | .add("resourceGroup", resourceGroup()) |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 257 | .toString(); |
| 258 | } |
| 259 | |
| 260 | } |