Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 59 additions & 10 deletions src/sonic-config-engine/config_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from ipaddress import ip_interface
from natsort import natsorted

import smartswitch_config

#TODO: Remove once Python 2 support is removed
if sys.version_info.major == 3:
UNICODE_TYPE = str
Expand Down Expand Up @@ -75,42 +77,89 @@ def generate_t1_sample_config(data):
port_count += 1
return data

def generate_t1_smartswitch_sample_config(data):
def generate_t1_smartswitch_switch_sample_config(data, ss_config):
data = generate_t1_sample_config(data)
data['DEVICE_METADATA']['localhost']['subtype'] = 'SmartSwitch'

mpbr_prefix = '169.254.200'
mpbr_address = '{}.254'.format(mpbr_prefix)

bridge_name = 'bridge_midplane'
data['MID_PLANE_BRIDGE'] = {
'GLOBAL': {
'bridge': bridge_name,
'ip_prefix': '{}/24'.format(mpbr_address)
}
}
bridge_name = 'bridge-midplane'

dhcp_server_ports = {}

for dpu_name in natsorted(data.get('DPUS', {})):
midplane_interface = data['DPUS'][dpu_name]['midplane_interface']
for dpu_name in natsorted(ss_config.get('DPUS', {})):
midplane_interface = ss_config['DPUS'][dpu_name]['midplane_interface']
dpu_id = int(midplane_interface.replace('dpu', ''))
dhcp_server_ports['{}|{}'.format(bridge_name, midplane_interface)] = {'ips': ['{}.{}'.format(mpbr_prefix, dpu_id + 1)]}

if dhcp_server_ports:
data['DPUS'] = ss_config['DPUS']

data['FEATURE'] = {
"dhcp_relay": {
"auto_restart": "enabled",
"check_up_status": "False",
"delayed": "False",
"has_global_scope": "True",
"has_per_asic_scope": "False",
"high_mem_alert": "disabled",
"set_owner": "local",
"state": "enabled",
"support_syslog_rate_limit": "True"
},
"dhcp_server": {
"auto_restart": "enabled",
"check_up_status": "False",
"delayed": "False",
"has_global_scope": "True",
"has_per_asic_scope": "False",
"high_mem_alert": "disabled",
"set_owner": "local",
"state": "enabled",
"support_syslog_rate_limit": "False"
}
}

data['DHCP_SERVER_IPV4'] = {
bridge_name: {
'customized_options': [
'option60',
'option223'
],
'gateway': mpbr_address,
'lease_time': '3600',
'mode': 'PORT',
'netmask': '255.255.255.0',
"state": "enabled"
}
}

data['DHCP_SERVER_IPV4_PORT'] = dhcp_server_ports

return data

def generate_t1_smartswitch_dpu_sample_config(data, ss_config):
data['DEVICE_METADATA']['localhost']['hostname'] = 'sonic'
data['DEVICE_METADATA']['localhost']['switch_type'] = 'dpu'
data['DEVICE_METADATA']['localhost']['type'] = 'SonicDpu'
data['DEVICE_METADATA']['localhost']['subtype'] = 'SmartSwitch'
data['DEVICE_METADATA']['localhost']['bgp_asn'] = '65100'

for port in natsorted(data['PORT']):
data['PORT'][port]['admin_status'] = 'up'
data['PORT'][port]['mtu'] = '9100'

return data

def generate_t1_smartswitch_sample_config(data):
ss_config = smartswitch_config.get_smartswitch_config(data['DEVICE_METADATA']['localhost']['hwsku'])

if smartswitch_config.DPU_TABLE in ss_config:
return generate_t1_smartswitch_dpu_sample_config(data, ss_config)

return generate_t1_smartswitch_switch_sample_config(data, ss_config)

def generate_empty_config(data):
new_data = {'DEVICE_METADATA': data['DEVICE_METADATA']}
if 'hostname' not in new_data['DEVICE_METADATA']['localhost']:
Expand Down
37 changes: 21 additions & 16 deletions src/sonic-config-engine/smartswitch_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import sys
import portconfig
from sonic_py_common import device_info

try:
if os.environ["CFGGEN_UNIT_TESTING"] == "2":
Expand All @@ -14,25 +15,29 @@
except KeyError:
pass

DPUS_TABLE = 'DPUS'
DPU_TABLE = 'DPU'
Copy link
Copy Markdown
Contributor

@prabhataravind prabhataravind Jul 15, 2024

Choose a reason for hiding this comment

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

Why do we have these both -- DPU_TABLE and DPUS_TABLE?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

DPUS indicates that the image is running on the switch.
DPU indicates that the image is running on the DPU.
https://github.com/sonic-net/SONiC/blob/master/doc/smart-switch/ip-address-assigment/smart-switch-ip-address-assignment.md#device-data-and-platform

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Based on the type of device we can generate different configurations for switch and DPU for the same topology

DPUS_TABLE = 'DPUS'


def get_smartswitch_config(hwsku=None, platform=None):
hwsku_json_file = portconfig.get_hwsku_file_name(hwsku, platform)

if os.environ.get("CFGGEN_UNIT_TESTING") == "2" and hwsku == 'SSwitch-32x1000Gb':
hwsku_json_file = os.path.join(tests_path, "data", "smartswitch", hwsku, "hwsku.json")

if not hwsku_json_file:
return {}

hwsku_dict = portconfig.readJson(hwsku_json_file)
if not hwsku_dict:
raise Exception("hwsku_dict is none")

def get_smartswitch_config(hwsku=None):
config = {}

if DPUS_TABLE in hwsku_dict:
config[DPUS_TABLE] = hwsku_dict[DPUS_TABLE]
if os.environ.get("CFGGEN_UNIT_TESTING") == "2":
if hwsku == 'SSwitch-32x1000Gb':
json_file = os.path.join(tests_path, "data", "smartswitch", "sample_switch_platform.json")
elif hwsku == 'SS-DPU-1x400Gb':
json_file = os.path.join(tests_path, "data", "smartswitch", "sample_dpu_platform.json")
else:
platform_path = device_info.get_path_to_platform_dir()
json_file = os.path.join(platform_path, device_info.PLATFORM_JSON_FILE)

platform_json = portconfig.readJson(json_file)
if not platform_json:
return config

if DPU_TABLE in platform_json:
config[DPU_TABLE] = platform_json[DPU_TABLE]
if DPUS_TABLE in platform_json:
config[DPUS_TABLE] = platform_json[DPUS_TABLE]

return config
6 changes: 0 additions & 6 deletions src/sonic-config-engine/sonic-cfggen
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ from config_samples import generate_sample_config, get_available_config
from functools import partial
from minigraph import minigraph_encoder, parse_xml, parse_device_desc_xml, parse_asic_sub_role, parse_asic_switch_type, parse_hostname
from portconfig import get_port_config, get_breakout_mode
from smartswitch_config import get_smartswitch_config
from sonic_py_common.multi_asic import get_asic_id_from_name, get_asic_device_id, is_multi_asic
from sonic_py_common import device_info
from swsscommon.swsscommon import ConfigDBConnector, SonicDBConfig, ConfigDBPipeConnector
Expand Down Expand Up @@ -371,11 +370,6 @@ def main():
if brkout_table is not None:
deep_update(data, {'BREAKOUT_CFG': brkout_table})

# Read Smart Switch config
smartswitch_config = get_smartswitch_config(hwsku, platform)
if smartswitch_config:
deep_update(data, smartswitch_config)

_process_json(args, data)

if args.yang is not None:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"interfaces": {
"Ethernet0": {
"default_brkout_mode": "1x400G"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,5 @@
"Ethernet144": {
"default_brkout_mode": "1x100000[50G,40000,25G,10000]"
}
},
"DPUS": {
"dpu0": {
"midplane_interface": "dpu0"
},
"dpu1": {
"midplane_interface": "dpu1"
},
"dpu2": {
"midplane_interface": "dpu2"
},
"dpu3": {
"midplane_interface": "dpu3"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"DPU": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"DPUS": {
"dpu0": {
"midplane_interface": "dpu0"
},
"dpu1": {
"midplane_interface": "dpu1"
},
"dpu2": {
"midplane_interface": "dpu2"
},
"dpu3": {
"midplane_interface": "dpu3"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"DEVICE_METADATA": {
"localhost": {
"hwsku": "SS-DPU-1x400Gb",
"hostname": "sonic",
"switch_type": "dpu",
"type": "SonicDpu",
"subtype": "SmartSwitch",
"bgp_asn": "65100"
}
},
"PORT": {
"Ethernet0": {
"lanes": "0,1,2,3,4,5,6,7",
"alias": "etp1",
"admin_status": "up",
"mtu": "9100"
}
},
"FLEX_COUNTER_TABLE": {
"ACL": {
"FLEX_COUNTER_STATUS": "disable",
"FLEX_COUNTER_DELAY_STATUS": "true",
"POLL_INTERVAL": "10000"
}
}
}
Loading