Bump upstreams for 2022.09 Chlorine
[ovsdb.git] / hwvtepsouthbound / hwvtepsouthbound-impl / src / main / java / org / opendaylight / ovsdb / hwvtepsouthbound / transact / HwvtepOperationalState.java
index e3ad78a438dad10132c38e7746b80cdf25272adf..afe4c7a40df8836d165a7d272e8ee3f5e9519576 100644 (file)
@@ -1,34 +1,47 @@
 /*
- * Copyright (c) 2015 China Telecom Beijing Research Institute and others.  All rights reserved.
+ * Copyright (c) 2015, 2017 China Telecom Beijing Research Institute and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.ovsdb.hwvtepsouthbound.transact;
 
+import static java.util.Objects.requireNonNull;
+
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
-
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
-import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import org.apache.commons.lang3.tuple.Pair;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.DataTreeModification;
+import org.opendaylight.mdsal.binding.api.ReadWriteTransaction;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepConnectionInstance;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepDeviceInfo;
 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundUtil;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.ovsdb.lib.notation.UUID;
+import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.EncapsulationTypeBase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepNodeName;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalLocatorAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalPortAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Acls;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalMcastMacs;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalMcastMacsKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalUcastMacs;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalUcastMacsKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalRouters;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalRoutersKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitchesKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacs;
@@ -36,39 +49,114 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hw
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteUcastMacs;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteUcastMacsKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Switches;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.Tunnels;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.TunnelsKey;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
+import org.opendaylight.yangtools.yang.binding.Identifiable;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
 
 //TODO: need to be optimized, get entry by iid not name
 public class HwvtepOperationalState {
+
     private static final Logger LOG = LoggerFactory.getLogger(HwvtepOperationalState.class);
-    private Map<InstanceIdentifier<Node>, Node> operationalNodes = new HashMap<>();
-    ReadWriteTransaction transaction;
 
-    public HwvtepOperationalState(DataBroker db, Collection<DataTreeModification<Node>> changes) {
+    private final Map<InstanceIdentifier<Node>, Node> operationalNodes = new HashMap<>();
+    private ReadWriteTransaction transaction;
+    HashMap<InstanceIdentifier<TerminationPoint>, UUID> inflightLocators = new HashMap<>();
+    private final HwvtepDeviceInfo deviceInfo;
+    private final HwvtepConnectionInstance connectionInstance;
+    private final Map<Class<? extends Identifiable>, Map<InstanceIdentifier, UUID>> currentTxUUIDs =
+            new ConcurrentHashMap<>();
+    private final Map<Class<? extends Identifiable>, Map<InstanceIdentifier, Boolean>> currentTxDeletedKeys =
+            new ConcurrentHashMap<>();
+
+    /* stores the modified and deleted data for each child type of each node id
+       Map<nodeid , Pair < updated, deleted >
+       each updated/ deleted contains Map < child type, List<ChildData>>
+       child type is the child of hwvtep Global augmentation
+     */
+    private Map<InstanceIdentifier<Node>,
+            Pair<Map<Class<? extends Identifiable>, List<Identifiable>>,
+                    Map<Class<? extends Identifiable>, List<Identifiable>>>> modifiedData = new HashMap<>();
+    private boolean inReconciliation = false;
+    private final DataBroker db;
+    private final Collection<DataTreeModification<Node>> changes;
+    long transactionId = 0;
+
+    public HwvtepOperationalState(final DataBroker db, final HwvtepConnectionInstance connectionInstance,
+                                  final Collection<DataTreeModification<Node>> changes) {
+        this.connectionInstance = connectionInstance;
+        deviceInfo = connectionInstance.getDeviceInfo();
+        this.db = db;
+        this.changes = changes;
+        transaction = db.newReadWriteTransaction();
+    }
+
+    public HwvtepOperationalState(final HwvtepConnectionInstance connectionInstance) {
+        this.connectionInstance = connectionInstance;
+        deviceInfo = connectionInstance.getDeviceInfo();
+        db = connectionInstance.getDataBroker();
+        changes = null;
+        transaction = connectionInstance.getDataBroker().newReadWriteTransaction();
+        Optional<Node> readNode = new MdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL,
+                connectionInstance.getInstanceIdentifier());
+        if (readNode.isPresent()) {
+            operationalNodes.put(connectionInstance.getInstanceIdentifier(), readNode.get());
+        }
+    }
+
+    public HwvtepOperationalState(final DataBroker db,
+                                  final HwvtepConnectionInstance connectionInstance,
+                                  final Collection<DataTreeModification<Node>> changes,
+                                  final Node globalOperNode,
+                                  final Node psNode) {
+        this(db, connectionInstance, changes);
+        operationalNodes.put(connectionInstance.getInstanceIdentifier(), globalOperNode);
+        HwvtepGlobalAugmentation globalAugmentation = globalOperNode.augmentation(HwvtepGlobalAugmentation.class);
+        if (globalAugmentation != null) {
+            if (!HwvtepSouthboundUtil.isEmptyMap(globalAugmentation.getSwitches())) {
+                operationalNodes.put((InstanceIdentifier<Node>)
+                        globalAugmentation.getSwitches().values().iterator().next().getSwitchRef().getValue(), psNode);
+            }
+        }
+    }
+
+    public void readOperationalNodes() {
+        if (inReconciliation) {
+            return;
+        }
+        if (changes == null) {
+            LOG.warn("Could not read operational nodes for {} as changes is",
+                    connectionInstance.getNodeId().getValue());
+            return;
+        }
         Map<InstanceIdentifier<Node>, Node> nodeCreateOrUpdate =
-            TransactUtils.extractCreatedOrUpdatedOrRemoved(changes, Node.class);
+                TransactUtils.extractCreatedOrUpdatedOrRemoved(changes, Node.class);
         if (nodeCreateOrUpdate != null) {
             transaction = db.newReadWriteTransaction();
             for (Entry<InstanceIdentifier<Node>, Node> entry: nodeCreateOrUpdate.entrySet()) {
-                Optional<Node> readNode = HwvtepSouthboundUtil.readNode(transaction, entry.getKey());
+                Optional<Node> readNode = new MdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL,
+                        entry.getKey());
                 //add related globalNode or physicalSwitchNode to operationalNodes map
                 //for example, when creating physical port, logical switch is needed
                 //but logical switch is in HwvtepGlobalAugmentation rather than PhysicalSwitchAugmentation
                 if (readNode.isPresent()) {
                     operationalNodes.put(entry.getKey(), readNode.get());
-                    HwvtepGlobalAugmentation hgAugmentation = readNode.get().getAugmentation(HwvtepGlobalAugmentation.class);
-                    PhysicalSwitchAugmentation psAugmentation = readNode.get().getAugmentation(PhysicalSwitchAugmentation.class);
-                    if (hgAugmentation != null) {
-                        for (Switches pswitch : hgAugmentation.getSwitches()) {
+                    HwvtepGlobalAugmentation hgAugmentation =
+                            readNode.get().augmentation(HwvtepGlobalAugmentation.class);
+                    PhysicalSwitchAugmentation psAugmentation =
+                            readNode.get().augmentation(PhysicalSwitchAugmentation.class);
+                    if (hgAugmentation != null && hgAugmentation.getSwitches() != null) {
+                        for (Switches pswitch : hgAugmentation.getSwitches().values()) {
                             @SuppressWarnings("unchecked")
-                            InstanceIdentifier<Node> psNodeIid = (InstanceIdentifier<Node>) pswitch.getSwitchRef().getValue();
-                            Optional<Node> psNode = HwvtepSouthboundUtil.readNode(transaction, psNodeIid);
+                            InstanceIdentifier<Node> psNodeIid =
+                                    (InstanceIdentifier<Node>) pswitch.getSwitchRef().getValue();
+                            Optional<Node> psNode =
+                                new MdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, psNodeIid);
                             if (psNode.isPresent()) {
                                 operationalNodes.put(psNodeIid, psNode.get());
                             }
@@ -76,8 +164,10 @@ public class HwvtepOperationalState {
                     }
                     if (psAugmentation != null) {
                         @SuppressWarnings("unchecked")
-                        InstanceIdentifier<Node> hgNodeIid = (InstanceIdentifier<Node>) psAugmentation.getManagedBy().getValue();
-                        Optional<Node> hgNode = HwvtepSouthboundUtil.readNode(transaction, hgNodeIid);
+                        InstanceIdentifier<Node> hgNodeIid =
+                                (InstanceIdentifier<Node>) psAugmentation.getManagedBy().getValue();
+                        Optional<Node> hgNode = new MdsalUtils(db).readOptional(
+                                LogicalDatastoreType.OPERATIONAL, hgNodeIid);
                         if (hgNode.isPresent()) {
                             operationalNodes.put(hgNodeIid, hgNode.get());
                         }
@@ -87,180 +177,273 @@ public class HwvtepOperationalState {
         }
     }
 
-    private Optional<Node> getGlobalNode(InstanceIdentifier<?> iid) {
+    public Optional<Node> getGlobalNode(final InstanceIdentifier<?> iid) {
         InstanceIdentifier<Node> nodeIid = iid.firstIdentifierOf(Node.class);
-        return Optional.fromNullable(operationalNodes.get(nodeIid));
+        return Optional.ofNullable(operationalNodes.get(nodeIid));
     }
 
-    public Optional<HwvtepGlobalAugmentation> getHwvtepGlobalAugmentation(InstanceIdentifier<?> iid) {
-        Preconditions.checkNotNull(iid);
-        Optional<Node> nodeOptional = getGlobalNode(iid);
+    public Optional<HwvtepGlobalAugmentation> getHwvtepGlobalAugmentation(final InstanceIdentifier<?> iid) {
+        Optional<Node> nodeOptional = getGlobalNode(requireNonNull(iid));
         if (nodeOptional.isPresent()) {
-            return Optional.fromNullable(nodeOptional.get().getAugmentation(HwvtepGlobalAugmentation.class));
+            return Optional.ofNullable(nodeOptional.get().augmentation(HwvtepGlobalAugmentation.class));
         }
-        return Optional.absent();
+        return Optional.empty();
     }
 
-    public Optional<PhysicalSwitchAugmentation> getPhysicalSwitchAugmentation(InstanceIdentifier<?> iid) {
-        Preconditions.checkNotNull(iid);
-        Optional<Node> nodeOptional = getGlobalNode(iid);
+    public Optional<PhysicalSwitchAugmentation> getPhysicalSwitchAugmentation(final InstanceIdentifier<?> iid) {
+        Optional<Node> nodeOptional = getGlobalNode(requireNonNull(iid));
         if (nodeOptional.isPresent()) {
-            return Optional.fromNullable(nodeOptional.get().getAugmentation(PhysicalSwitchAugmentation.class));
+            return Optional.ofNullable(nodeOptional.get().augmentation(PhysicalSwitchAugmentation.class));
         }
-        return Optional.absent();
+        return Optional.empty();
     }
 
-    public Optional<List<TerminationPoint>> getTerminationPointList(InstanceIdentifier<?> iid) {
-        Preconditions.checkNotNull(iid);
-        Optional<Node> nodeOptional = getGlobalNode(iid);
+    public Optional<Map<TerminationPointKey, TerminationPoint>> getTerminationPointList(
+            final InstanceIdentifier<?> iid) {
+        Optional<Node> nodeOptional = getGlobalNode(requireNonNull(iid));
         if (nodeOptional.isPresent() && nodeOptional.get().getTerminationPoint() != null) {
-            return Optional.fromNullable(nodeOptional.get().getTerminationPoint());
+            return Optional.ofNullable(nodeOptional.get().getTerminationPoint());
         }
-        return Optional.absent();
+        return Optional.empty();
     }
 
-    public Optional<LogicalSwitches> getLogicalSwitches(InstanceIdentifier<?> iid, LogicalSwitchesKey logicalSwitchesKey) {
-        Preconditions.checkNotNull(iid);
-        Optional<HwvtepGlobalAugmentation> nodeOptional = getHwvtepGlobalAugmentation(iid);
+    public Optional<LogicalSwitches> getLogicalSwitches(final InstanceIdentifier<?> iid,
+            final LogicalSwitchesKey logicalSwitchesKey) {
+        Optional<HwvtepGlobalAugmentation> nodeOptional = getHwvtepGlobalAugmentation(requireNonNull(iid));
         if (nodeOptional.isPresent()) {
-            HwvtepGlobalAugmentation hgAugmentation = nodeOptional.get();
-            List<LogicalSwitches> lswitchList = null;
-            if (hgAugmentation != null) {
-                lswitchList = hgAugmentation.getLogicalSwitches();
+            LogicalSwitches lswitch = nodeOptional.get().nonnullLogicalSwitches().get(logicalSwitchesKey);
+            if (lswitch != null) {
+                return Optional.of(lswitch);
             }
-            if (lswitchList != null) {
-                for (LogicalSwitches lswitch: lswitchList) {
-                    if (lswitch.getKey().equals(logicalSwitchesKey)) {
-                        return Optional.fromNullable(lswitch);
-                    }
-                }
+        }
+        return Optional.empty();
+    }
+
+    public Optional<LogicalSwitches> getLogicalSwitches(final InstanceIdentifier<LogicalSwitches> iid) {
+        return new MdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, iid);
+    }
+
+    public Optional<Tunnels> getTunnels(final InstanceIdentifier<?> iid, final TunnelsKey tunnelsKey) {
+        Optional<PhysicalSwitchAugmentation> psOptional = getPhysicalSwitchAugmentation(requireNonNull(iid));
+        if (psOptional.isPresent()) {
+            Tunnels tunnel = psOptional.get().nonnullTunnels().get(tunnelsKey);
+            if (tunnel != null) {
+                return Optional.of(tunnel);
             }
         }
-        return Optional.absent();
+        return Optional.empty();
+    }
+
+    public Optional<Tunnels> getTunnels(final InstanceIdentifier<Tunnels> iid) {
+        Optional<Tunnels> tunnels = new MdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, iid);
+        return tunnels;
     }
 
-    public Optional<HwvtepPhysicalPortAugmentation> getPhysicalPortAugmentation(InstanceIdentifier<?> iid,
-            HwvtepNodeName hwvtepNodeName) {
-        Preconditions.checkNotNull(iid);
-        Optional<List<TerminationPoint>> nodeOptional = getTerminationPointList(iid);
+    public Optional<HwvtepPhysicalPortAugmentation> getPhysicalPortAugmentation(final InstanceIdentifier<?> iid,
+            final HwvtepNodeName hwvtepNodeName) {
+        Optional<Map<TerminationPointKey, TerminationPoint>> nodeOptional =
+                getTerminationPointList(requireNonNull(iid));
         if (nodeOptional.isPresent()) {
-            List<TerminationPoint> tpList = nodeOptional.get();
-            for (TerminationPoint tp : tpList) {
-                HwvtepPhysicalPortAugmentation hppAugmentation = tp.getAugmentation(HwvtepPhysicalPortAugmentation.class);
-                if (hppAugmentation.getHwvtepNodeName().equals(hwvtepNodeName)) {
-                    return Optional.fromNullable(hppAugmentation);
+            for (TerminationPoint tp : nodeOptional.get().values()) {
+                HwvtepPhysicalPortAugmentation hppAugmentation =
+                        tp.augmentation(HwvtepPhysicalPortAugmentation.class);
+                if (hppAugmentation != null && hppAugmentation.getHwvtepNodeName().equals(hwvtepNodeName)) {
+                    return Optional.ofNullable(hppAugmentation);
                 }
             }
         }
-        return Optional.absent();
+        return Optional.empty();
     }
 
-    public Optional<HwvtepPhysicalLocatorAugmentation> getPhysicalLocatorAugmentation(InstanceIdentifier<?> iid,
-            IpAddress dstIp, Class<? extends EncapsulationTypeBase> encapType) {
-        Preconditions.checkNotNull(iid);
-        Optional<List<TerminationPoint>> nodeOptional = getTerminationPointList(iid);
+    public Optional<HwvtepPhysicalLocatorAugmentation> getPhysicalLocatorAugmentation(final InstanceIdentifier<?> iid,
+            final IpAddress dstIp, final EncapsulationTypeBase encapType) {
+        Optional<Map<TerminationPointKey, TerminationPoint>> nodeOptional =
+                getTerminationPointList(requireNonNull(iid));
         if (nodeOptional.isPresent()) {
-            List<TerminationPoint> tpList = nodeOptional.get();
-            for (TerminationPoint tp : tpList) {
-                HwvtepPhysicalLocatorAugmentation hppAugmentation = tp.getAugmentation(HwvtepPhysicalLocatorAugmentation.class);
-                if (hppAugmentation.getDstIp().equals(dstIp)
+            for (TerminationPoint tp : nodeOptional.get().values()) {
+                HwvtepPhysicalLocatorAugmentation hppAugmentation =
+                        tp.augmentation(HwvtepPhysicalLocatorAugmentation.class);
+                if (hppAugmentation != null && hppAugmentation.getDstIp().equals(dstIp)
                         && hppAugmentation.getEncapsulationType().equals(encapType)) {
-                    return Optional.fromNullable(hppAugmentation);
+                    return Optional.ofNullable(hppAugmentation);
                 }
             }
         }
-        return Optional.absent();
+        return Optional.empty();
     }
 
-    public Optional<LocalMcastMacs> getLocalMcastMacs(InstanceIdentifier<?> iid, LocalMcastMacsKey key) {
-        Preconditions.checkNotNull(iid);
-        Optional<HwvtepGlobalAugmentation> nodeOptional = getHwvtepGlobalAugmentation(iid);
+    public Optional<HwvtepPhysicalLocatorAugmentation>
+            getPhysicalLocatorAugmentation(final InstanceIdentifier<TerminationPoint> iid) {
+        Optional<TerminationPoint> tp =
+            new MdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, iid);
+        if (tp.isPresent()) {
+            return Optional.ofNullable(tp.get().augmentation(HwvtepPhysicalLocatorAugmentation.class));
+        }
+        return Optional.empty();
+    }
+
+    public Optional<LocalMcastMacs> getLocalMcastMacs(final InstanceIdentifier<?> iid, final LocalMcastMacsKey key) {
+        Optional<HwvtepGlobalAugmentation> nodeOptional = getHwvtepGlobalAugmentation(requireNonNull(iid));
         if (nodeOptional.isPresent()) {
-            HwvtepGlobalAugmentation hgAugmentation = nodeOptional.get();
-            List<LocalMcastMacs> macList = null;
-            if (hgAugmentation != null) {
-                macList = hgAugmentation.getLocalMcastMacs();
-            }
-            if (macList != null) {
-                for (LocalMcastMacs mac: macList) {
-                    if (mac.getKey().equals(key)) {
-                        return Optional.fromNullable(mac);
-                    }
-                }
+            LocalMcastMacs mac = nodeOptional.get().nonnullLocalMcastMacs().get(key);
+            if (mac != null) {
+                return Optional.of(mac);
             }
         }
-        return Optional.absent();
+        return Optional.empty();
     }
 
-    public Optional<RemoteMcastMacs> getRemoteMcastMacs(InstanceIdentifier<?> iid, RemoteMcastMacsKey key) {
-        Preconditions.checkNotNull(iid);
-        Optional<HwvtepGlobalAugmentation> nodeOptional = getHwvtepGlobalAugmentation(iid);
+    public Optional<RemoteMcastMacs> getRemoteMcastMacs(final InstanceIdentifier<?> iid, final RemoteMcastMacsKey key) {
+        Optional<HwvtepGlobalAugmentation> nodeOptional = getHwvtepGlobalAugmentation(requireNonNull(iid));
         if (nodeOptional.isPresent()) {
-            HwvtepGlobalAugmentation hgAugmentation = nodeOptional.get();
-            List<RemoteMcastMacs> macList = null;
-            if (hgAugmentation != null) {
-                macList = hgAugmentation.getRemoteMcastMacs();
-            }
-            if (macList != null) {
-                for (RemoteMcastMacs mac: macList) {
-                    if (mac.getKey().equals(key)) {
-                        return Optional.fromNullable(mac);
-                    }
-                }
+            RemoteMcastMacs mac = nodeOptional.get().nonnullRemoteMcastMacs().get(key);
+            if (mac != null) {
+                return Optional.of(mac);
             }
         }
-        return Optional.absent();
+        return Optional.empty();
     }
 
-    public Optional<LocalUcastMacs> getLocalUcastMacs(InstanceIdentifier<?> iid, LocalUcastMacsKey key) {
-        Preconditions.checkNotNull(iid);
-        Optional<HwvtepGlobalAugmentation> nodeOptional = getHwvtepGlobalAugmentation(iid);
+    public Optional<LocalUcastMacs> getLocalUcastMacs(final InstanceIdentifier<?> iid, final LocalUcastMacsKey key) {
+        Optional<HwvtepGlobalAugmentation> nodeOptional = getHwvtepGlobalAugmentation(requireNonNull(iid));
         if (nodeOptional.isPresent()) {
-            HwvtepGlobalAugmentation hgAugmentation = nodeOptional.get();
-            List<LocalUcastMacs> macList = null;
-            if (hgAugmentation != null) {
-                macList = hgAugmentation.getLocalUcastMacs();
-            }
-            if (macList != null) {
-                for (LocalUcastMacs mac: macList) {
-                    if (mac.getKey().equals(key)) {
-                        return Optional.fromNullable(mac);
-                    }
-                }
+            LocalUcastMacs mac = nodeOptional.get().nonnullLocalUcastMacs().get(key);
+            if (mac != null) {
+                return Optional.of(mac);
             }
         }
-        return Optional.absent();
+        return Optional.empty();
     }
 
-    public Optional<RemoteUcastMacs> getRemoteUcastMacs(InstanceIdentifier<?> iid, RemoteUcastMacsKey key) {
-        Preconditions.checkNotNull(iid);
-        Optional<HwvtepGlobalAugmentation> nodeOptional = getHwvtepGlobalAugmentation(iid);
+    public Optional<RemoteUcastMacs> getRemoteUcastMacs(final InstanceIdentifier<?> iid, final RemoteUcastMacsKey key) {
+        Optional<HwvtepGlobalAugmentation> nodeOptional = getHwvtepGlobalAugmentation(requireNonNull(iid));
         if (nodeOptional.isPresent()) {
-            HwvtepGlobalAugmentation hgAugmentation = nodeOptional.get();
-            List<RemoteUcastMacs> macList = null;
-            if (hgAugmentation != null) {
-                macList = hgAugmentation.getRemoteUcastMacs();
-            }
-            if (macList != null) {
-                for (RemoteUcastMacs mac: macList) {
-                    if (mac.getKey().equals(key)) {
-                        return Optional.fromNullable(mac);
-                    }
-                }
+            RemoteUcastMacs mac = nodeOptional.get().nonnullRemoteUcastMacs().get(key);
+            if (mac != null) {
+                return Optional.of(mac);
             }
         }
-        return Optional.absent();
+        return Optional.empty();
     }
 
-    public Optional<HwvtepPhysicalLocatorAugmentation> getPhysicalLocatorAugmentation(InstanceIdentifier<TerminationPoint> iid) {
-        Optional<TerminationPoint> tp = HwvtepSouthboundUtil.readNode(transaction, iid);
-        if (tp.isPresent()) {
-            return Optional.fromNullable(tp.get().getAugmentation(HwvtepPhysicalLocatorAugmentation.class));
+    public Optional<LogicalRouters> getLogicalRouters(final InstanceIdentifier<?> iid,
+            final LogicalRoutersKey logicalRoutersKey) {
+        Optional<HwvtepGlobalAugmentation> nodeOptional = getHwvtepGlobalAugmentation(requireNonNull(iid));
+        if (nodeOptional.isPresent()) {
+            LogicalRouters lrouter = nodeOptional.get().nonnullLogicalRouters().get(logicalRoutersKey);
+            if (lrouter != null) {
+                return Optional.of(lrouter);
+            }
         }
-        return Optional.absent();
+        return Optional.empty();
+    }
+
+    public Optional<Acls> getAcls(final InstanceIdentifier<Acls> iid) {
+        Optional<Acls> acl = new MdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, iid);
+        return acl;
     }
-    
+
     public ReadWriteTransaction getReadWriteTransaction() {
         return transaction;
     }
+
+    public void setPhysicalLocatorInFlight(final InstanceIdentifier<TerminationPoint> iid,
+                                           final UUID uuid) {
+        inflightLocators.put(iid, uuid);
+    }
+
+    public UUID getPhysicalLocatorInFlight(final InstanceIdentifier<TerminationPoint> iid) {
+        return inflightLocators.get(iid);
+    }
+
+    public HwvtepConnectionInstance getConnectionInstance() {
+        return connectionInstance;
+    }
+
+    public HwvtepDeviceInfo getDeviceInfo() {
+        return deviceInfo;
+    }
+
+    public void updateCurrentTxData(final Class<? extends Identifiable> cls, final InstanceIdentifier key,
+            final UUID uuid) {
+        HwvtepSouthboundUtil.updateData(currentTxUUIDs, cls, key, uuid);
+    }
+
+    public void updateCurrentTxDeleteData(final Class<? extends Identifiable> cls, final InstanceIdentifier key) {
+        HwvtepSouthboundUtil.updateData(currentTxDeletedKeys, cls, key, Boolean.TRUE);
+    }
+
+    public UUID getUUIDFromCurrentTx(final Class<? extends Identifiable> cls, final InstanceIdentifier key) {
+        return HwvtepSouthboundUtil.getData(currentTxUUIDs, cls, key);
+    }
+
+    public boolean isKeyPartOfCurrentTx(final Class<? extends Identifiable> cls, final InstanceIdentifier key) {
+        return HwvtepSouthboundUtil.containsKey(currentTxUUIDs, cls, key);
+    }
+
+    public Set<InstanceIdentifier> getDeletedKeysInCurrentTx(final Class<? extends Identifiable> cls) {
+        if (currentTxDeletedKeys.containsKey(cls)) {
+            return currentTxDeletedKeys.get(cls).keySet();
+        }
+        return Collections.emptySet();
+    }
+
+    public List<? extends Identifiable> getUpdatedData(final InstanceIdentifier<Node> key,
+                                                       final Class<? extends Identifiable> cls) {
+        List<Identifiable> result = null;
+        if (modifiedData.get(key) != null && modifiedData.get(key).getLeft() != null) {
+            result = modifiedData.get(key).getLeft().get(cls);
+        }
+        if (result == null) {
+            result = Collections.emptyList();
+        }
+        return result;
+    }
+
+    public List<? extends Identifiable> getDeletedData(final InstanceIdentifier<Node> key,
+                                                       final Class<? extends Identifiable> cls) {
+        List<Identifiable> result = null;
+        if (modifiedData.get(key) != null && modifiedData.get(key).getRight() != null) {
+            result = modifiedData.get(key).getRight().get(cls);
+        }
+        if (result == null) {
+            result = Collections.emptyList();
+        }
+        return result;
+    }
+
+    public void setModifiedData(final Map<InstanceIdentifier<Node>,
+            Pair<Map<Class<? extends Identifiable>, List<Identifiable>>,
+                    Map<Class<? extends Identifiable>, List<Identifiable>>>> modifiedData) {
+        this.modifiedData = modifiedData;
+    }
+
+    public boolean isInReconciliation() {
+        return inReconciliation;
+    }
+
+    public void setInReconciliation(final boolean inReconciliation) {
+        this.inReconciliation = inReconciliation;
+    }
+
+    public DataBroker getDataBroker() {
+        return db;
+    }
+
+
+    public void clearIntransitKeys() {
+        currentTxUUIDs.forEach((cls, map) -> {
+            map.forEach((iid, uuid) -> deviceInfo.clearInTransit(cls, iid));
+        });
+        currentTxDeletedKeys.forEach((cls, map) -> {
+            map.forEach((iid, val) -> deviceInfo.clearInTransit(cls, iid));
+        });
+        currentTxUUIDs.clear();
+        currentTxDeletedKeys.clear();
+        deviceInfo.onOperDataAvailable();
+    }
+
+    public long getTransactionId() {
+        return transactionId;
+    }
 }