Search in sources :

Example 6 with CreateFibEntryOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CreateFibEntryOutput in project netvirt by opendaylight.

the class NatTunnelInterfaceStateListener method hndlTepAddForDnatInEachRtr.

private void hndlTepAddForDnatInEachRtr(RoutersList router, Uint32 routerId, String nextHopIp, Uint64 tepAddedDpnId, ProviderTypes extNwProvType, TypedWriteTransaction<Configuration> confTx) {
    // DNAT : Advertise the new route to the floating IP having the new TEP IP as the next hop IP
    final String routerName = router.getRouter();
    InstanceIdentifier<RouterPorts> routerPortsId = NatUtil.getRouterPortsId(routerName);
    Optional<RouterPorts> optRouterPorts;
    try {
        optRouterPorts = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsId);
    } catch (ExecutionException | InterruptedException e) {
        LOG.error("hndlTepAddForDnatInEachRtr: Exception while reading RouterPorts DS for the router {}", routerName, e);
        return;
    }
    if (!optRouterPorts.isPresent()) {
        LOG.debug("hndlTepAddForDnatInEachRtr : DNAT -> Could not read Router Ports data object with id: {} " + "from DNAT FloatinIpInfo", routerName);
        return;
    }
    RouterPorts routerPorts = optRouterPorts.get();
    Uuid extNwId = routerPorts.getExternalNetworkId();
    final String vpnName = NatUtil.getAssociatedVPN(dataBroker, extNwId);
    if (vpnName == null) {
        LOG.info("hndlTepAddForDnatInEachRtr : DNAT -> No External VPN associated with ext nw {} for router {}", extNwId, routerName);
        return;
    }
    String rd = NatUtil.getVpnRd(dataBroker, vpnName);
    if (extNwProvType == null) {
        return;
    }
    String gwMacAddress = null;
    Uint32 l3Vni = Uint32.ZERO;
    if (extNwProvType == ProviderTypes.VXLAN) {
        // Get the External Gateway MAC Address which is Router gateway MAC address for SNAT
        gwMacAddress = NatUtil.getExtGwMacAddFromRouterName(dataBroker, routerName);
        if (gwMacAddress != null) {
            LOG.debug("hndlTepAddForDnatInEachRtr : External GwMAC address {} found for External Router ID {}", gwMacAddress, routerId);
        } else {
            LOG.error("hndlTepAddForDnatInEachRtr : No External GwMAC address found for External Router ID {}", routerId);
            return;
        }
        // get l3Vni value for external VPN
        l3Vni = NatEvpnUtil.getL3Vni(dataBroker, rd);
        if (l3Vni == NatConstants.DEFAULT_L3VNI_VALUE) {
            LOG.debug("hndlTepAddForDnatInEachRtr : L3VNI value is not configured in Internet VPN {} and RD {} " + "Carve-out L3VNI value from OpenDaylight VXLAN VNI Pool and continue to installing " + "NAT flows", vpnName, rd);
            l3Vni = natOverVxlanUtil.getInternetVpnVni(vpnName, routerId);
        }
    }
    for (Ports port : routerPorts.nonnullPorts().values()) {
        // Get the DPN on which this interface resides
        final String interfaceName = port.getPortName();
        final Uint64 fipCfgdDpnId = NatUtil.getDpnForInterface(interfaceService, interfaceName);
        if (fipCfgdDpnId.equals(Uint64.ZERO)) {
            LOG.info("hndlTepAddForDnatInEachRtr : DNAT->Skip processing Floating ip configuration for the port {}," + "since no DPN present for it", interfaceName);
            continue;
        }
        if (!fipCfgdDpnId.equals(tepAddedDpnId)) {
            LOG.debug("hndlTepAddForDnatInEachRtr : DNAT -> TEP added DPN {} is not the DPN {} which has the " + "floating IP configured for the port: {}", tepAddedDpnId, fipCfgdDpnId, interfaceName);
            continue;
        }
        for (InternalToExternalPortMap intExtPortMap : port.nonnullInternalToExternalPortMap().values()) {
            final String internalIp = intExtPortMap.getInternalIp();
            final String externalIp = intExtPortMap.getExternalIp();
            LOG.debug("hndlTepAddForDnatInEachRtr : DNAT -> Advertising the FIB route to the floating IP {} " + "configured for the port: {}", externalIp, interfaceName);
            Uint32 serviceId = null;
            String fibExternalIp = NatUtil.validateAndAddNetworkMask(externalIp);
            if (extNwProvType == ProviderTypes.VXLAN) {
                LOG.debug("hndlTepAddForDnatInEachRtr : DNAT -> Advertise the route to the externalIp {} " + "having nextHopIp {}", externalIp, nextHopIp);
                NatEvpnUtil.addRoutesForVxLanProvType(dataBroker, bgpManager, fibManager, vpnName, rd, externalIp, nextHopIp, l3Vni, interfaceName, gwMacAddress, confTx, RouteOrigin.STATIC, fipCfgdDpnId, extNwId);
                serviceId = l3Vni;
            } else {
                serviceId = floatingIPListener.getOperationalIpMapping(routerName, interfaceName, internalIp);
                if (serviceId == null || serviceId == NatConstants.INVALID_ID) {
                    LOG.error("hndlTepAddForDnatInEachRtr : DNAT -> Unable to advertise to the DC GW since label " + "is invalid");
                    return;
                }
                LOG.debug("hndlTepAddForDnatInEachRtr : DNAT -> Advertise the route to the externalIp {} " + "having nextHopIp {}", externalIp, nextHopIp);
                Uint32 l3vni = Uint32.ZERO;
                if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
                    l3vni = natOverVxlanUtil.getInternetVpnVni(vpnName, l3vni);
                }
                NatUtil.addPrefixToBGP(dataBroker, bgpManager, fibManager, vpnName, rd, fibExternalIp, nextHopIp, null, null, serviceId, l3vni, RouteOrigin.STATIC, fipCfgdDpnId);
            }
            // Install custom FIB routes (Table 21 -> Push MPLS label to Tunnel port
            List<Instruction> customInstructions = new ArrayList<>();
            customInstructions.add(new InstructionGotoTable(NwConstants.PDNAT_TABLE).buildInstruction(0));
            CreateFibEntryInput input = new CreateFibEntryInputBuilder().setVpnName(vpnName).setSourceDpid(fipCfgdDpnId).setInstruction(customInstructions).setIpAddressSource(FibEntryInputs.IpAddressSource.FloatingIP).setIpAddress(fibExternalIp).setServiceId(serviceId).setInstruction(customInstructions).build();
            ListenableFuture<RpcResult<CreateFibEntryOutput>> listenableFuture = fibRpcService.createFibEntry(input);
            Futures.addCallback(listenableFuture, new FutureCallback<RpcResult<CreateFibEntryOutput>>() {

                @Override
                public void onFailure(@NonNull Throwable error) {
                    LOG.error("hndlTepAddForDnatInEachRtr : DNAT -> Error in generate label or fib install process", error);
                }

                @Override
                public void onSuccess(@NonNull RpcResult<CreateFibEntryOutput> result) {
                    if (result.isSuccessful()) {
                        LOG.info("hndlTepAddForDnatInEachRtr : DNAT -> Successfully installed custom FIB routes " + "for prefix {}", externalIp);
                    } else {
                        LOG.error("hndlTepAddForDnatInEachRtr : DNAT -> Error in rpc call to create custom Fib " + "entries for prefix {} in DPN {}, {}", externalIp, fipCfgdDpnId, result.getErrors());
                    }
                }
            }, MoreExecutors.directExecutor());
        }
    }
}
Also used : RouterPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts) ArrayList(java.util.ArrayList) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction) ExecutionException(java.util.concurrent.ExecutionException) Uint32(org.opendaylight.yangtools.yang.common.Uint32) InternalToExternalPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap) InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) CreateFibEntryInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CreateFibEntryInputBuilder) CreateFibEntryOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CreateFibEntryOutput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) 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) CreateFibEntryInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CreateFibEntryInput) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Example 7 with CreateFibEntryOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CreateFibEntryOutput in project netvirt by opendaylight.

the class ExternalRoutersListener method advToBgpAndInstallFibAndTsFlows.

public void advToBgpAndInstallFibAndTsFlows(final Uint64 dpnId, final short tableId, final String vpnName, final Uint32 routerId, final String routerName, final String externalIp, final Uuid extNetworkId, @Nullable final Routers router, final TypedWriteTransaction<Configuration> confTx) {
    LOG.debug("advToBgpAndInstallFibAndTsFlows : entry for DPN ID {}, tableId {}, vpnname {} " + "and externalIp {}", dpnId, tableId, vpnName, externalIp);
    String nextHopIp = NatUtil.getEndpointIpAddressForDPN(dataBroker, dpnId);
    String rd = NatUtil.getVpnRd(dataBroker, vpnName);
    if (rd == null || rd.isEmpty()) {
        LOG.error("advToBgpAndInstallFibAndTsFlows : Unable to get RD for VPN Name {}", vpnName);
        return;
    }
    ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, extNetworkId);
    if (extNwProvType == null) {
        LOG.error("advToBgpAndInstallFibAndTsFlows : External Network Provider Type missing");
        return;
    }
    if (extNwProvType == ProviderTypes.VXLAN) {
        evpnSnatFlowProgrammer.evpnAdvToBgpAndInstallFibAndTsFlows(dpnId, tableId, externalIp, vpnName, rd, nextHopIp, routerId, routerName, extNetworkId, confTx);
        return;
    }
    // Generate VPN label for the external IP
    GenerateVpnLabelInput labelInput = new GenerateVpnLabelInputBuilder().setVpnName(vpnName).setIpPrefix(externalIp).build();
    ListenableFuture<RpcResult<GenerateVpnLabelOutput>> labelFuture = vpnService.generateVpnLabel(labelInput);
    // On successful generation of the VPN label, advertise the route to the BGP and install the FIB routes.
    ListenableFuture<RpcResult<CreateFibEntryOutput>> future = Futures.transformAsync(labelFuture, result -> {
        if (result.isSuccessful()) {
            LOG.debug("advToBgpAndInstallFibAndTsFlows : inside apply with result success");
            GenerateVpnLabelOutput output = result.getResult();
            final Uint32 label = output.getLabel();
            int externalIpInDsFlag = 0;
            // Get IPMaps from the DB for the router ID
            List<IpMap> dbIpMaps = NaptManager.getIpMapList(dataBroker, routerId);
            for (IpMap dbIpMap : dbIpMaps) {
                String dbExternalIp = dbIpMap.getExternalIp();
                // Select the IPMap, whose external IP is the IP for which FIB is installed
                if (dbExternalIp.contains(externalIp)) {
                    String dbInternalIp = dbIpMap.getInternalIp();
                    IpMapKey dbIpMapKey = dbIpMap.key();
                    LOG.debug("advToBgpAndInstallFibAndTsFlows : Setting label {} for internalIp {} " + "and externalIp {}", label, dbInternalIp, externalIp);
                    IpMap newIpm = new IpMapBuilder().withKey(dbIpMapKey).setInternalIp(dbInternalIp).setExternalIp(dbExternalIp).setLabel(label).build();
                    MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, naptManager.getIpMapIdentifier(routerId, dbInternalIp), newIpm);
                    externalIpInDsFlag++;
                }
            }
            if (externalIpInDsFlag <= 0) {
                LOG.debug("advToBgpAndInstallFibAndTsFlows : External Ip {} not found in DS, " + "Failed to update label {} for routerId {} in DS", externalIp, label, routerId);
                String errMsg = String.format("Failed to update label %s due to external Ip %s not" + " found in DS for router %s", label, externalIp, routerId);
                return Futures.immediateFailedFuture(new Exception(errMsg));
            }
            // Inform BGP
            Uint32 l3vni = Uint32.ZERO;
            if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
                l3vni = natOverVxlanUtil.getInternetVpnVni(vpnName, l3vni);
            }
            Routers extRouter = router != null ? router : NatUtil.getRoutersFromConfigDS(dataBroker, routerName);
            NatUtil.addPrefixToBGP(dataBroker, bgpManager, fibManager, vpnName, rd, externalIp, nextHopIp, extRouter.getNetworkId().getValue(), null, label, l3vni, RouteOrigin.STATIC, dpnId);
            // Install custom FIB routes
            List<Instruction> tunnelTableCustomInstructions = new ArrayList<>();
            tunnelTableCustomInstructions.add(new InstructionGotoTable(tableId).buildInstruction(0));
            makeTunnelTableEntry(dpnId, label, l3vni, tunnelTableCustomInstructions, confTx, extNwProvType);
            makeLFibTableEntry(dpnId, label, tableId, confTx);
            // Install custom FIB routes - FIB table.
            List<Instruction> fibTableCustomInstructions = createFibTableCustomInstructions(tableId, routerName, externalIp);
            if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
                // Install the flow table 25->44 If there is no FIP Match on table 25 (PDNAT_TABLE)
                NatUtil.makePreDnatToSnatTableEntry(mdsalManager, dpnId, NwConstants.INBOUND_NAPT_TABLE, confTx);
            }
            String externalVpn = vpnName;
            Uuid externalSubnetId = NatUtil.getExternalSubnetForRouterExternalIp(externalIp, extRouter);
            if (extNwProvType == ProviderTypes.VLAN || extNwProvType == ProviderTypes.FLAT) {
                Optional<Subnets> externalSubnet = NatUtil.getOptionalExternalSubnets(dataBroker, externalSubnetId);
                if (externalSubnet.isPresent()) {
                    externalVpn = externalSubnetId.getValue();
                }
            }
            String fibExternalIp = NatUtil.validateAndAddNetworkMask(externalIp);
            CreateFibEntryInput input = new CreateFibEntryInputBuilder().setVpnName(externalVpn).setSourceDpid(dpnId).setIpAddress(fibExternalIp).setServiceId(label).setIpAddressSource(CreateFibEntryInput.IpAddressSource.ExternalFixedIP).setInstruction(fibTableCustomInstructions).build();
            return fibService.createFibEntry(input);
        } else {
            LOG.error("advToBgpAndInstallFibAndTsFlows : inside apply with result failed");
            String errMsg = String.format("Could not retrieve the label for prefix %s in VPN %s, %s", externalIp, vpnName, result.getErrors());
            return Futures.immediateFailedFuture(new RuntimeException(errMsg));
        }
    }, MoreExecutors.directExecutor());
    Futures.addCallback(future, new FutureCallback<RpcResult<CreateFibEntryOutput>>() {

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

        @Override
        public void onSuccess(@NonNull RpcResult<CreateFibEntryOutput> result) {
            if (result.isSuccessful()) {
                LOG.info("advToBgpAndInstallFibAndTsFlows : Successfully installed custom FIB routes for prefix {}", externalIp);
            } else {
                LOG.error("advToBgpAndInstallFibAndTsFlows : Error in rpc call to create custom Fib entries " + "for prefix {} in DPN {}, {}", externalIp, dpnId, result.getErrors());
            }
        }
    }, MoreExecutors.directExecutor());
}
Also used : GenerateVpnLabelOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.GenerateVpnLabelOutput) ArrayList(java.util.ArrayList) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction) IpMapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMapKey) 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) Uint32(org.opendaylight.yangtools.yang.common.Uint32) InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) ExtRouters(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExtRouters) 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) CreateFibEntryOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CreateFibEntryOutput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) IpMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMap) CreateFibEntryInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CreateFibEntryInput) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) 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) IpMapBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMapBuilder)

Aggregations

Instruction (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction)7 Uint32 (org.opendaylight.yangtools.yang.common.Uint32)7 ArrayList (java.util.ArrayList)6 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)6 CreateFibEntryInput (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CreateFibEntryInput)6 CreateFibEntryInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CreateFibEntryInputBuilder)6 CreateFibEntryOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CreateFibEntryOutput)6 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)6 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)5 ExecutionException (java.util.concurrent.ExecutionException)4 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)3 InstructionKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey)3 FutureCallback (com.google.common.util.concurrent.FutureCallback)2 Futures (com.google.common.util.concurrent.Futures)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)2 BigInteger (java.math.BigInteger)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 List (java.util.List)2