blob: d0a9d54d06cd72aaba5988df7c0e55857819e29a [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2014-present Open Networking Foundation
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
Brian O'Connor9476fa12015-06-25 15:17:17 -040018import com.google.common.annotations.Beta;
Ray Milkeya2cf3a12018-02-15 16:13:56 -080019import com.google.common.base.MoreObjects;
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070020import org.onosproject.core.ApplicationId;
Pier Ventreffe88d62016-10-13 14:34:40 -070021import org.onosproject.net.FilteredConnectPoint;
Daniele Moro3a6e1512017-12-22 12:14:44 +010022import org.onosproject.net.Link;
Luca Prete670ac5d2017-02-03 15:55:43 -080023import org.onosproject.net.ResourceGroup;
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070024import org.onosproject.net.flow.TrafficSelector;
25import org.onosproject.net.flow.TrafficTreatment;
26
Ray Milkeya2cf3a12018-02-15 16:13:56 -080027import java.util.Collections;
28import java.util.List;
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070029
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
Daniele Moro3a6e1512017-12-22 12:14:44 +010042 private final List<Link> suggestedPath;
43
Brian O'Connorb876bf12014-10-02 14:59:37 -070044 /**
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070045 * 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 Ventreffe88d62016-10-13 14:34:40 -070060 FilteredConnectPoint ingressPoint;
61 FilteredConnectPoint egressPoint;
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070062
Daniele Moro3a6e1512017-12-22 12:14:44 +010063 List<Link> suggestedPath;
64
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070065 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 Prete670ac5d2017-02-03 15:55:43 -080099 @Override
100 public Builder resourceGroup(ResourceGroup resourceGroup) {
101 return (Builder) super.resourceGroup(resourceGroup);
102 }
103
Ray Milkey3e3ec5f2015-03-17 17:00:38 -0700104 /**
Pier Ventreffe88d62016-10-13 14:34:40 -0700105 * 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 Milkey3e3ec5f2015-03-17 17:00:38 -0700124 this.egressPoint = egressPoint;
125 return this;
126 }
127
128 /**
Daniele Moro3a6e1512017-12-22 12:14:44 +0100129 * 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 Milkey3e3ec5f2015-03-17 17:00:38 -0700140 * Builds a point to point intent from the accumulated parameters.
141 *
142 * @return point to point intent
143 */
144 public PointToPointIntent build() {
Daniele Moro3a6e1512017-12-22 12:14:44 +0100145 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 Milkey3e3ec5f2015-03-17 17:00:38 -0700159 return new PointToPointIntent(
160 appId,
161 key,
162 selector,
163 treatment,
164 ingressPoint,
165 egressPoint,
166 constraints,
Luca Prete670ac5d2017-02-03 15:55:43 -0800167 priority,
Daniele Moro3a6e1512017-12-22 12:14:44 +0100168 suggestedPath,
Luca Prete670ac5d2017-02-03 15:55:43 -0800169 resourceGroup
Ray Milkey3e3ec5f2015-03-17 17:00:38 -0700170 );
171 }
172 }
173
174
175
176 /**
Brian O'Connorb876bf12014-10-02 14:59:37 -0700177 * Creates a new point-to-point intent with the supplied ingress/egress
Ray Milkey5b3717e2015-02-05 11:44:08 -0800178 * ports and constraints.
179 *
Daniele Moro3a6e1512017-12-22 12:14:44 +0100180 * @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 Milkey3e3ec5f2015-03-17 17:00:38 -0700189 * @throws NullPointerException if {@code ingressPoint} or
Daniele Moro3a6e1512017-12-22 12:14:44 +0100190 * {@code egressPoints} or {@code appId} is null or {@code path} is null.
Ray Milkey5b3717e2015-02-05 11:44:08 -0800191 */
Ray Milkey3e3ec5f2015-03-17 17:00:38 -0700192 private PointToPointIntent(ApplicationId appId,
Luca Prete670ac5d2017-02-03 15:55:43 -0800193 Key key,
194 TrafficSelector selector,
195 TrafficTreatment treatment,
196 FilteredConnectPoint ingressPoint,
197 FilteredConnectPoint egressPoint,
198 List<Constraint> constraints,
199 int priority,
Daniele Moro3a6e1512017-12-22 12:14:44 +0100200 List<Link> suggestedPath,
Luca Prete670ac5d2017-02-03 15:55:43 -0800201 ResourceGroup resourceGroup) {
Daniele Moro3a6e1512017-12-22 12:14:44 +0100202 super(appId,
203 key,
204 suggestedPath != null ? resources(suggestedPath) : Collections.emptyList(),
205 selector,
206 treatment,
207 constraints,
208 priority,
209 resourceGroup);
Ray Milkey5b3717e2015-02-05 11:44:08 -0800210
Ray Milkey5b3717e2015-02-05 11:44:08 -0800211 checkArgument(!ingressPoint.equals(egressPoint),
212 "ingress and egress should be different (ingress: %s, egress: %s)", ingressPoint, egressPoint);
213
Ray Milkeyebc5d222015-03-18 15:45:36 -0700214 this.ingressPoint = checkNotNull(ingressPoint);
215 this.egressPoint = checkNotNull(egressPoint);
Daniele Moro3a6e1512017-12-22 12:14:44 +0100216 this.suggestedPath = suggestedPath;
217
Ray Milkey5b3717e2015-02-05 11:44:08 -0800218 }
219
220 /**
Brian O'Connorb876bf12014-10-02 14:59:37 -0700221 * Constructor for serializer.
222 */
223 protected PointToPointIntent() {
224 super();
tom85258ee2014-10-07 00:10:02 -0700225 this.ingressPoint = null;
226 this.egressPoint = null;
Daniele Moro3a6e1512017-12-22 12:14:44 +0100227 this.suggestedPath = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700228 }
229
230 /**
Pier Ventreffe88d62016-10-13 14:34:40 -0700231 * 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() {
tom85258ee2014-10-07 00:10:02 -0700246 return egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700247 }
248
Daniele Moro3a6e1512017-12-22 12:14:44 +0100249
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'Connorb876bf12014-10-02 14:59:37 -0700259 @Override
Brian O'Connorb876bf12014-10-02 14:59:37 -0700260 public String toString() {
261 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700262 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800263 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700264 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700265 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800266 .add("resources", resources())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700267 .add("selector", selector())
268 .add("treatment", treatment())
Pier Ventreffe88d62016-10-13 14:34:40 -0700269 .add("ingress", filteredIngressPoint())
270 .add("egress", filteredEgressPoint())
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800271 .add("constraints", constraints())
Daniele Moro3a6e1512017-12-22 12:14:44 +0100272 .add("links", suggestedPath())
Luca Prete670ac5d2017-02-03 15:55:43 -0800273 .add("resourceGroup", resourceGroup())
Brian O'Connorb876bf12014-10-02 14:59:37 -0700274 .toString();
275 }
276
277}