use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance 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 networkList 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> networkList) {
List<String> failedNwList = new ArrayList<>();
HashSet<Uuid> passedNwList = new HashSet<>();
ConcurrentMap<Uuid, Network> extNwMap = new ConcurrentHashMap<>();
IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
if (networkList.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 : networkList) {
List<Uuid> networkSubnets = neutronvpnUtils.getSubnetIdsFromNetworkId(nw);
if (networkSubnets == null) {
passedNwList.add(nw);
continue;
}
Network network = neutronvpnUtils.getNeutronNetwork(nw);
if (network == null) {
LOG.error("dissociateNetworksFromVpn: Network {} not found in ConfigDS", nw.getValue());
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;
}
/* Handle disassociation of external network(s) from Internet BGP-VPN use case outside of the
* networkList iteration
*/
if (neutronvpnUtils.getIsExternal(network)) {
extNwMap.put(nw, network);
// Handle external-Nw to BGPVPN Disassociation and still ext-router is being set with external-Nw
List<Uuid> routerList = neutronvpnUtils.getRouterIdsForExtNetwork(nw);
if (!routerList.isEmpty()) {
for (Uuid routerId : routerList) {
// If v6 subnet was already added to router means it requires IPv6 AddrFamily in VpnInstance
if (neutronvpnUtils.isV6SubnetPartOfRouter(routerId)) {
ipVersion = ipVersion.addVersion(IpVersionChoice.IPV6);
LOG.debug("dissociateNetworksFromVpn: External network {} is still associated with " + "router(router-gw) {} and V6 subnet is part of that router. Hence Set IPv6 " + "address family type in Internet VPN Instance {}", network, routerId, vpnId);
break;
}
}
}
}
for (Uuid subnet : networkSubnets) {
Subnetmap subnetmap = neutronvpnUtils.getSubnetmap(subnet);
if (subnetmap == null) {
failedNwList.add(String.format("subnetmap %s not found for network %s", subnet.getValue(), nw.getValue()));
LOG.error("dissociateNetworksFromVpn: Subnetmap for subnet {} not found when " + "dissociating network {} from VPN {}", subnet.getValue(), nw.getValue(), vpnId.getValue());
continue;
}
IpVersionChoice ipVers = NeutronvpnUtils.getIpVersionFromString(subnetmap.getSubnetIp());
if (!ipVersion.isIpVersionChosen(ipVers)) {
ipVersion = ipVersion.addVersion(ipVers);
}
if (!NeutronvpnUtils.getIsExternal(network)) {
LOG.debug("dissociateNetworksFromVpn: Withdraw subnet {} from VPN {}", subnet.getValue(), vpnId.getValue());
removeSubnetFromVpn(vpnId, subnetmap, null);
Set<VpnTarget> routeTargets = vpnManager.getRtListForVpn(vpnId.getValue());
vpnManager.removeRouteTargetsToSubnetAssociation(routeTargets, subnetmap.getSubnetIp(), vpnId.getValue());
passedNwList.add(nw);
}
}
if (ipVersion != IpVersionChoice.UNDEFINED) {
LOG.debug("dissociateNetworksFromVpn: Updating vpnInstance with ip address family {}" + " for VPN {}", ipVersion, vpnId);
neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), ipVersion, false);
}
}
// Handle disassociation of external network(s) from Internet BGP-VPN Instance use case
if (!extNwMap.isEmpty() || extNwMap != null) {
for (Network extNw : extNwMap.values()) {
if (disassociateExtNetworkFromVpn(vpnId, extNw)) {
passedNwList.add(extNw.getUuid());
} else {
LOG.error("dissociateNetworksFromVpn: Failed to withdraw External Provider Network {} from VPN {}", extNw, vpnId.getValue());
failedNwList.add(String.format("Failed to withdraw External Provider Network %s from VPN %s", extNw, vpnId.getValue()));
continue;
}
}
}
clearFromVpnMaps(vpnId, null, new ArrayList<>(passedNwList));
LOG.info("dissociateNetworksFromVpn: Network(s) {} disassociated from L3VPN {} successfully", passedNwList, vpnId.getValue());
return failedNwList;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance in project netvirt by opendaylight.
the class NeutronBgpvpnRouterAssociationChangeListener method remove.
@Override
public void remove(InstanceIdentifier<BgpvpnRouterAssociation> identifier, BgpvpnRouterAssociation input) {
LOG.trace("Removing Bgpvpn router association : key: {}, value={}", identifier, input);
Uuid vpnId = input.getBgpvpnId();
String vpnName = vpnId.getValue();
Uuid routerId = input.getRouterId();
NamedLocks<String> vpnLock = neutronBgpvpnUtils.getVpnLock();
try (AcquireResult lock = vpnLock.tryAcquire(vpnName, NeutronConstants.LOCK_WAIT_TIME, TimeUnit.SECONDS)) {
if (!lock.wasAcquired()) {
LOG.error("Remove router association: remove association failed for vpn : {} and routerId: {} due" + " to failure in acquiring lock", vpnName, routerId.getValue());
return;
}
neutronBgpvpnUtils.removeUnProcessedRouter(vpnId, routerId);
VpnInstance vpnInstance = neutronvpnUtils.getVpnInstance(vpnId);
if (vpnInstance != null) {
nvpnManager.dissociateRouterFromVpn(vpnId, routerId);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance in project netvirt by opendaylight.
the class NeutronBgpvpnRouterAssociationChangeListener method add.
@Override
public void add(InstanceIdentifier<BgpvpnRouterAssociation> identifier, BgpvpnRouterAssociation input) {
LOG.trace("Adding Bgpvpn router association : key: {}, value={}", identifier, input);
Uuid vpnId = input.getBgpvpnId();
String vpnName = vpnId.getValue();
Uuid routerId = input.getRouterId();
NamedLocks<String> vpnLock = neutronBgpvpnUtils.getVpnLock();
try (AcquireResult lock = vpnLock.tryAcquire(vpnName, NeutronConstants.LOCK_WAIT_TIME, TimeUnit.SECONDS)) {
if (!lock.wasAcquired()) {
LOG.error("Add router association: add association failed for vpn : {} and routerId: {} due to " + "failure in acquiring lock", vpnName, routerId.getValue());
return;
}
VpnInstance vpnInstance = neutronvpnUtils.getVpnInstance(vpnId);
if (vpnInstance != null) {
if (validateRouteInfo(routerId, vpnId)) {
nvpnManager.associateRouterToVpn(vpnId, routerId);
}
} else {
neutronBgpvpnUtils.addUnProcessedRouter(vpnId, routerId);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance in project netvirt by opendaylight.
the class NeutronBgpvpnNetworkAssociationChangeListener method add.
@Override
public void add(InstanceIdentifier<BgpvpnNetworkAssociation> identifier, BgpvpnNetworkAssociation input) {
LOG.trace("Adding Bgpvpn network association : key: {}, value={}", identifier, input);
Uuid vpnId = input.getBgpvpnId();
String vpnName = vpnId.getValue();
Uuid networkId = input.getNetworkId();
List<Uuid> networks = new ArrayList<>();
networks.add(networkId);
NamedLocks<String> vpnLock = neutronBgpvpnUtils.getVpnLock();
try (AcquireResult lock = vpnLock.tryAcquire(vpnName, NeutronConstants.LOCK_WAIT_TIME, TimeUnit.SECONDS)) {
if (!lock.wasAcquired()) {
LOG.error("Add network association: add association failed for vpn : {} and networkId: {} due to " + "failure in acquiring lock", vpnName, networkId.getValue());
return;
}
VpnInstance vpnInstance = neutronvpnUtils.getVpnInstance(vpnId);
if (vpnInstance != null) {
List<String> errorMessages = nvpnManager.associateNetworksToVpn(vpnId, networks);
if (!errorMessages.isEmpty()) {
LOG.error("BgpvpnNetworkAssociation add: associate network id {} to vpn {} failed due to {}", networkId.getValue(), vpnId.getValue(), errorMessages);
}
} else {
neutronBgpvpnUtils.addUnProcessedNetwork(vpnId, networkId);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance in project netvirt by opendaylight.
the class NeutronvpnManager method checkAlarmExtraRoutes.
/**
* This method setup or down an alarm about extra route fault.
* When extra routes are configured, through a router, if the number of nexthops is greater than the number of
* available RDs, then an alarm and an error is generated.<br>
* <b>Be careful</b> the routeList could be changed.
*
* @param vpnId the vpnId of vpn to control.
* @param routeList the list of router to check, it could be modified.
*/
private void checkAlarmExtraRoutes(Uuid vpnId, List<Routes> routeList) {
if (!neutronvpnAlarm.isAlarmEnabled()) {
LOG.debug("checkAlarmExtraRoutes is not enable for vpnId {} routeList {}", vpnId, routeList);
return;
}
VpnInstance vpnInstance = neutronvpnUtils.getVpnInstance(vpnId);
if (vpnInstance == null || routeList == null || routeList.isEmpty() || !neutronvpnAlarm.isAlarmEnabled()) {
LOG.debug("checkAlarmExtraRoutes have args null as following : vpnId {} routeList {}", vpnId, routeList);
return;
}
String primaryRd = neutronvpnUtils.getVpnRd(vpnId.getValue());
if (primaryRd == null || primaryRd.equals(vpnId.getValue())) {
LOG.debug("checkAlarmExtraRoutes. vpn {} is not a BGPVPN. cancel checkExtraRoute", vpnId);
return;
}
for (Routes route : routeList) {
// count the number of nexthops for each same route.getDestingation().getValue()
String destination = route.getDestination().stringValue();
String nextHop = route.getNexthop().stringValue();
List<String> nextHopList = new ArrayList<>();
nextHopList.add(nextHop);
int nbNextHops = 1;
for (Routes routeTmp : routeList) {
String routeDest = routeTmp.getDestination().stringValue();
if (!destination.equals(routeDest)) {
continue;
}
String routeNextH = routeTmp.getNexthop().stringValue();
if (nextHop.equals(routeNextH)) {
continue;
}
nbNextHops++;
nextHopList.add(routeTmp.getNexthop().stringValue());
}
final List<String> rdList = new ArrayList<>();
if (vpnInstance != null && vpnInstance.getRouteDistinguisher() != null) {
vpnInstance.getRouteDistinguisher().forEach(rd -> {
if (rd != null) {
rdList.add(rd);
}
});
}
// 1. VPN Instance Name
String typeAlarm = "for vpnId: " + vpnId + " have exceeded next hops for prefixe";
// 2. Router ID
List<Uuid> routerUuidList = neutronvpnUtils.getRouterIdListforVpn(vpnId);
Uuid routerUuid = routerUuidList.get(0);
StringBuilder detailsAlarm = new StringBuilder("routerUuid: ");
detailsAlarm.append(routerUuid == null ? vpnId.toString() : routerUuid.getValue());
// 3. List of RDs associated with the VPN
detailsAlarm.append(" List of RDs associated with the VPN: ");
for (String s : rdList) {
detailsAlarm.append(s);
detailsAlarm.append(", ");
}
// 4. Prefix in question
detailsAlarm.append(" for prefix: ");
detailsAlarm.append(route.getDestination().stringValue());
// 5. List of NHs for the prefix
detailsAlarm.append(" for nextHops: ");
for (String s : nextHopList) {
detailsAlarm.append(s);
detailsAlarm.append(", ");
}
if (rdList.size() < nbNextHops) {
neutronvpnAlarm.raiseNeutronvpnAlarm(typeAlarm, detailsAlarm.toString());
} else {
neutronvpnAlarm.clearNeutronvpnAlarm(typeAlarm, detailsAlarm.toString());
}
}
}
Aggregations