Search in sources :

Example 1 with L3nexthop

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.L3nexthop in project netvirt by opendaylight.

the class VpnOpStatusListener method update.

@Override
@SuppressWarnings("checkstyle:IllegalCatch")
protected void update(InstanceIdentifier<VpnInstanceOpDataEntry> identifier, VpnInstanceOpDataEntry original, VpnInstanceOpDataEntry update) {
    LOG.info("update: Processing update for vpn {} with rd {}", update.getVpnInstanceName(), update.getVrfId());
    if (update.getVpnState() == VpnInstanceOpDataEntry.VpnState.PendingDelete && vpnFootprintService.isVpnFootPrintCleared(update)) {
        // Cleanup VPN data
        final String vpnName = update.getVpnInstanceName();
        final List<String> rds = update.getRd();
        String primaryRd = update.getVrfId();
        final long vpnId = VpnUtil.getVpnId(dataBroker, vpnName);
        jobCoordinator.enqueueJob("VPN-" + update.getVpnInstanceName(), () -> {
            WriteTransaction writeTxn = dataBroker.newWriteOnlyTransaction();
            // Clean up VpnInstanceToVpnId from Config DS
            VpnUtil.removeVpnIdToVpnInstance(dataBroker, vpnId, writeTxn);
            VpnUtil.removeVpnInstanceToVpnId(dataBroker, vpnName, writeTxn);
            LOG.trace("Removed vpnIdentifier for  rd{} vpnname {}", primaryRd, vpnName);
            // Clean up FIB Entries Config DS
            fibManager.removeVrfTable(primaryRd, null);
            // Clean up VPNExtraRoutes Operational DS
            if (VpnUtil.isBgpVpn(vpnName, primaryRd)) {
                if (update.getType() == VpnInstanceOpDataEntry.Type.L2) {
                    rds.parallelStream().forEach(rd -> bgpManager.deleteVrf(rd, false, AddressFamily.L2VPN));
                }
                if (update.isIpv4Configured()) {
                    rds.parallelStream().forEach(rd -> bgpManager.deleteVrf(rd, false, AddressFamily.IPV4));
                }
                if (update.isIpv6Configured()) {
                    rds.parallelStream().forEach(rd -> bgpManager.deleteVrf(rd, false, AddressFamily.IPV6));
                }
            }
            InstanceIdentifier<Vpn> vpnToExtraroute = VpnExtraRouteHelper.getVpnToExtrarouteVpnIdentifier(vpnName);
            Optional<Vpn> optVpnToExtraroute = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, vpnToExtraroute);
            if (optVpnToExtraroute.isPresent()) {
                VpnUtil.removeVpnExtraRouteForVpn(dataBroker, vpnName, writeTxn);
            }
            if (VpnUtil.isL3VpnOverVxLan(update.getL3vni())) {
                VpnUtil.removeExternalTunnelDemuxFlows(vpnName, dataBroker, mdsalManager);
            }
            // Clean up VPNInstanceOpDataEntry
            VpnUtil.removeVpnOpInstance(dataBroker, primaryRd, writeTxn);
            // Clean up PrefixToInterface Operational DS
            VpnUtil.removePrefixToInterfaceForVpnId(dataBroker, vpnId, writeTxn);
            // Clean up L3NextHop Operational DS
            VpnUtil.removeL3nexthopForVpnId(dataBroker, vpnId, writeTxn);
            // Release the ID used for this VPN back to IdManager
            VpnUtil.releaseId(idManager, VpnConstants.VPN_IDPOOL_NAME, vpnName);
            List<ListenableFuture<Void>> futures = new ArrayList<>();
            futures.add(writeTxn.submit());
            return futures;
        }, SystemPropertyReader.getDataStoreJobCoordinatorMaxRetries());
    } else if (update.getVpnState() == VpnInstanceOpDataEntry.VpnState.Created) {
        final String vpnName = update.getVpnInstanceName();
        final List<String> rds = update.getRd();
        String primaryRd = update.getVrfId();
        if (!VpnUtil.isBgpVpn(vpnName, primaryRd)) {
            return;
        }
        if (original == null) {
            LOG.error("VpnOpStatusListener.update: vpn {} with RD {}. add() handler already called", vpnName, primaryRd);
            return;
        }
        if (update.getVpnTargets() == null) {
            LOG.error("VpnOpStatusListener.update: vpn {} with RD {} vpnTargets not ready", vpnName, primaryRd);
            return;
        }
        List<VpnTarget> vpnTargetList = update.getVpnTargets().getVpnTarget();
        List<String> ertList = new ArrayList<>();
        List<String> irtList = new ArrayList<>();
        if (vpnTargetList != null) {
            for (VpnTarget vpnTarget : vpnTargetList) {
                if (vpnTarget.getVrfRTType() == VpnTarget.VrfRTType.ExportExtcommunity) {
                    ertList.add(vpnTarget.getVrfRTValue());
                }
                if (vpnTarget.getVrfRTType() == VpnTarget.VrfRTType.ImportExtcommunity) {
                    irtList.add(vpnTarget.getVrfRTValue());
                }
                if (vpnTarget.getVrfRTType() == VpnTarget.VrfRTType.Both) {
                    ertList.add(vpnTarget.getVrfRTValue());
                    irtList.add(vpnTarget.getVrfRTValue());
                }
            }
        } else {
            LOG.error("VpnOpStatusListener.update: vpn target list is empty, cannot add BGP" + " VPN {} RD {}", vpnName, primaryRd);
            return;
        }
        jobCoordinator.enqueueJob("VPN-" + update.getVpnInstanceName(), () -> {
            WriteTransaction writeTxn = dataBroker.newWriteOnlyTransaction();
            long primaryRdAddFailed = rds.parallelStream().filter(rd -> {
                try {
                    LOG.info("VpnOpStatusListener.update: updating BGPVPN for vpn {} with RD {}" + " Type is {}, IPv4 is {}, IPv6 is {}", vpnName, primaryRd, update.getType(), update.isIpv4Configured(), update.isIpv6Configured());
                    if (update.getType() == VpnInstanceOpDataEntry.Type.L2) {
                        bgpManager.addVrf(rd, irtList, ertList, AddressFamily.L2VPN);
                    } else {
                        bgpManager.deleteVrf(rd, false, AddressFamily.L2VPN);
                    }
                    if (!original.isIpv4Configured() && update.isIpv4Configured()) {
                        bgpManager.addVrf(rd, irtList, ertList, AddressFamily.IPV4);
                    } else if (original.isIpv4Configured() && !update.isIpv4Configured()) {
                        bgpManager.deleteVrf(rd, false, AddressFamily.IPV4);
                    }
                    if (!original.isIpv6Configured() && update.isIpv6Configured()) {
                        bgpManager.addVrf(rd, irtList, ertList, AddressFamily.IPV6);
                    } else if (original.isIpv6Configured() && !update.isIpv6Configured()) {
                        bgpManager.deleteVrf(rd, false, AddressFamily.IPV6);
                    }
                } catch (Exception e) {
                    LOG.error("VpnOpStatusListener.update: Exception when updating VRF to BGP" + " for vpn {} rd {}", vpnName, rd);
                    return false;
                }
                return false;
            }).count();
            return Collections.emptyList();
        });
    }
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) ArrayList(java.util.ArrayList) VpnTarget(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpntargets.VpnTarget) Vpn(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.Vpn) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)1 VpnTarget (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpntargets.VpnTarget)1 Vpn (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.Vpn)1