Add sflow schema, validators (currently nothing to do), and dumper

This commit is contained in:
2024-10-28 15:49:35 +01:00
parent c859738b0f
commit 78a6f413aa
6 changed files with 93 additions and 12 deletions

View File

@ -40,6 +40,7 @@ from .vxlan_tunnel import validate_vxlan_tunnels
from .tap import validate_taps from .tap import validate_taps
from .prefixlist import validate_prefixlists from .prefixlist import validate_prefixlists
from .acl import validate_acls from .acl import validate_acls
from .sflow import validate_sflow
class IPInterfaceWithPrefixLength(validators.Validator): class IPInterfaceWithPrefixLength(validators.Validator):
@ -94,6 +95,7 @@ class Validator:
validate_taps, validate_taps,
validate_prefixlists, validate_prefixlists,
validate_acls, validate_acls,
validate_sflow,
] ]
def validate(self, yaml): def validate(self, yaml):

30
vppcfg/config/sflow.py Normal file
View File

@ -0,0 +1,30 @@
#
# Copyright (c) 2024 Pim van Pelt
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
""" A vppcfg configuration module that validates sflow config """
import logging
def validate_sflow(yaml):
"""Validate the semantics of all YAML 'sflow' config entries"""
result = True
msgs = []
logger = logging.getLogger("vppcfg.config")
logger.addHandler(logging.NullHandler())
if not "sflow" in yaml:
return result, msgs
## NOTE(pim): Nothing to validate. sflow config values are all
## integers and enforced by yamale.
return result, msgs

View File

@ -10,10 +10,12 @@ interfaces:
device-type: dpdk device-type: dpdk
mtu: 9000 mtu: 9000
description: "LAG #1" description: "LAG #1"
sflow: true
GigabitEthernet3/0/1: GigabitEthernet3/0/1:
device-type: dpdk device-type: dpdk
mtu: 9000 mtu: 9000
description: "LAG #2" description: "LAG #2"
sflow: false
HundredGigabitEthernet12/0/0: HundredGigabitEthernet12/0/0:
device-type: dpdk device-type: dpdk
@ -163,3 +165,8 @@ acls:
icmp-code: any icmp-code: any
- description: "Deny any IPv4 or IPv6" - description: "Deny any IPv4 or IPv6"
action: deny action: deny
sflow:
header-bytes: 128
polling-interval: 30
sample-rate: 1000

View File

@ -6,6 +6,7 @@ vxlan_tunnels: map(include('vxlan'),key=str(matches='vxlan_tunnel[0-9]+'),requir
taps: map(include('tap'),key=str(matches='tap[0-9]+'),required=False) taps: map(include('tap'),key=str(matches='tap[0-9]+'),required=False)
prefixlists: map(include('prefixlist'),key=str(matches='[a-z][a-z0-9\-]+',min=1,max=64),required=False) prefixlists: map(include('prefixlist'),key=str(matches='[a-z][a-z0-9\-]+',min=1,max=64),required=False)
acls: map(include('acl'),key=str(matches='[a-z][a-z0-9\-]+',min=1,max=56),required=False) acls: map(include('acl'),key=str(matches='[a-z][a-z0-9\-]+',min=1,max=56),required=False)
sflow: include('sflow',required=False)
--- ---
vxlan: vxlan:
description: str(exclude='\'"',len=64,required=False) description: str(exclude='\'"',len=64,required=False)
@ -57,6 +58,7 @@ interface:
state: enum('up', 'down', required=False) state: enum('up', 'down', required=False)
mpls: bool(required=False) mpls: bool(required=False)
device-type: enum('dpdk', required=False) device-type: enum('dpdk', required=False)
sflow: bool(required=False)
--- ---
sub-interface: sub-interface:
description: str(exclude='\'"',len=64,required=False) description: str(exclude='\'"',len=64,required=False)
@ -113,3 +115,8 @@ acl-term:
acl: acl:
description: str(exclude='\'"',len=64,required=False) description: str(exclude='\'"',len=64,required=False)
terms: list(include('acl-term'), min=1, max=100, required=True) terms: list(include('acl-term'), min=1, max=100, required=True)
---
sflow:
header-bytes: int(min=1,max=256,required=False)
polling-interval: int(min=5,max=600,required=False)
sample-rate: int(min=100,max=1000000,required=False)

View File

@ -67,6 +67,7 @@ class Dumper(VPPApi):
"taps": {}, "taps": {},
"prefixlists": {}, "prefixlists": {},
"acls": {}, "acls": {},
"sflow": {},
} }
for idx, bond_iface in self.cache["bondethernets"].items(): for idx, bond_iface in self.cache["bondethernets"].items():
bond = {"description": ""} bond = {"description": ""}
@ -301,9 +302,9 @@ class Dumper(VPPApi):
acl_rule.srcport_or_icmptype_first acl_rule.srcport_or_icmptype_first
) )
else: else:
config_term["icmp-type"] = ( config_term[
f"{acl_rule.srcport_or_icmptype_first}-{maxval}" "icmp-type"
) ] = f"{acl_rule.srcport_or_icmptype_first}-{maxval}"
maxval = acl_rule.dstport_or_icmpcode_last maxval = acl_rule.dstport_or_icmpcode_last
if maxval > 255: if maxval > 255:
@ -316,9 +317,9 @@ class Dumper(VPPApi):
acl_rule.dstport_or_icmpcode_first acl_rule.dstport_or_icmpcode_first
) )
else: else:
config_term["icmp-code"] = ( config_term[
f"{acl_rule.dstport_or_icmpcode_first}-{maxval}" "icmp-code"
) ] = f"{acl_rule.dstport_or_icmpcode_first}-{maxval}"
elif acl_rule.proto in [6, 17]: elif acl_rule.proto in [6, 17]:
if acl_rule.proto == 6: if acl_rule.proto == 6:
config_term["protocol"] = "tcp" config_term["protocol"] = "tcp"
@ -332,9 +333,9 @@ class Dumper(VPPApi):
acl_rule.srcport_or_icmptype_first acl_rule.srcport_or_icmptype_first
) )
else: else:
config_term["source-port"] = ( config_term[
f"{acl_rule.srcport_or_icmptype_first}-{acl_rule.srcport_or_icmptype_last}" "source-port"
) ] = f"{acl_rule.srcport_or_icmptype_first}-{acl_rule.srcport_or_icmptype_last}"
if ( if (
acl_rule.dstport_or_icmpcode_first acl_rule.dstport_or_icmpcode_first
== acl_rule.dstport_or_icmpcode_last == acl_rule.dstport_or_icmpcode_last
@ -343,9 +344,9 @@ class Dumper(VPPApi):
acl_rule.dstport_or_icmpcode_first acl_rule.dstport_or_icmpcode_first
) )
else: else:
config_term["destination-port"] = ( config_term[
f"{acl_rule.dstport_or_icmpcode_first}-{acl_rule.dstport_or_icmpcode_last}" "destination-port"
) ] = f"{acl_rule.dstport_or_icmpcode_first}-{acl_rule.dstport_or_icmpcode_last}"
else: else:
config_term["protocol"] = int(acl_rule.proto) config_term["protocol"] = int(acl_rule.proto)
@ -353,4 +354,9 @@ class Dumper(VPPApi):
config["acls"][aclname] = config_acl config["acls"][aclname] = config_acl
config["sflow"] = self.cache["sflow"]
for hw_if_index in self.cache["interface_sflow"]:
vpp_iface = self.cache["interfaces"][hw_if_index]
config["interfaces"][vpp_iface.interface_name]["sflow"] = True
return config return config

View File

@ -130,6 +130,8 @@ class VPPApi:
"taps": {}, "taps": {},
"acls": {}, "acls": {},
"acl_tags": {}, "acl_tags": {},
"interface_sflow": {},
"sflow": {},
} }
return True return True
@ -415,6 +417,33 @@ class VPPApi:
for tap in api_response: for tap in api_response:
self.cache["taps"][tap.sw_if_index] = tap self.cache["taps"][tap.sw_if_index] = tap
try:
self.logger.debug("Retrieving sFlow")
api_response = self.vpp.api.sflow_sampling_rate_get()
if api_response:
self.cache["sflow"]["sampling-rate"] = api_response.sampling_N
api_response = self.vpp.api.sflow_polling_interval_get()
if api_response:
self.cache["sflow"]["polling-interval"] = api_response.polling_S
api_response = self.vpp.api.sflow_header_bytes_get()
if api_response:
self.cache["sflow"]["header-bytes"] = api_response.header_B
api_response = self.vpp.api.sflow_interface_dump()
for iface in api_response:
self.cache["interface_sflow"][iface.hw_if_index] = True
except AttributeError as err:
self.logger.warning(f"sFlow API not found - missing plugin: {err}")
self.logger.debug("Retrieving interface Unnumbered state")
api_response = self.vpp.api.ip_unnumbered_dump()
for iface in api_response:
self.cache["interface_unnumbered"][iface.sw_if_index] = iface.ip_sw_if_index
self.logger.debug("Retrieving bondethernets")
api_response = self.vpp.api.sw_bond_interface_dump()
self.cache_read = True self.cache_read = True
return self.cache_read return self.cache_read