From 1a3105c06d4cfb4ed5618575bcd74a482f87ed8b Mon Sep 17 00:00:00 2001 From: Richard Alpe Date: Tue, 26 Sep 2023 16:27:24 +0200 Subject: [PATCH] cli: pretty print existing Ethernet frame stats Pretty print all Ethernet frame statistics from the operational datastore. Only in the detailed interface view. Signed-off-by: Richard Alpe --- board/netconf/rootfs/lib/infix/cli-pretty | 17 +++++++++++++++++ test/case/cli_pretty/json/bloated.json | 23 +++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/board/netconf/rootfs/lib/infix/cli-pretty b/board/netconf/rootfs/lib/infix/cli-pretty index 2f8b249e..914a1e19 100755 --- a/board/netconf/rootfs/lib/infix/cli-pretty +++ b/board/netconf/rootfs/lib/infix/cli-pretty @@ -32,6 +32,16 @@ class Decore(): return Decore.decorate("32", txt, "39") class Iface: + def get_json_data(self, default, *args): + data = self.data + for arg in args: + if data.get(arg): + data = data.get(arg) + else: + return default + + return data + def __init__(self, data): self.data = data self.name = data.get('name', '') @@ -181,6 +191,13 @@ class Iface: print(f"{'in-octets':<{20}}: {self.in_octets}") print(f"{'out-octets':<{20}}: {self.out_octets}") + frame = self.get_json_data([], 'ieee802-ethernet-interface:ethernet', + 'statistics', 'frame') + if frame: + print(f"") + for key, val in frame.items(): + print(f"eth-{key:<{16}}: {val}") + def find_iface(_ifaces, name): for _iface in [Iface(data) for data in _ifaces]: diff --git a/test/case/cli_pretty/json/bloated.json b/test/case/cli_pretty/json/bloated.json index 1c425a5b..ef402cb7 100644 --- a/test/case/cli_pretty/json/bloated.json +++ b/test/case/cli_pretty/json/bloated.json @@ -189,6 +189,29 @@ ] } }, + { + "TEST-DESCR": "Interface ieee802-ethernet-interface stats", + "name": "e13", + "type": "infix-if-type:ethernet", + "oper-status": "up", + "if-index": 4, + "phys-address": "02:ee:00:00:12:00", + "statistics": { + "in-octets": "11", + "out-octets": "22" + }, + "ieee802-ethernet-interface:ethernet": { + "statistics": { + "frame": { + "in-frames": "1111", + "out-frames": "2222" + } + } + }, + "ietf-ip:ipv4": { + "mtu": 1500 + } + }, { "TEST-DESCR": "Interface with VLAN on top", "name": "e20",