bug 8029 added ref counts for physical locators.
[ovsdb.git] / hwvtepsouthbound / hwvtepsouthbound-impl / src / main / java / org / opendaylight / ovsdb / hwvtepsouthbound / transact / HwvtepOperationalState.java
1 /*
2  * Copyright (c) 2015, 2017 China Telecom Beijing Research Institute and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.ovsdb.hwvtepsouthbound.transact;
10
11 import com.google.common.base.Optional;
12 import com.google.common.base.Preconditions;
13 import org.apache.commons.lang3.tuple.Pair;
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
16 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
17 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepConnectionInstance;
18 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepDeviceInfo;
19 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundUtil;
20 import org.opendaylight.ovsdb.lib.notation.UUID;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.EncapsulationTypeBase;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepNodeName;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalLocatorAugmentation;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalPortAugmentation;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Acls;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.AclsKey;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalMcastMacs;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalMcastMacsKey;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalUcastMacs;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalUcastMacsKey;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalRouters;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalRoutersKey;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitchesKey;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacs;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacsKey;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteUcastMacs;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteUcastMacsKey;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Switches;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.Tunnels;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.TunnelsKey;
45 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
46 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
47 import org.opendaylight.yangtools.yang.binding.Identifiable;
48 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
49 import org.slf4j.Logger;
50 import org.slf4j.LoggerFactory;
51
52 import java.util.Collection;
53 import java.util.Collections;
54 import java.util.HashMap;
55 import java.util.List;
56 import java.util.Map;
57 import java.util.Map.Entry;
58 import java.util.Set;
59 import java.util.concurrent.ConcurrentHashMap;
60
61 //TODO: need to be optimized, get entry by iid not name
62 public class HwvtepOperationalState {
63
64     private static final Logger LOG = LoggerFactory.getLogger(HwvtepOperationalState.class);
65
66     private Map<InstanceIdentifier<Node>, Node> operationalNodes = new HashMap<>();
67     private ReadWriteTransaction transaction;
68     HashMap<InstanceIdentifier<TerminationPoint>, UUID> inflightLocators = new HashMap<>();
69     private HwvtepDeviceInfo deviceInfo;
70     private HwvtepConnectionInstance connectionInstance;
71     private Map<Class<? extends Identifiable>, Map<InstanceIdentifier, UUID>> currentTxUUIDs = new ConcurrentHashMap<>();
72     private Map<Class<? extends Identifiable>, Map<InstanceIdentifier, Boolean>> currentTxDeletedKeys = new ConcurrentHashMap<>();
73
74     /* stores the modified and deleted data for each child type of each node id
75        Map<nodeid , Pair < updated, deleted >
76        each updated/ deleted contains Map < child type, List<ChildData>>
77        child type is the child of hwvtep Global augmentation
78      */
79     private Map<InstanceIdentifier<Node>,
80             Pair<Map<Class<? extends Identifiable>, List<Identifiable>>,
81                     Map<Class<? extends Identifiable>, List<Identifiable>>>> modifiedData = new HashMap<>();
82     private boolean inReconciliation = false;
83     private final DataBroker db;
84     private final Collection<DataTreeModification<Node>> changes;
85
86     public HwvtepOperationalState(DataBroker db, HwvtepConnectionInstance connectionInstance,
87                                   Collection<DataTreeModification<Node>> changes) {
88         this.connectionInstance = connectionInstance;
89         this.deviceInfo = connectionInstance.getDeviceInfo();
90         this.db = db;
91         this.changes = changes;
92         this.transaction = db.newReadWriteTransaction();
93     }
94
95     public HwvtepOperationalState(HwvtepConnectionInstance connectionInstance) {
96         this.connectionInstance = connectionInstance;
97         this.deviceInfo = connectionInstance.getDeviceInfo();
98         this.db = connectionInstance.getDataBroker();
99         this.changes = null;
100         transaction = connectionInstance.getDataBroker().newReadWriteTransaction();
101         Optional<Node> readNode = HwvtepSouthboundUtil.readNode(transaction,
102                 connectionInstance.getInstanceIdentifier());
103         if (readNode.isPresent()) {
104             operationalNodes.put(connectionInstance.getInstanceIdentifier(), readNode.get());
105         }
106     }
107
108     public HwvtepOperationalState(final DataBroker db,
109                                   final HwvtepConnectionInstance connectionInstance,
110                                   final Collection<DataTreeModification<Node>> changes,
111                                   final Node globalOperNode,
112                                   final Node psNode) {
113         this(db, connectionInstance, changes);
114         operationalNodes.put(connectionInstance.getInstanceIdentifier(), globalOperNode);
115         HwvtepGlobalAugmentation globalAugmentation = globalOperNode.getAugmentation(HwvtepGlobalAugmentation.class);
116         if (globalAugmentation != null) {
117             if (!HwvtepSouthboundUtil.isEmpty(globalAugmentation.getSwitches())) {
118                 operationalNodes.put((InstanceIdentifier<Node>)
119                         globalAugmentation.getSwitches().get(0).getSwitchRef().getValue(), psNode);
120             }
121         }
122     }
123
124     public void readOperationalNodes() {
125         if (inReconciliation) {
126             return;
127         }
128         if (changes == null) {
129             LOG.warn("Could not read operational nodes for {} as changes is",
130                     connectionInstance.getNodeId().getValue());
131             return;
132         }
133         Map<InstanceIdentifier<Node>, Node> nodeCreateOrUpdate =
134                 TransactUtils.extractCreatedOrUpdatedOrRemoved(changes, Node.class);
135         if (nodeCreateOrUpdate != null) {
136             transaction = db.newReadWriteTransaction();
137             for (Entry<InstanceIdentifier<Node>, Node> entry: nodeCreateOrUpdate.entrySet()) {
138                 Optional<Node> readNode = HwvtepSouthboundUtil.readNode(transaction, entry.getKey());
139                 //add related globalNode or physicalSwitchNode to operationalNodes map
140                 //for example, when creating physical port, logical switch is needed
141                 //but logical switch is in HwvtepGlobalAugmentation rather than PhysicalSwitchAugmentation
142                 if (readNode.isPresent()) {
143                     operationalNodes.put(entry.getKey(), readNode.get());
144                     HwvtepGlobalAugmentation hgAugmentation = readNode.get().getAugmentation(HwvtepGlobalAugmentation.class);
145                     PhysicalSwitchAugmentation psAugmentation = readNode.get().getAugmentation(PhysicalSwitchAugmentation.class);
146                     if (hgAugmentation != null && hgAugmentation.getSwitches() != null) {
147                         for (Switches pswitch : hgAugmentation.getSwitches()) {
148                             @SuppressWarnings("unchecked")
149                             InstanceIdentifier<Node> psNodeIid = (InstanceIdentifier<Node>) pswitch.getSwitchRef().getValue();
150                             Optional<Node> psNode = HwvtepSouthboundUtil.readNode(transaction, psNodeIid);
151                             if (psNode.isPresent()) {
152                                 operationalNodes.put(psNodeIid, psNode.get());
153                             }
154                         }
155                     }
156                     if (psAugmentation != null) {
157                         @SuppressWarnings("unchecked")
158                         InstanceIdentifier<Node> hgNodeIid = (InstanceIdentifier<Node>) psAugmentation.getManagedBy().getValue();
159                         Optional<Node> hgNode = HwvtepSouthboundUtil.readNode(transaction, hgNodeIid);
160                         if (hgNode.isPresent()) {
161                             operationalNodes.put(hgNodeIid, hgNode.get());
162                         }
163                     }
164                 }
165             }
166         }
167     }
168
169     public Optional<Node> getGlobalNode(InstanceIdentifier<?> iid) {
170         InstanceIdentifier<Node> nodeIid = iid.firstIdentifierOf(Node.class);
171         return Optional.fromNullable(operationalNodes.get(nodeIid));
172     }
173
174     public Optional<HwvtepGlobalAugmentation> getHwvtepGlobalAugmentation(InstanceIdentifier<?> iid) {
175         Preconditions.checkNotNull(iid);
176         Optional<Node> nodeOptional = getGlobalNode(iid);
177         if (nodeOptional.isPresent()) {
178             return Optional.fromNullable(nodeOptional.get().getAugmentation(HwvtepGlobalAugmentation.class));
179         }
180         return Optional.absent();
181     }
182
183     public Optional<PhysicalSwitchAugmentation> getPhysicalSwitchAugmentation(InstanceIdentifier<?> iid) {
184         Preconditions.checkNotNull(iid);
185         Optional<Node> nodeOptional = getGlobalNode(iid);
186         if (nodeOptional.isPresent()) {
187             return Optional.fromNullable(nodeOptional.get().getAugmentation(PhysicalSwitchAugmentation.class));
188         }
189         return Optional.absent();
190     }
191
192     public Optional<List<TerminationPoint>> getTerminationPointList(InstanceIdentifier<?> iid) {
193         Preconditions.checkNotNull(iid);
194         Optional<Node> nodeOptional = getGlobalNode(iid);
195         if (nodeOptional.isPresent() && nodeOptional.get().getTerminationPoint() != null) {
196             return Optional.fromNullable(nodeOptional.get().getTerminationPoint());
197         }
198         return Optional.absent();
199     }
200
201     public Optional<LogicalSwitches> getLogicalSwitches(InstanceIdentifier<?> iid, LogicalSwitchesKey logicalSwitchesKey) {
202         Preconditions.checkNotNull(iid);
203         Optional<HwvtepGlobalAugmentation> nodeOptional = getHwvtepGlobalAugmentation(iid);
204         if (nodeOptional.isPresent()) {
205             HwvtepGlobalAugmentation hgAugmentation = nodeOptional.get();
206             List<LogicalSwitches> lswitchList = null;
207             if (hgAugmentation != null) {
208                 lswitchList = hgAugmentation.getLogicalSwitches();
209             }
210             if (lswitchList != null) {
211                 for (LogicalSwitches lswitch: lswitchList) {
212                     if (lswitch.getKey().equals(logicalSwitchesKey)) {
213                         return Optional.fromNullable(lswitch);
214                     }
215                 }
216             }
217         }
218         return Optional.absent();
219     }
220
221     public Optional<Tunnels> getTunnels(InstanceIdentifier<?> iid, TunnelsKey tunnelsKey) {
222         Preconditions.checkNotNull(iid);
223         Optional<PhysicalSwitchAugmentation> psOptional = getPhysicalSwitchAugmentation(iid);
224         if (psOptional.isPresent()) {
225             PhysicalSwitchAugmentation psAugmentation = psOptional.get();
226             List<Tunnels> tunnelList = null;
227             if (psAugmentation != null) {
228                 tunnelList = psAugmentation.getTunnels();
229             }
230             if (tunnelList != null) {
231                 for (Tunnels tunnel: tunnelList) {
232                     if (tunnel.getKey().equals(tunnelsKey)) {
233                         return Optional.fromNullable(tunnel);
234                     }
235                 }
236             }
237         }
238         return Optional.absent();
239     }
240
241     public Optional<HwvtepPhysicalPortAugmentation> getPhysicalPortAugmentation(InstanceIdentifier<?> iid,
242             HwvtepNodeName hwvtepNodeName) {
243         Preconditions.checkNotNull(iid);
244         Optional<List<TerminationPoint>> nodeOptional = getTerminationPointList(iid);
245         if (nodeOptional.isPresent()) {
246             List<TerminationPoint> tpList = nodeOptional.get();
247             for (TerminationPoint tp : tpList) {
248                 HwvtepPhysicalPortAugmentation hppAugmentation = tp.getAugmentation(HwvtepPhysicalPortAugmentation.class);
249                 if (hppAugmentation != null && hppAugmentation.getHwvtepNodeName().equals(hwvtepNodeName)) {
250                     return Optional.fromNullable(hppAugmentation);
251                 }
252             }
253         }
254         return Optional.absent();
255     }
256
257     public Optional<HwvtepPhysicalLocatorAugmentation> getPhysicalLocatorAugmentation(InstanceIdentifier<?> iid,
258             IpAddress dstIp, Class<? extends EncapsulationTypeBase> encapType) {
259         Preconditions.checkNotNull(iid);
260         Optional<List<TerminationPoint>> nodeOptional = getTerminationPointList(iid);
261         if (nodeOptional.isPresent()) {
262             List<TerminationPoint> tpList = nodeOptional.get();
263             for (TerminationPoint tp : tpList) {
264                 HwvtepPhysicalLocatorAugmentation hppAugmentation = tp.getAugmentation(HwvtepPhysicalLocatorAugmentation.class);
265                 if (hppAugmentation != null && hppAugmentation.getDstIp().equals(dstIp)
266                         && hppAugmentation.getEncapsulationType().equals(encapType)) {
267                     return Optional.fromNullable(hppAugmentation);
268                 }
269             }
270         }
271         return Optional.absent();
272     }
273
274     public Optional<LocalMcastMacs> getLocalMcastMacs(InstanceIdentifier<?> iid, LocalMcastMacsKey key) {
275         Preconditions.checkNotNull(iid);
276         Optional<HwvtepGlobalAugmentation> nodeOptional = getHwvtepGlobalAugmentation(iid);
277         if (nodeOptional.isPresent()) {
278             HwvtepGlobalAugmentation hgAugmentation = nodeOptional.get();
279             List<LocalMcastMacs> macList = null;
280             if (hgAugmentation != null) {
281                 macList = hgAugmentation.getLocalMcastMacs();
282             }
283             if (macList != null) {
284                 for (LocalMcastMacs mac: macList) {
285                     if (mac.getKey().equals(key)) {
286                         return Optional.fromNullable(mac);
287                     }
288                 }
289             }
290         }
291         return Optional.absent();
292     }
293
294     public Optional<RemoteMcastMacs> getRemoteMcastMacs(InstanceIdentifier<?> iid, RemoteMcastMacsKey key) {
295         Preconditions.checkNotNull(iid);
296         Optional<HwvtepGlobalAugmentation> nodeOptional = getHwvtepGlobalAugmentation(iid);
297         if (nodeOptional.isPresent()) {
298             HwvtepGlobalAugmentation hgAugmentation = nodeOptional.get();
299             List<RemoteMcastMacs> macList = null;
300             if (hgAugmentation != null) {
301                 macList = hgAugmentation.getRemoteMcastMacs();
302             }
303             if (macList != null) {
304                 for (RemoteMcastMacs mac: macList) {
305                     if (mac.getKey().equals(key)) {
306                         return Optional.fromNullable(mac);
307                     }
308                 }
309             }
310         }
311         return Optional.absent();
312     }
313
314     public Optional<LocalUcastMacs> getLocalUcastMacs(InstanceIdentifier<?> iid, LocalUcastMacsKey key) {
315         Preconditions.checkNotNull(iid);
316         Optional<HwvtepGlobalAugmentation> nodeOptional = getHwvtepGlobalAugmentation(iid);
317         if (nodeOptional.isPresent()) {
318             HwvtepGlobalAugmentation hgAugmentation = nodeOptional.get();
319             List<LocalUcastMacs> macList = null;
320             if (hgAugmentation != null) {
321                 macList = hgAugmentation.getLocalUcastMacs();
322             }
323             if (macList != null) {
324                 for (LocalUcastMacs mac: macList) {
325                     if (mac.getKey().equals(key)) {
326                         return Optional.fromNullable(mac);
327                     }
328                 }
329             }
330         }
331         return Optional.absent();
332     }
333
334     public Optional<RemoteUcastMacs> getRemoteUcastMacs(InstanceIdentifier<?> iid, RemoteUcastMacsKey key) {
335         Preconditions.checkNotNull(iid);
336         Optional<HwvtepGlobalAugmentation> nodeOptional = getHwvtepGlobalAugmentation(iid);
337         if (nodeOptional.isPresent()) {
338             HwvtepGlobalAugmentation hgAugmentation = nodeOptional.get();
339             List<RemoteUcastMacs> macList = null;
340             if (hgAugmentation != null) {
341                 macList = hgAugmentation.getRemoteUcastMacs();
342             }
343             if (macList != null) {
344                 for (RemoteUcastMacs mac: macList) {
345                     if (mac.getKey().equals(key)) {
346                         return Optional.fromNullable(mac);
347                     }
348                 }
349             }
350         }
351         return Optional.absent();
352     }
353
354     public Optional<LogicalRouters> getLogicalRouters(final InstanceIdentifier<?> iid,
355             final LogicalRoutersKey logicalRoutersKey) {
356         Preconditions.checkNotNull(iid);
357         Optional<HwvtepGlobalAugmentation> nodeOptional = getHwvtepGlobalAugmentation(iid);
358         if (nodeOptional.isPresent()) {
359             HwvtepGlobalAugmentation hgAugmentation = nodeOptional.get();
360             if (hgAugmentation != null && hgAugmentation.getLogicalRouters() != null) {
361                 for (LogicalRouters lrouter: hgAugmentation.getLogicalRouters()) {
362                     if (lrouter.getKey().equals(logicalRoutersKey)) {
363                         return Optional.fromNullable(lrouter);
364                     }
365                 }
366             }
367         }
368         return Optional.absent();
369     }
370
371     public Optional<HwvtepPhysicalLocatorAugmentation> getPhysicalLocatorAugmentation(InstanceIdentifier<TerminationPoint> iid) {
372         Optional<TerminationPoint> tp = HwvtepSouthboundUtil.readNode(transaction, iid);
373         if (tp.isPresent()) {
374             return Optional.fromNullable(tp.get().getAugmentation(HwvtepPhysicalLocatorAugmentation.class));
375         }
376         return Optional.absent();
377     }
378
379     public Optional<LogicalSwitches> getLogicalSwitches(InstanceIdentifier<LogicalSwitches> iid) {
380         Optional<LogicalSwitches> lswitch = HwvtepSouthboundUtil.readNode(transaction, iid);
381         return lswitch;
382     }
383
384     public Optional<Tunnels> getTunnels(InstanceIdentifier<Tunnels> iid) {
385         Optional<Tunnels> tunnels = HwvtepSouthboundUtil.readNode(transaction, iid);
386         return tunnels;
387     }
388
389     public Optional<Acls> getAcls(InstanceIdentifier<Acls> iid) {
390         Optional<Acls> acl = HwvtepSouthboundUtil.readNode(transaction, iid);
391         return acl;
392     }
393
394     public ReadWriteTransaction getReadWriteTransaction() {
395         return transaction;
396     }
397
398     public void setPhysicalLocatorInFlight(InstanceIdentifier<TerminationPoint> iid,
399                                            UUID uuid) {
400         inflightLocators.put(iid, uuid);
401     }
402
403     public UUID getPhysicalLocatorInFlight(InstanceIdentifier<TerminationPoint> iid) {
404         return inflightLocators.get(iid);
405     }
406
407     public HwvtepConnectionInstance getConnectionInstance() {
408         return connectionInstance;
409     }
410
411     public HwvtepDeviceInfo getDeviceInfo() {
412         return deviceInfo;
413     }
414
415     public void updateCurrentTxData(Class<? extends Identifiable> cls, InstanceIdentifier key, UUID uuid) {
416         HwvtepSouthboundUtil.updateData(currentTxUUIDs, cls, key, uuid);
417     }
418
419     public void updateCurrentTxDeleteData(Class<? extends Identifiable> cls, InstanceIdentifier key) {
420         HwvtepSouthboundUtil.updateData(currentTxDeletedKeys, cls, key, Boolean.TRUE);
421     }
422
423     public UUID getUUIDFromCurrentTx(Class<? extends Identifiable> cls, InstanceIdentifier key) {
424         return HwvtepSouthboundUtil.getData(currentTxUUIDs, cls, key);
425     }
426
427     public boolean isKeyPartOfCurrentTx(Class<? extends Identifiable> cls, InstanceIdentifier key) {
428         return HwvtepSouthboundUtil.containsKey(currentTxUUIDs, cls, key);
429     }
430
431     public Set<InstanceIdentifier> getDeletedKeysInCurrentTx(Class<? extends Identifiable> cls) {
432         if (currentTxDeletedKeys.containsKey(cls)) {
433             return currentTxDeletedKeys.get(cls).keySet();
434         }
435         return Collections.EMPTY_SET;
436     }
437
438     public List<? extends Identifiable> getUpdatedData(final InstanceIdentifier<Node> key,
439                                                        final Class<? extends Identifiable> cls) {
440         List<Identifiable> result = null;
441         if (modifiedData.get(key) != null && modifiedData.get(key).getLeft() != null) {
442             result = modifiedData.get(key).getLeft().get(cls);
443         }
444         if (result == null) {
445             result = Collections.EMPTY_LIST;
446         }
447         return result;
448     }
449
450     public List<? extends Identifiable> getDeletedData(final InstanceIdentifier<Node> key,
451                                                        final Class<? extends Identifiable> cls) {
452         List<Identifiable> result = null;
453         if (modifiedData.get(key) != null && modifiedData.get(key).getRight() != null) {
454             result = modifiedData.get(key).getRight().get(cls);
455         }
456         if (result == null) {
457             result = Collections.EMPTY_LIST;
458         }
459         return result;
460     }
461
462     public void setModifiedData(final Map<InstanceIdentifier<Node>,
463             Pair<Map<Class<? extends Identifiable>, List<Identifiable>>,
464                     Map<Class<? extends Identifiable>, List<Identifiable>>>> modifiedData) {
465         this.modifiedData = modifiedData;
466     }
467
468     public boolean isInReconciliation() {
469         return inReconciliation;
470     }
471
472     public void setInReconciliation(boolean inReconciliation) {
473         this.inReconciliation = inReconciliation;
474     }
475
476     public DataBroker getDataBroker() {
477         return db;
478     }
479
480
481     public void clearIntransitKeys() {
482         currentTxUUIDs.forEach( (cls, map) -> {
483             map.forEach( (iid, uuid) -> deviceInfo.clearInTransit(cls, iid));
484         });
485         currentTxDeletedKeys.forEach( (cls, map) -> {
486             map.forEach( (iid, val) -> deviceInfo.clearInTransit(cls, iid));
487         });
488         currentTxUUIDs.clear();
489         currentTxDeletedKeys.clear();
490         deviceInfo.onOperDataAvailable();
491     }
492 }