Search in sources :

Example 6 with NatMode

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.config.rev170206.NatserviceConfig.NatMode in project netvirt by opendaylight.

the class NatTunnelInterfaceStateListener method hndlTepAddForSnatInEachRtr.

private void hndlTepAddForSnatInEachRtr(RoutersList router, long routerId, final BigInteger srcDpnId, String tunnelType, String srcTepIp, String destTepIp, String tunnelName, String nextHopIp, ProviderTypes extNwProvType, WriteTransaction writeFlowInvTx) {
    /*SNAT : Remove the old routes to the external IP having the old TEP IP as the next hop IP
                 Advertise to the BGP about the new route to the external IP having the new TEP IP
                  added as the next hop IP
         */
    String routerName = router.getRouter();
    // Check if this is externalRouter else ignore
    InstanceIdentifier<Routers> extRoutersId = NatUtil.buildRouterIdentifier(routerName);
    Optional<Routers> routerData = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, extRoutersId);
    if (!routerData.isPresent()) {
        LOG.warn("hndlTepAddForSnatInEachRtr : SNAT->Ignoring TEP add for router {} since its not External Router", routerName);
        return;
    }
    BigInteger naptId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
    if (naptId == null || naptId.equals(BigInteger.ZERO)) {
        LOG.warn("hndlTepAddForSnatInEachRtr : SNAT -> Ignoring TEP add for the DPN {} having the router {} since" + " the router is not part of the NAT service  - the TUNNEL TYPE {} b/w SRC IP {} and DST IP {} and" + "TUNNEL NAME {} ", srcDpnId, routerName, tunnelType, srcTepIp, destTepIp, tunnelName);
        return;
    }
    if (natMode == NatMode.Conntrack) {
        natServiceManager.notify(routerData.get(), naptId, srcDpnId, SnatServiceManager.Action.SNAT_ROUTER_ENBL);
    } else {
        Uuid bgpVpnUuId = NatUtil.getVpnForRouter(dataBroker, routerName);
        // Check if the DPN having the router is the NAPT switch
        if (!naptId.equals(srcDpnId)) {
            /*
            1) Install default NAT rule from table 21 to 26
            2) Install the group which forward packet to the tunnel port for the NAPT switch.
            3) Install the flow 26 which forwards the packet to the group.
                 */
            if (!hndlTepAddOnNonNaptSwitch(srcDpnId, naptId, tunnelType, srcTepIp, destTepIp, tunnelName, routerName, routerId, bgpVpnUuId, writeFlowInvTx)) {
                LOG.error("hndlTepAddForSnatInEachRtr : Unable to process the TEP add event on NON-NAPT switch {}", srcDpnId);
                return;
            }
            return;
        }
        if (!hndlTepAddOnNaptSwitch(srcDpnId, tunnelType, srcTepIp, destTepIp, tunnelName, routerId, routerData, nextHopIp, bgpVpnUuId, extNwProvType, writeFlowInvTx)) {
            LOG.debug("hndlTepAddForSnatInEachRtr : Unable to process the TEP add event on NAPT switch {}", srcDpnId);
            return;
        }
    }
    return;
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) BigInteger(java.math.BigInteger)

Example 7 with NatMode

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.config.rev170206.NatserviceConfig.NatMode in project netvirt by opendaylight.

the class NatTunnelInterfaceStateListener method hndlTepDelForSnatInEachRtr.

private void hndlTepDelForSnatInEachRtr(RoutersList router, long routerId, BigInteger dpnId, String tunnelType, String srcTepIp, String destTepIp, String tunnelName, ProviderTypes extNwProvType, WriteTransaction writeFlowInvTx) {
    /*SNAT :
            1) Elect a new switch as the primary NAPT
            2) Advertise the new routes to BGP for the newly elected TEP IP as the DPN IP
            3) This will make sure old routes are withdrawn and new routes are advertised.
         */
    String routerName = router.getRouter();
    LOG.debug("hndlTepDelForSnatInEachRtr : SNAT -> Trying to clear routes to the External fixed IP associated " + "to the router {}", routerName);
    // Check if this is externalRouter else ignore
    InstanceIdentifier<Routers> extRoutersId = NatUtil.buildRouterIdentifier(routerName);
    Optional<Routers> routerData = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, extRoutersId);
    if (!routerData.isPresent()) {
        LOG.debug("hndlTepDelForSnatInEachRtr : SNAT->Ignoring TEP del for router {} since its not External Router", routerName);
        return;
    }
    // Check if the DPN having the router is the NAPT switch
    BigInteger naptId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
    if (naptId == null || naptId.equals(BigInteger.ZERO) || !naptId.equals(dpnId)) {
        LOG.warn("hndlTepDelForSnatInEachRtr : SNAT -> Ignoring TEP delete for the DPN {} since" + " its NOT a NAPT switch for the TUNNEL TYPE {} b/w SRC IP {} and DST IP {} and" + "TUNNEL NAME {} ", dpnId, tunnelType, srcTepIp, destTepIp, tunnelName);
        return;
    }
    if (natMode == NatMode.Conntrack) {
        natServiceManager.notify(routerData.get(), naptId, dpnId, SnatServiceManager.Action.SNAT_ROUTER_DISBL);
    } else {
        Uuid networkId = routerData.get().getNetworkId();
        if (networkId == null) {
            LOG.error("hndlTepDelForSnatInEachRtr : SNAT->Ignoring TEP delete for the DPN {} having the router {} " + "since the Router instance {} not found in ExtRouters model b/w SRC IP {} and DST " + "IP {} and TUNNEL NAME {} ", dpnId, routerData.get().getRouterName(), tunnelType, srcTepIp, destTepIp, tunnelName);
            return;
        }
        LOG.debug("hndlTepDelForSnatInEachRtr : SNAT->Router {} is associated with ext nw {}", routerId, networkId);
        Uuid bgpVpnUuid = NatUtil.getVpnForRouter(dataBroker, routerName);
        Long bgpVpnId;
        if (bgpVpnUuid == null) {
            LOG.debug("hndlTepDelForSnatInEachRtr : SNAT->Internal VPN-ID {} associated to router {}", routerId, routerName);
            bgpVpnId = routerId;
            // Install default entry in FIB to SNAT table
            LOG.debug("hndlTepDelForSnatInEachRtr : Installing default route in FIB on DPN {} for router {} with" + " vpn {}...", dpnId, routerName, bgpVpnId);
            defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, bgpVpnId, writeFlowInvTx);
        } else {
            bgpVpnId = NatUtil.getVpnId(dataBroker, bgpVpnUuid.getValue());
            if (bgpVpnId == NatConstants.INVALID_ID) {
                LOG.error("hndlTepDelForSnatInEachRtr :SNAT->Invalid Private BGP VPN ID returned for routerName {}", routerName);
                return;
            }
            LOG.debug("hndlTepDelForSnatInEachRtr :SNAT->External BGP VPN (Private BGP) {} associated to router {}", bgpVpnId, routerName);
            // Install default entry in FIB to SNAT table
            LOG.debug("hndlTepDelForSnatInEachRtr : Installing default route in FIB on dpn {} for routerId {} " + "with vpnId {}...", dpnId, routerId, bgpVpnId);
            defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, bgpVpnId, routerId, writeFlowInvTx);
        }
        if (routerData.get().isEnableSnat()) {
            LOG.info("hndlTepDelForSnatInEachRtr : SNAT enabled for router {}", routerId);
            long routerVpnId = routerId;
            if (bgpVpnId != NatConstants.INVALID_ID) {
                LOG.debug("hndlTepDelForSnatInEachRtr : SNAT -> Private BGP VPN ID (Internal BGP VPN ID) {} " + "associated to the router {}", bgpVpnId, routerName);
                routerVpnId = bgpVpnId;
            } else {
                LOG.debug("hndlTepDelForSnatInEachRtr : SNAT -> Internal L3 VPN ID (Router ID) {} " + "associated to the router {}", routerVpnId, routerName);
            }
            // Re-elect the other available switch as the NAPT switch and program the NAT flows.
            removeSNATFromDPN(dpnId, routerName, routerId, routerVpnId, networkId, extNwProvType, writeFlowInvTx);
        } else {
            LOG.info("hndlTepDelForSnatInEachRtr : SNAT is not enabled for router {} to handle addDPN event {}", routerId, dpnId);
        }
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) BigInteger(java.math.BigInteger)

Example 8 with NatMode

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.config.rev170206.NatserviceConfig.NatMode in project netvirt by opendaylight.

the class RouterDpnChangeListener method remove.

@Override
protected void remove(InstanceIdentifier<DpnVpninterfacesList> identifier, DpnVpninterfacesList dpnInfo) {
    LOG.trace("remove : key: {}, value: {}", dpnInfo.getKey(), dpnInfo);
    final String routerUuid = identifier.firstKeyOf(RouterDpnList.class).getRouterId();
    Long routerId = NatUtil.getVpnId(dataBroker, routerUuid);
    if (routerId == NatConstants.INVALID_ID) {
        LOG.error("REMOVE: Invalid routId returned for routerName {}", routerUuid);
        return;
    }
    BigInteger dpnId = dpnInfo.getDpnId();
    // check router is associated to external network
    InstanceIdentifier<Routers> id = NatUtil.buildRouterIdentifier(routerUuid);
    Optional<Routers> routerData = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
    if (routerData.isPresent()) {
        Routers router = routerData.get();
        Uuid networkId = router.getNetworkId();
        if (networkId != null) {
            if (natMode == NatMode.Conntrack) {
                BigInteger naptSwitch = NatUtil.getPrimaryNaptfromRouterName(dataBroker, router.getRouterName());
                if (naptSwitch == null || naptSwitch.equals(BigInteger.ZERO)) {
                    LOG.warn("remove : NAPT switch is not selected.");
                    return;
                }
                // If it is for NAPT switch skip as the flows would be already programmed.
                if (naptSwitch.equals(dpnId)) {
                    LOG.debug("Skipping the notification recived for NAPT switch {}", routerUuid);
                    return;
                }
                natServiceManager.notify(router, naptSwitch, dpnId, SnatServiceManager.Action.SNAT_ROUTER_DISBL);
            } else {
                coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + dpnInfo.getKey(), () -> {
                    WriteTransaction removeFlowInvTx = dataBroker.newWriteOnlyTransaction();
                    LOG.debug("remove : Router {} is associated with ext nw {}", routerUuid, networkId);
                    Uuid vpnName = NatUtil.getVpnForRouter(dataBroker, routerUuid);
                    Long vpnId;
                    List<ListenableFuture<Void>> futures = new ArrayList<>();
                    if (vpnName == null) {
                        LOG.debug("remove : Internal vpn associated to router {}", routerUuid);
                        vpnId = routerId;
                        if (vpnId == NatConstants.INVALID_ID) {
                            LOG.error("remove : Invalid vpnId returned for routerName {}", routerUuid);
                            removeFlowInvTx.cancel();
                            return futures;
                        }
                        LOG.debug("remove : Retrieved vpnId {} for router {}", vpnId, routerUuid);
                        // Remove default entry in FIB
                        LOG.debug("remove : Removing default route in FIB on dpn {} for vpn {} ...", dpnId, vpnName);
                        snatDefaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, vpnId, removeFlowInvTx);
                    } else {
                        LOG.debug("remove : External vpn associated to router {}", routerUuid);
                        vpnId = NatUtil.getVpnId(dataBroker, vpnName.getValue());
                        if (vpnId == NatConstants.INVALID_ID) {
                            LOG.error("remove : Invalid vpnId returned for routerName {}", routerUuid);
                            removeFlowInvTx.cancel();
                            return futures;
                        }
                        LOG.debug("remove : Retrieved vpnId {} for router {}", vpnId, routerUuid);
                        // Remove default entry in FIB
                        LOG.debug("remove : Removing default route in FIB on dpn {} for vpn {} ...", dpnId, vpnName);
                        snatDefaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, vpnId, routerId, removeFlowInvTx);
                    }
                    if (router.isEnableSnat()) {
                        LOG.info("remove : SNAT enabled for router {}", routerUuid);
                        removeSNATFromDPN(dpnId, routerUuid, routerId, vpnId, networkId, removeFlowInvTx);
                    } else {
                        LOG.info("remove : SNAT is not enabled for router {} to handle removeDPN event {}", routerUuid, dpnId);
                    }
                    futures.add(NatUtil.waitForTransactionToComplete(removeFlowInvTx));
                    return futures;
                }, NatConstants.NAT_DJC_MAX_RETRIES);
            }
        // end of controller based SNAT
        }
    }
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) RouterDpnList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.RouterDpnList)

Example 9 with NatMode

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.config.rev170206.NatserviceConfig.NatMode in project netvirt by opendaylight.

the class ExternalRoutersListener method add.

@Override
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
protected void add(InstanceIdentifier<Routers> identifier, Routers routers) {
    // Populate the router-id-name container
    String routerName = routers.getRouterName();
    LOG.info("add : external router event for {}", routerName);
    long routerId = NatUtil.getVpnId(dataBroker, routerName);
    NatUtil.createRouterIdsConfigDS(dataBroker, routerId, routerName);
    Uuid bgpVpnUuid = NatUtil.getVpnForRouter(dataBroker, routerName);
    if (natMode == NatMode.Conntrack && !upgradeState.isUpgradeInProgress()) {
        if (bgpVpnUuid != null) {
            return;
        }
        List<ExternalIps> externalIps = routers.getExternalIps();
        // Allocate Primary Napt Switch for this router
        if (routers.isEnableSnat() && externalIps != null && !externalIps.isEmpty()) {
            centralizedSwitchScheduler.scheduleCentralizedSwitch(routers);
        }
    // snatServiceManger.notify(routers, null, Action.ADD);
    } else {
        try {
            coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + routers.getKey(), () -> {
                WriteTransaction writeFlowInvTx = dataBroker.newWriteOnlyTransaction();
                LOG.info("add : Installing NAT default route on all dpns part of router {}", routerName);
                long bgpVpnId = NatConstants.INVALID_ID;
                if (bgpVpnUuid != null) {
                    bgpVpnId = NatUtil.getVpnId(dataBroker, bgpVpnUuid.getValue());
                }
                addOrDelDefFibRouteToSNAT(routerName, routerId, bgpVpnId, bgpVpnUuid, true, writeFlowInvTx);
                List<ListenableFuture<Void>> futures = new ArrayList<>();
                // Allocate Primary Napt Switch for this router
                BigInteger primarySwitchId = getPrimaryNaptSwitch(routerName);
                if (primarySwitchId != null && !primarySwitchId.equals(BigInteger.ZERO)) {
                    if (!routers.isEnableSnat()) {
                        LOG.info("add : SNAT is disabled for external router {} ", routerName);
                        /* If SNAT is disabled on ext-router though L3_FIB_TABLE(21) -> PSNAT_TABLE(26) flow
                             * is required for DNAT. Hence writeFlowInvTx object submit is required.
                             */
                        return futures;
                    }
                    handleEnableSnat(routers, routerId, primarySwitchId, bgpVpnId, writeFlowInvTx);
                }
                // final submit call for writeFlowInvTx
                futures.add(NatUtil.waitForTransactionToComplete(writeFlowInvTx));
                return futures;
            }, NatConstants.NAT_DJC_MAX_RETRIES);
        } catch (Exception ex) {
            LOG.error("add : Exception while Installing NAT flows on all dpns as part of router {}", routerName, ex);
        }
    }
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ArrayList(java.util.ArrayList) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) BigInteger(java.math.BigInteger) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) ExternalIps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)

Example 10 with NatMode

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.config.rev170206.NatserviceConfig.NatMode in project netvirt by opendaylight.

the class UpgradeStateListener method update.

@Override
public void update(@Nonnull Config original, Config updated) {
    if (natMode != NatserviceConfig.NatMode.Conntrack) {
        return;
    }
    LOG.info("UpgradeStateListener update from {} to {}", original, updated);
    if (!(original.isUpgradeInProgress() && !updated.isUpgradeInProgress())) {
        return;
    }
    SingleTransactionDataBroker reader = new SingleTransactionDataBroker(dataBroker);
    ExtRouters routers;
    try {
        routers = reader.syncRead(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(ExtRouters.class));
    } catch (ReadFailedException e) {
        LOG.error("Error reading external routers", e);
        return;
    }
    for (Routers router : routers.getRouters()) {
        List<ExternalIps> externalIps = router.getExternalIps();
        if (router.isEnableSnat() && externalIps != null && !externalIps.isEmpty()) {
            centralizedSwitchScheduler.scheduleCentralizedSwitch(router);
        }
    }
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) ExtRouters(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExtRouters) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) SingleTransactionDataBroker(org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker) ExtRouters(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExtRouters) ExternalIps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)9 BigInteger (java.math.BigInteger)7 Routers (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers)6 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)4 ArrayList (java.util.ArrayList)4 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)4 ExternalIps (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)3 ExecutionException (java.util.concurrent.ExecutionException)2 RouterDpnList (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.RouterDpnList)2 IpMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMap)2 UnknownHostException (java.net.UnknownHostException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)1 SingleTransactionDataBroker (org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker)1 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)1 GroupEntity (org.opendaylight.genius.mdsalutil.GroupEntity)1 ExtRouters (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExtRouters)1