From: Bruce Richardson <bruce.richard...@intel.com>

This patch adds a python script that can be used with the new telemetry
socket. It connects as a client to the socket, and allows the user send
a command and see the JSON response.

The example usage below shows the script connecting to the new telemetry
socket, and sending two basic ethdev commands entered by the user.
The response for each command is shown below the user input.

Connecting to /var/run/dpdk/rte/dpdk_telemetry.v2
{"pid": 63724, "version": "DPDK 20.05.0-rc0", "max_output_len": 16384}
--> /
{"/": ["/", "/ethdev/link_status", "/ethdev/list", "/ethdev/xstats", \
    "/info"]}
--> /info
{"/info": {"pid": 63724, "version": "DPDK 20.05.0-rc0", \
    "max_output_len": 16384}}
--> /ethdev/list
{"/ethdev/list": [0, 1]}
--> /ethdev/link_status,0
{"/ethdev/link_status": {"status": "UP", "speed": 10000, "duplex": \
    "full-duplex"}}
--> /ethdev/xstats,0
{"/ethdev/xstats": {"rx_good_packets": 0, "tx_good_packets": 0, \
    <snip>
    "tx_priority7_xon_to_xoff_packets": 0}}

Signed-off-by: Bruce Richardson <bruce.richard...@intel.com>
Signed-off-by: Ciara Power <ciara.po...@intel.com>

---
v2:
  - Renamed new python script to dpdk-telemetry.py.
  - Fixed script to validate input before sending to Telemetry.
---
 usertools/dpdk-telemetry.py | 44 +++++++++++++++++++++++++++++++++++++
 usertools/meson.build       |  2 +-
 2 files changed, 45 insertions(+), 1 deletion(-)
 create mode 100755 usertools/dpdk-telemetry.py

diff --git a/usertools/dpdk-telemetry.py b/usertools/dpdk-telemetry.py
new file mode 100755
index 0000000000..55fa532136
--- /dev/null
+++ b/usertools/dpdk-telemetry.py
@@ -0,0 +1,44 @@
+#! /usr/bin/python3
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2020 Intel Corporation
+
+import socket
+import os
+import glob
+import json
+
+telemetry_version = "v2"
+
+def read_socket(buf_len):
+    reply = fd.recv(buf_len).decode()
+    try:
+        print(json.dumps(json.loads(reply)))
+        return json.loads(reply)
+    except:
+            print("Error in reply: ", reply)
+            raise
+
+def handle_socket(path):
+    print("Connecting to " + path)
+    try:
+        fd.connect(path)
+    except OSError:
+        return
+    json_reply = read_socket(1024)
+    output_buf_len = json_reply["max_output_len"]
+    text = input('--> ').strip()
+    while (text != "quit"):
+        if text.startswith('/'):
+            fd.send(text.encode())
+            read_socket(output_buf_len)
+        text = input('--> ').strip()
+
+    fd.close()
+
+fd = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET)
+# Path to sockets for processes run as a root user
+for f in glob.glob('/var/run/dpdk/*/dpdk_telemetry.%s' % telemetry_version):
+  handle_socket(f)
+# Path to sockets for processes run as a regular user
+for f in glob.glob('/run/user/%d/dpdk/*/dpdk_telemetry.%s' % (os.getuid(), 
telemetry_version)):
+  handle_socket(f)
diff --git a/usertools/meson.build b/usertools/meson.build
index 149e788e3d..64e27238f4 100644
--- a/usertools/meson.build
+++ b/usertools/meson.build
@@ -1,4 +1,4 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2017 Intel Corporation
 
-install_data(['dpdk-devbind.py', 'dpdk-pmdinfo.py'], install_dir: 'bin')
+install_data(['dpdk-devbind.py', 'dpdk-pmdinfo.py', 'dpdk-telemetry.py'], 
install_dir: 'bin')
-- 
2.17.1

Reply via email to