Search in sources :

Example 51 with Network

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.dhcp_allocation_pool.rev161214.dhcp_allocation_pool.Network in project netvirt by opendaylight.

the class NeutronvpnManager method removeExternalVpnInterfaces.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
protected void removeExternalVpnInterfaces(Uuid extNetId) {
    Collection<String> extElanInterfaces = elanService.getExternalElanInterfaces(extNetId.getValue());
    if (extElanInterfaces == null || extElanInterfaces.isEmpty()) {
        LOG.error("No external ports attached for external network {}", extNetId.getValue());
        return;
    }
    try {
        WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
        for (String elanInterface : extElanInterfaces) {
            InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(elanInterface);
            LOG.info("Removing vpn interface {}", elanInterface);
            wrtConfigTxn.delete(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
        }
        wrtConfigTxn.submit();
    } catch (Exception ex) {
        LOG.error("Removal of vpninterfaces {} failed", extElanInterfaces, ex);
    }
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) VpnInterface(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) ExecutionException(java.util.concurrent.ExecutionException) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)

Example 52 with Network

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.dhcp_allocation_pool.rev161214.dhcp_allocation_pool.Network in project netvirt by opendaylight.

the class NeutronvpnManager method dissociateNetworksFromVpn.

/**
 * Parses and disassociates networks list from given VPN.
 *
 * @param vpnId Uuid of given VPN.
 * @param networks List list of network Ids (Uuid), which will be disassociated.
 * @return list of formatted strings with detailed error messages.
 */
@Nonnull
protected List<String> dissociateNetworksFromVpn(@Nonnull Uuid vpnId, @Nonnull List<Uuid> networks) {
    List<String> failedNwList = new ArrayList<>();
    HashSet<Uuid> passedNwList = new HashSet<>();
    if (networks.isEmpty()) {
        LOG.error("dissociateNetworksFromVpn: Failed as networks list is empty");
        failedNwList.add(String.format("Failed to disassociate networks from VPN %s as networks list is empty", vpnId.getValue()));
        return failedNwList;
    }
    for (Uuid nw : networks) {
        Network network = neutronvpnUtils.getNeutronNetwork(nw);
        if (network == null) {
            LOG.error("dissociateNetworksFromVpn: Network {} not found in ConfigDS");
            failedNwList.add(String.format("Failed to disassociate network %s as is not found in ConfigDS", nw.getValue()));
            continue;
        }
        Uuid networkVpnId = neutronvpnUtils.getVpnForNetwork(nw);
        if (networkVpnId == null) {
            LOG.error("dissociateNetworksFromVpn: Network {} is not associated to any VPN", nw.getValue());
            failedNwList.add(String.format("Failed to disassociate network %s as is not associated to any VPN", nw.getValue()));
            continue;
        }
        if (!vpnId.equals(networkVpnId)) {
            LOG.error("dissociateNetworksFromVpn: Network {} is associated to another VPN {} instead of given {}", nw.getValue(), networkVpnId.getValue(), vpnId.getValue());
            failedNwList.add(String.format("Failed to disassociate network %s as it is associated to another " + "vpn %s instead of given %s", nw.getValue(), networkVpnId.getValue(), vpnId.getValue()));
            continue;
        }
        if (neutronvpnUtils.getIsExternal(network)) {
            if (disassociateExtNetworkFromVpn(vpnId, network)) {
                passedNwList.add(nw);
                continue;
            } else {
                LOG.error("dissociateNetworksFromVpn: Failed to withdraw Provider Network {} from VPN {}", nw.getValue(), vpnId.getValue());
                failedNwList.add(String.format("Failed to withdraw Provider Network %s from VPN %s", nw.getValue(), vpnId.getValue()));
                continue;
            }
        }
        List<Uuid> networkSubnets = neutronvpnUtils.getSubnetIdsFromNetworkId(nw);
        if (networkSubnets == null) {
            passedNwList.add(nw);
            continue;
        }
        for (Uuid subnet : networkSubnets) {
            Subnetmap sm = neutronvpnUtils.getSubnetmap(subnet);
            if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToRemove(sm, vpnId)) {
                IpVersionChoice ipVersionsToRemove = IpVersionChoice.UNDEFINED;
                IpVersionChoice ipVersion = neutronvpnUtils.getIpVersionFromString(sm.getSubnetIp());
                neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), ipVersionsToRemove.addVersion(ipVersion), false);
            }
            LOG.debug("dissociateNetworksFromVpn: Withdraw subnet {} from VPN {}", subnet.getValue(), vpnId.getValue());
            removeSubnetFromVpn(vpnId, subnet, null);
            passedNwList.add(nw);
        }
    }
    LOG.info("dissociateNetworksFromVpn: Withdraw networks list {} from VPN {}", networks.toString(), vpnId.getValue());
    clearFromVpnMaps(vpnId, null, new ArrayList<Uuid>(passedNwList));
    return failedNwList;
}
Also used : 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) ArrayList(java.util.ArrayList) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) HashSet(java.util.HashSet) IpVersionChoice(org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice) Nonnull(javax.annotation.Nonnull)

Example 53 with Network

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.dhcp_allocation_pool.rev161214.dhcp_allocation_pool.Network in project netvirt by opendaylight.

the class NeutronExternalSubnetHandler method handleExternalSubnetRemoved.

public void handleExternalSubnetRemoved(Network network, Uuid subnetId) {
    Uuid networkId = network.getUuid();
    if (NeutronvpnUtils.getIsExternal(network) && NeutronvpnUtils.isFlatOrVlanNetwork(network)) {
        LOG.info("Removed subnet {} part of external network {} will remove NAT external subnet", subnetId.getValue(), networkId.getValue());
        nvpnManager.removeVpnInstanceForSubnet(subnetId);
        nvpnNatManager.removeExternalSubnet(subnetId);
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)

Example 54 with Network

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.dhcp_allocation_pool.rev161214.dhcp_allocation_pool.Network in project netvirt by opendaylight.

the class NeutronExternalSubnetHandler method handleExternalSubnetAdded.

public void handleExternalSubnetAdded(Network network, Uuid subnetId, List<Uuid> routerIds) {
    Uuid networkId = network.getUuid();
    if (NeutronvpnUtils.getIsExternal(network) && NeutronvpnUtils.isFlatOrVlanNetwork(network)) {
        LOG.info("Added external subnet {} part of external network {} will create NAT external subnet", subnetId.getValue(), networkId.getValue());
        nvpnNatManager.updateOrAddExternalSubnet(networkId, subnetId, routerIds);
        nvpnManager.updateSubnetNode(subnetId, null, /* routerId */
        subnetId, null);
        nvpnManager.createVpnInstanceForSubnet(subnetId);
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)

Example 55 with Network

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.dhcp_allocation_pool.rev161214.dhcp_allocation_pool.Network in project netvirt by opendaylight.

the class NeutronNetworkChangeListener method createElanInstance.

private ElanInstance createElanInstance(Network input) {
    String elanInstanceName = input.getUuid().getValue();
    InstanceIdentifier<ElanInstance> id = createElanInstanceIdentifier(elanInstanceName);
    Optional<ElanInstance> existingElanInstance = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
    if (existingElanInstance.isPresent()) {
        return existingElanInstance.get();
    }
    Class<? extends SegmentTypeBase> segmentType = NeutronvpnUtils.getSegmentTypeFromNeutronNetwork(input);
    String segmentationId = NeutronvpnUtils.getSegmentationIdFromNeutronNetwork(input);
    String physicalNetworkName = NeutronvpnUtils.getPhysicalNetworkName(input);
    long elanTag = elanService.retrieveNewElanTag(elanInstanceName);
    ElanInstance elanInstance = createElanInstanceBuilder(elanInstanceName, segmentType, segmentationId, physicalNetworkName, input).setElanTag(elanTag).build();
    MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, elanInstance);
    LOG.debug("ELANInstance {} created with elan tag {} and segmentation ID {}", elanInstanceName, elanTag, segmentationId);
    return elanInstance;
}
Also used : ElanInstance(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)93 ArrayList (java.util.ArrayList)46 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)33 BigInteger (java.math.BigInteger)31 Network (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network)31 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)26 ProviderTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)19 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)19 Port (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port)19 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)17 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)15 ElanInstance (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance)12 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)11 ExecutionException (java.util.concurrent.ExecutionException)10 ExternalNetworks (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks)10 Networks (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks)10 QosPolicy (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.qos.rev160613.qos.attributes.qos.policies.QosPolicy)10 Routers (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers)9 HashSet (java.util.HashSet)8 Nonnull (javax.annotation.Nonnull)8