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