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 static void print(InstanceIdentifier<Node> iid, HwvtepConnectionInstance connectionInstance) {
87 PrintStream printStream = System.out;
88 printStream.print("Printing for Node : ");
89 printStream.println(iid.firstKeyOf(Node.class).getNodeId().getValue());
91 printStream.println(SECTION_SEPERATOR);
92 printStream.println("Config data");
93 printStream.println(SECTION_SEPERATOR);
94 HwvtepDeviceInfo deviceInfo = connectionInstance.getDeviceInfo();
95 deviceInfo.getConfigData().entrySet().forEach((entry) -> {
96 printEntry(printStream, entry);
100 printStream.println(SECTION_SEPERATOR);
101 printStream.println("Oper data");
102 printStream.println(SECTION_SEPERATOR);
103 deviceInfo.getOperData().entrySet().forEach((entry) -> {
104 printEntry(printStream, entry);
107 printStream.println(SECTION_SEPERATOR);
108 printStream.println("Uuid data");
109 printStream.println(SECTION_SEPERATOR);
110 deviceInfo.getUuidData().entrySet().forEach((entry) -> {
111 printEntryUUID(printStream, entry);
113 printStream.println(SECTION_SEPERATOR);
114 printStream.println(SECTION_SEPERATOR);
118 private static void printEntry(PrintStream console, Map.Entry<Class<? extends Identifiable>,
119 Map<InstanceIdentifier, HwvtepDeviceInfo.DeviceData>> entry) {
120 Class<? extends Identifiable> cls = entry.getKey();
121 Map<InstanceIdentifier, HwvtepDeviceInfo.DeviceData> map = entry.getValue();
122 String clsName = cls.getSimpleName();
123 console.println(clsName + " - ");
124 map.values().forEach((deviceData) -> {
125 printTable(console, clsName, deviceData);
129 private static void printTable(PrintStream console, String clsName, HwvtepDeviceInfo.DeviceData deviceData) {
131 if (clsName.equals("LogicalSwitches")) {
132 printLogicalSwitches(console, deviceData);
133 } else if (clsName.equals("RemoteMcastMacs")) {
134 printRemoteMcasts(console, deviceData);
135 } else if (clsName.equals("RemoteUcastMacs")) {
136 printRemoteUcasts(console, deviceData);
137 } else if (clsName.equals("TerminationPoint") || clsName.equals("VlanBindings")) {
138 printTerminationPoint(console, deviceData);
139 } else if (clsName.equals("Node")) {
140 printNode(console, deviceData);
142 printCommon(console, deviceData);
145 if (deviceData.getData() == null && deviceData.getStatus() != HwvtepDeviceInfo.DeviceDataStatus.IN_TRANSIT) {
146 console.print("data null unexpected ");
149 console.print(deviceData.getStatus());
151 console.println(deviceData.getUuid());
154 private static void printLogicalSwitches(PrintStream console, HwvtepDeviceInfo.DeviceData deviceData) {
155 InstanceIdentifier<LogicalSwitches> ls = deviceData.getKey();
156 console.print(ls.firstKeyOf(LogicalSwitches.class).getHwvtepNodeName().getValue());
159 private static void printRemoteMcasts(PrintStream console, HwvtepDeviceInfo.DeviceData deviceData) {
160 InstanceIdentifier<RemoteMcastMacs> remoteMcastMacsIid = deviceData.getKey();
161 String macAddress = remoteMcastMacsIid.firstKeyOf(RemoteMcastMacs.class).getMacEntryKey().getValue();
162 String logicalSwitchRef = remoteMcastMacsIid.firstKeyOf(RemoteMcastMacs.class).getLogicalSwitchRef().getValue()
163 .firstKeyOf(LogicalSwitches.class).getHwvtepNodeName().getValue();
164 StringBuilder macEntryDetails = new StringBuilder(macAddress).append(" LogicalSwitchRef ")
165 .append(logicalSwitchRef);
166 console.print(macEntryDetails);
169 private static void printRemoteUcasts(PrintStream console, HwvtepDeviceInfo.DeviceData deviceData) {
170 InstanceIdentifier<RemoteUcastMacs> remoteUcastMacsIid = deviceData.getKey();
171 String macAddress = remoteUcastMacsIid.firstKeyOf(RemoteUcastMacs.class).getMacEntryKey().getValue();
172 String logicalSwitchRef = remoteUcastMacsIid.firstKeyOf(RemoteUcastMacs.class).getLogicalSwitchRef().getValue()
173 .firstKeyOf(LogicalSwitches.class).getHwvtepNodeName().getValue();
174 StringBuilder macEntryDetails = new StringBuilder(macAddress).append(" LogicalSwitchRef ")
175 .append(logicalSwitchRef);
176 console.print(macEntryDetails);
179 private static void printTerminationPoint(PrintStream console, HwvtepDeviceInfo.DeviceData deviceData) {
180 InstanceIdentifier<TerminationPoint> terminationPointIid = deviceData.getKey();
181 console.print(terminationPointIid.firstKeyOf(TerminationPoint.class).getTpId().getValue());
183 PhysicalPort physicalPort = (PhysicalPort) deviceData.getData();
184 console.print(" " + physicalPort.getVlanBindingsColumn().getData().keySet());
185 } catch (ClassCastException exp) {
186 //This is the Karaf cli display command , ignore the exception.
190 private static void printNode(PrintStream console, HwvtepDeviceInfo.DeviceData deviceData) {
191 InstanceIdentifier<Node> ls = deviceData.getKey();
192 console.print(ls.firstKeyOf(Node.class).getNodeId().getValue());
195 private static void printCommon(PrintStream console, HwvtepDeviceInfo.DeviceData deviceData) {
196 console.print(deviceData.getKey());
198 if (deviceData.getData() == null && deviceData.getStatus() != HwvtepDeviceInfo.DeviceDataStatus.IN_TRANSIT) {
199 console.print("data null unexpected ");
201 console.print(deviceData.getStatus());
203 console.println(deviceData.getUuid());
206 private static void printEntryUUID(PrintStream console, Map.Entry<Class<? extends Identifiable>, Map<UUID,
207 HwvtepDeviceInfo.DeviceData>> entry) {
208 Class<? extends Identifiable> cls = entry.getKey();
209 Map<UUID, HwvtepDeviceInfo.DeviceData> map = entry.getValue();
210 String clsName = cls.getSimpleName();
211 console.println(clsName + " - ");
212 map.values().forEach((deviceData) -> {
213 printTable(console, clsName, deviceData);