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