Search in sources :

Example 21 with InternalToExternalPortMap

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap in project netvirt by opendaylight.

the class VpnFloatingIpHandler method onRemoveFloatingIp.

@Override
public void onRemoveFloatingIp(final BigInteger dpnId, String routerUuid, long routerId, final Uuid networkId, InternalToExternalPortMap mapping, final long label, WriteTransaction removeFlowInvTx) {
    String externalIp = mapping.getExternalIp();
    Uuid floatingIpId = mapping.getExternalId();
    Uuid subnetId = NatUtil.getFloatingIpPortSubnetIdFromFloatingIpId(dataBroker, floatingIpId);
    Optional<Subnets> externalSubnet = NatUtil.getOptionalExternalSubnets(dataBroker, subnetId);
    final String vpnName = externalSubnet.isPresent() ? subnetId.getValue() : NatUtil.getAssociatedVPN(dataBroker, networkId);
    if (vpnName == null) {
        LOG.error("onRemoveFloatingIp: No VPN associated with ext nw {} to remove floating ip {} configuration " + "for router {}", networkId, externalIp, routerUuid);
        return;
    }
    // Remove floating mac from mymac table
    LOG.debug("onRemoveFloatingIp: Removing FloatingIp {}", externalIp);
    String floatingIpPortMacAddress = NatUtil.getFloatingIpPortMacFromFloatingIpId(dataBroker, floatingIpId);
    if (floatingIpPortMacAddress == null) {
        LOG.error("onRemoveFloatingIp: Unable to retrieve floatingIp port MAC address from floatingIpId {} for " + "router {} to remove floatingIp {}", floatingIpId, routerUuid, externalIp);
        return;
    }
    ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
        String networkVpnName = NatUtil.getAssociatedVPN(dataBroker, networkId);
        vpnManager.removeSubnetMacFromVpnInstance(networkVpnName, subnetId.getValue(), floatingIpPortMacAddress, dpnId, tx);
        vpnManager.removeArpResponderFlowsToExternalNetworkIps(routerUuid, Collections.singletonList(externalIp), floatingIpPortMacAddress, dpnId, networkId);
    }), LOG, "onRemoveFloatingIp");
    removeFromFloatingIpPortInfo(floatingIpId);
    ProviderTypes provType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerUuid, networkId);
    if (provType == null) {
        return;
    }
    if (provType == ProviderTypes.VXLAN) {
        Uuid floatingIpInterface = NatEvpnUtil.getFloatingIpInterfaceIdFromFloatingIpId(dataBroker, floatingIpId);
        evpnDnatFlowProgrammer.onRemoveFloatingIp(dpnId, vpnName, externalIp, floatingIpInterface.getValue(), floatingIpPortMacAddress, routerId, removeFlowInvTx);
        return;
    }
    cleanupFibEntries(dpnId, vpnName, externalIp, label, removeFlowInvTx, provType);
}
Also used : SingleTransactionDataBroker(org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker) IFibManager(org.opendaylight.netvirt.fibmanager.api.IFibManager) GenerateVpnLabelOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.GenerateVpnLabelOutput) InternalToExternalPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap) FibRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.FibRpcService) 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) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) SendArpRequestInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.SendArpRequestInput) ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes) Future(java.util.concurrent.Future) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) Optional(com.google.common.base.Optional) IBgpManager(org.opendaylight.netvirt.bgpmanager.api.IBgpManager) InterfaceAddress(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.interfaces.InterfaceAddress) BigInteger(java.math.BigInteger) MDSALUtil(org.opendaylight.genius.mdsalutil.MDSALUtil) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) VpnRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.VpnRpcService) PhysAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress) Subnets(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.Subnets) ManagedNewTransactionRunner(org.opendaylight.genius.infra.ManagedNewTransactionRunner) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions) RemoveFibEntryInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.RemoveFibEntryInput) WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) List(java.util.List) SendArpRequestInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.SendArpRequestInputBuilder) ActionSetFieldEthernetDestination(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetDestination) CreateFibEntryInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CreateFibEntryInput) InterfaceAddressBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.interfaces.InterfaceAddressBuilder) FloatingIpIdToPortMapping(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.port.info.FloatingIpIdToPortMapping) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) CreateFibEntryInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CreateFibEntryInputBuilder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) IElanService(org.opendaylight.netvirt.elanmanager.api.IElanService) Singleton(javax.inject.Singleton) JdkFutureAdapters(com.google.common.util.concurrent.JdkFutureAdapters) INeutronVpnManager(org.opendaylight.netvirt.neutronvpn.interfaces.INeutronVpnManager) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) RemoveVpnLabelInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.RemoveVpnLabelInputBuilder) MatchTunnelId(org.opendaylight.genius.mdsalutil.matches.MatchTunnelId) RemoveFibEntryInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.RemoveFibEntryInputBuilder) ManagedNewTransactionRunnerImpl(org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) MatchEthernetType(org.opendaylight.genius.mdsalutil.matches.MatchEthernetType) NwConstants(org.opendaylight.genius.mdsalutil.NwConstants) ActionPopMpls(org.opendaylight.genius.mdsalutil.actions.ActionPopMpls) Nonnull(javax.annotation.Nonnull) JdkFutures(org.opendaylight.infrautils.utils.concurrent.JdkFutures) Logger(org.slf4j.Logger) GenerateVpnLabelInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.GenerateVpnLabelInputBuilder) NatUtil.buildfloatingIpIdToPortMappingIdentifier(org.opendaylight.netvirt.natservice.internal.NatUtil.buildfloatingIpIdToPortMappingIdentifier) RouteOrigin(org.opendaylight.netvirt.fibmanager.api.RouteOrigin) IVpnManager(org.opendaylight.netvirt.vpnmanager.api.IVpnManager) RemoveVpnLabelInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.RemoveVpnLabelInput) IdManagerService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService) FutureCallback(com.google.common.util.concurrent.FutureCallback) ListenableFutures(org.opendaylight.infrautils.utils.concurrent.ListenableFutures) Futures(com.google.common.util.concurrent.Futures) GenerateVpnLabelInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.GenerateVpnLabelInput) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) IMdsalApiManager(org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager) MatchMplsLabel(org.opendaylight.genius.mdsalutil.matches.MatchMplsLabel) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) AsyncFunction(com.google.common.util.concurrent.AsyncFunction) InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) Collections(java.util.Collections) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction) IpAddressBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressBuilder) OdlArputilService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.OdlArputilService) Subnets(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.Subnets) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)

Example 22 with InternalToExternalPortMap

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap in project netvirt by opendaylight.

the class NatRpcServiceImpl method getNatTranslationsForNetworkAndIpaddress.

public Future<RpcResult<GetNatTranslationsForNetworkAndIpaddressOutput>> getNatTranslationsForNetworkAndIpaddress(GetNatTranslationsForNetworkAndIpaddressInput input) {
    String ipAddress = String.valueOf(input.getIpAddress().getValue());
    RpcResultBuilder<GetNatTranslationsForNetworkAndIpaddressOutput> rpcResultBuilder = null;
    GetNatTranslationsForNetworkAndIpaddressOutputBuilder output = null;
    List<Uuid> subnetUuidList = NatUtil.getSubnetIdsFromNetworkId(dataBroker, input.getNetworkUuid());
    if (subnetUuidList.isEmpty()) {
        String errMsg = String.format("404 Not Found - Invalid Network UUID {%s} provided as no Subnetworks found", input.getNetworkUuid().getValue());
        rpcResultBuilder = RpcResultBuilder.<GetNatTranslationsForNetworkAndIpaddressOutput>failed().withError(RpcError.ErrorType.APPLICATION, errMsg);
        return Futures.immediateFuture(rpcResultBuilder.build());
    }
    Subnet subNet = null;
    Boolean isIpInSubnet = Boolean.FALSE;
    outerloop: for (Uuid subnetUuid : subnetUuidList) {
        subNet = nvpnManager.getNeutronSubnet(subnetUuid);
        for (AllocationPools allocationPool : subNet.getAllocationPools()) {
            if (NatUtil.isIpInSubnet(ipAddress, String.valueOf(allocationPool.getStart().getValue()), String.valueOf(allocationPool.getEnd().getValue()))) {
                LOG.debug("getNatTranslationsForNetworkAndIpaddress : IP Adderess {} falls within the Subnet {}", ipAddress, subNet.getUuid().getValue());
                isIpInSubnet = Boolean.TRUE;
                break outerloop;
            }
        }
    }
    if (!isIpInSubnet) {
        String errMsg = String.format("404 Not Found - IP Adress {%s} does not fall within the Subnet IP range" + " of Network {%s}", ipAddress, input.getNetworkUuid().getValue());
        rpcResultBuilder = RpcResultBuilder.<GetNatTranslationsForNetworkAndIpaddressOutput>failed().withError(RpcError.ErrorType.APPLICATION, errMsg);
        return Futures.immediateFuture(rpcResultBuilder.build());
    }
    Subnetmap subnetMap = NatUtil.getSubnetMap(dataBroker, subNet.getUuid());
    long routerId = NatUtil.getVpnId(dataBroker, subnetMap.getRouterId().getValue());
    List<Ports> fipPorts = NatUtil.getFloatingIpPortsForRouter(dataBroker, subnetMap.getRouterId());
    if (fipPorts.isEmpty()) {
        LOG.warn("getNatTranslationsForNetworkAndIpaddress : No DNAT IP Mapping found for IP {}", ipAddress);
    } else {
        for (Ports fipPort : fipPorts) {
            List<InternalToExternalPortMap> ipMapping = fipPort.getInternalToExternalPortMap();
            for (InternalToExternalPortMap fipMap : ipMapping) {
                if (fipMap.getInternalIp().equals(ipAddress)) {
                    output = new GetNatTranslationsForNetworkAndIpaddressOutputBuilder().setExternalIp(fipMap.getExternalIp()).setNatTranslation("DNAT");
                    rpcResultBuilder = RpcResultBuilder.success();
                    rpcResultBuilder.withResult(output.build());
                    return Futures.immediateFuture(rpcResultBuilder.build());
                }
            }
        }
    }
    IpPortMapping ipPortMapping = NatUtil.getIportMapping(dataBroker, routerId);
    if (ipPortMapping == null) {
        LOG.warn("getNatTranslationsForNetworkAndIpaddress : No SNAT IP Mapping found for IP {}", ipAddress);
    } else {
        for (IntextIpProtocolType protocolType : ipPortMapping.getIntextIpProtocolType()) {
            for (IpPortMap ipPortMap : protocolType.getIpPortMap()) {
                String[] internalIpPort = ipPortMap.getIpPortInternal().split(NwConstants.MACADDR_SEP);
                if (ipAddress.equals(internalIpPort[0])) {
                    output = new GetNatTranslationsForNetworkAndIpaddressOutputBuilder().setExternalIp(ipPortMap.getIpPortExternal().getIpAddress()).setInternalIp(internalIpPort[0]).setNatTranslation("SNAT").setInternalPort(internalIpPort[1]).setExternalPort(ipPortMap.getIpPortExternal().getPortNum().toString()).setProtocol(protocolType.getProtocol().getName());
                    rpcResultBuilder = RpcResultBuilder.success();
                    rpcResultBuilder.withResult(output.build());
                    return Futures.immediateFuture(rpcResultBuilder.build());
                }
            }
        }
    }
    String errMsg = String.format("404 Not Found - No NAT Translation found for IP {%s}", ipAddress);
    rpcResultBuilder = RpcResultBuilder.<GetNatTranslationsForNetworkAndIpaddressOutput>failed().withError(RpcError.ErrorType.APPLICATION, errMsg);
    return Futures.immediateFuture(rpcResultBuilder.build());
}
Also used : GetNatTranslationsForNetworkAndIpaddressOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rpc.rev170209.GetNatTranslationsForNetworkAndIpaddressOutputBuilder) GetNatTranslationsForNetworkAndIpaddressOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rpc.rev170209.GetNatTranslationsForNetworkAndIpaddressOutput) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) Ports(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.Ports) AllocationPools(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnet.attributes.AllocationPools) IpPortMapping(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.IpPortMapping) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) 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) Subnet(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet) InternalToExternalPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap)

Aggregations

InternalToExternalPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap)15 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)14 RouterPorts (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts)13 Ports (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.Ports)11 ArrayList (java.util.ArrayList)10 BigInteger (java.math.BigInteger)9 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)7 ProviderTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)5 PortsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.PortsKey)5 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)4 ActionInfo (org.opendaylight.genius.mdsalutil.ActionInfo)4 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)4 InstructionApplyActions (org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)4 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)4 ActionNxResubmit (org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit)3 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)3 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)3 Optional (com.google.common.base.Optional)2 AsyncFunction (com.google.common.util.concurrent.AsyncFunction)2 FutureCallback (com.google.common.util.concurrent.FutureCallback)2