}
if (portIsIpv6) {
listVpnIds.add(internetVpnId);
- if (neutronvpnUtils.shouldVpnHandleIpVersionChoiceChangeToAdd(
- IpVersionChoice.IPV6, internetVpnId)) {
- neutronvpnUtils.updateVpnInstanceWithIpFamily(internetVpnId.getValue(),
- IpVersionChoice.IPV6, true);
+ if (neutronvpnUtils.shouldVpnHandleIpVersionChoiceChange(
+ IpVersionChoice.IPV6, routerId, true)) {
+ neutronvpnUtils.updateVpnInstanceWithIpFamily(internetVpnId.getValue(), IpVersionChoice.IPV6,
+ true);
neutronvpnUtils.updateVpnInstanceWithFallback(internetVpnId.getValue(), true);
}
}
if (! subnetMapList.isEmpty()) {
nvpnManager.createVpnInterface(listVpnIds, routerPort, null);
}
+ IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
for (FixedIps portIP : routerPort.getFixedIps()) {
String ipValue = portIP.getIpAddress().stringValue();
- IpVersionChoice version = NeutronvpnUtils.getIpVersionFromString(ipValue);
- if (neutronvpnUtils.shouldVpnHandleIpVersionChoiceChangeToAdd(version, vpnId)) {
- neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(),
- version, true);
- }
- if (version.isIpVersionChosen(IpVersionChoice.IPV4)) {
+ ipVersion = NeutronvpnUtils.getIpVersionFromString(ipValue);
+ if (ipVersion.isIpVersionChosen(IpVersionChoice.IPV4)) {
nvpnManager.addSubnetToVpn(vpnId, portIP.getSubnetId(),
null /* internet-vpn-id */);
} else {
ipValue, routerPort.getMacAddress(),
routerPort.getUuid().getValue(), vpnId.getValue());
}
+ if (neutronvpnUtils.shouldVpnHandleIpVersionChoiceChange(ipVersion, routerId, true)) {
+ LOG.debug("vpnInstanceOpDataEntry is getting update with ip address family {} for VPN {}",
+ ipVersion, vpnId.getValue());
+ neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), ipVersion, true);
+ }
nvpnManager.addToNeutronRouterInterfacesMap(routerId, routerPort.getUuid().getValue());
jobCoordinator.enqueueJob(routerId.toString(), () -> {
nvpnNatManager.handleSubnetsForExternalRouter(routerId);
// update RouterInterfaces map
ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
confTx -> {
- boolean vpnInstanceIpVersionRemoved = false;
- IpVersionChoice vpnInstanceIpVersionToRemove = IpVersionChoice.UNDEFINED;
+ IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
for (FixedIps portIP : portIps) {
Subnetmap sn = neutronvpnUtils.getSubnetmap(portIP.getSubnetId());
// router Port have either IPv4 or IPv6, never both
- if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToRemove(sn, vpnId)) {
- vpnInstanceIpVersionRemoved = true;
- vpnInstanceIpVersionToRemove = NeutronvpnUtils.getIpVersionFromString(sn.getSubnetIp());
- }
+ ipVersion = neutronvpnUtils.getIpVersionFromString(sn.getSubnetIp());
String ipValue = portIP.getIpAddress().stringValue();
neutronvpnUtils.removeVpnPortFixedIpToPort(vpnId.getValue(), ipValue, confTx);
// NOTE: Please donot change the order of calls to removeSubnetFromVpn and
// and updateSubnetNodeWithFixedIP
- nvpnManager.removeSubnetFromVpn(vpnId, portIP.getSubnetId(),
- sn != null ? sn.getInternetVpnId() : null);
+ nvpnManager.removeSubnetFromVpn(vpnId, portIP.getSubnetId(), sn.getInternetVpnId());
nvpnManager.updateSubnetNodeWithFixedIp(portIP.getSubnetId(), null, null,
null, null, null);
}
nvpnNatManager.handleSubnetsForExternalRouter(routerId);
return Collections.emptyList();
});
- if (vpnInstanceIpVersionRemoved) {
- neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), vpnInstanceIpVersionToRemove,
- false);
+ if (neutronvpnUtils.shouldVpnHandleIpVersionChoiceChange(ipVersion, routerId, false)) {
+ LOG.debug("vpnInstanceOpDataEntry is getting update with ip address family {} for VPN {}",
+ ipVersion, vpnId.getValue());
+ neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), ipVersion, false);
}
}), LOG, "Error handling interface removal");
if (vpnInstanceInternetIpVersionRemoved) {
- neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnInstanceInternetUuid.getValue(),
- IpVersionChoice.IPV6, false);
+ neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnInstanceInternetUuid.getValue(), IpVersionChoice.IPV6,
+ false);
neutronvpnUtils.updateVpnInstanceWithFallback(vpnInstanceInternetUuid.getValue(), false);
}
}
protected void associateRouterToVpn(Uuid vpnId, Uuid routerId) {
updateVpnMaps(vpnId, null, routerId, null, null);
LOG.debug("Updating association of subnets to external vpn {}", vpnId.getValue());
- List<Uuid> routerSubnets = neutronvpnUtils.getNeutronRouterSubnetIds(routerId);
- for (Uuid subnetId : routerSubnets) {
- Subnetmap sn = updateVpnForSubnet(routerId, vpnId, subnetId, true);
- if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToAdd(sn, vpnId)) {
- neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(),
- NeutronvpnUtils.getIpVersionFromString(sn.getSubnetIp()), true);
+ IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
+ List<Subnetmap> subMapList = neutronvpnUtils.getNeutronRouterSubnetMapList(routerId);
+ for (Subnetmap sn : subMapList) {
+ updateVpnForSubnet(routerId, vpnId, sn.getId(), true);
+ IpVersionChoice ipVers = neutronvpnUtils.getIpVersionFromString(sn.getSubnetIp());
+ if (!ipVersion.isIpVersionChosen(ipVers)) {
+ ipVersion = ipVersion.addVersion(ipVers);
}
}
+ if (ipVersion != IpVersionChoice.UNDEFINED) {
+ LOG.debug("vpnInstanceOpDataEntry is getting update with ip address family {} for VPN {} ", ipVersion,
+ vpnId);
+ neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), ipVersion, true);
+ }
try {
checkAndPublishRouterAssociatedtoVpnNotification(routerId, vpnId);
@SuppressWarnings("checkstyle:IllegalCatch")
protected void dissociateRouterFromVpn(Uuid vpnId, Uuid routerId) {
- List<Uuid> routerSubnets = neutronvpnUtils.getNeutronRouterSubnetIds(routerId);
- boolean vpnInstanceIpVersionsRemoved = false;
- IpVersionChoice vpnInstanceIpVersionsToRemove = IpVersionChoice.UNDEFINED;
- for (Uuid subnetId : routerSubnets) {
- Subnetmap sn = neutronvpnUtils.getSubnetmap(subnetId);
- if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToRemove(sn, vpnId)) {
- vpnInstanceIpVersionsToRemove = vpnInstanceIpVersionsToRemove.addVersion(NeutronvpnUtils
- .getIpVersionFromString(sn.getSubnetIp()));
- vpnInstanceIpVersionsRemoved = true;
+ List<Subnetmap> subMapList = neutronvpnUtils.getNeutronRouterSubnetMapList(routerId);
+ IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
+ for (Subnetmap sn : subMapList) {
+ IpVersionChoice ipVers = neutronvpnUtils.getIpVersionFromString(sn.getSubnetIp());
+ if (ipVersion.isIpVersionChosen(ipVers)) {
+ ipVersion = ipVersion.addVersion(ipVers);
}
LOG.debug("Updating association of subnets to internal vpn {}", routerId.getValue());
- updateVpnForSubnet(vpnId, routerId, subnetId, false);
+ updateVpnForSubnet(vpnId, routerId, sn.getId(), false);
}
-
- if (vpnInstanceIpVersionsRemoved) {
- neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), vpnInstanceIpVersionsToRemove, false);
+ if (ipVersion != IpVersionChoice.UNDEFINED) {
+ LOG.debug("vpnInstanceOpDataEntry is getting update with ip address family {} for VPN {} ",
+ ipVersion, vpnId);
+ neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), ipVersion,
+ false);
}
clearFromVpnMaps(vpnId, routerId, null);
try {
if (vpnManager.checkForOverlappingSubnets(nw, subnetmapList, vpnId, routeTargets, failedNwList)) {
continue;
}
+ IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
for (Subnetmap subnetmap : subnetmapList) {
Uuid subnetId = subnetmap.getId();
Uuid subnetVpnId = neutronvpnUtils.getVpnForSubnet(subnetId);
+ " as it is already associated", subnetId.getValue(), vpnId.getValue()));
continue;
}
- if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToAdd(subnetmap, vpnId)) {
- neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(),
- NeutronvpnUtils.getIpVersionFromString(subnetmap.getSubnetIp()), true);
+ IpVersionChoice ipVers = neutronvpnUtils.getIpVersionFromString(subnetmap.getSubnetIp());
+ if (!ipVersion.isIpVersionChosen(ipVers)) {
+ ipVersion = ipVersion.addVersion(ipVers);
}
if (!NeutronvpnUtils.getIsExternal(network)) {
LOG.debug("associateNetworksToVpn: Add subnet {} to VPN {}", subnetId.getValue(),
passedNwList.add(nw);
}
}
+ if (ipVersion != IpVersionChoice.UNDEFINED) {
+ LOG.debug("vpnInstanceOpDataEntry is getting update with ip address family {} for VPN {} ",
+ ipVersion, vpnId);
+ neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), ipVersion, true);
+ }
passedNwList.add(nw);
}
} catch (ReadFailedException e) {
}
}
Set<VpnTarget> routeTargets = vpnManager.getRtListForVpn(vpnId.getValue());
+ IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
for (Uuid subnet : networkSubnets) {
Subnetmap subnetmap = neutronvpnUtils.getSubnetmap(subnet);
- if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToRemove(subnetmap, vpnId)) {
- IpVersionChoice ipVersionsToRemove = IpVersionChoice.UNDEFINED;
- IpVersionChoice ipVersion = NeutronvpnUtils.getIpVersionFromString(subnetmap.getSubnetIp());
- neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(),
- ipVersionsToRemove.addVersion(ipVersion), false);
+ IpVersionChoice ipVers = neutronvpnUtils.getIpVersionFromString(subnetmap.getSubnetIp());
+ if (!ipVersion.isIpVersionChosen(ipVers)) {
+ ipVersion = ipVersion.addVersion(ipVers);
}
LOG.debug("dissociateNetworksFromVpn: Withdraw subnet {} from VPN {}", subnet.getValue(),
vpnId.getValue());
vpnId.getValue());
passedNwList.add(nw);
}
+ if (ipVersion != IpVersionChoice.UNDEFINED) {
+ LOG.debug("vpnInstanceOpDataEntry is getting update with ip address family {} for VPN {}",
+ ipVersion, vpnId);
+ neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), ipVersion, false);
+ }
}
clearFromVpnMaps(vpnId, null, new ArrayList<>(passedNwList));
LOG.info("Network(s) {} disassociated from L3VPN {} successfully", passedNwList.toString(),
return subnet;
}
+ protected List<Subnetmap> getNeutronRouterSubnetMapList(Uuid routerId) {
+ List<Subnetmap> subnetMapList = new ArrayList<>();
+ Optional<Subnetmaps> subnetMaps = read(LogicalDatastoreType.CONFIGURATION,
+ InstanceIdentifier.builder(Subnetmaps.class).build());
+ if (subnetMaps.isPresent() && subnetMaps.get().getSubnetmap() != null) {
+ for (Subnetmap subnetmap : subnetMaps.get().getSubnetmap()) {
+ if (routerId.equals(subnetmap.getRouterId())) {
+ subnetMapList.add(subnetmap);
+ }
+ }
+ }
+ LOG.debug("getNeutronRouterSubnetMapList returns {}", subnetMapList);
+ return subnetMapList;
+ }
+
@Nonnull
protected List<Uuid> getNeutronRouterSubnetIds(Uuid routerId) {
LOG.debug("getNeutronRouterSubnetIds for {}", routerId.getValue());
.child(VpnInstanceOpDataEntry.class, new VpnInstanceOpDataEntryKey(primaryRd)).build();
}
- public boolean shouldVpnHandleIpVersionChangeToAdd(Subnetmap sm, Uuid vpnId) {
- if (sm == null) {
- return false;
- }
- IpVersionChoice ipVersion = getIpVersionFromString(sm.getSubnetIp());
- return shouldVpnHandleIpVersionChoiceChangeToAdd(ipVersion, vpnId);
- }
-
- public boolean shouldVpnHandleIpVersionChoiceChangeToAdd(IpVersionChoice ipVersion, Uuid vpnId) {
- VpnInstanceOpDataEntry vpnInstanceOpDataEntry = getVpnInstanceOpDataEntryFromVpnId(vpnId.getValue());
- if (vpnInstanceOpDataEntry == null) {
- return false;
- }
- if (vpnInstanceOpDataEntry.getType() == VpnInstanceOpDataEntry.Type.L2) {
- LOG.error("shouldVpnHandleIpVersionChangeToAdd: {} "
- + "VpnInstanceOpDataEntry is L2 instance. Do nothing.", vpnId.getValue());
+ public boolean shouldVpnHandleIpVersionChoiceChange(IpVersionChoice ipVersion, Uuid routerId, boolean add) {
+ int subnetCount = -1;
+ if (ipVersion.isIpVersionChosen(IpVersionChoice.IPV4)) {
+ subnetCount = getSubnetCountFromRouter(routerId, ipVersion);
+ } else if (ipVersion.isIpVersionChosen(IpVersionChoice.IPV6)) {
+ subnetCount = getSubnetCountFromRouter(routerId, ipVersion);
+ } else {
+ //Possible value of ipversion choice is either V4 or V6 only. Not accepted V4andV6 and Undefined
return false;
}
- boolean isIpv4Configured = vpnInstanceOpDataEntry.isIpv4Configured();
- boolean isVpnInstanceIpv4Changed = false;
- if (ipVersion.isIpVersionChosen(IpVersionChoice.IPV4) && !isIpv4Configured) {
- isVpnInstanceIpv4Changed = true;
- }
- boolean isIpv6Configured = vpnInstanceOpDataEntry.isIpv6Configured();
- boolean isVpnInstanceIpv6Changed = false;
- if (ipVersion.isIpVersionChosen(IpVersionChoice.IPV6) && !isIpv6Configured) {
- isVpnInstanceIpv6Changed = true;
- }
- if (!isVpnInstanceIpv4Changed && !isVpnInstanceIpv6Changed) {
- LOG.debug("shouldVpnHandleIpVersionChangeToAdd: VPN {} did not change with IpFamily {}",
- vpnId.getValue(), ipVersion.toString());
+ /* ADD: Update vpnInstanceOpDataEntry with address family only on first IPv4/IPv6 subnet
+ * for the VPN Instance.
+ *
+ * REMOVE: Update vpnInstanceOpDataEntry with address family only on last IPv4/IPv6 subnet
+ * for the VPN Instance.
+ */
+ if (add && subnetCount == 1) {
+ return true;
+ } else if (!add && subnetCount == 0) {
+ return true;
+ } else {
return false;
}
- return true;
}
public boolean shouldVpnHandleIpVersionChangeToRemove(Subnetmap sm, Uuid vpnId) {
return false;
}
+ public int getSubnetCountFromRouter(Uuid routerId, IpVersionChoice ipVer) {
+ List<Subnetmap> subnetMapList = getNeutronRouterSubnetMapList(routerId);
+ int subnetCount = 0;
+ for (Subnetmap subMap : subnetMapList) {
+ IpVersionChoice ipVersion = getIpVersionFromString(subMap.getSubnetIp());
+ if (ipVersion.isIpVersionChosen(ipVer)) {
+ subnetCount++;
+ }
+ if (subnetCount > 1) {
+ break;
+ }
+ }
+ return subnetCount;
+ }
+
public void updateVpnInstanceWithIpFamily(String vpnName, IpVersionChoice ipVersion, boolean add) {
VpnInstanceOpDataEntry vpnInstanceOpDataEntry = getVpnInstanceOpDataEntryFromVpnId(vpnName);
if (vpnInstanceOpDataEntry == null) {
}
if (vpnInstanceOpDataEntry.getType() == VpnInstanceOpDataEntry.Type.L2) {
LOG.debug("updateVpnInstanceWithIpFamily: Update VpnInstance {} with ipFamily {}."
- + "VpnInstanceOpDataEntry is L2 instance. Do nothing.", vpnName,
- ipVersion.toString());
+ + "VpnInstanceOpDataEntry is L2 instance. Do nothing.", vpnName, ipVersion);
+ return;
+ }
+ if (ipVersion == IpVersionChoice.UNDEFINED) {
+ LOG.debug("updateVpnInstanceWithIpFamily: Update VpnInstance {} with Undefined address family"
+ + "is not allowed. Do nothing", vpnName);
return;
}
- final boolean isFinalVpnInstanceIpv6Changed = ipVersion
- .isIpVersionChosen(IpVersionChoice.IPV6) ? true : false;
- final boolean isFinalVpnInstanceIpv4Changed = ipVersion
- .isIpVersionChosen(IpVersionChoice.IPV4) ? true : false;
- final boolean finalIsIpv4Configured = ipVersion.isIpVersionChosen(IpVersionChoice.IPV4) ? add : false;
- final boolean finalIsIpv6Configured = ipVersion.isIpVersionChosen(IpVersionChoice.IPV6) ? add : false;
jobCoordinator.enqueueJob("VPN-" + vpnName, () -> {
VpnInstanceOpDataEntryBuilder builder = new VpnInstanceOpDataEntryBuilder(vpnInstanceOpDataEntry);
- if (isFinalVpnInstanceIpv4Changed) {
- builder.setIpv4Configured(finalIsIpv4Configured);
- }
- if (isFinalVpnInstanceIpv6Changed) {
- builder.setIpv6Configured(finalIsIpv6Configured);
+ boolean ipConfigured = add;
+ if (ipVersion.isIpVersionChosen(IpVersionChoice.IPV4AND6)) {
+ builder.setIpv4Configured(ipConfigured);
+ builder.setIpv6Configured(ipConfigured);
+ } else if (ipVersion.isIpVersionChosen(IpVersionChoice.IPV4)) {
+ builder.setIpv4Configured(ipConfigured);
+ } else if (ipVersion.isIpVersionChosen(IpVersionChoice.IPV6)) {
+ builder.setIpv6Configured(ipConfigured);
}
return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
- OPERATIONAL, tx -> {
- InstanceIdentifier<VpnInstanceOpDataEntry> id = InstanceIdentifier.builder(VpnInstanceOpData.class)
- .child(VpnInstanceOpDataEntry.class,
- new VpnInstanceOpDataEntryKey(vpnInstanceOpDataEntry.getVrfId())).build();
+ OPERATIONAL, tx -> {
+ InstanceIdentifier<VpnInstanceOpDataEntry> id = InstanceIdentifier
+ .builder(VpnInstanceOpData.class).child(VpnInstanceOpDataEntry.class,
+ new VpnInstanceOpDataEntryKey(vpnInstanceOpDataEntry.getVrfId())).build();
tx.merge(id, builder.build(), false);
LOG.info("updateVpnInstanceWithIpFamily: Successfully {} {} to Vpn {}",
- add ? "added" : "removed",
- ipVersion.toString(), vpnName);
+ add == true ? "added" : "removed", ipVersion, vpnName);
}));
});
}