- portDataStoreCoordinator.enqueueJob("PORT- " + portupdate.getUuid().getValue(), new
- Callable<List<ListenableFuture<Void>>>() {
- @Override
- public List<ListenableFuture<Void>> call() throws Exception {
- WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
- List<ListenableFuture<Void>> futures = new ArrayList<>();
-
- Uuid vpnIdNew = null;
- final Uuid subnetIdOr = portupdate.getFixedIps().get(0).getSubnetId();
- final Uuid subnetIdUp = portupdate.getFixedIps().get(0).getSubnetId();
- // check if subnet UUID has changed upon change in fixedIP
- final Boolean subnetUpdated = subnetIdUp.equals(subnetIdOr) ? false : true;
-
- if (subnetUpdated) {
- Subnetmap subnetMapOld = nvpnManager.removePortsFromSubnetmapNode(subnetIdOr, portoriginal
- .getUuid(), null);
- Uuid vpnIdOld = (subnetMapOld != null) ? subnetMapOld.getVpnId() : null;
- Subnetmap subnetMapNew = nvpnManager.updateSubnetmapNodeWithPorts(subnetIdUp, portupdate
- .getUuid(), null);
- vpnIdNew = (subnetMapNew != null) ? subnetMapNew.getVpnId() : null;
- }
- if (!subnetUpdated) {
- Subnetmap subnetmap = NeutronvpnUtils.getSubnetmap(dataBroker, subnetIdUp);
- vpnIdNew = subnetmap.getVpnId();
- }
- if (vpnIdNew != null) {
- // remove vpn-interface for this neutron port
- LOG.debug("removing VPN Interface for port {}", portupdate.getUuid().getValue());
- nvpnManager.deleteVpnInterface(vpnIdNew, null, portupdate, wrtConfigTxn);
- // create vpn-interface on this neutron port
- LOG.debug("Adding VPN Interface for port {}", portupdate.getUuid().getValue());
- nvpnManager.createVpnInterface(vpnIdNew, null, portupdate, wrtConfigTxn);
- }
- futures.add(wrtConfigTxn.submit());
- return futures;
- }
- });
+ portDataStoreCoordinator.enqueueJob("PORT- " + portupdate.getUuid().getValue(), () -> {
+ WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
+ List<ListenableFuture<Void>> futures = new ArrayList<>();
+ final List<Uuid> originalSnMapsIds = portoriginalIps.stream().map(ip -> ip.getSubnetId())
+ .collect(Collectors.toList());
+ final List<Uuid> updateSnMapsIds = portupdateIps.stream().map(ip -> ip.getSubnetId())
+ .collect(Collectors.toList());
+ for (Uuid snId: originalSnMapsIds) {
+ if (!updateSnMapsIds.remove(snId)) {
+ // snId was present in originalSnMapsIds, but not in updateSnMapsIds
+ nvpnManager.removePortsFromSubnetmapNode(snId, portoriginal.getUuid(), null);
+ }
+ }
+ for (Uuid snId: updateSnMapsIds) {
+ nvpnManager.updateSubnetmapNodeWithPorts(snId, portupdate.getUuid(), null);
+ }
+ final Uuid oldVpnId = NeutronvpnUtils.getVpnForNetwork(dataBroker, portoriginal.getNetworkId());
+ if (oldVpnId != null) {
+ LOG.info("removing VPN Interface for port {}", portoriginal.getUuid().getValue());
+ nvpnManager.deleteVpnInterface(oldVpnId, portoriginal, wrtConfigTxn);
+ futures.add(wrtConfigTxn.submit());
+ }
+ final Uuid newVpnId = NeutronvpnUtils.getVpnForNetwork(dataBroker, portupdate.getNetworkId());
+ if (newVpnId != null) {
+ LOG.info("Adding VPN Interface for port {}", portupdate.getUuid().getValue());
+ nvpnManager.createVpnInterface(newVpnId, portupdate, wrtConfigTxn);
+ futures.add(wrtConfigTxn.submit());
+ }
+ return futures;
+ });