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