janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.l3vpn.netl3vpn; |
| 18 | |
| 19 | import org.onosproject.net.DeviceId; |
janani b | d821b18 | 2017-03-30 16:34:49 +0530 | [diff] [blame] | 20 | import org.onosproject.net.behaviour.L3VpnConfig; |
janani b | f7060cd | 2017-03-28 19:06:30 +0530 | [diff] [blame] | 21 | import org.onosproject.net.driver.DriverHandler; |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 22 | import org.onosproject.net.driver.DriverService; |
| 23 | import org.onosproject.yang.model.ModelObjectData; |
| 24 | |
| 25 | import java.util.LinkedList; |
| 26 | import java.util.List; |
| 27 | |
| 28 | /** |
| 29 | * Representation of standard device model, with interface, instance and its |
| 30 | * respective device id. |
| 31 | */ |
| 32 | public 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 b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 68 | public DeviceId deviceId() { |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 69 | return deviceId; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Adds a interface name to the list. |
| 74 | * |
| 75 | * @param ifName interface name |
| 76 | */ |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 77 | public void addIfName(String ifName) { |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 78 | 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 b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 89 | public List<String> ifNames() { |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 90 | return ifNames; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Sets the list of interface name. |
| 95 | * |
| 96 | * @param ifNames interface names |
| 97 | */ |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 98 | public void ifNames(List<String> ifNames) { |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 99 | this.ifNames = ifNames; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Returns the BGP information. |
| 104 | * |
| 105 | * @return BGP info |
| 106 | */ |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 107 | public BgpInfo bgpInfo() { |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 108 | return bgpInfo; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Sets the BGP information. |
| 113 | * |
| 114 | * @param bgpInfo BGP info |
| 115 | */ |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 116 | public void bgpInfo(BgpInfo bgpInfo) { |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 117 | this.bgpInfo = bgpInfo; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Returns the list of network accesses. |
| 122 | * |
| 123 | * @return network accesses |
| 124 | */ |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 125 | public List<AccessInfo> accesses() { |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 126 | return accesses; |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Sets the list of network accesses. |
| 131 | * |
| 132 | * @param accesses network accesses |
| 133 | */ |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 134 | public void accesses(List<AccessInfo> accesses) { |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 135 | this.accesses = accesses; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Adds a access info to the network accesses list. |
| 140 | * |
| 141 | * @param accessInfo access info |
| 142 | */ |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 143 | public void addAccessInfo(AccessInfo accessInfo) { |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 144 | 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 b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 159 | public ModelObjectData processCreateInstance(DriverService driverSvc, |
| 160 | ModelObjectData modelData) { |
janani b | d821b18 | 2017-03-30 16:34:49 +0530 | [diff] [blame] | 161 | L3VpnConfig config = getL3VpnConfig(driverSvc); |
janani b | f7060cd | 2017-03-28 19:06:30 +0530 | [diff] [blame] | 162 | return (ModelObjectData) config.createInstance(modelData); |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 163 | } |
| 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 b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 174 | public ModelObjectData processCreateInterface(DriverService driverSvc, |
| 175 | ModelObjectData modData) { |
janani b | d821b18 | 2017-03-30 16:34:49 +0530 | [diff] [blame] | 176 | L3VpnConfig config = getL3VpnConfig(driverSvc); |
janani b | f7060cd | 2017-03-28 19:06:30 +0530 | [diff] [blame] | 177 | return (ModelObjectData) config.bindInterface(modData); |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 178 | } |
| 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 b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 190 | public ModelObjectData processCreateBgpInfo(DriverService driverSvc, |
| 191 | BgpInfo bgpInfo, |
| 192 | BgpDriverInfo driverInfo) { |
janani b | d821b18 | 2017-03-30 16:34:49 +0530 | [diff] [blame] | 193 | L3VpnConfig config = getL3VpnConfig(driverSvc); |
janani b | f7060cd | 2017-03-28 19:06:30 +0530 | [diff] [blame] | 194 | return (ModelObjectData) config.createBgpInfo(bgpInfo, driverInfo); |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 195 | } |
| 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 b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 206 | public ModelObjectData processDeleteInstance(DriverService driverSvc, |
janani b | f7060cd | 2017-03-28 19:06:30 +0530 | [diff] [blame] | 207 | ModelObjectData modData) { |
janani b | d821b18 | 2017-03-30 16:34:49 +0530 | [diff] [blame] | 208 | L3VpnConfig config = getL3VpnConfig(driverSvc); |
janani b | f7060cd | 2017-03-28 19:06:30 +0530 | [diff] [blame] | 209 | return (ModelObjectData) config.deleteInstance(modData); |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 210 | } |
| 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 b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 221 | public ModelObjectData processDeleteInterface(DriverService driverSvc, |
janani b | f7060cd | 2017-03-28 19:06:30 +0530 | [diff] [blame] | 222 | ModelObjectData objectData) { |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 223 | // 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 b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 237 | public ModelObjectData processDeleteBgpInfo(DriverService driverSvc, |
janani b | f7060cd | 2017-03-28 19:06:30 +0530 | [diff] [blame] | 238 | BgpInfo bgpInfo, |
| 239 | BgpDriverInfo driverInfo) { |
janani b | d821b18 | 2017-03-30 16:34:49 +0530 | [diff] [blame] | 240 | L3VpnConfig config = getL3VpnConfig(driverSvc); |
| 241 | return (ModelObjectData) config.deleteBgpInfo(bgpInfo, driverInfo); |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 242 | } |
janani b | f7060cd | 2017-03-28 19:06:30 +0530 | [diff] [blame] | 243 | |
| 244 | /** |
| 245 | * Returns the L3VPN config instance from the behaviour. |
| 246 | * |
| 247 | * @param driverSvc driver service |
| 248 | * @return L3VPN config |
| 249 | */ |
janani b | d821b18 | 2017-03-30 16:34:49 +0530 | [diff] [blame] | 250 | private L3VpnConfig getL3VpnConfig(DriverService driverSvc) { |
janani b | f7060cd | 2017-03-28 19:06:30 +0530 | [diff] [blame] | 251 | DriverHandler handler = driverSvc.createHandler(deviceId); |
janani b | d821b18 | 2017-03-30 16:34:49 +0530 | [diff] [blame] | 252 | return handler.behaviour(L3VpnConfig.class); |
janani b | f7060cd | 2017-03-28 19:06:30 +0530 | [diff] [blame] | 253 | } |
janani b | f41dec3 | 2017-03-24 18:44:07 +0530 | [diff] [blame] | 254 | } |