Skip to content

Commit

Permalink
[config qos] QoS and Buffer config genration for multi ASIC platforms (
Browse files Browse the repository at this point in the history
…#978)

* QoS and Buffer config genration for multi ASIC platforms. 

In case of multi ASIC platforms each ASIC has its own buffer and QoS 
configuration template that is used to populate corresponding ASIC's config DB. 
Made changes so that QoS config commands generates QoS and buffer configs for
all ASICs. Also the 'config qos clear' acts on all ASIC instances.
  • Loading branch information
smaheshm authored Aug 8, 2020
1 parent ed3d7cb commit a80826d
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 27 deletions.
117 changes: 92 additions & 25 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,10 +663,21 @@ def _clear_qos():
'BUFFER_PROFILE',
'BUFFER_PG',
'BUFFER_QUEUE']
config_db = ConfigDBConnector()
config_db.connect()
for qos_table in QOS_TABLE_NAMES:
config_db.delete_table(qos_table)

namespace_list = [DEFAULT_NAMESPACE]
if sonic_device_util.get_num_npus() > 1:
namespace_list = sonic_device_util.get_namespaces()

for ns in namespace_list:
if ns is DEFAULT_NAMESPACE:
config_db = ConfigDBConnector()
else:
config_db = ConfigDBConnector(
use_unix_socket_path=True, namespace=ns
)
config_db.connect()
for qos_table in QOS_TABLE_NAMES:
config_db.delete_table(qos_table)

def _get_sonic_generated_services(num_asic):
if not os.path.isfile(SONIC_GENERATED_SERVICE_PATH):
Expand Down Expand Up @@ -1231,11 +1242,11 @@ def load_minigraph(db, no_service_restart):
if namespace is DEFAULT_NAMESPACE:
config_db = ConfigDBConnector()
cfggen_namespace_option = " "
ns_cmd_prefix = " "
ns_cmd_prefix = ""
else:
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
cfggen_namespace_option = " -n {}".format(namespace)
ns_cmd_prefix = "sudo ip netns exec {}".format(namespace)
ns_cmd_prefix = "sudo ip netns exec {} ".format(namespace)
config_db.connect()
client = config_db.get_redis_client(config_db.CONFIG_DB)
client.flushdb()
Expand All @@ -1252,12 +1263,14 @@ def load_minigraph(db, no_service_restart):
# These commands are not run for host on multi asic platform
if num_npus == 1 or namespace is not DEFAULT_NAMESPACE:
if device_type != 'MgmtToRRouter':
run_command('{} pfcwd start_default'.format(ns_cmd_prefix), display_cmd=True)
run_command("{} config qos reload".format(ns_cmd_prefix), display_cmd=True)
run_command('{}pfcwd start_default'.format(ns_cmd_prefix), display_cmd=True)

if os.path.isfile('/etc/sonic/acl.json'):
run_command("acl-loader update full /etc/sonic/acl.json", display_cmd=True)

# generate QoS and Buffer configs
run_command("config qos reload", display_cmd=True)

# Write latest db version string into db
db_migrator='/usr/bin/db_migrator.py'
if os.path.isfile(db_migrator) and os.access(db_migrator, os.X_OK):
Expand Down Expand Up @@ -1642,26 +1655,80 @@ def reload():
_clear_qos()
platform = sonic_device_util.get_platform()
hwsku = sonic_device_util.get_hwsku()
buffer_template_file = os.path.join('/usr/share/sonic/device/', platform, hwsku, 'buffers.json.j2')
if os.path.isfile(buffer_template_file):
command = "{} -d -t {} >/tmp/buffers.json".format(SONIC_CFGGEN_PATH, buffer_template_file)
run_command(command, display_cmd=True)

qos_template_file = os.path.join('/usr/share/sonic/device/', platform, hwsku, 'qos.json.j2')
sonic_version_file = os.path.join('/etc/sonic/', 'sonic_version.yml')
if os.path.isfile(qos_template_file):
command = "{} -d -t {} -y {} >/tmp/qos.json".format(SONIC_CFGGEN_PATH, qos_template_file, sonic_version_file)
run_command(command, display_cmd=True)
namespace_list = [DEFAULT_NAMESPACE]
if sonic_device_util.get_num_npus() > 1:
namespace_list = sonic_device_util.get_namespaces()

# Apply the configurations only when both buffer and qos configuration files are presented
command = "{} -j /tmp/buffers.json --write-to-db".format(SONIC_CFGGEN_PATH)
run_command(command, display_cmd=True)
command = "{} -j /tmp/qos.json --write-to-db".format(SONIC_CFGGEN_PATH)
for ns in namespace_list:
if ns is DEFAULT_NAMESPACE:
asic_id_suffix = ""
else:
asic_id = sonic_device_util.get_npu_id_from_name(ns)
if asic_id is None:
click.secho(
"Command 'qos reload' failed with invalid namespace '{}'".
format(ns),
fg='yellow'
)
raise click.Abort()
asic_id_suffix = str(asic_id)

buffer_template_file = os.path.join(
'/usr/share/sonic/device/',
platform,
hwsku,
asic_id_suffix,
'buffers.json.j2'
)
buffer_output_file = "/tmp/buffers{}.json".format(asic_id_suffix)
qos_output_file = "/tmp/qos{}.json".format(asic_id_suffix)

cmd_ns = "" if ns is DEFAULT_NAMESPACE else "-n {}".format(ns)
if os.path.isfile(buffer_template_file):
command = "{} {} -d -t {} > {}".format(
SONIC_CFGGEN_PATH,
cmd_ns,
buffer_template_file,
buffer_output_file
)
run_command(command, display_cmd=True)
qos_template_file = os.path.join(
'/usr/share/sonic/device/',
platform,
hwsku,
asic_id_suffix,
'qos.json.j2'
)
sonic_version_file = os.path.join(
'/etc/sonic/', 'sonic_version.yml'
)
if os.path.isfile(qos_template_file):
command = "{} {} -d -t {} -y {} > {}".format(
SONIC_CFGGEN_PATH,
cmd_ns,
qos_template_file,
sonic_version_file,
qos_output_file
)
run_command(command, display_cmd=True)
# Apply the configurations only when both buffer and qos
# configuration files are presented
command = "{} {} -j {} --write-to-db".format(
SONIC_CFGGEN_PATH, cmd_ns, buffer_output_file
)
run_command(command, display_cmd=True)
command = "{} {} -j {} --write-to-db".format(
SONIC_CFGGEN_PATH, cmd_ns, qos_output_file
)
run_command(command, display_cmd=True)
else:
click.secho('QoS definition template not found at {}'.format(
qos_template_file
), fg='yellow')
else:
click.secho('QoS definition template not found at {}'.format(qos_template_file), fg='yellow')
else:
click.secho('Buffer definition template not found at {}'.format(buffer_template_file), fg='yellow')
click.secho('Buffer definition template not found at {}'.format(
buffer_template_file
), fg='yellow')

#
# 'warm_restart' group ('config warm_restart ...')
Expand Down
4 changes: 2 additions & 2 deletions tests/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
Executing stop of service hostcfgd...
Executing stop of service nat...
Running command: /usr/local/bin/sonic-cfggen -H -m --write-to-db
Running command: pfcwd start_default
Running command: config qos reload
Running command: pfcwd start_default
Running command: config qos reload
Executing reset-failed of service bgp...
Executing reset-failed of service dhcp_relay...
Executing reset-failed of service hostcfgd...
Expand Down

2 comments on commit a80826d

@lguohan
Copy link
Contributor

@lguohan lguohan commented on a80826d Aug 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not see additional new tests being added for this pr. can you add additional new tests.

@smaheshm
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not see additional new tests being added for this pr. can you add additional new tests.

I didn't find unit tests for qos and buffer configs. In any case I'll add test cases for both single and multi-ASIC.

Please sign in to comment.