Search in sources :

Example 26 with Origin

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.Origin in project netvirt by opendaylight.

the class VpnManagerImpl method addExtraRoute.

@Override
public void addExtraRoute(String vpnName, String destination, String nextHop, String rd, String routerID, Long l3vni, RouteOrigin origin, String intfName, Adjacency operationalAdj, VrfEntry.EncapType encapType, WriteTransaction writeConfigTxn) {
    Boolean writeConfigTxnPresent = true;
    if (writeConfigTxn == null) {
        writeConfigTxnPresent = false;
        writeConfigTxn = dataBroker.newWriteOnlyTransaction();
    }
    // add extra route to vpn mapping; advertise with nexthop as tunnel ip
    VpnUtil.syncUpdate(dataBroker, LogicalDatastoreType.OPERATIONAL, VpnExtraRouteHelper.getVpnToExtrarouteVrfIdIdentifier(vpnName, rd != null ? rd : routerID, destination), VpnUtil.getVpnToExtraroute(destination, Collections.singletonList(nextHop)));
    BigInteger dpnId = null;
    if (intfName != null && !intfName.isEmpty()) {
        dpnId = InterfaceUtils.getDpnForInterface(ifaceMgrRpcService, intfName);
        String nextHopIp = InterfaceUtils.getEndpointIpAddressForDPN(dataBroker, dpnId);
        if (nextHopIp == null || nextHopIp.isEmpty()) {
            LOG.error("addExtraRoute: NextHop for interface {} is null / empty." + " Failed advertising extra route for rd {} prefix {} dpn {}", intfName, rd, destination, dpnId);
            return;
        }
        nextHop = nextHopIp;
    }
    String primaryRd = VpnUtil.getPrimaryRd(dataBroker, vpnName);
    // TODO: This is a limitation to be stated in docs. When configuring static route to go to
    // another VPN, there can only be one nexthop or, at least, the nexthop to the interVpnLink should be in
    // first place.
    Optional<InterVpnLinkDataComposite> optVpnLink = interVpnLinkCache.getInterVpnLinkByEndpoint(nextHop);
    if (optVpnLink.isPresent() && optVpnLink.get().isActive()) {
        InterVpnLinkDataComposite interVpnLink = optVpnLink.get();
        // If the nexthop is the endpoint of Vpn2, then prefix must be advertised to Vpn1 in DC-GW, with nexthops
        // pointing to the DPNs where Vpn1 is instantiated. LFIB in these DPNS must have a flow entry, with lower
        // priority, where if Label matches then sets the lportTag of the Vpn2 endpoint and goes to LportDispatcher
        // This is like leaking one of the Vpn2 routes towards Vpn1
        String srcVpnUuid = interVpnLink.getVpnNameByIpAddress(nextHop);
        String dstVpnUuid = interVpnLink.getOtherVpnNameByIpAddress(nextHop);
        String dstVpnRd = VpnUtil.getVpnRd(dataBroker, dstVpnUuid);
        long newLabel = VpnUtil.getUniqueId(idManager, VpnConstants.VPN_IDPOOL_NAME, VpnUtil.getNextHopLabelKey(dstVpnRd, destination));
        if (newLabel == 0) {
            LOG.error("addExtraRoute: Unable to fetch label from Id Manager. Bailing out of adding intervpnlink" + " route for destination {}", destination);
            return;
        }
        ivpnLinkService.leakRoute(interVpnLink, srcVpnUuid, dstVpnUuid, destination, newLabel, RouteOrigin.STATIC);
    } else {
        Optional<Routes> optVpnExtraRoutes = VpnExtraRouteHelper.getVpnExtraroutes(dataBroker, vpnName, rd != null ? rd : routerID, destination);
        if (optVpnExtraRoutes.isPresent()) {
            List<String> nhList = optVpnExtraRoutes.get().getNexthopIpList();
            if (nhList != null && nhList.size() > 1) {
                // If nhList is greater than one for vpnextraroute, a call to populatefib doesn't update vrfentry.
                fibManager.refreshVrfEntry(primaryRd, destination);
            } else {
                L3vpnInput input = new L3vpnInput().setNextHop(operationalAdj).setNextHopIp(nextHop).setL3vni(l3vni).setPrimaryRd(primaryRd).setVpnName(vpnName).setDpnId(dpnId).setEncapType(encapType).setRd(rd).setRouteOrigin(origin);
                L3vpnRegistry.getRegisteredPopulator(encapType).populateFib(input, writeConfigTxn);
            }
        }
    }
    if (!writeConfigTxnPresent) {
        writeConfigTxn.submit();
    }
}
Also used : BigInteger(java.math.BigInteger) Routes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.extra.routes.Routes) L3vpnInput(org.opendaylight.netvirt.vpnmanager.populator.input.L3vpnInput) InterVpnLinkDataComposite(org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite)

Example 27 with Origin

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.Origin in project netvirt by opendaylight.

the class VpnUtil method getVrfEntriesByOrigin.

/**
 * Retrieves the VrfEntries that belong to a given VPN filtered out by
 * Origin, searching by its Route-Distinguisher.
 *
 * @param broker dataBroker service reference
 * @param rd Route-distinguisher of the VPN
 * @param originsToConsider Only entries whose origin is included in this list will be considered
 * @return the list of VrfEntries
 */
public static List<VrfEntry> getVrfEntriesByOrigin(DataBroker broker, String rd, List<RouteOrigin> originsToConsider) {
    List<VrfEntry> result = new ArrayList<>();
    List<VrfEntry> allVpnVrfEntries = getAllVrfEntries(broker, rd);
    for (VrfEntry vrfEntry : allVpnVrfEntries) {
        if (originsToConsider.contains(RouteOrigin.value(vrfEntry.getOrigin()))) {
            result.add(vrfEntry);
        }
    }
    return result;
}
Also used : VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) ArrayList(java.util.ArrayList)

Example 28 with Origin

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.Origin in project netvirt by opendaylight.

the class VpnUtil method removeVrfEntriesByOrigin.

/**
 * Remove from MDSAL all those VrfEntries in a VPN that have an specific RouteOrigin.
 *
 * @param broker dataBroker service reference
 * @param rd Route Distinguisher
 * @param origin Origin of the Routes to be removed (see {@link RouteOrigin})
 */
public static void removeVrfEntriesByOrigin(DataBroker broker, String rd, RouteOrigin origin) {
    InstanceIdentifier<VrfTables> vpnVrfTableIid = InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class, new VrfTablesKey(rd)).build();
    Optional<VrfTables> vrfTablesOpc = read(broker, LogicalDatastoreType.CONFIGURATION, vpnVrfTableIid);
    if (vrfTablesOpc.isPresent()) {
        VrfTables vrfTables = vrfTablesOpc.get();
        WriteTransaction tx = broker.newWriteOnlyTransaction();
        for (VrfEntry vrfEntry : vrfTables.getVrfEntry()) {
            if (origin == RouteOrigin.value(vrfEntry.getOrigin())) {
                tx.delete(LogicalDatastoreType.CONFIGURATION, vpnVrfTableIid.child(VrfEntry.class, vrfEntry.getKey()));
            }
        }
        tx.submit();
    }
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) 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) VrfTables(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTables)

Example 29 with Origin

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.Origin in project netvirt by opendaylight.

the class InterVpnLinkUtil method leakRoute.

/**
 * Leaks a route from one VPN to another. By default, the origin for this leaked route is INTERVPN.
 *
 * @param broker dataBroker service reference
 * @param bgpManager Used to advertise routes to the BGP Router
 * @param interVpnLink Reference to the object that holds the info about the link between the 2 VPNs
 * @param srcVpnUuid UUID of the VPN that has the route that is going to be leaked to the other VPN
 * @param dstVpnUuid UUID of the VPN that is going to receive the route
 * @param prefix Prefix of the route
 * @param label Label of the route in the original VPN
 */
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public static void leakRoute(DataBroker broker, IBgpManager bgpManager, InterVpnLink interVpnLink, String srcVpnUuid, String dstVpnUuid, String prefix, Long label) {
    Preconditions.checkNotNull(interVpnLink);
    // The source VPN must participate in the InterVpnLink
    Preconditions.checkArgument(interVpnLink.getFirstEndpoint().getVpnUuid().getValue().equals(srcVpnUuid) || interVpnLink.getSecondEndpoint().getVpnUuid().getValue().equals(srcVpnUuid), "The source VPN {} does not participate in the interVpnLink {}", srcVpnUuid, interVpnLink.getName());
    // The destination VPN must participate in the InterVpnLink
    Preconditions.checkArgument(interVpnLink.getFirstEndpoint().getVpnUuid().getValue().equals(dstVpnUuid) || interVpnLink.getSecondEndpoint().getVpnUuid().getValue().equals(dstVpnUuid), "The destination VPN {} does not participate in the interVpnLink {}", dstVpnUuid, interVpnLink.getName());
    boolean destinationIs1stEndpoint = interVpnLink.getFirstEndpoint().getVpnUuid().getValue().equals(dstVpnUuid);
    String endpointIp = destinationIs1stEndpoint ? interVpnLink.getSecondEndpoint().getIpAddress().getValue() : interVpnLink.getFirstEndpoint().getIpAddress().getValue();
    VrfEntry newVrfEntry = FibHelper.getVrfEntryBuilder(prefix, label, endpointIp, RouteOrigin.INTERVPN, null).build();
    String dstVpnRd = VpnUtil.getVpnRd(broker, dstVpnUuid);
    InstanceIdentifier<VrfEntry> newVrfEntryIid = InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class, new VrfTablesKey(dstVpnRd)).child(VrfEntry.class, new VrfEntryKey(newVrfEntry.getDestPrefix())).build();
    VpnUtil.asyncWrite(broker, LogicalDatastoreType.CONFIGURATION, newVrfEntryIid, newVrfEntry);
    // Finally, route is advertised it to the DC-GW. But while in the FibEntries the nexthop is the other
    // endpoint's IP, in the DC-GW the nexthop for those prefixes are the IPs of those DPNs where the target
    // VPN has been instantiated
    Optional<InterVpnLinkState> optVpnLinkState = getInterVpnLinkState(broker, interVpnLink.getName());
    if (optVpnLinkState.isPresent()) {
        InterVpnLinkState vpnLinkState = optVpnLinkState.get();
        List<BigInteger> dpnIdList = destinationIs1stEndpoint ? vpnLinkState.getFirstEndpointState().getDpId() : vpnLinkState.getSecondEndpointState().getDpId();
        List<String> nexthops = new ArrayList<>();
        for (BigInteger dpnId : dpnIdList) {
            nexthops.add(InterfaceUtils.getEndpointIpAddressForDPN(broker, dpnId));
        }
        try {
            LOG.debug("Advertising route in VPN={} [prefix={} label={}  nexthops={}] to DC-GW", dstVpnRd, newVrfEntry.getDestPrefix(), label.intValue(), nexthops);
            bgpManager.advertisePrefix(dstVpnRd, null, /*macAddress*/
            newVrfEntry.getDestPrefix(), nexthops, VrfEntry.EncapType.Mplsgre, label.intValue(), 0, /*l3vni*/
            0, /*l2vni*/
            null);
        } catch (Exception ex) {
            LOG.error("Could not advertise prefix {} with label {} to VPN rd={}", newVrfEntry.getDestPrefix(), label.intValue(), dstVpnRd, ex);
        }
    } else {
        LOG.warn("Error when advertising leaked routes: Could not find State for InterVpnLink={}", interVpnLink.getName());
    }
}
Also used : FibEntries(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.FibEntries) ArrayList(java.util.ArrayList) VrfEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntryKey) VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) VrfTablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTablesKey) BigInteger(java.math.BigInteger) InterVpnLinkState(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.InterVpnLinkState)

Example 30 with Origin

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.Origin in project netvirt by opendaylight.

the class FibDSWriter method addFibEntryToDS.

public synchronized void addFibEntryToDS(String rd, String prefix, List<String> nextHopList, VrfEntry.EncapType encapType, int label, long l3vni, String gatewayMacAddress, RouteOrigin origin) {
    if (rd == null || rd.isEmpty()) {
        LOG.error("Prefix {} not associated with vpn", prefix);
        return;
    }
    Preconditions.checkNotNull(nextHopList, "NextHopList can't be null");
    for (String nextHop : nextHopList) {
        if (nextHop == null || nextHop.isEmpty()) {
            LOG.error("nextHop list contains null element");
            return;
        }
        LOG.debug("Created vrfEntry for {} nexthop {} label {}", prefix, nextHop, label);
    }
    // Looking for existing prefix in MDSAL database
    InstanceIdentifier<VrfEntry> vrfEntryId = InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class, new VrfTablesKey(rd)).child(VrfEntry.class, new VrfEntryKey(prefix)).build();
    VrfEntryBuilder vrfEntryBuilder = new VrfEntryBuilder().setDestPrefix(prefix).setOrigin(origin.getValue());
    buildVpnEncapSpecificInfo(vrfEntryBuilder, encapType, label, l3vni, gatewayMacAddress, nextHopList);
    bgpUtil.update(vrfEntryId, vrfEntryBuilder.build());
}
Also used : MacVrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.macvrfentries.MacVrfEntry) VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) VrfTablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTablesKey) FibEntries(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.FibEntries) MacVrfEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.macvrfentries.MacVrfEntryKey) VrfEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntryKey) MacVrfEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.macvrfentries.MacVrfEntryBuilder) VrfEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntryBuilder)

Aggregations

AttributesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder)14 Test (org.junit.Test)13 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)12 VrfEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry)11 OriginBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.OriginBuilder)11 UpdateBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.UpdateBuilder)10 Attributes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes)10 AsPathBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.AsPathBuilder)10 Ipv4NextHopCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCaseBuilder)10 Ipv4NextHopBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder)10 ArrayList (java.util.ArrayList)8 VrfTablesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTablesKey)8 ByteBuf (io.netty.buffer.ByteBuf)7 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)7 FibEntries (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.FibEntries)7 Update (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update)7 LocalPrefBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.LocalPrefBuilder)7 Nlri (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.update.message.Nlri)7 NlriBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.update.message.NlriBuilder)7 AsNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)6