import org.opendaylight.genius.mdsalutil.MatchInfo;
import org.opendaylight.genius.mdsalutil.NwConstants;
import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
+import org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.Acquired;
import org.opendaylight.netvirt.elan.utils.ElanConstants;
import org.opendaylight.netvirt.elan.utils.ElanEtreeUtils;
import org.opendaylight.netvirt.elan.utils.ElanItmUtils;
public List<ListenableFuture<Void>> evpnDeleteDmacFlowsToExternalMac(EvpnDmacFlow evpnDmacFlow) {
List<ListenableFuture<Void>> futures = new ArrayList<>();
- synchronized (ElanUtils.getElanMacDPNKey(evpnDmacFlow.getElanTag(), evpnDmacFlow.getDstMacAddress(),
+ try (Acquired lock = ElanUtils.lockElanMacDPN(evpnDmacFlow.getElanTag(), evpnDmacFlow.getDstMacAddress(),
evpnDmacFlow.getDpId())) {
futures.addAll(
evpnRemoveFlowThatSendsThePacketOnAnExternalTunnel(evpnDmacFlow.getElanTag(), evpnDmacFlow.dpId,
}
static class EvpnDmacFlow {
- private BigInteger dpId;
- private String nexthopIP;
- private long elanTag;
- private Long vni;
- private String dstMacAddress;
- private String elanName;
+ private final BigInteger dpId;
+ private final String nexthopIP;
+ private final long elanTag;
+ private final Long vni;
+ private final String dstMacAddress;
+ private final String elanName;
EvpnDmacFlow(BigInteger dpId, String nexthopIP, long elanTag, Long vni, String dstMacAddress,
String elanName) {
import org.opendaylight.genius.utils.ServiceIndex;
import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
import org.opendaylight.infrautils.utils.concurrent.LoggingFutures;
+import org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.Acquired;
import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
import org.opendaylight.netvirt.elan.cache.ElanInterfaceCache;
import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayMulticastUtils;
String macAddress = macEntry.getMacAddress().getValue();
LOG.info("Installing remote dmac for mac address {} and interface {}", macAddress,
interfaceName);
- synchronized (ElanUtils.getElanMacDPNKey(elanInfo.getElanTag(), macAddress,
+ try (Acquired lock = ElanUtils.lockElanMacDPN(elanInfo.getElanTag(), macAddress,
interfaceInfo.getDpId())) {
LOG.info("Acquired lock for mac : {}, proceeding with remote dmac install operation",
macAddress);
return "MAC-" + macAddress + " ELAN_TAG-" + elanTag;
}
+ private static String getElanMacDPNKey(long elanTag, String macAddress, BigInteger dpnId) {
+ return "MAC-" + macAddress + " ELAN_TAG-" + elanTag + "DPN_ID-" + dpnId;
+ }
+
private void enqueueJobForDPNSpecificTasks(final String macAddress, final long elanTag, String interfaceName,
PhysAddress physAddress, ElanInstance elanInstance,
InterfaceInfo interfaceInfo, MacEntry oldMacEntry,
MacEntry newMacEntry, boolean isVlanOrFlatProviderIface) {
- jobCoordinator.enqueueJob(ElanUtils.getElanMacDPNKey(elanTag, macAddress, interfaceInfo.getDpId()), () -> {
+ jobCoordinator.enqueueJob(getElanMacDPNKey(elanTag, macAddress, interfaceInfo.getDpId()), () -> {
macMigrationFlowsCleanup(interfaceName, elanInstance, oldMacEntry, isVlanOrFlatProviderIface);
BigInteger dpId = interfaceManager.getDpnForInterface(interfaceName);
elanL2GatewayUtils.scheduleAddDpnMacInExtDevices(elanInstance.getElanInstanceName(), dpId,
import org.opendaylight.genius.mdsalutil.packet.Ethernet;
import org.opendaylight.genius.mdsalutil.packet.IPv4;
import org.opendaylight.infrautils.utils.concurrent.LoggingFutures;
+import org.opendaylight.infrautils.utils.concurrent.NamedLocks;
+import org.opendaylight.infrautils.utils.concurrent.NamedSimpleReentrantLock.Acquired;
import org.opendaylight.netvirt.elan.arp.responder.ArpResponderUtil;
import org.opendaylight.netvirt.elan.cache.ElanInterfaceCache;
import org.opendaylight.netvirt.elanmanager.api.ElanHelper;
@Singleton
public class ElanUtils {
+ private static final class ElanLockName {
+ private final String macAddress;
+ private final BigInteger dpnId;
+ private final long elanTag;
+
+ ElanLockName(long elanTag, String macAddress, BigInteger dpnId) {
+ this.elanTag = elanTag;
+ this.macAddress = macAddress;
+ this.dpnId = dpnId;
+ }
+
+ @Override
+ public int hashCode() {
+ return 31 * Long.hashCode(elanTag) + Objects.hash(macAddress, dpnId);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!(obj instanceof ElanLockName)) {
+ return false;
+ }
+ final ElanLockName other = (ElanLockName) obj;
+ return elanTag == other.elanTag && Objects.equals(macAddress, other.macAddress)
+ && Objects.equals(dpnId, other.dpnId);
+ }
+ }
private static final Logger LOG = LoggerFactory.getLogger(ElanUtils.class);
+ private static final NamedLocks<ElanLockName> ELAN_LOCKS = new NamedLocks<>();
private final DataBroker broker;
private final ManagedNewTransactionRunner txRunner;
public void setupMacFlows(ElanInstance elanInfo, InterfaceInfo interfaceInfo,
long macTimeout, String macAddress, boolean configureRemoteFlows,
TypedWriteTransaction<Configuration> writeFlowGroupTx) {
- synchronized (getElanMacDPNKey(elanInfo.getElanTag(), macAddress, interfaceInfo.getDpId())) {
+ try (Acquired lock = lockElanMacDPN(elanInfo.getElanTag(), macAddress, interfaceInfo.getDpId())) {
setupKnownSmacFlow(elanInfo, interfaceInfo, macTimeout, macAddress, mdsalManager,
writeFlowGroupTx);
setupOrigDmacFlows(elanInfo, interfaceInfo, macAddress, configureRemoteFlows, mdsalManager,
return;
}
String macAddress = macEntry.getMacAddress().getValue();
- synchronized (getElanMacDPNKey(elanInfo.getElanTag(), macAddress, interfaceInfo.getDpId())) {
+ try (Acquired lock = lockElanMacDPN(elanInfo.getElanTag(), macAddress, interfaceInfo.getDpId())) {
deleteMacFlows(elanInfo, interfaceInfo, macAddress, /* alsoDeleteSMAC */ true, flowTx);
}
}
return null;
}
- public static String getElanMacDPNKey(long elanTag, String macAddress, BigInteger dpnId) {
- String elanMacDmacDpnKey = "MAC-" + macAddress + " ELAN_TAG-" + elanTag + "DPN_ID-" + dpnId;
- return elanMacDmacDpnKey.intern();
+ public static Acquired lockElanMacDPN(long elanTag, String macAddress, BigInteger dpnId) {
+ return ELAN_LOCKS.acquire(new ElanLockName(elanTag, macAddress, dpnId));
}
public static List<ListenableFuture<Void>>