Skip to content

Commit

Permalink
Adding support for DSCP configuration (#9)
Browse files Browse the repository at this point in the history
Support dscp configuration using os-net-config templates. It uses
pyroute2 modules to send/receive, encode/decode the netlink messages.
The persistence of the configuration is done with dcb_config.service
  • Loading branch information
vcandapp committed Feb 28, 2024
2 parents 4602528 + 3c11aef commit 2e998f5
Show file tree
Hide file tree
Showing 14 changed files with 995 additions and 34 deletions.
17 changes: 17 additions & 0 deletions etc/os-net-config/samples/dcb_config_sample.yaml
@@ -0,0 +1,17 @@
# For reconfiguring the DCB, the below template could be used.
# use ``os-net-config-dcb -c <config.yaml> `` to perform the
# reconfiguration.

dcb_config:
-
type: dcb_config
name: ens1f0np0
dscp2prio:
# Add the dscp configs.
# It requires priority and protocol
- priority: 5
protocol: 45
- priority: 5
protocol: 46
- priority: 6
protocol: 47
24 changes: 24 additions & 0 deletions etc/os-net-config/samples/dcb_sample.yaml
@@ -0,0 +1,24 @@
network_config:
-
type: sriov_pf
name: ens1f0np0
numvfs: 4
use_dhcp: false
dcb:
dscp2prio:
# Add the dscp configs.
# It requires priority and protocol
- priority: 5
protocol: 45
- priority: 5
protocol: 46
- priority: 6
protocol: 47
-
type: sriov_pf
name: ens1f1np1
numvfs: 4
use_dhcp: false
dcb:
# Remove the dscp configurations
dscp2prio: []
13 changes: 13 additions & 0 deletions os_net_config/cli.py
Expand Up @@ -22,6 +22,7 @@
import yaml

from os_net_config import common
from os_net_config import dcb_config
from os_net_config import impl_eni
from os_net_config import impl_ifcfg
from os_net_config import impl_iproute
Expand Down Expand Up @@ -279,6 +280,11 @@ def main(argv=sys.argv, main_logger=None):
else:
main_logger.warning('\n'.join(validation_errors))

# Reset the DCB Config during rerun.
# This is required to apply the new values and clear the old ones
if utils.is_dcb_config_required():
common.reset_dcb_map()

# Look for the presence of SriovPF types in the first parse of the json
# if SriovPFs exists then PF devices needs to be configured so that the VF
# devices are created.
Expand Down Expand Up @@ -347,6 +353,13 @@ def main(argv=sys.argv, main_logger=None):

files_changed = provider.apply(cleanup=opts.cleanup,
activate=not opts.no_activate)

if utils.is_dcb_config_required():
# Apply the DCB Config
utils.configure_dcb_config_service()
dcb_apply = dcb_config.DcbApplyConfig()
dcb_apply.apply()

if opts.noop:
if configure_sriov:
files_changed.update(pf_files_changed)
Expand Down
80 changes: 80 additions & 0 deletions os_net_config/common.py
Expand Up @@ -56,6 +56,18 @@
# promisc: "on"/"off"
SRIOV_CONFIG_FILE = '/var/lib/os-net-config/sriov_config.yaml'

# File to contain the list of DCB configurations
# Format of the file shall be
# - name: <pf name>
# dscp2prio:
# - protocol: 44
# selector: 5
# priority: 6
# - protocol: 42
# selector: 5
# priority: 3

DCB_CONFIG_FILE = '/var/lib/os-net-config/dcb_config.yaml'

_SYS_BUS_PCI_DEV = '/sys/bus/pci/devices'
SYS_CLASS_NET = '/sys/class/net'
Expand Down Expand Up @@ -146,6 +158,74 @@ def get_file_data(filename):
return ''


def write_yaml_config(filepath, data):
os.makedirs(os.path.dirname(filepath), exist_ok=True)
with open(filepath, 'w') as f:
yaml.safe_dump(data, f, default_flow_style=False)


def update_dcb_map(ifname, pci_addr, driver, noop, dscp2prio=None):
if not noop:
dcb_map = get_dcb_config_map()
for item in dcb_map:
if item['pci_addr'] == pci_addr:
item['name'] = ifname
item['driver'] = driver
item['dscp2prio'] = dscp2prio
break
else:
new_item = {}
new_item['pci_addr'] = pci_addr
new_item['driver'] = driver
new_item['name'] = ifname
new_item['dscp2prio'] = dscp2prio
dcb_map.append(new_item)

write_yaml_config(DCB_CONFIG_FILE, dcb_map)


def write_dcb_map(dcb_map):
write_yaml_config(DCB_CONFIG_FILE, dcb_map)


def get_dcb_config_map():
contents = get_file_data(DCB_CONFIG_FILE)
dcb_config_map = yaml.safe_load(contents) if contents else []
return dcb_config_map


def get_empty_dcb_map():
contents = get_file_data(DCB_CONFIG_FILE)
dcb_config_map = yaml.safe_load(contents) if contents else []
for entry in dcb_config_map:
entry['dscp2prio'] = []
return dcb_config_map


def add_dcb_entry(dcb_config_map, data):
for entry in dcb_config_map:
if entry['pci_addr'] == data.pci_addr:
entry['dscp2prio'] = data.dscp2prio
entry['name'] = data.name
entry['driver'] = data.driver
break
else:
new_entry = {}
new_entry['name'] = data.name
new_entry['pci_addr'] = data.pci_addr
new_entry['driver'] = data.driver
new_entry['dscp2prio'] = data.dscp2prio

dcb_config_map.append(new_entry)
return dcb_config_map


def reset_dcb_map():
dcb_map = get_empty_dcb_map()
if dcb_map != []:
write_dcb_map(dcb_map)


def get_sriov_map(pf_name=None):
contents = get_file_data(SRIOV_CONFIG_FILE)
sriov_map = yaml.safe_load(contents) if contents else []
Expand Down

0 comments on commit 2e998f5

Please sign in to comment.