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