2 * Copyright (c) 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
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
8 package org.opendaylight.genius.utils.hwvtep;
10 import com.google.common.util.concurrent.FluentFuture;
11 import java.util.ArrayList;
12 import java.util.List;
13 import java.util.concurrent.ExecutionException;
14 import java.util.stream.StreamSupport;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
18 import org.opendaylight.mdsal.binding.api.DataBroker;
19 import org.opendaylight.mdsal.binding.api.WriteTransaction;
20 import org.opendaylight.mdsal.binding.util.Datastore;
21 import org.opendaylight.mdsal.binding.util.Datastore.Configuration;
22 import org.opendaylight.mdsal.binding.util.TypedReadTransaction;
23 import org.opendaylight.mdsal.binding.util.TypedWriteTransaction;
24 import org.opendaylight.mdsal.common.api.CommitInfo;
25 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.IetfYangUtil;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepNodeName;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalLocatorAugmentation;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalPortAugmentation;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalPortAugmentationBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalUcastMacs;
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.RemoteMcastMacs;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacsKey;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteUcastMacs;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteUcastMacsKey;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical.port.attributes.VlanBindings;
42 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
43 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
44 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
45 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
46 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
47 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
48 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder;
49 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
50 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
53 * Utility class to related to Hardware VTEP devices.
55 public final class HwvtepUtils {
56 private HwvtepUtils() {
60 // TODO: (eperefr) Move this to HwvtepSouthboundUtils when in place.
61 public static InstanceIdentifier<LocalUcastMacs> getWildCardPathForLocalUcastMacs() {
62 return InstanceIdentifier.create(NetworkTopology.class).child(Topology.class).child(Node.class)
63 .augmentation(HwvtepGlobalAugmentation.class).child(LocalUcastMacs.class);
67 * Adds the logical switch into config DS.
73 * @param logicalSwitch
75 * @return the listenable future
76 * @deprecated Use {@link #addLogicalSwitch(TypedWriteTransaction, NodeId, LogicalSwitches)}.
79 public static FluentFuture<? extends @NonNull CommitInfo> addLogicalSwitch(DataBroker broker, NodeId nodeId,
80 LogicalSwitches logicalSwitch) {
81 WriteTransaction transaction = broker.newWriteOnlyTransaction();
82 putLogicalSwitch(transaction,LogicalDatastoreType.CONFIGURATION, nodeId, logicalSwitch);
83 return transaction.commit();
87 public static FluentFuture<? extends @NonNull CommitInfo> addLogicalSwitch(DataBroker broker,
88 LogicalDatastoreType logicalDatastoreType,
90 LogicalSwitches logicalSwitch) {
91 WriteTransaction transaction = broker.newWriteOnlyTransaction();
92 putLogicalSwitch(transaction,logicalDatastoreType, nodeId, logicalSwitch);
93 return transaction.commit();
97 * Adds the logical switch.
99 * @param tx The configuration transaction.
100 * @param nodeId The node identifier.
101 * @param logicalSwitch The logical switch.
103 public static void addLogicalSwitch(TypedWriteTransaction<Configuration> tx, NodeId nodeId,
104 LogicalSwitches logicalSwitch) {
105 InstanceIdentifier<LogicalSwitches> iid = HwvtepSouthboundUtils.createLogicalSwitchesInstanceIdentifier(nodeId,
106 logicalSwitch.getHwvtepNodeName());
107 tx.mergeParentStructurePut(iid, logicalSwitch);
111 * Put the logical switches in the transaction.
120 public static void putLogicalSwitches(final WriteTransaction transaction, final NodeId nodeId,
121 final List<LogicalSwitches> lstSwitches) {
122 if (lstSwitches != null) {
123 for (LogicalSwitches logicalSwitch : lstSwitches) {
124 putLogicalSwitch(transaction,LogicalDatastoreType.CONFIGURATION, nodeId, logicalSwitch);
130 * Put logical switch in the transaction.
134 * @param logicalDatastoreType the LogicalDatastoreType
137 * @param logicalSwitch
140 public static void putLogicalSwitch(final WriteTransaction transaction,LogicalDatastoreType logicalDatastoreType,
141 final NodeId nodeId, final LogicalSwitches logicalSwitch) {
142 InstanceIdentifier<LogicalSwitches> iid = HwvtepSouthboundUtils.createLogicalSwitchesInstanceIdentifier(nodeId,
143 logicalSwitch.getHwvtepNodeName());
144 transaction.mergeParentStructurePut(logicalDatastoreType, iid, logicalSwitch);
148 * Delete logical switch from config DS.
154 * @param logicalSwitchName
155 * the logical switch name
156 * @return the listenable future
157 * @deprecated Use {@link #deleteLogicalSwitch(TypedWriteTransaction, NodeId, String)}.
160 public static FluentFuture<? extends @NonNull CommitInfo> deleteLogicalSwitch(DataBroker broker, NodeId nodeId,
161 String logicalSwitchName) {
162 WriteTransaction transaction = broker.newWriteOnlyTransaction();
163 deleteLogicalSwitch(transaction, nodeId, logicalSwitchName);
164 return transaction.commit();
168 * Delete logical switch from the transaction.
174 * @param logicalSwitchName
175 * the logical switch name
176 * @deprecated Use {@link #deleteLogicalSwitch(TypedWriteTransaction, NodeId, String)}.
179 public static void deleteLogicalSwitch(final WriteTransaction transaction, final NodeId nodeId,
180 final String logicalSwitchName) {
181 transaction.delete(LogicalDatastoreType.CONFIGURATION, HwvtepSouthboundUtils
182 .createLogicalSwitchesInstanceIdentifier(nodeId, new HwvtepNodeName(logicalSwitchName)));
186 * Deletes the given logical switch.
188 * @param tx The transaction.
189 * @param nodeId The node identifier.
190 * @param logicalSwitchName The logical switch name.
192 public static void deleteLogicalSwitch(TypedWriteTransaction<Configuration> tx, NodeId nodeId,
193 String logicalSwitchName) {
194 tx.delete(HwvtepSouthboundUtils
195 .createLogicalSwitchesInstanceIdentifier(nodeId, new HwvtepNodeName(logicalSwitchName)));
199 * Gets the logical switch.
201 * @param broker the broker
202 * @param datastoreType the datastore type
205 * @param logicalSwitchName
206 * the logical switch name
207 * @return the logical switch
208 * @deprecated Use {@link #getLogicalSwitch(TypedReadTransaction, NodeId, String)}.
209 * @throws ExecutionException in case of a technical (!) error while reading
210 * @throws InterruptedException if the transaction is interrupted.
213 public static LogicalSwitches getLogicalSwitch(DataBroker broker, LogicalDatastoreType datastoreType, NodeId nodeId,
214 String logicalSwitchName) throws ExecutionException, InterruptedException {
215 final InstanceIdentifier<LogicalSwitches> iid = HwvtepSouthboundUtils
216 .createLogicalSwitchesInstanceIdentifier(nodeId, new HwvtepNodeName(logicalSwitchName));
217 return SingleTransactionDataBroker.syncReadOptional(broker, datastoreType, iid).orElse(null);
221 * Retrieves the logical switch.
223 * @param tx The transaction to use.
224 * @param nodeId The node identifier.
225 * @param logicalSwitchName The logical switch name.
226 * @return The logical switch, if any.
229 public static LogicalSwitches getLogicalSwitch(TypedReadTransaction<Configuration> tx, NodeId nodeId,
230 String logicalSwitchName) {
231 final InstanceIdentifier<LogicalSwitches> iid = HwvtepSouthboundUtils
232 .createLogicalSwitchesInstanceIdentifier(nodeId, new HwvtepNodeName(logicalSwitchName));
234 return tx.read(iid).get().orElse(null);
235 } catch (InterruptedException | ExecutionException e) {
236 throw new RuntimeException("Error reading logical switch " + iid, e);
241 * Gets physical port termination point.
245 * @param datastoreType
248 * the physical switch node id
250 * port name under physical switch node id
251 * @return the physical port termination point
252 * @throws ExecutionException in case of a technical (!) error while reading
253 * @throws InterruptedException if the transaction is interrupted.
255 public static TerminationPoint getPhysicalPortTerminationPoint(DataBroker broker,
256 LogicalDatastoreType datastoreType, NodeId nodeId, String portName) throws ExecutionException,
257 InterruptedException {
258 TerminationPointKey tpKey = new TerminationPointKey(new TpId(portName));
259 InstanceIdentifier<TerminationPoint> iid = HwvtepSouthboundUtils.createTerminationPointId(nodeId, tpKey);
260 return SingleTransactionDataBroker.syncReadOptional(broker, datastoreType, iid).orElse(null);
264 * Get LogicalSwitches for a given hwVtepNodeId.
268 * @param hwVtepNodeId
269 * Hardware VTEP Node Id
272 * @return the logical switches
273 * @throws ExecutionException in case of a technical (!) error while reading
274 * @throws InterruptedException if the transaction is interrupted.
276 public static LogicalSwitches getLogicalSwitches(DataBroker broker, String hwVtepNodeId, String vni)
277 throws ExecutionException, InterruptedException {
278 NodeId nodeId = new NodeId(hwVtepNodeId);
279 InstanceIdentifier<LogicalSwitches> logicalSwitchesIdentifier = HwvtepSouthboundUtils
280 .createLogicalSwitchesInstanceIdentifier(nodeId, new HwvtepNodeName(vni));
282 return SingleTransactionDataBroker.syncReadOptional(broker, LogicalDatastoreType.CONFIGURATION,
283 logicalSwitchesIdentifier).orElse(null);
287 * Put physical locators in the transaction.
293 * @param lstPhysicalLocator
294 * the lst physical locator
296 public static void putPhysicalLocators(WriteTransaction transaction, NodeId nodeId,
297 List<HwvtepPhysicalLocatorAugmentation> lstPhysicalLocator) {
298 if (lstPhysicalLocator != null) {
299 for (HwvtepPhysicalLocatorAugmentation phyLocator : lstPhysicalLocator) {
300 putPhysicalLocator(transaction, nodeId, phyLocator);
306 * Put physical locator in the transaction.
315 public static void putPhysicalLocator(final WriteTransaction transaction, final NodeId nodeId,
316 final HwvtepPhysicalLocatorAugmentation phyLocator) {
317 InstanceIdentifier<TerminationPoint> iid = HwvtepSouthboundUtils.createPhysicalLocatorInstanceIdentifier(nodeId,
319 TerminationPoint terminationPoint = new TerminationPointBuilder()
320 .withKey(HwvtepSouthboundUtils.getTerminationPointKey(phyLocator))
321 .addAugmentation(HwvtepPhysicalLocatorAugmentation.class, phyLocator).build();
323 transaction.mergeParentStructurePut(LogicalDatastoreType.CONFIGURATION, iid, terminationPoint);
327 * Gets the physical locator.
331 * @param datastoreType
335 * @param phyLocatorIp
337 * @return the physical locator
338 * @throws ExecutionException in case of a technical (!) error while reading
339 * @throws InterruptedException if the transaction is interrupted.
341 public static HwvtepPhysicalLocatorAugmentation getPhysicalLocator(DataBroker broker,
342 LogicalDatastoreType datastoreType, NodeId nodeId, final IpAddress phyLocatorIp) throws
343 ExecutionException, InterruptedException {
344 HwvtepPhysicalLocatorAugmentation phyLocatorAug = HwvtepSouthboundUtils
345 .createHwvtepPhysicalLocatorAugmentation(phyLocatorIp);
346 InstanceIdentifier<HwvtepPhysicalLocatorAugmentation> iid = HwvtepSouthboundUtils
347 .createPhysicalLocatorInstanceIdentifier(nodeId, phyLocatorAug)
348 .augmentation(HwvtepPhysicalLocatorAugmentation.class);
349 return SingleTransactionDataBroker.syncReadOptional(broker, datastoreType, iid).orElse(null);
353 * Adds the remote ucast macs into config DS.
359 * @param lstRemoteUcastMacs
360 * the lst remote ucast macs
361 * @return the listenable future
362 * @deprecated Use {@link #addRemoteUcastMacs(TypedWriteTransaction, NodeId, Iterable)}.
365 public static FluentFuture<? extends @NonNull CommitInfo> addRemoteUcastMacs(DataBroker broker, NodeId nodeId,
366 List<RemoteUcastMacs> lstRemoteUcastMacs) {
367 WriteTransaction transaction = broker.newWriteOnlyTransaction();
368 putRemoteUcastMacs(transaction, nodeId, lstRemoteUcastMacs);
369 return transaction.commit();
373 * Adds the given remote unicast MACs.
375 * @param tx The transaction to use.
376 * @param nodeId The node identifier.
377 * @param remoteUcastMacs The MACs to add.
379 public static void addRemoteUcastMacs(TypedWriteTransaction<Configuration> tx, NodeId nodeId,
380 Iterable<RemoteUcastMacs> remoteUcastMacs) {
381 if (remoteUcastMacs != null) {
382 remoteUcastMacs.forEach(remoteUcastMac -> addRemoteUcastMac(tx, nodeId, remoteUcastMac));
387 * Adds the given remote unicast MAC.
389 * @param tx The transaction to use.
390 * @param nodeId The node identifier.
391 * @param remoteUcastMac The MAC to add.
393 public static void addRemoteUcastMac(TypedWriteTransaction<Configuration> tx, NodeId nodeId,
394 RemoteUcastMacs remoteUcastMac) {
395 InstanceIdentifier<RemoteUcastMacs> iid = HwvtepSouthboundUtils.createInstanceIdentifier(nodeId)
396 .augmentation(HwvtepGlobalAugmentation.class).child(RemoteUcastMacs.class,
397 new RemoteUcastMacsKey(remoteUcastMac.getLogicalSwitchRef(), remoteUcastMac.getMacEntryKey()));
398 tx.mergeParentStructurePut(iid, remoteUcastMac);
402 * Put remote ucast macs in the transaction.
408 * @param lstRemoteUcastMacs
409 * the lst remote ucast macs
410 * @deprecated Use {@link #addRemoteUcastMacs(TypedWriteTransaction, NodeId, Iterable)}.
413 public static void putRemoteUcastMacs(final WriteTransaction transaction, final NodeId nodeId,
414 final List<RemoteUcastMacs> lstRemoteUcastMacs) {
415 if (lstRemoteUcastMacs != null && !lstRemoteUcastMacs.isEmpty()) {
416 for (RemoteUcastMacs remoteUcastMac : lstRemoteUcastMacs) {
417 putRemoteUcastMac(transaction, nodeId, remoteUcastMac);
423 * Put remote ucast mac in the transaction.
429 * @param remoteUcastMac
430 * the remote ucast mac
431 * @deprecated Use {@link #addRemoteUcastMac(TypedWriteTransaction, NodeId, RemoteUcastMacs)}.
434 public static void putRemoteUcastMac(final WriteTransaction transaction, final NodeId nodeId,
435 RemoteUcastMacs remoteUcastMac) {
436 InstanceIdentifier<RemoteUcastMacs> iid = HwvtepSouthboundUtils.createInstanceIdentifier(nodeId)
437 .augmentation(HwvtepGlobalAugmentation.class).child(RemoteUcastMacs.class,
438 new RemoteUcastMacsKey(remoteUcastMac.getLogicalSwitchRef(), remoteUcastMac.getMacEntryKey()));
439 transaction.mergeParentStructurePut(LogicalDatastoreType.CONFIGURATION, iid, remoteUcastMac);
443 * Delete remote ucast mac from the config DS.
449 * @param logicalSwitchName the logical switch name
452 * @return the listenable future
453 * @deprecated Use {@link #deleteRemoteUcastMac(TypedWriteTransaction, NodeId, String, MacAddress)}.
456 public static FluentFuture<? extends @NonNull CommitInfo> deleteRemoteUcastMac(DataBroker broker, NodeId nodeId,
457 String logicalSwitchName, MacAddress mac) {
458 WriteTransaction transaction = broker.newWriteOnlyTransaction();
459 deleteRemoteUcastMac(transaction, nodeId, logicalSwitchName, mac);
460 return transaction.commit();
464 * Delete remote ucast mac from the transaction.
470 * @param logialSwitchName the logical switch name
473 * @deprecated Use {@link #deleteRemoteUcastMac(TypedWriteTransaction, NodeId, String, MacAddress)}.
476 public static void deleteRemoteUcastMac(final WriteTransaction transaction, final NodeId nodeId,
477 String logialSwitchName, final MacAddress mac) {
478 transaction.delete(LogicalDatastoreType.CONFIGURATION,
479 HwvtepSouthboundUtils.createRemoteUcastMacsInstanceIdentifier(nodeId, logialSwitchName, mac));
483 * Deletes the given remote unicast MAC.
485 * @param tx The transaction to use.
486 * @param nodeId The node identifier.
487 * @param logicalSwitchName The logical switch name.
488 * @param macAddress The MAC.
490 public static void deleteRemoteUcastMac(TypedWriteTransaction<Configuration> tx, NodeId nodeId,
491 String logicalSwitchName, MacAddress macAddress) {
492 tx.delete(HwvtepSouthboundUtils.createRemoteUcastMacsInstanceIdentifier(nodeId, logicalSwitchName, macAddress));
496 * Delete remote ucast macs from the config DS.
502 * @param logicalSwitchName the logical switch name
505 * @return the listenable future
506 * @deprecated Use {@link #deleteRemoteUcastMacs(TypedWriteTransaction, NodeId, String, Iterable)}.
509 public static FluentFuture<? extends @NonNull CommitInfo> deleteRemoteUcastMacs(DataBroker broker, NodeId nodeId,
510 String logicalSwitchName, List<MacAddress> lstMac) {
511 WriteTransaction transaction = broker.newWriteOnlyTransaction();
512 deleteRemoteUcastMacs(transaction, nodeId, logicalSwitchName, lstMac);
513 return transaction.commit();
517 * Delete remote ucast macs from the transaction.
523 * @param logicalSwitchName the logical switch name
526 * @deprecated Use {@link #deleteRemoteUcastMacs(TypedWriteTransaction, NodeId, String, Iterable)}.
529 public static void deleteRemoteUcastMacs(final WriteTransaction transaction, final NodeId nodeId,
530 String logicalSwitchName, final List<MacAddress> lstMac) {
531 if (lstMac != null && !lstMac.isEmpty()) {
532 for (MacAddress mac : lstMac) {
533 deleteRemoteUcastMac(transaction, nodeId, logicalSwitchName, mac);
539 * Deletes the given remote unicast MACs.
541 * @param tx The transaction to use.
542 * @param nodeId The node identifier.
543 * @param logicalSwitchName The logical switch name.
544 * @param macAddresses The MAC addresses.
546 public static void deleteRemoteUcastMacs(TypedWriteTransaction<Configuration> tx, NodeId nodeId,
547 String logicalSwitchName, Iterable<MacAddress> macAddresses) {
548 if (macAddresses != null) {
549 macAddresses.forEach(macAddress -> deleteRemoteUcastMac(tx, nodeId, logicalSwitchName, macAddress));
554 * Adds the remote mcast macs into config DS.
560 * @param lstRemoteMcastMacs
561 * the lst remote mcast macs
562 * @return the listenable future
564 public static FluentFuture<? extends @NonNull CommitInfo> addRemoteMcastMacs(DataBroker broker, NodeId nodeId,
565 List<RemoteMcastMacs> lstRemoteMcastMacs) {
566 WriteTransaction transaction = broker.newWriteOnlyTransaction();
567 putRemoteMcastMacs(transaction, nodeId, lstRemoteMcastMacs);
568 return transaction.commit();
572 * Put remote mcast macs in the transaction.
578 * @param lstRemoteMcastMacs
579 * the lst remote mcast macs
581 public static void putRemoteMcastMacs(final WriteTransaction transaction, final NodeId nodeId,
582 final List<RemoteMcastMacs> lstRemoteMcastMacs) {
583 if (lstRemoteMcastMacs != null && !lstRemoteMcastMacs.isEmpty()) {
584 for (RemoteMcastMacs remoteMcastMac : lstRemoteMcastMacs) {
585 putRemoteMcastMac(transaction, nodeId, remoteMcastMac);
591 * Put remote mcast mac in the transaction.
597 * @param remoteMcastMac
598 * the remote mcast mac
599 * @deprecated Use {@link #addRemoteMcastMac(TypedWriteTransaction, NodeId, RemoteMcastMacs)}.
602 public static void putRemoteMcastMac(final WriteTransaction transaction, final NodeId nodeId,
603 RemoteMcastMacs remoteMcastMac) {
604 InstanceIdentifier<RemoteMcastMacs> iid = HwvtepSouthboundUtils.createRemoteMcastMacsInstanceIdentifier(nodeId,
605 remoteMcastMac.key());
606 transaction.mergeParentStructurePut(LogicalDatastoreType.CONFIGURATION, iid, remoteMcastMac);
610 * Adds a remote multicast MAC.
612 * @param transaction the transaction
613 * @param logicalDatastoreType the LogicalDatastoreType
614 * @param nodeId the node id
615 * @param remoteMcastMac the remote mcast mac
616 * @deprecated Use {@link #addRemoteMcastMac(TypedWriteTransaction, NodeId, RemoteMcastMacs)}.
619 public static void putRemoteMcastMac(final WriteTransaction transaction,LogicalDatastoreType logicalDatastoreType,
621 RemoteMcastMacs remoteMcastMac) {
622 InstanceIdentifier<RemoteMcastMacs> iid = HwvtepSouthboundUtils.createRemoteMcastMacsInstanceIdentifier(nodeId,
623 remoteMcastMac.key());
624 transaction.mergeParentStructurePut(logicalDatastoreType, iid, remoteMcastMac);
628 * Store a remote multicast MAC.
630 * @param tx The transaction.
631 * @param nodeId The node identifier.
632 * @param remoteMcastMac The remote multicast MAC.
634 public static void addRemoteMcastMac(final TypedWriteTransaction<? extends Datastore> tx, final NodeId nodeId,
635 RemoteMcastMacs remoteMcastMac) {
636 InstanceIdentifier<RemoteMcastMacs> iid = HwvtepSouthboundUtils.createRemoteMcastMacsInstanceIdentifier(nodeId,
637 remoteMcastMac.key());
638 tx.mergeParentStructurePut(iid, remoteMcastMac);
642 * Gets the remote mcast mac.
646 * @param datastoreType
650 * @param remoteMcastMacsKey
651 * the remote mcast macs key
652 * @return the remote mcast mac
653 * @deprecated Use {@link #getRemoteMcastMac(TypedReadTransaction, NodeId, RemoteMcastMacsKey)}.
654 * @throws ExecutionException in case of a technical (!) error while reading
655 * @throws InterruptedException if the transaction is interrupted.
658 public static RemoteMcastMacs getRemoteMcastMac(DataBroker broker, LogicalDatastoreType datastoreType,
659 NodeId nodeId, RemoteMcastMacsKey remoteMcastMacsKey)
660 throws ExecutionException, InterruptedException {
661 final InstanceIdentifier<RemoteMcastMacs> iid = HwvtepSouthboundUtils
662 .createRemoteMcastMacsInstanceIdentifier(nodeId, remoteMcastMacsKey);
663 return SingleTransactionDataBroker.syncReadOptional(broker, datastoreType, iid).orElse(null);
667 * Retrieve a remote multicast MAC.
669 * @param tx The transction to use.
670 * @param nodeId The node identifier.
671 * @param remoteMcastMacsKey The MAC key.
672 * @return The MAC, if any ({@code null} if there is none).
675 public static RemoteMcastMacs getRemoteMcastMac(TypedReadTransaction<? extends Datastore> tx, NodeId nodeId,
676 RemoteMcastMacsKey remoteMcastMacsKey) {
677 final InstanceIdentifier<RemoteMcastMacs> iid = HwvtepSouthboundUtils
678 .createRemoteMcastMacsInstanceIdentifier(nodeId, remoteMcastMacsKey);
680 return tx.read(iid).get().orElse(null);
681 } catch (InterruptedException | ExecutionException e) {
682 throw new RuntimeException("Error reading remote multicast MAC " + iid, e);
687 * Delete remote mcast mac from config DS.
693 * @param remoteMcastMacsKey
694 * the remote mcast macs key
695 * @return the listenable future
696 * @deprecated Use {@link #deleteRemoteMcastMac(TypedWriteTransaction, NodeId, RemoteMcastMacsKey)}.
699 public static FluentFuture<? extends @NonNull CommitInfo> deleteRemoteMcastMac(DataBroker broker, NodeId nodeId,
700 RemoteMcastMacsKey remoteMcastMacsKey) {
701 WriteTransaction transaction = broker.newWriteOnlyTransaction();
702 deleteRemoteMcastMac(transaction, nodeId, remoteMcastMacsKey);
703 return transaction.commit();
707 * Delete remote mcast mac from the transaction.
713 * @param remoteMcastMacsKey
714 * the remote mcast macs key
715 * @deprecated Use {@link #deleteRemoteMcastMac(TypedWriteTransaction, NodeId, RemoteMcastMacsKey)}.
718 public static void deleteRemoteMcastMac(final WriteTransaction transaction, final NodeId nodeId,
719 final RemoteMcastMacsKey remoteMcastMacsKey) {
720 transaction.delete(LogicalDatastoreType.CONFIGURATION,
721 HwvtepSouthboundUtils.createRemoteMcastMacsInstanceIdentifier(nodeId, remoteMcastMacsKey));
725 * Deletes the given remote multicast MAC.
727 * @param tx The configuration transaction.
728 * @param nodeId The node identifier.
729 * @param remoteMcastMacsKey The remote multicast MAC key.
731 public static void deleteRemoteMcastMac(TypedWriteTransaction<Configuration> tx, final NodeId nodeId,
732 final RemoteMcastMacsKey remoteMcastMacsKey) {
733 tx.delete(HwvtepSouthboundUtils.createRemoteMcastMacsInstanceIdentifier(nodeId, remoteMcastMacsKey));
737 * Delete remote mcast macs from config DS.
743 * @param lstRemoteMcastMacsKey
744 * the lst remote mcast macs key
745 * @return the listenable future
747 public static FluentFuture<? extends @NonNull CommitInfo> deleteRemoteMcastMacs(DataBroker broker, NodeId nodeId,
748 List<RemoteMcastMacsKey> lstRemoteMcastMacsKey) {
749 WriteTransaction transaction = broker.newWriteOnlyTransaction();
750 deleteRemoteMcastMacs(transaction, nodeId, lstRemoteMcastMacsKey);
751 return transaction.commit();
755 * Delete remote mcast macs from the transaction.
761 * @param lstRemoteMcastMacsKey
762 * the lst remote mcast macs key
764 public static void deleteRemoteMcastMacs(final WriteTransaction transaction, final NodeId nodeId,
765 final List<RemoteMcastMacsKey> lstRemoteMcastMacsKey) {
766 if (lstRemoteMcastMacsKey != null && !lstRemoteMcastMacsKey.isEmpty()) {
767 for (RemoteMcastMacsKey mac : lstRemoteMcastMacsKey) {
768 deleteRemoteMcastMac(transaction, nodeId, mac);
774 * Merge vlan bindings in the transaction.
780 * @param phySwitchName
781 * the phy switch name
784 * @param vlanBindings
786 * @deprecated Use {@link #mergeVlanBindings(TypedWriteTransaction, NodeId, String, String, List)}.
789 public static void mergeVlanBindings(final WriteTransaction transaction, final NodeId nodeId,
790 final String phySwitchName, final String phyPortName, final List<VlanBindings> vlanBindings) {
791 NodeId physicalSwitchNodeId = HwvtepSouthboundUtils.createManagedNodeId(nodeId, phySwitchName);
792 mergeVlanBindings(transaction, physicalSwitchNodeId, phyPortName, vlanBindings);
796 * Merges the given VLAN bindings.
798 * @param tx The transaction to use.
799 * @param nodeId The node identifier.
800 * @param phySwitchName The physical switch name.
801 * @param phyPortName The physical port name.
802 * @param vlanBindings The VLAN bindings.
804 public static void mergeVlanBindings(TypedWriteTransaction<Configuration> tx, NodeId nodeId,
805 String phySwitchName, String phyPortName, List<VlanBindings> vlanBindings) {
806 NodeId physicalSwitchNodeId = HwvtepSouthboundUtils.createManagedNodeId(nodeId, phySwitchName);
807 mergeVlanBindings(tx, physicalSwitchNodeId, phyPortName, vlanBindings);
811 * Merge vlan bindings in the transaction.
815 * @param physicalSwitchNodeId
816 * the physical switch node id
819 * @param vlanBindings
821 * @deprecated Use {@link #mergeVlanBindings(TypedWriteTransaction, NodeId, String, List)}.
824 public static void mergeVlanBindings(final WriteTransaction transaction, final NodeId physicalSwitchNodeId,
825 final String phyPortName, final List<VlanBindings> vlanBindings) {
826 HwvtepPhysicalPortAugmentation phyPortAug = new HwvtepPhysicalPortAugmentationBuilder()
827 .setHwvtepNodeName(new HwvtepNodeName(phyPortName)).setVlanBindings(vlanBindings).build();
829 final InstanceIdentifier<HwvtepPhysicalPortAugmentation> iid = HwvtepSouthboundUtils
830 .createPhysicalPortInstanceIdentifier(physicalSwitchNodeId, phyPortName);
831 transaction.mergeParentStructureMerge(LogicalDatastoreType.CONFIGURATION, iid, phyPortAug);
835 * Merges the given VLAN bindings.
837 * @param tx The transaction to use.
838 * @param physicalSwitchNodeId The physical switch’s node identifier.
839 * @param phyPortName The physical port name.
840 * @param vlanBindings The VLAN bindings.
842 public static void mergeVlanBindings(TypedWriteTransaction<Configuration> tx, NodeId physicalSwitchNodeId,
843 String phyPortName, List<VlanBindings> vlanBindings) {
844 HwvtepPhysicalPortAugmentation phyPortAug = new HwvtepPhysicalPortAugmentationBuilder()
845 .setHwvtepNodeName(new HwvtepNodeName(phyPortName)).setVlanBindings(vlanBindings).build();
847 final InstanceIdentifier<HwvtepPhysicalPortAugmentation> iid = HwvtepSouthboundUtils
848 .createPhysicalPortInstanceIdentifier(physicalSwitchNodeId, phyPortName);
849 tx.mergeParentStructureMerge(iid, phyPortAug);
853 * Delete vlan binding from transaction.
857 * @param physicalSwitchNodeId
858 * the physical switch node id
863 * @deprecated Use {@link #deleteVlanBinding(TypedWriteTransaction, NodeId, String, Integer)}.
866 public static void deleteVlanBinding(WriteTransaction transaction, NodeId physicalSwitchNodeId, String phyPortName,
868 InstanceIdentifier<VlanBindings> iid = HwvtepSouthboundUtils
869 .createVlanBindingInstanceIdentifier(physicalSwitchNodeId, phyPortName, vlanId);
870 transaction.delete(LogicalDatastoreType.CONFIGURATION, iid);
874 * Deletes the given VLAN binding.
876 * @param tx The transaction to use.
877 * @param physicalSwitchNodeId The physical switch’s node identifier.
878 * @param phyPortName The physical port name.
879 * @param vlanId The VLAN identifier.
881 public static void deleteVlanBinding(TypedWriteTransaction<Configuration> tx, NodeId physicalSwitchNodeId,
882 String phyPortName, Integer vlanId) {
883 tx.delete(HwvtepSouthboundUtils.createVlanBindingInstanceIdentifier(physicalSwitchNodeId, phyPortName, vlanId));
887 * Gets the hw vtep node.
891 * @param datastoreType
895 * @return the hw vtep node
896 * @deprecated Use {@link #getHwVtepNode(TypedReadTransaction, NodeId)}.
897 * @throws ExecutionException in case of a technical (!) error while reading
898 * @throws InterruptedException if the transaction is interrupted.
901 public static Node getHwVtepNode(DataBroker dataBroker, LogicalDatastoreType datastoreType, NodeId nodeId)
902 throws ExecutionException, InterruptedException {
903 return SingleTransactionDataBroker.syncReadOptional(dataBroker, datastoreType,
904 HwvtepSouthboundUtils.createInstanceIdentifier(nodeId)).orElse(null);
908 * Retrieves the hardware VTEP node.
910 * @param tx The transaction.
911 * @param nodeId The node identifier.
912 * @return The hardware VTEP node.
914 public static Node getHwVtepNode(TypedReadTransaction<? extends Datastore> tx, NodeId nodeId) {
916 return tx.read(HwvtepSouthboundUtils.createInstanceIdentifier(nodeId)).get().orElse(null);
917 } catch (InterruptedException | ExecutionException e) {
918 throw new RuntimeException("Failed to read hwvtep node", e);
923 * Installs a list of Mac Addresses as remote Ucast address in an external
924 * device using the hwvtep-southbound.
926 * @param broker the databroker
927 * @param deviceNodeId
928 * NodeId if the ExternalDevice where the macs must be installed
930 * @param macAddresses
931 * List of Mac addresses to be installed in the external device.
932 * @param logicalSwitchName
933 * the logical switch name
934 * @param remoteVtepIp
935 * VTEP's IP in this OVS used for the tunnel with external
937 * @deprecated Use {@link #addUcastMacs(TypedWriteTransaction, String, Iterable, String, IpAddress)}.
938 * @return future if present
941 public static FluentFuture<? extends @NonNull CommitInfo> installUcastMacs(DataBroker broker,
942 String deviceNodeId, List<PhysAddress> macAddresses,
943 String logicalSwitchName, IpAddress remoteVtepIp) {
944 NodeId nodeId = new NodeId(deviceNodeId);
945 HwvtepPhysicalLocatorAugmentation phyLocatorAug = HwvtepSouthboundUtils
946 .createHwvtepPhysicalLocatorAugmentation(remoteVtepIp);
947 List<RemoteUcastMacs> macs = new ArrayList<>();
948 for (PhysAddress mac : macAddresses) {
949 // TODO: Query ARP cache to get IP address corresponding to
951 //IpAddress ipAddress = null;
952 macs.add(HwvtepSouthboundUtils.createRemoteUcastMac(nodeId,
953 IetfYangUtil.INSTANCE.canonizePhysAddress(mac).getValue(), /*ipAddress*/ null, logicalSwitchName,
956 return addRemoteUcastMacs(broker, nodeId, macs);
962 * @param tx The transaction to use.
963 * @param deviceNodeId The device’s node identifier.
964 * @param macAddresses The MAC addresses.
965 * @param logicalSwitchName The logical switch name.
966 * @param remoteVtepIp The remote VTEP IP address.
968 public static void addUcastMacs(TypedWriteTransaction<Configuration> tx, String deviceNodeId,
969 Iterable<PhysAddress> macAddresses, String logicalSwitchName, IpAddress remoteVtepIp) {
970 NodeId nodeId = new NodeId(deviceNodeId);
971 HwvtepPhysicalLocatorAugmentation phyLocatorAug = HwvtepSouthboundUtils
972 .createHwvtepPhysicalLocatorAugmentation(remoteVtepIp);
973 // TODO: Query ARP cache to get IP address corresponding to the MAC
974 StreamSupport.stream(macAddresses.spliterator(), false)
975 .map(macAddress -> HwvtepSouthboundUtils.createRemoteUcastMac(nodeId,
976 IetfYangUtil.INSTANCE.canonizePhysAddress(macAddress).getValue(), /*ipAddress*/ null, logicalSwitchName,
978 .forEach(mac -> addRemoteUcastMac(tx, nodeId, mac));
982 * Retrieves the database version.
984 * @param broker the broker
985 * @param nodeId the node id
986 * @deprecated Use {@link #getDbVersion(TypedReadTransaction, NodeId)}.
988 * @throws ExecutionException in case of a technical (!) error while reading
989 * @throws InterruptedException if the transaction is interrupted.
992 public static String getDbVersion(DataBroker broker, NodeId nodeId) throws ExecutionException,
993 InterruptedException {
994 Node hwvtepNode = getHwVtepNode(broker, LogicalDatastoreType.OPERATIONAL, nodeId);
995 String dbVersion = "";
996 if (hwvtepNode != null) {
997 dbVersion = hwvtepNode.augmentation(HwvtepGlobalAugmentation.class).getDbVersion();
1003 * Retrieves the database version, as indicated by the hardware VTEP node.
1005 * @param tx The transaction.
1006 * @param nodeId The node identifier.
1007 * @return The database version.
1009 public static String getDbVersion(TypedReadTransaction<? extends Datastore> tx, NodeId nodeId) {
1010 Node hwvtepNode = getHwVtepNode(tx, nodeId);
1011 return hwvtepNode == null ? "" : hwvtepNode.augmentation(HwvtepGlobalAugmentation.class).getDbVersion();