Skip to content

Commit c259c99

Browse files
authored
Use the macsec_enabled flag in platform to enable macsec feature state (#11998)
* Use the macsec_enabled flag in platform to enable macesc feature state * Add macsec supported metadata in DEVICE_RUNTIME_METADATA
1 parent 1320319 commit c259c99

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
usemsi=1
22
dmasize=64M
3+
macsec_enabled=1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
usemsi=1
22
dmasize=512M
33
default_mtu=9100
4+
macsec_enabled=1

files/build_templates/init_cfg.json.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
{%- if include_p4rt == "y" %}{% do features.append(("p4rt", "disabled", false, "enabled")) %}{% endif %}
5353
{%- if include_restapi == "y" %}{% do features.append(("restapi", "enabled", false, "enabled")) %}{% endif %}
5454
{%- if include_sflow == "y" %}{% do features.append(("sflow", "disabled", false, "enabled")) %}{% endif %}
55-
{%- if include_macsec == "y" %}{% do features.append(("macsec", "disabled", false, "enabled")) %}{% endif %}
55+
{%- if include_macsec == "y" %}{% do features.append(("macsec", "{% if 'type' in DEVICE_METADATA['localhost'] and DEVICE_METADATA['localhost']['type'] == 'SpineRouter' and DEVICE_RUNTIME_METADATA['MACSEC_SUPPORTED'] %}enabled{% else %}disabled{% endif %}", false, "enabled")) %}{% endif %}
5656
{%- if include_system_telemetry == "y" %}{% do features.append(("telemetry", "enabled", true, "enabled")) %}{% endif %}
5757
"FEATURE": {
5858
{# has_timer field if set, will start the feature systemd .timer unit instead of .service unit #}

src/sonic-py-common/sonic_py_common/device_info.py

+23
Original file line numberDiff line numberDiff line change
@@ -469,16 +469,39 @@ def is_supervisor():
469469
return True
470470
return False
471471

472+
# Check if this platform has macsec capability.
473+
def is_macsec_supported():
474+
supported = 0
475+
platform_env_conf_file_path = get_platform_env_conf_file_path()
476+
477+
# platform_env.conf file not present for platform
478+
if platform_env_conf_file_path is None:
479+
return supported
480+
481+
# Else open the file check for keyword - macsec_enabled -
482+
with open(platform_env_conf_file_path) as platform_env_conf_file:
483+
for line in platform_env_conf_file:
484+
tokens = line.split('=')
485+
if len(tokens) < 2:
486+
continue
487+
if tokens[0].lower() == 'macsec_enabled':
488+
supported = tokens[1].strip()
489+
break
490+
return int(supported)
491+
492+
472493
def get_device_runtime_metadata():
473494
chassis_metadata = {}
474495
if is_chassis():
475496
chassis_metadata = {'CHASSIS_METADATA': {'module_type' : 'supervisor' if is_supervisor() else 'linecard',
476497
'chassis_type': 'voq' if is_voq_chassis() else 'packet'}}
477498

478499
port_metadata = {'ETHERNET_PORTS_PRESENT': True if get_path_to_port_config_file(hwsku=None, asic="0" if is_multi_npu() else None) else False}
500+
macsec_support_metadata = {'MACSEC_SUPPORTED': True if is_macsec_supported() else False}
479501
runtime_metadata = {}
480502
runtime_metadata.update(chassis_metadata)
481503
runtime_metadata.update(port_metadata)
504+
runtime_metadata.update(macsec_support_metadata)
482505
return {'DEVICE_RUNTIME_METADATA': runtime_metadata }
483506

484507
def get_npu_id_from_name(npu_name):

0 commit comments

Comments
 (0)