Search in sources :

Example 1 with DataBroker

use of org.opendaylight.mdsal.binding.api.DataBroker in project netvirt by opendaylight.

the class BaseVrfEntryHandler method resolveAdjacency.

@NonNull
protected List<AdjacencyResult> resolveAdjacency(final Uint64 remoteDpnId, final Uint32 vpnId, final VrfEntry vrfEntry, String rd) {
    List<RoutePaths> routePaths = new ArrayList<RoutePaths>(vrfEntry.nonnullRoutePaths().values());
    FibHelper.sortIpAddress(routePaths);
    List<AdjacencyResult> adjacencyList = new ArrayList<>();
    List<String> prefixIpList;
    LOG.trace("resolveAdjacency called with remotedDpnId {}, vpnId{}, VrfEntry {}", remoteDpnId, vpnId, vrfEntry);
    final Class<? extends TunnelTypeBase> tunnelType;
    try {
        if (RouteOrigin.value(vrfEntry.getOrigin()) != RouteOrigin.BGP) {
            tunnelType = TunnelTypeVxlan.class;
            List<String> usedRds = VpnExtraRouteHelper.getUsedRds(dataBroker, vpnId, vrfEntry.getDestPrefix());
            List<Routes> vpnExtraRoutes = VpnExtraRouteHelper.getAllVpnExtraRoutes(dataBroker, fibUtil.getVpnNameFromId(vpnId), usedRds, vrfEntry.getDestPrefix());
            if (vpnExtraRoutes.isEmpty()) {
                Prefixes prefixInfo = fibUtil.getPrefixToInterface(vpnId, vrfEntry.getDestPrefix());
                /* We don't want to provide an adjacencyList for
                     * (1) an extra-route-prefix or,
                     * (2) for a local route without prefix-to-interface.
                     * Allow only self-imported routes in such cases */
                if (prefixInfo == null && FibHelper.isControllerManagedNonSelfImportedRoute(RouteOrigin.value(vrfEntry.getOrigin()))) {
                    LOG.debug("The prefix {} in rd {} for vpn {} does not have a valid extra-route or" + " prefix-to-interface entry in the data-store", vrfEntry.getDestPrefix(), rd, vpnId);
                    return adjacencyList;
                }
                prefixIpList = Collections.singletonList(vrfEntry.getDestPrefix());
            } else {
                List<String> prefixIpListLocal = new ArrayList<>();
                vpnExtraRoutes.stream().filter(route -> route.getNexthopIpList() != null).forEach(route -> route.getNexthopIpList().forEach(extraRouteIp -> {
                    String ipPrefix;
                    if (isIpv4Address(extraRouteIp)) {
                        ipPrefix = extraRouteIp + NwConstants.IPV4PREFIX;
                    } else {
                        ipPrefix = extraRouteIp + NwConstants.IPV6PREFIX;
                    }
                    prefixIpListLocal.add(ipPrefix);
                }));
                prefixIpList = prefixIpListLocal;
            }
        } else {
            prefixIpList = Collections.singletonList(vrfEntry.getDestPrefix());
            if (vrfEntry.getEncapType() == VrfEntry.EncapType.Mplsgre) {
                tunnelType = TunnelTypeMplsOverGre.class;
            } else {
                tunnelType = TunnelTypeVxlan.class;
            }
        }
        for (String prefixIp : prefixIpList) {
            if (routePaths == null || routePaths.isEmpty()) {
                LOG.trace("Processing Destination IP {} without NextHop IP", prefixIp);
                AdjacencyResult adjacencyResult = nextHopManager.getRemoteNextHopPointer(remoteDpnId, vpnId, prefixIp, null, tunnelType);
                addAdjacencyResultToList(adjacencyList, adjacencyResult);
                continue;
            }
            adjacencyList.addAll(routePaths.stream().map(routePath -> {
                LOG.debug("NextHop IP for destination {} is {}", prefixIp, routePath.getNexthopAddress());
                return nextHopManager.getRemoteNextHopPointer(remoteDpnId, vpnId, prefixIp, routePath.getNexthopAddress(), tunnelType);
            }).filter(adjacencyResult -> adjacencyResult != null && !adjacencyList.contains(adjacencyResult)).distinct().collect(toList()));
        }
    } catch (NullPointerException e) {
        // FIXME: NPEs should not be caught but rather their root cause should be eliminated
        LOG.trace("Failed to remove adjacency", e);
    }
    return adjacencyList;
}
Also used : SingleTransactionDataBroker(org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker) Table(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table) AdjacencyResult(org.opendaylight.netvirt.fibmanager.NexthopManager.AdjacencyResult) VpnToExtraroutes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.VpnToExtraroutes) LoggerFactory(org.slf4j.LoggerFactory) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow) ActionNxResubmit(org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit) SubTransactionImpl(org.opendaylight.genius.utils.batching.SubTransactionImpl) MatchEthernetDestination(org.opendaylight.genius.mdsalutil.matches.MatchEthernetDestination) InetAddress(java.net.InetAddress) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) ActionSetSourceIp(org.opendaylight.genius.mdsalutil.actions.ActionSetSourceIp) FlowKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey) Vpn(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.Vpn) Nullable(org.eclipse.jdt.annotation.Nullable) DataTreeEventCallbackRegistrar(org.opendaylight.genius.datastoreutils.listeners.DataTreeEventCallbackRegistrar) Duration(java.time.Duration) Datastore(org.opendaylight.mdsal.binding.util.Datastore) LoggingFutures(org.opendaylight.infrautils.utils.concurrent.LoggingFutures) MDSALUtil(org.opendaylight.genius.mdsalutil.MDSALUtil) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) UpgradeState(org.opendaylight.serviceutils.upgrade.UpgradeState) MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) VpnKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.VpnKey) TunnelTypeMplsOverGre(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeMplsOverGre) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions) Routes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.extra.routes.Routes) ActionNxLoadInPort(org.opendaylight.genius.mdsalutil.actions.ActionNxLoadInPort) Interface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) SubTransaction(org.opendaylight.genius.utils.batching.SubTransaction) List(java.util.List) ActionSetFieldEthernetDestination(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetDestination) MatchIpv6Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv6Destination) ManagedNewTransactionRunnerImpl(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl) TunnelTypeBase(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeBase) RoutePaths(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentrybase.RoutePaths) VpnInstanceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry) ActionMoveSourceDestinationIp(org.opendaylight.genius.mdsalutil.actions.ActionMoveSourceDestinationIp) Optional(java.util.Optional) NWUtil.isIpv4Address(org.opendaylight.genius.mdsalutil.NWUtil.isIpv4Address) NonNull(org.eclipse.jdt.annotation.NonNull) ActionSetFieldTunnelId(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldTunnelId) ActionSetIcmpType(org.opendaylight.genius.mdsalutil.actions.ActionSetIcmpType) Uint64(org.opendaylight.yangtools.yang.common.Uint64) ExtraRoutesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.ExtraRoutesKey) ManagedNewTransactionRunner(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) Singleton(javax.inject.Singleton) TransactionAdapter(org.opendaylight.mdsal.binding.util.TransactionAdapter) ActionSetFieldEthernetSource(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetSource) FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) MatchIcmpv4(org.opendaylight.genius.mdsalutil.matches.MatchIcmpv4) MatchIpv4Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination) TunnelTypeVxlan(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeVxlan) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) MatchEthernetType(org.opendaylight.genius.mdsalutil.matches.MatchEthernetType) NwConstants(org.opendaylight.genius.mdsalutil.NwConstants) VpnNexthop(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.VpnNexthop) ExtraRoutes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.ExtraRoutes) VpnExtraRouteHelper(org.opendaylight.netvirt.vpnmanager.api.VpnExtraRouteHelper) RoutesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.extra.routes.RoutesKey) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) MatchIpProtocol(org.opendaylight.genius.mdsalutil.matches.MatchIpProtocol) Uint32(org.opendaylight.yangtools.yang.common.Uint32) Logger(org.slf4j.Logger) VrfTablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTablesKey) RouteOrigin(org.opendaylight.netvirt.fibmanager.api.RouteOrigin) WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) TableKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey) Inet4Address(java.net.Inet4Address) UnknownHostException(java.net.UnknownHostException) ActionMoveSourceDestinationEth(org.opendaylight.genius.mdsalutil.actions.ActionMoveSourceDestinationEth) ExecutionException(java.util.concurrent.ExecutionException) Collectors.toList(java.util.stream.Collectors.toList) ChronoUnit(java.time.temporal.ChronoUnit) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) Prefixes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.vpn.ids.Prefixes) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) IMdsalApiManager(org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) Collections(java.util.Collections) MetaDataUtil(org.opendaylight.genius.mdsalutil.MetaDataUtil) FibHelper(org.opendaylight.netvirt.fibmanager.api.FibHelper) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) ArrayList(java.util.ArrayList) Routes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.extra.routes.Routes) ExtraRoutes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.ExtraRoutes) Prefixes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.vpn.ids.Prefixes) AdjacencyResult(org.opendaylight.netvirt.fibmanager.NexthopManager.AdjacencyResult) RoutePaths(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentrybase.RoutePaths) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 2 with DataBroker

use of org.opendaylight.mdsal.binding.api.DataBroker in project netvirt by opendaylight.

the class ElanServiceTestModule method configureBindings.

@Override
protected void configureBindings() {
    DataBroker dataBroker = DataBrokerTestModule.dataBroker();
    EntityOwnershipService mockedEntityOwnershipService = mock(EntityOwnershipService.class);
    EntityOwnershipState mockedEntityOwnershipState = EntityOwnershipState.IS_OWNER;
    Mockito.when(mockedEntityOwnershipService.getOwnershipState(Mockito.any())).thenReturn(Optional.of(mockedEntityOwnershipState));
    bind(EntityOwnershipService.class).toInstance(mockedEntityOwnershipService);
    bind(L2GatewayCache.class).to(L2GatewayCacheImpl.class);
    bind(HwvtepHACache.class).toInstance(mock(HwvtepHACache.class));
    bind(ServiceRecoveryRegistry.class).toInstance(mock(ServiceRecoveryRegistry.class));
    bind(INeutronVpnManager.class).toInstance(mock(NeutronvpnManagerImpl.class));
    IVpnManager ivpnManager = mock(VpnManagerTestImpl.class, CALLS_REAL_METHODS);
    MDSALManager mockedMdsalManager = new MDSALManager(dataBroker, mock(PacketProcessingService.class));
    bind(IMdsalApiManager.class).toInstance(mockedMdsalManager);
    // Bindings for external services to "real" implementations
    bind(LockManagerService.class).to(LockManagerServiceImpl.class);
    bind(ElanConfig.class).toInstance(new ElanConfigBuilder().setIntBridgeGenMac(true).setTempSmacLearnTimeout(Uint16.TEN).build());
    bind(MetricProvider.class).toInstance(new TestMetricProviderImpl());
    // Bindings of all listeners (which are not directly referenced in the code)
    // This is required to be explicit here, because these are referenced neither from src/main nor src/test
    // and we, intentionally, don't use "classpath scanning for auto-discovery"
    // so this list must kept, manually, in line with the rc/main/resources/org/opendaylight/blueprint/*.xml
    // and target/generated-resources/org/opendaylight/blueprint/autowire.xml
    // bind(ElanGroupListener.class);
    // TODO complete this list!!! after Gerrit which adds @Inject to all listeners
    // Bindings to test infra (fakes & mocks)
    TestInterfaceManager testInterfaceManager = TestInterfaceManager.newInstance(dataBroker);
    IITMProvider testItmProvider = TestItmProvider.newInstance();
    ItmRpcService itmRpcService = new ItmRpcTestImpl();
    bind(DataBroker.class).toInstance(dataBroker);
    bind(IdManagerService.class).toInstance(mock(IdHelper.class, CALLS_REAL_METHODS));
    bind(IInterfaceManager.class).toInstance(testInterfaceManager);
    bind(TestInterfaceManager.class).toInstance(testInterfaceManager);
    bind(IITMProvider.class).toInstance(testItmProvider);
    InterfaceMetaUtils interfaceMetaUtils = new InterfaceMetaUtils(dataBroker, mock(IdHelper.class, CALLS_REAL_METHODS), mock(BatchingUtils.class));
    InterfaceManagerCommonUtils interfaceManagerCommonUtils = new InterfaceManagerCommonUtils(dataBroker, mockedMdsalManager, mock(IdHelper.class, CALLS_REAL_METHODS), interfaceMetaUtils, mock(BatchingUtils.class));
    bind(OdlInterfaceRpcService.class).toInstance(ElanEgressActionsHelper.newInstance(interfaceManagerCommonUtils, testInterfaceManager));
    SingleTransactionDataBroker singleTransactionDataBroker = new SingleTransactionDataBroker(dataBroker);
    bind(SingleTransactionDataBroker.class).toInstance(singleTransactionDataBroker);
    IBgpManager ibgpManager = BgpManagerTestImpl.newInstance(singleTransactionDataBroker);
    bind(ItmRpcService.class).toInstance(itmRpcService);
    bind(ItmRpcTestImpl.class).toInstance((ItmRpcTestImpl) itmRpcService);
    bind(DataImportBootReady.class).toInstance(new DataImportBootReady() {
    });
    bind(DiagStatusService.class).toInstance(mock(DiagStatusService.class));
    bind(IVpnManager.class).toInstance(ivpnManager);
    bind(IBgpManager.class).toInstance(ibgpManager);
    bind(IElanService.class).to(ElanServiceProvider.class);
    MdsalUtils mdsalUtils = new MdsalUtils(dataBroker);
    bind(MdsalUtils.class).toInstance(mdsalUtils);
    bind(SouthboundUtils.class).toInstance(new SouthboundUtils(mdsalUtils));
    bind(IL2gwService.class).toInstance(mock(IL2gwService.class));
}
Also used : SouthboundUtils(org.opendaylight.ovsdb.utils.southbound.utils.SouthboundUtils) IL2gwService(org.opendaylight.netvirt.elanmanager.api.IL2gwService) IInterfaceManager(org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager) TestInterfaceManager(org.opendaylight.genius.testutils.TestInterfaceManager) L2GatewayCache(org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayCache) LockManagerService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockManagerService) IdHelper(org.opendaylight.netvirt.elanmanager.tests.utils.IdHelper) IElanService(org.opendaylight.netvirt.elanmanager.api.IElanService) SingleTransactionDataBroker(org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) NeutronvpnManagerImpl(org.opendaylight.netvirt.neutronvpn.NeutronvpnManagerImpl) PacketProcessingService(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService) InterfaceMetaUtils(org.opendaylight.genius.interfacemanager.commons.InterfaceMetaUtils) InterfaceManagerCommonUtils(org.opendaylight.genius.interfacemanager.commons.InterfaceManagerCommonUtils) MdsalUtils(org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils) OdlInterfaceRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService) IVpnManager(org.opendaylight.netvirt.vpnmanager.api.IVpnManager) BatchingUtils(org.opendaylight.genius.interfacemanager.renderer.ovs.utilities.BatchingUtils) EntityOwnershipState(org.opendaylight.mdsal.eos.common.api.EntityOwnershipState) TestMetricProviderImpl(org.opendaylight.infrautils.metrics.testimpl.TestMetricProviderImpl) IdManagerService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService) ElanConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.config.rev150710.ElanConfig) INeutronVpnManager(org.opendaylight.netvirt.neutronvpn.interfaces.INeutronVpnManager) SingleTransactionDataBroker(org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker) HwvtepHACache(org.opendaylight.genius.utils.hwvtep.HwvtepHACache) MDSALManager(org.opendaylight.genius.mdsalutil.internal.MDSALManager) ItmRpcTestImpl(org.opendaylight.genius.testutils.itm.ItmRpcTestImpl) IMdsalApiManager(org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager) IITMProvider(org.opendaylight.genius.itm.api.IITMProvider) ElanConfigBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.config.rev150710.ElanConfigBuilder) ItmRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService) MetricProvider(org.opendaylight.infrautils.metrics.MetricProvider) EntityOwnershipService(org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService) ServiceRecoveryRegistry(org.opendaylight.serviceutils.srm.ServiceRecoveryRegistry) DataImportBootReady(org.opendaylight.daexim.DataImportBootReady) DiagStatusService(org.opendaylight.infrautils.diagstatus.DiagStatusService) IBgpManager(org.opendaylight.netvirt.bgpmanager.api.IBgpManager)

Example 3 with DataBroker

use of org.opendaylight.mdsal.binding.api.DataBroker in project netvirt by opendaylight.

the class VpnInterfaceManager method addVpnInterfaceToVpn.

private void addVpnInterfaceToVpn(final InstanceIdentifier<VpnInterfaceOpDataEntry> vpnInterfaceOpIdentifier, final VpnInterface vpnInterface, @Nullable final List<Adjacency> oldAdjs, @Nullable final List<Adjacency> newAdjs, final InstanceIdentifier<VpnInterface> identifier, String vpnName) {
    final VpnInterfaceKey key = identifier.firstKeyOf(VpnInterface.class);
    final String interfaceName = key.getName();
    String primaryRd = vpnUtil.getPrimaryRd(vpnName);
    if (!vpnUtil.isVpnPendingDelete(primaryRd)) {
        Interface interfaceState = InterfaceUtils.getInterfaceStateFromOperDS(dataBroker, interfaceName);
        boolean isBgpVpnInternetVpn = vpnUtil.isBgpVpnInternet(vpnName);
        if (interfaceState != null) {
            try {
                final Uint64 dpnId = InterfaceUtils.getDpIdFromInterface(interfaceState);
                final int ifIndex = interfaceState.getIfIndex();
                jobCoordinator.enqueueJob("VPNINTERFACE-" + interfaceName, () -> {
                    // TODO Deal with sequencing — the config tx must only submitted if the oper tx goes in
                    // (the inventory tx goes in last)
                    List<ListenableFuture<?>> futures = new ArrayList<>();
                    // set of prefix 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
                    Set<String> prefixListForRefreshFib = new HashSet<>();
                    ListenableFuture<?> confFuture = txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, confTx -> futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, operTx -> futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, invTx -> {
                        LOG.info("addVpnInterface: VPN Interface add event - intfName {} vpnName {}" + " on dpn {}", vpnInterface.getName(), vpnName, vpnInterface.getDpnId());
                        processVpnInterfaceUp(dpnId, vpnInterface, primaryRd, ifIndex, false, confTx, operTx, invTx, interfaceState, vpnName, prefixListForRefreshFib);
                        if (oldAdjs != null && !oldAdjs.equals(newAdjs)) {
                            LOG.info("addVpnInterface: Adjacency changed upon VPNInterface {}" + " Update for swapping VPN {} case.", interfaceName, vpnName);
                            if (newAdjs != null) {
                                for (Adjacency adj : newAdjs) {
                                    if (oldAdjs.contains(adj)) {
                                        oldAdjs.remove(adj);
                                    } else {
                                        if (!isBgpVpnInternetVpn || vpnUtil.isAdjacencyEligibleToVpnInternet(adj)) {
                                            addNewAdjToVpnInterface(vpnInterfaceOpIdentifier, primaryRd, adj, dpnId, operTx, confTx, invTx, prefixListForRefreshFib);
                                        }
                                    }
                                }
                            }
                            for (Adjacency adj : oldAdjs) {
                                if (!isBgpVpnInternetVpn || vpnUtil.isAdjacencyEligibleToVpnInternet(adj)) {
                                    delAdjFromVpnInterface(vpnInterfaceOpIdentifier, adj, dpnId, operTx, confTx);
                                }
                            }
                        }
                    })))));
                    Futures.addCallback(confFuture, new VpnInterfaceCallBackHandler(primaryRd, prefixListForRefreshFib), MoreExecutors.directExecutor());
                    futures.add(confFuture);
                    Futures.addCallback(confFuture, new PostVpnInterfaceWorker(interfaceName, true, "Config"), MoreExecutors.directExecutor());
                    LOG.info("addVpnInterface: Addition of interface {} in VPN {} on dpn {}" + " processed successfully", interfaceName, vpnName, dpnId);
                    return futures;
                });
            } catch (NumberFormatException | IllegalStateException e) {
                LOG.error("addVpnInterface: Unable to retrieve dpnId from interface operational data store for " + "interface {}. Interface addition on vpn {} failed", interfaceName, vpnName, e);
                return;
            }
        } else if (Boolean.TRUE.equals(vpnInterface.isRouterInterface())) {
            jobCoordinator.enqueueJob("VPNINTERFACE-" + vpnInterface.getName(), () -> {
                ListenableFuture<?> future = txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, confTx -> {
                    createFibEntryForRouterInterface(primaryRd, vpnInterface, interfaceName, confTx, vpnName);
                    LOG.info("addVpnInterface: Router interface {} for vpn {} on dpn {}", interfaceName, vpnName, vpnInterface.getDpnId());
                });
                LoggingFutures.addErrorLogging(future, LOG, "Error creating FIB entry for interface {} on VPN {}", vpnInterface.getName(), vpnName);
                return Collections.singletonList(future);
            });
        } else {
            LOG.info("addVpnInterface: Handling addition of VPN interface {} on vpn {} skipped as interfaceState" + " is not available", interfaceName, vpnName);
        }
    } else {
        LOG.error("addVpnInterface: Handling addition of VPN interface {} on vpn {} dpn {} skipped" + " as vpn is pending delete", interfaceName, vpnName, vpnInterface.getDpnId());
    }
}
Also used : StateTunnelList(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.StateTunnelList) VpnInterfaceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry) CacheProvider(org.opendaylight.infrautils.caches.CacheProvider) Map(java.util.Map) IBgpManager(org.opendaylight.netvirt.bgpmanager.api.IBgpManager) VpnInterfaces(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.VpnInterfaces) LabelRouteInfoBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.label.route.map.LabelRouteInfoBuilder) Set(java.util.Set) DpnVpninterfacesList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.DpnVpninterfacesList) VpnHelper(org.opendaylight.netvirt.vpnmanager.api.VpnHelper) TypedWriteTransaction(org.opendaylight.mdsal.binding.util.TypedWriteTransaction) TypedReadWriteTransaction(org.opendaylight.mdsal.binding.util.TypedReadWriteTransaction) VpnInstanceOpData(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.VpnInstanceOpData) ArpResponderHandler(org.opendaylight.netvirt.vpnmanager.arp.responder.ArpResponderHandler) LabelRouteMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.LabelRouteMap) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.Adjacency) Uint64(org.opendaylight.yangtools.yang.common.Uint64) OdlInterfaceRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService) ManagedNewTransactionRunner(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner) VpnInterfaceOpDataEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntryKey) AdjacencyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.AdjacencyBuilder) ArrayList(java.util.ArrayList) InstanceIdentifierBuilder(org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder) LabelRouteInfoKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.label.route.map.LabelRouteInfoKey) RouterDpnList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.RouterDpnList) RouterDpnListKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.RouterDpnListKey) L3vpnInput(org.opendaylight.netvirt.vpnmanager.populator.input.L3vpnInput) RouterInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.RouterInterface) VrfTablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTablesKey) AbstractAsyncDataTreeChangeListener(org.opendaylight.serviceutils.tools.listener.AbstractAsyncDataTreeChangeListener) VpnPopulator(org.opendaylight.netvirt.vpnmanager.populator.intfc.VpnPopulator) VrfTables(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTables) VpnInstanceNames(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.vpn._interface.VpnInstanceNames) Adjacencies(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.Adjacencies) FutureCallback(com.google.common.util.concurrent.FutureCallback) ExecutionException(java.util.concurrent.ExecutionException) Futures(com.google.common.util.concurrent.Futures) Prefixes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.vpn.ids.Prefixes) VpnToDpnList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnList) VpnPortipToPort(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPort) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) IMdsalApiManager(org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) LearntVpnVipToPort(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort) RouterInterfaceBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.RouterInterfaceBuilder) FibHelper(org.opendaylight.netvirt.fibmanager.api.FibHelper) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) CONFIGURATION(org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION) SingleTransactionDataBroker(org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker) IFibManager(org.opendaylight.netvirt.fibmanager.api.IFibManager) NeutronRouterDpns(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.NeutronRouterDpns) VpnInterfaceOpDataEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntryBuilder) FibEntries(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.FibEntries) LoggerFactory(org.slf4j.LoggerFactory) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) PreDestroy(javax.annotation.PreDestroy) Nullable(org.eclipse.jdt.annotation.Nullable) LoggingFutures(org.opendaylight.infrautils.utils.concurrent.LoggingFutures) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) NetworkType(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NetworkAttributes.NetworkType) AdjacencyKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.AdjacencyKey) Subnets(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.Subnets) VrfTablesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTablesBuilder) L3vpnRegistry(org.opendaylight.netvirt.vpnmanager.populator.registry.L3vpnRegistry) Collections.emptyList(java.util.Collections.emptyList) Predicate(java.util.function.Predicate) LabelRouteInfo(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.label.route.map.LabelRouteInfo) Configuration(org.opendaylight.mdsal.binding.util.Datastore.Configuration) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Interface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) VrfEntryBase(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.VrfEntryBase) ManagedNewTransactionRunnerImpl(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl) VpnInstanceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry) Optional(java.util.Optional) SubnetRoute(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.SubnetRoute) AdjacenciesOp(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOp) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) VpnTarget(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpntargets.VpnTarget) AdjacencyType(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.Adjacency.AdjacencyType) VpnInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) NWUtil(org.opendaylight.genius.mdsalutil.NWUtil) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Executors(org.opendaylight.infrautils.utils.concurrent.Executors) VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) Singleton(javax.inject.Singleton) Iterators(com.google.common.collect.Iterators) HashSet(java.util.HashSet) Inject(javax.inject.Inject) InterfaceUtils(org.opendaylight.netvirt.vpnmanager.api.InterfaceUtils) Objects.requireNonNull(java.util.Objects.requireNonNull) NwConstants(org.opendaylight.genius.mdsalutil.NwConstants) InstanceIdDataObjectCache(org.opendaylight.genius.mdsalutil.cache.InstanceIdDataObjectCache) IInterfaceManager(org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager) Uint32(org.opendaylight.yangtools.yang.common.Uint32) Logger(org.slf4j.Logger) ReentrantLock(java.util.concurrent.locks.ReentrantLock) RouteOrigin(org.opendaylight.netvirt.fibmanager.api.RouteOrigin) JobCoordinator(org.opendaylight.infrautils.jobcoordinator.JobCoordinator) Operational(org.opendaylight.mdsal.binding.util.Datastore.Operational) IVpnManager(org.opendaylight.netvirt.vpnmanager.api.IVpnManager) VpnInterfaceKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterfaceKey) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) IdManagerService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService) Consumer(java.util.function.Consumer) DpnVpninterfacesListKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.DpnVpninterfacesListKey) Collections(java.util.Collections) OPERATIONAL(org.opendaylight.mdsal.binding.util.Datastore.OPERATIONAL) JvmGlobalLocks(org.opendaylight.genius.utils.JvmGlobalLocks) ArrayList(java.util.ArrayList) VpnInterfaceKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterfaceKey) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.Adjacency) RouterInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.RouterInterface) Interface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface) VpnInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface) Uint64(org.opendaylight.yangtools.yang.common.Uint64) HashSet(java.util.HashSet)

Example 4 with DataBroker

use of org.opendaylight.mdsal.binding.api.DataBroker in project netvirt by opendaylight.

the class TunnelInterfaceStateListener method update.

@Override
public void update(InstanceIdentifier<StateTunnelList> identifier, StateTunnelList original, StateTunnelList update) {
    LOG.trace("update: Tunnel updation---- {}", update);
    LOG.info("update: ITM Tunnel {} of type {} state event changed from :{} to :{}", update.getTunnelInterfaceName(), fibManager.getTransportTypeStr(update.getTransportType().toString()), original.getOperState(), update.getOperState());
    TunnelOperStatus tunOpStatus = update.getOperState();
    if (tunOpStatus != TunnelOperStatus.Down && tunOpStatus != TunnelOperStatus.Up) {
        LOG.info("update: Returning from unsupported tunnelOperStatus {} for tunnel interface {}", tunOpStatus, update.getTunnelInterfaceName());
        return;
    }
    boolean isTunnelUp = TunnelOperStatus.Up == update.getOperState();
    if (isGreTunnel(update)) {
        programDcGwLoadBalancingGroup(update, NwConstants.MOD_FLOW, isTunnelUp);
    }
    // Remove the corresponding nexthop from the routepath under extraroute in fibentries.
    Uint64 srcDpnId = Uint64.valueOf(update.getSrcInfo().getTepDeviceId()).intern();
    String srcTepIp = update.getSrcInfo().getTepIp().stringValue();
    List<VpnInstanceOpDataEntry> vpnInstanceOpData = vpnUtil.getAllVpnInstanceOpData();
    if (vpnInstanceOpData == null) {
        LOG.trace("update: No vpnInstanceOpdata present");
        return;
    }
    vpnInstanceOpData.stream().filter(opData -> opData.getVpnToDpnList() != null && opData.getVpnToDpnList().values().stream().anyMatch(vpnToDpn -> Objects.equals(vpnToDpn.getDpnId(), srcDpnId))).forEach(opData -> {
        List<DestPrefixes> prefixes = VpnExtraRouteHelper.getExtraRouteDestPrefixes(dataBroker, opData.getVpnId());
        prefixes.forEach(destPrefix -> {
            VrfEntry vrfEntry = vpnUtil.getVrfEntry(opData.getVrfId(), destPrefix.getDestPrefix());
            if (vrfEntry == null || vrfEntry.getRoutePaths() == null) {
                return;
            }
            List<RoutePaths> routePaths = new ArrayList<RoutePaths>(vrfEntry.getRoutePaths().values());
            routePaths.forEach(routePath -> {
                if (Objects.equals(routePath.getNexthopAddress(), srcTepIp)) {
                    String prefix = destPrefix.getDestPrefix();
                    String vpnPrefixKey = VpnUtil.getVpnNamePrefixKey(opData.getVpnInstanceName(), prefix);
                    // FIXME: separate out to somehow?
                    final ReentrantLock lock = JvmGlobalLocks.getLockForString(vpnPrefixKey);
                    lock.lock();
                    try {
                        fibManager.refreshVrfEntry(opData.getVrfId(), prefix);
                    } finally {
                        lock.unlock();
                    }
                }
            });
        });
    });
}
Also used : CONFIGURATION(org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION) SingleTransactionDataBroker(org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker) IFibManager(org.opendaylight.netvirt.fibmanager.api.IFibManager) LoggerFactory(org.slf4j.LoggerFactory) TepTypeInternal(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.TepTypeInternal) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) StateTunnelList(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.StateTunnelList) GetDpnInterfaceListInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetDpnInterfaceListInputBuilder) VpnInterfaceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry) Interface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface) PreDestroy(javax.annotation.PreDestroy) Future(java.util.concurrent.Future) ParentRefs(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefs) Map(java.util.Map) AdjacencyKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.AdjacencyKey) TunnelTypeMplsOverGre(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeMplsOverGre) TunnelsState(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.TunnelsState) Set(java.util.Set) Interfaces(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.get.dpn._interface.list.output.Interfaces) VpnHelper(org.opendaylight.netvirt.vpnmanager.api.VpnHelper) Objects(java.util.Objects) List(java.util.List) ManagedNewTransactionRunnerImpl(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl) TunnelOperStatus(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.TunnelOperStatus) RoutePaths(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentrybase.RoutePaths) VpnInstanceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry) Optional(java.util.Optional) AdjacenciesOp(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOp) PortOpData(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.PortOpData) VpnInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface) 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) 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) OdlInterfaceRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) Executors(org.opendaylight.infrautils.utils.concurrent.Executors) ManagedNewTransactionRunner(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) Singleton(javax.inject.Singleton) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) IfTunnel(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel) Strings(com.google.common.base.Strings) InterfaceUtils(org.opendaylight.netvirt.vpnmanager.api.InterfaceUtils) TunnelTypeVxlan(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeVxlan) NwConstants(org.opendaylight.genius.mdsalutil.NwConstants) VpnExtraRouteHelper(org.opendaylight.netvirt.vpnmanager.api.VpnExtraRouteHelper) TepTypeHwvtep(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.TepTypeHwvtep) DestPrefixes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.extraroute.rds.map.extraroute.rds.DestPrefixes) Uint32(org.opendaylight.yangtools.yang.common.Uint32) Logger(org.slf4j.Logger) ReentrantLock(java.util.concurrent.locks.ReentrantLock) TepTypeExternal(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.TepTypeExternal) AbstractAsyncDataTreeChangeListener(org.opendaylight.serviceutils.tools.listener.AbstractAsyncDataTreeChangeListener) JobCoordinator(org.opendaylight.infrautils.jobcoordinator.JobCoordinator) VpnInstanceNames(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.vpn._interface.VpnInstanceNames) ExecutionException(java.util.concurrent.ExecutionException) L2vlan(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev170119.L2vlan) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) GetDpnInterfaceListOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetDpnInterfaceListOutput) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) Collections(java.util.Collections) FibHelper(org.opendaylight.netvirt.fibmanager.api.FibHelper) OPERATIONAL(org.opendaylight.mdsal.binding.util.Datastore.OPERATIONAL) JvmGlobalLocks(org.opendaylight.genius.utils.JvmGlobalLocks) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) ReentrantLock(java.util.concurrent.locks.ReentrantLock) ArrayList(java.util.ArrayList) TunnelOperStatus(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.TunnelOperStatus) 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) DestPrefixes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.extraroute.rds.map.extraroute.rds.DestPrefixes) RoutePaths(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentrybase.RoutePaths) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Example 5 with DataBroker

use of org.opendaylight.mdsal.binding.api.DataBroker in project netvirt by opendaylight.

the class DpnInVpnChangeListener method onRemoveDpnEvent.

@Override
public void onRemoveDpnEvent(RemoveDpnEvent notification) {
    RemoveEventData eventData = notification.getRemoveEventData();
    final String rd = eventData.getRd();
    final String vpnName = eventData.getVpnName();
    BigInteger dpnId = eventData.getDpnId().toJava();
    LOG.trace("Remove Dpn Event notification received for rd {} VpnName {} DpnId {}", rd, vpnName, dpnId);
    // FIXME: separate out to somehow?
    final ReentrantLock lock = JvmGlobalLocks.getLockForString(vpnName);
    lock.lock();
    try {
        InstanceIdentifier<VpnInstanceOpDataEntry> id = VpnUtil.getVpnInstanceOpDataIdentifier(rd);
        Optional<VpnInstanceOpDataEntry> vpnOpValue = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
        if (vpnOpValue.isPresent()) {
            VpnInstanceOpDataEntry vpnInstOpData = vpnOpValue.get();
            Map<VpnToDpnListKey, VpnToDpnList> vpnToDpnMap = vpnInstOpData.nonnullVpnToDpnList();
            boolean flushDpnsOnVpn = true;
            for (VpnToDpnList dpn : vpnToDpnMap.values()) {
                if (dpn.getDpnState() == VpnToDpnList.DpnState.Active) {
                    flushDpnsOnVpn = false;
                    break;
                }
            }
            if (flushDpnsOnVpn) {
                try {
                    txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, tx -> deleteDpn(vpnToDpnMap.values(), rd, tx)).get();
                } catch (InterruptedException | ExecutionException e) {
                    LOG.error("Error removing dpnToVpnList for vpn {} ", vpnName);
                    throw new RuntimeException(e.getMessage(), e);
                }
            }
        }
    } catch (InterruptedException | ExecutionException e) {
        LOG.error("onRemoveDpnEvent: Failed to read data store for rd {} vpn {} dpn {}", rd, vpnName, dpnId);
    } finally {
        lock.unlock();
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) SingleTransactionDataBroker(org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker) AddInterfaceToDpnOnVpnEvent(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AddInterfaceToDpnOnVpnEvent) LoggerFactory(org.slf4j.LoggerFactory) ManagedNewTransactionRunner(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner) Singleton(javax.inject.Singleton) OdlL3vpnListener(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.OdlL3vpnListener) Inject(javax.inject.Inject) RemoveEventData(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.remove.dpn.event.RemoveEventData) Map(java.util.Map) BigInteger(java.math.BigInteger) VpnToDpnListKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnListKey) Logger(org.slf4j.Logger) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Collection(java.util.Collection) Operational(org.opendaylight.mdsal.binding.util.Datastore.Operational) AddDpnEvent(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AddDpnEvent) VpnHelper(org.opendaylight.netvirt.vpnmanager.api.VpnHelper) ExecutionException(java.util.concurrent.ExecutionException) VpnToDpnList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnList) ManagedNewTransactionRunnerImpl(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) VpnInstanceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry) TypedWriteTransaction(org.opendaylight.mdsal.binding.util.TypedWriteTransaction) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) Optional(java.util.Optional) RemoveDpnEvent(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.RemoveDpnEvent) OPERATIONAL(org.opendaylight.mdsal.binding.util.Datastore.OPERATIONAL) RemoveInterfaceFromDpnOnVpnEvent(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.RemoveInterfaceFromDpnOnVpnEvent) JvmGlobalLocks(org.opendaylight.genius.utils.JvmGlobalLocks) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) RemoveEventData(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.remove.dpn.event.RemoveEventData) VpnToDpnList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnList) VpnToDpnListKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnListKey) VpnInstanceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry) BigInteger(java.math.BigInteger) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

DataBroker (org.opendaylight.mdsal.binding.api.DataBroker)39 Logger (org.slf4j.Logger)38 LoggerFactory (org.slf4j.LoggerFactory)38 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)36 ManagedNewTransactionRunner (org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner)35 ManagedNewTransactionRunnerImpl (org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl)35 LogicalDatastoreType (org.opendaylight.mdsal.common.api.LogicalDatastoreType)35 Singleton (javax.inject.Singleton)33 ArrayList (java.util.ArrayList)32 Inject (javax.inject.Inject)32 List (java.util.List)31 Optional (java.util.Optional)30 ExecutionException (java.util.concurrent.ExecutionException)30 CONFIGURATION (org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION)29 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)29 Collections (java.util.Collections)28 SingleTransactionDataBroker (org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker)28 Uint32 (org.opendaylight.yangtools.yang.common.Uint32)27 NwConstants (org.opendaylight.genius.mdsalutil.NwConstants)25 Map (java.util.Map)24