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