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