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