Search in sources :

Example 6 with RemoveFibEntryOutput

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

the class NatTepChangeListener method hndlTepDelForDnatInEachRtr.

private boolean hndlTepDelForDnatInEachRtr(RoutersList router, Uint32 routerId, Uint64 tepDeletedDpnId, ProviderTypes extNwProvType) {
    // DNAT : Withdraw the routes from the BGP
    String routerName = router.getRouter();
    Boolean isFipExists = Boolean.FALSE;
    LOG.debug("hndlTepDelForDnatInEachRtr : DNAT -> Trying to clear routes to the Floating IP " + "associated to the router {}", routerName);
    InstanceIdentifier<RouterPorts> routerPortsId = NatUtil.getRouterPortsId(routerName);
    Optional<RouterPorts> optRouterPorts;
    try {
        optRouterPorts = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsId);
    } catch (ExecutionException | InterruptedException e) {
        LOG.error("hndlTepDelForDnatInEachRtr: Exception while reading RouterPorts DS for the router {}", routerName, e);
        return isFipExists;
    }
    if (!optRouterPorts.isPresent()) {
        LOG.debug("hndlTepDelForDnatInEachRtr : DNAT -> Could not read Router Ports data object with id: {} " + "from DNAT FloatingIpInfo", routerName);
        return isFipExists;
    }
    RouterPorts routerPorts = optRouterPorts.get();
    Uuid extNwId = routerPorts.getExternalNetworkId();
    final String vpnName = NatUtil.getAssociatedVPN(dataBroker, extNwId);
    if (vpnName == null) {
        LOG.error("hndlTepDelForDnatInEachRtr : DNAT -> No External VPN associated with Ext N/W {} for Router {}", extNwId, routerName);
        return isFipExists;
    }
    String rd = NatUtil.getVpnRd(dataBroker, vpnName);
    if (extNwProvType == null) {
        return isFipExists;
    }
    Uint32 l3Vni = Uint32.ZERO;
    if (extNwProvType == ProviderTypes.VXLAN) {
        // get l3Vni value for external VPN
        l3Vni = NatEvpnUtil.getL3Vni(dataBroker, rd);
        if (l3Vni == NatConstants.DEFAULT_L3VNI_VALUE) {
            LOG.debug("hndlTepDelForDnatInEachRtr : 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);
        }
    }
    Map<PortsKey, Ports> interfacesMap = routerPorts.nonnullPorts();
    for (Ports port : interfacesMap.values()) {
        // Get the DPN on which this interface resides
        String interfaceName = port.getPortName();
        Uint64 fipCfgdDpnId = NatUtil.getDpnForInterface(interfaceService, interfaceName);
        if (fipCfgdDpnId.equals(Uint64.ZERO)) {
            LOG.info("hndlTepDelForDnatInEachRtr : DNAT -> Abort processing Floating ip configuration. " + "No DPN for port : {}", interfaceName);
            continue;
        }
        if (!fipCfgdDpnId.equals(tepDeletedDpnId)) {
            LOG.info("hndlTepDelForDnatInEachRtr : DNAT -> TEP deleted DPN {} is not the DPN {} which has the " + "floating IP configured for the port: {}", tepDeletedDpnId, fipCfgdDpnId, interfaceName);
            continue;
        }
        isFipExists = Boolean.TRUE;
        Map<InternalToExternalPortMapKey, InternalToExternalPortMap> keyInternalToExternalPortMapMap = port.nonnullInternalToExternalPortMap();
        for (InternalToExternalPortMap intExtPortMap : keyInternalToExternalPortMapMap.values()) {
            String internalIp = intExtPortMap.getInternalIp();
            String externalIp = intExtPortMap.getExternalIp();
            externalIp = NatUtil.validateAndAddNetworkMask(externalIp);
            LOG.debug("hndlTepDelForDnatInEachRtr : DNAT -> Withdrawing the FIB route to the floating IP {} " + "configured for the port: {}", externalIp, interfaceName);
            NatUtil.removePrefixFromBGP(bgpManager, fibManager, rd, externalIp, vpnName);
            Uint32 serviceId = null;
            if (extNwProvType == ProviderTypes.VXLAN) {
                serviceId = l3Vni;
            } else {
                serviceId = floatingIPListener.getOperationalIpMapping(routerName, interfaceName, internalIp);
                if (serviceId == null || serviceId == NatConstants.INVALID_ID) {
                    LOG.error("hndlTepDelForDnatInEachRtr : DNAT -> Unable to remove the table 21 entry pushing the" + " MPLS label to the tunnel since label is invalid");
                    continue;
                }
            }
            RemoveFibEntryInput input = new RemoveFibEntryInputBuilder().setVpnName(vpnName).setSourceDpid(fipCfgdDpnId).setIpAddress(externalIp).setServiceId(serviceId).setIpAddressSource(RemoveFibEntryInput.IpAddressSource.FloatingIP).build();
            ListenableFuture<RpcResult<RemoveFibEntryOutput>> future = fibRpcService.removeFibEntry(input);
            Futures.addCallback(future, new FutureCallback<RpcResult<RemoveFibEntryOutput>>() {

                @Override
                public void onFailure(Throwable error) {
                    LOG.error("hndlTepDelForDnatInEachRtr : DNAT -> Error in removing the table 21 entry pushing " + "the MPLS label to the tunnel since label is invalid ", error);
                }

                @Override
                public void onSuccess(RpcResult<RemoveFibEntryOutput> result) {
                    if (result.isSuccessful()) {
                        LOG.info("hndlTepDelForDnatInEachRtr : DNAT -> Successfully removed the entry pushing the " + "MPLS label to the tunnel");
                    } else {
                        LOG.error("hndlTepDelForDnatInEachRtr : DNAT -> Error in fib rpc call to remove the table " + "21 entry pushing the MPLS label to the tunnnel due to {}", result.getErrors());
                    }
                }
            }, MoreExecutors.directExecutor());
        }
    }
    return isFipExists;
}
Also used : InternalToExternalPortMapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMapKey) RouterPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts) RemoveFibEntryOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.RemoveFibEntryOutput) RemoveFibEntryInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.RemoveFibEntryInput) 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) PortsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.PortsKey) 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) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) RemoveFibEntryInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.RemoveFibEntryInputBuilder) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Aggregations

RemoveFibEntryInput (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.RemoveFibEntryInput)5 RemoveFibEntryInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.RemoveFibEntryInputBuilder)5 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)5 Uint32 (org.opendaylight.yangtools.yang.common.Uint32)5 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)3 RemoveFibEntryOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.RemoveFibEntryOutput)3 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)3 ExecutionException (java.util.concurrent.ExecutionException)2 RemoveVpnLabelInput (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.RemoveVpnLabelInput)2 RemoveVpnLabelInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.RemoveVpnLabelInputBuilder)2 RemoveVpnLabelOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.RemoveVpnLabelOutput)2 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1