janani b | 35f6cbc | 2017-03-24 21:56:58 +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.impl; |
| 18 | |
| 19 | import org.onosproject.l3vpn.netl3vpn.AccessInfo; |
| 20 | import org.onosproject.l3vpn.netl3vpn.BgpDriverInfo; |
| 21 | import org.onosproject.l3vpn.netl3vpn.BgpInfo; |
| 22 | import org.onosproject.l3vpn.netl3vpn.InterfaceInfo; |
| 23 | import org.onosproject.l3vpn.netl3vpn.NetL3VpnException; |
| 24 | import org.onosproject.l3vpn.netl3vpn.VpnType; |
| 25 | import org.onosproject.net.DeviceId; |
Vidyashree Rama | 04147ca | 2017-05-26 11:32:47 +0530 | [diff] [blame] | 26 | import org.onosproject.yang.gen.v1.ietfinterfaces.rev20140508.ietfinterfaces.devices.device.Interfaces; |
| 27 | import org.onosproject.yang.gen.v1.ietfl3vpnsvc.rev20160730.ietfl3vpnsvc.DefaultL3VpnSvc; |
| 28 | import org.onosproject.yang.gen.v1.ietfl3vpnsvc.rev20160730.ietfl3vpnsvc.SiteRole; |
| 29 | import org.onosproject.yang.gen.v1.ietfl3vpnsvc.rev20160730.ietfl3vpnsvc.l3vpnsvc.DefaultSites; |
| 30 | import org.onosproject.yang.gen.v1.ietfnetworkinstance.rev20160623.ietfnetworkinstance.DefaultDevices; |
| 31 | import org.onosproject.yang.gen.v1.ietfnetworkinstance.rev20160623.ietfnetworkinstance.Devices; |
| 32 | import org.onosproject.yang.gen.v1.ietfnetworkinstance.rev20160623.ietfnetworkinstance.devices.DefaultDevice; |
| 33 | import org.onosproject.yang.gen.v1.ietfnetworkinstance.rev20160623.ietfnetworkinstance.devices.Device; |
| 34 | import org.onosproject.yang.gen.v1.ietfnetworkinstance.rev20160623.ietfnetworkinstance.devices.DeviceKeys; |
| 35 | import org.onosproject.yang.gen.v1.ietfnetworkinstance.rev20160623.ietfnetworkinstance.devices.device.NetworkInstances; |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 36 | import org.onosproject.yang.model.DataNode; |
| 37 | import org.onosproject.yang.model.DefaultModelObjectData; |
Vidyashree Rama | 04147ca | 2017-05-26 11:32:47 +0530 | [diff] [blame] | 38 | import org.onosproject.yang.model.DefaultResourceData; |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 39 | import org.onosproject.yang.model.InnerModelObject; |
| 40 | import org.onosproject.yang.model.ModelObjectData; |
| 41 | import org.onosproject.yang.model.ModelObjectId; |
| 42 | import org.onosproject.yang.model.ResourceData; |
| 43 | import org.onosproject.yang.model.ResourceId; |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 44 | |
| 45 | import java.util.LinkedList; |
| 46 | import java.util.List; |
| 47 | import java.util.Map; |
| 48 | |
| 49 | import static org.onosproject.l3vpn.netl3vpn.BgpModelIdLevel.DEVICE; |
| 50 | import static org.onosproject.l3vpn.netl3vpn.BgpModelIdLevel.DEVICES; |
| 51 | import static org.onosproject.l3vpn.netl3vpn.BgpModelIdLevel.ROOT; |
janani b | d821b18 | 2017-03-30 16:34:49 +0530 | [diff] [blame] | 52 | import static org.onosproject.l3vpn.netl3vpn.BgpModelIdLevel.VPN; |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 53 | import static org.onosproject.l3vpn.netl3vpn.VpnType.ANY_TO_ANY; |
| 54 | import static org.onosproject.l3vpn.netl3vpn.VpnType.HUB; |
| 55 | import static org.onosproject.l3vpn.netl3vpn.VpnType.SPOKE; |
| 56 | |
| 57 | /** |
| 58 | * Representation of utility for YANG tree builder. |
| 59 | */ |
| 60 | public final class NetL3VpnUtil { |
| 61 | |
| 62 | /** |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 63 | * Error message for site VPN name being not present in global VPN. |
| 64 | */ |
| 65 | static final String SITE_VPN_MISMATCH = "Site VPN instance name did not " + |
| 66 | "match any of the global VPN names"; |
| 67 | |
| 68 | /** |
| 69 | * Error message for VPN attachment object being null. |
| 70 | */ |
| 71 | static final String VPN_ATTACHMENT_NULL = "The VPN attachment information" + |
| 72 | " cannot be null"; |
| 73 | |
| 74 | /** |
| 75 | * Error message for VPN policy being not supported. |
| 76 | */ |
| 77 | static final String VPN_POLICY_NOT_SUPPORTED = "VPN policy implementation" + |
| 78 | " is not supported."; |
| 79 | |
| 80 | /** |
| 81 | * Static constant value for hundred. |
| 82 | */ |
| 83 | static final String CONS_HUNDRED = "100:"; |
| 84 | |
| 85 | /** |
| 86 | * Error message for site role being not present in site network access. |
| 87 | */ |
| 88 | static final String SITE_ROLE_NULL = "There must be a site role available" + |
| 89 | " for the VPN in site network access."; |
| 90 | |
| 91 | /** |
| 92 | * Error message for bearer object information being null. |
| 93 | */ |
| 94 | static final String BEARER_NULL = "The bearer information of the access " + |
| 95 | "is not available"; |
| 96 | |
| 97 | /** |
| 98 | * Error message for requested type or ip connect being null. |
| 99 | */ |
| 100 | static final String IP_INT_INFO_NULL = "The required information of " + |
| 101 | "request type or ip connection is not available"; |
| 102 | |
| 103 | /** |
| 104 | * Error message for device info being not available from augment. |
| 105 | */ |
| 106 | static final String DEVICE_INFO_NULL = "Bearer of site does not have any " + |
| 107 | "device information in the augment info."; |
| 108 | |
| 109 | /** |
janani b | 176905a | 2017-03-28 17:36:18 +0530 | [diff] [blame] | 110 | * Static constant value for ip address. |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 111 | */ |
janani b | 176905a | 2017-03-28 17:36:18 +0530 | [diff] [blame] | 112 | static final String IP = "ipaddress"; |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 113 | |
| 114 | /** |
| 115 | * Error message for VPN type being not supported. |
| 116 | */ |
| 117 | static final String VPN_TYPE_UNSUPPORTED = "The VPN type is not supported"; |
| 118 | |
| 119 | /** |
| 120 | * Error message when the generated ID has crossed the limit. |
| 121 | */ |
| 122 | static final String ID_LIMIT_EXCEEDED = "The ID generation has got " + |
| 123 | "exceeded"; |
| 124 | |
| 125 | /** |
| 126 | * Static constant value ID management limit. |
| 127 | */ |
| 128 | static final Long ID_LIMIT = 4294967295L; |
| 129 | |
| 130 | /** |
| 131 | * Error message for interface information being not available. |
| 132 | */ |
| 133 | static final String INT_INFO_NULL = "Requested type does not have any " + |
| 134 | "interface information in the augment info."; |
| 135 | |
| 136 | /** |
| 137 | * Static constant value of port name. |
| 138 | */ |
| 139 | static final String PORT_NAME = "portName"; |
| 140 | |
janani b | 176905a | 2017-03-28 17:36:18 +0530 | [diff] [blame] | 141 | /** |
| 142 | * Static constants to use with accumulator for maximum number of events. |
| 143 | */ |
| 144 | static final int MAX_EVENTS = 1000; |
| 145 | |
| 146 | /** |
| 147 | * Static constants to use with accumulator for maximum number of millis. |
| 148 | */ |
| 149 | static final int MAX_BATCH_MS = 5000; |
| 150 | |
| 151 | /** |
| 152 | * Static constants to use with accumulator for maximum number of idle |
| 153 | * millis. |
| 154 | */ |
| 155 | static final int MAX_IDLE_MS = 1000; |
| 156 | |
| 157 | /** |
| 158 | * Static constants for timer name. |
| 159 | */ |
| 160 | static final String TIMER = "dynamic-config-l3vpn-timer"; |
| 161 | |
| 162 | /** |
| 163 | * Error message for unknown event being occurred. |
| 164 | */ |
| 165 | static final String UNKNOWN_EVENT = "NetL3VPN listener: unknown event: {}"; |
| 166 | |
| 167 | /** |
| 168 | * Error message for event being null. |
| 169 | */ |
| 170 | static final String EVENT_NULL = "Event cannot be null"; |
| 171 | |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 172 | private static final String SITE_ROLE_INVALID = "The given site role is " + |
| 173 | "invalid"; |
| 174 | private static final String ANY_TO_ANY_ROLE = "AnyToAnyRole"; |
| 175 | private static final String HUB_ROLE = "HubRole"; |
| 176 | private static final String SPOKE_ROLE = "SpokeRole"; |
| 177 | |
| 178 | // No instantiation. |
| 179 | private NetL3VpnUtil() { |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * Returns the model object id for service L3VPN container. |
| 184 | * |
| 185 | * @return model object id |
| 186 | */ |
| 187 | static ModelObjectId getModIdForL3VpnSvc() { |
| 188 | return ModelObjectId.builder().addChild(DefaultL3VpnSvc.class).build(); |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Returns the model object id for service sites container. |
| 193 | * |
| 194 | * @return model object id |
| 195 | */ |
| 196 | static ModelObjectId getModIdForSites() { |
| 197 | return ModelObjectId.builder().addChild(DefaultL3VpnSvc.class) |
| 198 | .addChild(DefaultSites.class).build(); |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * Returns the resource data from the data node and the resource id. |
| 203 | * |
| 204 | * @param dataNode data node |
| 205 | * @param resId resource id |
| 206 | * @return resource data |
| 207 | */ |
| 208 | static ResourceData getResourceData(DataNode dataNode, ResourceId resId) { |
| 209 | return DefaultResourceData.builder().addDataNode(dataNode) |
| 210 | .resourceId(resId).build(); |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * Returns the VPN role from the service site role. |
| 215 | * |
| 216 | * @param siteRole service site role |
| 217 | * @return VPN type |
| 218 | */ |
| 219 | static VpnType getRole(Class<? extends SiteRole> siteRole) { |
| 220 | switch (siteRole.getSimpleName()) { |
| 221 | case ANY_TO_ANY_ROLE: |
| 222 | return ANY_TO_ANY; |
| 223 | |
| 224 | case HUB_ROLE: |
| 225 | return HUB; |
| 226 | |
| 227 | case SPOKE_ROLE: |
| 228 | return SPOKE; |
| 229 | |
| 230 | default: |
| 231 | throw new NetL3VpnException(SITE_ROLE_INVALID); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | /** |
| 236 | * Returns error message for management ip being unavailable in device. |
| 237 | * |
| 238 | * @param ip management ip |
| 239 | * @return error message |
| 240 | */ |
| 241 | static String getMgmtIpUnAvailErr(String ip) { |
| 242 | return "The device with management ip " + ip + " is not available."; |
| 243 | } |
| 244 | |
| 245 | /** |
| 246 | * Returns true if device id present in the interface map; false otherwise. |
| 247 | * |
| 248 | * @param info interface map |
| 249 | * @param id device id |
| 250 | * @return true if device id available; false otherwise |
| 251 | */ |
| 252 | private static boolean isDevIdPresent(Map<AccessInfo, InterfaceInfo> info, |
| 253 | String id) { |
| 254 | for (Map.Entry<AccessInfo, InterfaceInfo> inter : info.entrySet()) { |
| 255 | InterfaceInfo interfaceInfo = inter.getValue(); |
| 256 | DeviceId devId = interfaceInfo.devInfo().deviceId(); |
| 257 | if (devId.toString().equals(id)) { |
| 258 | return true; |
| 259 | } |
| 260 | } |
| 261 | return false; |
| 262 | } |
| 263 | |
| 264 | /** |
| 265 | * Builds the device model VPN instance model object data, with respect to |
| 266 | * the device level. |
| 267 | * |
| 268 | * @param id device id |
| 269 | * @param ins VPN instance |
| 270 | * @return model object data, with device level |
| 271 | */ |
| 272 | private static ModelObjectData buildInsModDataDevice(String id, |
| 273 | NetworkInstances ins) { |
| 274 | DeviceKeys devKeys = new DeviceKeys(); |
| 275 | devKeys.deviceid(id); |
| 276 | ModelObjectId modelId = ModelObjectId.builder() |
| 277 | .addChild(DefaultDevices.class) |
| 278 | .addChild(DefaultDevice.class, devKeys) |
| 279 | .build(); |
Thomas Vachuska | d17bc73 | 2017-03-24 11:46:55 -0700 | [diff] [blame] | 280 | return DefaultModelObjectData.builder().identifier(modelId) |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 281 | .addModelObject((InnerModelObject) ins).build(); |
| 282 | } |
| 283 | |
| 284 | /** |
| 285 | * Builds the device model VPN instance model object data, with respect to |
| 286 | * the devices level. |
| 287 | * |
| 288 | * @param id device id |
| 289 | * @param ins VPN instance |
| 290 | * @return model object data, with devices level |
| 291 | */ |
| 292 | private static ModelObjectData buildInsModDataDevices(String id, |
| 293 | NetworkInstances ins) { |
| 294 | ModelObjectId modelId = ModelObjectId.builder() |
| 295 | .addChild(DefaultDevices.class).build(); |
| 296 | Device device = new DefaultDevice(); |
| 297 | device.deviceid(id); |
| 298 | device.networkInstances(ins); |
Thomas Vachuska | d17bc73 | 2017-03-24 11:46:55 -0700 | [diff] [blame] | 299 | return DefaultModelObjectData.builder().identifier(modelId) |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 300 | .addModelObject((InnerModelObject) device).build(); |
| 301 | } |
| 302 | |
| 303 | /** |
| 304 | * Builds the device model VPN instance model object data, with respect to |
| 305 | * root level. |
| 306 | * |
| 307 | * @param id device id |
| 308 | * @param ins VPN instance |
| 309 | * @return model object data, with root level |
| 310 | */ |
| 311 | private static ModelObjectData buildInsModDataRoot(String id, |
| 312 | NetworkInstances ins) { |
| 313 | Devices devices = new DefaultDevices(); |
| 314 | Device device = new DefaultDevice(); |
| 315 | List<Device> deviceList = new LinkedList<>(); |
| 316 | device.deviceid(id); |
| 317 | device.networkInstances(ins); |
| 318 | deviceList.add(device); |
| 319 | devices.device(deviceList); |
| 320 | return DefaultModelObjectData.builder() |
| 321 | .addModelObject((InnerModelObject) devices).build(); |
| 322 | } |
| 323 | |
| 324 | /** |
| 325 | * Builds the device model interface model object data, with respect to |
| 326 | * device level. |
| 327 | * |
| 328 | * @param id device id |
| 329 | * @param ifs interface object |
| 330 | * @return model object data, with device level |
| 331 | */ |
| 332 | private static ModelObjectData buildIntModDataDevice(String id, |
| 333 | Interfaces ifs) { |
Vidyashree Rama | 04147ca | 2017-05-26 11:32:47 +0530 | [diff] [blame] | 334 | org.onosproject.yang.gen.v1.ietfinterfaces |
| 335 | .rev20140508.ietfinterfaces.devices.DeviceKeys keys = new org. |
| 336 | onosproject.yang.gen.v1.ietfinterfaces.rev20140508 |
| 337 | .ietfinterfaces.devices.DeviceKeys(); |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 338 | keys.deviceid(id); |
| 339 | ModelObjectId modelId = ModelObjectId.builder() |
Vidyashree Rama | 04147ca | 2017-05-26 11:32:47 +0530 | [diff] [blame] | 340 | .addChild(org.onosproject.yang.gen.v1.ietfinterfaces.rev20140508 |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 341 | .ietfinterfaces.DefaultDevices.class) |
Vidyashree Rama | 04147ca | 2017-05-26 11:32:47 +0530 | [diff] [blame] | 342 | .addChild(org.onosproject.yang.gen.v1.ietfinterfaces.rev20140508 |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 343 | .ietfinterfaces.devices.DefaultDevice.class, |
| 344 | keys) |
| 345 | .build(); |
Thomas Vachuska | d17bc73 | 2017-03-24 11:46:55 -0700 | [diff] [blame] | 346 | return DefaultModelObjectData.builder().identifier(modelId) |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 347 | .addModelObject((InnerModelObject) ifs).build(); |
| 348 | } |
| 349 | |
| 350 | /** |
| 351 | * Returns the VPN instance create model object data. |
| 352 | * |
| 353 | * @param intMap interface map |
| 354 | * @param instances VPN instances |
| 355 | * @param id device id |
| 356 | * @return VPN instance model object data |
| 357 | */ |
| 358 | static ModelObjectData getVpnCreateModObj(Map<AccessInfo, InterfaceInfo> intMap, |
| 359 | NetworkInstances instances, |
| 360 | String id) { |
| 361 | ModelObjectData modData; |
| 362 | boolean devAdded = isDevIdPresent(intMap, id); |
| 363 | if (devAdded) { |
| 364 | modData = buildInsModDataDevice(id, instances); |
| 365 | } else if (intMap.size() != 0) { |
| 366 | modData = buildInsModDataDevices(id, instances); |
| 367 | } else { |
| 368 | modData = buildInsModDataRoot(id, instances); |
| 369 | } |
| 370 | return modData; |
| 371 | } |
| 372 | |
| 373 | /** |
| 374 | * Returns error message for interface being unavailable in device. |
| 375 | * |
| 376 | * @param intName interface name |
| 377 | * @return error message |
| 378 | */ |
| 379 | static String getIntNotAvailable(String intName) { |
| 380 | return "The interface " + intName + " is not available."; |
| 381 | } |
| 382 | |
| 383 | /** |
| 384 | * Returns the interface create model object data. |
| 385 | * |
janani b | d821b18 | 2017-03-30 16:34:49 +0530 | [diff] [blame] | 386 | * @param ifNames interfaces |
| 387 | * @param ifs interface instance |
| 388 | * @param id device id |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 389 | * @return interface model object data |
| 390 | */ |
janani b | d821b18 | 2017-03-30 16:34:49 +0530 | [diff] [blame] | 391 | static ModelObjectData getIntCreateModObj(List<String> ifNames, |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 392 | Interfaces ifs, String id) { |
| 393 | ModelObjectData modData; |
janani b | d821b18 | 2017-03-30 16:34:49 +0530 | [diff] [blame] | 394 | if (ifNames.size() > 1) { |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 395 | modData = buildIntModDataDevice(id, ifs); |
| 396 | } else { |
| 397 | modData = buildIntModDataRoot(id, ifs); |
| 398 | } |
| 399 | return modData; |
| 400 | } |
| 401 | |
| 402 | /** |
| 403 | * Builds the device model interface model object data, with respect to |
| 404 | * root level. |
| 405 | * |
| 406 | * @param id device id |
| 407 | * @param ifs interface object |
| 408 | * @return model object data, with root level |
| 409 | */ |
| 410 | private static ModelObjectData buildIntModDataRoot(String id, |
| 411 | Interfaces ifs) { |
Vidyashree Rama | 04147ca | 2017-05-26 11:32:47 +0530 | [diff] [blame] | 412 | org.onosproject.yang.gen.v1.ietfinterfaces |
| 413 | .rev20140508.ietfinterfaces.Devices devices = new org |
| 414 | .onosproject.yang.gen.v1.ietfinterfaces.rev20140508 |
| 415 | .ietfinterfaces.DefaultDevices(); |
| 416 | org.onosproject.yang.gen.v1.ietfinterfaces.rev20140508.ietfinterfaces. |
| 417 | devices.Device device = new org.onosproject.yang.gen.v1. |
| 418 | ietfinterfaces.rev20140508.ietfinterfaces.devices.DefaultDevice(); |
| 419 | List<org.onosproject.yang.gen.v1.ietfinterfaces.rev20140508 |
| 420 | .ietfinterfaces.devices.Device> deviceList = new LinkedList<>(); |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 421 | |
| 422 | device.deviceid(id); |
| 423 | device.interfaces(ifs); |
| 424 | deviceList.add(device); |
| 425 | devices.device(deviceList); |
| 426 | return DefaultModelObjectData.builder() |
| 427 | .addModelObject((InnerModelObject) devices).build(); |
| 428 | } |
| 429 | |
| 430 | /** |
| 431 | * Returns the BGP create driver info. |
| 432 | * |
| 433 | * @param bgpMap BGP map |
| 434 | * @param id device id |
janani b | d821b18 | 2017-03-30 16:34:49 +0530 | [diff] [blame] | 435 | * @param devBgp device BGP info |
| 436 | * @param intBgp interface BGP info |
| 437 | * @return BGP driver config |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 438 | */ |
| 439 | static BgpDriverInfo getBgpCreateConfigObj(Map<BgpInfo, DeviceId> bgpMap, |
janani b | d821b18 | 2017-03-30 16:34:49 +0530 | [diff] [blame] | 440 | String id, BgpInfo devBgp, |
| 441 | BgpInfo intBgp) { |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 442 | boolean isDevIdPresent = isDevIdBgpPresent(bgpMap, id); |
| 443 | BgpDriverInfo info; |
janani b | d821b18 | 2017-03-30 16:34:49 +0530 | [diff] [blame] | 444 | if (devBgp != intBgp) { |
| 445 | //TODO: With ipv6 BGP it has to be changed |
| 446 | info = new BgpDriverInfo(VPN, id); |
| 447 | } else if (isDevIdPresent) { |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 448 | info = new BgpDriverInfo(DEVICE, id); |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 449 | } else if (bgpMap.size() != 0) { |
| 450 | info = new BgpDriverInfo(DEVICES, id); |
| 451 | } else { |
| 452 | info = new BgpDriverInfo(ROOT, id); |
| 453 | } |
| 454 | return info; |
| 455 | } |
| 456 | |
| 457 | /** |
| 458 | * Returns true if the device is present in the BGP map; false otherwise. |
| 459 | * |
| 460 | * @param bgpMap BGP map |
| 461 | * @param id device id |
| 462 | * @return true if device is present; false otherwise |
| 463 | */ |
| 464 | private static boolean isDevIdBgpPresent(Map<BgpInfo, DeviceId> bgpMap, |
| 465 | String id) { |
| 466 | for (Map.Entry<BgpInfo, DeviceId> info : bgpMap.entrySet()) { |
| 467 | DeviceId devId = info.getValue(); |
| 468 | if (devId.toString().equals(id)) { |
| 469 | return true; |
| 470 | } |
| 471 | } |
| 472 | return false; |
| 473 | } |
janani b | d821b18 | 2017-03-30 16:34:49 +0530 | [diff] [blame] | 474 | |
| 475 | /** |
| 476 | * Returns the model object data for VPN instance deletion. |
| 477 | * |
| 478 | * @param intMap interface map |
| 479 | * @param ins VPN instance |
| 480 | * @param id device id |
| 481 | * @return model object data |
| 482 | */ |
| 483 | static ModelObjectData getVpnDelModObj(Map<AccessInfo, InterfaceInfo> intMap, |
| 484 | NetworkInstances ins, |
| 485 | String id) { |
| 486 | boolean isDevIdPresent = isDevIdPresent(intMap, id); |
| 487 | ModelObjectData modData; |
| 488 | if (intMap.size() == 0) { |
| 489 | modData = buildInsModDataRoot(id, ins); |
| 490 | } else if (isDevIdPresent) { |
| 491 | modData = buildInsModDataDevice(id, ins); |
| 492 | } else { |
| 493 | modData = buildInsModDataDevices(id, ins); |
| 494 | } |
| 495 | return modData; |
| 496 | } |
| 497 | |
| 498 | /** |
| 499 | * Returns the BGP driver info for VPN BGP instance deletion. |
| 500 | * |
| 501 | * @param bgpMap BGP map |
| 502 | * @param id device id |
| 503 | * @return BGP driver info |
| 504 | */ |
| 505 | static BgpDriverInfo getVpnBgpDelModObj(Map<BgpInfo, DeviceId> bgpMap, |
| 506 | String id) { |
| 507 | boolean isDevIdPresent = isDevIdBgpPresent(bgpMap, id); |
| 508 | BgpDriverInfo driInfo; |
| 509 | if (bgpMap.size() == 0) { |
| 510 | driInfo = new BgpDriverInfo(ROOT, id); |
| 511 | } else if (isDevIdPresent) { |
| 512 | driInfo = new BgpDriverInfo(DEVICE, id); |
| 513 | } else { |
| 514 | driInfo = new BgpDriverInfo(DEVICES, id); |
| 515 | } |
| 516 | return driInfo; |
| 517 | } |
janani b | 35f6cbc | 2017-03-24 21:56:58 +0530 | [diff] [blame] | 518 | } |