Skip to content

Commit 1517192

Browse files
authored
Merge pull request #4687 from l0crian1/vid-to-vni-stats
op-mode: T7764: Add 'vlan-to-vni statistics' op-mode command
2 parents 8822c56 + e92d007 commit 1517192

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

op-mode-definitions/show-interfaces-vxlan.xml.in

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@
5252
</properties>
5353
<command>${vyos_op_scripts_dir}/interfaces.py show_vlan_to_vni --intf-name="$4" --vid="$7" --detail</command>
5454
</leafNode>
55+
<leafNode name="statistics">
56+
<properties>
57+
<help>Show VLAN to VNI statistics for the specified VLAN</help>
58+
</properties>
59+
<command>${vyos_op_scripts_dir}/interfaces.py show_vlan_to_vni --intf-name="$4" --vid="$7" --statistics</command>
60+
</leafNode>
5561
</children>
5662
</tagNode>
5763
<leafNode name="detail">
@@ -60,6 +66,12 @@
6066
</properties>
6167
<command>${vyos_op_scripts_dir}/interfaces.py show_vlan_to_vni --intf-name="$4" --detail</command>
6268
</leafNode>
69+
<leafNode name="statistics">
70+
<properties>
71+
<help>Show VLAN to VNI statistics for the specified VXLAN interface</help>
72+
</properties>
73+
<command>${vyos_op_scripts_dir}/interfaces.py show_vlan_to_vni --intf-name="$4" --statistics</command>
74+
</leafNode>
6375
</children>
6476
</node>
6577
#include <include/show-interface-type-event-log.xml.i>

src/op_mode/interfaces.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,9 @@ def show_counters(raw: bool, intf_name: typing.Optional[str],
664664
return _show_raw(data, intf_name)
665665
return _format_show_counters(data)
666666

667-
def show_vlan_to_vni(raw: bool, intf_name: typing.Optional[str], vid: typing.Optional[str], detail: bool):
667+
def show_vlan_to_vni(raw: bool, intf_name: typing.Optional[str],
668+
vid: typing.Optional[str], detail: bool,
669+
statistics: bool):
668670
if not interface_exists(intf_name):
669671
raise vyos.opmode.UnconfiguredObject(f"Interface {intf_name} does not exist\n")
670672

@@ -696,6 +698,14 @@ def show_vlan_to_vni(raw: bool, intf_name: typing.Optional[str], vid: typing.Opt
696698
vlan_id = str(vlan.get("vid"))
697699
description = mapping_config.get(vlan_id, {}).get("description", "")
698700

701+
# detail allows for longer descriptions; each output wraps to 80 characters
702+
if detail:
703+
description = "\n".join(textwrap.wrap(description, width=65))
704+
elif raw:
705+
pass
706+
else:
707+
description = "\n".join(textwrap.wrap(description, width=48))
708+
699709
if raw:
700710
tunnel_dict["vlan"] = vlan_id
701711
tunnel_dict["rx_bytes"] = vlan.get("rx_bytes")
@@ -709,22 +719,26 @@ def show_vlan_to_vni(raw: bool, intf_name: typing.Optional[str], vid: typing.Opt
709719
*([intf_name] if not detail else []),
710720
vlan_id,
711721
tunnel_id,
712-
description,
713-
*([vlan.get("rx_bytes")] if detail else []),
714-
*([vlan.get("tx_bytes")] if detail else []),
715-
*([vlan.get("rx_packets")] if detail else []),
716-
*([vlan.get("tx_packets")] if detail else [])
722+
*([description] if not statistics else []),
723+
*([vlan.get("rx_packets")] if any([detail, statistics]) else []),
724+
*([vlan.get("rx_bytes")] if any([detail, statistics]) else []),
725+
*([vlan.get("tx_packets")] if any([detail, statistics]) else []),
726+
*([vlan.get("tx_bytes")] if any([detail, statistics]) else [])
717727
])
718728

719729
if raw:
720730
return raw_data
721731

722732
if detail:
723733
# Detail headers; ex. show interfaces vxlan vxlan1 vlan-to-vni detail
724-
detail_header = ['VLAN', 'VNI', 'Description', 'Rx Bytes', 'Tx Bytes', 'Rx Packets', 'Tx Packets']
734+
detail_header = ['VLAN', 'VNI', 'Description', 'Rx Packets', 'Rx Bytes', 'Tx Packets', 'Tx Bytes']
725735
print('-' * 35)
726736
print(f"Interface: {intf_name}\n")
727737
detailed_output(output_list, detail_header)
738+
elif statistics:
739+
# Statistics headers; ex. show interfaces vxlan vxlan1 vlan-to-vni statistics
740+
headers = ['Interface', 'VLAN', 'VNI', 'Rx Packets', 'Rx Bytes', 'Tx Packets', 'Tx Bytes']
741+
print(tabulate(output_list, headers))
728742
else:
729743
# Normal headers; ex. show interfaces vxlan vxlan1 vlan-to-vni
730744
headers = ['Interface', 'VLAN', 'VNI', 'Description']

0 commit comments

Comments
 (0)