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