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