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