blob: 817db21fc2cd81813501132c120c47525021e0b6 [file] [log] [blame]
Brian Stanke11f6d532016-07-05 16:17:59 -04001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Brian Stanke11f6d532016-07-05 16:17:59 -04003 *
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
7 *
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.
15 */
16
17package org.onosproject.incubator.net.virtual;
18
19import com.google.common.annotations.Beta;
20import com.google.common.base.MoreObjects;
21import org.onosproject.core.ApplicationId;
22import org.onosproject.net.ConnectPoint;
Luca Prete670ac5d2017-02-03 15:55:43 -080023import org.onosproject.net.ResourceGroup;
Brian Stanke11f6d532016-07-05 16:17:59 -040024import org.onosproject.net.flow.TrafficSelector;
25import org.onosproject.net.flow.TrafficTreatment;
26import org.onosproject.net.intent.ConnectivityIntent;
27import org.onosproject.net.intent.Constraint;
28import org.onosproject.net.intent.Key;
29
30import java.util.Collections;
31import java.util.List;
32
33import static com.google.common.base.Preconditions.checkArgument;
34import static com.google.common.base.Preconditions.checkNotNull;
35
36/**
37 * Abstraction of VirtualNetworkIntent connectivity.
38 */
39@Beta
40public final class VirtualNetworkIntent extends ConnectivityIntent {
41
42 private final NetworkId networkId;
43 private final ConnectPoint ingressPoint;
44 private final ConnectPoint egressPoint;
45
46 private static final String NETWORK_ID_NULL = "Network ID cannot be null";
47
48 /**
49 * Returns a new point to point intent builder. The application id,
50 * ingress point and egress point are required fields. If they are
51 * not set by calls to the appropriate methods, an exception will
52 * be thrown.
53 *
54 * @return point to point builder
55 */
56 public static VirtualNetworkIntent.Builder builder() {
57 return new VirtualNetworkIntent.Builder();
58 }
59
60 /**
61 * Builder of a point to point intent.
62 */
63 public static final class Builder extends ConnectivityIntent.Builder {
64 NetworkId networkId;
65 ConnectPoint ingressPoint;
66 ConnectPoint egressPoint;
67
68 /**
69 * Builder constructor.
70 */
71 private Builder() {
72 // Hide constructor
73 }
74
75 @Override
Luca Prete670ac5d2017-02-03 15:55:43 -080076 public Builder appId(ApplicationId appId) {
77 return (Builder) super.appId(appId);
Brian Stanke11f6d532016-07-05 16:17:59 -040078 }
79
80 @Override
Luca Prete670ac5d2017-02-03 15:55:43 -080081 public Builder key(Key key) {
82 return (Builder) super.key(key);
Brian Stanke11f6d532016-07-05 16:17:59 -040083 }
84
85 @Override
Luca Prete670ac5d2017-02-03 15:55:43 -080086 public Builder selector(TrafficSelector selector) {
87 return (Builder) super.selector(selector);
Brian Stanke11f6d532016-07-05 16:17:59 -040088 }
89
90 @Override
Luca Prete670ac5d2017-02-03 15:55:43 -080091 public Builder treatment(TrafficTreatment treatment) {
92 return (Builder) super.treatment(treatment);
Brian Stanke11f6d532016-07-05 16:17:59 -040093 }
94
95 @Override
Luca Prete670ac5d2017-02-03 15:55:43 -080096 public Builder constraints(List<Constraint> constraints) {
97 return (Builder) super.constraints(constraints);
Brian Stanke11f6d532016-07-05 16:17:59 -040098 }
99
100 @Override
Luca Prete670ac5d2017-02-03 15:55:43 -0800101 public Builder priority(int priority) {
102 return (Builder) super.priority(priority);
103 }
104
105 @Override
106 public Builder resourceGroup(ResourceGroup resourceGroup) {
107 return (Builder) super.resourceGroup(resourceGroup);
Brian Stanke11f6d532016-07-05 16:17:59 -0400108 }
109
110 /**
111 * Sets the virtual network of the virtual network intent.
112 *
113 * @param networkId virtual network identifier
114 * @return this builder
115 */
116 public VirtualNetworkIntent.Builder networkId(NetworkId networkId) {
117 this.networkId = networkId;
118 return this;
119 }
120
121 /**
122 * Sets the ingress point of the virtual network intent that will be built.
123 *
124 * @param ingressPoint ingress connect point
125 * @return this builder
126 */
127 public VirtualNetworkIntent.Builder ingressPoint(ConnectPoint ingressPoint) {
128 this.ingressPoint = ingressPoint;
129 return this;
130 }
131
132 /**
133 * Sets the egress point of the virtual network intent that will be built.
134 *
135 * @param egressPoint egress connect point
136 * @return this builder
137 */
138 public VirtualNetworkIntent.Builder egressPoint(ConnectPoint egressPoint) {
139 this.egressPoint = egressPoint;
140 return this;
141 }
142
143 /**
144 * Builds a virtual network intent from the accumulated parameters.
145 *
146 * @return virtual network intent
147 */
148 public VirtualNetworkIntent build() {
149
150 return new VirtualNetworkIntent(
151 networkId,
152 appId,
153 key,
154 selector,
155 treatment,
156 ingressPoint,
157 egressPoint,
158 constraints,
Luca Prete670ac5d2017-02-03 15:55:43 -0800159 priority,
160 resourceGroup
Brian Stanke11f6d532016-07-05 16:17:59 -0400161 );
162 }
163 }
164
165
166 /**
167 * Creates a new point-to-point intent with the supplied ingress/egress
168 * ports and constraints.
169 *
170 * @param networkId virtual network identifier
171 * @param appId application identifier
172 * @param key key of the intent
173 * @param selector traffic selector
174 * @param treatment treatment
175 * @param ingressPoint ingress port
176 * @param egressPoint egress port
177 * @param constraints optional list of constraints
178 * @param priority priority to use for flows generated by this intent
179 * @throws NullPointerException if {@code ingressPoint} or
180 * {@code egressPoints} or {@code appId} is null.
181 */
182 private VirtualNetworkIntent(NetworkId networkId,
183 ApplicationId appId,
184 Key key,
185 TrafficSelector selector,
186 TrafficTreatment treatment,
187 ConnectPoint ingressPoint,
188 ConnectPoint egressPoint,
189 List<Constraint> constraints,
Luca Prete670ac5d2017-02-03 15:55:43 -0800190 int priority,
191 ResourceGroup resourceGroup) {
Brian Stanke11f6d532016-07-05 16:17:59 -0400192 super(appId, key, Collections.emptyList(), selector, treatment, constraints,
Luca Prete670ac5d2017-02-03 15:55:43 -0800193 priority, resourceGroup);
Brian Stanke11f6d532016-07-05 16:17:59 -0400194
195 checkNotNull(networkId, NETWORK_ID_NULL);
196 checkArgument(!ingressPoint.equals(egressPoint),
197 "ingress and egress should be different (ingress: %s, egress: %s)", ingressPoint, egressPoint);
198
199 this.networkId = networkId;
200 this.ingressPoint = checkNotNull(ingressPoint);
201 this.egressPoint = checkNotNull(egressPoint);
202 }
203
204 /**
205 * Constructor for serializer.
206 */
207 protected VirtualNetworkIntent() {
208 super();
209 this.networkId = null;
210 this.ingressPoint = null;
211 this.egressPoint = null;
212 }
213
214 /**
215 * Returns the virtual network identifier.
216 *
217 * @return network identifier
218 */
219 public NetworkId networkId() {
220 return networkId;
221 }
222
223 /**
224 * Returns the port on which the ingress traffic should be connected to
225 * the egress.
226 *
227 * @return ingress port
228 */
229 public ConnectPoint ingressPoint() {
230 return ingressPoint;
231 }
232
233 /**
234 * Returns the port on which the traffic should egress.
235 *
236 * @return egress port
237 */
238 public ConnectPoint egressPoint() {
239 return egressPoint;
240 }
241
242 @Override
243 public String toString() {
244 return MoreObjects.toStringHelper(getClass())
245 .add("networkId", networkId)
246 .add("id", id())
247 .add("key", key())
248 .add("appId", appId())
249 .add("priority", priority())
250 .add("resources", resources())
251 .add("selector", selector())
252 .add("treatment", treatment())
253 .add("ingress", ingressPoint)
254 .add("egress", egressPoint)
255 .add("constraints", constraints())
Luca Prete670ac5d2017-02-03 15:55:43 -0800256 .add("resourceGroup", resourceGroup())
Brian Stanke11f6d532016-07-05 16:17:59 -0400257 .toString();
258 }
259
260}