Search in sources :

Example 6 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 InterfaceStateEventListener method processInterfaceAdded.

private void processInterfaceAdded(String portName, String routerId, List<ListenableFuture<Void>> futures) {
    LOG.trace("processInterfaceAdded : Processing Interface Add Event for interface {}", portName);
    List<InternalToExternalPortMap> intExtPortMapList = getIntExtPortMapListForPortName(portName, routerId);
    if (intExtPortMapList == null || intExtPortMapList.isEmpty()) {
        LOG.debug("processInterfaceAdded : Ip Mapping list is empty/null for portname {}", portName);
        return;
    }
    InstanceIdentifier<RouterPorts> portIid = NatUtil.buildRouterPortsIdentifier(routerId);
    WriteTransaction installFlowInvTx = dataBroker.newWriteOnlyTransaction();
    for (InternalToExternalPortMap intExtPortMap : intExtPortMapList) {
        floatingIPListener.createNATFlowEntries(portName, intExtPortMap, portIid, routerId, installFlowInvTx);
    }
    // final submit call for installFlowInvTx
    futures.add(NatUtil.waitForTransactionToComplete(installFlowInvTx));
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) RouterPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts) InternalToExternalPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap)

Example 7 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 onAddFloatingIp.

@Override
public void onAddFloatingIp(final BigInteger dpnId, final String routerUuid, final long routerId, final Uuid networkId, final String interfaceName, final InternalToExternalPortMap mapping, WriteTransaction writeFlowInvTx) {
    String externalIp = mapping.getExternalIp();
    String internalIp = mapping.getInternalIp();
    Uuid floatingIpId = mapping.getExternalId();
    Uuid subnetId = NatUtil.getFloatingIpPortSubnetIdFromFloatingIpId(dataBroker, floatingIpId);
    String floatingIpPortMacAddress = NatUtil.getFloatingIpPortMacFromFloatingIpId(dataBroker, floatingIpId);
    if (floatingIpPortMacAddress == null) {
        LOG.error("onAddFloatingIp: Unable to retrieve floatingIp port MAC address from floatingIpId {} for " + "router {} to handle floatingIp {}", floatingIpId, routerUuid, externalIp);
        return;
    }
    Optional<Subnets> externalSubnet = NatUtil.getOptionalExternalSubnets(dataBroker, subnetId);
    final String vpnName = externalSubnet.isPresent() ? subnetId.getValue() : NatUtil.getAssociatedVPN(dataBroker, networkId);
    final String subnetVpnName = externalSubnet.isPresent() ? subnetId.getValue() : null;
    if (vpnName == null) {
        LOG.error("onAddFloatingIp: No VPN is associated with ext nw {} to handle add floating ip {} configuration " + "for router {}", networkId, externalIp, routerId);
        return;
    }
    String rd = NatUtil.getVpnRd(dataBroker, vpnName);
    if (rd == null) {
        LOG.error("onAddFloatingIp: Unable to retrieve external (internet) VPN RD from external VPN {} for " + "router {} to handle floatingIp {}", vpnName, routerId, externalIp);
        return;
    }
    ProviderTypes provType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerUuid, networkId);
    if (provType == null) {
        return;
    }
    /*
         *  For external network of type GRE, it is required to use "Internet VPN VNI" for intra-DC
         *  communication, but we still require "MPLS labels" to reach SNAT/DNAT VMs from external
         *  entities via MPLSOverGRE.
         *
         *  MPLSOverGRE based external networks, the ``opendaylight-vni-ranges`` pool will be
         *  used to carve out a unique VNI per Internet VPN (GRE-provider-type) to be used in the
         *  datapath for traffic forwarding for ``SNAT-to-DNAT`` and ``DNAT-to-DNAT`` cases within the
         *  DataCenter.
        */
    if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanService, provType)) {
        NatOverVxlanUtil.validateAndCreateVxlanVniPool(dataBroker, nvpnManager, idManager, NatConstants.ODL_VNI_POOL_NAME);
    }
    String nextHopIp = NatUtil.getEndpointIpAddressForDPN(dataBroker, dpnId);
    LOG.debug("onAddFloatingIp: Nexthop ip for prefix {} is {}", externalIp, nextHopIp);
    if (provType == ProviderTypes.VXLAN) {
        Uuid floatingIpInterface = NatEvpnUtil.getFloatingIpInterfaceIdFromFloatingIpId(dataBroker, floatingIpId);
        evpnDnatFlowProgrammer.onAddFloatingIp(dpnId, routerUuid, routerId, vpnName, internalIp, externalIp, networkId, interfaceName, floatingIpInterface.getValue(), floatingIpPortMacAddress, rd, nextHopIp, writeFlowInvTx);
        return;
    }
    /*
         *  MPLS label will be used to advertise prefixes and in "L3_LFIB_TABLE" (table 20) taking the packet
         *  to "INBOUND_NAPT_TABLE" (table 44) and "PDNAT_TABLE" (table 25).
         */
    GenerateVpnLabelInput labelInput = new GenerateVpnLabelInputBuilder().setVpnName(vpnName).setIpPrefix(externalIp).build();
    Future<RpcResult<GenerateVpnLabelOutput>> labelFuture = vpnService.generateVpnLabel(labelInput);
    ListenableFuture<RpcResult<Void>> future = Futures.transformAsync(JdkFutureAdapters.listenInPoolThread(labelFuture), (AsyncFunction<RpcResult<GenerateVpnLabelOutput>, RpcResult<Void>>) result -> {
        if (result.isSuccessful()) {
            GenerateVpnLabelOutput output = result.getResult();
            long label = output.getLabel();
            LOG.debug("onAddFloatingIp : Generated label {} for prefix {}", label, externalIp);
            FloatingIPListener.updateOperationalDS(dataBroker, routerUuid, interfaceName, label, internalIp, externalIp);
            long l3vni = 0;
            if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanService, provType)) {
                l3vni = NatOverVxlanUtil.getInternetVpnVni(idManager, vpnName, l3vni).longValue();
            }
            String fibExternalIp = NatUtil.validateAndAddNetworkMask(externalIp);
            NatUtil.addPrefixToBGP(dataBroker, bgpManager, fibManager, vpnName, rd, subnetId, fibExternalIp, nextHopIp, networkId.getValue(), floatingIpPortMacAddress, label, l3vni, RouteOrigin.STATIC, dpnId);
            List<Instruction> instructions = new ArrayList<>();
            List<ActionInfo> actionsInfos = new ArrayList<>();
            actionsInfos.add(new ActionNxResubmit(NwConstants.PDNAT_TABLE));
            instructions.add(new InstructionApplyActions(actionsInfos).buildInstruction(0));
            makeTunnelTableEntry(vpnName, dpnId, label, instructions, writeFlowInvTx, provType);
            List<ActionInfo> actionInfoFib = new ArrayList<>();
            List<Instruction> customInstructions = new ArrayList<>();
            actionInfoFib.add(new ActionSetFieldEthernetDestination(new MacAddress(floatingIpPortMacAddress)));
            customInstructions.add(new InstructionApplyActions(actionInfoFib).buildInstruction(0));
            customInstructions.add(new InstructionGotoTable(NwConstants.PDNAT_TABLE).buildInstruction(1));
            makeLFibTableEntry(dpnId, label, floatingIpPortMacAddress, NwConstants.PDNAT_TABLE, writeFlowInvTx);
            CreateFibEntryInput input = new CreateFibEntryInputBuilder().setVpnName(vpnName).setSourceDpid(dpnId).setInstruction(customInstructions).setIpAddress(fibExternalIp).setServiceId(label).setIpAddressSource(CreateFibEntryInput.IpAddressSource.FloatingIP).setInstruction(customInstructions).build();
            Future<RpcResult<Void>> future1 = fibService.createFibEntry(input);
            LOG.debug("onAddFloatingIp : Add Floating Ip {} , found associated to fixed port {}", externalIp, interfaceName);
            String networkVpnName = NatUtil.getAssociatedVPN(dataBroker, networkId);
            txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
                vpnManager.addSubnetMacIntoVpnInstance(networkVpnName, subnetVpnName, floatingIpPortMacAddress, dpnId, tx);
                vpnManager.addArpResponderFlowsToExternalNetworkIps(routerUuid, Collections.singleton(externalIp), floatingIpPortMacAddress, dpnId, networkId, tx);
            });
            return JdkFutureAdapters.listenInPoolThread(future1);
        } else {
            String errMsg = String.format("onAddFloatingIp : Could not retrieve the label for prefix %s " + "in VPN %s, %s", externalIp, vpnName, result.getErrors());
            LOG.error(errMsg);
            return Futures.immediateFailedFuture(new RuntimeException(errMsg));
        }
    }, MoreExecutors.directExecutor());
    Futures.addCallback(future, new FutureCallback<RpcResult<Void>>() {

        @Override
        public void onFailure(@Nonnull Throwable error) {
            LOG.error("onAddFloatingIp : Error in generate label or fib install process", error);
        }

        @Override
        public void onSuccess(@Nonnull RpcResult<Void> result) {
            if (result.isSuccessful()) {
                LOG.info("onAddFloatingIp : Successfully installed custom FIB routes for prefix {}", externalIp);
            } else {
                LOG.error("onAddFloatingIp : Error in rpc call to create custom Fib entries for prefix {} " + "in DPN {}, {}", externalIp, dpnId, result.getErrors());
            }
        }
    }, MoreExecutors.directExecutor());
    // Handle GARP transmission
    final IpAddress extrenalAddress = IpAddressBuilder.getDefaultInstance(externalIp);
    sendGarpOnInterface(dpnId, networkId, extrenalAddress, floatingIpPortMacAddress);
}
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) GenerateVpnLabelOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.GenerateVpnLabelOutput) ActionNxResubmit(org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit) List(java.util.List) ArrayList(java.util.ArrayList) GenerateVpnLabelInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.GenerateVpnLabelInputBuilder) GenerateVpnLabelInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.GenerateVpnLabelInput) InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes) CreateFibEntryInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CreateFibEntryInputBuilder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) CreateFibEntryInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CreateFibEntryInput) ActionSetFieldEthernetDestination(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetDestination) 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) Future(java.util.concurrent.Future) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)

Example 8 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 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)

Example 9 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 NeutronFloatingToFixedIpMappingChangeListener method clearFromFloatingIpInfo.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void clearFromFloatingIpInfo(String routerName, String fixedNeutronPortName, String fixedIpAddress) {
    boolean isLockAcquired = false;
    InstanceIdentifier.InstanceIdentifierBuilder<RouterPorts> routerPortsIdentifierBuilder = InstanceIdentifier.builder(FloatingIpInfo.class).child(RouterPorts.class, new RouterPortsKey(routerName));
    try {
        Optional<RouterPorts> optionalRouterPorts = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsIdentifierBuilder.build());
        if (optionalRouterPorts.isPresent()) {
            RouterPorts routerPorts = optionalRouterPorts.get();
            List<Ports> portsList = routerPorts.getPorts();
            List<InternalToExternalPortMap> intExtPortMap = new ArrayList<>();
            for (Ports ports : portsList) {
                if (ports.getPortName().equals(fixedNeutronPortName)) {
                    intExtPortMap = ports.getInternalToExternalPortMap();
                    break;
                }
            }
            if (intExtPortMap.size() == 1) {
                removeRouterPortsOrPortsNode(routerName, routerPortsIdentifierBuilder, portsList, fixedNeutronPortName, isLockAcquired);
            } else {
                for (InternalToExternalPortMap intToExtMap : intExtPortMap) {
                    if (intToExtMap.getInternalIp().equals(fixedIpAddress)) {
                        InstanceIdentifier<InternalToExternalPortMap> intExtPortMapIdentifier = routerPortsIdentifierBuilder.child(Ports.class, new PortsKey(fixedNeutronPortName)).child(InternalToExternalPortMap.class, new InternalToExternalPortMapKey(fixedIpAddress)).build();
                        try {
                            // remove particular internal-to-external-port-map
                            isLockAcquired = routerLock.tryLock(fixedIpAddress, LOCK_WAIT_TIME, TimeUnit.SECONDS);
                            LOG.debug("removing particular internal-to-external-port-map {}", intExtPortMap);
                            MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, intExtPortMapIdentifier);
                        } catch (Exception e) {
                            LOG.error("Failure in deletion of internal-to-external-port-map {}", intExtPortMap, e);
                        } finally {
                            if (isLockAcquired) {
                                routerLock.unlock(fixedIpAddress);
                            }
                        }
                    }
                }
            }
            LOG.debug("Deletion from FloatingIpInfo DS successful for fixedIp {} ", fixedIpAddress);
        } else {
            LOG.warn("routerPorts for router {} - fixedIp {} not found", routerName, fixedIpAddress);
        }
    } catch (RuntimeException | ReadFailedException e) {
        LOG.error("Failed to delete internal-to-external-port-map from FloatingIpInfo DS for fixed Ip {}", fixedIpAddress, e);
    }
}
Also used : InternalToExternalPortMapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMapKey) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) RouterPortsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPortsKey) RouterPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts) ArrayList(java.util.ArrayList) RouterPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts) Ports(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.Ports) FloatingIpInfo(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.FloatingIpInfo) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) InternalToExternalPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap) PortsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.PortsKey) RouterPortsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPortsKey)

Example 10 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 NeutronFloatingToFixedIpMappingChangeListener method addToFloatingIpInfo.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void addToFloatingIpInfo(String routerName, Uuid extNetworkId, String fixedNeutronPortName, String fixedIpAddress, String floatingIpAddress, Uuid floatingIpId) {
    RouterPortsBuilder routerPortsBuilder;
    boolean isLockAcquired = false;
    InstanceIdentifier<RouterPorts> routerPortsIdentifier = InstanceIdentifier.builder(FloatingIpInfo.class).child(RouterPorts.class, new RouterPortsKey(routerName)).build();
    try {
        Optional<RouterPorts> optionalRouterPorts = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsIdentifier);
        if (optionalRouterPorts.isPresent()) {
            LOG.debug("Updating routerPorts node {} in floatingIpInfo DS for floating IP {} on fixed " + "neutron port {} : ", routerName, floatingIpAddress, fixedNeutronPortName);
            routerPortsBuilder = new RouterPortsBuilder(optionalRouterPorts.get());
        } else {
            LOG.debug("Creating new routerPorts node {} in floatingIpInfo DS for floating IP {} on fixed " + "neutron port {} : ", routerName, floatingIpAddress, fixedNeutronPortName);
            routerPortsBuilder = new RouterPortsBuilder().setKey(new RouterPortsKey(routerName)).setRouterId(routerName);
        }
        if (extNetworkId != null) {
            routerPortsBuilder.setExternalNetworkId(extNetworkId);
        }
        if (fixedNeutronPortName != null) {
            List<Ports> portsList = routerPortsBuilder.getPorts();
            if (portsList == null) {
                portsList = new ArrayList<>();
            }
            PortsBuilder fixedNeutronPortBuilder = null;
            for (Ports neutronPort : portsList) {
                if (neutronPort.getPortName().equals(fixedNeutronPortName)) {
                    fixedNeutronPortBuilder = new PortsBuilder(neutronPort);
                    break;
                }
            }
            if (fixedNeutronPortBuilder == null) {
                fixedNeutronPortBuilder = new PortsBuilder().setKey(new PortsKey(fixedNeutronPortName)).setPortName(fixedNeutronPortName);
            }
            if (fixedIpAddress != null) {
                List<InternalToExternalPortMap> intExtPortMapList = fixedNeutronPortBuilder.getInternalToExternalPortMap();
                if (intExtPortMapList == null) {
                    intExtPortMapList = new ArrayList<>();
                }
                InternalToExternalPortMap intExtPortMap = new InternalToExternalPortMapBuilder().setKey(new InternalToExternalPortMapKey(fixedIpAddress)).setInternalIp(fixedIpAddress).setExternalIp(floatingIpAddress).setExternalId(floatingIpId).setLabel(null).build();
                intExtPortMapList.add(intExtPortMap);
                fixedNeutronPortBuilder.setInternalToExternalPortMap(intExtPortMapList);
            }
            portsList.add(fixedNeutronPortBuilder.build());
            routerPortsBuilder.setPorts(portsList);
        }
        isLockAcquired = routerLock.tryLock(routerName, LOCK_WAIT_TIME, TimeUnit.SECONDS);
        LOG.debug("Creating/Updating routerPorts node {} in floatingIpInfo DS for floating IP {} on fixed " + "neutron port {} : ", routerName, floatingIpAddress, fixedNeutronPortName);
        MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsIdentifier, routerPortsBuilder.build());
        LOG.debug("FloatingIpInfo DS updated for floating IP {} ", floatingIpAddress);
    } catch (ReadFailedException | RuntimeException e) {
        LOG.error("addToFloatingIpInfo failed for floating IP: {} ", floatingIpAddress, e);
    } finally {
        if (isLockAcquired) {
            routerLock.unlock(routerName);
        }
    }
}
Also used : InternalToExternalPortMapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMapKey) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) RouterPortsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPortsKey) RouterPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts) RouterPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts) Ports(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.Ports) InternalToExternalPortMapBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMapBuilder) RouterPortsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPortsBuilder) RouterPortsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPortsBuilder) PortsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.PortsBuilder) InternalToExternalPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap) PortsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.PortsKey) RouterPortsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPortsKey)

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