From 4ba8c59fd824ffc2c2a372b8af505db351b6ac60 Mon Sep 17 00:00:00 2001 From: Pim van Pelt Date: Mon, 28 Oct 2024 16:13:34 +0100 Subject: [PATCH] Add planner for sFlow --- vppcfg/vpp/reconciler.py | 52 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/vppcfg/vpp/reconciler.py b/vppcfg/vpp/reconciler.py index 6797044..500424f 100644 --- a/vppcfg/vpp/reconciler.py +++ b/vppcfg/vpp/reconciler.py @@ -967,6 +967,9 @@ class Reconciler: if not self.__sync_mpls_state(): self.logger.warning("Could not sync interface MPLS state in VPP") ret = False + if not self.__sync_sflow_state(): + self.logger.warning("Could not sync interface sFlow state in VPP") + ret = False if not self.__sync_admin_state(): self.logger.warning("Could not sync interface adminstate in VPP") ret = False @@ -1311,6 +1314,55 @@ class Reconciler: ret = False return ret + def __sync_sflow_state(self): + """Synchronize the VPP Dataplane configuration and phy sFlow state""" + + if "sflow" in self.cfg and self.vpp.cache["sflow"]: + if "header-bytes" in self.cfg["sflow"]: + if ( + self.vpp.cache["sflow"]["header-bytes"] + != self.cfg["sflow"]["header-bytes"] + ): + cli = f"sflow header-bytes {self.cfg['sflow']['header-bytes']}" + self.cli["sync"].append(cli) + if "polling-interval" in self.cfg["sflow"]: + if ( + self.vpp.cache["sflow"]["polling-interval"] + != self.cfg["sflow"]["polling-interval"] + ): + cli = f"sflow polling-interval {self.cfg['sflow']['polling-interval']}" + self.cli["sync"].append(cli) + if "sampling-rate" in self.cfg["sflow"]: + if ( + self.vpp.cache["sflow"]["sampling-rate"] + != self.cfg["sflow"]["sampling-rate"] + ): + cli = f"sflow sampling-rate {self.cfg['sflow']['sampling-rate']}" + self.cli["sync"].append(cli) + + for ifname in interface.get_interfaces(self.cfg): + vpp_ifname, config_iface = interface.get_by_name(self.cfg, ifname) + + try: + config_sflow = config_iface["sflow"] + except KeyError: + config_sflow = False + + vpp_sflow = False + if vpp_ifname in self.vpp.cache["interface_names"]: + hw_if_index = self.vpp.cache["interface_names"][vpp_ifname] + try: + vpp_sflow = self.vpp.cache["interface_sflow"][hw_if_index] + except KeyError: + pass + if vpp_sflow != config_sflow: + if config_sflow: + cli = f"sflow enable {vpp_ifname}" + else: + cli = f"sflow enable-disable {vpp_ifname} disable" + self.cli["sync"].append(cli) + return True + def __sync_mpls_state(self): """Synchronize the VPP Dataplane configuration for interface and loopback MPLS state""" for ifname in loopback.get_loopbacks(self.cfg) + interface.get_interfaces(