Search in sources :

Example 21 with InterVpnLink

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.links.InterVpnLink in project netvirt by opendaylight.

the class InterVpnLinkNodeListener method reinstallInterVpnLink.

private void reinstallInterVpnLink(InterVpnLinkDataComposite ivl) {
    String ivlName = ivl.getInterVpnLinkName();
    LOG.debug("Reinstalling InterVpnLink {} affected by node going down", ivlName);
    // Lets move the InterVpnLink to some other place. Basically, remove it and create it again
    InstanceIdentifier<InterVpnLink> interVpnLinkIid = InterVpnLinkUtil.getInterVpnLinkPath(ivlName);
    String specificJobKey = "InterVpnLink.update." + ivlName;
    InterVpnLink interVpnLink = ivl.getInterVpnLinkConfig();
    jobCoordinator.enqueueJob(specificJobKey, new InterVpnLinkRemoverTask(dataBroker, interVpnLinkIid));
    jobCoordinator.enqueueJob(specificJobKey, new InterVpnLinkCleanedCheckerTask(dataBroker, interVpnLink));
    jobCoordinator.enqueueJob(specificJobKey, new InterVpnLinkCreatorTask(dataBroker, interVpnLink));
}
Also used : InterVpnLink(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.links.InterVpnLink) InterVpnLinkRemoverTask(org.opendaylight.netvirt.vpnmanager.intervpnlink.tasks.InterVpnLinkRemoverTask) InterVpnLinkCleanedCheckerTask(org.opendaylight.netvirt.vpnmanager.intervpnlink.tasks.InterVpnLinkCleanedCheckerTask) InterVpnLinkCreatorTask(org.opendaylight.netvirt.vpnmanager.intervpnlink.tasks.InterVpnLinkCreatorTask)

Example 22 with InterVpnLink

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.links.InterVpnLink 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 23 with InterVpnLink

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.links.InterVpnLink in project netvirt by opendaylight.

the class InterVpnLinkUtil method installLPortDispatcherTableFlow.

/**
 * Installs a Flow in LPortDispatcher table that matches on SI=2 and
 * the lportTag of one InterVpnLink's endpoint and sets the vrfTag of the
 * other endpoint and sends to FIB table.
 *
 * @param broker dataBroker service reference
 * @param mdsalManager MDSAL API accessor
 * @param interVpnLinkName Name of the InterVpnLink.
 * @param dpnList The list of DPNs where this flow must be installed
 * @param vpnUuidOtherEndpoint UUID of the other endpoint of the InterVpnLink
 * @param lportTagOfOtherEndpoint Dataplane identifier of the other endpoint of the InterVpnLink
 * @return the list of Futures for each and every flow that has been installed
 */
public static List<ListenableFuture<Void>> installLPortDispatcherTableFlow(DataBroker broker, IMdsalApiManager mdsalManager, String interVpnLinkName, List<BigInteger> dpnList, String vpnUuidOtherEndpoint, Long lportTagOfOtherEndpoint) {
    List<ListenableFuture<Void>> result = new ArrayList<>();
    long vpnId = VpnUtil.getVpnId(broker, vpnUuidOtherEndpoint);
    for (BigInteger dpnId : dpnList) {
        // insert into LPortDispatcher table
        Flow lportDispatcherFlow = buildLPortDispatcherFlow(interVpnLinkName, vpnId, lportTagOfOtherEndpoint.intValue());
        result.add(mdsalManager.installFlow(dpnId, lportDispatcherFlow));
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) BigInteger(java.math.BigInteger) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)

Example 24 with InterVpnLink

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.links.InterVpnLink in project netvirt by opendaylight.

the class VrfEntryListener method installIVpnLinkSwitchingFlows.

/*
     * Installs the flows in FIB table that, for a given route, do the switching from one VPN to the other.
     */
private void installIVpnLinkSwitchingFlows(final InterVpnLinkDataComposite interVpnLink, final String vpnUuid, final VrfEntry vrfEntry, long vpnTag) {
    Preconditions.checkNotNull(interVpnLink, "InterVpnLink cannot be null");
    Preconditions.checkArgument(vrfEntry.getRoutePaths() != null && vrfEntry.getRoutePaths().size() == 1);
    String destination = vrfEntry.getDestPrefix();
    String nextHop = vrfEntry.getRoutePaths().get(0).getNexthopAddress();
    String interVpnLinkName = interVpnLink.getInterVpnLinkName();
    // using as metadata the LPortTag associated to that vpn in the inter-vpn-link.
    if (interVpnLink.getState().or(State.Error) != State.Active) {
        LOG.warn("Route to {} with nexthop={} cannot be installed because the interVpnLink {} is not active", destination, nextHop, interVpnLinkName);
        return;
    }
    Optional<Long> optOtherEndpointLportTag = interVpnLink.getOtherEndpointLportTagByVpnName(vpnUuid);
    if (!optOtherEndpointLportTag.isPresent()) {
        LOG.warn("Could not find suitable LportTag for the endpoint opposite to vpn {} in interVpnLink {}", vpnUuid, interVpnLinkName);
        return;
    }
    List<BigInteger> targetDpns = interVpnLink.getEndpointDpnsByVpnName(vpnUuid);
    if (targetDpns.isEmpty()) {
        LOG.warn("Could not find DPNs for endpoint opposite to vpn {} in interVpnLink {}", vpnUuid, interVpnLinkName);
        return;
    }
    String[] values = destination.split("/");
    String destPrefixIpAddress = values[0];
    int prefixLength = values.length == 1 ? 0 : Integer.parseInt(values[1]);
    List<MatchInfo> matches = new ArrayList<>();
    matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnTag), MetaDataUtil.METADATA_MASK_VRFID));
    matches.add(MatchEthernetType.IPV4);
    if (prefixLength != 0) {
        matches.add(new MatchIpv4Destination(destPrefixIpAddress, Integer.toString(prefixLength)));
    }
    List<Instruction> instructions = Arrays.asList(new InstructionWriteMetadata(MetaDataUtil.getMetaDataForLPortDispatcher(optOtherEndpointLportTag.get().intValue(), ServiceIndex.getIndex(NwConstants.L3VPN_SERVICE_NAME, NwConstants.L3VPN_SERVICE_INDEX)), MetaDataUtil.getMetaDataMaskForLPortDispatcher()).buildInstruction(0), new InstructionGotoTable(NwConstants.L3_INTERFACE_TABLE).buildInstruction(1));
    int priority = DEFAULT_FIB_FLOW_PRIORITY + prefixLength;
    String flowRef = getInterVpnFibFlowRef(interVpnLinkName, destination, nextHop);
    Flow flowEntity = MDSALUtil.buildFlowNew(NwConstants.L3_FIB_TABLE, flowRef, priority, flowRef, 0, 0, COOKIE_VM_FIB_TABLE, matches, instructions);
    LOG.trace("Installing flow in FIB table for vpn {} interVpnLink {} nextHop {} key {}", vpnUuid, interVpnLink.getInterVpnLinkName(), nextHop, flowRef);
    for (BigInteger dpId : targetDpns) {
        LOG.debug("Installing flow: VrfEntry=[prefix={} route-paths={}] dpn {} for InterVpnLink {} in FIB", vrfEntry.getDestPrefix(), vrfEntry.getRoutePaths(), dpId, interVpnLink.getInterVpnLinkName());
        mdsalManager.installFlow(dpId, flowEntity);
    }
}
Also used : MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) MatchIpv4Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) BigInteger(java.math.BigInteger) InstructionWriteMetadata(org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata)

Example 25 with InterVpnLink

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.links.InterVpnLink in project netvirt by opendaylight.

the class NeutronRouterChangeListener method handleChangedRoutes.

private void handleChangedRoutes(Uuid vpnName, List<Routes> routes, int addedOrRemoved) {
    // Some routes may point to an InterVpnLink's endpoint, lets treat them differently
    List<Routes> interVpnLinkRoutes = new ArrayList<>();
    List<Routes> otherRoutes = new ArrayList<>();
    HashMap<String, InterVpnLink> nexthopsXinterVpnLinks = new HashMap<>();
    for (Routes route : routes) {
        String nextHop = String.valueOf(route.getNexthop().getValue());
        // Nexthop is another VPN?
        Optional<InterVpnLink> interVpnLink = neutronvpnUtils.getInterVpnLinkByEndpointIp(nextHop);
        if (interVpnLink.isPresent()) {
            Optional<InterVpnLinkState> interVpnLinkState = neutronvpnUtils.getInterVpnLinkState(interVpnLink.get().getName());
            if (interVpnLinkState.isPresent() && interVpnLinkState.get().getState() == InterVpnLinkState.State.Active) {
                interVpnLinkRoutes.add(route);
                nexthopsXinterVpnLinks.put(nextHop, interVpnLink.get());
            } else {
                LOG.error("Failed installing route to {}. Reason: InterVPNLink {} is not Active", String.valueOf(route.getDestination().getValue()), interVpnLink.get().getName());
            }
        } else {
            otherRoutes.add(route);
        }
    }
    if (addedOrRemoved == NwConstants.ADD_FLOW) {
        nvpnManager.addInterVpnRoutes(vpnName, interVpnLinkRoutes, nexthopsXinterVpnLinks);
        nvpnManager.updateVpnInterfaceWithExtraRouteAdjacency(vpnName, otherRoutes);
    } else {
        nvpnManager.removeAdjacencyforExtraRoute(vpnName, otherRoutes);
        nvpnManager.removeInterVpnRoutes(vpnName, interVpnLinkRoutes, nexthopsXinterVpnLinks);
    }
}
Also used : InterVpnLink(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.links.InterVpnLink) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Routes(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.l3.attributes.Routes) InterVpnLinkState(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.InterVpnLinkState)

Aggregations

BigInteger (java.math.BigInteger)11 ArrayList (java.util.ArrayList)8 InterVpnLinkState (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.InterVpnLinkState)8 InterVpnLinkDataComposite (org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite)7 InterVpnLink (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.links.InterVpnLink)7 Routes (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.l3.attributes.Routes)6 VrfTablesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTablesKey)5 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)4 VrfEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry)4 InterVpnLinkStateBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.InterVpnLinkStateBuilder)4 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)3 HashMap (java.util.HashMap)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3 ExecutionException (java.util.concurrent.ExecutionException)3 PostConstruct (javax.annotation.PostConstruct)3 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)3 Optional (com.google.common.base.Optional)2 Preconditions (com.google.common.base.Preconditions)2 Collections (java.util.Collections)2 List (java.util.List)2