Search in sources :

Example 16 with InterVpnLinkDataComposite

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

the class InterVpnLinkNodeAddTask method installLPortDispatcherTable.

private void installLPortDispatcherTable(InterVpnLinkState interVpnLinkState, List<BigInteger> firstDpnList, List<BigInteger> secondDpnList) {
    String ivpnLinkName = interVpnLinkState.getKey().getInterVpnLinkName();
    Optional<InterVpnLinkDataComposite> optVpnLink = interVpnLinkCache.getInterVpnLinkByName(ivpnLinkName);
    if (!optVpnLink.isPresent()) {
        LOG.warn("installLPortDispatcherTable: Could not find interVpnLink {}", ivpnLinkName);
        return;
    }
    InterVpnLinkDataComposite vpnLink = optVpnLink.get();
    Optional<Long> opt1stEndpointLportTag = vpnLink.getFirstEndpointLportTag();
    if (!opt1stEndpointLportTag.isPresent()) {
        LOG.warn("installLPortDispatcherTable: Could not find LPortTag for 1stEnpoint in InterVpnLink {}", ivpnLinkName);
        return;
    }
    Optional<Long> opt2ndEndpointLportTag = vpnLink.getSecondEndpointLportTag();
    if (!opt2ndEndpointLportTag.isPresent()) {
        LOG.warn("installLPortDispatcherTable: Could not find LPortTag for 2ndEnpoint in InterVpnLink {}", ivpnLinkName);
        return;
    }
    String firstEndpointVpnUuid = vpnLink.getFirstEndpointVpnUuid().get();
    String secondEndpointVpnUuid = vpnLink.getSecondEndpointVpnUuid().get();
    // Note that in the DPN of the firstEndpoint we install the lportTag of the secondEndpoint and viceversa
    String vpn1PrimaryRd = VpnUtil.getPrimaryRd(broker, firstEndpointVpnUuid);
    String vpn2PrimaryRd = VpnUtil.getPrimaryRd(broker, secondEndpointVpnUuid);
    if (!VpnUtil.isVpnPendingDelete(broker, vpn1PrimaryRd) && !VpnUtil.isVpnPendingDelete(broker, vpn2PrimaryRd)) {
        InterVpnLinkUtil.installLPortDispatcherTableFlow(broker, mdsalManager, ivpnLinkName, firstDpnList, secondEndpointVpnUuid, opt2ndEndpointLportTag.get());
        InterVpnLinkUtil.installLPortDispatcherTableFlow(broker, mdsalManager, ivpnLinkName, secondDpnList, firstEndpointVpnUuid, opt1stEndpointLportTag.get());
        // Update the VPN -> DPNs Map.
        // Note: when a set of DPNs is calculated for Vpn1, these DPNs are added to the VpnToDpn map of Vpn2. Why?
        // because we do the handover from Vpn1 to Vpn2 in those DPNs, so in those DPNs we must know how to reach
        // to Vpn2 targets. If new Vpn2 targets are added later, the Fib will be maintained in these DPNs even if
        // Vpn2 is not physically present there.
        InterVpnLinkUtil.updateVpnFootprint(vpnFootprintService, secondEndpointVpnUuid, vpn1PrimaryRd, firstDpnList);
        InterVpnLinkUtil.updateVpnFootprint(vpnFootprintService, firstEndpointVpnUuid, vpn2PrimaryRd, secondDpnList);
    }
}
Also used : InterVpnLinkDataComposite(org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite)

Example 17 with InterVpnLinkDataComposite

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

the class VpnRpcServiceImpl method addStaticRoute.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public Future<RpcResult<AddStaticRouteOutput>> addStaticRoute(AddStaticRouteInput input) {
    SettableFuture<RpcResult<AddStaticRouteOutput>> result = SettableFuture.create();
    String destination = input.getDestination();
    String vpnInstanceName = input.getVpnInstanceName();
    String nexthop = input.getNexthop();
    Long label = input.getLabel();
    LOG.info("Adding static route for Vpn {} with destination {}, nexthop {} and label {}", vpnInstanceName, destination, nexthop, label);
    Collection<RpcError> rpcErrors = validateAddStaticRouteInput(input);
    if (!rpcErrors.isEmpty()) {
        result.set(RpcResultBuilder.<AddStaticRouteOutput>failed().withRpcErrors(rpcErrors).build());
        return result;
    }
    if (label == null || label == 0) {
        label = (long) VpnUtil.getUniqueId(idManager, VpnConstants.VPN_IDPOOL_NAME, VpnUtil.getNextHopLabelKey(vpnInstanceName, destination));
        if (label == 0) {
            String message = "Unable to retrieve a new Label for the new Route";
            result.set(RpcResultBuilder.<AddStaticRouteOutput>failed().withError(RpcError.ErrorType.APPLICATION, message).build());
            return result;
        }
    }
    String vpnRd = VpnUtil.getVpnRd(dataBroker, input.getVpnInstanceName());
    VpnInstanceOpDataEntry vpnOpEntry = VpnUtil.getVpnInstanceOpData(dataBroker, vpnRd);
    Boolean isVxlan = VpnUtil.isL3VpnOverVxLan(vpnOpEntry.getL3vni());
    VrfEntry.EncapType encapType = VpnUtil.getEncapType(isVxlan);
    if (vpnRd == null) {
        String message = "Could not find Route-Distinguisher for VpnName " + vpnInstanceName;
        result.set(RpcResultBuilder.<AddStaticRouteOutput>failed().withError(RpcError.ErrorType.APPLICATION, message).build());
        return result;
    }
    Optional<InterVpnLinkDataComposite> optIVpnLink = interVpnLinkCache.getInterVpnLinkByEndpoint(nexthop);
    if (optIVpnLink.isPresent()) {
        try {
            InterVpnLinkUtil.handleStaticRoute(optIVpnLink.get(), vpnInstanceName, destination, nexthop, label.intValue(), dataBroker, fibManager, bgpManager);
        } catch (Exception e) {
            result.set(RpcResultBuilder.<AddStaticRouteOutput>failed().withError(ErrorType.APPLICATION, formatAndLog(LOG::warn, "Could not advertise route [vpn={}, prefix={}, label={}, nexthop={}] to BGP: {}", vpnRd, destination, label, nexthop, e.getMessage(), e)).build());
            return result;
        }
    } else {
        vpnManager.addExtraRoute(vpnInstanceName, destination, nexthop, vpnRd, null, /* routerId */
        vpnOpEntry.getL3vni(), RouteOrigin.STATIC, null, /* intfName */
        null, /*Adjacency*/
        encapType, null);
    }
    AddStaticRouteOutput labelOutput = new AddStaticRouteOutputBuilder().setLabel(label).build();
    result.set(RpcResultBuilder.success(labelOutput).build());
    return result;
}
Also used : RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) RpcError(org.opendaylight.yangtools.yang.common.RpcError) AddStaticRouteOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.AddStaticRouteOutput) 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) AddStaticRouteOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.AddStaticRouteOutputBuilder) InterVpnLinkDataComposite(org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite)

Example 18 with InterVpnLinkDataComposite

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

the class InterVpnLinkTestCatalog method populateIvpnLinks.

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

Example 19 with InterVpnLinkDataComposite

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

the class InterVpnLinkNodeListener method remove.

@Override
protected void remove(InstanceIdentifier<Node> identifier, Node del) {
    LOG.trace("Node {} has been deleted", identifier.firstKeyOf(Node.class).toString());
    NodeId nodeId = del.getNodeId();
    String[] node = nodeId.getValue().split(":");
    if (node.length < 2) {
        LOG.warn("Unexpected nodeId {}", nodeId.getValue());
        return;
    }
    BigInteger dpId = new BigInteger(node[1]);
    List<InterVpnLinkDataComposite> allInterVpnLinks = interVpnLinkCache.getAllInterVpnLinks();
    allInterVpnLinks.stream().filter(// Only those affected by DPN going down
    ivl -> ivl.stepsOnDpn(dpId)).forEach(// Move them somewhere else
    this::reinstallInterVpnLink);
}
Also used : InterVpnLinkCleanedCheckerTask(org.opendaylight.netvirt.vpnmanager.intervpnlink.tasks.InterVpnLinkCleanedCheckerTask) InterVpnLink(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.links.InterVpnLink) LoggerFactory(org.slf4j.LoggerFactory) InterVpnLinkRemoverTask(org.opendaylight.netvirt.vpnmanager.intervpnlink.tasks.InterVpnLinkRemoverTask) Singleton(javax.inject.Singleton) Inject(javax.inject.Inject) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) InterVpnLinkCache(org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkCache) InterVpnLinkDataComposite(org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite) BigInteger(java.math.BigInteger) Logger(org.slf4j.Logger) Uri(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) InterVpnLinkCreatorTask(org.opendaylight.netvirt.vpnmanager.intervpnlink.tasks.InterVpnLinkCreatorTask) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) JobCoordinator(org.opendaylight.infrautils.jobcoordinator.JobCoordinator) TopologyId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId) VpnFootprintService(org.opendaylight.netvirt.vpnmanager.VpnFootprintService) AsyncDataTreeChangeListenerBase(org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase) NetworkTopology(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) Topology(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology) List(java.util.List) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) IMdsalApiManager(org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager) PostConstruct(javax.annotation.PostConstruct) TopologyKey(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) BigInteger(java.math.BigInteger) InterVpnLinkDataComposite(org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite)

Example 20 with InterVpnLinkDataComposite

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

the class FibManagerImpl method removeInterVPNLinkRouteFlows.

@Override
public void removeInterVPNLinkRouteFlows(final String interVpnLinkName, final boolean isVpnFirstEndPoint, final VrfEntry vrfEntry) {
    Optional<InterVpnLinkDataComposite> optInterVpnLink = interVpnLinkCache.getInterVpnLinkByName(interVpnLinkName);
    if (!optInterVpnLink.isPresent()) {
        LOG.warn("Could not find InterVpnLink with name {}. InterVpnLink route flows wont be removed", interVpnLinkName);
        return;
    }
    InterVpnLinkDataComposite interVpnLink = optInterVpnLink.get();
    String vpnName = isVpnFirstEndPoint ? interVpnLink.getFirstEndpointVpnUuid().get() : interVpnLink.getSecondEndpointVpnUuid().get();
    vrfEntryListener.removeInterVPNLinkRouteFlows(interVpnLink, vpnName, vrfEntry);
}
Also used : 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