Search in sources :

Example 26 with Networks

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.Networks in project netvirt by opendaylight.

the class VpnSubnetRouteHandler method onSubnetAddedToVpn.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void onSubnetAddedToVpn(Subnetmap subnetmap, boolean isBgpVpn, Long elanTag) {
    Uuid subnetId = subnetmap.getId();
    String subnetIp = subnetmap.getSubnetIp();
    SubnetOpDataEntry subOpEntry = null;
    SubnetOpDataEntryBuilder subOpBuilder = null;
    InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = null;
    Optional<SubnetOpDataEntry> optionalSubs = null;
    Uint32 label;
    requireNonNull(subnetId, LOGGING_PREFIX + " onSubnetAddedToVpn: SubnetId cannot be null or empty!");
    requireNonNull(subnetIp, LOGGING_PREFIX + " onSubnetAddedToVpn: SubnetPrefix cannot be null or empty!");
    requireNonNull(elanTag, LOGGING_PREFIX + " onSubnetAddedToVpn: ElanTag cannot be null or empty!");
    if (subnetmap.getVpnId() == null) {
        LOG.error("onSubnetAddedToVpn: VpnId {} for subnet {} not found, bailing out", subnetmap.getVpnId(), subnetId);
        return;
    }
    String vpnName = subnetmap.getVpnId().getValue();
    Uint32 vpnId = waitAndGetVpnIdIfInvalid(vpnName);
    if (VpnConstants.INVALID_ID.equals(vpnId)) {
        LOG.error("{} onSubnetAddedToVpn: VpnInstance to VPNId mapping not yet available for VpnName {} " + "processing subnet {} with IP {}, bailing out now.", LOGGING_PREFIX, vpnName, subnetId, subnetIp);
        return;
    }
    String primaryRd = vpnUtil.getPrimaryRd(vpnName);
    VpnInstanceOpDataEntry vpnInstanceOpData = waitAndGetVpnInstanceOpDataIfNull(vpnName, primaryRd);
    if (vpnInstanceOpData == null) {
        LOG.error("{} onSubnetAddedToVpn: VpnInstanceOpData not yet available for VpnName {} " + "processing subnet {} with IP {}, bailing out now.", LOGGING_PREFIX, vpnName, subnetId, subnetIp);
        return;
    }
    LOG.info("{} onSubnetAddedToVpn: Subnet {} with IP {} being added to vpn {}", LOGGING_PREFIX, subnetId.getValue(), subnetIp, vpnName);
    // TODO(vivek): Change this to use more granularized lock at subnetId level
    try {
        vpnUtil.lockSubnet(subnetId.getValue());
        if (isBgpVpn) {
            InstanceIdentifier<Networks> netsIdentifier = InstanceIdentifier.builder(ExternalNetworks.class).child(Networks.class, new NetworksKey(subnetmap.getNetworkId())).build();
            Optional<Networks> optionalNets = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier);
            if (optionalNets.isPresent()) {
                LOG.info("{} onSubnetAddedToVpn: subnet {} with IP {} is an external subnet on external " + "network {}, so ignoring this for SubnetRoute on vpn {}", LOGGING_PREFIX, subnetId.getValue(), subnetIp, subnetmap.getNetworkId().getValue(), vpnName);
                return;
            }
        }
        // Create and add SubnetOpDataEntry object for this subnet to the SubnetOpData container
        subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(subnetId)).build();
        optionalSubs = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier);
        if (optionalSubs.isPresent()) {
            LOG.error("{} onSubnetAddedToVpn: SubnetOpDataEntry for subnet {} with ip {} and vpn {} already" + " detected to be present", LOGGING_PREFIX, subnetId.getValue(), subnetIp, vpnName);
            return;
        }
        LOG.debug("{} onSubnetAddedToVpn: Creating new SubnetOpDataEntry node for subnet {} subnetIp {} " + "vpn {}", LOGGING_PREFIX, subnetId.getValue(), subnetIp, vpnName);
        subOpBuilder = new SubnetOpDataEntryBuilder().withKey(new SubnetOpDataEntryKey(subnetId));
        subOpBuilder.setSubnetId(subnetId);
        subOpBuilder.setSubnetCidr(subnetIp);
        if (isBgpVpn && !VpnUtil.isBgpVpn(vpnName, primaryRd)) {
            LOG.error("{} onSubnetAddedToVpn: The VPN Instance name {} does not have RD. Bailing out for" + " subnet {} subnetIp {} ", LOGGING_PREFIX, vpnName, subnetId.getValue(), subnetIp);
            return;
        }
        // Allocate MPLS label for subnet-route at the time SubnetOpDataEntry creation
        label = vpnUtil.getUniqueId(VpnConstants.VPN_IDPOOL_NAME, VpnUtil.getNextHopLabelKey(primaryRd, subnetIp));
        if (label == VpnConstants.INVALID_ID) {
            LOG.error("onSubnetAddedToVpn: Unable to retrieve label for rd {}, subnetIp {}", primaryRd, subnetIp);
            return;
        }
        subOpBuilder.setVrfId(primaryRd);
        subOpBuilder.setVpnName(vpnName);
        subOpBuilder.setSubnetToDpn(new ArrayList<>());
        subOpBuilder.setRouteAdvState(TaskState.Idle);
        subOpBuilder.setElanTag(elanTag);
        subOpBuilder.setLabel(label);
        Long l3Vni = vpnInstanceOpData.getL3vni() != null ? vpnInstanceOpData.getL3vni().toJava() : 0L;
        subOpBuilder.setL3vni(l3Vni);
        subOpEntry = subOpBuilder.build();
        SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier, subOpEntry, VpnUtil.SINGLE_TRANSACTION_BROKER_NO_RETRY);
        LOG.info("{} onSubnetAddedToVpn: Added subnetopdataentry to OP Datastore for subnet {}", LOGGING_PREFIX, subnetId.getValue());
    } catch (TransactionCommitFailedException e) {
        LOG.error("{} Creation of SubnetOpDataEntry for subnet {} failed ", LOGGING_PREFIX, subnetId.getValue(), e);
        // The second part of this method depends on subnetmap being non-null so fail fast here.
        return;
    } catch (RuntimeException e) {
        // TODO: Avoid this
        LOG.error("{} onSubnetAddedToVpn: Unable to handle subnet {} with ip {} added to vpn {}", LOGGING_PREFIX, subnetId.getValue(), subnetIp, vpnName, e);
        return;
    } catch (InterruptedException | ExecutionException e) {
        LOG.error("{} onSubnetAddedToVpn: Failed to read data store for subnet {} ip {} vpn {}", LOGGING_PREFIX, subnetId, subnetIp, vpnName);
        return;
    } finally {
        vpnUtil.unlockSubnet(subnetId.getValue());
    }
    try {
        // In second critical section , Port-Op-Data will be updated.
        vpnUtil.lockSubnet(subnetId.getValue());
        Uint64 dpnId = null;
        SubnetToDpn subDpn = null;
        Map<Uint64, SubnetToDpn> subDpnMap = new HashMap<>();
        optionalSubs = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier);
        subOpBuilder = new SubnetOpDataEntryBuilder(optionalSubs.get()).withKey(new SubnetOpDataEntryKey(subnetId));
        List<Uuid> portList = subnetmap.getPortList();
        if (portList != null) {
            for (Uuid port : portList) {
                Interface intfState = InterfaceUtils.getInterfaceStateFromOperDS(dataBroker, port.getValue());
                if (intfState != null) {
                    try {
                        dpnId = InterfaceUtils.getDpIdFromInterface(intfState);
                    } catch (Exception e) {
                        LOG.error("{} onSubnetAddedToVpn: Unable to obtain dpnId for interface {}," + " subnetroute inclusion for this interface for subnet {} subnetIp {} " + "vpn {} failed with exception", LOGGING_PREFIX, port.getValue(), subnetId.getValue(), subnetIp, vpnName, e);
                        continue;
                    }
                    if (dpnId.equals(Uint64.ZERO)) {
                        LOG.error("{} onSubnetAddedToVpn: Port {} is not assigned DPN yet," + " ignoring subnet {} subnetIP {} vpn {}", LOGGING_PREFIX, port.getValue(), subnetId.getValue(), subnetIp, vpnName);
                        continue;
                    }
                    subOpDpnManager.addPortOpDataEntry(port.getValue(), subnetId, dpnId);
                    if (intfState.getOperStatus() != OperStatus.Up) {
                        LOG.error("{} onSubnetAddedToVpn: Port {} is not UP yet, ignoring subnet {}" + " subnetIp {} vpn {}", LOGGING_PREFIX, port.getValue(), subnetId.getValue(), subnetIp, vpnName);
                        continue;
                    }
                    subDpn = subOpDpnManager.addInterfaceToDpn(subnetId, dpnId, port.getValue());
                    if (intfState.getOperStatus() == OperStatus.Up) {
                        // port is UP
                        subDpnMap.put(dpnId, subDpn);
                    }
                } else {
                    subOpDpnManager.addPortOpDataEntry(port.getValue(), subnetId, null);
                }
            }
            if (subDpnMap.size() > 0) {
                subOpBuilder.setSubnetToDpn(new ArrayList<>(subDpnMap.values()));
            }
        }
        electNewDpnForSubnetRoute(subOpBuilder, null, /* oldDpnId */
        subnetId, subnetmap.getNetworkId(), isBgpVpn, label);
        subOpEntry = subOpBuilder.build();
        SingleTransactionDataBroker.syncUpdate(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier, subOpEntry, VpnUtil.SINGLE_TRANSACTION_BROKER_NO_RETRY);
        LOG.info("{} onSubnetAddedToVpn: Added PortOpDataEntry and VpnInterfaces to SubnetOpData" + " for subnet {} subnetIp {} vpn {} TaskState {} lastTaskState {}", LOGGING_PREFIX, subnetId.getValue(), subnetIp, vpnName, subOpEntry.getRouteAdvState(), subOpEntry.getLastAdvState());
    } catch (RuntimeException e) {
        LOG.error("{} onSubnetAddedToVpn: Unable to handle subnet {} with ip {} added to vpn {}", LOGGING_PREFIX, subnetId.getValue(), subnetIp, vpnName, e);
    } catch (InterruptedException | ExecutionException e) {
        LOG.error("{} onSubnetAddedToVpn: Failed to read data store for subnet {} ip {} vpn {}", LOGGING_PREFIX, subnetId, subnetIp, vpnName);
    } catch (TransactionCommitFailedException ex) {
        LOG.error("{} onSubnetAddedToVpn: Creation of SubnetOpDataEntry for subnet {} subnetIp {} vpn {} failed", LOGGING_PREFIX, subnetId.getValue(), subnetIp, vpnName, ex);
    } finally {
        vpnUtil.unlockSubnet(subnetId.getValue());
    }
}
Also used : Networks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks) ExternalNetworks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks) HashMap(java.util.HashMap) SubnetOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) ExecutionException(java.util.concurrent.ExecutionException) Uint32(org.opendaylight.yangtools.yang.common.Uint32) SubnetOpDataEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryBuilder) SubnetOpData(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.SubnetOpData) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) ExecutionException(java.util.concurrent.ExecutionException) SubnetToDpn(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.SubnetToDpn) NetworksKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksKey) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnInstanceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry) SubnetOpDataEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryKey) Interface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Example 27 with Networks

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.Networks in project netvirt by opendaylight.

the class NeutronvpnManager method createVpn.

/**
 * Performs the creation of a Neutron L3VPN, associating the new VPN to the
 * specified Neutron Networks and Routers.
 *
 * @param vpnId Uuid of the VPN tp be created
 * @param name Representative name of the new VPN
 * @param tenantId Uuid of the Tenant under which the VPN is going to be created
 * @param rdList Route-distinguisher for the VPN
 * @param irtList A list of Import Route Targets
 * @param ertList A list of Export Route Targets
 * @param routerIdsList ist of neutron router Id to associate with created VPN
 * @param networkList UUID of the neutron network the VPN may be associated to
 * @param isL2Vpn True if VPN Instance is of type L2, false if L3
 * @param l3vni L3VNI for the VPN Instance using VxLAN as the underlay
 * @throws Exception if association of L3VPN failed
 */
public void createVpn(Uuid vpnId, String name, Uuid tenantId, List<String> rdList, List<String> irtList, List<String> ertList, @Nullable List<Uuid> routerIdsList, @Nullable List<Uuid> networkList, boolean isL2Vpn, long l3vni) throws Exception {
    IpVersionChoice ipVersChoices = IpVersionChoice.UNDEFINED;
    if (routerIdsList != null && !routerIdsList.isEmpty()) {
        for (Uuid routerId : routerIdsList) {
            IpVersionChoice vers = neutronvpnUtils.getIpVersionChoicesFromRouterUuid(routerId);
            ipVersChoices = ipVersChoices.addVersion(vers);
        }
    }
    updateVpnInstanceNode(vpnId, rdList, irtList, ertList, isL2Vpn, l3vni, ipVersChoices);
    // Please note that router and networks will be filled into VPNMaps
    // by subsequent calls here to associateRouterToVpn and
    // associateNetworksToVpn
    updateVpnMaps(vpnId, name, null, tenantId, null);
    LOG.debug("Created L3VPN with ID {}, name {}, tenantID {}, RDList {}, iRTList {}, eRTList{}, routerIdsList {}, " + "networkList {}", vpnId.getValue(), name, tenantId, rdList, irtList, ertList, routerIdsList, networkList);
    if (routerIdsList != null && !routerIdsList.isEmpty()) {
        for (Uuid routerId : routerIdsList) {
            associateRouterToVpn(vpnId, routerId);
        }
    }
    if (networkList != null) {
        List<String> failStrings = associateNetworksToVpn(vpnId, networkList);
        if (!failStrings.isEmpty()) {
            LOG.error("VPN {} association to networks failed for networks: {}. ", vpnId.getValue(), failStrings);
            throw new Exception(failStrings.toString());
        }
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ExecutionException(java.util.concurrent.ExecutionException) OptimisticLockFailedException(org.opendaylight.mdsal.common.api.OptimisticLockFailedException) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) IpVersionChoice(org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice)

Example 28 with Networks

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.Networks in project netvirt by opendaylight.

the class NeutronvpnManager method removeExternalNetworkFromVpn.

private boolean removeExternalNetworkFromVpn(Network extNet) {
    Uuid extNetId = extNet.getUuid();
    InstanceIdentifier<Networks> extNetsId = InstanceIdentifier.builder(ExternalNetworks.class).child(Networks.class, new NetworksKey(extNetId)).build();
    try {
        Optional<Networks> optionalNets = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, extNetsId);
        NetworksBuilder builder = null;
        if (optionalNets.isPresent()) {
            builder = new NetworksBuilder(optionalNets.get());
        } else {
            LOG.error("removeExternalNetworkFromVpn: Provider Network {} is not present in the ConfigDS", extNetId.getValue());
            return false;
        }
        builder.setVpnid(null);
        Networks networks = builder.build();
        LOG.info("removeExternalNetworkFromVpn: Withdraw VPN Id from Provider Network {} node", extNetId.getValue());
        SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, extNetsId, networks);
        return true;
    } catch (TransactionCommitFailedException | ExecutionException | InterruptedException ex) {
        LOG.error("removeExternalNetworkFromVpn: Failed to withdraw VPN Id from Provider Network node {}: ", extNetId.getValue(), ex);
    }
    return false;
}
Also used : Networks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks) ExternalNetworks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks) NetworksKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksKey) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ExecutionException(java.util.concurrent.ExecutionException) NetworksBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksBuilder)

Example 29 with Networks

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.Networks in project netvirt by opendaylight.

the class NeutronvpnNatManager method addExternalNetworkToRouter.

private void addExternalNetworkToRouter(Router update) {
    Uuid routerId = update.getUuid();
    Uuid extNetId = update.getExternalGatewayInfo().getExternalNetworkId();
    Map<ExternalFixedIpsKey, ExternalFixedIps> keyExternalFixedIpsMap = update.getExternalGatewayInfo().nonnullExternalFixedIps();
    try {
        Network input = neutronvpnUtils.getNeutronNetwork(extNetId);
        ProviderTypes providerNwType = NeutronvpnUtils.getProviderNetworkType(input);
        if (providerNwType == null) {
            LOG.error("Unable to get Network Provider Type for network {}", input.getUuid().getValue());
            return;
        }
        // Add this router to the ExtRouters list
        addExternalRouter(update);
        // Update External Subnets for this router
        updateExternalSubnetsForRouter(routerId, extNetId, new ArrayList<ExternalFixedIps>(keyExternalFixedIpsMap.values()));
        // Create and add Networks object for this External Network to the ExternalNetworks list
        InstanceIdentifier<Networks> netsIdentifier = InstanceIdentifier.builder(ExternalNetworks.class).child(Networks.class, new NetworksKey(extNetId)).build();
        Optional<Networks> optionalNets = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier);
        if (!optionalNets.isPresent()) {
            LOG.error("External Network {} not present in the NVPN datamodel", extNetId.getValue());
            return;
        }
        NetworksBuilder builder = new NetworksBuilder(optionalNets.get());
        List<Uuid> rtrList = (builder.getRouterIds() != null && !builder.getRouterIds().isEmpty()) ? new ArrayList<>(builder.getRouterIds()) : new ArrayList<>();
        rtrList.add(routerId);
        builder.setRouterIds(rtrList);
        if (NeutronvpnUtils.isFlatOrVlanNetwork(input)) {
            builder.setVpnid(extNetId);
        }
        Networks networkss = builder.build();
        // Add Networks object to the ExternalNetworks list
        LOG.trace("Updating externalnetworks {}", networkss);
        SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier, networkss);
        LOG.trace("Updated externalnetworks successfully to CONFIG Datastore");
    } catch (TransactionCommitFailedException | ExecutionException | InterruptedException ex) {
        LOG.error("Creation of externalnetworks failed for {}", extNetId.getValue(), ex);
    }
}
Also used : Networks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks) ExternalNetworks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks) ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes) ExternalFixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.router.external_gateway_info.ExternalFixedIps) NetworksKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksKey) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Network(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network) ExternalFixedIpsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.router.external_gateway_info.ExternalFixedIpsKey) ExecutionException(java.util.concurrent.ExecutionException) NetworksBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksBuilder)

Example 30 with Networks

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.Networks in project netvirt by opendaylight.

the class NeutronvpnManager method dissociateNetworksFromVpn.

/**
 * Parses and disassociates networks list from given VPN.
 *
 * @param vpnId Uuid of given VPN.
 * @param networkList List list of network Ids (Uuid), which will be disassociated.
 * @return list of formatted strings with detailed error messages.
 */
@NonNull
protected List<String> dissociateNetworksFromVpn(@NonNull Uuid vpnId, @NonNull List<Uuid> networkList) {
    List<String> failedNwList = new ArrayList<>();
    HashSet<Uuid> passedNwList = new HashSet<>();
    ConcurrentMap<Uuid, Network> extNwMap = new ConcurrentHashMap<>();
    IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
    if (networkList.isEmpty()) {
        LOG.error("dissociateNetworksFromVpn: Failed as networks list is empty");
        failedNwList.add(String.format("Failed to disassociate networks from VPN %s as networks list is empty", vpnId.getValue()));
        return failedNwList;
    }
    for (Uuid nw : networkList) {
        List<Uuid> networkSubnets = neutronvpnUtils.getSubnetIdsFromNetworkId(nw);
        if (networkSubnets == null) {
            passedNwList.add(nw);
            continue;
        }
        Network network = neutronvpnUtils.getNeutronNetwork(nw);
        if (network == null) {
            LOG.error("dissociateNetworksFromVpn: Network {} not found in ConfigDS", nw.getValue());
            failedNwList.add(String.format("Failed to disassociate network %s as is not found in ConfigDS", nw.getValue()));
            continue;
        }
        Uuid networkVpnId = neutronvpnUtils.getVpnForNetwork(nw);
        if (networkVpnId == null) {
            LOG.error("dissociateNetworksFromVpn: Network {} is not associated to any VPN", nw.getValue());
            failedNwList.add(String.format("Failed to disassociate network %s as is not associated to any VPN", nw.getValue()));
            continue;
        }
        if (!vpnId.equals(networkVpnId)) {
            LOG.error("dissociateNetworksFromVpn: Network {} is associated to another VPN {} instead of given {}", nw.getValue(), networkVpnId.getValue(), vpnId.getValue());
            failedNwList.add(String.format("Failed to disassociate network %s as it is associated to another " + "vpn %s instead of given %s", nw.getValue(), networkVpnId.getValue(), vpnId.getValue()));
            continue;
        }
        /* Handle disassociation of external network(s) from Internet BGP-VPN use case outside of the
             * networkList iteration
             */
        if (neutronvpnUtils.getIsExternal(network)) {
            extNwMap.put(nw, network);
            // Handle external-Nw to BGPVPN Disassociation and still ext-router is being set with external-Nw
            List<Uuid> routerList = neutronvpnUtils.getRouterIdsForExtNetwork(nw);
            if (!routerList.isEmpty()) {
                for (Uuid routerId : routerList) {
                    // If v6 subnet was already added to router means it requires IPv6 AddrFamily in VpnInstance
                    if (neutronvpnUtils.isV6SubnetPartOfRouter(routerId)) {
                        ipVersion = ipVersion.addVersion(IpVersionChoice.IPV6);
                        LOG.debug("dissociateNetworksFromVpn: External network {} is still associated with " + "router(router-gw) {} and V6 subnet is part of that router. Hence Set IPv6 " + "address family type in Internet VPN Instance {}", network, routerId, vpnId);
                        break;
                    }
                }
            }
        }
        for (Uuid subnet : networkSubnets) {
            Subnetmap subnetmap = neutronvpnUtils.getSubnetmap(subnet);
            if (subnetmap == null) {
                failedNwList.add(String.format("subnetmap %s not found for network %s", subnet.getValue(), nw.getValue()));
                LOG.error("dissociateNetworksFromVpn: Subnetmap for subnet {} not found when " + "dissociating network {} from VPN {}", subnet.getValue(), nw.getValue(), vpnId.getValue());
                continue;
            }
            IpVersionChoice ipVers = NeutronvpnUtils.getIpVersionFromString(subnetmap.getSubnetIp());
            if (!ipVersion.isIpVersionChosen(ipVers)) {
                ipVersion = ipVersion.addVersion(ipVers);
            }
            if (!NeutronvpnUtils.getIsExternal(network)) {
                LOG.debug("dissociateNetworksFromVpn: Withdraw subnet {} from VPN {}", subnet.getValue(), vpnId.getValue());
                removeSubnetFromVpn(vpnId, subnetmap, null);
                Set<VpnTarget> routeTargets = vpnManager.getRtListForVpn(vpnId.getValue());
                vpnManager.removeRouteTargetsToSubnetAssociation(routeTargets, subnetmap.getSubnetIp(), vpnId.getValue());
                passedNwList.add(nw);
            }
        }
        if (ipVersion != IpVersionChoice.UNDEFINED) {
            LOG.debug("dissociateNetworksFromVpn: Updating vpnInstance with ip address family {}" + " for VPN {}", ipVersion, vpnId);
            neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), ipVersion, false);
        }
    }
    // Handle disassociation of external network(s) from Internet BGP-VPN Instance use case
    if (!extNwMap.isEmpty() || extNwMap != null) {
        for (Network extNw : extNwMap.values()) {
            if (disassociateExtNetworkFromVpn(vpnId, extNw)) {
                passedNwList.add(extNw.getUuid());
            } else {
                LOG.error("dissociateNetworksFromVpn: Failed to withdraw External Provider Network {} from VPN {}", extNw, vpnId.getValue());
                failedNwList.add(String.format("Failed to withdraw External Provider Network %s from VPN %s", extNw, vpnId.getValue()));
                continue;
            }
        }
    }
    clearFromVpnMaps(vpnId, null, new ArrayList<>(passedNwList));
    LOG.info("dissociateNetworksFromVpn: Network(s) {} disassociated from L3VPN {} successfully", passedNwList, vpnId.getValue());
    return failedNwList;
}
Also used : ArrayList(java.util.ArrayList) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnTarget(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.vpn.instance.vpntargets.VpnTarget) Network(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashSet(java.util.HashSet) IpVersionChoice(org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice) NonNull(org.eclipse.jdt.annotation.NonNull)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)43 ExecutionException (java.util.concurrent.ExecutionException)19 ArrayList (java.util.ArrayList)16 ProviderTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)14 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)13 ExternalNetworks (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks)13 Networks (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks)13 NetworksKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksKey)11 Uint32 (org.opendaylight.yangtools.yang.common.Uint32)9 BigInteger (java.math.BigInteger)6 Networks (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.Networks)6 NetworksKey (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.NetworksKey)6 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)5 HashSet (java.util.HashSet)4 NonNull (org.eclipse.jdt.annotation.NonNull)4 AcquireResult (org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.AcquireResult)4 NetworksBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksBuilder)4 InternalToExternalPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap)4 VpnMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap)4 Network (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network)4