blob: 77b455651488cc02ce360969d91f0848696669b2 [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuska83e090e2014-10-22 14:25:35 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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 Vachuska83e090e2014-10-22 14:25:35 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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 Vachuska83e090e2014-10-22 14:25:35 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.intent;
Brian O'Connorb876bf12014-10-02 14:59:37 -070017
Sho SHIMIZUd7d18002015-01-21 14:37:14 -080018import java.util.Collections;
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080019import java.util.List;
Brian O'Connorb876bf12014-10-02 14:59:37 -070020
Brian O'Connor9476fa12015-06-25 15:17:17 -040021import com.google.common.annotations.Beta;
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070022import org.onosproject.core.ApplicationId;
23import org.onosproject.net.ConnectPoint;
Pier Ventreffe88d62016-10-13 14:34:40 -070024import org.onosproject.net.FilteredConnectPoint;
Luca Prete670ac5d2017-02-03 15:55:43 -080025import org.onosproject.net.ResourceGroup;
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070026import org.onosproject.net.flow.TrafficSelector;
27import org.onosproject.net.flow.TrafficTreatment;
28
29import com.google.common.base.MoreObjects;
30
Sho SHIMIZU2e660802014-11-21 14:55:32 -080031import static com.google.common.base.Preconditions.checkArgument;
toma1d16b62014-10-02 23:45:11 -070032import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connorb876bf12014-10-02 14:59:37 -070033
34/**
35 * Abstraction of point-to-point connectivity.
36 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040037@Beta
Ray Milkeybd4f0112015-03-02 17:07:09 -080038public final class PointToPointIntent extends ConnectivityIntent {
Brian O'Connorb876bf12014-10-02 14:59:37 -070039
Pier Ventreffe88d62016-10-13 14:34:40 -070040 private final FilteredConnectPoint ingressPoint;
41 private final FilteredConnectPoint egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070042
43 /**
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070044 * 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 Ventreffe88d62016-10-13 14:34:40 -070059 FilteredConnectPoint ingressPoint;
60 FilteredConnectPoint egressPoint;
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070061
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 Prete670ac5d2017-02-03 15:55:43 -080096 @Override
97 public Builder resourceGroup(ResourceGroup resourceGroup) {
98 return (Builder) super.resourceGroup(resourceGroup);
99 }
100
Ray Milkey3e3ec5f2015-03-17 17:00:38 -0700101 /**
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 Ventreffe88d62016-10-13 14:34:40 -0700107 @Deprecated
Ray Milkey3e3ec5f2015-03-17 17:00:38 -0700108 public Builder ingressPoint(ConnectPoint ingressPoint) {
Pier Ventreffe88d62016-10-13 14:34:40 -0700109 this.ingressPoint = new FilteredConnectPoint(ingressPoint);
Ray Milkey3e3ec5f2015-03-17 17:00:38 -0700110 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 Ventreffe88d62016-10-13 14:34:40 -0700119 @Deprecated
Ray Milkey3e3ec5f2015-03-17 17:00:38 -0700120 public Builder egressPoint(ConnectPoint egressPoint) {
Pier Ventreffe88d62016-10-13 14:34:40 -0700121 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 Milkey3e3ec5f2015-03-17 17:00:38 -0700145 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 Prete670ac5d2017-02-03 15:55:43 -0800164 priority,
165 resourceGroup
Ray Milkey3e3ec5f2015-03-17 17:00:38 -0700166 );
167 }
168 }
169
170
171
172 /**
Brian O'Connorb876bf12014-10-02 14:59:37 -0700173 * Creates a new point-to-point intent with the supplied ingress/egress
Ray Milkey5b3717e2015-02-05 11:44:08 -0800174 * 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 Ventreffe88d62016-10-13 14:34:40 -0700180 * @param ingressPoint filtered ingress port
181 * @param egressPoint filtered egress port
Ray Milkey5b3717e2015-02-05 11:44:08 -0800182 * @param constraints optional list of constraints
Ray Milkeyc24cde32015-03-10 18:20:18 -0700183 * @param priority priority to use for flows generated by this intent
Ray Milkey3e3ec5f2015-03-17 17:00:38 -0700184 * @throws NullPointerException if {@code ingressPoint} or
185 * {@code egressPoints} or {@code appId} is null.
Ray Milkey5b3717e2015-02-05 11:44:08 -0800186 */
Ray Milkey3e3ec5f2015-03-17 17:00:38 -0700187 private PointToPointIntent(ApplicationId appId,
Luca Prete670ac5d2017-02-03 15:55:43 -0800188 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 Milkeyc24cde32015-03-10 18:20:18 -0700196 super(appId, key, Collections.emptyList(), selector, treatment, constraints,
Luca Prete670ac5d2017-02-03 15:55:43 -0800197 priority, resourceGroup);
Ray Milkey5b3717e2015-02-05 11:44:08 -0800198
Ray Milkey5b3717e2015-02-05 11:44:08 -0800199 checkArgument(!ingressPoint.equals(egressPoint),
200 "ingress and egress should be different (ingress: %s, egress: %s)", ingressPoint, egressPoint);
201
Ray Milkeyebc5d222015-03-18 15:45:36 -0700202 this.ingressPoint = checkNotNull(ingressPoint);
203 this.egressPoint = checkNotNull(egressPoint);
Ray Milkey5b3717e2015-02-05 11:44:08 -0800204 }
205
206 /**
Brian O'Connorb876bf12014-10-02 14:59:37 -0700207 * Constructor for serializer.
208 */
209 protected PointToPointIntent() {
210 super();
tom85258ee2014-10-07 00:10:02 -0700211 this.ingressPoint = null;
212 this.egressPoint = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700213 }
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 Ventreffe88d62016-10-13 14:34:40 -0700221 @Deprecated
tom85258ee2014-10-07 00:10:02 -0700222 public ConnectPoint ingressPoint() {
Pier Ventreffe88d62016-10-13 14:34:40 -0700223 return ingressPoint.connectPoint();
Brian O'Connorb876bf12014-10-02 14:59:37 -0700224 }
225
226 /**
227 * Returns the port on which the traffic should egress.
228 *
229 * @return egress port
230 */
Pier Ventreffe88d62016-10-13 14:34:40 -0700231 @Deprecated
tom85258ee2014-10-07 00:10:02 -0700232 public ConnectPoint egressPoint() {
Pier Ventreffe88d62016-10-13 14:34:40 -0700233 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() {
tom85258ee2014-10-07 00:10:02 -0700252 return egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700253 }
254
255 @Override
Brian O'Connorb876bf12014-10-02 14:59:37 -0700256 public String toString() {
257 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700258 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800259 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700260 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700261 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800262 .add("resources", resources())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700263 .add("selector", selector())
264 .add("treatment", treatment())
Pier Ventreffe88d62016-10-13 14:34:40 -0700265 .add("ingress", filteredIngressPoint())
266 .add("egress", filteredEgressPoint())
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800267 .add("constraints", constraints())
Luca Prete670ac5d2017-02-03 15:55:43 -0800268 .add("resourceGroup", resourceGroup())
Brian O'Connorb876bf12014-10-02 14:59:37 -0700269 .toString();
270 }
271
272}