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