blob: 1a38bfde7666a1f1938f6b74f362261291a6de4e [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;
Luca Prete670ac5d2017-02-03 15:55:43 -080022import org.onosproject.net.ResourceGroup;
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070023import org.onosproject.net.flow.TrafficSelector;
24import org.onosproject.net.flow.TrafficTreatment;
25
Ray Milkeya2cf3a12018-02-15 16:13:56 -080026import java.util.Collections;
27import java.util.List;
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070028
Sho SHIMIZU2e660802014-11-21 14:55:32 -080029import static com.google.common.base.Preconditions.checkArgument;
toma1d16b62014-10-02 23:45:11 -070030import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connorb876bf12014-10-02 14:59:37 -070031
32/**
33 * Abstraction of point-to-point connectivity.
34 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040035@Beta
Ray Milkeybd4f0112015-03-02 17:07:09 -080036public final class PointToPointIntent extends ConnectivityIntent {
Brian O'Connorb876bf12014-10-02 14:59:37 -070037
Pier Ventreffe88d62016-10-13 14:34:40 -070038 private final FilteredConnectPoint ingressPoint;
39 private final FilteredConnectPoint egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -070040
41 /**
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070042 * Returns a new point to point intent builder. The application id,
43 * ingress point and egress point are required fields. If they are
44 * not set by calls to the appropriate methods, an exception will
45 * be thrown.
46 *
47 * @return point to point builder
48 */
49 public static PointToPointIntent.Builder builder() {
50 return new Builder();
51 }
52
53 /**
54 * Builder of a point to point intent.
55 */
56 public static final class Builder extends ConnectivityIntent.Builder {
Pier Ventreffe88d62016-10-13 14:34:40 -070057 FilteredConnectPoint ingressPoint;
58 FilteredConnectPoint egressPoint;
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070059
60 private Builder() {
61 // Hide constructor
62 }
63
64 @Override
65 public Builder appId(ApplicationId appId) {
66 return (Builder) super.appId(appId);
67 }
68
69 @Override
70 public Builder key(Key key) {
71 return (Builder) super.key(key);
72 }
73
74 @Override
75 public Builder selector(TrafficSelector selector) {
76 return (Builder) super.selector(selector);
77 }
78
79 @Override
80 public Builder treatment(TrafficTreatment treatment) {
81 return (Builder) super.treatment(treatment);
82 }
83
84 @Override
85 public Builder constraints(List<Constraint> constraints) {
86 return (Builder) super.constraints(constraints);
87 }
88
89 @Override
90 public Builder priority(int priority) {
91 return (Builder) super.priority(priority);
92 }
93
Luca Prete670ac5d2017-02-03 15:55:43 -080094 @Override
95 public Builder resourceGroup(ResourceGroup resourceGroup) {
96 return (Builder) super.resourceGroup(resourceGroup);
97 }
98
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070099 /**
Pier Ventreffe88d62016-10-13 14:34:40 -0700100 * Sets the filtered ingress point of the point to
101 * point intent that will be built.
102 *
103 * @param ingressPoint filtered ingress connect point
104 * @return this builder
105 */
106 public Builder filteredIngressPoint(FilteredConnectPoint ingressPoint) {
107 this.ingressPoint = ingressPoint;
108 return this;
109 }
110
111 /**
112 * Sets the filtered egress point of the point to
113 * point intent that will be built.
114 *
115 * @param egressPoint filtered egress connect point
116 * @return this builder
117 */
118 public Builder filteredEgressPoint(FilteredConnectPoint egressPoint) {
Ray Milkey3e3ec5f2015-03-17 17:00:38 -0700119 this.egressPoint = egressPoint;
120 return this;
121 }
122
123 /**
124 * Builds a point to point intent from the accumulated parameters.
125 *
126 * @return point to point intent
127 */
128 public PointToPointIntent build() {
129
130 return new PointToPointIntent(
131 appId,
132 key,
133 selector,
134 treatment,
135 ingressPoint,
136 egressPoint,
137 constraints,
Luca Prete670ac5d2017-02-03 15:55:43 -0800138 priority,
139 resourceGroup
Ray Milkey3e3ec5f2015-03-17 17:00:38 -0700140 );
141 }
142 }
143
144
145
146 /**
Brian O'Connorb876bf12014-10-02 14:59:37 -0700147 * Creates a new point-to-point intent with the supplied ingress/egress
Ray Milkey5b3717e2015-02-05 11:44:08 -0800148 * ports and constraints.
149 *
150 * @param appId application identifier
151 * @param key key of the intent
152 * @param selector traffic selector
153 * @param treatment treatment
Pier Ventreffe88d62016-10-13 14:34:40 -0700154 * @param ingressPoint filtered ingress port
155 * @param egressPoint filtered egress port
Ray Milkey5b3717e2015-02-05 11:44:08 -0800156 * @param constraints optional list of constraints
Ray Milkeyc24cde32015-03-10 18:20:18 -0700157 * @param priority priority to use for flows generated by this intent
Ray Milkey3e3ec5f2015-03-17 17:00:38 -0700158 * @throws NullPointerException if {@code ingressPoint} or
159 * {@code egressPoints} or {@code appId} is null.
Ray Milkey5b3717e2015-02-05 11:44:08 -0800160 */
Ray Milkey3e3ec5f2015-03-17 17:00:38 -0700161 private PointToPointIntent(ApplicationId appId,
Luca Prete670ac5d2017-02-03 15:55:43 -0800162 Key key,
163 TrafficSelector selector,
164 TrafficTreatment treatment,
165 FilteredConnectPoint ingressPoint,
166 FilteredConnectPoint egressPoint,
167 List<Constraint> constraints,
168 int priority,
169 ResourceGroup resourceGroup) {
Ray Milkeyc24cde32015-03-10 18:20:18 -0700170 super(appId, key, Collections.emptyList(), selector, treatment, constraints,
Luca Prete670ac5d2017-02-03 15:55:43 -0800171 priority, resourceGroup);
Ray Milkey5b3717e2015-02-05 11:44:08 -0800172
Ray Milkey5b3717e2015-02-05 11:44:08 -0800173 checkArgument(!ingressPoint.equals(egressPoint),
174 "ingress and egress should be different (ingress: %s, egress: %s)", ingressPoint, egressPoint);
175
Ray Milkeyebc5d222015-03-18 15:45:36 -0700176 this.ingressPoint = checkNotNull(ingressPoint);
177 this.egressPoint = checkNotNull(egressPoint);
Ray Milkey5b3717e2015-02-05 11:44:08 -0800178 }
179
180 /**
Brian O'Connorb876bf12014-10-02 14:59:37 -0700181 * Constructor for serializer.
182 */
183 protected PointToPointIntent() {
184 super();
tom85258ee2014-10-07 00:10:02 -0700185 this.ingressPoint = null;
186 this.egressPoint = null;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700187 }
188
189 /**
Pier Ventreffe88d62016-10-13 14:34:40 -0700190 * Returns the filtered port on which the ingress traffic should be connected to the
191 * egress.
192 *
193 * @return ingress port
194 */
195 public FilteredConnectPoint filteredIngressPoint() {
196 return ingressPoint;
197 }
198
199 /**
200 * Return the filtered port on which the traffic should exit.
201 *
202 * @return egress port
203 */
204 public FilteredConnectPoint filteredEgressPoint() {
tom85258ee2014-10-07 00:10:02 -0700205 return egressPoint;
Brian O'Connorb876bf12014-10-02 14:59:37 -0700206 }
207
208 @Override
Brian O'Connorb876bf12014-10-02 14:59:37 -0700209 public String toString() {
210 return MoreObjects.toStringHelper(getClass())
tom85258ee2014-10-07 00:10:02 -0700211 .add("id", id())
Ray Milkeyc3573812015-02-09 09:18:34 -0800212 .add("key", key())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700213 .add("appId", appId())
Ray Milkeyc24cde32015-03-10 18:20:18 -0700214 .add("priority", priority())
Jonathan Hart23b5a762015-01-26 14:47:33 -0800215 .add("resources", resources())
Thomas Vachuskae291c842014-10-21 02:52:38 -0700216 .add("selector", selector())
217 .add("treatment", treatment())
Pier Ventreffe88d62016-10-13 14:34:40 -0700218 .add("ingress", filteredIngressPoint())
219 .add("egress", filteredEgressPoint())
Thomas Vachuskaedc944c2014-11-04 15:42:25 -0800220 .add("constraints", constraints())
Luca Prete670ac5d2017-02-03 15:55:43 -0800221 .add("resourceGroup", resourceGroup())
Brian O'Connorb876bf12014-10-02 14:59:37 -0700222 .toString();
223 }
224
225}