Search in sources :

Example 1 with SnatIpMappingBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rpc.rev170209.snat.state.SnatIpMappingBuilder 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

ArrayList (java.util.ArrayList)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 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 RouterNat (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rpc.rev170209.nat.output.RouterNat)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