Search in sources :

Example 1 with AssociatedSubnet

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnets.associated.to.route.targets.route.target.AssociatedSubnet in project netvirt by opendaylight.

the class VpnManagerImpl method addSubnetAssociationOperationToTx.

private void addSubnetAssociationOperationToTx(String rt, RouteTarget.RtType rtType, String cidr, String vpnName, TypedReadWriteTransaction<Operational> tx, boolean isAssociationRemoved) throws InterruptedException, ExecutionException {
    if (isAssociationRemoved) {
        // Remove RT-Subnet-Vpn Association
        Optional<AssociatedSubnet> associatedSubnet = tx.read(VpnUtil.getAssociatedSubnetIdentifier(rt, rtType, cidr)).get();
        boolean deleteParent = false;
        if (associatedSubnet.isPresent()) {
            List<AssociatedVpn> associatedVpns = new ArrayList<>(associatedSubnet.get().nonnullAssociatedVpn().values());
            if (associatedVpns == null || associatedVpns.isEmpty()) {
                deleteParent = true;
            } else {
                for (Iterator<AssociatedVpn> iterator = associatedVpns.iterator(); iterator.hasNext(); ) {
                    AssociatedVpn associatedVpn = iterator.next();
                    if (Objects.equals(associatedVpn.getName(), vpnName)) {
                        iterator.remove();
                        break;
                    }
                }
                if (associatedVpns.isEmpty()) {
                    deleteParent = true;
                }
            }
        }
        if (deleteParent) {
            deleteParentForSubnetToVpnAssociation(rt, rtType, cidr, tx);
        } else {
            // Some other VPNs are also part of this rtVal, rtType and subnetCidr combination.
            // Delete only this AssociatedVpn Object
            tx.delete(VpnUtil.getAssociatedSubnetAndVpnIdentifier(rt, rtType, cidr, vpnName));
            LOG.debug("addSubnetAssocOperationToTx: Removed vpn {} from association rt {} rtType {} cidr {}", vpnName, rt, rtType, cidr);
        }
    } else {
        // Add RT-Subnet-Vpn Association
        tx.mergeParentStructurePut(VpnUtil.getAssociatedSubnetAndVpnIdentifier(rt, rtType, cidr, vpnName), VpnUtil.buildAssociatedSubnetAndVpn(vpnName));
    }
}
Also used : ArrayList(java.util.ArrayList) AssociatedSubnet(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnets.associated.to.route.targets.route.target.AssociatedSubnet) AssociatedVpn(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnets.associated.to.route.targets.route.target.associated.subnet.AssociatedVpn)

Aggregations

ArrayList (java.util.ArrayList)1 AssociatedSubnet (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnets.associated.to.route.targets.route.target.AssociatedSubnet)1 AssociatedVpn (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnets.associated.to.route.targets.route.target.associated.subnet.AssociatedVpn)1