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