janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 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 | |
| 17 | package org.onosproject.l3vpn.netl3vpn; |
| 18 | |
| 19 | import org.onosproject.net.DeviceId; |
janani b | f7060cd | 2017-03-28 19:06:30 +0530 | [diff] [blame] | 20 | import org.onosproject.net.driver.DriverHandler; |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 21 | import org.onosproject.net.driver.DriverService; |
| 22 | import org.onosproject.yang.model.ModelObjectData; |
| 23 | |
| 24 | import java.util.LinkedList; |
| 25 | import java.util.List; |
| 26 | |
| 27 | /** |
| 28 | * Representation of standard device model, with interface, instance and its |
| 29 | * respective device id. |
| 30 | */ |
| 31 | public class DeviceInfo { |
| 32 | |
| 33 | /** |
| 34 | * Device id of the device. |
| 35 | */ |
| 36 | private final DeviceId deviceId; |
| 37 | |
| 38 | /** |
janani b | 9ed76be | 2017-08-29 19:11:33 +0530 | [diff] [blame] | 39 | * Type of the VPN. |
| 40 | */ |
| 41 | private final VpnType type; |
| 42 | |
| 43 | /** |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 44 | * 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 b | 9ed76be | 2017-08-29 19:11:33 +0530 | [diff] [blame] | 59 | * 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 b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 70 | * |
| 71 | * @param d device id |
janani b | 9ed76be | 2017-08-29 19:11:33 +0530 | [diff] [blame] | 72 | * @param t VPN type |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 73 | */ |
janani b | 9ed76be | 2017-08-29 19:11:33 +0530 | [diff] [blame] | 74 | public DeviceInfo(DeviceId d, VpnType t) { |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 75 | deviceId = d; |
janani b | 9ed76be | 2017-08-29 19:11:33 +0530 | [diff] [blame] | 76 | type = t; |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Returns the device id. |
| 81 | * |
| 82 | * @return device id |
| 83 | */ |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 84 | public DeviceId deviceId() { |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 85 | return deviceId; |
| 86 | } |
| 87 | |
| 88 | /** |
janani b | 9ed76be | 2017-08-29 19:11:33 +0530 | [diff] [blame] | 89 | * Returns the type of the VPN instance. |
| 90 | * |
| 91 | * @return VPN type |
| 92 | */ |
| 93 | public VpnType type() { |
| 94 | return type; |
| 95 | } |
| 96 | |
| 97 | /** |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 98 | * Adds a interface name to the list. |
| 99 | * |
| 100 | * @param ifName interface name |
| 101 | */ |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 102 | public void addIfName(String ifName) { |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 103 | 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 b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 114 | public List<String> ifNames() { |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 115 | return ifNames; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Sets the list of interface name. |
| 120 | * |
| 121 | * @param ifNames interface names |
| 122 | */ |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 123 | public void ifNames(List<String> ifNames) { |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 124 | this.ifNames = ifNames; |
| 125 | } |
| 126 | |
janani b | 9ed76be | 2017-08-29 19:11:33 +0530 | [diff] [blame] | 127 | /*** |
| 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 b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 177 | /** |
| 178 | * Returns the BGP information. |
| 179 | * |
| 180 | * @return BGP info |
| 181 | */ |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 182 | public BgpInfo bgpInfo() { |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 183 | return bgpInfo; |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * Sets the BGP information. |
| 188 | * |
| 189 | * @param bgpInfo BGP info |
| 190 | */ |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 191 | public void bgpInfo(BgpInfo bgpInfo) { |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 192 | this.bgpInfo = bgpInfo; |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * Returns the list of network accesses. |
| 197 | * |
| 198 | * @return network accesses |
| 199 | */ |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 200 | public List<AccessInfo> accesses() { |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 201 | return accesses; |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * Sets the list of network accesses. |
| 206 | * |
| 207 | * @param accesses network accesses |
| 208 | */ |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 209 | public void accesses(List<AccessInfo> accesses) { |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 210 | this.accesses = accesses; |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * Adds a access info to the network accesses list. |
| 215 | * |
| 216 | * @param accessInfo access info |
| 217 | */ |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 218 | public void addAccessInfo(AccessInfo accessInfo) { |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 219 | 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 b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 234 | public ModelObjectData processCreateInstance(DriverService driverSvc, |
| 235 | ModelObjectData modelData) { |
janani b | d821b18 | 2017-03-30 16:34:49 +0530 | [diff] [blame] | 236 | L3VpnConfig config = getL3VpnConfig(driverSvc); |
janani b | 9ed76be | 2017-08-29 19:11:33 +0530 | [diff] [blame] | 237 | return config.createInstance(modelData); |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 238 | } |
| 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 b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 249 | public ModelObjectData processCreateInterface(DriverService driverSvc, |
| 250 | ModelObjectData modData) { |
janani b | d821b18 | 2017-03-30 16:34:49 +0530 | [diff] [blame] | 251 | L3VpnConfig config = getL3VpnConfig(driverSvc); |
janani b | 9ed76be | 2017-08-29 19:11:33 +0530 | [diff] [blame] | 252 | return config.bindInterface(modData); |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 253 | } |
| 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 b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 265 | public ModelObjectData processCreateBgpInfo(DriverService driverSvc, |
| 266 | BgpInfo bgpInfo, |
| 267 | BgpDriverInfo driverInfo) { |
janani b | d821b18 | 2017-03-30 16:34:49 +0530 | [diff] [blame] | 268 | L3VpnConfig config = getL3VpnConfig(driverSvc); |
janani b | 9ed76be | 2017-08-29 19:11:33 +0530 | [diff] [blame] | 269 | 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 b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 330 | } |
| 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 b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 341 | public ModelObjectData processDeleteInstance(DriverService driverSvc, |
janani b | f7060cd | 2017-03-28 19:06:30 +0530 | [diff] [blame] | 342 | ModelObjectData modData) { |
janani b | d821b18 | 2017-03-30 16:34:49 +0530 | [diff] [blame] | 343 | L3VpnConfig config = getL3VpnConfig(driverSvc); |
janani b | 9ed76be | 2017-08-29 19:11:33 +0530 | [diff] [blame] | 344 | return config.deleteInstance(modData); |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 345 | } |
| 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 b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 356 | public ModelObjectData processDeleteInterface(DriverService driverSvc, |
janani b | f7060cd | 2017-03-28 19:06:30 +0530 | [diff] [blame] | 357 | ModelObjectData objectData) { |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 358 | // 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 b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 372 | public ModelObjectData processDeleteBgpInfo(DriverService driverSvc, |
janani b | f7060cd | 2017-03-28 19:06:30 +0530 | [diff] [blame] | 373 | BgpInfo bgpInfo, |
| 374 | BgpDriverInfo driverInfo) { |
janani b | d821b18 | 2017-03-30 16:34:49 +0530 | [diff] [blame] | 375 | L3VpnConfig config = getL3VpnConfig(driverSvc); |
janani b | 9ed76be | 2017-08-29 19:11:33 +0530 | [diff] [blame] | 376 | 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 b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 392 | } |
janani b | f7060cd | 2017-03-28 19:06:30 +0530 | [diff] [blame] | 393 | |
| 394 | /** |
| 395 | * Returns the L3VPN config instance from the behaviour. |
| 396 | * |
| 397 | * @param driverSvc driver service |
| 398 | * @return L3VPN config |
| 399 | */ |
janani b | d821b18 | 2017-03-30 16:34:49 +0530 | [diff] [blame] | 400 | private L3VpnConfig getL3VpnConfig(DriverService driverSvc) { |
janani b | f7060cd | 2017-03-28 19:06:30 +0530 | [diff] [blame] | 401 | DriverHandler handler = driverSvc.createHandler(deviceId); |
janani b | d821b18 | 2017-03-30 16:34:49 +0530 | [diff] [blame] | 402 | return handler.behaviour(L3VpnConfig.class); |
janani b | f7060cd | 2017-03-28 19:06:30 +0530 | [diff] [blame] | 403 | } |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 404 | } |