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