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