use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.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);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.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;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.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;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.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);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.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);
}
}
Aggregations