blob: ba3b2c2fb5daebe737ec037fe39a60daa7f4e950 [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;
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070025import org.onosproject.net.flow.TrafficSelector;
26import org.onosproject.net.flow.TrafficTreatment;
27
28import com.google.common.base.MoreObjects;
29
Sho SHIMIZU2e660802014-11-21 14:55:32 -080030import static com.google.common.base.Preconditions.checkArgument;
toma1d16b62014-10-02 23:45:11 -070031import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connorb876bf12014-10-02 14:59:37 -070032
33/**
34 * Abstraction of point-to-point connectivity.
35 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040036@Beta
Ray Milkeybd4f0112015-03-02 17:07:09 -080037public final class PointToPointIntent extends ConnectivityIntent {
Brian O'Connorb876bf12014-10-02 14:59:37 -070038
Pier Ventreffe88d62016-10-13 14:34:40 -070039 private final FilteredConnectPoint ingressPoint;
40 private final FilteredConnectPoint egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070041
42 /**
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070043 * 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 Ventreffe88d62016-10-13 14:34:40 -070058 FilteredConnectPoint ingressPoint;
59 FilteredConnectPoint egressPoint;
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070060
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 Ventreffe88d62016-10-13 14:34:40 -0700101 @Deprecated
Ray Milkey3e3ec5f2015-03-17 17:00:38 -0700102 public Builder ingressPoint(ConnectPoint ingressPoint) {
Pier Ventreffe88d62016-10-13 14:34:40 -0700103 this.ingressPoint = new FilteredConnectPoint(ingressPoint);
Ray Milkey3e3ec5f2015-03-17 17:00:38 -0700104 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 Ventreffe88d62016-10-13 14:34:40 -0700113 @Deprecated
Ray Milkey3e3ec5f2015-03-17 17:00:38 -0700114 public Builder egressPoint(ConnectPoint egressPoint) {
Pier Ventreffe88d62016-10-13 14:34:40 -0700115 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 Milkey3e3ec5f2015-03-17 17:00:38 -0700139 this.egressPoint = egressPoint;
140 return this;
141 }
142
Pier Ventreffe88d62016-10-13 14:34:40 -0700143
Ray Milkey3e3ec5f2015-03-17 17:00:38 -0700144 /**
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'Connorb876bf12014-10-02 14:59:37 -0700167 * Creates a new point-to-point intent with the supplied ingress/egress
Ray Milkey5b3717e2015-02-05 11:44:08 -0800168 * 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 Ventreffe88d62016-10-13 14:34:40 -0700174 * @param ingressPoint filtered ingress port
175 * @param egressPoint filtered egress port
Ray Milkey5b3717e2015-02-05 11:44:08 -0800176 * @param constraints optional list of constraints
Ray Milkeyc24cde32015-03-10 18:20:18 -0700177 * @param priority priority to use for flows generated by this intent
Ray Milkey3e3ec5f2015-03-17 17:00:38 -0700178 * @throws NullPointerException if {@code ingressPoint} or
179 * {@code egressPoints} or {@code appId} is null.
Ray Milkey5b3717e2015-02-05 11:44:08 -0800180 */
Ray Milkey3e3ec5f2015-03-17 17:00:38 -0700181 private PointToPointIntent(ApplicationId appId,
Ray Milkey5b3717e2015-02-05 11:44:08 -0800182 Key key,
183 TrafficSelector selector,
184 TrafficTreatment treatment,
Pier Ventreffe88d62016-10-13 14:34:40 -0700185 FilteredConnectPoint ingressPoint,
186 FilteredConnectPoint egressPoint,
Ray Milkeyc24cde32015-03-10 18:20:18 -0700187 List<Constraint> constraints,
188 int priority) {
189 super(appId, key, Collections.emptyList(), selector, treatment, constraints,
190 priority);
Ray Milkey5b3717e2015-02-05 11:44:08 -0800191
Ray Milkey5b3717e2015-02-05 11:44:08 -0800192 checkArgument(!ingressPoint.equals(egressPoint),
193 "ingress and egress should be different (ingress: %s, egress: %s)", ingressPoint, egressPoint);
194
Ray Milkeyebc5d222015-03-18 15:45:36 -0700195 this.ingressPoint = checkNotNull(ingressPoint);
196 this.egressPoint = checkNotNull(egressPoint);
Ray Milkey5b3717e2015-02-05 11:44:08 -0800197 }
198
199 /**
Brian O'Connorb876bf12014-10-02 14:59:37 -0700200 * Constructor for serializer.
201 */
202 protected PointToPointIntent() {
203 super();
tom85258ee2014-10-07 00:10:02 -0700204 this.ingressPoint = null;
205 this.egressPoint = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700206 }
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 Ventreffe88d62016-10-13 14:34:40 -0700214 @Deprecated
tom85258ee2014-10-07 00:10:02 -0700215 public ConnectPoint ingressPoint() {
Pier Ventreffe88d62016-10-13 14:34:40 -0700216 return ingressPoint.connectPoint();
Brian O'Connorb876bf12014-10-02 14:59:37 -0700217 }
218
219 /**
220 * Returns the port on which the traffic should egress.
221 *
222 * @return egress port
223 */
Pier Ventreffe88d62016-10-13 14:34:40 -0700224 @Deprecated
tom85258ee2014-10-07 00:10:02 -0700225 public ConnectPoint egressPoint() {
Pier Ventreffe88d62016-10-13 14:34:40 -0700226 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() {
tom85258ee2014-10-07 00:10:02 -0700245 return egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700246 }
247
248 @Override
Brian O'Connorb876bf12014-10-02 14:59:37 -0700249 public String toString() {
250 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700251 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800252 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700253 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700254 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800255 .add("resources", resources())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700256 .add("selector", selector())
257 .add("treatment", treatment())
Pier Ventreffe88d62016-10-13 14:34:40 -0700258 .add("ingress", filteredIngressPoint())
259 .add("egress", filteredEgressPoint())
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800260 .add("constraints", constraints())
Brian O'Connorb876bf12014-10-02 14:59:37 -0700261 .toString();
262 }
263
264}