diff options
| author | l0crian1 <ryan.claridge13@gmail.com> | 2025-08-29 11:27:22 -0400 |
|---|---|---|
| committer | l0crian1 <ryan.claridge13@gmail.com> | 2025-08-29 11:27:22 -0400 |
| commit | 6403816d96f3675e66471d5c7cc464798d68a4cd (patch) | |
| tree | d2a7af9817466177da941ce8b995ed76452486dc | |
| parent | b1b4545cb7984cd3cdf42554ab2b28acd1ecb6cb (diff) | |
| download | vyos-1x-6403816d96f3675e66471d5c7cc464798d68a4cd.tar.gz vyos-1x-6403816d96f3675e66471d5c7cc464798d68a4cd.zip | |
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..11b0a64a6 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 statistics for the t0 VNI mapping</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'] |
