Search in sources :

Example 16 with Networks

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks in project netvirt by opendaylight.

the class NeutronvpnManager method removeVpn.

public void removeVpn(Uuid id) {
    // read VPNMaps
    VpnMap vpnMap = neutronvpnUtils.getVpnMap(id);
    Uuid router = vpnMap != null ? vpnMap.getRouterId() : null;
    // dissociate router
    if (router != null) {
        dissociateRouterFromVpn(id, router);
    }
    // dissociate networks
    if (!id.equals(router) && vpnMap.getNetworkIds() != null) {
        dissociateNetworksFromVpn(id, vpnMap.getNetworkIds());
    }
    // remove entire vpnMaps node
    deleteVpnMapsNode(id);
    // remove vpn-instance
    deleteVpnInstance(id);
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap)

Example 17 with Networks

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks 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 18 with Networks

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks in project netvirt by opendaylight.

the class NeutronvpnManager method associateNetworks.

/**
 * It handles the invocations to the neutronvpn:associateNetworks RPC method.
 */
@Override
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public Future<RpcResult<AssociateNetworksOutput>> associateNetworks(AssociateNetworksInput input) {
    AssociateNetworksOutputBuilder opBuilder = new AssociateNetworksOutputBuilder();
    SettableFuture<RpcResult<AssociateNetworksOutput>> result = SettableFuture.create();
    LOG.debug("associateNetworks {}", input);
    StringBuilder returnMsg = new StringBuilder();
    Uuid vpnId = input.getVpnId();
    try {
        if (neutronvpnUtils.getVpnMap(vpnId) != null) {
            List<Uuid> netIds = input.getNetworkId();
            if (netIds != null && !netIds.isEmpty()) {
                List<String> failed = associateNetworksToVpn(vpnId, netIds);
                if (!failed.isEmpty()) {
                    returnMsg.append(failed);
                }
            }
        } else {
            returnMsg.append("VPN not found : ").append(vpnId.getValue());
        }
        if (returnMsg.length() != 0) {
            opBuilder.setResponse("ErrorType: PROTOCOL, ErrorTag: invalid-value, ErrorMessage: " + formatAndLog(LOG::error, "associate Networks to vpn {} failed due to {}", vpnId.getValue(), returnMsg));
            result.set(RpcResultBuilder.<AssociateNetworksOutput>success().withResult(opBuilder.build()).build());
        } else {
            result.set(RpcResultBuilder.<AssociateNetworksOutput>success().build());
        }
    } catch (Exception ex) {
        result.set(RpcResultBuilder.<AssociateNetworksOutput>failed().withError(ErrorType.APPLICATION, formatAndLog(LOG::error, "associate Networks to vpn {} failed due to {}", input.getVpnId().getValue(), ex.getMessage(), ex)).build());
    }
    LOG.debug("associateNetworks returns..");
    return result;
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) AssociateNetworksOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.AssociateNetworksOutput) AssociateNetworksOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.AssociateNetworksOutputBuilder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) 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 19 with Networks

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks in project netvirt by opendaylight.

the class NeutronvpnManager method createL3InternalVpn.

public void createL3InternalVpn(Uuid vpn, String name, Uuid tenant, List<String> rd, List<String> irt, List<String> ert, Uuid router, List<Uuid> networks) {
    IpVersionChoice ipVersChoices = neutronvpnUtils.getIpVersionChoicesFromRouterUuid(router);
    // Update VPN Instance node
    updateVpnInstanceNode(vpn, rd, irt, ert, VpnInstance.Type.L3, 0, /*l3vni*/
    ipVersChoices);
    // Update local vpn-subnet DS
    updateVpnMaps(vpn, name, router, tenant, networks);
    if (router != null) {
        Uuid existingVpn = neutronvpnUtils.getVpnForRouter(router, true);
        if (existingVpn != null) {
            // use case when a cluster is rebooted and router add DCN is received, triggering #createL3InternalVpn
            // if before reboot, router was already associated to VPN, should not proceed associating router to
            // internal VPN. Adding to RouterInterfacesMap is also not needed since it's a config DS and will be
            // preserved upon reboot.
            // For a non-reboot case #associateRouterToInternalVPN already takes care of adding to
            // RouterInterfacesMap via #createVPNInterface call.
            LOG.info("Associating router to Internal VPN skipped for VPN {} due to router {} already associated " + "to external VPN {}", vpn.getValue(), router.getValue(), existingVpn.getValue());
            return;
        }
        associateRouterToInternalVpn(vpn, router);
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) IpVersionChoice(org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice)

Example 20 with Networks

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks in project netvirt by opendaylight.

the class NeutronBgpvpnChangeListener method handleNetworksUpdate.

protected void handleNetworksUpdate(Uuid vpnId, List<Uuid> oldNetworks, List<Uuid> newNetworks) {
    if (newNetworks != null && !newNetworks.isEmpty()) {
        if (oldNetworks != null && !oldNetworks.isEmpty()) {
            if (oldNetworks != newNetworks) {
                Iterator<Uuid> iter = newNetworks.iterator();
                while (iter.hasNext()) {
                    Uuid net = iter.next();
                    if (oldNetworks.contains(net)) {
                        oldNetworks.remove(net);
                        iter.remove();
                    }
                }
                // clear removed networks
                if (!oldNetworks.isEmpty()) {
                    LOG.trace("Removing old networks {} ", oldNetworks);
                    nvpnManager.dissociateNetworksFromVpn(vpnId, oldNetworks);
                }
                // add new (Delta) Networks
                if (!newNetworks.isEmpty()) {
                    LOG.trace("Adding delta New networks {} ", newNetworks);
                    nvpnManager.associateNetworksToVpn(vpnId, newNetworks);
                }
            }
        } else {
            // add new Networks
            LOG.trace("Adding New networks {} ", newNetworks);
            nvpnManager.associateNetworksToVpn(vpnId, newNetworks);
        }
    } else if (oldNetworks != null && !oldNetworks.isEmpty()) {
        LOG.trace("Removing old networks {} ", oldNetworks);
        nvpnManager.dissociateNetworksFromVpn(vpnId, oldNetworks);
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)29 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)12 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)11 ExternalNetworks (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks)11 Networks (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks)11 NetworksKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksKey)10 ArrayList (java.util.ArrayList)9 BigInteger (java.math.BigInteger)7 NetworksBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksBuilder)6 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)6 Nonnull (javax.annotation.Nonnull)5 Networks (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Networks)5 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)4 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)3 HashSet (java.util.HashSet)3 ExecutionException (java.util.concurrent.ExecutionException)3 IpVersionChoice (org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice)3 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)3 InternalToExternalPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap)3 VpnMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap)3