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