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