Search in sources :

Example 31 with Routes

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes in project netvirt by opendaylight.

the class NaptSwitchHA method isNaptSwitchDown.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public boolean isNaptSwitchDown(Routers extRouter, Uint32 routerId, Uint64 dpnId, Uint64 naptSwitch, Uint32 routerVpnId, Collection<String> externalIpCache, boolean isClearBgpRts, TypedReadWriteTransaction<Configuration> confTx) throws ExecutionException, InterruptedException {
    externalIpsCache = externalIpCache;
    String routerName = extRouter.getRouterName();
    if (!naptSwitch.equals(dpnId)) {
        LOG.debug("isNaptSwitchDown : DpnId {} is not a naptSwitch {} for Router {}", dpnId, naptSwitch, routerName);
        return false;
    }
    LOG.debug("NaptSwitch {} is down for Router {}", naptSwitch, routerName);
    if (routerId == NatConstants.INVALID_ID) {
        LOG.error("isNaptSwitchDown : Invalid routerId returned for routerName {}", routerName);
        return true;
    }
    Uuid networkId = extRouter.getNetworkId();
    String vpnName = getExtNetworkVpnName(routerName, networkId);
    // elect a new NaptSwitch
    naptSwitch = naptSwitchSelector.selectNewNAPTSwitch(routerName, Arrays.asList(naptSwitch));
    if (natMode == NatMode.Conntrack) {
        Routers extRouters = NatUtil.getRoutersFromConfigDS(dataBroker, routerName);
        natServiceManager.notify(confTx, extRouters, null, dpnId, dpnId, SnatServiceManager.Action.CNT_ROUTER_ALL_SWITCH_DISBL);
        if (extRouters.isEnableSnat()) {
            natServiceManager.notify(confTx, extRouters, null, dpnId, dpnId, SnatServiceManager.Action.SNAT_ALL_SWITCH_DISBL);
        }
        natServiceManager.notify(confTx, extRouters, null, naptSwitch, naptSwitch, SnatServiceManager.Action.CNT_ROUTER_ALL_SWITCH_ENBL);
        if (extRouters.isEnableSnat()) {
            natServiceManager.notify(confTx, extRouters, null, naptSwitch, naptSwitch, SnatServiceManager.Action.SNAT_ALL_SWITCH_ENBL);
        }
    } else {
        if (naptSwitch.equals(Uint64.ZERO)) {
            LOG.warn("isNaptSwitchDown : No napt switch is elected since all the switches for router {}" + " are down. SNAT IS NOT SUPPORTED FOR ROUTER {}", routerName, routerName);
            boolean naptUpdatedStatus = updateNaptSwitch(routerName, naptSwitch);
            if (!naptUpdatedStatus) {
                LOG.debug("isNaptSwitchDown : Failed to update naptSwitch {} for router {} in ds", naptSwitch, routerName);
            }
            // clearBgpRoutes
            if (externalIpsCache != null) {
                if (vpnName != null) {
                    // if (externalIps != null) {
                    if (isClearBgpRts) {
                        LOG.debug("isNaptSwitchDown : Clearing both FIB entries and the BGP routes");
                        for (String externalIp : externalIpsCache) {
                            externalRouterListener.clearBgpRoutes(externalIp, vpnName);
                        }
                    } else {
                        LOG.debug("isNaptSwitchDown : Clearing the FIB entries but not the BGP routes");
                        String rd = NatUtil.getVpnRd(dataBroker, vpnName);
                        for (String externalIp : externalIpsCache) {
                            LOG.debug("isNaptSwitchDown : Removing Fib entry rd {} prefix {}", rd, externalIp);
                            fibManager.removeFibEntry(rd, externalIp, null, null);
                        }
                    }
                } else {
                    LOG.debug("isNaptSwitchDown : vpn is not associated to extn/w for router {}", routerName);
                }
            } else {
                LOG.debug("isNaptSwitchDown : No ExternalIps found for subnets under router {}, " + "no bgp routes need to be cleared", routerName);
            }
            return true;
        }
        // checking elected switch health status
        if (!NatUtil.getSwitchStatus(dataBroker, naptSwitch)) {
            LOG.error("isNaptSwitchDown : Newly elected Napt switch {} for router {} is down", naptSwitch, routerName);
            return true;
        }
        LOG.debug("isNaptSwitchDown : New NaptSwitch {} is up for Router {} and can proceed for flow installation", naptSwitch, routerName);
        // update napt model for new napt switch
        boolean naptUpdated = updateNaptSwitch(routerName, naptSwitch);
        if (naptUpdated) {
            // update group of ordinary switch point to naptSwitch tunnel port
            updateNaptSwitchBucketStatus(routerName, routerId, naptSwitch);
        } else {
            LOG.error("isNaptSwitchDown : Failed to update naptSwitch model for newNaptSwitch {} for router {}", naptSwitch, routerName);
        }
        // update table26 forward packets to table46(outbound napt table)
        FlowEntity flowEntity = buildSnatFlowEntityForNaptSwitch(naptSwitch, routerName, routerVpnId, NatConstants.ADD_FLOW);
        if (flowEntity == null) {
            LOG.error("isNaptSwitchDown : Failed to populate flowentity for router {} in naptSwitch {}", routerName, naptSwitch);
        } else {
            LOG.debug("isNaptSwitchDown : Successfully installed flow in naptSwitch {} for router {}", naptSwitch, routerName);
            mdsalManager.addFlow(confTx, flowEntity);
        }
        installSnatFlows(routerName, routerId, naptSwitch, routerVpnId, networkId, vpnName, confTx);
        boolean flowInstalledStatus = handleNatFlowsInNewNaptSwitch(routerName, routerId, dpnId, naptSwitch, routerVpnId, networkId);
        if (flowInstalledStatus) {
            LOG.debug("isNaptSwitchDown :Installed all active session flows in newNaptSwitch {} for routerName {}", naptSwitch, routerName);
        } else {
            LOG.error("isNaptSwitchDown : Failed to install flows in newNaptSwitch {} for routerId {}", naptSwitch, routerId);
        }
        // remove group in new naptswitch, coz this switch acted previously as ordinary switch
        Uint32 groupId = NatUtil.getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME, NatUtil.getGroupIdKey(routerName));
        if (groupId != NatConstants.INVALID_ID) {
            try {
                LOG.info("isNaptSwitchDown : Removing NAPT Group in new naptSwitch {}", naptSwitch);
                mdsalManager.removeGroup(confTx, naptSwitch, groupId.longValue());
            } catch (Exception ex) {
                LOG.error("isNaptSwitchDown : Failed to remove group in new naptSwitch {}", naptSwitch, ex);
            }
        } else {
            LOG.error("NAT Service : Unable to obtain groupId for router:{}", routerName);
        }
    }
    return true;
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) Uint32(org.opendaylight.yangtools.yang.common.Uint32) ExecutionException(java.util.concurrent.ExecutionException) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity)

Example 32 with Routes

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes in project netvirt by opendaylight.

the class NatTepChangeListener method hndlTepDelForSnatInEachRtr.

private void hndlTepDelForSnatInEachRtr(RoutersList router, Uint32 routerId, Uint64 dpnId, String srcTepIp, Boolean isFipExists, ProviderTypes extNwProvType, TypedReadWriteTransaction<Configuration> confTx) throws ExecutionException, InterruptedException {
    /*SNAT :
        1) Elect a new switch as the primary NAPT
        2) Advertise the new routes to BGP for the newly elected TEP IP as the DPN IP
        3) This will make sure old routes are withdrawn and new routes are advertised.
         */
    String routerName = router.getRouter();
    LOG.debug("hndlTepDelForSnatInEachRtr : SNAT -> Trying to clear routes to the External fixed IP associated " + "to the router {}", routerName);
    // Check if this is externalRouter else ignore
    InstanceIdentifier<Routers> extRoutersId = NatUtil.buildRouterIdentifier(routerName);
    Optional<Routers> routerData = Optional.empty();
    try {
        routerData = confTx.read(extRoutersId).get();
    } catch (InterruptedException | ExecutionException e) {
        LOG.error("Error retrieving routers {}", extRoutersId, e);
    }
    if (!routerData.isPresent()) {
        LOG.debug("hndlTepDelForSnatInEachRtr : SNAT->Ignoring TEP del for router {} since its not External Router", routerName);
        return;
    }
    // Check if the DPN having the router is the NAPT switch
    Uint64 naptId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
    if (naptId == null || naptId.equals(Uint64.ZERO) || !naptId.equals(dpnId)) {
        LOG.error("hndlTepDelForSnatInEachRtr : SNAT -> Ignoring TEP delete for the DPN {} since" + "srcTepIp : {} is NOT a NAPT switch", dpnId, srcTepIp);
        return;
    }
    if (natMode == NatMode.Conntrack) {
        Routers extRouter = routerData.get();
        natServiceManager.notify(confTx, extRouter, null, naptId, dpnId, SnatServiceManager.Action.CNT_ROUTER_DISBL);
        if (extRouter.isEnableSnat()) {
            natServiceManager.notify(confTx, extRouter, null, naptId, dpnId, SnatServiceManager.Action.SNAT_ROUTER_DISBL);
        }
    } else {
        Uuid networkId = routerData.get().getNetworkId();
        if (networkId == null) {
            LOG.error("hndlTepDelForSnatInEachRtr : SNAT -> Ignoring TEP delete for the DPN {} for router {}" + "as external network configuraton is missing", dpnId, routerName);
            return;
        }
        LOG.debug("hndlTepDelForSnatInEachRtr : SNAT->Router {} is associated with ext nw {}", routerId, networkId);
        Uuid bgpVpnUuid = NatUtil.getVpnForRouter(dataBroker, routerName);
        Uint32 bgpVpnId;
        if (bgpVpnUuid == null) {
            LOG.debug("hndlTepDelForSnatInEachRtr : SNAT->Internal VPN-ID {} associated to router {}", routerId, routerName);
            bgpVpnId = routerId;
        } else {
            bgpVpnId = NatUtil.getVpnId(dataBroker, bgpVpnUuid.getValue());
            if (bgpVpnId == NatConstants.INVALID_ID) {
                LOG.error("hndlTepDelForSnatInEachRtr :SNAT->Invalid Private BGP VPN ID returned for routerName {}", routerName);
                return;
            }
        }
        if (!isFipExists) {
            // Remove default entry in FIB to SNAT table
            LOG.debug("NAT Service : Installing default route in FIB on DPN {} for router {} with" + " vpn {}...", dpnId, routerName, bgpVpnId);
            defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, bgpVpnId, routerId, confTx);
        }
        if (routerData.get().isEnableSnat()) {
            LOG.info("hndlTepDelForSnatInEachRtr : SNAT enabled for router {}", routerId);
            Uint32 routerVpnId = routerId;
            if (bgpVpnId != NatConstants.INVALID_ID) {
                LOG.debug("hndlTepDelForSnatInEachRtr : SNAT -> Private BGP VPN ID (Internal BGP VPN ID) {} " + "associated to the router {}", bgpVpnId, routerName);
                routerVpnId = bgpVpnId;
            } else {
                LOG.debug("hndlTepDelForSnatInEachRtr : SNAT -> Internal L3 VPN ID (Router ID) {} " + "associated to the router {}", routerVpnId, routerName);
            }
            // Re-elect the other available switch as the NAPT switch and program the NAT flows.
            String externalVpnName = NatUtil.getAssociatedVPN(dataBroker, routerData.get().getNetworkId());
            NatUtil.removeSNATFromDPN(dataBroker, mdsalManager, idManager, naptSwitchHA, dpnId, routerData.get(), routerId, routerVpnId, externalVpnName, extNwProvType, confTx);
        } else {
            LOG.info("hndlTepDelForSnatInEachRtr : SNAT is not enabled for router {} to handle addDPN event {}", routerId, dpnId);
        }
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) ExecutionException(java.util.concurrent.ExecutionException) Uint32(org.opendaylight.yangtools.yang.common.Uint32) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Example 33 with Routes

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes in project netvirt by opendaylight.

the class NatTepChangeListener method handleTepDelForAllRtrs.

@SuppressWarnings("checkstyle:IllegalCatch")
private void handleTepDelForAllRtrs(Uint64 srcDpnId, String srcTepIp) {
    LOG.trace("handleTepDelForAllRtrs : TEP DEL ----- on DPN-ID {} having SRC IP : {}", srcDpnId, srcTepIp);
    List<RoutersList> routersList = null;
    InstanceIdentifier<DpnRoutersList> dpnRoutersListId = NatUtil.getDpnRoutersId(srcDpnId);
    Optional<DpnRoutersList> optionalRouterDpnList = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, dpnRoutersListId);
    if (optionalRouterDpnList.isPresent()) {
        routersList = new ArrayList<RoutersList>(optionalRouterDpnList.get().nonnullRoutersList().values());
    } else {
        LOG.debug("NAT Service : RouterDpnList is empty for DPN {}. Hence ignoring TEP DEL event", srcDpnId);
        return;
    }
    if (routersList == null) {
        LOG.error("handleTepDelForAllRtrs : DPN {} does not have the Routers presence", srcDpnId);
        return;
    }
    for (RoutersList router : routersList) {
        String routerName = router.getRouter();
        LOG.debug("handleTepDelForAllRtrs :  TEP DEL : DNAT -> Withdrawing routes for router {} ", routerName);
        Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);
        if (routerId == NatConstants.INVALID_ID) {
            LOG.error("handleTepDelForAllRtrs :Invalid ROUTER-ID {} returned for routerName {}", routerId, routerName);
            return;
        }
        Uuid externalNetworkId = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
        ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, externalNetworkId);
        if (extNwProvType == null) {
            return;
        }
        boolean isFipExists = hndlTepDelForDnatInEachRtr(router, routerId, srcDpnId, extNwProvType);
        LOG.debug("handleTepDelForAllRtrs :  TEP DEL : SNAT -> Withdrawing and Advertising routes for router {} ", router.getRouter());
        coordinator.enqueueJob((NatConstants.NAT_DJC_PREFIX + router.getRouter()), () -> {
            List<ListenableFuture<Void>> futures = new ArrayList<>();
            txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, configTx -> {
                hndlTepDelForSnatInEachRtr(router, routerId, srcDpnId, srcTepIp, isFipExists, extNwProvType, configTx);
            });
            return futures;
        }, NatConstants.NAT_DJC_MAX_RETRIES);
    }
    return;
}
Also used : ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes) ArrayList(java.util.ArrayList) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) DpnRoutersList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.dpn.routers.DpnRoutersList) RoutersList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.dpn.routers.dpn.routers.list.RoutersList) DpnRoutersList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.dpn.routers.DpnRoutersList) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Uint32(org.opendaylight.yangtools.yang.common.Uint32)

Example 34 with Routes

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes in project netvirt by opendaylight.

the class EvpnUtils method advertisePrefix.

@SuppressWarnings("checkstyle:IllegalCatch")
public void advertisePrefix(ElanInstance elanInfo, String rd, String macAddress, String prefix, String interfaceName, Uint64 dpnId) {
    if (rd == null) {
        LOG.debug("advertisePrefix : rd is NULL for elanInfo {}, macAddress {}", elanInfo, macAddress);
        return;
    }
    String nextHop = getEndpointIpAddressForDPN(dpnId);
    if (nextHop == null) {
        LOG.debug("Failed to get the dpn tep ip for dpn {}", dpnId);
        return;
    }
    Uint32 vpnLabel = Uint32.ZERO;
    Uint32 l2vni = ElanUtils.getVxlanSegmentationId(elanInfo);
    Uint32 l3vni = Uint32.ZERO;
    String gatewayMacAddr = null;
    String l3VpName = getL3vpnNameFromElan(elanInfo);
    if (l3VpName != null) {
        VpnInstance l3VpnInstance = vpnManager.getVpnInstance(broker, l3VpName);
        l3vni = l3VpnInstance.getL3vni();
        Optional<String> gatewayMac = getGatewayMacAddressForInterface(l3VpName, interfaceName, prefix);
        gatewayMacAddr = gatewayMac.isPresent() ? gatewayMac.get() : null;
    }
    LOG.info("Advertising routes with rd {},  macAddress {}, prefix {}, nextHop {}," + " vpnLabel {}, l3vni {}, l2vni {}, gatewayMac {}", rd, macAddress, prefix, nextHop, vpnLabel, l3vni, l2vni, gatewayMacAddr);
    try {
        bgpManager.advertisePrefix(rd, macAddress, prefix, nextHop, VrfEntryBase.EncapType.Vxlan, vpnLabel, l3vni, l2vni, gatewayMacAddr);
    } catch (Exception e) {
        LOG.error("Failed to advertisePrefix", e);
    }
}
Also used : VpnInstance(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance) Uint32(org.opendaylight.yangtools.yang.common.Uint32) ExecutionException(java.util.concurrent.ExecutionException)

Example 35 with Routes

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes in project netvirt by opendaylight.

the class EvpnUtils method withdrawEvpnRT2Routes.

public void withdrawEvpnRT2Routes(EvpnAugmentation evpnAugmentation, String elanName) {
    if (evpnAugmentation == null || evpnAugmentation.getEvpnName() == null) {
        LOG.trace("withdrawEvpnRT2Routes, evpnAugmentation is null");
        return;
    }
    String evpnName = evpnAugmentation.getEvpnName();
    String rd = vpnManager.getVpnRd(broker, evpnName);
    if (rd == null) {
        LOG.debug("withdrawEvpnRT2Routes : rd is null for {}", elanName);
        return;
    }
    List<MacEntry> macEntries = elanUtils.getElanMacEntries(elanName);
    if (macEntries == null || macEntries.isEmpty()) {
        LOG.debug("withdrawEvpnRT2Routes : macEntries  is empty for elan {} ", elanName);
        return;
    }
    for (MacEntry macEntry : macEntries) {
        if (!isIpv4PrefixAvailable.test(macEntry)) {
            LOG.debug("withdrawEvpnRT2Routes macEntry does not have IPv4 prefix {}", macEntry);
            continue;
        }
        String prefix = macEntry.getIpPrefix().getIpv4Address().getValue();
        LOG.info("Withdrawing routes with rd {}, prefix {}", rd, prefix);
        bgpManager.withdrawPrefix(rd, prefix);
    }
}
Also used : MacEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.forwarding.entries.MacEntry)

Aggregations

Test (org.junit.Test)86 ArrayList (java.util.ArrayList)69 AbstractRIBSupportTest (org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest)61 Update (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update)45 Uint32 (org.opendaylight.yangtools.yang.common.Uint32)43 ExecutionException (java.util.concurrent.ExecutionException)41 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)40 Routes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.extra.routes.Routes)33 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)31 List (java.util.List)30 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)30 BigInteger (java.math.BigInteger)29 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)27 VrfEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry)27 VpnInstanceOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry)27 Logger (org.slf4j.Logger)27 LoggerFactory (org.slf4j.LoggerFactory)27 Collections (java.util.Collections)26 Prefixes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.vpn.ids.Prefixes)26 AttributesReach (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.AttributesReach)26