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