Skip to content

Commit

Permalink
Adding support for DSCP configuration
Browse files Browse the repository at this point in the history
Allow the user to do DSCP mapping for network objects
Interface and SriovPF. The feature needs the handling
of netlink messages. The pyroute2 module is used in
the encode/decode of the netlink messages.
The persistence of the DSCP configurations are taken care
by the os-net-config-dcb-config service. The user configurations
are preserved in /var/lib/os-net-config/dcb_config.yaml

The details of the DSCP configurations could be read anytime
with the cli.
``os-net-config-dcb --show``

The new DSCP configurations can be applied with cli using
``os-net-config-dcb --config <config.yaml>``

The sample config.yaml for updating DCB only is available at
etc/os-net-config/samples/dcb_config_sample.yaml
  • Loading branch information
karthiksundaravel committed Feb 23, 2024
1 parent 28f6860 commit 3c11aef
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 3c11aef

Please sign in to comment.