Search in sources :

Example 6 with NetworksBuilder

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.NetworksBuilder in project netvirt by opendaylight.

the class NeutronvpnManager method addExternalNetworkToVpn.

private boolean addExternalNetworkToVpn(Network extNet, Uuid vpnId) {
    Uuid extNetId = extNet.getUuid();
    InstanceIdentifier<Networks> extNetIdentifier = InstanceIdentifier.builder(ExternalNetworks.class).child(Networks.class, new NetworksKey(extNetId)).build();
    try {
        Optional<Networks> optionalExtNets = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, extNetIdentifier);
        if (!optionalExtNets.isPresent()) {
            LOG.error("addExternalNetworkToVpn: Provider Network {} is not present in ConfigDS", extNetId.getValue());
            return false;
        }
        NetworksBuilder builder = new NetworksBuilder(optionalExtNets.get());
        builder.setVpnid(vpnId);
        Networks networks = builder.build();
        // Add Networks object to the ExternalNetworks list
        LOG.trace("addExternalNetworkToVpn: Set VPN Id {} for Provider Network {}", vpnId.getValue(), extNetId.getValue());
        SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, extNetIdentifier, networks);
        return true;
    } catch (TransactionCommitFailedException | ReadFailedException ex) {
        LOG.error("addExternalNetworkToVpn: Failed to set VPN Id {} to Provider Network {}: ", vpnId.getValue(), extNetId.getValue(), ex);
    }
    return false;
}
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) 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) NetworksBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksBuilder)

Example 7 with NetworksBuilder

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.NetworksBuilder 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)

Example 8 with NetworksBuilder

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.NetworksBuilder in project netvirt by opendaylight.

the class NeutronvpnNatManager method addExternalNetwork.

public void addExternalNetwork(Network net) {
    Uuid extNetId = net.getUuid();
    // 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();
    try {
        LOG.trace(" Creating/Updating a new Networks node {}", extNetId.getValue());
        Optional<Networks> optionalNets = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier);
        if (optionalNets.isPresent()) {
            LOG.error("External Network {} already detected to be present", extNetId.getValue());
            return;
        }
        ProviderTypes provType = NeutronvpnUtils.getProviderNetworkType(net);
        if (provType == null) {
            LOG.error("Unable to get Network Provider Type for network {}", extNetId);
            return;
        }
        NetworksBuilder builder = null;
        builder = new NetworksBuilder().setKey(new NetworksKey(extNetId)).setId(extNetId);
        builder.setVpnid(neutronvpnUtils.getVpnForNetwork(extNetId));
        builder.setRouterIds(new ArrayList<>());
        builder.setProviderNetworkType(provType);
        Networks networkss = builder.build();
        // Add Networks object to the ExternalNetworks list
        LOG.trace("Creating externalnetworks {}", networkss);
        SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier, networkss);
        LOG.trace("Wrote externalnetwork successfully to CONFIG Datastore");
    } catch (TransactionCommitFailedException | ReadFailedException ex) {
        LOG.error("Creation of External Network {} failed", 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) NetworksKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksKey) 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) ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes) NetworksBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksBuilder)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)6 NetworksBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksBuilder)6 NetworksKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksKey)6 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)5 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)5 ExternalNetworks (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks)5 Networks (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks)5 IpVersionChoice (org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice)2 Networks (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Networks)2 NetworksBuilder (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.NetworksBuilder)2 NetworksKey (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.NetworksKey)2 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)2 ProviderTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)2 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)2 ArrayList (java.util.ArrayList)1 Mockito.doReturn (org.mockito.Mockito.doReturn)1 Ipv4FamilyBuilder (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.vpn.instance.Ipv4FamilyBuilder)1 InterfaceKey (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey)1 AllocateIdInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder)1 AllocateIdOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutputBuilder)1