Search in sources :

Example 11 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 VrfEntryListener method manageRemoteRouteOnDPN.

public void manageRemoteRouteOnDPN(final boolean action, final BigInteger localDpnId, final long vpnId, final String rd, final String destPrefix, final String destTepIp, final long label) {
    final VpnInstanceOpDataEntry vpnInstance = fibUtil.getVpnInstance(rd);
    if (vpnInstance == null) {
        LOG.error("VpnInstance for rd {} not present for prefix {}", rd, destPrefix);
        return;
    }
    jobCoordinator.enqueueJob(FibUtil.getJobKeyForVpnIdDpnId(vpnId, localDpnId), () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
        synchronized (vpnInstance.getVpnInstanceName().intern()) {
            VrfTablesKey vrfTablesKey = new VrfTablesKey(rd);
            VrfEntry vrfEntry = getVrfEntry(dataBroker, rd, destPrefix);
            if (vrfEntry == null) {
                return;
            }
            LOG.trace("manageRemoteRouteOnDPN :: action {}, DpnId {}, vpnId {}, rd {}, destPfx {}", action, localDpnId, vpnId, rd, destPrefix);
            List<RoutePaths> routePathList = vrfEntry.getRoutePaths();
            VrfEntry modVrfEntry;
            if (routePathList == null || routePathList.isEmpty()) {
                modVrfEntry = FibHelper.getVrfEntryBuilder(vrfEntry, label, Collections.singletonList(destTepIp), RouteOrigin.value(vrfEntry.getOrigin()), null).build();
            } else {
                modVrfEntry = vrfEntry;
            }
            if (action) {
                LOG.trace("manageRemoteRouteOnDPN updated(add)  vrfEntry :: {}", modVrfEntry);
                createRemoteFibEntry(localDpnId, vpnId, vrfTablesKey.getRouteDistinguisher(), modVrfEntry, tx);
            } else {
                LOG.trace("manageRemoteRouteOnDPN updated(remove)  vrfEntry :: {}", modVrfEntry);
                List<String> usedRds = VpnExtraRouteHelper.getUsedRds(dataBroker, vpnInstance.getVpnId(), vrfEntry.getDestPrefix());
                if (usedRds.size() > 1) {
                    LOG.debug("The extra route prefix is still present in some DPNs");
                    return;
                }
                // Is this fib route an extra route? If yes, get the nexthop which would be
                // an adjacency in the vpn
                Optional<Routes> extraRouteOptional = Optional.absent();
                if (usedRds.size() != 0) {
                    extraRouteOptional = VpnExtraRouteHelper.getVpnExtraroutes(dataBroker, fibUtil.getVpnNameFromId(vpnInstance.getVpnId()), usedRds.get(0), vrfEntry.getDestPrefix());
                }
                baseVrfEntryHandler.deleteRemoteRoute(null, localDpnId, vpnId, vrfTablesKey, modVrfEntry, extraRouteOptional, tx);
            }
        }
    })));
}
Also used : VrfTablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTablesKey) VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) VpnInstanceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry) RoutePaths(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentrybase.RoutePaths) Routes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.extra.routes.Routes)

Example 12 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 VrfEntryListener method deleteLocalFibEntry.

public List<BigInteger> deleteLocalFibEntry(Long vpnId, String rd, VrfEntry vrfEntry) {
    List<BigInteger> returnLocalDpnId = new ArrayList<>();
    Prefixes localNextHopInfo = fibUtil.getPrefixToInterface(vpnId, vrfEntry.getDestPrefix());
    String vpnName = fibUtil.getVpnNameFromId(vpnId);
    boolean isExtraroute = false;
    if (localNextHopInfo == null) {
        List<String> usedRds = VpnExtraRouteHelper.getUsedRds(dataBroker, vpnId, vrfEntry.getDestPrefix());
        if (usedRds.size() > 1) {
            LOG.error("The extra route prefix {} is still present in some DPNs in vpn {} on rd {}", vrfEntry.getDestPrefix(), vpnName, rd);
            return returnLocalDpnId;
        }
        // Is this fib route an extra route? If yes, get the nexthop which would be an adjacency
        // in the vpn
        Optional<Routes> extraRouteOptional = VpnExtraRouteHelper.getVpnExtraroutes(dataBroker, vpnName, rd, vrfEntry.getDestPrefix());
        if (extraRouteOptional.isPresent()) {
            isExtraroute = true;
            Routes extraRoute = extraRouteOptional.get();
            String ipPrefix;
            if (isIpv4Address(extraRoute.getNexthopIpList().get(0))) {
                ipPrefix = extraRoute.getNexthopIpList().get(0) + NwConstants.IPV4PREFIX;
            } else {
                ipPrefix = extraRoute.getNexthopIpList().get(0) + NwConstants.IPV6PREFIX;
            }
            localNextHopInfo = fibUtil.getPrefixToInterface(vpnId, ipPrefix);
            if (localNextHopInfo != null) {
                String localNextHopIP = localNextHopInfo.getIpAddress();
                BigInteger dpnId = checkDeleteLocalFibEntry(localNextHopInfo, localNextHopIP, vpnId, rd, vrfEntry, isExtraroute, vpnId);
                if (!dpnId.equals(BigInteger.ZERO)) {
                    LOG.trace("Deleting ECMP group for prefix {}, dpn {}", vrfEntry.getDestPrefix(), dpnId);
                    nextHopManager.setupLoadBalancingNextHop(vpnId, dpnId, vrfEntry.getDestPrefix(), /*listBucketInfo*/
                    Collections.emptyList(), /*remove*/
                    false);
                    returnLocalDpnId.add(dpnId);
                }
            } else {
                LOG.error("localNextHopInfo unavailable while deleting prefix {} with rds {}, primary rd {} in " + "vpn {}", vrfEntry.getDestPrefix(), usedRds, rd, vpnName);
            }
        }
        if (localNextHopInfo == null) {
            /* Imported VRF entry */
            java.util.Optional<Long> optionalLabel = FibUtil.getLabelFromRoutePaths(vrfEntry);
            if (optionalLabel.isPresent()) {
                Long label = optionalLabel.get();
                List<String> nextHopAddressList = FibHelper.getNextHopListFromRoutePaths(vrfEntry);
                LabelRouteInfo lri = getLabelRouteInfo(label);
                if (isPrefixAndNextHopPresentInLri(vrfEntry.getDestPrefix(), nextHopAddressList, lri)) {
                    PrefixesBuilder prefixBuilder = new PrefixesBuilder();
                    prefixBuilder.setDpnId(lri.getDpnId());
                    BigInteger dpnId = checkDeleteLocalFibEntry(prefixBuilder.build(), nextHopAddressList.get(0), vpnId, rd, vrfEntry, isExtraroute, lri.getParentVpnid());
                    if (!dpnId.equals(BigInteger.ZERO)) {
                        returnLocalDpnId.add(dpnId);
                    }
                }
            }
        }
    } else {
        LOG.debug("Obtained prefix to interface for rd {} prefix {}", rd, vrfEntry.getDestPrefix());
        String localNextHopIP = localNextHopInfo.getIpAddress();
        BigInteger dpnId = checkDeleteLocalFibEntry(localNextHopInfo, localNextHopIP, vpnId, rd, vrfEntry, isExtraroute, vpnId);
        if (!dpnId.equals(BigInteger.ZERO)) {
            returnLocalDpnId.add(dpnId);
        }
    }
    return returnLocalDpnId;
}
Also used : LabelRouteInfo(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.label.route.map.LabelRouteInfo) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) Routes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.extra.routes.Routes) Prefixes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.vpn.ids.Prefixes) PrefixesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.vpn.ids.PrefixesBuilder) BigInteger(java.math.BigInteger)

Example 13 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 BaseVrfEntryHandler method deleteRemoteRoute.

public void deleteRemoteRoute(final BigInteger localDpnId, final BigInteger remoteDpnId, final long vpnId, final VrfTablesKey vrfTableKey, final VrfEntry vrfEntry, Optional<Routes> extraRouteOptional, WriteTransaction tx) {
    Boolean wrTxPresent = true;
    if (tx == null) {
        wrTxPresent = false;
        tx = dataBroker.newWriteOnlyTransaction();
    }
    LOG.debug("deleting remote route: prefix={}, vpnId={} localDpnId {} remoteDpnId {}", vrfEntry.getDestPrefix(), vpnId, localDpnId, remoteDpnId);
    String rd = vrfTableKey.getRouteDistinguisher();
    if (localDpnId != null && localDpnId != BigInteger.ZERO) {
        // localDpnId is not known when clean up happens for last vm for a vpn on a dpn
        if (extraRouteOptional.isPresent()) {
            nextHopManager.setupLoadBalancingNextHop(vpnId, remoteDpnId, vrfEntry.getDestPrefix(), Collections.emptyList(), /*listBucketInfo*/
            false);
        }
        makeConnectedRoute(remoteDpnId, vpnId, vrfEntry, rd, null, NwConstants.DEL_FLOW, tx, null);
        LOG.debug("Successfully delete FIB entry: vrfEntry={}, vpnId={}", vrfEntry.getDestPrefix(), vpnId);
        return;
    }
    // below two reads are kept as is, until best way is found to identify dpnID
    VpnNexthop localNextHopInfo = nextHopManager.getVpnNexthop(vpnId, vrfEntry.getDestPrefix());
    if (extraRouteOptional.isPresent()) {
        nextHopManager.setupLoadBalancingNextHop(vpnId, remoteDpnId, vrfEntry.getDestPrefix(), Collections.emptyList(), /*listBucketInfo*/
        false);
    } else {
        checkDpnDeleteFibEntry(localNextHopInfo, remoteDpnId, vpnId, vrfEntry, rd, tx, null);
    }
    if (!wrTxPresent) {
        tx.submit();
    }
}
Also used : VpnNexthop(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.VpnNexthop)

Example 14 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 EvpnVrfEntryHandler method createLocalEvpnFlows.

private List<BigInteger> createLocalEvpnFlows(long vpnId, String rd, VrfEntry vrfEntry, Prefixes localNextHopInfo) {
    List<BigInteger> returnLocalDpnId = new ArrayList<>();
    String localNextHopIP = vrfEntry.getDestPrefix();
    if (localNextHopInfo == null) {
        // Handle extra routes and imported routes
        Routes extraRoute = getVpnToExtraroute(vpnId, rd, vrfEntry.getDestPrefix());
        if (extraRoute != null) {
            for (String nextHopIp : extraRoute.getNexthopIpList()) {
                LOG.info("NextHop IP for destination {} is {}", vrfEntry.getDestPrefix(), nextHopIp);
                if (nextHopIp != null) {
                    localNextHopInfo = getFibUtil().getPrefixToInterface(vpnId, nextHopIp + "/32");
                    if (localNextHopInfo != null) {
                        localNextHopIP = nextHopIp + "/32";
                        BigInteger dpnId = checkCreateLocalEvpnFlows(localNextHopInfo, localNextHopIP, vpnId, rd, vrfEntry);
                        returnLocalDpnId.add(dpnId);
                    }
                }
            }
        }
    } else {
        LOG.info("Creating local EVPN flows for prefix {} rd {} route-paths {} evi {}.", vrfEntry.getDestPrefix(), rd, vrfEntry.getRoutePaths(), vrfEntry.getL3vni());
        BigInteger dpnId = checkCreateLocalEvpnFlows(localNextHopInfo, localNextHopIP, vpnId, rd, vrfEntry);
        returnLocalDpnId.add(dpnId);
    }
    return returnLocalDpnId;
}
Also used : ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) Routes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.extra.routes.Routes)

Example 15 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 L3vpnOverMplsGrePopulator method populateFib.

@Override
public void populateFib(L3vpnInput input, WriteTransaction writeConfigTxn) {
    if (input.getRouteOrigin() == RouteOrigin.CONNECTED) {
        LOG.info("populateFib : Found SubnetRoute for subnet {} rd {}", input.getSubnetIp(), input.getPrimaryRd());
        addSubnetRouteFibEntry(input);
        return;
    }
    Adjacency nextHop = input.getNextHop();
    long label = nextHop.getLabel();
    String vpnName = input.getVpnName();
    String primaryRd = input.getPrimaryRd();
    String rd = input.getRd();
    String nextHopIp = input.getNextHopIp();
    VrfEntry.EncapType encapType = input.getEncapType();
    LOG.info("populateFib : Found Interface Adjacency with prefix {} rd {}", nextHop.getIpAddress(), primaryRd);
    List<VpnInstanceOpDataEntry> vpnsToImportRoute = VpnUtil.getVpnsImportingMyRoute(broker, vpnName);
    long vpnId = VpnUtil.getVpnId(broker, vpnName);
    // it is a valid case for nextHopIpAddress to be null
    String nextHopIpAddress = nextHop.getIpAddress();
    // and internalVpnForExtraRoute (where rd is DpnId)
    if (VpnUtil.isEligibleForBgp(primaryRd, input.getVpnName(), input.getDpnId(), input.getNetworkName())) {
        // the DpnId is set as rd in case of extra routes present in router based VPN
        addToLabelMapper(label, input.getDpnId(), nextHopIpAddress, Arrays.asList(nextHopIp), vpnId, input.getInterfaceName(), null, false, primaryRd);
        Objects.requireNonNull(input.getRouteOrigin(), "RouteOrigin is mandatory");
        addPrefixToBGP(rd, primaryRd, null, /*macAddress*/
        nextHopIpAddress, nextHopIp, encapType, label, 0, /*l3vni*/
        input.getGatewayMac(), input.getRouteOrigin(), writeConfigTxn);
        // TODO: ERT - check for VPNs importing my route
        for (VpnInstanceOpDataEntry vpn : vpnsToImportRoute) {
            String vpnRd = vpn.getVrfId();
            if (vpnRd != null) {
                fibManager.addOrUpdateFibEntry(vpnRd, null, /*macAddress*/
                nextHopIpAddress, Arrays.asList(nextHopIp), encapType, (int) label, 0, /*l3vni*/
                input.getGatewayMac(), null, /*parentVpnRd*/
                RouteOrigin.SELF_IMPORTED, writeConfigTxn);
                LOG.info("populateFib: Exported route with rd {} prefix {} nexthop {} label {}" + " to VPN {} for interface {} on dpn {}", vpnRd, nextHop.getIpAddress(), nextHopIp, label, vpn, input.getInterfaceName(), input.getDpnId());
            }
        }
    } else {
        // ### add FIB route directly
        fibManager.addOrUpdateFibEntry(vpnName, null, /*macAddress*/
        nextHopIpAddress, Arrays.asList(nextHopIp), encapType, (int) label, 0, /*l3vni*/
        input.getGatewayMac(), null, /*parentVpnRd*/
        input.getRouteOrigin(), writeConfigTxn);
        LOG.info("populateFib: Added internal FIB entry for prefix {} nexthop {} label {}" + " to VPN {} for interface {} on dpn {}", nextHop.getIpAddress(), nextHopIp, label, vpnName, input.getInterfaceName(), input.getDpnId());
    }
}
Also used : VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) VpnInstanceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency)

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