Search in sources :

Example 61 with Uint32

use of org.opendaylight.yangtools.yang.common.Uint32 in project netvirt by opendaylight.

the class NatRpcServiceImpl method getNatTranslationsOnVpn.

@Override
public ListenableFuture<RpcResult<GetNatTranslationsOnVpnOutput>> getNatTranslationsOnVpn(GetNatTranslationsOnVpnInput input) {
    RpcResultBuilder<GetNatTranslationsOnVpnOutput> rpcResultBuilder = null;
    List<Uuid> routerUuidList = NatUtil.getRouterUuIdsForVpn(dataBroker, input.getVpnUuid());
    if (routerUuidList.isEmpty()) {
        String errMsg = String.format("404 Not Found - Invalid external vpn {%s} provided", input.getVpnUuid().getValue());
        rpcResultBuilder = RpcResultBuilder.<GetNatTranslationsOnVpnOutput>failed().withError(RpcError.ErrorType.APPLICATION, errMsg);
        return rpcResultBuilder.buildFuture();
    }
    List<RouterNat> natRouterList = new ArrayList<>();
    for (Uuid routerUuid : routerUuidList) {
        Uint32 routerId = NatUtil.getVpnId(dataBroker, routerUuid.getValue());
        if (routerId == NatConstants.INVALID_ID) {
            LOG.warn("getNatTranslationsOnVpn : Invalid RouterID found {}", routerId);
            continue;
        }
        natRouterList.addAll(constructNatInformation(routerUuid, routerId));
    }
    GetNatTranslationsOnVpnOutputBuilder output = new GetNatTranslationsOnVpnOutputBuilder().setRouterNat(natRouterList);
    rpcResultBuilder = RpcResultBuilder.success();
    rpcResultBuilder.withResult(output.build());
    return Futures.immediateFuture(rpcResultBuilder.build());
}
Also used : GetNatTranslationsOnVpnOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rpc.rev170209.GetNatTranslationsOnVpnOutput) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) GetNatTranslationsOnVpnOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rpc.rev170209.GetNatTranslationsOnVpnOutputBuilder) RouterNat(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rpc.rev170209.nat.output.RouterNat) ArrayList(java.util.ArrayList) Uint32(org.opendaylight.yangtools.yang.common.Uint32)

Example 62 with Uint32

use of org.opendaylight.yangtools.yang.common.Uint32 in project netvirt by opendaylight.

the class NatRpcServiceImpl method getNatTranslationsOnRouter.

@Override
public ListenableFuture<RpcResult<GetNatTranslationsOnRouterOutput>> getNatTranslationsOnRouter(GetNatTranslationsOnRouterInput input) {
    RpcResultBuilder<GetNatTranslationsOnRouterOutput> rpcResultBuilder = null;
    Uint32 routerId = NatUtil.getVpnId(dataBroker, input.getRouterUuid().getValue());
    if (routerId == NatConstants.INVALID_ID) {
        String errMsg = String.format("404 Not Found - No Router found with UUID {%s}", input.getRouterUuid().getValue());
        rpcResultBuilder = RpcResultBuilder.<GetNatTranslationsOnRouterOutput>failed().withError(RpcError.ErrorType.APPLICATION, errMsg);
        return rpcResultBuilder.buildFuture();
    }
    List<RouterNat> routerNatList = constructNatInformation(input.getRouterUuid(), routerId);
    GetNatTranslationsOnRouterOutputBuilder output = new GetNatTranslationsOnRouterOutputBuilder().setRouterNat(routerNatList);
    rpcResultBuilder = RpcResultBuilder.success();
    rpcResultBuilder.withResult(output.build());
    return rpcResultBuilder.buildFuture();
}
Also used : GetNatTranslationsOnRouterOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rpc.rev170209.GetNatTranslationsOnRouterOutput) RouterNat(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rpc.rev170209.nat.output.RouterNat) GetNatTranslationsOnRouterOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rpc.rev170209.GetNatTranslationsOnRouterOutputBuilder) Uint32(org.opendaylight.yangtools.yang.common.Uint32)

Example 63 with Uint32

use of org.opendaylight.yangtools.yang.common.Uint32 in project netvirt by opendaylight.

the class NatTepChangeListener method hndlTepDelForSnatInEachRtr.

private void hndlTepDelForSnatInEachRtr(RoutersList router, Uint32 routerId, Uint64 dpnId, String srcTepIp, Boolean isFipExists, ProviderTypes extNwProvType, TypedReadWriteTransaction<Configuration> confTx) throws ExecutionException, InterruptedException {
    /*SNAT :
        1) Elect a new switch as the primary NAPT
        2) Advertise the new routes to BGP for the newly elected TEP IP as the DPN IP
        3) This will make sure old routes are withdrawn and new routes are advertised.
         */
    String routerName = router.getRouter();
    LOG.debug("hndlTepDelForSnatInEachRtr : SNAT -> Trying to clear routes to the External fixed IP associated " + "to the router {}", routerName);
    // Check if this is externalRouter else ignore
    InstanceIdentifier<Routers> extRoutersId = NatUtil.buildRouterIdentifier(routerName);
    Optional<Routers> routerData = Optional.empty();
    try {
        routerData = confTx.read(extRoutersId).get();
    } catch (InterruptedException | ExecutionException e) {
        LOG.error("Error retrieving routers {}", extRoutersId, e);
    }
    if (!routerData.isPresent()) {
        LOG.debug("hndlTepDelForSnatInEachRtr : SNAT->Ignoring TEP del for router {} since its not External Router", routerName);
        return;
    }
    // Check if the DPN having the router is the NAPT switch
    Uint64 naptId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
    if (naptId == null || naptId.equals(Uint64.ZERO) || !naptId.equals(dpnId)) {
        LOG.error("hndlTepDelForSnatInEachRtr : SNAT -> Ignoring TEP delete for the DPN {} since" + "srcTepIp : {} is NOT a NAPT switch", dpnId, srcTepIp);
        return;
    }
    if (natMode == NatMode.Conntrack) {
        Routers extRouter = routerData.get();
        natServiceManager.notify(confTx, extRouter, null, naptId, dpnId, SnatServiceManager.Action.CNT_ROUTER_DISBL);
        if (extRouter.isEnableSnat()) {
            natServiceManager.notify(confTx, extRouter, null, naptId, dpnId, SnatServiceManager.Action.SNAT_ROUTER_DISBL);
        }
    } else {
        Uuid networkId = routerData.get().getNetworkId();
        if (networkId == null) {
            LOG.error("hndlTepDelForSnatInEachRtr : SNAT -> Ignoring TEP delete for the DPN {} for router {}" + "as external network configuraton is missing", dpnId, routerName);
            return;
        }
        LOG.debug("hndlTepDelForSnatInEachRtr : SNAT->Router {} is associated with ext nw {}", routerId, networkId);
        Uuid bgpVpnUuid = NatUtil.getVpnForRouter(dataBroker, routerName);
        Uint32 bgpVpnId;
        if (bgpVpnUuid == null) {
            LOG.debug("hndlTepDelForSnatInEachRtr : SNAT->Internal VPN-ID {} associated to router {}", routerId, routerName);
            bgpVpnId = routerId;
        } else {
            bgpVpnId = NatUtil.getVpnId(dataBroker, bgpVpnUuid.getValue());
            if (bgpVpnId == NatConstants.INVALID_ID) {
                LOG.error("hndlTepDelForSnatInEachRtr :SNAT->Invalid Private BGP VPN ID returned for routerName {}", routerName);
                return;
            }
        }
        if (!isFipExists) {
            // Remove default entry in FIB to SNAT table
            LOG.debug("NAT Service : Installing default route in FIB on DPN {} for router {} with" + " vpn {}...", dpnId, routerName, bgpVpnId);
            defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, bgpVpnId, routerId, confTx);
        }
        if (routerData.get().isEnableSnat()) {
            LOG.info("hndlTepDelForSnatInEachRtr : SNAT enabled for router {}", routerId);
            Uint32 routerVpnId = routerId;
            if (bgpVpnId != NatConstants.INVALID_ID) {
                LOG.debug("hndlTepDelForSnatInEachRtr : SNAT -> Private BGP VPN ID (Internal BGP VPN ID) {} " + "associated to the router {}", bgpVpnId, routerName);
                routerVpnId = bgpVpnId;
            } else {
                LOG.debug("hndlTepDelForSnatInEachRtr : SNAT -> Internal L3 VPN ID (Router ID) {} " + "associated to the router {}", routerVpnId, routerName);
            }
            // Re-elect the other available switch as the NAPT switch and program the NAT flows.
            String externalVpnName = NatUtil.getAssociatedVPN(dataBroker, routerData.get().getNetworkId());
            NatUtil.removeSNATFromDPN(dataBroker, mdsalManager, idManager, naptSwitchHA, dpnId, routerData.get(), routerId, routerVpnId, externalVpnName, extNwProvType, confTx);
        } else {
            LOG.info("hndlTepDelForSnatInEachRtr : SNAT is not enabled for router {} to handle addDPN event {}", routerId, dpnId);
        }
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) ExecutionException(java.util.concurrent.ExecutionException) Uint32(org.opendaylight.yangtools.yang.common.Uint32) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Example 64 with Uint32

use of org.opendaylight.yangtools.yang.common.Uint32 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 65 with Uint32

use of org.opendaylight.yangtools.yang.common.Uint32 in project netvirt by opendaylight.

the class NatUtil method removeSnatEntriesForPort.

public static void removeSnatEntriesForPort(DataBroker dataBroker, NaptManager naptManager, IMdsalApiManager mdsalManager, NeutronvpnService neutronVpnService, String interfaceName, String routerName) {
    Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);
    if (routerId == NatConstants.INVALID_ID) {
        LOG.error("removeSnatEntriesForPort: routerId not found for routername {}", routerName);
        return;
    }
    Uint64 naptSwitch = getPrimaryNaptfromRouterName(dataBroker, routerName);
    if (naptSwitch == null || naptSwitch.equals(Uint64.ZERO)) {
        LOG.error("removeSnatEntriesForPort: NaptSwitch is not elected for router {}" + "with Id {}", routerName, routerId);
        return;
    }
    // getInternalIp for port
    List<String> fixedIps = getFixedIpsForPort(neutronVpnService, interfaceName);
    if (fixedIps == null) {
        LOG.error("removeSnatEntriesForPort: Internal Ips not found for InterfaceName {} in router {} with id {}", interfaceName, routerName, routerId);
        return;
    }
    List<ProtocolTypes> protocolTypesList = getPortocolList();
    for (String internalIp : fixedIps) {
        LOG.debug("removeSnatEntriesForPort: Internal Ip retrieved for interface {} is {} in router with Id {}", interfaceName, internalIp, routerId);
        for (ProtocolTypes protocol : protocolTypesList) {
            List<Uint16> portList = NatUtil.getInternalIpPortListInfo(dataBroker, routerId, internalIp, protocol);
            if (portList != null) {
                for (Uint16 portnum : portList) {
                    // build and remove the flow in outbound table
                    removeNatFlow(mdsalManager, naptSwitch, NwConstants.OUTBOUND_NAPT_TABLE, routerId, internalIp, portnum.toJava(), protocol.getName());
                    // build and remove the flow in inboundtable
                    removeNatFlow(mdsalManager, naptSwitch, NwConstants.INBOUND_NAPT_TABLE, routerId, internalIp, portnum.toJava(), protocol.getName());
                    // Get the external IP address and the port from the model
                    NAPTEntryEvent.Protocol proto = protocol.toString().equals(ProtocolTypes.TCP.toString()) ? NAPTEntryEvent.Protocol.TCP : NAPTEntryEvent.Protocol.UDP;
                    IpPortExternal ipPortExternal = NatUtil.getExternalIpPortMap(dataBroker, routerId, internalIp, String.valueOf(portnum.toJava()), proto);
                    if (ipPortExternal == null) {
                        LOG.error("removeSnatEntriesForPort: Mapping for internalIp {} " + "with port {} is not found in " + "router with Id {}", internalIp, portnum, routerId);
                        return;
                    }
                    String externalIpAddress = ipPortExternal.getIpAddress();
                    String internalIpPort = internalIp + ":" + portnum.toJava();
                    // delete the entry from IntExtIpPortMap DS
                    naptManager.removeFromIpPortMapDS(routerId, internalIpPort, proto);
                    naptManager.removePortFromPool(internalIpPort, externalIpAddress);
                }
            } else {
                LOG.debug("removeSnatEntriesForPort: No {} session for interface {} with internalIP {} " + "in router with id {}", protocol, interfaceName, internalIp, routerId);
            }
        }
        // delete the entry from SnatIntIpPortMap DS
        LOG.debug("removeSnatEntriesForPort: Removing InternalIp :{} of router {} from snatint-ip-port-map", internalIp, routerId);
        naptManager.removeFromSnatIpPortDS(routerId, internalIp);
    }
}
Also used : ProtocolTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProtocolTypes) Uint16(org.opendaylight.yangtools.yang.common.Uint16) IpPortExternal(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.intext.ip.protocol.type.ip.port.map.IpPortExternal) Uint32(org.opendaylight.yangtools.yang.common.Uint32) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Aggregations

Uint32 (org.opendaylight.yangtools.yang.common.Uint32)394 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)111 ArrayList (java.util.ArrayList)105 ExecutionException (java.util.concurrent.ExecutionException)79 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)68 List (java.util.List)60 Optional (java.util.Optional)52 DataBroker (org.opendaylight.mdsal.binding.api.DataBroker)51 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)51 Logger (org.slf4j.Logger)51 LoggerFactory (org.slf4j.LoggerFactory)51 ManagedNewTransactionRunner (org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner)49 Inject (javax.inject.Inject)48 Singleton (javax.inject.Singleton)48 Test (org.junit.Test)48 ManagedNewTransactionRunnerImpl (org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl)48 LogicalDatastoreType (org.opendaylight.mdsal.common.api.LogicalDatastoreType)46 Collections (java.util.Collections)44 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)43 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)38