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; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 17 | |
Brian O'Connor | 9476fa1 | 2015-06-25 15:17:17 -0400 | [diff] [blame] | 18 | import com.google.common.annotations.Beta; |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 19 | import com.google.common.base.MoreObjects; |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 20 | import com.google.common.collect.ImmutableList; |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 21 | import com.google.common.collect.ImmutableSet; |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 22 | |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 23 | import com.google.common.collect.Sets; |
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; |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 27 | import org.onosproject.net.ResourceGroup; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 28 | import org.onosproject.net.flow.TrafficSelector; |
| 29 | import org.onosproject.net.flow.TrafficTreatment; |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 30 | import org.slf4j.Logger; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 31 | |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 32 | import java.util.Set; |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 33 | import java.util.List; |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 34 | import java.util.stream.Collectors; |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 35 | |
| 36 | import static com.google.common.base.Preconditions.checkArgument; |
| 37 | import static com.google.common.base.Preconditions.checkNotNull; |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 38 | import static org.slf4j.LoggerFactory.getLogger; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 39 | |
| 40 | /** |
| 41 | * Abstraction of single source, multiple destination connectivity intent. |
| 42 | */ |
Brian O'Connor | 9476fa1 | 2015-06-25 15:17:17 -0400 | [diff] [blame] | 43 | @Beta |
Ray Milkey | bd4f011 | 2015-03-02 17:07:09 -0800 | [diff] [blame] | 44 | public final class SinglePointToMultiPointIntent extends ConnectivityIntent { |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 45 | private final FilteredConnectPoint ingressPoint; |
| 46 | private final Set<FilteredConnectPoint> egressPoints; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 47 | |
| 48 | /** |
| 49 | * Creates a new single-to-multi point connectivity intent. |
| 50 | * |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 51 | * @param appId application identifier |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 52 | * @param key intent key |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 53 | * @param selector traffic selector |
| 54 | * @param treatment treatment |
| 55 | * @param ingressPoint port on which traffic will ingress |
| 56 | * @param egressPoints set of ports on which traffic will egress |
| 57 | * @param constraints constraints to apply to the intent |
Ray Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame] | 58 | * @param priority priority to use for flows generated by this intent |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 59 | * @throws NullPointerException if {@code ingressPoint} or |
| 60 | * {@code egressPoints} is null |
| 61 | * @throws IllegalArgumentException if the size of {@code egressPoints} is |
| 62 | * not more than 1 |
| 63 | */ |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 64 | private SinglePointToMultiPointIntent(ApplicationId appId, |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 65 | Key key, |
| 66 | TrafficSelector selector, |
| 67 | TrafficTreatment treatment, |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 68 | FilteredConnectPoint ingressPoint, |
| 69 | Set<FilteredConnectPoint> egressPoints, |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 70 | List<Constraint> constraints, |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 71 | int priority, |
| 72 | ResourceGroup resourceGroup) { |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 73 | super(appId, key, ImmutableList.of(), selector, treatment, constraints, |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 74 | priority, resourceGroup); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 75 | checkNotNull(egressPoints); |
Sho SHIMIZU | 2e66080 | 2014-11-21 14:55:32 -0800 | [diff] [blame] | 76 | checkNotNull(ingressPoint); |
Thomas Vachuska | c96058a | 2014-10-20 23:00:16 -0700 | [diff] [blame] | 77 | checkArgument(!egressPoints.isEmpty(), "Egress point set cannot be empty"); |
Sho SHIMIZU | 2e66080 | 2014-11-21 14:55:32 -0800 | [diff] [blame] | 78 | checkArgument(!egressPoints.contains(ingressPoint), |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 79 | "Set of egresses should not contain ingress (ingress: %s)", ingressPoint); |
Sho SHIMIZU | 2e66080 | 2014-11-21 14:55:32 -0800 | [diff] [blame] | 80 | |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 81 | this.ingressPoint = ingressPoint; |
| 82 | this.egressPoints = Sets.newHashSet(egressPoints); |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Returns a new single point to multi point intent builder. The application id, |
| 87 | * ingress point and egress points are required fields. If they are |
| 88 | * not set by calls to the appropriate methods, an exception will |
| 89 | * be thrown. |
| 90 | * |
| 91 | * @return single point to multi point builder |
| 92 | */ |
| 93 | public static Builder builder() { |
| 94 | return new Builder(); |
| 95 | } |
| 96 | |
| 97 | /** |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 98 | * Creates a new builder pre-populated with the information in the given |
| 99 | * intent. |
| 100 | * |
| 101 | * @param intent initial intent |
| 102 | * @return intent builder |
| 103 | */ |
| 104 | public static Builder builder(SinglePointToMultiPointIntent intent) { |
| 105 | return new Builder(intent); |
| 106 | } |
| 107 | |
| 108 | /** |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 109 | * Builder of a single point to multi point intent. |
| 110 | */ |
| 111 | public static final class Builder extends ConnectivityIntent.Builder { |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 112 | private final Logger log = getLogger(getClass()); |
| 113 | private FilteredConnectPoint ingressPoint; |
| 114 | private Set<FilteredConnectPoint> egressPoints; |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 115 | |
| 116 | private Builder() { |
| 117 | // Hide constructor |
| 118 | } |
| 119 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 120 | /** |
| 121 | * Creates a new builder pre-populated with information from the given |
| 122 | * intent. |
| 123 | * |
| 124 | * @param intent initial intent |
| 125 | */ |
| 126 | protected Builder(SinglePointToMultiPointIntent intent) { |
| 127 | super(intent); |
| 128 | |
| 129 | this.filteredEgressPoints(intent.filteredEgressPoints()) |
| 130 | .filteredIngressPoint(intent.filteredIngressPoint()); |
| 131 | |
| 132 | } |
| 133 | |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 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 | |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 164 | @Override |
| 165 | public Builder resourceGroup(ResourceGroup resourceGroup) { |
| 166 | return (Builder) super.resourceGroup(resourceGroup); |
| 167 | } |
| 168 | |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 169 | /** |
| 170 | * Sets the ingress point of the single point to multi point intent |
| 171 | * that will be built. |
| 172 | * |
| 173 | * @param ingressPoint ingress connect point |
| 174 | * @return this builder |
| 175 | */ |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 176 | @Deprecated |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 177 | public Builder ingressPoint(ConnectPoint ingressPoint) { |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 178 | if (this.ingressPoint != null) { |
| 179 | log.warn("Ingress point is already set, " + |
| 180 | "this will override original ingress point."); |
| 181 | } |
| 182 | this.ingressPoint = new FilteredConnectPoint(ingressPoint); |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 183 | return this; |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * Sets the 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 | */ |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 193 | @Deprecated |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 194 | public Builder egressPoints(Set<ConnectPoint> egressPoints) { |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 195 | if (this.egressPoints != null) { |
| 196 | log.warn("Egress points are already set, " + |
| 197 | "this will override original egress points."); |
| 198 | } |
| 199 | Set<FilteredConnectPoint> filteredConnectPoints = |
| 200 | egressPoints.stream() |
| 201 | .map(FilteredConnectPoint::new) |
| 202 | .collect(Collectors.toSet()); |
| 203 | this.egressPoints = ImmutableSet.copyOf(filteredConnectPoints); |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 204 | return this; |
| 205 | } |
| 206 | |
| 207 | /** |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 208 | * Sets the filtered ingress point of the single point to |
| 209 | * multi point intent that will be built. |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 210 | * |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 211 | * @param ingressPoint ingress connect point |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 212 | * @return this builder |
| 213 | */ |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 214 | public Builder filteredIngressPoint(FilteredConnectPoint ingressPoint) { |
| 215 | this.ingressPoint = ingressPoint; |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 216 | return this; |
| 217 | } |
| 218 | |
| 219 | /** |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 220 | * Sets the filtered egress points of the single point to |
| 221 | * multi point intent that will be built. |
| 222 | * |
| 223 | * @param egressPoints egress connect points |
| 224 | * @return this builder |
| 225 | */ |
| 226 | public Builder filteredEgressPoints(Set<FilteredConnectPoint> egressPoints) { |
| 227 | this.egressPoints = ImmutableSet.copyOf(egressPoints); |
| 228 | return this; |
| 229 | } |
| 230 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 231 | /** |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 232 | * Builds a single point to multi point intent from the |
| 233 | * accumulated parameters. |
| 234 | * |
| 235 | * @return point to point intent |
| 236 | */ |
| 237 | public SinglePointToMultiPointIntent build() { |
| 238 | |
| 239 | return new SinglePointToMultiPointIntent( |
| 240 | appId, |
| 241 | key, |
| 242 | selector, |
| 243 | treatment, |
| 244 | ingressPoint, |
| 245 | egressPoints, |
| 246 | constraints, |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 247 | priority, |
| 248 | resourceGroup |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 249 | ); |
| 250 | } |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | /** |
| 254 | * Constructor for serializer. |
| 255 | */ |
| 256 | protected SinglePointToMultiPointIntent() { |
| 257 | super(); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 258 | this.ingressPoint = null; |
| 259 | this.egressPoints = null; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | /** |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 263 | * Returns the port on which the ingress traffic should be connected to the |
| 264 | * egress. |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 265 | * |
| 266 | * @return ingress port |
| 267 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 268 | public ConnectPoint ingressPoint() { |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 269 | return ingressPoint.connectPoint(); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | /** |
| 273 | * Returns the set of ports on which the traffic should egress. |
| 274 | * |
| 275 | * @return set of egress ports |
| 276 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 277 | public Set<ConnectPoint> egressPoints() { |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 278 | return egressPoints.stream() |
| 279 | .map(FilteredConnectPoint::connectPoint) |
| 280 | .collect(Collectors.toSet()); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 281 | } |
| 282 | |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 283 | /** |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 284 | * Returns the filtered port on which the ingress traffic should be connected to the |
| 285 | * egress. |
| 286 | * |
| 287 | * @return ingress port |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 288 | */ |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 289 | public FilteredConnectPoint filteredIngressPoint() { |
| 290 | return ingressPoint; |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 291 | } |
| 292 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 293 | /** |
| 294 | * Returns the set of filtered ports on which the traffic should egress. |
| 295 | * |
| 296 | * @return set of egress ports |
| 297 | */ |
| 298 | public Set<FilteredConnectPoint> filteredEgressPoints() { |
| 299 | return egressPoints; |
| 300 | } |
| 301 | |
| 302 | |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 303 | @Override |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 304 | public String toString() { |
| 305 | return MoreObjects.toStringHelper(getClass()) |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 306 | .add("id", id()) |
Ray Milkey | c357381 | 2015-02-09 09:18:34 -0800 | [diff] [blame] | 307 | .add("key", key()) |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 308 | .add("appId", appId()) |
Ray Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame] | 309 | .add("priority", priority()) |
Jonathan Hart | 23b5a76 | 2015-01-26 14:47:33 -0800 | [diff] [blame] | 310 | .add("resources", resources()) |
Thomas Vachuska | e291c84 | 2014-10-21 02:52:38 -0700 | [diff] [blame] | 311 | .add("selector", selector()) |
| 312 | .add("treatment", treatment()) |
| 313 | .add("ingress", ingressPoint) |
| 314 | .add("egress", egressPoints) |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 315 | .add("filteredIngressCPs", filteredIngressPoint()) |
| 316 | .add("filteredEgressCP", filteredEgressPoints()) |
Michele Santuari | 4a33807 | 2014-11-05 18:38:55 +0100 | [diff] [blame] | 317 | .add("constraints", constraints()) |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 318 | .add("resourceGroup", resourceGroup()) |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 319 | .toString(); |
| 320 | } |
| 321 | |
| 322 | } |