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