Skip to content

Commit

Permalink
cli: pretty print existing Ethernet frame stats
Browse files Browse the repository at this point in the history
Pretty print all Ethernet frame statistics from the operational
datastore. Only in the detailed interface view.

Signed-off-by: Richard Alpe <richard@bit42.se>
  • Loading branch information
rical committed Oct 11, 2023
1 parent 62e96a3 commit 220f268
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
17 changes: 17 additions & 0 deletions board/netconf/rootfs/lib/infix/cli-pretty
Original file line number Diff line number Diff line change
Expand Up @@ -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', '')
Expand Down Expand Up @@ -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]:
Expand Down
23 changes: 23 additions & 0 deletions test/case/cli_pretty/json/bloated.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 220f268

Please sign in to comment.