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