import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Consumer;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
import org.opendaylight.genius.infra.TypedWriteTransaction;
import org.opendaylight.genius.mdsalutil.NwConstants;
+import org.opendaylight.genius.utils.JvmGlobalLocks;
import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
import org.opendaylight.infrautils.utils.concurrent.KeyedLocks;
import org.opendaylight.infrautils.utils.concurrent.ListenableFutures;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.GetL3VPNOutputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NetworkAttributes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NeutronvpnService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.RouterAssociatedToVpn;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.RouterAssociatedToVpnBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.RouterDisassociatedFromVpn;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.RouterDisassociatedFromVpnBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.RouterInterfacesMap;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.Subnetmaps;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.VpnMaps;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.RemoveStaticRouteInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.RemoveStaticRouteInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.VpnRpcService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.extensions.rev160617.BgpvpnVni;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.extensions.rev160617.OperationalPortStatus;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.extensions.rev160617.service.provider.features.attributes.Features;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.extensions.rev160617.service.provider.features.attributes.features.Feature;
final VpnRpcService vpnRpcSrv, final IElanService elanService,
final NeutronFloatingToFixedIpMappingChangeListener neutronFloatingToFixedIpMappingChangeListener,
final NeutronvpnConfig neutronvpnConfig, final IVpnManager vpnManager,
- final JobCoordinator jobCoordinator, final NeutronvpnUtils neutronvpnUtils) {
+ final JobCoordinator jobCoordinator,
+ final NeutronvpnUtils neutronvpnUtils) throws TransactionCommitFailedException {
this.dataBroker = dataBroker;
this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
notificationPublishService = notiPublishService;
LOG.info("{} close", getClass().getSimpleName());
}
- private void configureFeatures() {
+ private void configureFeatures() throws TransactionCommitFailedException {
InstanceIdentifier<Feature> iid = InstanceIdentifier.builder(
Neutron.class).child(Features.class).child(
Feature.class, new FeatureKey(OperationalPortStatus.class)).build();
Feature feature = new FeatureBuilder().withKey(new FeatureKey(OperationalPortStatus.class)).build();
try {
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, iid, feature);
- } catch (TransactionCommitFailedException e) {
- LOG.warn("Error configuring feature {}", feature, e);
+ } catch (OptimisticLockFailedException e) {
+ LOG.debug("Optimistic lock failed exception while configuring feature {}", feature, e);
+ }
+ InstanceIdentifier<Feature> bgpvpnVniIid = InstanceIdentifier.builder(
+ Neutron.class).child(Features.class).child(
+ Feature.class, new FeatureKey(BgpvpnVni.class)).build();
+ Feature bgpvpnVniFeature = new FeatureBuilder().withKey(new FeatureKey(BgpvpnVni.class)).build();
+ try {
+ SingleTransactionDataBroker.syncWrite(
+ dataBroker, LogicalDatastoreType.OPERATIONAL, bgpvpnVniIid, bgpvpnVniFeature);
+ } catch (OptimisticLockFailedException e) {
+ LOG.debug("Optimistic lock failed exception while configuring feature {}", bgpvpnVniFeature, e);
}
}
@Nullable NetworkAttributes.NetworkType networkType, long segmentationId) {
try {
InstanceIdentifier<Subnetmap> subnetMapIdentifier = NeutronvpnUtils.buildSubnetMapIdentifier(subnetId);
- synchronized (subnetId.getValue().intern()) {
+ final ReentrantLock lock = lockForUuid(subnetId);
+ lock.lock();
+ try {
LOG.info("createSubnetmapNode: subnet ID {}", subnetId.toString());
Optional<Subnetmap> sn = SingleTransactionDataBroker.syncReadOptional(dataBroker,
LogicalDatastoreType.CONFIGURATION, subnetMapIdentifier);
subnetId.getValue());
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION,
subnetMapIdentifier, subnetmapBuilder.build());
+ } finally {
+ lock.unlock();
}
} catch (TransactionCommitFailedException | ReadFailedException e) {
LOG.error("createSubnetmapNode: Creating subnetmap node failed for subnet {}", subnetId.getValue());
InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class)
.child(Subnetmap.class, new SubnetmapKey(subnetId))
.build();
+ final ReentrantLock lock = lockForUuid(subnetId);
+ lock.lock();
try {
- synchronized (subnetId.getValue().intern()) {
- Optional<Subnetmap> sn =
- SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
- id);
- if (!sn.isPresent()) {
- LOG.error("subnetmap node for subnet {} does not exist, returning", subnetId.getValue());
- return null;
- }
- LOG.debug("updating existing subnetmap node for subnet ID {}", subnetId.getValue());
- SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
- if (routerId != null) {
- builder.setRouterId(routerId);
- }
- if (vpnId != null) {
- builder.setVpnId(vpnId);
- }
- if (neutronvpnUtils.getIpVersionFromString(sn.get().getSubnetIp()) == IpVersionChoice.IPV6) {
- builder.setInternetVpnId(internetvpnId);
- }
- Subnetmap subnetmap = builder.build();
- LOG.debug("Creating/Updating subnetMap node: {} ", subnetId.getValue());
- SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, subnetmap);
- return subnetmap;
+ Optional<Subnetmap> sn =
+ SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
+ if (!sn.isPresent()) {
+ LOG.error("subnetmap node for subnet {} does not exist, returning", subnetId.getValue());
+ return null;
+ }
+ LOG.debug("updating existing subnetmap node for subnet ID {}", subnetId.getValue());
+ SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
+ if (routerId != null) {
+ builder.setRouterId(routerId);
+ }
+ if (vpnId != null) {
+ builder.setVpnId(vpnId);
}
+ if (NeutronvpnUtils.getIpVersionFromString(sn.get().getSubnetIp()) == IpVersionChoice.IPV6) {
+ builder.setInternetVpnId(internetvpnId);
+ }
+ Subnetmap subnetmap = builder.build();
+ LOG.debug("Creating/Updating subnetMap node: {} ", subnetId.getValue());
+ SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, subnetmap);
+ return subnetmap;
} catch (ReadFailedException | TransactionCommitFailedException e) {
LOG.error("Subnet map update failed for node {}", subnetId.getValue(), e);
return null;
+ } finally {
+ lock.unlock();
}
}
@Nullable Uuid routerInterfacePortId, @Nullable String fixedIp,
@Nullable String routerIntfMacAddress, @Nullable Uuid vpnId) {
InstanceIdentifier<Subnetmap> id =
- InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
+ InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
+ final ReentrantLock lock = lockForUuid(subnetId);
+ lock.lock();
try {
- synchronized (subnetId.getValue().intern()) {
- Optional<Subnetmap> sn =
- SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
- id);
- if (!sn.isPresent()) {
- LOG.error("WithRouterFixedIP: subnetmap node for subnet {} does not exist, returning ",
- subnetId.getValue());
- return;
- }
- LOG.debug("WithRouterFixedIP: Updating existing subnetmap node for subnet ID {}",
+ Optional<Subnetmap> sn =
+ SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
+ if (!sn.isPresent()) {
+ LOG.error("WithRouterFixedIP: subnetmap node for subnet {} does not exist, returning ",
subnetId.getValue());
- SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
- builder.setRouterId(routerId);
- builder.setRouterInterfacePortId(routerInterfacePortId);
- builder.setRouterIntfMacAddress(routerIntfMacAddress);
- builder.setRouterInterfaceFixedIp(fixedIp);
- if (vpnId != null) {
- builder.setVpnId(vpnId);
- }
- Subnetmap subnetmap = builder.build();
- LOG.debug("WithRouterFixedIP Creating/Updating subnetMap node for Router FixedIp: {} ",
- subnetId.getValue());
- SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, subnetmap);
+ return;
}
+ LOG.debug("WithRouterFixedIP: Updating existing subnetmap node for subnet ID {}",
+ subnetId.getValue());
+ SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
+ builder.setRouterId(routerId);
+ builder.setRouterInterfacePortId(routerInterfacePortId);
+ builder.setRouterIntfMacAddress(routerIntfMacAddress);
+ builder.setRouterInterfaceFixedIp(fixedIp);
+ if (vpnId != null) {
+ builder.setVpnId(vpnId);
+ }
+ Subnetmap subnetmap = builder.build();
+ LOG.debug("WithRouterFixedIP Creating/Updating subnetMap node for Router FixedIp: {} ",
+ subnetId.getValue());
+ SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, subnetmap);
} catch (ReadFailedException | TransactionCommitFailedException e) {
LOG.error("WithRouterFixedIP: subnet map for Router FixedIp failed for node {}",
subnetId.getValue(), e);
+ } finally {
+ lock.unlock();
}
}
InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class,
new SubnetmapKey(subnetId)).build();
LOG.info("updateSubnetmapNodeWithPorts : subnetId {}, subnetMapId {}", subnetId.toString(), id.toString());
+ final ReentrantLock lock = lockForUuid(subnetId);
+ lock.lock();
try {
- synchronized (subnetId.getValue().intern()) {
- Optional<Subnetmap> sn =
- SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
- id);
- if (sn.isPresent()) {
- SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
- if (null != portId) {
- List<Uuid> portList = builder.getPortList();
- if (null == portList) {
- portList = new ArrayList<>();
- }
- portList.add(portId);
- builder.setPortList(portList);
- LOG.debug("updateSubnetmapNodeWithPorts: Updating existing subnetmap node {} with port {}",
- subnetId.getValue(), portId.getValue());
+ Optional<Subnetmap> sn =
+ SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
+ id);
+ if (sn.isPresent()) {
+ SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
+ if (null != portId) {
+ List<Uuid> portList = builder.getPortList();
+ if (null == portList) {
+ portList = new ArrayList<>();
}
- if (null != directPortId) {
- List<Uuid> directPortList = builder.getDirectPortList();
- if (null == directPortList) {
- directPortList = new ArrayList<>();
- }
- directPortList.add(directPortId);
- builder.setDirectPortList(directPortList);
- LOG.debug("Updating existing subnetmap node {} with port {}", subnetId.getValue(),
- directPortId.getValue());
+ portList.add(portId);
+ builder.setPortList(portList);
+ LOG.debug("updateSubnetmapNodeWithPorts: Updating existing subnetmap node {} with port {}",
+ subnetId.getValue(), portId.getValue());
+ }
+ if (null != directPortId) {
+ List<Uuid> directPortList = builder.getDirectPortList();
+ if (null == directPortList) {
+ directPortList = new ArrayList<>();
}
- subnetmap = builder.build();
- SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id,
- subnetmap);
- } else {
- LOG.info("updateSubnetmapNodeWithPorts: Subnetmap node is not ready {}, put port {} in unprocessed "
+ directPortList.add(directPortId);
+ builder.setDirectPortList(directPortList);
+ LOG.debug("Updating existing subnetmap node {} with port {}", subnetId.getValue(),
+ directPortId.getValue());
+ }
+ subnetmap = builder.build();
+ SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id,
+ subnetmap);
+ } else {
+ LOG.info("updateSubnetmapNodeWithPorts: Subnetmap node is not ready {}, put port {} in unprocessed "
+ "cache ", subnetId.getValue(), portId.getValue());
- unprocessedPortsMap.put(portId, subnetId);
- }
+ unprocessedPortsMap.put(portId, subnetId);
}
} catch (ReadFailedException | TransactionCommitFailedException e) {
LOG.error("Updating port list of a given subnetMap failed for node: {}", subnetId.getValue(), e);
+ } finally {
+ lock.unlock();
}
return subnetmap;
}
InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class)
.child(Subnetmap.class, new SubnetmapKey(subnetId))
.build();
+ final ReentrantLock lock = lockForUuid(subnetId);
+ lock.lock();
try {
- synchronized (subnetId.getValue().intern()) {
- Optional<Subnetmap> sn =
- SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
- id);
- if (sn.isPresent()) {
- SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
- if (routerId != null) {
- builder.setRouterId(null);
- }
- if (networkId != null) {
- builder.setNetworkId(null);
- }
- if (vpnId != null) {
- builder.setVpnId(null);
- }
- builder.setInternetVpnId(null);
- if (portId != null && builder.getPortList() != null) {
- List<Uuid> portList = builder.getPortList();
- portList.remove(portId);
- builder.setPortList(portList);
- }
-
- subnetmap = builder.build();
- LOG.debug("Removing from existing subnetmap node: {} ", subnetId.getValue());
- SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id,
- subnetmap);
- } else {
- LOG.warn("removing from non-existing subnetmap node: {} ", subnetId.getValue());
+ Optional<Subnetmap> sn =
+ SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
+ id);
+ if (sn.isPresent()) {
+ SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
+ if (routerId != null) {
+ builder.setRouterId(null);
+ }
+ if (networkId != null) {
+ builder.setNetworkId(null);
+ }
+ if (vpnId != null) {
+ builder.setVpnId(null);
+ }
+ builder.setInternetVpnId(null);
+ if (portId != null && builder.getPortList() != null) {
+ List<Uuid> portList = builder.getPortList();
+ portList.remove(portId);
+ builder.setPortList(portList);
}
+
+ subnetmap = builder.build();
+ LOG.debug("Removing from existing subnetmap node: {} ", subnetId.getValue());
+ SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id,
+ subnetmap);
+ } else {
+ LOG.warn("removing from non-existing subnetmap node: {} ", subnetId.getValue());
}
} catch (ReadFailedException | TransactionCommitFailedException e) {
LOG.error("Removal from subnetmap failed for node: {}", subnetId.getValue());
+ } finally {
+ lock.unlock();
}
return subnetmap;
}
Subnetmap subnetmap = null;
InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class,
new SubnetmapKey(subnetId)).build();
+ final ReentrantLock lock = lockForUuid(subnetId);
+ lock.lock();
try {
- synchronized (subnetId.getValue().intern()) {
- Optional<Subnetmap> sn =
- SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
- id);
- if (sn.isPresent()) {
- SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
- if (null != portId && null != builder.getPortList()) {
- List<Uuid> portList = builder.getPortList();
- portList.remove(portId);
- builder.setPortList(portList);
- LOG.debug("Removing port {} from existing subnetmap node: {} ", portId.getValue(),
- subnetId.getValue());
- }
- if (null != directPortId && null != builder.getDirectPortList()) {
- List<Uuid> directPortList = builder.getDirectPortList();
- directPortList.remove(directPortId);
- builder.setDirectPortList(directPortList);
- LOG.debug("Removing direct port {} from existing subnetmap node: {} ", directPortId
- .getValue(), subnetId.getValue());
- }
- subnetmap = builder.build();
- SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id,
- subnetmap);
- } else {
- LOG.info("Trying to remove port from non-existing subnetmap node {}", subnetId.getValue());
+ Optional<Subnetmap> sn =
+ SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
+ id);
+ if (sn.isPresent()) {
+ SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
+ if (null != portId && null != builder.getPortList()) {
+ List<Uuid> portList = builder.getPortList();
+ portList.remove(portId);
+ builder.setPortList(portList);
+ LOG.debug("Removing port {} from existing subnetmap node: {} ", portId.getValue(),
+ subnetId.getValue());
}
+ if (null != directPortId && null != builder.getDirectPortList()) {
+ List<Uuid> directPortList = builder.getDirectPortList();
+ directPortList.remove(directPortId);
+ builder.setDirectPortList(directPortList);
+ LOG.debug("Removing direct port {} from existing subnetmap node: {} ", directPortId
+ .getValue(), subnetId.getValue());
+ }
+ subnetmap = builder.build();
+ SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id,
+ subnetmap);
+ } else {
+ LOG.info("Trying to remove port from non-existing subnetmap node {}", subnetId.getValue());
}
} catch (ReadFailedException | TransactionCommitFailedException e) {
LOG.error("Removing a port from port list of a subnetmap failed for node: {}",
subnetId.getValue(), e);
+ } finally {
+ lock.unlock();
}
return subnetmap;
}
InstanceIdentifier<Subnetmap> subnetMapIdentifier =
InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
LOG.debug("removing subnetMap node: {} ", subnetId.getValue());
+ final ReentrantLock lock = lockForUuid(subnetId);
+ lock.lock();
try {
- synchronized (subnetId.getValue().intern()) {
- SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION,
- subnetMapIdentifier);
- }
+ SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, subnetMapIdentifier);
} catch (TransactionCommitFailedException e) {
LOG.error("Delete subnetMap node failed for subnet : {} ", subnetId.getValue());
+ } finally {
+ lock.unlock();
}
}
protected void updateVpnInterface(Uuid vpnId, @Nullable Uuid oldVpnId, Port port, boolean isBeingAssociated,
boolean isSubnetIp,
- TypedWriteTransaction<Configuration> writeConfigTxn) {
+ TypedWriteTransaction<Configuration> writeConfigTxn,
+ boolean isInternetVpn) {
if (vpnId == null || port == null) {
return;
}
neutronvpnUtils.removeVpnPortFixedIpToPort(oldVpnId.getValue(),
ipValue, writeConfigTxn);
}
+ if ((NeutronvpnUtils.getIpVersionFromString(ipValue) != IpVersionChoice.IPV6)
+ && (isInternetVpn == true)) {
+ continue;
+ }
+
neutronvpnUtils.createVpnPortFixedIpToPort(vpnId.getValue(), ipValue, infName, port
.getMacAddress().getValue(), isSubnetIp, writeConfigTxn);
}
txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, wrtConfigTxn -> {
if (isBeingAssociated) {
updateVpnInterface(vpn, null, neutronvpnUtils.getNeutronPort(
- sm.getRouterInterfacePortId()), true, true, wrtConfigTxn);
+ sm.getRouterInterfacePortId()), true, true, wrtConfigTxn, true);
} else {
removeInternetVpnFromVpnInterface(vpn,
neutronvpnUtils.getNeutronPort(sm.getRouterInterfacePortId()), wrtConfigTxn, sm);
tx -> {
if (isBeingAssociated) {
updateVpnInterface(vpn, null, neutronvpnUtils.getNeutronPort(port),
- true, false, tx);
+ true, false, tx, true);
} else {
removeInternetVpnFromVpnInterface(vpn, neutronvpnUtils.getNeutronPort(port), tx, sm);
}
txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
tx -> updateVpnInterface(newVpnId, oldVpnId,
neutronvpnUtils.getNeutronPort(sn.getRouterInterfacePortId()),
- isBeingAssociated, true, tx));
+ isBeingAssociated, true, tx, false));
Futures.addCallback(future, new FutureCallback<Void>() {
@Override
public void onSuccess(Void result) {
txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
tx -> updateVpnInterface(newVpnId, oldVpnId,
neutronvpnUtils.getNeutronPort(port), isBeingAssociated, false,
- tx))));
+ tx, false))));
}
}
}
}
protected void addToNeutronRouterInterfacesMap(Uuid routerId, String interfaceName) {
- synchronized (routerId.getValue().intern()) {
- InstanceIdentifier<RouterInterfaces> routerInterfacesId = getRouterInterfacesId(routerId);
- try {
- Optional<RouterInterfaces> optRouterInterfaces =
- SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
- routerInterfacesId);
- Interfaces routerInterface = new InterfacesBuilder().withKey(new InterfacesKey(interfaceName))
+ final InstanceIdentifier<RouterInterfaces> routerInterfacesId = getRouterInterfacesId(routerId);
+ final ReentrantLock lock = lockForUuid(routerId);
+ lock.lock();
+ try {
+ Optional<RouterInterfaces> optRouterInterfaces =
+ SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
+ routerInterfacesId);
+ Interfaces routerInterface = new InterfacesBuilder().withKey(new InterfacesKey(interfaceName))
.setInterfaceId(interfaceName).build();
- if (optRouterInterfaces.isPresent()) {
- SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION,
- routerInterfacesId.child(Interfaces.class, new InterfacesKey(interfaceName)),
- routerInterface);
- } else {
- // TODO Shouldn't we be doing something with builder and interfaces?
-// RouterInterfacesBuilder builder = new RouterInterfacesBuilder().setRouterId(routerId);
-// List<Interfaces> interfaces = new ArrayList<>();
-// interfaces.add(routerInterface);
+ if (optRouterInterfaces.isPresent()) {
+ SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION,
+ routerInterfacesId.child(Interfaces.class, new InterfacesKey(interfaceName)), routerInterface);
+ } else {
+ // TODO Shouldn't we be doing something with builder and interfaces?
+ // RouterInterfacesBuilder builder = new RouterInterfacesBuilder().setRouterId(routerId);
+ // List<Interfaces> interfaces = new ArrayList<>();
+ // interfaces.add(routerInterface);
- SingleTransactionDataBroker.syncUpdate(dataBroker, LogicalDatastoreType.CONFIGURATION,
- routerInterfacesId.child(Interfaces.class, new InterfacesKey(interfaceName)),
- routerInterface);
- }
- } catch (ReadFailedException | TransactionCommitFailedException e) {
- LOG.error("Error reading router interfaces for {}", routerInterfacesId, e);
+ SingleTransactionDataBroker.syncUpdate(dataBroker, LogicalDatastoreType.CONFIGURATION,
+ routerInterfacesId.child(Interfaces.class, new InterfacesKey(interfaceName)), routerInterface);
}
+ } catch (ReadFailedException | TransactionCommitFailedException e) {
+ LOG.error("Error reading router interfaces for {}", routerInterfacesId, e);
+ } finally {
+ lock.unlock();
}
}
protected void removeFromNeutronRouterInterfacesMap(Uuid routerId, String interfaceName) {
- synchronized (routerId.getValue().intern()) {
- InstanceIdentifier<RouterInterfaces> routerInterfacesId = getRouterInterfacesId(routerId);
- try {
- Optional<RouterInterfaces> optRouterInterfaces =
- SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
- routerInterfacesId);
- Interfaces routerInterface = new InterfacesBuilder().withKey(new InterfacesKey(interfaceName))
+ final InstanceIdentifier<RouterInterfaces> routerInterfacesId = getRouterInterfacesId(routerId);
+ final ReentrantLock lock = lockForUuid(routerId);
+ lock.lock();
+ try {
+ Optional<RouterInterfaces> optRouterInterfaces =
+ SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
+ routerInterfacesId);
+ Interfaces routerInterface = new InterfacesBuilder().withKey(new InterfacesKey(interfaceName))
.setInterfaceId(interfaceName).build();
- if (optRouterInterfaces.isPresent()) {
- RouterInterfaces routerInterfaces = optRouterInterfaces.get();
- List<Interfaces> interfaces = routerInterfaces.getInterfaces();
- if (interfaces != null && interfaces.remove(routerInterface)) {
- if (interfaces.isEmpty()) {
- SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION,
- routerInterfacesId);
- } else {
- SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION,
- routerInterfacesId.child(Interfaces.class, new InterfacesKey(interfaceName)));
- }
+ if (optRouterInterfaces.isPresent()) {
+ RouterInterfaces routerInterfaces = optRouterInterfaces.get();
+ List<Interfaces> interfaces = routerInterfaces.getInterfaces();
+ if (interfaces != null && interfaces.remove(routerInterface)) {
+ if (interfaces.isEmpty()) {
+ SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION,
+ routerInterfacesId);
+ } else {
+ SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION,
+ routerInterfacesId.child(Interfaces.class, new InterfacesKey(interfaceName)));
}
}
- } catch (ReadFailedException | TransactionCommitFailedException e) {
- LOG.error("Error reading the router interfaces for {}", routerInterfacesId, e);
}
+ } catch (ReadFailedException | TransactionCommitFailedException e) {
+ LOG.error("Error reading the router interfaces for {}", routerInterfacesId, e);
+ } finally {
+ lock.unlock();
}
}
@SuppressWarnings("checkstyle:IllegalCatch")
protected void associateRouterToVpn(Uuid vpnId, Uuid routerId) {
updateVpnMaps(vpnId, null, routerId, null, null);
- LOG.debug("Updating association of subnets to external vpn {}", vpnId.getValue());
- IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
+ LOG.debug("associateRouterToVpn: Updating association of subnets to external vpn {}", vpnId.getValue());
List<Subnetmap> subMapList = neutronvpnUtils.getNeutronRouterSubnetMapList(routerId);
+ IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
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);
+ LOG.debug("associateRouterToVpn: Updating vpnInstanceOpDataEntrywith ip address family {} for VPN {} ",
+ ipVersion, vpnId);
neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), ipVersion, true);
}
-
- try {
- checkAndPublishRouterAssociatedtoVpnNotification(routerId, vpnId);
- LOG.debug("notification upon association of router {} to VPN {} published", routerId.getValue(),
- vpnId.getValue());
- } catch (Exception e) {
- LOG.error("publishing of notification upon association of router {} to VPN {} failed : ", routerId
- .getValue(), vpnId.getValue(), e);
+ for (Subnetmap sn : subMapList) {
+ updateVpnForSubnet(routerId, vpnId, sn.getId(), true);
}
}
List<Subnetmap> subMapList = neutronvpnUtils.getNeutronRouterSubnetMapList(routerId);
IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
for (Subnetmap sn : subMapList) {
- IpVersionChoice ipVers = neutronvpnUtils.getIpVersionFromString(sn.getSubnetIp());
+ 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());
+ LOG.debug("dissociateRouterFromVpn: Updating association of subnets to internal vpn {}",
+ routerId.getValue());
updateVpnForSubnet(vpnId, routerId, sn.getId(), false);
}
if (ipVersion != IpVersionChoice.UNDEFINED) {
- LOG.debug("vpnInstanceOpDataEntry is getting update with ip address family {} for VPN {} ",
+ LOG.debug("dissociateRouterFromVpn; Updating vpnInstanceOpDataEntry with ip address family {} for VPN {} ",
ipVersion, vpnId);
neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), ipVersion,
false);
}
- try {
- checkAndPublishRouterDisassociatedFromVpnNotification(routerId, vpnId);
- LOG.debug("notification upon disassociation of router {} from VPN {} published", routerId.getValue(),
- vpnId.getValue());
- } catch (Exception e) {
- LOG.error("publishing of notification upon disassociation of router {} from VPN {} failed : ", routerId
- .getValue(), vpnId.getValue(), e);
- }
}
/**
continue;
}
IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
+ for (Subnetmap subnetmap : subnetmapList) {
+ IpVersionChoice ipVers = neutronvpnUtils.getIpVersionFromString(subnetmap.getSubnetIp());
+ if (!ipVersion.isIpVersionChosen(ipVers)) {
+ ipVersion = ipVersion.addVersion(ipVers);
+ }
+ }
+ if (ipVersion != IpVersionChoice.UNDEFINED) {
+ LOG.debug("associateNetworksToVpn: Updating vpnInstanceOpDataEntry with ip address family {}"
+ + " for VPN {} ", ipVersion, vpnId);
+ neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), ipVersion, true);
+ }
for (Subnetmap subnetmap : subnetmapList) {
Uuid subnetId = subnetmap.getId();
Uuid subnetVpnId = neutronvpnUtils.getVpnForSubnet(subnetId);
+ " as it is already associated", subnetId.getValue(), vpnId.getValue()));
continue;
}
- 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(),
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, true);
- }
passedNwList.add(nw);
}
} catch (ReadFailedException e) {
LOG.error("associateExtNetworkToVpn: can not find subnet with Id {} in ConfigDS", snId.getValue());
continue;
}
- IpVersionChoice ipVers = neutronvpnUtils.getIpVersionFromString(sm.getSubnetIp());
+ IpVersionChoice ipVers = NeutronvpnUtils.getIpVersionFromString(sm.getSubnetIp());
if (ipVers.isIpVersionChosen(IpVersionChoice.IPV4)) {
continue;
}
IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
for (Uuid subnet : networkSubnets) {
Subnetmap subnetmap = neutronvpnUtils.getSubnetmap(subnet);
- IpVersionChoice ipVers = neutronvpnUtils.getIpVersionFromString(subnetmap.getSubnetIp());
+ IpVersionChoice ipVers = NeutronvpnUtils.getIpVersionFromString(subnetmap.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);
+ LOG.debug("dissociateNetworksFromVpn: Updating vpnInstanceOpDataEntryupdate 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(),
- vpnId.getValue());
+ LOG.info("dissociateNetworksFromVpn: Network(s) {} disassociated from L3VPN {} successfully",
+ passedNwList.toString(), vpnId.getValue());
return failedNwList;
}
LOG.error("disassociateExtNetworkFromVpn: can not find subnet with Id {} in ConfigDS", snId.getValue());
continue;
}
- IpVersionChoice ipVers = neutronvpnUtils.getIpVersionFromString(sm.getSubnetIp());
+ IpVersionChoice ipVers = NeutronvpnUtils.getIpVersionFromString(sm.getSubnetIp());
if (ipVers.isIpVersionChosen(IpVersionChoice.IPV4)) {
continue;
}
if (networkUuid != null) {
Network portNetwork = neutronvpnUtils.getNeutronNetwork(networkUuid);
ProviderTypes providerType = NeutronvpnUtils.getProviderNetworkType(portNetwork);
- NetworkAttributes.NetworkType networkType = (providerType != null)
+ NetworkAttributes.NetworkType networkType = providerType != null
? NetworkAttributes.NetworkType.valueOf(providerType.getName()) : null;
String segmentationId = NeutronvpnUtils.getSegmentationIdFromNeutronNetwork(portNetwork);
vpnb.setNetworkId(networkUuid).setNetworkType(networkType)
return help.toString();
}
- private void checkAndPublishRouterAssociatedtoVpnNotification(Uuid routerId, Uuid vpnId) throws
- InterruptedException {
- RouterAssociatedToVpn routerAssociatedToVpn = new RouterAssociatedToVpnBuilder().setRouterId(routerId)
- .setVpnId(vpnId).build();
- LOG.info("publishing notification upon association of router to VPN");
- notificationPublishService.putNotification(routerAssociatedToVpn);
- }
-
- private void checkAndPublishRouterDisassociatedFromVpnNotification(Uuid routerId, Uuid vpnId) throws
- InterruptedException {
- RouterDisassociatedFromVpn routerDisassociatedFromVpn =
- new RouterDisassociatedFromVpnBuilder().setRouterId(routerId).setVpnId(vpnId).build();
- LOG.info("publishing notification upon disassociation of router from VPN");
- notificationPublishService.putNotification(routerDisassociatedFromVpn);
- }
-
protected void dissociatefixedIPFromFloatingIP(String fixedNeutronPortName) {
floatingIpMapListener.dissociatefixedIPFromFloatingIP(fixedNeutronPortName);
}
return existingVpnName;
}
- private String formatAndLog(Consumer<String> logger, String template, Object arg) {
+ private static String formatAndLog(Consumer<String> logger, String template, Object arg) {
return logAndReturnMessage(logger, MessageFormatter.format(template, arg));
}
- private String formatAndLog(Consumer<String> logger, String template, Object arg1, Object arg2) {
+ private static String formatAndLog(Consumer<String> logger, String template, Object arg1, Object arg2) {
return logAndReturnMessage(logger, MessageFormatter.format(template, arg1, arg2));
}
- private String formatAndLog(Consumer<String> logger, String template, Object... args) {
+ private static String formatAndLog(Consumer<String> logger, String template, Object... args) {
return logAndReturnMessage(logger, MessageFormatter.arrayFormat(template, args));
}
- private String logAndReturnMessage(Consumer<String> logger, FormattingTuple tuple) {
+ private static String logAndReturnMessage(Consumer<String> logger, FormattingTuple tuple) {
String message = tuple.getMessage();
logger.accept(message);
return message;
? true : false);
}
}
+
+ private static ReentrantLock lockForUuid(Uuid uuid) {
+ // FIXME: prove that this locks only on Uuids and not some other entity or create a separate lock domain
+ return JvmGlobalLocks.getLockForString(uuid.getValue());
+ }
}