blob: 648d556aa90c4556819f5c7ce5d4ec0f1e18d4d8 [file] [log] [blame]
janani bf41dec32017-03-24 18:44:07 +05301/*
2 * Copyright 2017-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.l3vpn.netl3vpn;
18
19import org.onosproject.net.DeviceId;
janani bf7060cd2017-03-28 19:06:30 +053020import org.onosproject.net.behaviour.L3vpnConfig;
21import org.onosproject.net.driver.DriverHandler;
janani bf41dec32017-03-24 18:44:07 +053022import org.onosproject.net.driver.DriverService;
23import org.onosproject.yang.model.ModelObjectData;
24
25import java.util.LinkedList;
26import java.util.List;
27
28/**
29 * Representation of standard device model, with interface, instance and its
30 * respective device id.
31 */
32public class DeviceInfo {
33
34 /**
35 * Device id of the device.
36 */
37 private final DeviceId deviceId;
38
39 /**
40 * BGP information of the device.
41 */
42 private BgpInfo bgpInfo;
43
44 /**
45 * List of interface names of the device.
46 */
47 private List<String> ifNames;
48
49 /**
50 * List of network access of the device.
51 */
52 private List<AccessInfo> accesses;
53
54 /**
55 * Constructs device info with a device id.
56 *
57 * @param d device id
58 */
59 public DeviceInfo(DeviceId d) {
60 deviceId = d;
61 }
62
63 /**
64 * Returns the device id.
65 *
66 * @return device id
67 */
janani b35f6cbc2017-03-24 21:56:58 +053068 public DeviceId deviceId() {
janani bf41dec32017-03-24 18:44:07 +053069 return deviceId;
70 }
71
72 /**
73 * Adds a interface name to the list.
74 *
75 * @param ifName interface name
76 */
janani b35f6cbc2017-03-24 21:56:58 +053077 public void addIfName(String ifName) {
janani bf41dec32017-03-24 18:44:07 +053078 if (ifNames == null) {
79 ifNames = new LinkedList<>();
80 }
81 ifNames.add(ifName);
82 }
83
84 /**
85 * Returns the list of interface name.
86 *
87 * @return interface names
88 */
janani b35f6cbc2017-03-24 21:56:58 +053089 public List<String> ifNames() {
janani bf41dec32017-03-24 18:44:07 +053090 return ifNames;
91 }
92
93 /**
94 * Sets the list of interface name.
95 *
96 * @param ifNames interface names
97 */
janani b35f6cbc2017-03-24 21:56:58 +053098 public void ifNames(List<String> ifNames) {
janani bf41dec32017-03-24 18:44:07 +053099 this.ifNames = ifNames;
100 }
101
102 /**
103 * Returns the BGP information.
104 *
105 * @return BGP info
106 */
janani b35f6cbc2017-03-24 21:56:58 +0530107 public BgpInfo bgpInfo() {
janani bf41dec32017-03-24 18:44:07 +0530108 return bgpInfo;
109 }
110
111 /**
112 * Sets the BGP information.
113 *
114 * @param bgpInfo BGP info
115 */
janani b35f6cbc2017-03-24 21:56:58 +0530116 public void bgpInfo(BgpInfo bgpInfo) {
janani bf41dec32017-03-24 18:44:07 +0530117 this.bgpInfo = bgpInfo;
118 }
119
120 /**
121 * Returns the list of network accesses.
122 *
123 * @return network accesses
124 */
janani b35f6cbc2017-03-24 21:56:58 +0530125 public List<AccessInfo> accesses() {
janani bf41dec32017-03-24 18:44:07 +0530126 return accesses;
127 }
128
129 /**
130 * Sets the list of network accesses.
131 *
132 * @param accesses network accesses
133 */
janani b35f6cbc2017-03-24 21:56:58 +0530134 public void accesses(List<AccessInfo> accesses) {
janani bf41dec32017-03-24 18:44:07 +0530135 this.accesses = accesses;
136 }
137
138 /**
139 * Adds a access info to the network accesses list.
140 *
141 * @param accessInfo access info
142 */
janani b35f6cbc2017-03-24 21:56:58 +0530143 public void addAccessInfo(AccessInfo accessInfo) {
janani bf41dec32017-03-24 18:44:07 +0530144 if (accesses == null) {
145 accesses = new LinkedList<>();
146 }
147 accesses.add(accessInfo);
148 }
149
150 /**
151 * Processes the creation of VPN instance to the driver with the model
152 * object data of standard device model. It returns the VPN instance of
153 * driver constructed model object data.
154 *
155 * @param driverSvc driver service
156 * @param modelData std device model object data
157 * @return driver instance model object data
158 */
janani b35f6cbc2017-03-24 21:56:58 +0530159 public ModelObjectData processCreateInstance(DriverService driverSvc,
160 ModelObjectData modelData) {
janani bf7060cd2017-03-28 19:06:30 +0530161 L3vpnConfig config = getL3VpnConfig(driverSvc);
162 return (ModelObjectData) config.createInstance(modelData);
janani bf41dec32017-03-24 18:44:07 +0530163 }
164
165 /**
166 * Processes the creation of interface to the driver with the model
167 * object data of standard device model. It returns the interface of driver
168 * constructed model object data.
169 *
170 * @param driverSvc driver service
171 * @param modData std device model object data
172 * @return driver interface model object data
173 */
janani b35f6cbc2017-03-24 21:56:58 +0530174 public ModelObjectData processCreateInterface(DriverService driverSvc,
175 ModelObjectData modData) {
janani bf7060cd2017-03-28 19:06:30 +0530176 L3vpnConfig config = getL3VpnConfig(driverSvc);
177 return (ModelObjectData) config.bindInterface(modData);
janani bf41dec32017-03-24 18:44:07 +0530178 }
179
180 /**
181 * Processes the creation of BGP info to the driver with the BGP info and
182 * the BGP driver configuration. It returns the BGP info of driver
183 * constructed model object data.
184 *
185 * @param driverSvc driver service
186 * @param bgpInfo BGP info
187 * @param driverInfo driver config details
188 * @return driver BGP model object data
189 */
janani b35f6cbc2017-03-24 21:56:58 +0530190 public ModelObjectData processCreateBgpInfo(DriverService driverSvc,
191 BgpInfo bgpInfo,
192 BgpDriverInfo driverInfo) {
janani bf7060cd2017-03-28 19:06:30 +0530193 L3vpnConfig config = getL3VpnConfig(driverSvc);
194 return (ModelObjectData) config.createBgpInfo(bgpInfo, driverInfo);
janani bf41dec32017-03-24 18:44:07 +0530195 }
196
197 /**
198 * Processes the deletion of VPN instance to the driver with the model
199 * object data of standard device model. It returns the VPN instance of
200 * driver constructed model object data.
201 *
202 * @param driverSvc driver service
203 * @param modData model object data
204 * @return driver instance model object data
205 */
janani b35f6cbc2017-03-24 21:56:58 +0530206 public ModelObjectData processDeleteInstance(DriverService driverSvc,
janani bf7060cd2017-03-28 19:06:30 +0530207 ModelObjectData modData) {
208 L3vpnConfig config = getL3VpnConfig(driverSvc);
209 return (ModelObjectData) config.deleteInstance(modData);
janani bf41dec32017-03-24 18:44:07 +0530210 }
211
212 /**
213 * Processes the deletion of interface to the driver with the model
214 * object data of standard device model. It returns the interface of driver
215 * constructed model object data.
216 *
217 * @param driverSvc driver service
218 * @param objectData model object data
219 * @return driver interface model object data
220 */
janani b35f6cbc2017-03-24 21:56:58 +0530221 public ModelObjectData processDeleteInterface(DriverService driverSvc,
janani bf7060cd2017-03-28 19:06:30 +0530222 ModelObjectData objectData) {
janani bf41dec32017-03-24 18:44:07 +0530223 // TODO: Need to call the behaviour.
224 return null;
225 }
226
227 /**
228 * Processes the deletion of BGP info to the driver with the BGP info and
229 * the BGP driver configuration. It returns the BGP info of driver
230 * constructed model object data.
231 *
232 * @param driverSvc driver service
233 * @param bgpInfo BGP info
234 * @param driverInfo driver config details
235 * @return driver BGP model object data
236 */
janani b35f6cbc2017-03-24 21:56:58 +0530237 public ModelObjectData processDeleteBgpInfo(DriverService driverSvc,
janani bf7060cd2017-03-28 19:06:30 +0530238 BgpInfo bgpInfo,
239 BgpDriverInfo driverInfo) {
janani bf41dec32017-03-24 18:44:07 +0530240 // TODO: Need to call the behaviour.
241 return null;
242 }
janani bf7060cd2017-03-28 19:06:30 +0530243
244 /**
245 * Returns the L3VPN config instance from the behaviour.
246 *
247 * @param driverSvc driver service
248 * @return L3VPN config
249 */
250 private L3vpnConfig getL3VpnConfig(DriverService driverSvc) {
251 DriverHandler handler = driverSvc.createHandler(deviceId);
252 return handler.behaviour(L3vpnConfig.class);
253 }
janani bf41dec32017-03-24 18:44:07 +0530254}