Search in sources :

Example 11 with ExtRouters

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExtRouters 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 12 with ExtRouters

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExtRouters 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)

Example 13 with ExtRouters

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExtRouters in project netvirt by opendaylight.

the class NeutronvpnNatManager method addExternalRouter.

public void addExternalRouter(Router update) {
    Uuid routerId = update.getUuid();
    Uuid extNetId = update.getExternalGatewayInfo().getExternalNetworkId();
    Uuid gatewayPortId = update.getGatewayPortId();
    // Create and add Routers object for this Router to the ExtRouters list
    // Create a Routers object
    InstanceIdentifier<Routers> routersIdentifier = NeutronvpnUtils.buildExtRoutersIdentifier(routerId);
    try {
        Network input = neutronvpnUtils.getNeutronNetwork(extNetId);
        ProviderTypes providerNwType = NeutronvpnUtils.getProviderNetworkType(input);
        if (providerNwType == null) {
            LOG.error("Unable to get Network Provider Type for network {}", input.getUuid().getValue());
            return;
        }
        Optional<Routers> optionalRouters = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier);
        LOG.trace("Creating/Updating a new Routers node: {}", routerId.getValue());
        RoutersBuilder builder = null;
        if (optionalRouters.isPresent()) {
            builder = new RoutersBuilder(optionalRouters.get());
        } else {
            builder = new RoutersBuilder().setKey(new RoutersKey(routerId.getValue()));
        }
        builder.setRouterName(routerId.getValue());
        builder.setNetworkId(extNetId);
        builder.setEnableSnat(update.getExternalGatewayInfo().isEnableSnat());
        ArrayList<ExternalIps> externalIps = new ArrayList<>();
        for (ExternalFixedIps fixedIps : update.getExternalGatewayInfo().getExternalFixedIps()) {
            addExternalFixedIpToExternalIpsList(externalIps, fixedIps);
        }
        builder.setExternalIps(externalIps);
        if (gatewayPortId != null) {
            LOG.trace("Setting/Updating gateway Mac for router {}", routerId.getValue());
            Port port = neutronvpnUtils.getNeutronPort(gatewayPortId);
            if (port != null && port.getDeviceOwner().equals(NeutronConstants.DEVICE_OWNER_GATEWAY_INF)) {
                builder.setExtGwMacAddress(port.getMacAddress().getValue());
            }
        }
        List<Uuid> subList = neutronvpnUtils.getNeutronRouterSubnetIds(routerId);
        builder.setSubnetIds(subList);
        Routers routers = builder.build();
        // Add Routers object to the ExtRouters list
        LOG.trace("Creating extrouters {}", routers);
        SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier, builder.build());
        LOG.trace("Wrote successfully Routers to CONFIG Datastore");
    } catch (ReadFailedException | TransactionCommitFailedException ex) {
        LOG.error("Creation of extrouters failed for router {} failed", routerId.getValue(), ex);
    }
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes) Port(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port) ArrayList(java.util.ArrayList) ExternalIps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps) RoutersKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.RoutersKey) ExternalFixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.router.external_gateway_info.ExternalFixedIps) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) RoutersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.RoutersBuilder) Network(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network)

Example 14 with ExtRouters

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExtRouters in project netvirt by opendaylight.

the class NeutronvpnNatManager method removeExternalNetworkFromRouter.

public void removeExternalNetworkFromRouter(Uuid origExtNetId, Router update, List<ExternalFixedIps> origExtFixedIps) {
    Uuid routerId = update.getUuid();
    // Remove the router to the ExtRouters list
    removeExternalRouter(update);
    // Remove router entry from floating-ip-info list
    removeRouterFromFloatingIpInfo(update, dataBroker);
    // Remove the router from External Subnets
    removeRouterFromExternalSubnets(routerId, origExtNetId, origExtFixedIps);
    // Remove the router from the ExternalNetworks list
    InstanceIdentifier<Networks> netsIdentifier = InstanceIdentifier.builder(ExternalNetworks.class).child(Networks.class, new NetworksKey(origExtNetId)).build();
    Optional<Networks> optionalNets = null;
    try {
        optionalNets = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier);
    } catch (ReadFailedException ex) {
        LOG.error("removeExternalNetworkFromRouter: Failed to remove provider network {} from router {}", origExtNetId.getValue(), routerId.getValue(), ex);
        return;
    }
    if (!optionalNets.isPresent()) {
        LOG.error("removeExternalNetworkFromRouter: Provider Network {} not present in the NVPN datamodel", origExtNetId.getValue());
        return;
    }
    Networks nets = optionalNets.get();
    try {
        NetworksBuilder builder = new NetworksBuilder(nets);
        List<Uuid> rtrList = builder.getRouterIds();
        if (rtrList != null) {
            rtrList.remove(routerId);
            builder.setRouterIds(rtrList);
            Networks networkss = builder.build();
            SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier, networkss);
            LOG.trace("removeExternalNetworkFromRouter: Remove router {} from External Networks node {}", routerId, origExtNetId.getValue());
        }
    } catch (TransactionCommitFailedException ex) {
        LOG.error("removeExternalNetworkFromRouter: Failed to remove provider network {} from router {}", origExtNetId.getValue(), routerId.getValue(), ex);
    }
    // Remove the vpnInternetId fromSubnetmap
    Network net = neutronvpnUtils.getNeutronNetwork(nets.getId());
    List<Uuid> submapIds = neutronvpnUtils.getPrivateSubnetsToExport(net);
    for (Uuid snId : submapIds) {
        Subnetmap subnetMap = neutronvpnUtils.getSubnetmap(snId);
        if ((subnetMap == null) || (subnetMap.getInternetVpnId() == null)) {
            LOG.error("removeExternalNetworkFromRouter: Can not find Subnetmap for SubnetId {} in ConfigDS", snId.getValue());
            continue;
        }
        LOG.trace("removeExternalNetworkFromRouter: Remove Internet VPN Id {} from SubnetMap {}", subnetMap.getInternetVpnId(), subnetMap.getId());
        IpVersionChoice ipVers = NeutronvpnUtils.getIpVersionFromString(subnetMap.getSubnetIp());
        if (ipVers == IpVersionChoice.IPV6) {
            nvpnManager.updateVpnInternetForSubnet(subnetMap, subnetMap.getInternetVpnId(), false);
            LOG.debug("removeExternalNetworkFromRouter: Withdraw IPv6 routes from VPN {}", subnetMap.getInternetVpnId());
        }
    }
}
Also used : Networks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks) ExternalNetworks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks) NetworksKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksKey) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Network(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) NetworksBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksBuilder) IpVersionChoice(org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice)

Aggregations

Routers (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers)11 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)10 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)8 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)7 RoutersBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.RoutersBuilder)6 ExternalIps (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)4 ArrayList (java.util.ArrayList)3 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)3 ExternalFixedIps (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.router.external_gateway_info.ExternalFixedIps)3 Network (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network)3 BigInteger (java.math.BigInteger)2 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)2 IpVersionChoice (org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice)2 ExtRouters (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExtRouters)2 ExternalNetworks (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks)2 ProviderTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)2 Networks (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks)2 NetworksBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksBuilder)2 NetworksKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksKey)2 Inet6Address (java.net.Inet6Address)1