use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.bgpvpns.rev150903.bgpvpns.attributes.bgpvpns.Bgpvpn 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.neutron.bgpvpns.rev150903.bgpvpns.attributes.bgpvpns.Bgpvpn 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.neutron.bgpvpns.rev150903.bgpvpns.attributes.bgpvpns.Bgpvpn 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.neutron.bgpvpns.rev150903.bgpvpns.attributes.bgpvpns.Bgpvpn 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());
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.bgpvpns.rev150903.bgpvpns.attributes.bgpvpns.Bgpvpn in project netvirt by opendaylight.
the class NeutronvpnManager method associateNetworksToVpn.
/**
* Parses and associates networks list with given VPN.
*
* @param vpnId Uuid of given VPN.
* @param networkList List list of network Ids (Uuid), which will be associated.
* @return list of formatted strings with detailed error messages.
*/
@NonNull
protected List<String> associateNetworksToVpn(@NonNull Uuid vpnId, @NonNull List<Uuid> networkList) {
List<String> failedNwList = new ArrayList<>();
HashSet<Uuid> passedNwList = new HashSet<>();
ConcurrentMap<Uuid, Network> extNwMap = new ConcurrentHashMap<>();
boolean isExternalNetwork = false;
if (networkList.isEmpty()) {
LOG.error("associateNetworksToVpn: Failed as given networks list is empty, VPN Id: {}", vpnId.getValue());
failedNwList.add(String.format("Failed to associate networks with VPN %s as given networks list is empty", vpnId.getValue()));
return failedNwList;
}
VpnInstance vpnInstance = VpnHelper.getVpnInstance(dataBroker, vpnId.getValue());
if (vpnInstance == null) {
LOG.error("associateNetworksToVpn: Can not find vpnInstance for VPN {} in ConfigDS", vpnId.getValue());
failedNwList.add(String.format("Failed to associate network: can not found vpnInstance for VPN %s " + "in ConfigDS", vpnId.getValue()));
return failedNwList;
}
try {
if (isVpnOfTypeL2(vpnInstance) && neutronEvpnUtils.isVpnAssociatedWithNetwork(vpnInstance)) {
LOG.error("associateNetworksToVpn: EVPN {} supports only one network to be associated with", vpnId.getValue());
failedNwList.add(String.format("Failed to associate network: EVPN %s supports only one network to be " + "associated with", vpnId.getValue()));
return failedNwList;
}
Set<VpnTarget> routeTargets = vpnManager.getRtListForVpn(vpnId.getValue());
boolean isIpFamilyUpdated = false;
IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
for (Uuid nw : networkList) {
Network network = neutronvpnUtils.getNeutronNetwork(nw);
if (network == null) {
LOG.error("associateNetworksToVpn: Network {} not found in ConfigDS", nw.getValue());
failedNwList.add(String.format("Failed to associate network: network %s not found in ConfigDS", nw.getValue()));
continue;
}
NetworkProviderExtension providerExtension = network.augmentation(NetworkProviderExtension.class);
if (providerExtension.getSegments() != null && providerExtension.getSegments().size() > 1) {
LOG.error("associateNetworksToVpn: MultiSegmented network {} not supported in BGPVPN {}", nw.getValue(), vpnId.getValue());
failedNwList.add(String.format("Failed to associate multisegmented network %s with BGPVPN %s", nw.getValue(), vpnId.getValue()));
continue;
}
Uuid networkVpnId = neutronvpnUtils.getVpnForNetwork(nw);
if (networkVpnId != null) {
LOG.error("associateNetworksToVpn: Network {} already associated with another VPN {}", nw.getValue(), networkVpnId.getValue());
failedNwList.add(String.format("Failed to associate network %s as it is already associated to " + "another VPN %s", nw.getValue(), networkVpnId.getValue()));
continue;
}
/* Handle association of external network(s) to Internet BGP-VPN use case outside of the
* networkList iteration
*/
if (neutronvpnUtils.getIsExternal(network)) {
extNwMap.put(nw, network);
isExternalNetwork = true;
// Check whether router-gw is set with external network before external network to BGPVPN association
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("associateNetworksToVpn: External network {} is already 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;
}
}
}
}
List<Subnetmap> subnetmapList = neutronvpnUtils.getSubnetmapListFromNetworkId(nw);
if (subnetmapList == null || subnetmapList.isEmpty()) {
passedNwList.add(nw);
continue;
}
if (vpnManager.checkForOverlappingSubnets(nw, subnetmapList, vpnId, routeTargets, failedNwList)) {
continue;
}
for (Subnetmap subnetmap : subnetmapList) {
IpVersionChoice ipVers = NeutronvpnUtils.getIpVersionFromString(subnetmap.getSubnetIp());
if (!ipVersion.isIpVersionChosen(ipVers)) {
ipVersion = ipVersion.addVersion(ipVers);
}
}
// Update vpnInstance for IP address family
if (ipVersion != IpVersionChoice.UNDEFINED && !isIpFamilyUpdated) {
LOG.debug("associateNetworksToVpn: Updating vpnInstance with ip address family {}" + " for VPN {} ", ipVersion, vpnId);
neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), ipVersion, true);
isIpFamilyUpdated = true;
}
for (Subnetmap subnetmap : subnetmapList) {
Uuid subnetId = subnetmap.getId();
Uuid subnetVpnId = neutronvpnUtils.getVpnForSubnet(subnetId);
if (subnetVpnId != null) {
LOG.error("associateNetworksToVpn: Failed to associate subnet {} with VPN {}" + " as it is already associated", subnetId.getValue(), subnetVpnId.getValue());
failedNwList.add(String.format("Failed to associate subnet %s with VPN %s" + " as it is already associated", subnetId.getValue(), vpnId.getValue()));
continue;
}
if (!NeutronvpnUtils.getIsExternal(network)) {
LOG.debug("associateNetworksToVpn: Add subnet {} to VPN {}", subnetId.getValue(), vpnId.getValue());
addSubnetToVpn(vpnId, subnetId, null);
vpnManager.updateRouteTargetsToSubnetAssociation(routeTargets, subnetmap.getSubnetIp(), vpnId.getValue());
passedNwList.add(nw);
}
}
passedNwList.add(nw);
// Handle association of external network(s) to Internet BGP-VPN Instance use case
if (!extNwMap.isEmpty() || extNwMap != null) {
for (Network extNw : extNwMap.values()) {
if (!associateExtNetworkToVpn(vpnId, extNw, vpnInstance.getBgpvpnType())) {
LOG.error("associateNetworksToVpn: Failed to associate Provider External Network {} with " + "VPN {}", extNw, vpnId.getValue());
failedNwList.add(String.format("Failed to associate Provider External Network %s with " + "VPN %s", extNw, vpnId.getValue()));
continue;
}
}
}
}
} catch (ExecutionException | InterruptedException e) {
LOG.error("associateNetworksToVpn: Failed to associate VPN {} with networks {}: ", vpnId.getValue(), networkList, e);
failedNwList.add(String.format("Failed to associate VPN %s with networks %s: %s", vpnId.getValue(), networkList, e));
}
// VpnMap update for ext-nw is already done in associateExtNetworkToVpn() method.
if (!isExternalNetwork) {
updateVpnMaps(vpnId, null, null, null, new ArrayList<>(passedNwList));
}
LOG.info("Network(s) {} associated to L3VPN {} successfully", passedNwList, vpnId.getValue());
return failedNwList;
}
Aggregations