Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[smart-switch] Extend config generator for t1-smartswitch topology. #27

Closed
wants to merge 1 commit into from
Closed
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
35 changes: 26 additions & 9 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,25 +77,19 @@ 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'] = {

Choose a reason for hiding this comment

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

Can you please clarify why is this removed?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Based on the changes in IP address assignment HLD, it is no longer needed. This configuration now sits in platform.json and is used only by midplane bridge service

'GLOBAL': {
'bridge': bridge_name,
'ip_prefix': '{}/24'.format(mpbr_address)
}
}

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)]}

Expand All @@ -111,6 +107,27 @@ def generate_t1_smartswitch_sample_config(data):

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'] = 'SmartSwitcch'
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.DPUS_TABLE in ss_config:
return generate_t1_smartswitch_switch_sample_config(data, ss_config)
elif smartswitch_config.DPU_TABLE in ss_config:
return generate_t1_smartswitch_dpu_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'
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)

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": "SmartSwitcch",
"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"
}
}
}
20 changes: 0 additions & 20 deletions src/sonic-config-engine/tests/sample_output/t1-smartswitch.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,20 +202,6 @@
"mtu": "9100"
}
},
"DPUS": {
"dpu0": {
"midplane_interface": "dpu0"
},
"dpu1": {
"midplane_interface": "dpu1"
},
"dpu2": {
"midplane_interface": "dpu2"
},
"dpu3": {
"midplane_interface": "dpu3"
}
},
"FLEX_COUNTER_TABLE": {
"ACL": {
"FLEX_COUNTER_STATUS": "disable",
Expand Down Expand Up @@ -551,12 +537,6 @@
"Ethernet240|10.0.0.60/31": {},
"Ethernet248|10.0.0.62/31": {}
},
"MID_PLANE_BRIDGE": {
"GLOBAL": {
"bridge": "bridge_midplane",
"ip_prefix": "169.254.200.254/24"
}
},
"DHCP_SERVER_IPV4": {
"bridge_midplane": {
"gateway": "169.254.200.254",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# name lanes alias
Ethernet0 0,1,2,3,4,5,6,7 etp1
12 changes: 12 additions & 0 deletions src/sonic-config-engine/tests/test_j2files.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def setUp(self):
self.t0_port_config = os.path.join(self.test_dir, 't0-sample-port-config.ini')
self.t0_port_config_tiny = os.path.join(self.test_dir, 't0-sample-port-config-tiny.ini')
self.t1_ss_port_config = os.path.join(self.test_dir, 't1-ss-sample-port-config.ini')
self.t1_ss_dpu_port_config = os.path.join(self.test_dir, 't1-ss-dpu-sample-port-config.ini')
self.l1_l3_port_config = os.path.join(self.test_dir, 'l1-l3-sample-port-config.ini')
self.t0_7050cx3_port_config = os.path.join(self.test_dir, 't0_7050cx3_d48c8_port_config.ini')
self.t1_mlnx_minigraph = os.path.join(self.test_dir, 't1-sample-graph-mlnx.xml')
Expand Down Expand Up @@ -314,6 +315,17 @@ def test_t1_smartswitch_template(self):

self.assertTrue(json.dumps(sample_output_json, sort_keys=True) == json.dumps(output_json, sort_keys=True))

def test_t1_smartswitch_dpu_template(self):
argument = ['-k', 'SS-DPU-1x400Gb', '--preset', 't1-smartswitch', '-p', self.t1_ss_dpu_port_config]
output = self.run_script(argument)
output_json = json.loads(output)

sample_output_file = os.path.join(self.test_dir, 'sample_output', 't1-smartswitch-dpu.json')
with open(sample_output_file) as sample_output_fd:
sample_output_json = json.load(sample_output_fd)

self.assertTrue(json.dumps(sample_output_json, sort_keys=True) == json.dumps(output_json, sort_keys=True))

def test_qos_arista7050_render_template(self):
self._test_qos_render_template('arista', 'x86_64-arista_7050_qx32s', 'Arista-7050-QX-32S', 'sample-arista-7050-t0-minigraph.xml', 'qos-arista7050.json')

Expand Down