Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -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 | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 15 | */ |
Pier Ventre | 647138f | 2016-08-26 17:32:44 -0700 | [diff] [blame] | 16 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 17 | package org.onosproject.net.intent; |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 18 | |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 19 | import java.util.List; |
| 20 | import java.util.Map; |
| 21 | import java.util.Set; |
| 22 | |
Brian O'Connor | 9476fa1 | 2015-06-25 15:17:17 -0400 | [diff] [blame] | 23 | import com.google.common.annotations.Beta; |
Pier Ventre | 647138f | 2016-08-26 17:32:44 -0700 | [diff] [blame] | 24 | import com.google.common.collect.ImmutableMap; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 25 | import org.onosproject.core.ApplicationId; |
| 26 | import org.onosproject.net.ConnectPoint; |
| 27 | import org.onosproject.net.Link; |
| 28 | import org.onosproject.net.flow.TrafficSelector; |
| 29 | import org.onosproject.net.flow.TrafficTreatment; |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 30 | |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 31 | import com.google.common.base.MoreObjects; |
| 32 | import com.google.common.collect.ImmutableSet; |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
| 35 | * Abstraction of a connectivity intent that is implemented by a set of path |
| 36 | * segments. |
| 37 | */ |
Brian O'Connor | 9476fa1 | 2015-06-25 15:17:17 -0400 | [diff] [blame] | 38 | @Beta |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 39 | public final class LinkCollectionIntent extends ConnectivityIntent { |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 40 | |
| 41 | private final Set<Link> links; |
| 42 | |
Pavlin Radoslavov | 2811c40 | 2015-02-25 14:30:17 -0800 | [diff] [blame] | 43 | private final Set<ConnectPoint> ingressPoints; |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 44 | private final Set<ConnectPoint> egressPoints; |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 45 | private final boolean egressTreatmentFlag; |
Pier Ventre | 647138f | 2016-08-26 17:32:44 -0700 | [diff] [blame] | 46 | /** |
| 47 | * To manage multiple selectors use case. |
| 48 | */ |
| 49 | private final Map<ConnectPoint, TrafficSelector> ingressSelectors; |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 50 | /** |
| 51 | * To manage multiple treatments use case. |
| 52 | */ |
| 53 | private final Map<ConnectPoint, TrafficTreatment> egressTreatments; |
Jonathan Hart | 6b2ffc3 | 2014-10-18 02:09:22 -0700 | [diff] [blame] | 54 | |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 55 | /** |
Pavlin Radoslavov | 2811c40 | 2015-02-25 14:30:17 -0800 | [diff] [blame] | 56 | * Creates a new actionable intent capable of funneling the selected |
| 57 | * traffic along the specified convergent tree and out the given egress |
Pavlin Radoslavov | 2811c40 | 2015-02-25 14:30:17 -0800 | [diff] [blame] | 58 | * point satisfying the specified constraints. |
Sho SHIMIZU | ac8f352 | 2014-11-10 12:14:50 -0800 | [diff] [blame] | 59 | * |
| 60 | * @param appId application identifier |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 61 | * @param key key to use for the intent |
Sho SHIMIZU | ac8f352 | 2014-11-10 12:14:50 -0800 | [diff] [blame] | 62 | * @param selector traffic match |
| 63 | * @param treatment action |
| 64 | * @param links traversed links |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 65 | * @param ingressPoints ingress points |
| 66 | * @param egressPoints egress points |
Sho SHIMIZU | ac8f352 | 2014-11-10 12:14:50 -0800 | [diff] [blame] | 67 | * @param constraints optional list of constraints |
Ray Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame] | 68 | * @param priority priority to use for the flows generated by this intent |
Nicholas Dean | 126b8af | 2016-07-18 14:43:13 -0700 | [diff] [blame] | 69 | * @param egressTreatment true if treatment should be applied by the egress device |
Pier Ventre | 647138f | 2016-08-26 17:32:44 -0700 | [diff] [blame] | 70 | * @param ingressSelectors map to store the association ingress to selector |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 71 | * @param egressTreatments map to store the association egress to treatment |
Sho SHIMIZU | ac8f352 | 2014-11-10 12:14:50 -0800 | [diff] [blame] | 72 | * @throws NullPointerException {@code path} is null |
| 73 | */ |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 74 | private LinkCollectionIntent(ApplicationId appId, |
Nicholas Dean | 126b8af | 2016-07-18 14:43:13 -0700 | [diff] [blame] | 75 | Key key, |
| 76 | TrafficSelector selector, |
| 77 | TrafficTreatment treatment, |
| 78 | Set<Link> links, |
| 79 | Set<ConnectPoint> ingressPoints, |
| 80 | Set<ConnectPoint> egressPoints, |
| 81 | List<Constraint> constraints, |
Pier Ventre | 647138f | 2016-08-26 17:32:44 -0700 | [diff] [blame] | 82 | int priority, |
| 83 | boolean egressTreatment, |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 84 | Map<ConnectPoint, TrafficSelector> ingressSelectors, |
| 85 | Map<ConnectPoint, TrafficTreatment> egressTreatments) { |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 86 | super(appId, key, resources(links), selector, treatment, constraints, priority); |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 87 | this.links = links; |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 88 | this.ingressPoints = ingressPoints; |
| 89 | this.egressPoints = egressPoints; |
Nicholas Dean | 126b8af | 2016-07-18 14:43:13 -0700 | [diff] [blame] | 90 | this.egressTreatmentFlag = egressTreatment; |
Pier Ventre | 647138f | 2016-08-26 17:32:44 -0700 | [diff] [blame] | 91 | this.ingressSelectors = ingressSelectors; |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 92 | this.egressTreatments = egressTreatments; |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 95 | /** |
| 96 | * Constructor for serializer. |
| 97 | */ |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 98 | protected LinkCollectionIntent() { |
| 99 | super(); |
| 100 | this.links = null; |
Pavlin Radoslavov | 2811c40 | 2015-02-25 14:30:17 -0800 | [diff] [blame] | 101 | this.ingressPoints = null; |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 102 | this.egressPoints = null; |
Nicholas Dean | 126b8af | 2016-07-18 14:43:13 -0700 | [diff] [blame] | 103 | this.egressTreatmentFlag = false; |
Pier Ventre | 647138f | 2016-08-26 17:32:44 -0700 | [diff] [blame] | 104 | this.ingressSelectors = null; |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 105 | this.egressTreatments = null; |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 108 | /** |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 109 | * Returns a new link collection intent builder. The application id, |
| 110 | * ingress point and egress points are required fields. If they are |
| 111 | * not set by calls to the appropriate methods, an exception will |
| 112 | * be thrown. |
| 113 | * |
| 114 | * @return single point to multi point builder |
| 115 | */ |
| 116 | public static Builder builder() { |
| 117 | return new Builder(); |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Builder of a single point to multi point intent. |
| 122 | */ |
| 123 | public static final class Builder extends ConnectivityIntent.Builder { |
| 124 | Set<Link> links; |
| 125 | Set<ConnectPoint> ingressPoints; |
| 126 | Set<ConnectPoint> egressPoints; |
Thomas Vachuska | e45ab44 | 2016-08-31 14:21:33 -0700 | [diff] [blame] | 127 | Map<ConnectPoint, TrafficSelector> ingressSelectors = ImmutableMap.of(); |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 128 | Map<ConnectPoint, TrafficTreatment> egressTreatments = ImmutableMap.of(); |
Nicholas Dean | 126b8af | 2016-07-18 14:43:13 -0700 | [diff] [blame] | 129 | boolean egressTreatmentFlag; |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 130 | |
| 131 | private Builder() { |
| 132 | // Hide constructor |
| 133 | } |
| 134 | |
| 135 | @Override |
| 136 | public Builder appId(ApplicationId appId) { |
| 137 | return (Builder) super.appId(appId); |
| 138 | } |
| 139 | |
| 140 | @Override |
| 141 | public Builder key(Key key) { |
| 142 | return (Builder) super.key(key); |
| 143 | } |
| 144 | |
| 145 | @Override |
| 146 | public Builder selector(TrafficSelector selector) { |
| 147 | return (Builder) super.selector(selector); |
| 148 | } |
| 149 | |
| 150 | @Override |
| 151 | public Builder treatment(TrafficTreatment treatment) { |
| 152 | return (Builder) super.treatment(treatment); |
| 153 | } |
| 154 | |
| 155 | @Override |
| 156 | public Builder constraints(List<Constraint> constraints) { |
| 157 | return (Builder) super.constraints(constraints); |
| 158 | } |
| 159 | |
| 160 | @Override |
| 161 | public Builder priority(int priority) { |
| 162 | return (Builder) super.priority(priority); |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * Sets the ingress point of the single point to multi point intent |
| 167 | * that will be built. |
| 168 | * |
| 169 | * @param ingressPoints ingress connect points |
| 170 | * @return this builder |
| 171 | */ |
| 172 | public Builder ingressPoints(Set<ConnectPoint> ingressPoints) { |
| 173 | this.ingressPoints = ImmutableSet.copyOf(ingressPoints); |
| 174 | return this; |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Sets the egress points of the single point to multi point intent |
| 179 | * that will be built. |
| 180 | * |
| 181 | * @param egressPoints egress connect points |
| 182 | * @return this builder |
| 183 | */ |
| 184 | public Builder egressPoints(Set<ConnectPoint> egressPoints) { |
| 185 | this.egressPoints = ImmutableSet.copyOf(egressPoints); |
| 186 | return this; |
| 187 | } |
| 188 | |
| 189 | /** |
Pier Ventre | 647138f | 2016-08-26 17:32:44 -0700 | [diff] [blame] | 190 | * Sets the map ingress selectors to connection points of the intent. |
| 191 | * |
| 192 | * @param ingressSelectors maps connection point to traffic selector |
| 193 | * @return this builder |
| 194 | */ |
| 195 | public Builder ingressSelectors(Map<ConnectPoint, TrafficSelector> ingressSelectors) { |
| 196 | this.ingressSelectors = ImmutableMap.copyOf(ingressSelectors); |
| 197 | return this; |
| 198 | } |
| 199 | |
| 200 | /** |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 201 | * Sets the map egress treatments to connection points of the intent. |
| 202 | * |
| 203 | * @param egressTreatments maps connection point to traffic treatment |
| 204 | * @return this builder |
| 205 | */ |
| 206 | public Builder egressTreatments(Map<ConnectPoint, TrafficTreatment> egressTreatments) { |
| 207 | this.egressTreatments = ImmutableMap.copyOf(egressTreatments); |
| 208 | return this; |
| 209 | } |
| 210 | |
| 211 | /** |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 212 | * Sets the links of the link collection intent |
| 213 | * that will be built. |
| 214 | * |
| 215 | * @param links links for the intent |
| 216 | * @return this builder |
| 217 | */ |
| 218 | public Builder links(Set<Link> links) { |
| 219 | this.links = ImmutableSet.copyOf(links); |
| 220 | return this; |
| 221 | } |
| 222 | |
Nicholas Dean | 126b8af | 2016-07-18 14:43:13 -0700 | [diff] [blame] | 223 | /** |
| 224 | * Sets the intent to apply treatment at the egress rather than the |
| 225 | * ingress. |
| 226 | * |
| 227 | * @param treatmentOnEgress true applies treatment on egress device |
| 228 | * @return this builder |
| 229 | */ |
| 230 | public Builder applyTreatmentOnEgress(boolean treatmentOnEgress) { |
| 231 | this.egressTreatmentFlag = treatmentOnEgress; |
| 232 | return this; |
| 233 | } |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 234 | |
| 235 | /** |
| 236 | * Builds a single point to multi point intent from the |
| 237 | * accumulated parameters. |
| 238 | * |
| 239 | * @return point to point intent |
| 240 | */ |
| 241 | public LinkCollectionIntent build() { |
| 242 | |
| 243 | return new LinkCollectionIntent( |
| 244 | appId, |
| 245 | key, |
| 246 | selector, |
| 247 | treatment, |
| 248 | links, |
| 249 | ingressPoints, |
| 250 | egressPoints, |
| 251 | constraints, |
Nicholas Dean | 126b8af | 2016-07-18 14:43:13 -0700 | [diff] [blame] | 252 | priority, |
Pier Ventre | 647138f | 2016-08-26 17:32:44 -0700 | [diff] [blame] | 253 | egressTreatmentFlag, |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 254 | ingressSelectors, |
| 255 | egressTreatments |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 256 | ); |
| 257 | } |
| 258 | } |
| 259 | |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 260 | /** |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 261 | * Returns the set of links that represent the network connections needed |
| 262 | * by this intent. |
| 263 | * |
| 264 | * @return Set of links for the network hops needed by this intent |
| 265 | */ |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 266 | public Set<Link> links() { |
| 267 | return links; |
| 268 | } |
| 269 | |
Jonathan Hart | 6b2ffc3 | 2014-10-18 02:09:22 -0700 | [diff] [blame] | 270 | /** |
Pavlin Radoslavov | 2811c40 | 2015-02-25 14:30:17 -0800 | [diff] [blame] | 271 | * Returns the ingress points of the intent. |
Jonathan Hart | 6b2ffc3 | 2014-10-18 02:09:22 -0700 | [diff] [blame] | 272 | * |
Pavlin Radoslavov | 2811c40 | 2015-02-25 14:30:17 -0800 | [diff] [blame] | 273 | * @return the ingress points |
| 274 | */ |
| 275 | public Set<ConnectPoint> ingressPoints() { |
| 276 | return ingressPoints; |
| 277 | } |
| 278 | |
| 279 | /** |
| 280 | * Returns the egress points of the intent. |
| 281 | * |
| 282 | * @return the egress points |
Jonathan Hart | 6b2ffc3 | 2014-10-18 02:09:22 -0700 | [diff] [blame] | 283 | */ |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 284 | public Set<ConnectPoint> egressPoints() { |
| 285 | return egressPoints; |
Jonathan Hart | 6b2ffc3 | 2014-10-18 02:09:22 -0700 | [diff] [blame] | 286 | } |
| 287 | |
Nicholas Dean | 126b8af | 2016-07-18 14:43:13 -0700 | [diff] [blame] | 288 | /** |
Pier Ventre | 647138f | 2016-08-26 17:32:44 -0700 | [diff] [blame] | 289 | * Returns the multiple selectors jointly with their connection points. |
| 290 | * @return multiple selectors |
| 291 | */ |
| 292 | public Map<ConnectPoint, TrafficSelector> ingressSelectors() { |
| 293 | return ingressSelectors; |
| 294 | } |
| 295 | |
| 296 | /** |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 297 | * Returns the multiple treatments jointly with their connection points. |
| 298 | * @return multiple treatments |
| 299 | */ |
| 300 | public Map<ConnectPoint, TrafficTreatment> egressTreatments() { |
| 301 | return egressTreatments; |
| 302 | } |
| 303 | |
| 304 | /** |
Nicholas Dean | 126b8af | 2016-07-18 14:43:13 -0700 | [diff] [blame] | 305 | * Returns whether treatment should be applied on egress. |
| 306 | * |
| 307 | * @return the egress treatment flag |
| 308 | */ |
| 309 | public boolean applyTreatmentOnEgress() { |
| 310 | return egressTreatmentFlag; |
| 311 | } |
| 312 | |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 313 | @Override |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 314 | public String toString() { |
| 315 | return MoreObjects.toStringHelper(getClass()) |
| 316 | .add("id", id()) |
Ray Milkey | c357381 | 2015-02-09 09:18:34 -0800 | [diff] [blame] | 317 | .add("key", key()) |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 318 | .add("appId", appId()) |
Ray Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame] | 319 | .add("priority", priority()) |
Jonathan Hart | 23b5a76 | 2015-01-26 14:47:33 -0800 | [diff] [blame] | 320 | .add("resources", resources()) |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 321 | .add("selector", selector()) |
| 322 | .add("treatment", treatment()) |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 323 | .add("links", links()) |
Pavlin Radoslavov | 2811c40 | 2015-02-25 14:30:17 -0800 | [diff] [blame] | 324 | .add("ingress", ingressPoints()) |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 325 | .add("egress", egressPoints()) |
Pier Ventre | 647138f | 2016-08-26 17:32:44 -0700 | [diff] [blame] | 326 | .add("selectors", ingressSelectors()) |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 327 | .add("treatments", egressTreatments()) |
| 328 | .add("treatementOnEgress", applyTreatmentOnEgress()) |
Ray Milkey | 0742ec9 | 2014-10-13 08:39:55 -0700 | [diff] [blame] | 329 | .toString(); |
| 330 | } |
Pier Ventre | 647138f | 2016-08-26 17:32:44 -0700 | [diff] [blame] | 331 | } |