5d8993a1f73c00139f90e5841bacd99378f1c6c1
[genius.git] / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / genius / utils / hwvtep / HwvtepUtils.java
1 /*
2  * Copyright (c) 2016, 2017 Ericsson India Global Services Pvt Ltd. 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.genius.utils.hwvtep;
10
11 import com.google.common.util.concurrent.ListenableFuture;
12 import java.util.ArrayList;
13 import java.util.List;
14 import java.util.Locale;
15 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
16 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
17 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
18 import org.opendaylight.genius.mdsalutil.MDSALUtil;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepNodeName;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalLocatorAugmentation;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalPortAugmentation;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalPortAugmentationBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalUcastMacs;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacs;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacsKey;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteUcastMacs;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteUcastMacsKey;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical.port.attributes.VlanBindings;
34 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
35 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
36 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
37 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
38 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
39 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
40 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder;
41 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
42 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
43
44 /**
45  * Utility class to related to Hardware VTEP devices.
46  */
47 public final class HwvtepUtils {
48
49     private HwvtepUtils() { }
50
51     // TODO: (eperefr) Move this to HwvtepSouthboundUtils when in place.
52     public static InstanceIdentifier<LocalUcastMacs> getWildCardPathForLocalUcastMacs() {
53         return InstanceIdentifier.create(NetworkTopology.class).child(Topology.class).child(Node.class)
54                 .augmentation(HwvtepGlobalAugmentation.class).child(LocalUcastMacs.class);
55     }
56
57     /**
58      * Adds the logical switch into config DS.
59      *
60      * @param broker
61      *            the broker
62      * @param nodeId
63      *            the node id
64      * @param logicalSwitch
65      *            the logical switch
66      * @return the listenable future
67      */
68     public static ListenableFuture<Void> addLogicalSwitch(DataBroker broker, NodeId nodeId,
69                                                           LogicalSwitches logicalSwitch) {
70         WriteTransaction transaction = broker.newWriteOnlyTransaction();
71         putLogicalSwitch(transaction,LogicalDatastoreType.CONFIGURATION, nodeId, logicalSwitch);
72         return transaction.submit();
73     }
74
75     public static ListenableFuture<Void> addLogicalSwitch(DataBroker broker, LogicalDatastoreType logicalDatastoreType,
76                                                           NodeId nodeId,
77                                                           LogicalSwitches logicalSwitch) {
78         WriteTransaction transaction = broker.newWriteOnlyTransaction();
79         putLogicalSwitch(transaction,logicalDatastoreType, nodeId, logicalSwitch);
80         return transaction.submit();
81     }
82
83     /**
84      * Put the logical switches in the transaction.
85      *
86      * @param transaction
87      *            the transaction
88      * @param nodeId
89      *            the node id
90      * @param lstSwitches
91      *            the lst switches
92      */
93     public static void putLogicalSwitches(final WriteTransaction transaction, final NodeId nodeId,
94                                           final List<LogicalSwitches> lstSwitches) {
95         if (lstSwitches != null) {
96             for (LogicalSwitches logicalSwitch : lstSwitches) {
97                 putLogicalSwitch(transaction,LogicalDatastoreType.CONFIGURATION, nodeId, logicalSwitch);
98             }
99         }
100     }
101
102     /**
103      * Put logical switch in the transaction.
104      *
105      * @param transaction
106      *            the transaction
107      * @param nodeId
108      *            the node id
109      * @param logicalSwitch
110      *            the logical switch
111      */
112     public static void putLogicalSwitch(final WriteTransaction transaction,LogicalDatastoreType logicalDatastoreType,
113                                         final NodeId nodeId, final LogicalSwitches logicalSwitch) {
114         InstanceIdentifier<LogicalSwitches> iid = HwvtepSouthboundUtils.createLogicalSwitchesInstanceIdentifier(nodeId,
115                 logicalSwitch.getHwvtepNodeName());
116         transaction.put(logicalDatastoreType, iid, logicalSwitch, true);
117     }
118
119     /**
120      * Delete logical switch from config DS.
121      *
122      * @param broker
123      *            the broker
124      * @param nodeId
125      *            the node id
126      * @param logicalSwitchName
127      *            the logical switch name
128      * @return the listenable future
129      */
130     public static ListenableFuture<Void> deleteLogicalSwitch(DataBroker broker, NodeId nodeId,
131                                                              String logicalSwitchName) {
132         WriteTransaction transaction = broker.newWriteOnlyTransaction();
133         deleteLogicalSwitch(transaction, nodeId, logicalSwitchName);
134         return transaction.submit();
135     }
136
137     /**
138      * Delete logical switch from the transaction.
139      *
140      * @param transaction
141      *            the transaction
142      * @param nodeId
143      *            the node id
144      * @param logicalSwitchName
145      *            the logical switch name
146      */
147     public static void deleteLogicalSwitch(final WriteTransaction transaction, final NodeId nodeId,
148                                            final String logicalSwitchName) {
149         transaction.delete(LogicalDatastoreType.CONFIGURATION, HwvtepSouthboundUtils
150                 .createLogicalSwitchesInstanceIdentifier(nodeId, new HwvtepNodeName(logicalSwitchName)));
151     }
152
153     /**
154      * Gets the logical switch.
155      *
156      * @param nodeId
157      *            the node id
158      * @param logicalSwitchName
159      *            the logical switch name
160      * @return the logical switch
161      */
162     public static LogicalSwitches getLogicalSwitch(DataBroker broker, LogicalDatastoreType datastoreType, NodeId nodeId,
163                                                    String logicalSwitchName) {
164         final InstanceIdentifier<LogicalSwitches> iid = HwvtepSouthboundUtils
165                 .createLogicalSwitchesInstanceIdentifier(nodeId, new HwvtepNodeName(logicalSwitchName));
166         return MDSALUtil.read(broker, datastoreType, iid).orNull();
167     }
168
169     /**
170      * Gets physical port termination point.
171      *
172      * @param broker
173      *          the broker
174      * @param datastoreType
175      *          the datastore type
176      * @param nodeId
177      *          the physical switch node id
178      * @param portName
179      *          port name under physical switch node id
180      * @return the physical port termination point
181      */
182     public static TerminationPoint getPhysicalPortTerminationPoint(DataBroker broker,
183             LogicalDatastoreType datastoreType, NodeId nodeId, String portName) {
184         TerminationPointKey tpKey = new TerminationPointKey(new TpId(portName));
185         InstanceIdentifier<TerminationPoint> iid = HwvtepSouthboundUtils.createTerminationPointId(nodeId, tpKey);
186         return MDSALUtil.read(broker, datastoreType, iid).orNull();
187     }
188
189     /**
190      * Get LogicalSwitches for a given hwVtepNodeId.
191      *
192      * @param broker
193      *            the broker
194      * @param hwVtepNodeId
195      *            Hardware VTEP Node Id
196      * @param vni
197      *            virtual network id
198      * @return the logical switches
199      */
200     public static LogicalSwitches getLogicalSwitches(DataBroker broker, String hwVtepNodeId, String vni) {
201         NodeId nodeId = new NodeId(hwVtepNodeId);
202         InstanceIdentifier<LogicalSwitches> logicalSwitchesIdentifier = HwvtepSouthboundUtils
203                 .createLogicalSwitchesInstanceIdentifier(nodeId, new HwvtepNodeName(vni));
204
205         return MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, logicalSwitchesIdentifier).orNull();
206     }
207
208     /**
209      * Put physical locators in the transaction.
210      *
211      * @param transaction
212      *            the transaction
213      * @param nodeId
214      *            the node id
215      * @param lstPhysicalLocator
216      *            the lst physical locator
217      */
218     public static void putPhysicalLocators(WriteTransaction transaction, NodeId nodeId,
219                                            List<HwvtepPhysicalLocatorAugmentation> lstPhysicalLocator) {
220         if (lstPhysicalLocator != null) {
221             for (HwvtepPhysicalLocatorAugmentation phyLocator : lstPhysicalLocator) {
222                 putPhysicalLocator(transaction, nodeId, phyLocator);
223             }
224         }
225     }
226
227     /**
228      * Put physical locator in the transaction.
229      *
230      * @param transaction
231      *            the transaction
232      * @param nodeId
233      *            the node id
234      * @param phyLocator
235      *            the phy locator
236      */
237     public static void putPhysicalLocator(final WriteTransaction transaction, final NodeId nodeId,
238                                           final HwvtepPhysicalLocatorAugmentation phyLocator) {
239         InstanceIdentifier<TerminationPoint> iid = HwvtepSouthboundUtils.createPhysicalLocatorInstanceIdentifier(nodeId,
240                 phyLocator);
241         TerminationPoint terminationPoint = new TerminationPointBuilder()
242                 .setKey(HwvtepSouthboundUtils.getTerminationPointKey(phyLocator))
243                 .addAugmentation(HwvtepPhysicalLocatorAugmentation.class, phyLocator).build();
244
245         transaction.put(LogicalDatastoreType.CONFIGURATION, iid, terminationPoint, true);
246     }
247
248     /**
249      * Gets the physical locator.
250      *
251      * @param broker
252      *            the broker
253      * @param datastoreType
254      *            the datastore type
255      * @param nodeId
256      *            the node id
257      * @param phyLocatorIp
258      *            the phy locator ip
259      * @return the physical locator
260      */
261     public static HwvtepPhysicalLocatorAugmentation getPhysicalLocator(DataBroker broker,
262             LogicalDatastoreType datastoreType, NodeId nodeId, final IpAddress phyLocatorIp) {
263         HwvtepPhysicalLocatorAugmentation phyLocatorAug = HwvtepSouthboundUtils
264                 .createHwvtepPhysicalLocatorAugmentation(String.valueOf(phyLocatorIp.getValue()));
265         InstanceIdentifier<HwvtepPhysicalLocatorAugmentation> iid = HwvtepSouthboundUtils
266                 .createPhysicalLocatorInstanceIdentifier(nodeId, phyLocatorAug)
267                 .augmentation(HwvtepPhysicalLocatorAugmentation.class);
268         return MDSALUtil.read(broker, datastoreType, iid).orNull();
269     }
270
271     /**
272      * Adds the remote ucast macs into config DS.
273      *
274      * @param broker
275      *            the broker
276      * @param nodeId
277      *            the node id
278      * @param lstRemoteUcastMacs
279      *            the lst remote ucast macs
280      * @return the listenable future
281      */
282     public static ListenableFuture<Void> addRemoteUcastMacs(DataBroker broker, NodeId nodeId,
283                                                             List<RemoteUcastMacs> lstRemoteUcastMacs) {
284         WriteTransaction transaction = broker.newWriteOnlyTransaction();
285         putRemoteUcastMacs(transaction, nodeId, lstRemoteUcastMacs);
286         return transaction.submit();
287     }
288
289     /**
290      * Put remote ucast macs in the transaction.
291      *
292      * @param transaction
293      *            the transaction
294      * @param nodeId
295      *            the node id
296      * @param lstRemoteUcastMacs
297      *            the lst remote ucast macs
298      */
299     public static void putRemoteUcastMacs(final WriteTransaction transaction, final NodeId nodeId,
300                                           final List<RemoteUcastMacs> lstRemoteUcastMacs) {
301         if (lstRemoteUcastMacs != null && !lstRemoteUcastMacs.isEmpty()) {
302             for (RemoteUcastMacs remoteUcastMac : lstRemoteUcastMacs) {
303                 putRemoteUcastMac(transaction, nodeId, remoteUcastMac);
304             }
305         }
306     }
307
308     /**
309      * Put remote ucast mac in the transaction.
310      *
311      * @param transaction
312      *            the transaction
313      * @param nodeId
314      *            the node id
315      * @param remoteUcastMac
316      *            the remote ucast mac
317      */
318     public static void putRemoteUcastMac(final WriteTransaction transaction, final NodeId nodeId,
319                                          RemoteUcastMacs remoteUcastMac) {
320         InstanceIdentifier<RemoteUcastMacs> iid = HwvtepSouthboundUtils.createInstanceIdentifier(nodeId)
321                 .augmentation(HwvtepGlobalAugmentation.class).child(RemoteUcastMacs.class,
322                         new RemoteUcastMacsKey(remoteUcastMac.getLogicalSwitchRef(), remoteUcastMac.getMacEntryKey()));
323         transaction.put(LogicalDatastoreType.CONFIGURATION, iid, remoteUcastMac, true);
324     }
325
326     /**
327      * Delete remote ucast mac from the config DS.
328      *
329      * @param broker
330      *            the broker
331      * @param nodeId
332      *            the node id
333      * @param mac
334      *            the mac
335      * @return the listenable future
336      */
337     public static ListenableFuture<Void> deleteRemoteUcastMac(DataBroker broker, NodeId nodeId,
338                                                               String logicalSwitchName, MacAddress mac) {
339         WriteTransaction transaction = broker.newWriteOnlyTransaction();
340         deleteRemoteUcastMac(transaction, nodeId, logicalSwitchName, mac);
341         return transaction.submit();
342     }
343
344     /**
345      * Delete remote ucast mac from the transaction.
346      *
347      * @param transaction
348      *            the transaction
349      * @param nodeId
350      *            the node id
351      * @param mac
352      *            the mac
353      */
354     public static void deleteRemoteUcastMac(final WriteTransaction transaction, final NodeId nodeId,
355                                             String logialSwitchName, final MacAddress mac) {
356         transaction.delete(LogicalDatastoreType.CONFIGURATION,
357                 HwvtepSouthboundUtils.createRemoteUcastMacsInstanceIdentifier(nodeId, logialSwitchName, mac));
358     }
359
360     /**
361      * Delete remote ucast macs from the config DS.
362      *
363      * @param broker
364      *            the broker
365      * @param nodeId
366      *            the node id
367      * @param lstMac
368      *            the lst mac
369      * @return the listenable future
370      */
371     public static ListenableFuture<Void> deleteRemoteUcastMacs(DataBroker broker, NodeId nodeId,
372                                                                String logicalSwitchName, List<MacAddress> lstMac) {
373         WriteTransaction transaction = broker.newWriteOnlyTransaction();
374         deleteRemoteUcastMacs(transaction, nodeId, logicalSwitchName, lstMac);
375         return transaction.submit();
376     }
377
378     /**
379      * Delete remote ucast macs from the transaction.
380      *
381      * @param transaction
382      *            the transaction
383      * @param nodeId
384      *            the node id
385      * @param lstMac
386      *            the lst mac
387      */
388     public static void deleteRemoteUcastMacs(final WriteTransaction transaction, final NodeId nodeId,
389                                              String logicalSwitchName, final List<MacAddress> lstMac) {
390         if (lstMac != null && !lstMac.isEmpty()) {
391             for (MacAddress mac : lstMac) {
392                 deleteRemoteUcastMac(transaction, nodeId, logicalSwitchName, mac);
393             }
394         }
395     }
396
397     /**
398      * Adds the remote mcast macs into config DS.
399      *
400      * @param broker
401      *            the broker
402      * @param nodeId
403      *            the node id
404      * @param lstRemoteMcastMacs
405      *            the lst remote mcast macs
406      * @return the listenable future
407      */
408     public static ListenableFuture<Void> addRemoteMcastMacs(DataBroker broker, NodeId nodeId,
409                                                             List<RemoteMcastMacs> lstRemoteMcastMacs) {
410         WriteTransaction transaction = broker.newWriteOnlyTransaction();
411         putRemoteMcastMacs(transaction, nodeId, lstRemoteMcastMacs);
412         return transaction.submit();
413     }
414
415     /**
416      * Put remote mcast macs in the transaction.
417      *
418      * @param transaction
419      *            the transaction
420      * @param nodeId
421      *            the node id
422      * @param lstRemoteMcastMacs
423      *            the lst remote mcast macs
424      */
425     public static void putRemoteMcastMacs(final WriteTransaction transaction, final NodeId nodeId,
426                                           final List<RemoteMcastMacs> lstRemoteMcastMacs) {
427         if (lstRemoteMcastMacs != null && !lstRemoteMcastMacs.isEmpty()) {
428             for (RemoteMcastMacs remoteMcastMac : lstRemoteMcastMacs) {
429                 putRemoteMcastMac(transaction, nodeId, remoteMcastMac);
430             }
431         }
432     }
433
434     /**
435      * Put remote mcast mac in the transaction.
436      *
437      * @param transaction
438      *            the transaction
439      * @param nodeId
440      *            the node id
441      * @param remoteMcastMac
442      *            the remote mcast mac
443      */
444     public static void putRemoteMcastMac(final WriteTransaction transaction, final NodeId nodeId,
445                                          RemoteMcastMacs remoteMcastMac) {
446         InstanceIdentifier<RemoteMcastMacs> iid = HwvtepSouthboundUtils.createRemoteMcastMacsInstanceIdentifier(nodeId,
447                 remoteMcastMac.getKey());
448         transaction.put(LogicalDatastoreType.CONFIGURATION, iid, remoteMcastMac, true);
449     }
450
451     public static void putRemoteMcastMac(final WriteTransaction transaction,LogicalDatastoreType logicalDatastoreType,
452                                          final NodeId nodeId,
453                                          RemoteMcastMacs remoteMcastMac) {
454         InstanceIdentifier<RemoteMcastMacs> iid = HwvtepSouthboundUtils.createRemoteMcastMacsInstanceIdentifier(nodeId,
455                 remoteMcastMac.getKey());
456         transaction.put(logicalDatastoreType, iid, remoteMcastMac, true);
457     }
458
459     /**
460      * Gets the remote mcast mac.
461      *
462      * @param broker
463      *            the broker
464      * @param datastoreType
465      *            the datastore type
466      * @param nodeId
467      *            the node id
468      * @param remoteMcastMacsKey
469      *            the remote mcast macs key
470      * @return the remote mcast mac
471      */
472     public static RemoteMcastMacs getRemoteMcastMac(DataBroker broker, LogicalDatastoreType datastoreType,
473                                                     NodeId nodeId, RemoteMcastMacsKey remoteMcastMacsKey) {
474         final InstanceIdentifier<RemoteMcastMacs> iid = HwvtepSouthboundUtils
475                 .createRemoteMcastMacsInstanceIdentifier(nodeId, remoteMcastMacsKey);
476         return MDSALUtil.read(broker, datastoreType, iid).orNull();
477     }
478
479     /**
480      * Delete remote mcast mac from config DS.
481      *
482      * @param broker
483      *            the broker
484      * @param nodeId
485      *            the node id
486      * @param remoteMcastMacsKey
487      *            the remote mcast macs key
488      * @return the listenable future
489      */
490     public static ListenableFuture<Void> deleteRemoteMcastMac(DataBroker broker, NodeId nodeId,
491                                                               RemoteMcastMacsKey remoteMcastMacsKey) {
492         WriteTransaction transaction = broker.newWriteOnlyTransaction();
493         deleteRemoteMcastMac(transaction, nodeId, remoteMcastMacsKey);
494         return transaction.submit();
495     }
496
497     /**
498      * Delete remote mcast mac from the transaction.
499      *
500      * @param transaction
501      *            the transaction
502      * @param nodeId
503      *            the node id
504      * @param remoteMcastMacsKey
505      *            the remote mcast macs key
506      */
507     public static void deleteRemoteMcastMac(final WriteTransaction transaction, final NodeId nodeId,
508                                             final RemoteMcastMacsKey remoteMcastMacsKey) {
509         transaction.delete(LogicalDatastoreType.CONFIGURATION,
510                 HwvtepSouthboundUtils.createRemoteMcastMacsInstanceIdentifier(nodeId, remoteMcastMacsKey));
511     }
512
513     /**
514      * Delete remote mcast macs from config DS.
515      *
516      * @param broker
517      *            the broker
518      * @param nodeId
519      *            the node id
520      * @param lstRemoteMcastMacsKey
521      *            the lst remote mcast macs key
522      * @return the listenable future
523      */
524     public static ListenableFuture<Void> deleteRemoteMcastMacs(DataBroker broker, NodeId nodeId,
525                                                                List<RemoteMcastMacsKey> lstRemoteMcastMacsKey) {
526         WriteTransaction transaction = broker.newWriteOnlyTransaction();
527         deleteRemoteMcastMacs(transaction, nodeId, lstRemoteMcastMacsKey);
528         return transaction.submit();
529     }
530
531     /**
532      * Delete remote mcast macs from the transaction.
533      *
534      * @param transaction
535      *            the transaction
536      * @param nodeId
537      *            the node id
538      * @param lstRemoteMcastMacsKey
539      *            the lst remote mcast macs key
540      */
541     public static void deleteRemoteMcastMacs(final WriteTransaction transaction, final NodeId nodeId,
542                                              final List<RemoteMcastMacsKey> lstRemoteMcastMacsKey) {
543         if (lstRemoteMcastMacsKey != null && !lstRemoteMcastMacsKey.isEmpty()) {
544             for (RemoteMcastMacsKey mac : lstRemoteMcastMacsKey) {
545                 deleteRemoteMcastMac(transaction, nodeId, mac);
546             }
547         }
548     }
549
550     /**
551      * Merge vlan bindings in the transaction.
552      *
553      * @param transaction
554      *            the transaction
555      * @param nodeId
556      *            the node id
557      * @param phySwitchName
558      *            the phy switch name
559      * @param phyPortName
560      *            the phy port name
561      * @param vlanBindings
562      *            the vlan bindings
563      */
564     public static void mergeVlanBindings(final WriteTransaction transaction, final NodeId nodeId,
565             final String phySwitchName, final String phyPortName, final List<VlanBindings> vlanBindings) {
566         NodeId physicalSwitchNodeId = HwvtepSouthboundUtils.createManagedNodeId(nodeId, phySwitchName);
567         mergeVlanBindings(transaction, physicalSwitchNodeId, phyPortName, vlanBindings);
568     }
569
570     /**
571      * Merge vlan bindings in the transaction.
572      *
573      * @param transaction
574      *            the transaction
575      * @param physicalSwitchNodeId
576      *            the physical switch node id
577      * @param phyPortName
578      *            the phy port name
579      * @param vlanBindings
580      *            the vlan bindings
581      */
582     public static void mergeVlanBindings(final WriteTransaction transaction, final NodeId physicalSwitchNodeId,
583                                          final String phyPortName, final List<VlanBindings> vlanBindings) {
584         HwvtepPhysicalPortAugmentation phyPortAug = new HwvtepPhysicalPortAugmentationBuilder()
585                 .setHwvtepNodeName(new HwvtepNodeName(phyPortName)).setVlanBindings(vlanBindings).build();
586
587         final InstanceIdentifier<HwvtepPhysicalPortAugmentation> iid = HwvtepSouthboundUtils
588                 .createPhysicalPortInstanceIdentifier(physicalSwitchNodeId, phyPortName);
589         transaction.merge(LogicalDatastoreType.CONFIGURATION, iid, phyPortAug, true);
590     }
591
592     /**
593      * Delete vlan binding from transaction.
594      *
595      * @param transaction
596      *            the transaction
597      * @param physicalSwitchNodeId
598      *            the physical switch node id
599      * @param phyPortName
600      *            the phy port name
601      * @param vlanId
602      *            the vlan id
603      */
604     public static void deleteVlanBinding(WriteTransaction transaction, NodeId physicalSwitchNodeId, String phyPortName,
605                                          Integer vlanId) {
606         InstanceIdentifier<VlanBindings> iid = HwvtepSouthboundUtils
607                 .createVlanBindingInstanceIdentifier(physicalSwitchNodeId, phyPortName, vlanId);
608         transaction.delete(LogicalDatastoreType.CONFIGURATION, iid);
609     }
610
611     /**
612      * Gets the hw vtep node.
613      *
614      * @param dataBroker
615      *            the data broker
616      * @param datastoreType
617      *            the datastore type
618      * @param nodeId
619      *            the node id
620      * @return the hw vtep node
621      */
622     public static Node getHwVtepNode(DataBroker dataBroker, LogicalDatastoreType datastoreType, NodeId nodeId) {
623         return MDSALUtil.read(dataBroker, datastoreType,
624                 HwvtepSouthboundUtils.createInstanceIdentifier(nodeId)).orNull();
625     }
626
627     /**
628      * Installs a list of Mac Addresses as remote Ucast address in an external
629      * device using the hwvtep-southbound.
630      *
631      * @param deviceNodeId
632      *            NodeId if the ExternalDevice where the macs must be installed
633      *            in.
634      * @param macAddresses
635      *            List of Mac addresses to be installed in the external device.
636      * @param logicalSwitchName
637      *            the logical switch name
638      * @param remoteVtepIp
639      *            VTEP's IP in this OVS used for the tunnel with external
640      *            device.
641      */
642     public static ListenableFuture<Void> installUcastMacs(DataBroker broker,
643                                                           String deviceNodeId, List<PhysAddress> macAddresses,
644                                                           String logicalSwitchName, IpAddress remoteVtepIp) {
645         NodeId nodeId = new NodeId(deviceNodeId);
646         HwvtepPhysicalLocatorAugmentation phyLocatorAug = HwvtepSouthboundUtils
647                 .createHwvtepPhysicalLocatorAugmentation(String.valueOf(remoteVtepIp.getValue()));
648         List<RemoteUcastMacs> macs = new ArrayList<>();
649         for (PhysAddress mac : macAddresses) {
650             // TODO: Query ARP cache to get IP address corresponding to
651             // the MAC
652             //IpAddress ipAddress = null;
653             macs.add(HwvtepSouthboundUtils.createRemoteUcastMac(nodeId, mac.getValue().toLowerCase(Locale.getDefault()),
654                     /*ipAddress*/ null, logicalSwitchName, phyLocatorAug));
655         }
656         return HwvtepUtils.addRemoteUcastMacs(broker, nodeId, macs);
657     }
658
659     public static String getDbVersion(DataBroker broker, NodeId nodeId) {
660         Node hwvtepNode = getHwVtepNode(broker, LogicalDatastoreType.OPERATIONAL, nodeId);
661         String dbVersion = "";
662         if (hwvtepNode != null) {
663             dbVersion = hwvtepNode.getAugmentation(HwvtepGlobalAugmentation.class).getDbVersion();
664         }
665         return dbVersion;
666     }
667
668 }