Search in sources :

Example 26 with VpnInstanceNames

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.vpn._interface.VpnInstanceNames in project netvirt by opendaylight.

the class VpnUtil method getVpnHandlingIpv4AssociatedWithInterface.

public Optional<List<String>> getVpnHandlingIpv4AssociatedWithInterface(String interfaceName) {
    InstanceIdentifier<VpnInterface> interfaceId = getVpnInterfaceIdentifier(interfaceName);
    Optional<List<String>> vpnOptional = Optional.empty();
    Optional<VpnInterface> optConfiguredVpnInterface = read(LogicalDatastoreType.CONFIGURATION, interfaceId);
    if (optConfiguredVpnInterface.isPresent()) {
        VpnInterface cfgVpnInterface = optConfiguredVpnInterface.get();
        java.util.Optional<List<VpnInstanceNames>> optVpnInstanceList = java.util.Optional.ofNullable(new ArrayList<>(cfgVpnInterface.nonnullVpnInstanceNames().values()));
        if (optVpnInstanceList.isPresent()) {
            List<String> vpnList = new ArrayList<>();
            for (VpnInstanceNames vpnInstance : optVpnInstanceList.get()) {
                vpnList.add(vpnInstance.getVpnName());
            }
            vpnOptional = Optional.of(vpnList);
        }
    }
    return vpnOptional;
}
Also used : VpnInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface) VpnInstanceNames(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.vpn._interface.VpnInstanceNames) ArrayList(java.util.ArrayList) ElanDpnInterfacesList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.dpn.interfaces.ElanDpnInterfacesList) ArrayList(java.util.ArrayList) VpnToDpnList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List)

Example 27 with VpnInstanceNames

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.vpn._interface.VpnInstanceNames in project netvirt by opendaylight.

the class InterfaceStateChangeListener method add.

@Override
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void add(InstanceIdentifier<Interface> identifier, Interface intrf) {
    try {
        if (L2vlan.class.equals(intrf.getType())) {
            LOG.info("VPN Interface add event - intfName {} from InterfaceStateChangeListener", intrf.getName());
            jobCoordinator.enqueueJob("VPNINTERFACE-" + intrf.getName(), () -> {
                List<ListenableFuture<?>> futures = new ArrayList<>(3);
                futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, writeInvTxn -> {
                    // map of prefix and vpn name used, as entry in prefix-to-interface datastore
                    // is prerequisite for refresh Fib to avoid race condition leading to missing remote next hop
                    // in bucket actions on bgp-vpn delete
                    Map<String, Set<String>> mapOfRdAndPrefixesForRefreshFib = new HashMap<>();
                    ListenableFuture<?> configFuture = txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, writeConfigTxn -> {
                        ListenableFuture<?> operFuture = txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, writeOperTxn -> {
                            final String interfaceName = intrf.getName();
                            LOG.info("Detected interface add event for interface {}", interfaceName);
                            final VpnInterface vpnIf = vpnUtil.getConfiguredVpnInterface(interfaceName);
                            if (vpnIf != null) {
                                for (VpnInstanceNames vpnInterfaceVpnInstance : vpnIf.nonnullVpnInstanceNames().values()) {
                                    String vpnName = vpnInterfaceVpnInstance.getVpnName();
                                    String primaryRd = vpnUtil.getPrimaryRd(vpnName);
                                    if (!vpnInterfaceManager.isVpnInstanceReady(vpnName)) {
                                        LOG.info("VPN Interface add event - intfName {} onto vpnName {} " + "running oper-driven, VpnInstance not ready, holding" + " on", vpnIf.getName(), vpnName);
                                    } else if (vpnUtil.isVpnPendingDelete(primaryRd)) {
                                        LOG.error("add: Ignoring addition of vpnInterface {}, as" + " vpnInstance {} with primaryRd {} is already marked for" + " deletion", interfaceName, vpnName, primaryRd);
                                    } else {
                                        Uint64 intfDpnId = Uint64.ZERO;
                                        try {
                                            intfDpnId = InterfaceUtils.getDpIdFromInterface(intrf);
                                        } catch (Exception e) {
                                            LOG.error("Unable to retrieve dpnId for interface {}. " + "Process vpn interface add failed", intrf.getName(), e);
                                            return;
                                        }
                                        LOG.error("InterfaceStateChangeListener- Processing ifState" + " {} add event with dpnId {}", intrf.getName(), intfDpnId);
                                        final Uint64 dpnId = intfDpnId;
                                        final int ifIndex = intrf.getIfIndex();
                                        LOG.info("VPN Interface add event - intfName {} onto vpnName {}" + " running oper-driven", vpnIf.getName(), vpnName);
                                        Set<String> prefixes = new HashSet<>();
                                        vpnInterfaceManager.processVpnInterfaceUp(dpnId, vpnIf, primaryRd, ifIndex, false, writeConfigTxn, writeOperTxn, writeInvTxn, intrf, vpnName, prefixes);
                                        mapOfRdAndPrefixesForRefreshFib.put(primaryRd, prefixes);
                                    }
                                }
                            }
                        });
                        futures.add(operFuture);
                        // Synchronous submit of operTxn
                        operFuture.get();
                    });
                    Futures.addCallback(configFuture, new VpnInterfaceCallBackHandler(mapOfRdAndPrefixesForRefreshFib), MoreExecutors.directExecutor());
                    futures.add(configFuture);
                    // TODO: Allow immediateFailedFuture from writeCfgTxn to cancel writeInvTxn as well.
                    Futures.addCallback(configFuture, new PostVpnInterfaceThreadWorker(intrf.getName(), true, "Operational"), MoreExecutors.directExecutor());
                }));
                return futures;
            });
        }
    } catch (Exception e) {
        LOG.error("Exception caught in Interface {} Operational State Up event", intrf.getName(), e);
    }
}
Also used : CONFIGURATION(org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION) IFibManager(org.opendaylight.netvirt.fibmanager.api.IFibManager) VpnInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) InterfacesState(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.Adjacency) Uint64(org.opendaylight.yangtools.yang.common.Uint64) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) LoggerFactory(org.slf4j.LoggerFactory) Executors(org.opendaylight.infrautils.utils.concurrent.Executors) ManagedNewTransactionRunner(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner) HashBasedTable(com.google.common.collect.HashBasedTable) HashMap(java.util.HashMap) Singleton(javax.inject.Singleton) VpnInterfaceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) PreDestroy(javax.annotation.PreDestroy) InterfaceUtils(org.opendaylight.netvirt.vpnmanager.api.InterfaceUtils) Map(java.util.Map) AdjacencyKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.AdjacencyKey) Logger(org.slf4j.Logger) OperStatus(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus) AbstractAsyncDataTreeChangeListener(org.opendaylight.serviceutils.tools.listener.AbstractAsyncDataTreeChangeListener) JobCoordinator(org.opendaylight.infrautils.jobcoordinator.JobCoordinator) Set(java.util.Set) VpnInstanceNames(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.vpn._interface.VpnInstanceNames) Interface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface) Adjacencies(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.Adjacencies) FutureCallback(com.google.common.util.concurrent.FutureCallback) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) ManagedNewTransactionRunnerImpl(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl) L2vlan(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev170119.L2vlan) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) Optional(java.util.Optional) LearntVpnVipToPort(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort) Table(com.google.common.collect.Table) OPERATIONAL(org.opendaylight.mdsal.binding.util.Datastore.OPERATIONAL) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) ArrayList(java.util.ArrayList) VpnInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface) VpnInstanceNames(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.vpn._interface.VpnInstanceNames) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) HashMap(java.util.HashMap) Map(java.util.Map) Uint64(org.opendaylight.yangtools.yang.common.Uint64) HashSet(java.util.HashSet)

Example 28 with VpnInstanceNames

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.vpn._interface.VpnInstanceNames in project netvirt by opendaylight.

the class SubnetRouteInterfaceStateChangeListener method update.

@Override
public void update(InstanceIdentifier<Interface> identifier, Interface original, Interface update) {
    String interfaceName = update.getName();
    if (L2vlan.class.equals(update.getType())) {
        LOG.trace("{} update: Operation Interface update event - Old: {}, New: {}", LOGGING_PREFIX, original, update);
        List<Uuid> subnetIdList = getSubnetId(update);
        if (subnetIdList.isEmpty()) {
            LOG.error("SubnetRouteInterfaceListener update: Port {} doesn't exist in configDS", update.getName());
            return;
        }
        for (Uuid subnetId : subnetIdList) {
            jobCoordinator.enqueueJob("SUBNETROUTE-" + subnetId, () -> {
                Uint64 dpnId = Uint64.ZERO;
                try {
                    dpnId = InterfaceUtils.getDpIdFromInterface(update);
                } catch (NullPointerException e) {
                    LOG.error("{} remove: Unable to retrieve dpnId for interface {} in subnet  {}. " + "Fetching from vpn interface itself", LOGGING_PREFIX, update.getName(), subnetId, e);
                }
                List<ListenableFuture<Void>> futures = new ArrayList<>();
                try {
                    InstanceIdentifier<VpnInterface> id = VpnUtil.getVpnInterfaceIdentifier(interfaceName);
                    Optional<VpnInterface> cfgVpnInterface = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
                    if (!cfgVpnInterface.isPresent()) {
                        return futures;
                    }
                    boolean interfaceChangeEligible = false;
                    for (VpnInstanceNames vpnInterfaceVpnInstance : cfgVpnInterface.get().nonnullVpnInstanceNames().values()) {
                        String vpnName = vpnInterfaceVpnInstance.getVpnName();
                        InstanceIdentifier<VpnInterfaceOpDataEntry> idOper = VpnUtil.getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
                        Optional<VpnInterfaceOpDataEntry> optVpnInterface = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, idOper);
                        if (optVpnInterface.isPresent()) {
                            Uint64 dpnIdLocal = dpnId;
                            if (Uint64.ZERO.equals(dpnIdLocal)) {
                                dpnIdLocal = optVpnInterface.get().getDpnId();
                            }
                            if (!Uint64.ZERO.equals(dpnIdLocal)) {
                                interfaceChangeEligible = true;
                                break;
                            }
                        }
                    }
                    if (interfaceChangeEligible) {
                        if (Interface.OperStatus.Up.equals(update.getOperStatus())) {
                            LOG.info("{} update: Received port UP event for interface {} in subnet {}", LOGGING_PREFIX, update.getName(), subnetId);
                            vpnSubnetRouteHandler.onInterfaceUp(dpnId, update.getName(), subnetId);
                        } else if (Interface.OperStatus.Down.equals(update.getOperStatus()) || Interface.OperStatus.Unknown.equals(update.getOperStatus())) {
                            /*
                                 * If the interface went down voluntarily (or) if the interface is not
                                 * reachable from control-path involuntarily, trigger subnetRoute election
                                 */
                            LOG.info("{} update: Received port {} event for interface {} in subnet {} ", LOGGING_PREFIX, Interface.OperStatus.Unknown.equals(update.getOperStatus()) ? "UNKNOWN" : "DOWN", update.getName(), subnetId);
                            vpnSubnetRouteHandler.onInterfaceDown(dpnId, update.getName(), subnetId);
                        }
                    }
                } catch (InterruptedException | ExecutionException e) {
                    LOG.error("update: Failed to read data store for interface {} dpn {}", interfaceName, dpnId);
                }
                return futures;
            });
        }
    }
    LOG.info("{} update: Processed Interface {} update event", LOGGING_PREFIX, update.getName());
}
Also used : ArrayList(java.util.ArrayList) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface) VpnInstanceNames(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.vpn._interface.VpnInstanceNames) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) VpnInterfaceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry) ExecutionException(java.util.concurrent.ExecutionException) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Example 29 with VpnInstanceNames

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.vpn._interface.VpnInstanceNames in project netvirt by opendaylight.

the class TunnelInterfaceStateListener method handleTunnelEventForDPN.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void handleTunnelEventForDPN(StateTunnelList stateTunnelList, TunnelAction tunnelAction) {
    final Uint64 srcDpnId = stateTunnelList.getSrcInfo() != null ? Uint64.valueOf(stateTunnelList.getSrcInfo().getTepDeviceId()).intern() : Uint64.ZERO;
    final String srcTepIp = stateTunnelList.getSrcInfo() != null ? stateTunnelList.getSrcInfo().getTepIp().stringValue() : "0";
    String destTepIp = stateTunnelList.getDstInfo() != null ? stateTunnelList.getDstInfo().getTepIp().stringValue() : "0";
    String rd;
    Uint64 remoteDpnId = null;
    boolean isTepDeletedOnDpn = false;
    LOG.info("handleTunnelEventForDPN: Handle tunnel event for srcDpn {} SrcTepIp {} DestTepIp {} ", srcDpnId, srcTepIp, destTepIp);
    int tunTypeVal = getTunnelType(stateTunnelList);
    LOG.trace("handleTunnelEventForDPN: tunTypeVal is {}", tunTypeVal);
    try {
        if (tunnelAction == TunnelAction.TUNNEL_EP_ADD) {
            LOG.info("handleTunnelEventForDPN: Tunnel ADD event received for Dpn {} VTEP Ip {} destTepIp {}", srcDpnId, srcTepIp, destTepIp);
            if (isTunnelInLogicalGroup(stateTunnelList)) {
                return;
            }
        } else if (tunnelAction == TunnelAction.TUNNEL_EP_DELETE) {
            LOG.info("handleTunnelEventForDPN: Tunnel DELETE event received for Dpn {} VTEP Ip {} DestTepIp {}", srcDpnId, srcTepIp, destTepIp);
            // When tunnel EP is deleted on a DPN , VPN gets two deletion event.
            // One for a DPN on which tunnel EP was deleted and another for other-end DPN.
            // Update the adj for the vpninterfaces for a DPN on which TEP is deleted.
            // Update the adj & VRF for the vpninterfaces for a DPN on which TEP is deleted.
            // Dont update the adj & VRF for vpninterfaces for a DPN on which TEP is not deleted.
            String endpointIpForDPN;
            try {
                endpointIpForDPN = InterfaceUtils.getEndpointIpAddressForDPN(dataBroker, srcDpnId);
            } catch (Exception e) {
                LOG.error("handleTunnelEventForDPN: Unable to resolve endpoint IP for srcDpn {}", srcDpnId);
                /* this dpn does not have the VTEP */
                endpointIpForDPN = null;
            }
            if (endpointIpForDPN == null) {
                LOG.info("handleTunnelEventForDPN: Tunnel TEP is deleted on Dpn {} VTEP Ip {} destTepIp {}", srcDpnId, srcTepIp, destTepIp);
                isTepDeletedOnDpn = true;
            }
        }
        // Get the list of VpnInterfaces from Intf Mgr for a SrcDPN on which TEP is added/deleted
        Future<RpcResult<GetDpnInterfaceListOutput>> result;
        List<Interfaces> srcDpninterfacelist = new ArrayList<>();
        List<Interfaces> destDpninterfacelist = new ArrayList<>();
        try {
            result = intfRpcService.getDpnInterfaceList(new GetDpnInterfaceListInputBuilder().setDpid(srcDpnId).build());
            RpcResult<GetDpnInterfaceListOutput> rpcResult = result.get();
            if (!rpcResult.isSuccessful()) {
                LOG.error("handleTunnelEventForDPN: RPC Call to GetDpnInterfaceList for srcDpnid {} srcTepIp {}" + " destTepIP {} returned with Errors {}", srcDpnId, srcTepIp, destTepIp, rpcResult.getErrors());
            } else {
                srcDpninterfacelist = rpcResult.getResult().nonnullInterfaces();
            }
        } catch (Exception e) {
            LOG.error("handleTunnelEventForDPN: Exception when querying for GetDpnInterfaceList for srcDpnid {}" + " srcTepIp {} destTepIp {}", srcDpnId, srcTepIp, destTepIp, e);
        }
        // Get the list of VpnInterfaces from Intf Mgr for a destDPN only for internal tunnel.
        if (tunTypeVal == VpnConstants.ITMTunnelLocType.Internal.getValue()) {
            remoteDpnId = Uint64.valueOf(stateTunnelList.getDstInfo() != null ? stateTunnelList.getDstInfo().getTepDeviceId() : "0").intern();
            try {
                result = intfRpcService.getDpnInterfaceList(new GetDpnInterfaceListInputBuilder().setDpid(remoteDpnId).build());
                RpcResult<GetDpnInterfaceListOutput> rpcResult = result.get();
                if (!rpcResult.isSuccessful()) {
                    LOG.error("handleTunnelEventForDPN: RPC Call to GetDpnInterfaceList for remoteDpnid {}" + " srcTepIP {} destTepIp {} returned with Errors {}", remoteDpnId, srcTepIp, destTepIp, rpcResult.getErrors());
                } else {
                    destDpninterfacelist = rpcResult.getResult().nonnullInterfaces();
                }
            } catch (Exception e) {
                LOG.error("handleTunnelEventForDPN: Exception when querying for GetDpnInterfaceList" + " for remoteDpnid {} srcTepIp {} destTepIp {}", remoteDpnId, srcTepIp, destTepIp, e);
            }
        }
        /*
             * Iterate over the list of VpnInterface for a SrcDpn on which TEP is added or deleted and read the adj.
             * Update the adjacencies with the updated nexthop.
             */
        List<Uuid> subnetList = new ArrayList<>();
        Map<Uint32, String> vpnIdRdMap = new HashMap<>();
        Set<String> listVpnName = new HashSet<>();
        for (Interfaces interfaces : srcDpninterfacelist) {
            if (!L2vlan.class.equals(interfaces.getInterfaceType())) {
                LOG.info("handleTunnelEventForDPN: Interface {} not of type L2Vlan", interfaces.getInterfaceName());
                continue;
            }
            String intfName = interfaces.getInterfaceName();
            VpnInterface vpnInterface = vpnUtil.getConfiguredVpnInterface(intfName);
            if (vpnInterface != null) {
                listVpnName.addAll(VpnHelper.getVpnInterfaceVpnInstanceNamesString(new ArrayList<VpnInstanceNames>(vpnInterface.nonnullVpnInstanceNames().values())));
                handleTunnelEventForDPNVpn(stateTunnelList, vpnIdRdMap, tunnelAction, isTepDeletedOnDpn, subnetList, TunnelEventProcessingMethod.POPULATESUBNETS, vpnInterface);
            }
        }
        /*
             * Iterate over the list of VpnInterface for destDPN and get the prefix .
             * Create remote rule for each of those prefix on srcDPN.
             */
        for (Interfaces interfaces : destDpninterfacelist) {
            if (!L2vlan.class.equals(interfaces.getInterfaceType())) {
                LOG.info("handleTunnelEventForDPN: Interface {} not of type L2Vlan", interfaces.getInterfaceName());
                continue;
            }
            String intfName = interfaces.getInterfaceName();
            VpnInterface vpnInterface = vpnUtil.getConfiguredVpnInterface(intfName);
            if (vpnInterface != null) {
                handleTunnelEventForDPNVpn(stateTunnelList, vpnIdRdMap, tunnelAction, isTepDeletedOnDpn, subnetList, TunnelEventProcessingMethod.MANAGEREMOTEROUTES, vpnInterface);
            }
        }
        // Iterate over the VpnId-to-Rd map.
        for (Map.Entry<Uint32, String> entry : vpnIdRdMap.entrySet()) {
            Uint32 vpnId = entry.getKey();
            rd = entry.getValue();
            if (tunnelAction == TunnelAction.TUNNEL_EP_ADD && tunTypeVal == VpnConstants.ITMTunnelLocType.External.getValue()) {
                fibManager.populateExternalRoutesOnDpn(srcDpnId, vpnId, rd, srcTepIp, destTepIp);
            } else if (tunnelAction == TunnelAction.TUNNEL_EP_DELETE && tunTypeVal == VpnConstants.ITMTunnelLocType.External.getValue()) {
                fibManager.cleanUpExternalRoutesOnDpn(srcDpnId, vpnId, rd, srcTepIp, destTepIp);
            }
        }
        if (listVpnName.size() >= 1) {
            if (tunnelAction == TunnelAction.TUNNEL_EP_ADD) {
                for (Uuid subnetId : subnetList) {
                    // Populate the List of subnets
                    vpnSubnetRouteHandler.updateSubnetRouteOnTunnelUpEvent(subnetId, srcDpnId);
                }
            }
            if (tunnelAction == TunnelAction.TUNNEL_EP_DELETE && isTepDeletedOnDpn) {
                for (Uuid subnetId : subnetList) {
                    // Populate the List of subnets
                    vpnSubnetRouteHandler.updateSubnetRouteOnTunnelDownEvent(subnetId, srcDpnId);
                }
            }
        }
        /*
             * Program the BGP routes of all the VPNs which have footprint on the source DPN.
             *
             * DC-GW LB groups are programmed in DJC Jobs, so DJC with same key is used here to make sure
             * groups are programmed first, then only BGP routes are programmed.
             */
        jobCoordinator.enqueueJob(FibHelper.getJobKeyForDcGwLoadBalancingGroup(srcDpnId), () -> {
            listVpnName.forEach(vpnName -> {
                Uint32 vpnId = vpnUtil.getVpnId(vpnName);
                final String vrfId = vpnIdRdMap.get(vpnId);
                if ((tunnelAction == TunnelAction.TUNNEL_EP_ADD) && (tunTypeVal == VpnConstants.ITMTunnelLocType.External.getValue())) {
                    fibManager.populateExternalRoutesOnDpn(srcDpnId, vpnId, vrfId, srcTepIp, destTepIp);
                }
            });
            return Collections.emptyList();
        }, RETRY_COUNT);
    } catch (RuntimeException e) {
        LOG.error("handleTunnelEventForDpn: Unable to handle the tunnel event for srcDpnId {} srcTepIp {}" + " remoteDpnId {} destTepIp {}", srcDpnId, srcTepIp, remoteDpnId, destTepIp, e);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GetDpnInterfaceListOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetDpnInterfaceListOutput) Uint32(org.opendaylight.yangtools.yang.common.Uint32) HashSet(java.util.HashSet) L2vlan(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev170119.L2vlan) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) ExecutionException(java.util.concurrent.ExecutionException) Interfaces(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.get.dpn._interface.list.output.Interfaces) GetDpnInterfaceListInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetDpnInterfaceListInputBuilder) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface) Map(java.util.Map) HashMap(java.util.HashMap) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Example 30 with VpnInstanceNames

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.vpn._interface.VpnInstanceNames in project netvirt by opendaylight.

the class TunnelInterfaceStateListener method handleTunnelEventForDPNVpn.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void handleTunnelEventForDPNVpn(StateTunnelList stateTunnelList, Map<Uint32, String> vpnIdRdMap, TunnelAction tunnelAction, boolean isTepDeletedOnDpn, List<Uuid> subnetList, TunnelEventProcessingMethod method, VpnInterface cfgVpnInterface) {
    String rd;
    String intfName = cfgVpnInterface.getName();
    final Uint64 srcDpnId = Uint64.valueOf(stateTunnelList.getSrcInfo() != null ? stateTunnelList.getSrcInfo().getTepDeviceId() : "0").intern();
    String destTepIp = stateTunnelList.getDstInfo() != null ? stateTunnelList.getDstInfo().getTepIp().stringValue() : null;
    String srcTepIp = stateTunnelList.getSrcInfo() != null ? stateTunnelList.getSrcInfo().getTepIp().stringValue() : null;
    int tunTypeVal = getTunnelType(stateTunnelList);
    Uint64 remoteDpnId = null;
    if (tunTypeVal == VpnConstants.ITMTunnelLocType.Internal.getValue()) {
        remoteDpnId = Uint64.valueOf(stateTunnelList.getDstInfo() != null ? stateTunnelList.getDstInfo().getTepDeviceId() : "0").intern();
    }
    if (cfgVpnInterface.getVpnInstanceNames() == null) {
        LOG.warn("handleTunnelEventForDpn: no vpnName found for interface {}", intfName);
        return;
    }
    try {
        for (VpnInstanceNames vpnInstance : cfgVpnInterface.getVpnInstanceNames().values()) {
            String vpnName = vpnInstance.getVpnName();
            if (method == TunnelEventProcessingMethod.POPULATESUBNETS) {
                Optional<VpnInterfaceOpDataEntry> opVpnInterface = vpnUtil.getVpnInterfaceOpDataEntry(intfName, vpnName);
                if (opVpnInterface.isPresent()) {
                    VpnInterfaceOpDataEntry vpnInterface = opVpnInterface.get();
                    jobCoordinator.enqueueJob("VPNINTERFACE-" + intfName, new UpdateVpnInterfaceOnTunnelEvent(tunnelAction, vpnInterface, stateTunnelList, isTepDeletedOnDpn));
                    // Populate the List of subnets
                    InstanceIdentifier<PortOpDataEntry> portOpIdentifier = InstanceIdentifier.builder(PortOpData.class).child(PortOpDataEntry.class, new PortOpDataEntryKey(intfName)).build();
                    Optional<PortOpDataEntry> optionalPortOp = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, portOpIdentifier);
                    if (optionalPortOp.isPresent()) {
                        List<Uuid> subnetIdList = optionalPortOp.get().getSubnetIds();
                        if (subnetIdList != null) {
                            for (Uuid subnetId : subnetIdList) {
                                if (!subnetList.contains(subnetId)) {
                                    subnetList.add(subnetId);
                                }
                            }
                        }
                    }
                    // Populate the map for VpnId-to-Rd
                    Uint32 vpnId = vpnUtil.getVpnId(vpnName);
                    rd = vpnUtil.getVpnRd(vpnName);
                    vpnIdRdMap.put(vpnId, rd);
                }
            } else if (method == TunnelEventProcessingMethod.MANAGEREMOTEROUTES) {
                Optional<VpnInterfaceOpDataEntry> opVpnInterface = vpnUtil.getVpnInterfaceOpDataEntry(intfName, vpnName);
                if (opVpnInterface.isPresent()) {
                    VpnInterfaceOpDataEntry vpnInterface = opVpnInterface.get();
                    AdjacenciesOp adjacencies = vpnInterface.augmentation(AdjacenciesOp.class);
                    Map<AdjacencyKey, Adjacency> adjacencyKeyAdjacencyMap = adjacencies != null && adjacencies.getAdjacency() != null ? adjacencies.getAdjacency() : Collections.<AdjacencyKey, Adjacency>emptyMap();
                    String prefix = null;
                    Uint32 vpnId = vpnUtil.getVpnId(vpnInterface.getVpnInstanceName());
                    if (vpnIdRdMap.containsKey(vpnId)) {
                        rd = vpnIdRdMap.get(vpnId);
                        LOG.info("handleTunnelEventForDPN: Remote DpnId {} VpnId {} rd {} VpnInterface {}" + " srcTepIp {} destTepIp {}", remoteDpnId, vpnId, rd, vpnInterface, srcTepIp, destTepIp);
                        for (Adjacency adj : adjacencyKeyAdjacencyMap.values()) {
                            prefix = adj.getIpAddress();
                            Uint32 label = adj.getLabel();
                            if (tunnelAction == TunnelAction.TUNNEL_EP_ADD && tunTypeVal == VpnConstants.ITMTunnelLocType.Internal.getValue()) {
                                fibManager.manageRemoteRouteOnDPN(true, srcDpnId, vpnId, rd, prefix, destTepIp, label);
                            }
                            if (tunnelAction == TunnelAction.TUNNEL_EP_DELETE && tunTypeVal == VpnConstants.ITMTunnelLocType.Internal.getValue()) {
                                fibManager.manageRemoteRouteOnDPN(false, srcDpnId, vpnId, rd, prefix, destTepIp, label);
                            }
                        }
                    }
                }
            }
        }
    } catch (InterruptedException | ExecutionException e) {
        LOG.error("handleTunnelEventForDPN: Failed to read data store for interface {} srcDpn {} srcTep {} " + "dstTep {}", intfName, srcDpnId, srcTepIp, destTepIp);
    }
}
Also used : Optional(java.util.Optional) PortOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.port.op.data.PortOpDataEntry) PortOpDataEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.port.op.data.PortOpDataEntryKey) AdjacencyKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.AdjacencyKey) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnInstanceNames(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.vpn._interface.VpnInstanceNames) AdjacenciesOp(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOp) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.Adjacency) VpnInterfaceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map) HashMap(java.util.HashMap) Uint32(org.opendaylight.yangtools.yang.common.Uint32) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Aggregations

ArrayList (java.util.ArrayList)25 VpnInstanceNames (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.vpn._interface.VpnInstanceNames)21 VpnInterface (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface)16 ExecutionException (java.util.concurrent.ExecutionException)14 List (java.util.List)13 VpnInterfaceOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry)13 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)13 VpnInstanceNames (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames)12 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)12 Adjacency (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.Adjacency)12 Optional (java.util.Optional)11 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)11 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)10 HashMap (java.util.HashMap)10 VpnInterface (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface)10 Adjacencies (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.Adjacencies)10 AdjacencyKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.AdjacencyKey)10 Map (java.util.Map)9 LearntVpnVipToPort (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort)9 Logger (org.slf4j.Logger)9