package org.opendaylight.netvirt.elan.cli.l2gw;
+import static org.opendaylight.mdsal.binding.util.Datastore.OPERATIONAL;
+
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import org.apache.karaf.shell.commands.Option;
import org.apache.karaf.shell.console.OsgiCommandSupport;
import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
+import org.opendaylight.genius.mdsalutil.MDSALUtil;
import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundConstants;
import org.opendaylight.genius.utils.hwvtep.HwvtepUtils;
import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner;
+import org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanInstances;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstanceKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepLogicalSwitchRef;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalLocatorRef;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteUcastMacs;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteUcastMacsKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Switches;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.SwitchesKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical.locator.set.attributes.LocatorSet;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical.port.attributes.VlanBindings;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
private static InstanceIdentifier<Node> createInstanceIdentifier(NodeId nodeId) {
return InstanceIdentifier.create(NetworkTopology.class).child(Topology.class,
- new TopologyKey(HwvtepSouthboundConstants.HWVTEP_TOPOLOGY_ID)).child(Node.class, new NodeKey(nodeId));
+ new TopologyKey(HwvtepSouthboundConstants.HWVTEP_TOPOLOGY_ID)).child(Node.class, new NodeKey(nodeId));
}
Map<NodeId, Node> opNodes = new HashMap<>();
@Override
@Nullable
+ @SuppressWarnings("illegalcatch")
protected Object doExecute() {
- List<Node> nodes = new ArrayList<>();
- Set<String> networks = new HashSet<>();
+ ManagedNewTransactionRunner txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
+
try {
- if (nodeId == null) {
- Optional<Topology> topologyOptional = SingleTransactionDataBroker.syncReadOptional(dataBroker,
- LogicalDatastoreType.OPERATIONAL, createHwvtepTopologyInstanceIdentifier());
- if (topologyOptional.isPresent()) {
- nodes.addAll(topologyOptional.get().nonnullNode().values());
- }
- } else {
- Optional<Node> nodeOptional = SingleTransactionDataBroker.syncReadOptional(dataBroker,
- LogicalDatastoreType.OPERATIONAL, createInstanceIdentifier(new NodeId(new Uri(nodeId))));
- if (nodeOptional.isPresent()) {
- nodes.add(nodeOptional.get());
+ txRunner.callWithNewReadOnlyTransactionAndClose(OPERATIONAL, operTx -> {
+ List<Node> nodes = new ArrayList<>();
+ Set<String> networks = new HashSet<>();
+ if (nodeId == null) {
+ Optional<Topology> topologyOptional = operTx.read(createHwvtepTopologyInstanceIdentifier()).get();
+ if (topologyOptional.isPresent()) {
+ nodes = new ArrayList<>(topologyOptional.get().getNode().values());
+ }
+ } else {
+ Optional<Node> nodeOptional = operTx
+ .read(createInstanceIdentifier(new NodeId(new Uri(nodeId)))).get();
+ if (nodeOptional.isPresent()) {
+ nodes.add(nodeOptional.get());
+ }
}
- }
- if (elanName == null) {
- //get all elan instance
- //get all device node id
- //print result
- Optional<ElanInstances> elanInstancesOptional = SingleTransactionDataBroker.syncReadOptional(dataBroker,
+ if (elanName == null) {
+ //get all elan instance
+ //get all device node id
+ //print result
+ Optional<ElanInstances> elanInstancesOptional = MDSALUtil.read(dataBroker,
LogicalDatastoreType.CONFIGURATION,
InstanceIdentifier.builder(ElanInstances.class).build());
- if (elanInstancesOptional.isPresent()) {
- Map<ElanInstanceKey, ElanInstance> elans = elanInstancesOptional.get().nonnullElanInstance();
- if (elans != null) {
- for (ElanInstance elan : elans.values()) {
- networks.add(elan.getElanInstanceName());
+ if (elanInstancesOptional.isPresent()) {
+ List<ElanInstance> elans = new ArrayList<>(elanInstancesOptional.get()
+ .getElanInstance().values());
+ if (elans != null) {
+ for (ElanInstance elan : elans) {
+ networks.add(elan.getElanInstanceName());
+ }
}
}
+ } else {
+ networks.add(elanName);
}
- } else {
- networks.add(elanName);
- }
- if (nodes != null) {
- for (Node node : nodes) {
- if (node.getNodeId().getValue().contains("physicalswitch")) {
- continue;
- }
- Node hwvtepConfigNode =
- HwvtepUtils.getHwVtepNode(dataBroker, LogicalDatastoreType.CONFIGURATION, node.getNodeId());
- Node hwvtepOpPsNode = getPSnode(node, LogicalDatastoreType.OPERATIONAL);
- Node hwvtepConfigPsNode = null;
- if (hwvtepOpPsNode != null) {
- hwvtepConfigPsNode = HwvtepUtils.getHwVtepNode(dataBroker, LogicalDatastoreType.CONFIGURATION,
- hwvtepOpPsNode.getNodeId());
- opPSNodes.put(node.getNodeId(), hwvtepOpPsNode);
- }
- opNodes.put(node.getNodeId(), node);
- configNodes.put(node.getNodeId(), hwvtepConfigNode);
-
- if (hwvtepConfigPsNode != null) {
- configPSNodes.put(node.getNodeId(), hwvtepConfigPsNode);
- }
- }
- }
- if (!networks.isEmpty()) {
- for (String network : networks) {
- session.getConsole().println("Network info for " + network);
+ if (nodes != null) {
for (Node node : nodes) {
if (node.getNodeId().getValue().contains("physicalswitch")) {
continue;
}
- session.getConsole().println("Printing for node " + node.getNodeId().getValue());
- process(node.getNodeId(), network);
+ Node hwvtepConfigNode =
+ HwvtepUtils.getHwVtepNode(dataBroker,
+ LogicalDatastoreType.CONFIGURATION, node.getNodeId());
+ Node hwvtepOpPsNode = getPSnode(node, LogicalDatastoreType.OPERATIONAL);
+ Node hwvtepConfigPsNode = null;
+ if (hwvtepOpPsNode != null) {
+ hwvtepConfigPsNode = HwvtepUtils.getHwVtepNode(dataBroker,
+ LogicalDatastoreType.CONFIGURATION, hwvtepOpPsNode.getNodeId());
+ opPSNodes.put(node.getNodeId(), hwvtepOpPsNode);
+ }
+ opNodes.put(node.getNodeId(), node);
+ configNodes.put(node.getNodeId(), hwvtepConfigNode);
+
+ if (hwvtepConfigPsNode != null) {
+ configPSNodes.put(node.getNodeId(), hwvtepConfigPsNode);
+ }
}
}
- }
- } catch (ExecutionException | InterruptedException e) {
+ if (!networks.isEmpty()) {
+ for (String network : networks) {
+ session.getConsole().println("Network info for " + network);
+ if (nodes != null) {
+ for (Node node : nodes) {
+ if (node.getNodeId().getValue().contains("physicalswitch")) {
+ continue;
+ }
+ session.getConsole().println("Printing for node " + node.getNodeId().getValue());
+ process(node.getNodeId(), network);
+ }
+ }
+ }
+ }
+ });
+ } catch (Exception e) {
session.getConsole().println("Failed with error " + e.getMessage());
}
return null;
return;
}
Map<RemoteUcastMacsKey, RemoteUcastMacs> remoteUcastMacs =
- hwvtepNode.augmentation(HwvtepGlobalAugmentation.class).nonnullRemoteUcastMacs();
+ hwvtepNode.augmentation(HwvtepGlobalAugmentation.class).nonnullRemoteUcastMacs();
if (remoteUcastMacs == null || remoteUcastMacs.isEmpty()) {
return;
}
return;
}
Map<LocalUcastMacsKey, LocalUcastMacs> localUcastMacs =
- hwvtepNode.augmentation(HwvtepGlobalAugmentation.class).nonnullLocalUcastMacs();
+ hwvtepNode.augmentation(HwvtepGlobalAugmentation.class).nonnullLocalUcastMacs();
if (localUcastMacs == null || localUcastMacs.isEmpty()) {
return;
}
return;
}
Map<LocalMcastMacsKey, LocalMcastMacs> localMcastMacs =
- hwvtepNode.augmentation(HwvtepGlobalAugmentation.class).nonnullLocalMcastMacs();
+ hwvtepNode.augmentation(HwvtepGlobalAugmentation.class).nonnullLocalMcastMacs();
if (localMcastMacs == null || localMcastMacs.isEmpty()) {
return;
}
return;
}
Map<RemoteMcastMacsKey, RemoteMcastMacs> remoteMcastMacs =
- hwvtepNode.augmentation(HwvtepGlobalAugmentation.class).nonnullRemoteMcastMacs();
+ hwvtepNode.augmentation(HwvtepGlobalAugmentation.class).nonnullRemoteMcastMacs();
if (remoteMcastMacs == null || remoteMcastMacs.isEmpty()) {
return;
}
}
for (TerminationPoint terminationPoint : terminationPoints.values()) {
HwvtepPhysicalPortAugmentation aug =
- terminationPoint.augmentation(HwvtepPhysicalPortAugmentation.class);
+ terminationPoint.augmentation(HwvtepPhysicalPortAugmentation.class);
if (aug == null || aug.getVlanBindings() == null) {
continue;
}
- for (VlanBindings vlanBindings : aug.getVlanBindings().values()) {
+ for (VlanBindings vlanBindings : aug.nonnullVlanBindings().values()) {
String lsFromremoteMac = getLogicalSwitchValue(vlanBindings.getLogicalSwitchRef());
if (elanName.equals(lsFromremoteMac)) {
session.getConsole().println(terminationPoint.getTpId().getValue()
}
}
}
-
-
}
@Nullable
return null;
}
return locatorRef.getValue()
- .firstKeyOf(TerminationPoint.class).getTpId().getValue();
+ .firstKeyOf(TerminationPoint.class).getTpId().getValue();
}
@Nullable
return null;
}
return logicalSwitchRef.getValue()
- .firstKeyOf(LogicalSwitches.class).getHwvtepNodeName().getValue();
+ .firstKeyOf(LogicalSwitches.class).getHwvtepNodeName().getValue();
}
@Nullable
- Node getPSnode(Node hwvtepNode, LogicalDatastoreType datastoreType) throws ExecutionException,
- InterruptedException {
- if (hwvtepNode.augmentation(HwvtepGlobalAugmentation.class) != null) {
- Map<SwitchesKey, Switches> switches = hwvtepNode.augmentation(HwvtepGlobalAugmentation.class)
- .nonnullSwitches();
- if (switches != null) {
- return HwvtepUtils.getHwVtepNode(dataBroker, datastoreType,
- switches.values().iterator().next().getSwitchRef().getValue().firstKeyOf(Node.class).getNodeId());
+ Node getPSnode(Node hwvtepNode, LogicalDatastoreType datastoreType)
+ throws ExecutionException, InterruptedException {
+ if (hwvtepNode.augmentation(HwvtepGlobalAugmentation.class) != null
+ && hwvtepNode.augmentation(HwvtepGlobalAugmentation.class).getSwitches() != null) {
+ for (Switches switches : hwvtepNode.augmentation(HwvtepGlobalAugmentation.class)
+ .nonnullSwitches().values()) {
+ NodeId psNodeId = switches.getSwitchRef().getValue().firstKeyOf(Node.class).getNodeId();
+ return HwvtepUtils.getHwVtepNode(dataBroker, datastoreType, psNodeId);
}
}
return null;