Search in sources :

Example 11 with InterVpnLinkDataComposite

use of org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite in project netvirt by opendaylight.

the class InterVpnLinkTestCatalog method build.

static InterVpnLinkDataComposite build(String ivpnLinkName, String vpn1Name, String vpn1IpAddr, String vpn2Name, String vpn2IpAddr, boolean bgpFlag, boolean staticFlag, boolean connectedFlag, List<BigInteger> vpn1Dpns, long vpn1LportTag, List<BigInteger> vpn2Dpns, long vpn2LportTag, InterVpnLinkState.State state, Optional<String> errMsg) {
    FirstEndpoint firstEndpoint = new FirstEndpointBuilder().setVpnUuid(new Uuid(vpn1Name)).setIpAddress(new Ipv4Address(vpn1IpAddr)).build();
    SecondEndpoint secondEndpoint = new SecondEndpointBuilder().setVpnUuid(new Uuid(vpn2Name)).setIpAddress(new Ipv4Address(vpn2IpAddr)).build();
    InterVpnLink ivpnLinkCfg = new InterVpnLinkBuilder().setName(ivpnLinkName).setFirstEndpoint(firstEndpoint).setSecondEndpoint(secondEndpoint).setBgpRoutesLeaking(bgpFlag).setStaticRoutesLeaking(staticFlag).setConnectedRoutesLeaking(connectedFlag).build();
    FirstEndpointState firstEndpointState = new FirstEndpointStateBuilder().setVpnUuid(new Uuid(vpn1Name)).setLportTag(vpn1LportTag).setDpId(vpn1Dpns).build();
    SecondEndpointState secondEndpointState = new SecondEndpointStateBuilder().setVpnUuid(new Uuid(vpn2Name)).setLportTag(vpn2LportTag).setDpId(vpn2Dpns).build();
    InterVpnLinkState ivpnLinkState = new InterVpnLinkStateBuilder().setInterVpnLinkName(ivpnLinkName).setState(state).setErrorDescription(errMsg.or("")).setFirstEndpointState(firstEndpointState).setSecondEndpointState(secondEndpointState).build();
    return new InterVpnLinkDataComposite(ivpnLinkCfg, ivpnLinkState);
}
Also used : InterVpnLinkBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.links.InterVpnLinkBuilder) SecondEndpoint(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.links.inter.vpn.link.SecondEndpoint) SecondEndpointBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.links.inter.vpn.link.SecondEndpointBuilder) FirstEndpoint(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.links.inter.vpn.link.FirstEndpoint) FirstEndpointState(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.inter.vpn.link.state.FirstEndpointState) InterVpnLinkStateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.InterVpnLinkStateBuilder) InterVpnLink(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.links.InterVpnLink) FirstEndpointStateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.inter.vpn.link.state.FirstEndpointStateBuilder) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) SecondEndpointStateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.inter.vpn.link.state.SecondEndpointStateBuilder) SecondEndpointState(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.inter.vpn.link.state.SecondEndpointState) InterVpnLinkState(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.InterVpnLinkState) FirstEndpointBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.links.inter.vpn.link.FirstEndpointBuilder) InterVpnLinkDataComposite(org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)

Example 12 with InterVpnLinkDataComposite

use of org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite in project netvirt by opendaylight.

the class InterVpnLinkTestCatalog method cleanIvpnLinks.

public static void cleanIvpnLinks(DataBroker broker2, InterVpnLinkDataComposite... ivpnLinks) throws TransactionCommitFailedException {
    for (InterVpnLinkDataComposite ivpnLink : ivpnLinks) {
        WriteTransaction writeTx1 = broker2.newWriteOnlyTransaction();
        writeTx1.delete(LogicalDatastoreType.OPERATIONAL, InterVpnLinkUtil.getInterVpnLinkStateIid(ivpnLink.getInterVpnLinkName()));
        writeTx1.submit().checkedGet();
        WriteTransaction writeTx2 = broker2.newWriteOnlyTransaction();
        writeTx2.delete(LogicalDatastoreType.CONFIGURATION, InterVpnLinkUtil.getInterVpnLinkPath(ivpnLink.getInterVpnLinkName()));
        writeTx2.submit().checkedGet();
    }
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) InterVpnLinkDataComposite(org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite)

Example 13 with InterVpnLinkDataComposite

use of org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite 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 14 with InterVpnLinkDataComposite

use of org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite in project netvirt by opendaylight.

the class IVpnLinkServiceImpl method leakRoute.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public void leakRoute(InterVpnLinkDataComposite interVpnLink, String srcVpnUuid, String dstVpnUuid, String prefix, Long label, RouteOrigin forcedOrigin) {
    String ivpnLinkName = interVpnLink.getInterVpnLinkName();
    // The source VPN must participate in the InterVpnLink
    Preconditions.checkArgument(interVpnLink.isVpnLinked(srcVpnUuid), "The source VPN {} does not participate in the interVpnLink {}", srcVpnUuid, ivpnLinkName);
    // The destination VPN must participate in the InterVpnLink
    Preconditions.checkArgument(interVpnLink.isVpnLinked(dstVpnUuid), "The destination VPN {} does not participate in the interVpnLink {}", dstVpnUuid, ivpnLinkName);
    String endpointIp = interVpnLink.getOtherEndpointIpAddr(dstVpnUuid);
    String leakedOrigin = forcedOrigin != null ? forcedOrigin.getValue() : RouteOrigin.INTERVPN.getValue();
    FibHelper.buildRoutePath(endpointIp, label);
    VrfEntry newVrfEntry = new VrfEntryBuilder().setKey(new VrfEntryKey(prefix)).setDestPrefix(prefix).setRoutePaths(Collections.singletonList(FibHelper.buildRoutePath(endpointIp, label))).setOrigin(leakedOrigin).build();
    String dstVpnRd = VpnUtil.getVpnRd(dataBroker, dstVpnUuid);
    InstanceIdentifier<VrfEntry> newVrfEntryIid = InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class, new VrfTablesKey(dstVpnRd)).child(VrfEntry.class, new VrfEntryKey(newVrfEntry.getDestPrefix())).build();
    VpnUtil.asyncWrite(dataBroker, 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
    List<BigInteger> srcDpnList = interVpnLink.getEndpointDpnsByVpnName(srcVpnUuid);
    List<String> nexthops = srcDpnList.stream().map(dpnId -> InterfaceUtils.getEndpointIpAddressForDPN(dataBroker, dpnId)).collect(Collectors.toList());
    LOG.debug("Advertising route in VPN={} [prefix={} label={}  nexthops={}] to DC-GW", dstVpnRd, newVrfEntry.getDestPrefix(), label.intValue(), nexthops);
    try {
        bgpManager.advertisePrefix(dstVpnRd, null, /*macAddress*/
        prefix, nexthops, VrfEntry.EncapType.Mplsgre, label.intValue(), 0, /*l3vni*/
        0, /*l2vni*/
        null);
    } catch (Exception e) {
        LOG.error("Exception while advertising prefix {} on vpnRd {} for intervpn link", prefix, dstVpnRd, e);
    }
}
Also used : IFibManager(org.opendaylight.netvirt.fibmanager.api.IFibManager) VpnUtil(org.opendaylight.netvirt.vpnmanager.VpnUtil) FibEntries(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.FibEntries) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) Singleton(javax.inject.Singleton) Neutron(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.Routers) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) PreDestroy(javax.annotation.PreDestroy) InterVpnLinkCache(org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkCache) InterfaceUtils(org.opendaylight.netvirt.vpnmanager.api.InterfaceUtils) InterVpnLinkDataComposite(org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite) Optional(com.google.common.base.Optional) VpnConstants(org.opendaylight.netvirt.vpnmanager.VpnConstants) Map(java.util.Map) IBgpManager(org.opendaylight.netvirt.bgpmanager.api.IBgpManager) BigInteger(java.math.BigInteger) NwConstants(org.opendaylight.genius.mdsalutil.NwConstants) MDSALUtil(org.opendaylight.genius.mdsalutil.MDSALUtil) IVpnLinkService(org.opendaylight.netvirt.vpnmanager.api.intervpnlink.IVpnLinkService) VpnMaps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.VpnMaps) Logger(org.slf4j.Logger) Predicate(java.util.function.Predicate) VrfTablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTablesKey) RouteOrigin(org.opendaylight.netvirt.fibmanager.api.RouteOrigin) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) VrfTables(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTables) Routes(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.l3.attributes.Routes) Collectors(java.util.stream.Collectors) IdManagerService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService) VpnMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) List(java.util.List) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) VrfEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntryBuilder) PostConstruct(javax.annotation.PostConstruct) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) Router(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router) Preconditions(com.google.common.base.Preconditions) VrfEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntryKey) Collections(java.util.Collections) FibHelper(org.opendaylight.netvirt.fibmanager.api.FibHelper) 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) BigInteger(java.math.BigInteger) VrfEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntryBuilder) VrfEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntryKey)

Example 15 with InterVpnLinkDataComposite

use of org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite in project netvirt by opendaylight.

the class InterVpnLinkLocator method findDPNsWithNoInterVpnLink.

/*
     * Given a list of Dpn Ids and a list of InterVpnLinks, this method finds
     * the DPNs in the first list where no InterVpnLink is instantiated there.
     *
     * @param dpnList A list of DPN IDs
     * @param interVpnLinks A List of InterVpnLinks to avoid
     *
     * @return the list of available DPNs among the specified ones
     */
private List<BigInteger> findDPNsWithNoInterVpnLink(List<BigInteger> dpnList, List<InterVpnLinkDataComposite> interVpnLinks) {
    List<BigInteger> occupiedDpns = new ArrayList<>();
    for (InterVpnLinkDataComposite ivl : interVpnLinks) {
        if (ivl.isActive()) {
            occupiedDpns.addAll(ivl.getFirstEndpointDpns());
            occupiedDpns.addAll(ivl.getSecondEndpointDpns());
        }
    }
    List<BigInteger> result = new ArrayList<>(dpnList);
    result.removeAll(occupiedDpns);
    return result;
}
Also used : ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) InterVpnLinkDataComposite(org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite)

Aggregations

InterVpnLinkDataComposite (org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite)20 BigInteger (java.math.BigInteger)9 ArrayList (java.util.ArrayList)6 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)5 List (java.util.List)3 PostConstruct (javax.annotation.PostConstruct)3 Inject (javax.inject.Inject)3 Singleton (javax.inject.Singleton)3 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)3 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)3 VrfTablesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTablesKey)3 Optional (com.google.common.base.Optional)2 Preconditions (com.google.common.base.Preconditions)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 Predicate (java.util.function.Predicate)2 Collectors (java.util.stream.Collectors)2