Search in sources :

Example 46 with Routers

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers in project netvirt by opendaylight.

the class ExternalRoutersListener method handleSnatReverseTraffic.

public void handleSnatReverseTraffic(BigInteger dpnId, Routers router, long routerId, String routerName, String externalIp, WriteTransaction writeFlowInvTx) {
    LOG.debug("handleSnatReverseTraffic : entry for DPN ID {}, routerId {}, externalIp: {}", dpnId, routerId, externalIp);
    Uuid networkId = router.getNetworkId();
    if (networkId == null) {
        LOG.error("handleSnatReverseTraffic : networkId is null for the router ID {}", routerId);
        return;
    }
    final String vpnName = NatUtil.getAssociatedVPN(dataBroker, networkId);
    if (vpnName == null) {
        LOG.error("handleSnatReverseTraffic : No VPN associated with ext nw {} to handle add external ip " + "configuration {} in router {}", networkId, externalIp, routerId);
        return;
    }
    advToBgpAndInstallFibAndTsFlows(dpnId, NwConstants.INBOUND_NAPT_TABLE, vpnName, routerId, routerName, externalIp, networkId, router, writeFlowInvTx);
    LOG.debug("handleSnatReverseTraffic : exit for DPN ID {}, routerId {}, externalIp : {}", dpnId, routerId, externalIp);
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)

Example 47 with Routers

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers in project netvirt by opendaylight.

the class ExternalRoutersListener method subnetRegisterMapping.

protected void subnetRegisterMapping(Routers routerEntry, Long segmentId) {
    List<Uuid> subnetList = null;
    List<String> externalIps = null;
    LOG.debug("subnetRegisterMapping : Fetching values from extRouters model");
    subnetList = routerEntry.getSubnetIds();
    externalIps = NatUtil.getIpsListFromExternalIps(routerEntry.getExternalIps());
    int counter = 0;
    int extIpCounter = externalIps.size();
    LOG.debug("subnetRegisterMapping : counter values before looping counter {} and extIpCounter {}", counter, extIpCounter);
    for (Uuid subnet : subnetList) {
        LOG.debug("subnetRegisterMapping : Looping internal subnets for subnet {}", subnet);
        InstanceIdentifier<Subnetmap> subnetmapId = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new SubnetmapKey(subnet)).build();
        Optional<Subnetmap> sn = read(dataBroker, LogicalDatastoreType.CONFIGURATION, subnetmapId);
        if (sn.isPresent()) {
            // subnets
            Subnetmap subnetmapEntry = sn.get();
            String subnetString = subnetmapEntry.getSubnetIp();
            String[] subnetSplit = subnetString.split("/");
            String subnetIp = subnetSplit[0];
            try {
                InetAddress address = InetAddress.getByName(subnetIp);
                if (address instanceof Inet6Address) {
                    LOG.debug("subnetRegisterMapping : Skipping ipv6 subnet {} for the router {} with ipv6 address " + "{} ", subnet, routerEntry.getRouterName(), address);
                    continue;
                }
            } catch (UnknownHostException e) {
                LOG.error("subnetRegisterMapping : Invalid ip address {}", subnetIp, e);
                return;
            }
            String subnetPrefix = "0";
            if (subnetSplit.length == 2) {
                subnetPrefix = subnetSplit[1];
            }
            IPAddress subnetAddr = new IPAddress(subnetIp, Integer.parseInt(subnetPrefix));
            LOG.debug("subnetRegisterMapping : subnetAddr is {} and subnetPrefix is {}", subnetAddr.getIpAddress(), subnetAddr.getPrefixLength());
            // externalIps
            LOG.debug("subnetRegisterMapping : counter values counter {} and extIpCounter {}", counter, extIpCounter);
            if (extIpCounter != 0) {
                if (counter < extIpCounter) {
                    String[] ipSplit = externalIps.get(counter).split("/");
                    String externalIp = ipSplit[0];
                    String extPrefix = Short.toString(NatConstants.DEFAULT_PREFIX);
                    if (ipSplit.length == 2) {
                        extPrefix = ipSplit[1];
                    }
                    IPAddress externalIpAddr = new IPAddress(externalIp, Integer.parseInt(extPrefix));
                    LOG.debug("subnetRegisterMapping : externalIp is {} and extPrefix  is {}", externalIpAddr.getIpAddress(), externalIpAddr.getPrefixLength());
                    naptManager.registerMapping(segmentId, subnetAddr, externalIpAddr);
                    LOG.debug("subnetRegisterMapping : Called registerMapping for subnetIp {}, prefix {}, " + "externalIp {}. prefix {}", subnetIp, subnetPrefix, externalIp, extPrefix);
                } else {
                    // Reset the counter which runs on externalIps for round-robbin effect
                    counter = 0;
                    LOG.debug("subnetRegisterMapping : Counter on externalIps got reset");
                    String[] ipSplit = externalIps.get(counter).split("/");
                    String externalIp = ipSplit[0];
                    String extPrefix = Short.toString(NatConstants.DEFAULT_PREFIX);
                    if (ipSplit.length == 2) {
                        extPrefix = ipSplit[1];
                    }
                    IPAddress externalIpAddr = new IPAddress(externalIp, Integer.parseInt(extPrefix));
                    LOG.debug("subnetRegisterMapping : externalIp is {} and extPrefix  is {}", externalIpAddr.getIpAddress(), externalIpAddr.getPrefixLength());
                    naptManager.registerMapping(segmentId, subnetAddr, externalIpAddr);
                    LOG.debug("subnetRegisterMapping : Called registerMapping for subnetIp {}, prefix {}, " + "externalIp {}. prefix {}", subnetIp, subnetPrefix, externalIp, extPrefix);
                }
            }
            counter++;
            LOG.debug("subnetRegisterMapping : Counter on externalIps incremented to {}", counter);
        } else {
            LOG.warn("subnetRegisterMapping : No internal subnets present in extRouters Model");
        }
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) Inet6Address(java.net.Inet6Address) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) SubnetmapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapKey) InetAddress(java.net.InetAddress)

Example 48 with Routers

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers 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 49 with Routers

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers in project netvirt by opendaylight.

the class FlatVlanConntrackBasedSnatService method handleSnatAllSwitch.

@Override
public boolean handleSnatAllSwitch(Routers routers, BigInteger primarySwitchId, int addOrRemove) {
    ProviderTypes extNwProviderType = NatUtil.getProviderTypefromNetworkId(dataBroker, routers.getNetworkId());
    LOG.debug("FlatVlanConntrackBasedSnatService: handleSnatAllSwitch ProviderTypes {}", extNwProviderType);
    if (extNwProviderType == ProviderTypes.VXLAN || extNwProviderType == ProviderTypes.GRE) {
        return false;
    }
    return super.handleSnatAllSwitch(routers, primarySwitchId, addOrRemove);
}
Also used : ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)

Example 50 with Routers

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers in project netvirt by opendaylight.

the class NaptManager method initialiseExternalCounter.

protected void initialiseExternalCounter(Routers routers, long routerId) {
    LOG.debug("initialiseExternalCounter : Initialise External IPs counter");
    List<ExternalIps> externalIps = routers.getExternalIps();
    // update the new counter value for this externalIp
    for (ExternalIps externalIp : externalIps) {
        String[] ipSplit = externalIp.getIpAddress().split("/");
        String extIp = ipSplit[0];
        String extPrefix = Short.toString(NatConstants.DEFAULT_PREFIX);
        if (ipSplit.length == 2) {
            extPrefix = ipSplit[1];
        }
        extIp = extIp + "/" + extPrefix;
        initialiseNewExternalIpCounter(routerId, extIp);
    }
}
Also used : 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)33 Routers (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers)26 BigInteger (java.math.BigInteger)22 ExternalIps (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)16 ProviderTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)12 ArrayList (java.util.ArrayList)11 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)7 UnknownHostException (java.net.UnknownHostException)6 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)6 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)6 RoutersBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.RoutersBuilder)6 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)5 ExecutionException (java.util.concurrent.ExecutionException)5 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)5 InetAddress (java.net.InetAddress)4 List (java.util.List)4 ExtRouters (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExtRouters)4 IpPortMapping (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.IpPortMapping)4 IntextIpProtocolType (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.IntextIpProtocolType)4 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)3