Search in sources :

Example 1 with RouterNat

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rpc.rev170209.nat.output.RouterNat in project netvirt by opendaylight.

the class NatRpcServiceImpl method getNatTranslationsOnRouter.

@Override
public Future<RpcResult<GetNatTranslationsOnRouterOutput>> getNatTranslationsOnRouter(GetNatTranslationsOnRouterInput input) {
    RpcResultBuilder<GetNatTranslationsOnRouterOutput> rpcResultBuilder = null;
    long 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 Futures.immediateFuture(rpcResultBuilder.build());
    }
    List<RouterNat> routerNatList = constructNatInformation(input.getRouterUuid(), routerId);
    GetNatTranslationsOnRouterOutputBuilder output = new GetNatTranslationsOnRouterOutputBuilder().setRouterNat(routerNatList);
    rpcResultBuilder = RpcResultBuilder.success();
    rpcResultBuilder.withResult(output.build());
    return Futures.immediateFuture(rpcResultBuilder.build());
}
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)

Example 2 with RouterNat

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rpc.rev170209.nat.output.RouterNat in project netvirt by opendaylight.

the class NatRpcServiceImpl method getNatTranslationsOnVpn.

@Override
public Future<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 Futures.immediateFuture(rpcResultBuilder.build());
    }
    List<RouterNat> natRouterList = new ArrayList<RouterNat>();
    for (Uuid routerUuid : routerUuidList) {
        long 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)

Example 3 with RouterNat

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rpc.rev170209.nat.output.RouterNat in project netvirt by opendaylight.

the class NatRpcServiceImpl method constructNatInformation.

private List<RouterNat> constructNatInformation(Uuid routerUuid, long 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<SnatIpMapping>();
        for (IntextIpProtocolType protocolType : ipPortMapping.getIntextIpProtocolType()) {
            for (IpPortMap ipPortMap : protocolType.getIpPortMap()) {
                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<DnatIpMapping>();
    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) {
            List<InternalToExternalPortMap> ipMapping = fipPort.getInternalToExternalPortMap();
            for (InternalToExternalPortMap fipMap : ipMapping) {
                DnatIpMappingBuilder natIpMappingBuilder = new DnatIpMappingBuilder().setExternalIp(fipMap.getExternalIp()).setInternalIp(fipMap.getInternalIp());
                dnatIpMapping.add(natIpMappingBuilder.build());
            }
        }
        natRouterBuilder.setDnatIpMapping(dnatIpMapping);
    }
    List<RouterNat> natRouterList = new ArrayList<RouterNat>();
    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

RouterNat (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rpc.rev170209.nat.output.RouterNat)3 ArrayList (java.util.ArrayList)2 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)1 Ports (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.Ports)1 InternalToExternalPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap)1 IpPortMapping (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.IpPortMapping)1 IntextIpProtocolType (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.IntextIpProtocolType)1 IpPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.intext.ip.protocol.type.IpPortMap)1 GetNatTranslationsOnRouterOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rpc.rev170209.GetNatTranslationsOnRouterOutput)1 GetNatTranslationsOnRouterOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rpc.rev170209.GetNatTranslationsOnRouterOutputBuilder)1 GetNatTranslationsOnVpnOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rpc.rev170209.GetNatTranslationsOnVpnOutput)1 GetNatTranslationsOnVpnOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rpc.rev170209.GetNatTranslationsOnVpnOutputBuilder)1 DnatIpMapping (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rpc.rev170209.dnat.configuration.DnatIpMapping)1 DnatIpMappingBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rpc.rev170209.dnat.configuration.DnatIpMappingBuilder)1 RouterNatBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rpc.rev170209.nat.output.RouterNatBuilder)1 SnatIpMapping (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rpc.rev170209.snat.state.SnatIpMapping)1 SnatIpMappingBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rpc.rev170209.snat.state.SnatIpMappingBuilder)1