Search in sources :

Example 91 with RouterId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.RouterId in project netvirt by opendaylight.

the class NatTepChangeListener method handleTepDelForAllRtrs.

@SuppressWarnings("checkstyle:IllegalCatch")
private void handleTepDelForAllRtrs(Uint64 srcDpnId, String srcTepIp) {
    LOG.trace("handleTepDelForAllRtrs : TEP DEL ----- on DPN-ID {} having SRC IP : {}", srcDpnId, srcTepIp);
    List<RoutersList> routersList = null;
    InstanceIdentifier<DpnRoutersList> dpnRoutersListId = NatUtil.getDpnRoutersId(srcDpnId);
    Optional<DpnRoutersList> optionalRouterDpnList = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, dpnRoutersListId);
    if (optionalRouterDpnList.isPresent()) {
        routersList = new ArrayList<RoutersList>(optionalRouterDpnList.get().nonnullRoutersList().values());
    } else {
        LOG.debug("NAT Service : RouterDpnList is empty for DPN {}. Hence ignoring TEP DEL event", srcDpnId);
        return;
    }
    if (routersList == null) {
        LOG.error("handleTepDelForAllRtrs : DPN {} does not have the Routers presence", srcDpnId);
        return;
    }
    for (RoutersList router : routersList) {
        String routerName = router.getRouter();
        LOG.debug("handleTepDelForAllRtrs :  TEP DEL : DNAT -> Withdrawing routes for router {} ", routerName);
        Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);
        if (routerId == NatConstants.INVALID_ID) {
            LOG.error("handleTepDelForAllRtrs :Invalid ROUTER-ID {} returned for routerName {}", routerId, routerName);
            return;
        }
        Uuid externalNetworkId = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
        ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, externalNetworkId);
        if (extNwProvType == null) {
            return;
        }
        boolean isFipExists = hndlTepDelForDnatInEachRtr(router, routerId, srcDpnId, extNwProvType);
        LOG.debug("handleTepDelForAllRtrs :  TEP DEL : SNAT -> Withdrawing and Advertising routes for router {} ", router.getRouter());
        coordinator.enqueueJob((NatConstants.NAT_DJC_PREFIX + router.getRouter()), () -> {
            List<ListenableFuture<Void>> futures = new ArrayList<>();
            txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, configTx -> {
                hndlTepDelForSnatInEachRtr(router, routerId, srcDpnId, srcTepIp, isFipExists, extNwProvType, configTx);
            });
            return futures;
        }, NatConstants.NAT_DJC_MAX_RETRIES);
    }
    return;
}
Also used : ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes) ArrayList(java.util.ArrayList) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) DpnRoutersList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.dpn.routers.DpnRoutersList) RoutersList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.dpn.routers.dpn.routers.list.RoutersList) DpnRoutersList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.dpn.routers.DpnRoutersList) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Uint32(org.opendaylight.yangtools.yang.common.Uint32)

Example 92 with RouterId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.RouterId in project netvirt by opendaylight.

the class SnatExternalRoutersListener method add.

@Override
@SuppressWarnings("checkstyle:IllegalCatch")
public void add(InstanceIdentifier<Routers> identifier, Routers routers) {
    if (natMode != NatMode.Conntrack) {
        return;
    }
    String routerName = routers.getRouterName();
    if (upgradeState.isUpgradeInProgress()) {
        LOG.warn("add event for ext-router {}, but upgrade is in progress.", routerName);
        return;
    }
    LOG.info("add : external router event for {}", routerName);
    Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);
    NatUtil.createRouterIdsConfigDS(dataBroker, routerId, routerName);
    Uuid bgpVpnUuid = NatUtil.getVpnForRouter(dataBroker, routerName);
    if (bgpVpnUuid != null) {
        // Router associated to BGPVPN, ignoring it.
        return;
    }
    // Allocate Primary NAPTSwitch for this router
    centralizedSwitchScheduler.scheduleCentralizedSwitch(routers);
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Uint32(org.opendaylight.yangtools.yang.common.Uint32)

Example 93 with RouterId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.RouterId in project netvirt by opendaylight.

the class SnatExternalRoutersListener method update.

@Override
public void update(InstanceIdentifier<Routers> identifier, Routers original, Routers update) {
    if (natMode != NatMode.Conntrack) {
        return;
    }
    String routerName = original.getRouterName();
    Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);
    if (routerId == NatConstants.INVALID_ID) {
        LOG.error("update : external router event - Invalid routerId for routerName {}", routerName);
        return;
    }
    LOG.info("update :called for router {} with originalSNATStatus {} and updatedSNATStatus {}", routerName, original.isEnableSnat(), update.isEnableSnat());
    if (!upgradeState.isUpgradeInProgress()) {
        centralizedSwitchScheduler.updateCentralizedSwitch(original, update);
    }
    if (!Objects.equals(original.getSubnetIds(), update.getSubnetIds()) || !Objects.equals(original.getExternalIps(), update.getExternalIps())) {
        LoggingFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, confTx -> natServiceManager.notify(confTx, update, original, null, null, SnatServiceManager.Action.SNAT_ROUTER_UPDATE)), LOG, "error handling external router update");
    }
}
Also used : CONFIGURATION(org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION) NatserviceConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.config.rev170206.NatserviceConfig) LoggerFactory(org.slf4j.LoggerFactory) Executors(org.opendaylight.infrautils.utils.concurrent.Executors) ManagedNewTransactionRunner(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner) Singleton(javax.inject.Singleton) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Inject(javax.inject.Inject) PreDestroy(javax.annotation.PreDestroy) LoggingFutures(org.opendaylight.infrautils.utils.concurrent.LoggingFutures) NatMode(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.config.rev170206.NatserviceConfig.NatMode) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) UpgradeState(org.opendaylight.serviceutils.upgrade.UpgradeState) Uint32(org.opendaylight.yangtools.yang.common.Uint32) Logger(org.slf4j.Logger) AbstractAsyncDataTreeChangeListener(org.opendaylight.serviceutils.tools.listener.AbstractAsyncDataTreeChangeListener) IdManagerService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService) Objects(java.util.Objects) CentralizedSwitchScheduler(org.opendaylight.netvirt.natservice.api.CentralizedSwitchScheduler) ManagedNewTransactionRunnerImpl(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) ExtRouters(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExtRouters) SnatServiceManager(org.opendaylight.netvirt.natservice.api.SnatServiceManager) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) Uint32(org.opendaylight.yangtools.yang.common.Uint32)

Example 94 with RouterId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.RouterId in project netvirt by opendaylight.

the class VxlanGreConntrackBasedSnatService method removeSnatSpecificEntriesForNaptSwitch.

@Override
protected void removeSnatSpecificEntriesForNaptSwitch(TypedReadWriteTransaction<Configuration> confTx, Routers routers, Uint64 dpnId) throws ExecutionException, InterruptedException {
    LOG.info("installSnatSpecificEntriesForNaptSwitch for router {}", routers.getRouterName());
    String routerName = routers.getRouterName();
    Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);
    /* Remove Outbound NAT entries */
    removeSnatMissEntryForPrimrySwch(confTx, dpnId, routerId);
    removeTerminatingServiceTblEntryForVxlanGre(confTx, dpnId, routerId);
    // Long extNetVpnId = NatUtil.getNetworkVpnIdFromRouterId(dataBroker, routerId);
    Uuid vpnUuid = NatUtil.getVpnIdfromNetworkId(dataBroker, routers.getNetworkId());
    if (vpnUuid == null) {
        LOG.error("installSnatSpecificEntriesForNaptSwitch: Unable to retrieve external vpn_id for " + "external network {} with routerId {}", routers.getNetworkId(), routerId);
        return;
    }
    Uint32 extNetVpnId = NatUtil.getVpnId(dataBroker, vpnUuid.getValue());
    LOG.info("installSnatSpecificEntriesForNaptSwitch: external network vpn_id {} for router {}", extNetVpnId, routers.getRouterName());
    Map<ExternalIpsKey, ExternalIps> keyExternalIpsMap = routers.nonnullExternalIps();
    removeOutboundTblTrackEntryForVxlanGre(confTx, dpnId, routerId);
    removeOutboundTblEntryForVxlanGre(confTx, dpnId, routerId, new ArrayList<ExternalIps>(keyExternalIpsMap.values()));
    removeNaptPfibFlowForVxlanGre(confTx, routers, dpnId, extNetVpnId);
    removeNaptPfibEntry(confTx, dpnId, routerId);
    // Install Inbound NAT entries
    removeInboundEntryForVxlanGre(confTx, dpnId, routerId, new ArrayList<ExternalIps>(keyExternalIpsMap.values()));
    if (keyExternalIpsMap.isEmpty()) {
        LOG.error("installSnatSpecificEntriesForNaptSwitch: No externalIP present for router {}", routerName);
        return;
    }
    // The logic now handle only one external IP per router, others if present will be ignored.
    String externalIp = NatUtil.validateAndAddNetworkMask(new ArrayList<ExternalIps>(keyExternalIpsMap.values()).get(0).getIpAddress());
    externalRouterListener.clearFibTsAndReverseTraffic(dpnId, routerId, routers.getNetworkId(), Collections.singletonList(externalIp), null, routers.getExtGwMacAddress(), confTx);
}
Also used : ExternalIpsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIpsKey) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Uint32(org.opendaylight.yangtools.yang.common.Uint32) ExternalIps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)

Example 95 with RouterId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.RouterId in project netvirt by opendaylight.

the class NatRpcServiceImpl method constructNatInformation.

private List<RouterNat> constructNatInformation(Uuid routerUuid, Uint32 routerId) {
    String neutronRouterName = NatUtil.getNeutronRouterNamebyUuid(dataBroker, routerUuid);
    RouterNatBuilder natRouterBuilder = new RouterNatBuilder();
    natRouterBuilder.setRouterUuid(routerUuid);
    natRouterBuilder.setRouterName(neutronRouterName);
    IpPortMapping ipPortMapping = NatUtil.getIportMapping(dataBroker, routerId);
    if (ipPortMapping == null) {
        LOG.warn("constructNatInformation : No SNAT IP Mapping found for router-uuid {}", routerUuid.getValue());
    } else {
        // Capturing SNAT information
        List<SnatIpMapping> snatIpMapping = new ArrayList<>();
        for (IntextIpProtocolType protocolType : ipPortMapping.nonnullIntextIpProtocolType().values()) {
            for (IpPortMap ipPortMap : protocolType.nonnullIpPortMap().values()) {
                String[] internalPortMap = ipPortMap.getIpPortInternal().split(NwConstants.MACADDR_SEP);
                SnatIpMappingBuilder natIpMappingBuilder = new SnatIpMappingBuilder().setInternalIp(internalPortMap[0]).setInternalPort(internalPortMap[1]).setExternalIp(ipPortMap.getIpPortExternal().getIpAddress()).setExternalPort(ipPortMap.getIpPortExternal().getPortNum().toString()).setProtocol(protocolType.getProtocol().getName());
                snatIpMapping.add(natIpMappingBuilder.build());
            }
        }
        natRouterBuilder.setSnatIpMapping(snatIpMapping);
    }
    // Capturing DNAT information
    List<DnatIpMapping> dnatIpMapping = new ArrayList<>();
    List<Ports> fipPorts = NatUtil.getFloatingIpPortsForRouter(dataBroker, routerUuid);
    if (fipPorts.isEmpty()) {
        LOG.warn("constructNatInformation : No DNAT IP Mapping found for router-uuid {}", routerUuid.getValue());
    } else {
        for (Ports fipPort : fipPorts) {
            for (InternalToExternalPortMap fipMap : fipPort.nonnullInternalToExternalPortMap().values()) {
                DnatIpMappingBuilder natIpMappingBuilder = new DnatIpMappingBuilder().setExternalIp(fipMap.getExternalIp()).setInternalIp(fipMap.getInternalIp());
                dnatIpMapping.add(natIpMappingBuilder.build());
            }
        }
        natRouterBuilder.setDnatIpMapping(dnatIpMapping);
    }
    List<RouterNat> natRouterList = new ArrayList<>();
    natRouterList.add(natRouterBuilder.build());
    return natRouterList;
}
Also used : SnatIpMappingBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rpc.rev170209.snat.state.SnatIpMappingBuilder) RouterNat(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rpc.rev170209.nat.output.RouterNat) ArrayList(java.util.ArrayList) Ports(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.Ports) IpPortMapping(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.IpPortMapping) SnatIpMapping(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rpc.rev170209.snat.state.SnatIpMapping) IpPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.intext.ip.protocol.type.IpPortMap) IntextIpProtocolType(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.IntextIpProtocolType) DnatIpMappingBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rpc.rev170209.dnat.configuration.DnatIpMappingBuilder) DnatIpMapping(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rpc.rev170209.dnat.configuration.DnatIpMapping) RouterNatBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rpc.rev170209.nat.output.RouterNatBuilder) InternalToExternalPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)152 ArrayList (java.util.ArrayList)78 Uint32 (org.opendaylight.yangtools.yang.common.Uint32)76 ExecutionException (java.util.concurrent.ExecutionException)63 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)44 ProviderTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)43 Routers (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers)34 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)34 BigInteger (java.math.BigInteger)33 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)33 ExternalIps (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)29 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)29 Logger (org.slf4j.Logger)27 LoggerFactory (org.slf4j.LoggerFactory)27 Inject (javax.inject.Inject)25 Singleton (javax.inject.Singleton)25 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)25 InternalToExternalPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap)24 List (java.util.List)23 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)23