From 4c08b0694c65f1bb434538980a44a94e5ae15d24 Mon Sep 17 00:00:00 2001 From: Nataliia Solomko Date: Fri, 17 Oct 2025 15:21:41 +0300 Subject: T7938: VPP: Rewrite sFlow implementation Execute commands for vpp sflow with API calls. Use values for polling interval and sampling rate from 'system sflow'. Add op-mode command --- python/vyos/vpp/sflow/__init__.py | 3 +++ python/vyos/vpp/sflow/sflow.py | 49 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 python/vyos/vpp/sflow/__init__.py create mode 100644 python/vyos/vpp/sflow/sflow.py (limited to 'python') diff --git a/python/vyos/vpp/sflow/__init__.py b/python/vyos/vpp/sflow/__init__.py new file mode 100644 index 000000000..8d27be75a --- /dev/null +++ b/python/vyos/vpp/sflow/__init__.py @@ -0,0 +1,3 @@ +from .sflow import SFlow + +__all__ = ['SFlow'] diff --git a/python/vyos/vpp/sflow/sflow.py b/python/vyos/vpp/sflow/sflow.py new file mode 100644 index 000000000..7677d32b3 --- /dev/null +++ b/python/vyos/vpp/sflow/sflow.py @@ -0,0 +1,49 @@ +# +# Copyright (C) VyOS Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +from vyos.vpp import VPPControl + + +class SFlow: + def __init__(self): + self.vpp = VPPControl() + + def enable_sflow(self, interface): + """Enable sFlow on interface""" + self.vpp.api.sflow_enable_disable( + enable_disable=True, + sw_if_index=self.vpp.get_sw_if_index(interface), + ) + + def disable_sflow(self, interface): + """Disable sFlow on interface""" + self.vpp.api.sflow_enable_disable( + enable_disable=False, + sw_if_index=self.vpp.get_sw_if_index(interface), + ) + + def set_sampling_rate(self, sample_rate): + """Set sFlow sampling-rate""" + self.vpp.api.sflow_sampling_rate(sampling_N=sample_rate) + + def set_polling_interval(self, interval): + """Set sFlow polling interval""" + self.vpp.api.sflow_polling_interval(polling_S=interval) + + def set_header_bytes(self, header_bytes): + """Set sFlow maximum header length in bytes""" + self.vpp.api.sflow_header_bytes(header_B=header_bytes) -- cgit v1.2.3