+ }
+
+ public void clearInTransit(Class<? extends Identifiable> cls, InstanceIdentifier key) {
+ DeviceData deviceData = getDeviceOperData(cls, key);
+ if (deviceData != null && deviceData.isInTransitState()) {
+ if (deviceData.getData() != null) {
+ HwvtepSouthboundUtil.updateData(opKeyVsData, cls, key,
+ new DeviceData(key, deviceData.getUuid(), deviceData.getData(), DeviceDataStatus.AVAILABLE));
+ } else {
+ clearDeviceOperData(cls, key);
+ }
+ }
+ }
+
+ public Map<InstanceIdentifier, DeviceData> getDeviceOperData(Class<? extends Identifiable> cls) {
+ return opKeyVsData.get(cls);
+ }
+
+ public void incRefCount(InstanceIdentifier reference, InstanceIdentifier tep) {
+ if (reference == null || tep == null) {
+ return;
+ }
+ tepIdReferences.computeIfAbsent(tep, (tepId) -> Sets.newConcurrentHashSet());
+ tepIdReferences.get(tep).add(reference);
+ }
+
+ public int getRefCount(InstanceIdentifier tep) {
+ return tepIdReferences.containsKey(tep) ? tepIdReferences.get(tep).size() : 0;
+ }
+
+ public Set<InstanceIdentifier> getRefCounts(InstanceIdentifier tep) {
+ return tepIdReferences.get(tep);
+ }
+
+ public void decRefCount(InstanceIdentifier reference, InstanceIdentifier tep) {
+ if (reference == null || tep == null || !tepIdReferences.containsKey(tep)) {
+ return;
+ }
+ //synchronize to make sure that no two parallel deletes puts the key in transit state twice
+ synchronized (this) {
+ boolean removed = tepIdReferences.get(tep).remove(reference);
+ if (removed && tepIdReferences.get(tep).isEmpty()) {
+ LOG.debug("Marking the termination point as in transit ref count zero {} ", tep);
+ markKeyAsInTransit(TerminationPoint.class, tep);
+ }
+ }
+ }
+
+ public void clearLogicalSwitchRefs(InstanceIdentifier<LogicalSwitches> logicalSwitchKey) {
+ Map<InstanceIdentifier<RemoteMcastMacs>, RemoteMcastMacs> mcasts = logicalSwitchVsMcasts.get(logicalSwitchKey);
+ if (mcasts != null ) {
+ mcasts.entrySet().forEach( (entry) -> removeRemoteMcast(logicalSwitchKey, entry.getKey()));
+ }
+ Map<InstanceIdentifier<RemoteUcastMacs>, RemoteUcastMacs> ucasts = logicalSwitchVsUcasts.get(logicalSwitchKey);
+ if (ucasts != null ) {
+ ucasts.entrySet().forEach( (entry) -> removeRemoteUcast(logicalSwitchKey, entry.getKey()));
+ }
+ markKeyAsInTransit(LogicalSwitches.class, logicalSwitchKey);
+ }
+
+ public void updateRemoteMcast(InstanceIdentifier<LogicalSwitches> lsIid,
+ InstanceIdentifier<RemoteMcastMacs> mcastIid,
+ RemoteMcastMacs mac) {
+ logicalSwitchVsMcasts.computeIfAbsent(lsIid, (lsKey) -> new ConcurrentHashMap<>());
+ logicalSwitchVsMcasts.get(lsIid).put(mcastIid, mac);
+ if (mac.getLocatorSet() != null) {
+ mac.getLocatorSet().forEach( (iid) -> incRefCount(mcastIid, iid.getLocatorRef().getValue()));
+ }
+ }
+
+ public void updateRemoteUcast(InstanceIdentifier<LogicalSwitches> lsIid,
+ InstanceIdentifier<RemoteUcastMacs> ucastIid,
+ RemoteUcastMacs mac) {
+ logicalSwitchVsUcasts.computeIfAbsent(lsIid, (lsKey) -> new ConcurrentHashMap<>());
+ logicalSwitchVsUcasts.get(lsIid).put(ucastIid, mac);
+ incRefCount(ucastIid, mac.getLocatorRef().getValue());
+ }
+
+ public void removeRemoteMcast(InstanceIdentifier<LogicalSwitches> lsIid, InstanceIdentifier<RemoteMcastMacs> mcastIid) {
+ if (!logicalSwitchVsMcasts.containsKey(lsIid)) {
+ return;
+ }
+ RemoteMcastMacs mac = logicalSwitchVsMcasts.get(lsIid).remove(mcastIid);
+ if (mac != null && mac.getLocatorSet() != null) {
+ mac.getLocatorSet().forEach((iid) -> decRefCount(mcastIid, iid.getLocatorRef().getValue()));
+ }
+ markKeyAsInTransit(RemoteMcastMacs.class, mcastIid);
+ }
+
+ public void removeRemoteUcast(InstanceIdentifier<LogicalSwitches> lsIid,
+ InstanceIdentifier<RemoteUcastMacs> ucastIid) {
+ if (!logicalSwitchVsUcasts.containsKey(lsIid)) {
+ return;
+ }
+ RemoteUcastMacs mac = logicalSwitchVsUcasts.get(lsIid).remove(ucastIid);
+ if (mac != null) {
+ decRefCount(ucastIid, mac.getLocatorRef().getValue());
+ }
+ markKeyAsInTransit(RemoteUcastMacs.class, ucastIid);
+ }
+
+ public HwvtepConnectionInstance getConnectionInstance() {
+ return connectionInstance;