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