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