2 * Copyright (c) 2019 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.ovsdb.hwvtepsouthbound.cli;
10 import java.io.PrintStream;
12 import org.apache.karaf.shell.api.action.Action;
13 import org.apache.karaf.shell.api.action.Argument;
14 import org.apache.karaf.shell.api.action.Command;
15 import org.apache.karaf.shell.api.action.lifecycle.Reference;
16 import org.apache.karaf.shell.api.action.lifecycle.Service;
17 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepConnectionInstance;
18 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepDeviceInfo;
19 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundProvider;
20 import org.opendaylight.ovsdb.lib.notation.UUID;
21 import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalPort;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacs;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteUcastMacs;
26 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
27 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
28 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
29 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
30 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
31 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
32 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
33 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
34 import org.opendaylight.yangtools.yang.binding.Identifiable;
35 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
38 @Command(scope = "hwvtep", name = "cache", description = "Disply hwvtep cache")
39 public class HwvtepCacheDisplayCmd implements Action {
41 @Argument(name = "nodeid", description = "Node Id",
42 required = false, multiValued = false)
43 private String nodeid;
46 private HwvtepSouthboundProvider hwvtepSouthboundProvider;
48 private static final TopologyId HWVTEP_TOPOLOGY_ID = new TopologyId(new Uri("hwvtep:1"));
49 private static final String SEPERATOR = "#######################################################";
50 private static final String SECTION_SEPERATOR = "==================================================="
51 + "=============================";
55 @SuppressWarnings("checkstyle:RegexpSinglelineJava")
56 public Object execute() throws Exception {
57 Map<InstanceIdentifier<Node>, HwvtepConnectionInstance> allConnectedInstances =
58 hwvtepSouthboundProvider.getHwvtepConnectionManager().getAllConnectedInstances();
60 allConnectedInstances.entrySet().forEach((entry) -> {
61 System.out.println(SEPERATOR + " START " + SEPERATOR);
62 print(entry.getKey(), entry.getValue());
63 System.out.println(SEPERATOR + " END " + SEPERATOR);
68 System.out.println(SEPERATOR + " START " + SEPERATOR);
69 print(getIid(), allConnectedInstances.get(getIid()));
70 System.out.println(SEPERATOR + " END " + SEPERATOR);
75 private InstanceIdentifier<Node> getIid() {
76 NodeId nodeId = new NodeId(new Uri(nodeid));
77 NodeKey nodeKey = new NodeKey(nodeId);
78 TopologyKey topoKey = new TopologyKey(HWVTEP_TOPOLOGY_ID);
79 return InstanceIdentifier.builder(NetworkTopology.class)
80 .child(Topology.class, topoKey)
81 .child(Node.class, nodeKey)
85 @SuppressWarnings("checkstyle:RegexpSinglelineJava")
86 private void print(InstanceIdentifier<Node> iid,
87 HwvtepConnectionInstance connectionInstance) {
88 PrintStream printStream = System.out;
89 printStream.print("Printing for Node : ");
90 printStream.println(iid.firstKeyOf(Node.class).getNodeId().getValue());
92 printStream.println(SECTION_SEPERATOR);
93 printStream.println("Config data");
94 printStream.println(SECTION_SEPERATOR);
95 HwvtepDeviceInfo deviceInfo = connectionInstance.getDeviceInfo();
96 deviceInfo.getConfigData().entrySet().forEach((entry) -> {
97 printEntry(printStream, entry);
101 printStream.println(SECTION_SEPERATOR);
102 printStream.println("Oper data");
103 printStream.println(SECTION_SEPERATOR);
104 deviceInfo.getOperData().entrySet().forEach((entry) -> {
105 printEntry(printStream, entry);
108 printStream.println(SECTION_SEPERATOR);
109 printStream.println("Uuid data");
110 printStream.println(SECTION_SEPERATOR);
111 deviceInfo.getUuidData().entrySet().forEach((entry) -> {
112 printEntryUUID(printStream, entry);
114 printStream.println(SECTION_SEPERATOR);
115 printStream.println(SECTION_SEPERATOR);
119 private void printEntry(PrintStream console, Map.Entry<Class<? extends Identifiable>,
120 Map<InstanceIdentifier, HwvtepDeviceInfo.DeviceData>> entry) {
121 Class<? extends Identifiable> cls = entry.getKey();
122 Map<InstanceIdentifier, HwvtepDeviceInfo.DeviceData> map = entry.getValue();
123 String clsName = cls.getSimpleName();
124 console.println(clsName + " - ");
125 map.values().forEach((deviceData) -> {
126 printTable(console, clsName, deviceData);
130 private void printTable(PrintStream console, String clsName, HwvtepDeviceInfo.DeviceData deviceData) {
132 if (clsName.equals("LogicalSwitches")) {
133 printLogicalSwitches(console, deviceData);
134 } else if (clsName.equals("RemoteMcastMacs")) {
135 printRemoteMcasts(console, deviceData);
136 } else if (clsName.equals("RemoteUcastMacs")) {
137 printRemoteUcasts(console, deviceData);
138 } else if (clsName.equals("TerminationPoint") || clsName.equals("VlanBindings")) {
139 printTerminationPoint(console, deviceData);
140 } else if (clsName.equals("Node")) {
141 printNode(console, deviceData);
143 printCommon(console, deviceData);
146 if (deviceData.getData() == null && deviceData.getStatus() != HwvtepDeviceInfo.DeviceDataStatus.IN_TRANSIT) {
147 console.print("data null unexpected ");
150 console.print(deviceData.getStatus());
152 console.println(deviceData.getUuid());
155 private void printLogicalSwitches(PrintStream console, HwvtepDeviceInfo.DeviceData deviceData) {
156 InstanceIdentifier<LogicalSwitches> ls = deviceData.getKey();
157 console.print(ls.firstKeyOf(LogicalSwitches.class).getHwvtepNodeName().getValue());
160 private void printRemoteMcasts(PrintStream console, HwvtepDeviceInfo.DeviceData deviceData) {
161 InstanceIdentifier<RemoteMcastMacs> remoteMcastMacsIid = deviceData.getKey();
162 String macAddress = remoteMcastMacsIid.firstKeyOf(RemoteMcastMacs.class).getMacEntryKey().getValue();
163 String logicalSwitchRef = remoteMcastMacsIid.firstKeyOf(RemoteMcastMacs.class).getLogicalSwitchRef().getValue()
164 .firstKeyOf(LogicalSwitches.class).getHwvtepNodeName().getValue();
165 StringBuilder macEntryDetails = new StringBuilder(macAddress).append(" LogicalSwitchRef ")
166 .append(logicalSwitchRef);
167 console.print(macEntryDetails);
170 private void printRemoteUcasts(PrintStream console, HwvtepDeviceInfo.DeviceData deviceData) {
171 InstanceIdentifier<RemoteUcastMacs> remoteUcastMacsIid = deviceData.getKey();
172 String macAddress = remoteUcastMacsIid.firstKeyOf(RemoteUcastMacs.class).getMacEntryKey().getValue();
173 String logicalSwitchRef = remoteUcastMacsIid.firstKeyOf(RemoteUcastMacs.class).getLogicalSwitchRef().getValue()
174 .firstKeyOf(LogicalSwitches.class).getHwvtepNodeName().getValue();
175 StringBuilder macEntryDetails = new StringBuilder(macAddress).append(" LogicalSwitchRef ")
176 .append(logicalSwitchRef);
177 console.print(macEntryDetails);
180 private void printTerminationPoint(PrintStream console, HwvtepDeviceInfo.DeviceData deviceData) {
181 InstanceIdentifier<TerminationPoint> terminationPointIid = deviceData.getKey();
182 console.print(terminationPointIid.firstKeyOf(TerminationPoint.class).getTpId().getValue());
184 PhysicalPort physicalPort = (PhysicalPort) deviceData.getData();
185 console.print(" " + physicalPort.getVlanBindingsColumn().getData().keySet());
186 } catch (ClassCastException exp) {
187 //This is the Karaf cli display command , ignore the exception.
191 private void printNode(PrintStream console, HwvtepDeviceInfo.DeviceData deviceData) {
192 InstanceIdentifier<Node> ls = deviceData.getKey();
193 console.print(ls.firstKeyOf(Node.class).getNodeId().getValue());
196 private void printCommon(PrintStream console, HwvtepDeviceInfo.DeviceData deviceData) {
197 console.print(deviceData.getKey());
199 if (deviceData.getData() == null && deviceData.getStatus() != HwvtepDeviceInfo.DeviceDataStatus.IN_TRANSIT) {
200 console.print("data null unexpected ");
202 console.print(deviceData.getStatus());
204 console.println(deviceData.getUuid());
207 private void printEntryUUID(PrintStream console, Map.Entry<Class<? extends Identifiable>, Map<UUID,
208 HwvtepDeviceInfo.DeviceData>> entry) {
209 Class<? extends Identifiable> cls = entry.getKey();
210 Map<UUID, HwvtepDeviceInfo.DeviceData> map = entry.getValue();
211 String clsName = cls.getSimpleName();
212 console.println(clsName + " - ");
213 map.values().forEach((deviceData) -> {
214 printTable(console, clsName, deviceData);