blob: 9a2c49aafd9187fa9ac229f10c53b7866a9f3d91 [file] [log] [blame]
janani bf41dec32017-03-24 18:44:07 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
janani bf41dec32017-03-24 18:44:07 +05303 *
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.l3vpn.netl3vpn;
18
19import org.onosproject.net.DeviceId;
janani bf7060cd2017-03-28 19:06:30 +053020import org.onosproject.net.driver.DriverHandler;
janani bf41dec32017-03-24 18:44:07 +053021import org.onosproject.net.driver.DriverService;
22import org.onosproject.yang.model.ModelObjectData;
23
24import java.util.LinkedList;
25import java.util.List;
26
27/**
28 * Representation of standard device model, with interface, instance and its
29 * respective device id.
30 */
31public class DeviceInfo {
32
33 /**
34 * Device id of the device.
35 */
36 private final DeviceId deviceId;
37
38 /**
janani b9ed76be2017-08-29 19:11:33 +053039 * Type of the VPN.
40 */
41 private final VpnType type;
42
43 /**
janani bf41dec32017-03-24 18:44:07 +053044 * BGP information of the device.
45 */
46 private BgpInfo bgpInfo;
47
48 /**
49 * List of interface names of the device.
50 */
51 private List<String> ifNames;
52
53 /**
54 * List of network access of the device.
55 */
56 private List<AccessInfo> accesses;
57
58 /**
janani b9ed76be2017-08-29 19:11:33 +053059 * List of tunnel names belonging to the device.
60 */
61 private List<String> tnlNames;
62
63 /**
64 * Status of tunnel policy being created for this device in this VPN.
65 */
66 private boolean isTnlPolCreated;
67
68 /**
69 * Constructs device info with a device id and VPN type.
janani bf41dec32017-03-24 18:44:07 +053070 *
71 * @param d device id
janani b9ed76be2017-08-29 19:11:33 +053072 * @param t VPN type
janani bf41dec32017-03-24 18:44:07 +053073 */
janani b9ed76be2017-08-29 19:11:33 +053074 public DeviceInfo(DeviceId d, VpnType t) {
janani bf41dec32017-03-24 18:44:07 +053075 deviceId = d;
janani b9ed76be2017-08-29 19:11:33 +053076 type = t;
janani bf41dec32017-03-24 18:44:07 +053077 }
78
79 /**
80 * Returns the device id.
81 *
82 * @return device id
83 */
janani b35f6cbc2017-03-24 21:56:58 +053084 public DeviceId deviceId() {
janani bf41dec32017-03-24 18:44:07 +053085 return deviceId;
86 }
87
88 /**
janani b9ed76be2017-08-29 19:11:33 +053089 * Returns the type of the VPN instance.
90 *
91 * @return VPN type
92 */
93 public VpnType type() {
94 return type;
95 }
96
97 /**
janani bf41dec32017-03-24 18:44:07 +053098 * Adds a interface name to the list.
99 *
100 * @param ifName interface name
101 */
janani b35f6cbc2017-03-24 21:56:58 +0530102 public void addIfName(String ifName) {
janani bf41dec32017-03-24 18:44:07 +0530103 if (ifNames == null) {
104 ifNames = new LinkedList<>();
105 }
106 ifNames.add(ifName);
107 }
108
109 /**
110 * Returns the list of interface name.
111 *
112 * @return interface names
113 */
janani b35f6cbc2017-03-24 21:56:58 +0530114 public List<String> ifNames() {
janani bf41dec32017-03-24 18:44:07 +0530115 return ifNames;
116 }
117
118 /**
119 * Sets the list of interface name.
120 *
121 * @param ifNames interface names
122 */
janani b35f6cbc2017-03-24 21:56:58 +0530123 public void ifNames(List<String> ifNames) {
janani bf41dec32017-03-24 18:44:07 +0530124 this.ifNames = ifNames;
125 }
126
janani b9ed76be2017-08-29 19:11:33 +0530127 /***
128 * Returns the list of tunnel names.
129 *
130 * @return tunnel names
131 */
132 public List<String> tnlNames() {
133 return tnlNames;
134 }
135
136 /**
137 * Sets the list of tunnel names.
138 *
139 * @param tnlNames tunnel names
140 */
141 public void tnlNames(List<String> tnlNames) {
142 this.tnlNames = tnlNames;
143 }
144
145 /**
146 * Adds a tunnel name to the list.
147 *
148 * @param tnlName tunnel name
149 */
150 public void addTnlName(String tnlName) {
151 if (tnlNames == null) {
152 tnlNames = new LinkedList<>();
153 }
154 tnlNames.add(tnlName);
155 }
156
157 /**
158 * Returns true if tunnel policy is created for this device in this VPN;
159 * false otherwise.
160 *
161 * @return true if tunnel policy is created; false otherwise
162 */
163 public boolean isTnlPolCreated() {
164 return isTnlPolCreated;
165 }
166
167 /**
168 * Sets true if tunnel policy is created for this device in this VPN;
169 * false otherwise.
170 *
171 * @param tnlPolCreated status of tunnel policy creation
172 */
173 public void setTnlPolCreated(boolean tnlPolCreated) {
174 isTnlPolCreated = tnlPolCreated;
175 }
176
janani bf41dec32017-03-24 18:44:07 +0530177 /**
178 * Returns the BGP information.
179 *
180 * @return BGP info
181 */
janani b35f6cbc2017-03-24 21:56:58 +0530182 public BgpInfo bgpInfo() {
janani bf41dec32017-03-24 18:44:07 +0530183 return bgpInfo;
184 }
185
186 /**
187 * Sets the BGP information.
188 *
189 * @param bgpInfo BGP info
190 */
janani b35f6cbc2017-03-24 21:56:58 +0530191 public void bgpInfo(BgpInfo bgpInfo) {
janani bf41dec32017-03-24 18:44:07 +0530192 this.bgpInfo = bgpInfo;
193 }
194
195 /**
196 * Returns the list of network accesses.
197 *
198 * @return network accesses
199 */
janani b35f6cbc2017-03-24 21:56:58 +0530200 public List<AccessInfo> accesses() {
janani bf41dec32017-03-24 18:44:07 +0530201 return accesses;
202 }
203
204 /**
205 * Sets the list of network accesses.
206 *
207 * @param accesses network accesses
208 */
janani b35f6cbc2017-03-24 21:56:58 +0530209 public void accesses(List<AccessInfo> accesses) {
janani bf41dec32017-03-24 18:44:07 +0530210 this.accesses = accesses;
211 }
212
213 /**
214 * Adds a access info to the network accesses list.
215 *
216 * @param accessInfo access info
217 */
janani b35f6cbc2017-03-24 21:56:58 +0530218 public void addAccessInfo(AccessInfo accessInfo) {
janani bf41dec32017-03-24 18:44:07 +0530219 if (accesses == null) {
220 accesses = new LinkedList<>();
221 }
222 accesses.add(accessInfo);
223 }
224
225 /**
226 * Processes the creation of VPN instance to the driver with the model
227 * object data of standard device model. It returns the VPN instance of
228 * driver constructed model object data.
229 *
230 * @param driverSvc driver service
231 * @param modelData std device model object data
232 * @return driver instance model object data
233 */
janani b35f6cbc2017-03-24 21:56:58 +0530234 public ModelObjectData processCreateInstance(DriverService driverSvc,
235 ModelObjectData modelData) {
janani bd821b182017-03-30 16:34:49 +0530236 L3VpnConfig config = getL3VpnConfig(driverSvc);
janani b9ed76be2017-08-29 19:11:33 +0530237 return config.createInstance(modelData);
janani bf41dec32017-03-24 18:44:07 +0530238 }
239
240 /**
241 * Processes the creation of interface to the driver with the model
242 * object data of standard device model. It returns the interface of driver
243 * constructed model object data.
244 *
245 * @param driverSvc driver service
246 * @param modData std device model object data
247 * @return driver interface model object data
248 */
janani b35f6cbc2017-03-24 21:56:58 +0530249 public ModelObjectData processCreateInterface(DriverService driverSvc,
250 ModelObjectData modData) {
janani bd821b182017-03-30 16:34:49 +0530251 L3VpnConfig config = getL3VpnConfig(driverSvc);
janani b9ed76be2017-08-29 19:11:33 +0530252 return config.bindInterface(modData);
janani bf41dec32017-03-24 18:44:07 +0530253 }
254
255 /**
256 * Processes the creation of BGP info to the driver with the BGP info and
257 * the BGP driver configuration. It returns the BGP info of driver
258 * constructed model object data.
259 *
260 * @param driverSvc driver service
261 * @param bgpInfo BGP info
262 * @param driverInfo driver config details
263 * @return driver BGP model object data
264 */
janani b35f6cbc2017-03-24 21:56:58 +0530265 public ModelObjectData processCreateBgpInfo(DriverService driverSvc,
266 BgpInfo bgpInfo,
267 BgpDriverInfo driverInfo) {
janani bd821b182017-03-30 16:34:49 +0530268 L3VpnConfig config = getL3VpnConfig(driverSvc);
janani b9ed76be2017-08-29 19:11:33 +0530269 return config.createBgpInfo(bgpInfo, driverInfo);
270 }
271
272 /**
273 * Processes the creation of tunnel tree from the devices and device
274 * level. It returns the tunnel info with devices and device of driver
275 * constructed model object data.
276 *
277 * @param driverSvc driver service
278 * @param tnlInfo tunnel info
279 * @return driver model object data of tunnel info with devices and device
280 */
281 public ModelObjectData processCreateTnlDev(DriverService driverSvc,
282 TunnelInfo tnlInfo) {
283 L3VpnConfig config = getL3VpnConfig(driverSvc);
284 return config.createTnlDev(tnlInfo);
285 }
286
287 /**
288 * Processes the creation of tunnel policy in the tree from the tunnel
289 * manager or tunnel policy level. It returns the tunnel info with
290 * tunnel policy level of driver constructed model object data.
291 *
292 * @param driverSvc driver service
293 * @param tnlInfo tunnel info
294 * @return driver model object data of tunnel info with tunnel policy
295 */
296 public ModelObjectData processCreateTnlPol(DriverService driverSvc,
297 TunnelInfo tnlInfo) {
298 L3VpnConfig config = getL3VpnConfig(driverSvc);
299 return config.createTnlPol(tnlInfo);
300 }
301
302 /**
303 * Processes the creation of tunnel in the tree from the tunnel next hops
304 * or only tunnel next hop. It returns the tunnel info with tunnel level
305 * of driver constructed model object data
306 *
307 * @param driverSvc driver service
308 * @param tnlInfo tunnel info
309 * @return driver model object data of tunnel info with tunnel
310 */
311 public ModelObjectData processCreateTnl(DriverService driverSvc,
312 TunnelInfo tnlInfo) {
313 L3VpnConfig config = getL3VpnConfig(driverSvc);
314 return config.createTnl(tnlInfo);
315 }
316
317 /**
318 * Processes the binding of tunnel policy to the VPN instance. It returns
319 * the VPN instance with tunnel policy of driver constructed model object
320 * data.
321 *
322 * @param driverSvc driver service
323 * @param tnlInfo tunnel info
324 * @return driver model object data of VPN instance with tunnel
325 */
326 public ModelObjectData processBindTnl(DriverService driverSvc,
327 TunnelInfo tnlInfo) {
328 L3VpnConfig config = getL3VpnConfig(driverSvc);
329 return config.bindTnl(tnlInfo);
janani bf41dec32017-03-24 18:44:07 +0530330 }
331
332 /**
333 * Processes the deletion of VPN instance to the driver with the model
334 * object data of standard device model. It returns the VPN instance of
335 * driver constructed model object data.
336 *
337 * @param driverSvc driver service
338 * @param modData model object data
339 * @return driver instance model object data
340 */
janani b35f6cbc2017-03-24 21:56:58 +0530341 public ModelObjectData processDeleteInstance(DriverService driverSvc,
janani bf7060cd2017-03-28 19:06:30 +0530342 ModelObjectData modData) {
janani bd821b182017-03-30 16:34:49 +0530343 L3VpnConfig config = getL3VpnConfig(driverSvc);
janani b9ed76be2017-08-29 19:11:33 +0530344 return config.deleteInstance(modData);
janani bf41dec32017-03-24 18:44:07 +0530345 }
346
347 /**
348 * Processes the deletion of interface to the driver with the model
349 * object data of standard device model. It returns the interface of driver
350 * constructed model object data.
351 *
352 * @param driverSvc driver service
353 * @param objectData model object data
354 * @return driver interface model object data
355 */
janani b35f6cbc2017-03-24 21:56:58 +0530356 public ModelObjectData processDeleteInterface(DriverService driverSvc,
janani bf7060cd2017-03-28 19:06:30 +0530357 ModelObjectData objectData) {
janani bf41dec32017-03-24 18:44:07 +0530358 // TODO: Need to call the behaviour.
359 return null;
360 }
361
362 /**
363 * Processes the deletion of BGP info to the driver with the BGP info and
364 * the BGP driver configuration. It returns the BGP info of driver
365 * constructed model object data.
366 *
367 * @param driverSvc driver service
368 * @param bgpInfo BGP info
369 * @param driverInfo driver config details
370 * @return driver BGP model object data
371 */
janani b35f6cbc2017-03-24 21:56:58 +0530372 public ModelObjectData processDeleteBgpInfo(DriverService driverSvc,
janani bf7060cd2017-03-28 19:06:30 +0530373 BgpInfo bgpInfo,
374 BgpDriverInfo driverInfo) {
janani bd821b182017-03-30 16:34:49 +0530375 L3VpnConfig config = getL3VpnConfig(driverSvc);
janani b9ed76be2017-08-29 19:11:33 +0530376 return config.deleteBgpInfo(bgpInfo, driverInfo);
377 }
378
379 /**
380 * Processes the deletion of tunnel info according to the levels it has
381 * to be deleted. It returns the tunnel info of driver constructed model
382 * object data.
383 *
384 * @param driverSvc driver service
385 * @param tnlInfo tunnel info
386 * @return driver tunnel info model object data
387 */
388 public ModelObjectData processDeleteTnl(DriverService driverSvc,
389 TunnelInfo tnlInfo) {
390 L3VpnConfig config = getL3VpnConfig(driverSvc);
391 return config.deleteTnl(tnlInfo);
janani bf41dec32017-03-24 18:44:07 +0530392 }
janani bf7060cd2017-03-28 19:06:30 +0530393
394 /**
395 * Returns the L3VPN config instance from the behaviour.
396 *
397 * @param driverSvc driver service
398 * @return L3VPN config
399 */
janani bd821b182017-03-30 16:34:49 +0530400 private L3VpnConfig getL3VpnConfig(DriverService driverSvc) {
janani bf7060cd2017-03-28 19:06:30 +0530401 DriverHandler handler = driverSvc.createHandler(deviceId);
janani bd821b182017-03-30 16:34:49 +0530402 return handler.behaviour(L3VpnConfig.class);
janani bf7060cd2017-03-28 19:06:30 +0530403 }
janani bf41dec32017-03-24 18:44:07 +0530404}