Search in sources :

Example 71 with Router

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router in project netvirt by opendaylight.

the class NeutronvpnNatManager method externalFixedIpsChanged.

private boolean externalFixedIpsChanged(Router orig, Router update) {
    ExternalGatewayInfo origExtGw = null;
    ExternalGatewayInfo newExtGw = null;
    if (orig != null && orig.getExternalGatewayInfo() != null) {
        origExtGw = orig.getExternalGatewayInfo();
    }
    if (update != null && update.getExternalGatewayInfo() != null) {
        newExtGw = update.getExternalGatewayInfo();
    }
    if (origExtGw == null && newExtGw != null && newExtGw.getExternalFixedIps() != null && !newExtGw.getExternalFixedIps().isEmpty()) {
        return true;
    }
    if (newExtGw == null && origExtGw != null && origExtGw.getExternalFixedIps() != null && !origExtGw.getExternalFixedIps().isEmpty()) {
        return true;
    }
    if (origExtGw != null && newExtGw != null) {
        if (origExtGw.getExternalFixedIps() != null) {
            if (!origExtGw.getExternalFixedIps().isEmpty()) {
                if (newExtGw.getExternalFixedIps() != null && !newExtGw.getExternalFixedIps().isEmpty()) {
                    List<ExternalFixedIps> origExtFixedIps = origExtGw.getExternalFixedIps();
                    HashSet<String> origFixedIpSet = new HashSet<>();
                    for (ExternalFixedIps fixedIps : origExtFixedIps) {
                        origFixedIpSet.add(fixedIps.getIpAddress().getIpv4Address().getValue());
                    }
                    List<ExternalFixedIps> newExtFixedIps = newExtGw.getExternalFixedIps();
                    HashSet<String> updFixedIpSet = new HashSet<>();
                    for (ExternalFixedIps fixedIps : newExtFixedIps) {
                        updFixedIpSet.add(fixedIps.getIpAddress().getIpv4Address().getValue());
                    }
                    // returns true if external subnets have changed
                    return !origFixedIpSet.equals(updFixedIpSet) ? true : false;
                }
                return true;
            } else if (newExtGw.getExternalFixedIps() != null && !newExtGw.getExternalFixedIps().isEmpty()) {
                return true;
            }
        } else if (newExtGw.getExternalFixedIps() != null && !newExtGw.getExternalFixedIps().isEmpty()) {
            return true;
        }
    }
    return false;
}
Also used : ExternalFixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.router.external_gateway_info.ExternalFixedIps) ExternalGatewayInfo(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.router.ExternalGatewayInfo) HashSet(java.util.HashSet)

Example 72 with Router

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router in project netvirt by opendaylight.

the class NeutronvpnNatManager method handleSnatSettingChangeForRouter.

private void handleSnatSettingChangeForRouter(Router update) {
    Uuid routerId = update.getUuid();
    InstanceIdentifier<Routers> routersIdentifier = NeutronvpnUtils.buildExtRoutersIdentifier(routerId);
    try {
        Optional<Routers> optionalRouters = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier);
        LOG.trace("Updating Internal subnets for Routers node: {}", routerId.getValue());
        RoutersBuilder builder = null;
        if (optionalRouters.isPresent()) {
            builder = new RoutersBuilder(optionalRouters.get());
        } else {
            LOG.trace("No Routers element found for router name {}", routerId.getValue());
            return;
        }
        builder.setEnableSnat(update.getExternalGatewayInfo().isEnableSnat());
        Routers routerss = builder.build();
        // Add Routers object to the ExtRouters list
        LOG.trace("Updating extrouters for snat change {}", routerss);
        SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier, routerss);
        LOG.trace("Updated successfully Routers to CONFIG Datastore");
    } catch (TransactionCommitFailedException | ReadFailedException ex) {
        LOG.error("Updation of snat for extrouters failed for router {}", routerId.getValue(), ex);
    }
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) 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) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers)

Example 73 with Router

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router in project netvirt by opendaylight.

the class NeutronvpnNatManager method addExternalNetworkToRouter.

private void addExternalNetworkToRouter(Router update) {
    Uuid routerId = update.getUuid();
    Uuid extNetId = update.getExternalGatewayInfo().getExternalNetworkId();
    List<ExternalFixedIps> externalFixedIps = update.getExternalGatewayInfo().getExternalFixedIps();
    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;
        }
        // Add this router to the ExtRouters list
        addExternalRouter(update);
        // Update External Subnets for this router
        updateExternalSubnetsForRouter(routerId, extNetId, externalFixedIps);
        // Create and add Networks object for this External Network to the ExternalNetworks list
        InstanceIdentifier<Networks> netsIdentifier = InstanceIdentifier.builder(ExternalNetworks.class).child(Networks.class, new NetworksKey(extNetId)).build();
        Optional<Networks> optionalNets = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier);
        if (!optionalNets.isPresent()) {
            LOG.error("External Network {} not present in the NVPN datamodel", extNetId.getValue());
            return;
        }
        NetworksBuilder builder = new NetworksBuilder(optionalNets.get());
        List<Uuid> rtrList = builder.getRouterIds();
        if (rtrList == null) {
            rtrList = new ArrayList<>();
        }
        rtrList.add(routerId);
        builder.setRouterIds(rtrList);
        if (NeutronvpnUtils.isFlatOrVlanNetwork(input)) {
            builder.setVpnid(extNetId);
        }
        Networks networkss = builder.build();
        // Add Networks object to the ExternalNetworks list
        LOG.trace("Updating externalnetworks {}", networkss);
        SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier, networkss);
        LOG.trace("Updated externalnetworks successfully to CONFIG Datastore");
        // get vpn external form this network external to setup vpnInternet for ipv6
        Uuid vpnExternal = neutronvpnUtils.getVpnForNetwork(extNetId);
        if (vpnExternal == null) {
            LOG.debug("addExternalNetworkToRouter : no vpnExternal for Network {}", extNetId);
        }
        LOG.debug("addExternalNetworkToRouter : the vpnExternal {}", vpnExternal);
        // get subnetmap associate to the router, any subnetmap "external" could be existing
        List<Subnetmap> snList = neutronvpnUtils.getNeutronRouterSubnetMaps(routerId);
        LOG.debug("addExternalNetworkToRouter : the vpnExternal {} subnetmap to be set with vpnInternet {}", vpnExternal, snList);
        for (Subnetmap sn : snList) {
            if (sn.getInternetVpnId() == null) {
                continue;
            }
            IpVersionChoice ipVers = neutronvpnUtils.getIpVersionFromString(sn.getSubnetIp());
            if (ipVers == IpVersionChoice.IPV6) {
                LOG.debug("addExternalNetworkToRouter : setup vpnInternet IPv6 for vpnExternal {} subnetmap {}", vpnExternal, sn);
                nvpnManager.updateVpnInternetForSubnet(sn, vpnExternal, true);
            }
        }
    } catch (TransactionCommitFailedException | ReadFailedException ex) {
        LOG.error("Creation of externalnetworks failed for {}", extNetId.getValue(), ex);
    }
}
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) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) ExternalFixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.router.external_gateway_info.ExternalFixedIps) NetworksKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksKey) 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) NetworksBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksBuilder) IpVersionChoice(org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice)

Example 74 with Router

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router in project netvirt by opendaylight.

the class NeutronvpnNatManager method handleSubnetsForExternalRouter.

public void handleSubnetsForExternalRouter(Uuid routerId) {
    InstanceIdentifier<Routers> routersIdentifier = NeutronvpnUtils.buildExtRoutersIdentifier(routerId);
    try {
        Optional<Routers> optionalRouters = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier);
        LOG.trace("Updating Internal subnets for Routers node: {}", routerId.getValue());
        RoutersBuilder builder = null;
        if (optionalRouters.isPresent()) {
            builder = new RoutersBuilder(optionalRouters.get());
        } else {
            LOG.debug("No Routers element found for router {}", routerId.getValue());
            return;
        }
        List<Uuid> subList = neutronvpnUtils.getNeutronRouterSubnetIds(routerId);
        builder.setSubnetIds(subList);
        Routers routerss = builder.build();
        // Add Routers object to the ExtRouters list
        LOG.trace("Updating extrouters {}", routerss);
        SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier, routerss);
        LOG.trace("Updated successfully Routers to CONFIG Datastore");
    } catch (TransactionCommitFailedException | ReadFailedException ex) {
        LOG.error("Updation of internal subnets for extrouters failed for router {}", routerId.getValue(), ex);
    }
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) RoutersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.RoutersBuilder) 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)

Example 75 with Router

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router in project netvirt by opendaylight.

the class NeutronvpnUtils method getIpVersionChoicesFromRouterUuid.

/**
 * Method to get an ipVersionChosen as IPV4 and/or IPV6 or undefined from the subnetmaps of the router.
 * @param routerUuid the Uuid for which find out the IP version associated
 * @return an IpVersionChoice used by the router from its attached subnetmaps. IpVersionChoice.UNDEFINED if any
 */
public IpVersionChoice getIpVersionChoicesFromRouterUuid(Uuid routerUuid) {
    IpVersionChoice rep = IpVersionChoice.UNDEFINED;
    if (routerUuid == null) {
        return rep;
    }
    List<Subnetmap> subnetmapList = getNeutronRouterSubnetMaps(routerUuid);
    if (subnetmapList.isEmpty()) {
        return rep;
    }
    for (Subnetmap sn : subnetmapList) {
        if (sn.getSubnetIp() != null) {
            IpVersionChoice ipVers = getIpVersionFromString(sn.getSubnetIp());
            if (rep.choice != ipVers.choice) {
                rep = rep.addVersion(ipVers);
            }
            if (rep.choice == IpVersionChoice.IPV4AND6.choice) {
                return rep;
            }
        }
    }
    return rep;
}
Also used : Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) IpVersionChoice(org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)93 BigInteger (java.math.BigInteger)60 ArrayList (java.util.ArrayList)46 ExecutionException (java.util.concurrent.ExecutionException)27 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)24 Routers (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers)24 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)23 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)21 ProviderTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)20 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)20 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)19 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)15 ExternalIps (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)14 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)13 UnknownHostException (java.net.UnknownHostException)12 Instruction (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction)12 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)11 RouterPorts (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts)11 List (java.util.List)10 InternalToExternalPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap)10