diff options
| author | Christian Breunig <christian@breunig.cc> | 2025-09-09 16:09:25 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-09 16:09:25 +0200 |
| commit | 151719295965fdb834cf507a3feb44fa80798fd8 (patch) | |
| tree | 607e0808a1d88dc83cfa695994e5cb6a013dbb8a | |
| parent | 8822c569cf151fcc896732fa32acc04ac7193cf0 (diff) | |
| parent | e92d00786e7cec3cc9cd144d061a0d66956bc7fe (diff) | |
| download | vyos-1x-151719295965fdb834cf507a3feb44fa80798fd8.tar.gz vyos-1x-151719295965fdb834cf507a3feb44fa80798fd8.zip | |
Merge pull request #4687 from l0crian1/vid-to-vni-stats
op-mode: T7764: Add 'vlan-to-vni statistics' op-mode command
| -rw-r--r-- | op-mode-definitions/show-interfaces-vxlan.xml.in | 12 | ||||
| -rwxr-xr-x | src/op_mode/interfaces.py | 28 |
2 files changed, 33 insertions, 7 deletions
diff --git a/op-mode-definitions/show-interfaces-vxlan.xml.in b/op-mode-definitions/show-interfaces-vxlan.xml.in index 59ce7a43c..6241361d9 100644 --- a/op-mode-definitions/show-interfaces-vxlan.xml.in +++ b/op-mode-definitions/show-interfaces-vxlan.xml.in @@ -52,6 +52,12 @@ </properties> <command>${vyos_op_scripts_dir}/interfaces.py show_vlan_to_vni --intf-name="$4" --vid="$7" --detail</command> </leafNode> + <leafNode name="statistics"> + <properties> + <help>Show VLAN to VNI statistics for the specified VLAN</help> + </properties> + <command>${vyos_op_scripts_dir}/interfaces.py show_vlan_to_vni --intf-name="$4" --vid="$7" --statistics</command> + </leafNode> </children> </tagNode> <leafNode name="detail"> @@ -60,6 +66,12 @@ </properties> <command>${vyos_op_scripts_dir}/interfaces.py show_vlan_to_vni --intf-name="$4" --detail</command> </leafNode> + <leafNode name="statistics"> + <properties> + <help>Show VLAN to VNI statistics for the specified VXLAN interface</help> + </properties> + <command>${vyos_op_scripts_dir}/interfaces.py show_vlan_to_vni --intf-name="$4" --statistics</command> + </leafNode> </children> </node> #include <include/show-interface-type-event-log.xml.i> diff --git a/src/op_mode/interfaces.py b/src/op_mode/interfaces.py index f238042a7..2e0be90e7 100755 --- a/src/op_mode/interfaces.py +++ b/src/op_mode/interfaces.py @@ -664,7 +664,9 @@ def show_counters(raw: bool, intf_name: typing.Optional[str], return _show_raw(data, intf_name) return _format_show_counters(data) -def show_vlan_to_vni(raw: bool, intf_name: typing.Optional[str], vid: typing.Optional[str], detail: bool): +def show_vlan_to_vni(raw: bool, intf_name: typing.Optional[str], + vid: typing.Optional[str], detail: bool, + statistics: bool): if not interface_exists(intf_name): raise vyos.opmode.UnconfiguredObject(f"Interface {intf_name} does not exist\n") @@ -696,6 +698,14 @@ def show_vlan_to_vni(raw: bool, intf_name: typing.Optional[str], vid: typing.Opt vlan_id = str(vlan.get("vid")) description = mapping_config.get(vlan_id, {}).get("description", "") + # detail allows for longer descriptions; each output wraps to 80 characters + if detail: + description = "\n".join(textwrap.wrap(description, width=65)) + elif raw: + pass + else: + description = "\n".join(textwrap.wrap(description, width=48)) + if raw: tunnel_dict["vlan"] = vlan_id tunnel_dict["rx_bytes"] = vlan.get("rx_bytes") @@ -709,11 +719,11 @@ def show_vlan_to_vni(raw: bool, intf_name: typing.Optional[str], vid: typing.Opt *([intf_name] if not detail else []), vlan_id, tunnel_id, - description, - *([vlan.get("rx_bytes")] if detail else []), - *([vlan.get("tx_bytes")] if detail else []), - *([vlan.get("rx_packets")] if detail else []), - *([vlan.get("tx_packets")] if detail else []) + *([description] if not statistics else []), + *([vlan.get("rx_packets")] if any([detail, statistics]) else []), + *([vlan.get("rx_bytes")] if any([detail, statistics]) else []), + *([vlan.get("tx_packets")] if any([detail, statistics]) else []), + *([vlan.get("tx_bytes")] if any([detail, statistics]) else []) ]) if raw: @@ -721,10 +731,14 @@ def show_vlan_to_vni(raw: bool, intf_name: typing.Optional[str], vid: typing.Opt if detail: # Detail headers; ex. show interfaces vxlan vxlan1 vlan-to-vni detail - detail_header = ['VLAN', 'VNI', 'Description', 'Rx Bytes', 'Tx Bytes', 'Rx Packets', 'Tx Packets'] + detail_header = ['VLAN', 'VNI', 'Description', 'Rx Packets', 'Rx Bytes', 'Tx Packets', 'Tx Bytes'] print('-' * 35) print(f"Interface: {intf_name}\n") detailed_output(output_list, detail_header) + elif statistics: + # Statistics headers; ex. show interfaces vxlan vxlan1 vlan-to-vni statistics + headers = ['Interface', 'VLAN', 'VNI', 'Rx Packets', 'Rx Bytes', 'Tx Packets', 'Tx Bytes'] + print(tabulate(output_list, headers)) else: # Normal headers; ex. show interfaces vxlan vxlan1 vlan-to-vni headers = ['Interface', 'VLAN', 'VNI', 'Description'] |
