Skip to content
29 changes: 28 additions & 1 deletion src/sonic-config-engine/config_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,31 @@
else:
UNICODE_TYPE = unicode

# The following config generation methods exits:
# 't1': generate_t1_sample_config,
# 'l2': generate_l2_config,
# 'empty': generate_empty_config,
# 'l1': generate_l1_config,
# 'l3': generate_l3_config

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

def generate_l3_config(data):
data['LOOPBACK_INTERFACE'] = {"Loopback0": {},
"Loopback0|10.1.0.1/32": {}}
data['BGP_NEIGHBOR'] = {}
data['DEVICE_NEIGHBOR'] = {}
data['INTERFACE'] = {}
for port in natsorted(data['PORT']):
data['PORT'][port]['admin_status'] = 'up'
data['PORT'][port]['mtu'] = '9100'
data['INTERFACE']['{}'.format(port)] = {}
return data;

def generate_t1_sample_config(data):
data['DEVICE_METADATA']['localhost']['hostname'] = 'sonic'
data['DEVICE_METADATA']['localhost']['type'] = 'LeafRouter'
Expand Down Expand Up @@ -126,7 +151,9 @@ def generate_l2_config(data):
_sample_generators = {
't1': generate_t1_sample_config,
'l2': generate_l2_config,
'empty': generate_empty_config
'empty': generate_empty_config,
'l1': generate_l1_config,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please add a unit test for this? You can refer as done for #7215

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the comments. Added UT. Please review.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@prsunny do you have any more comments or else would be able to approve this PR ?

'l3': generate_l3_config
}

def get_available_config():
Expand Down
26 changes: 26 additions & 0 deletions src/sonic-config-engine/data/l1intf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"DEVICE_METADATA": {
"localhost" : {
"hwsku" : "{{ DEVICE_METADATA.localhost.hwsku }}"
}
},
{% set ns = {'firstPrinted': False} -%}
"PORT": {
{%- for key, value in PORT.items() -%}
{%- if ns.firstPrinted %},{% endif %}

"{{ key }}": {
{%- for keyPort, valuePort in value.items() %}

{% if keyPort != "admin_status" %}"{{ keyPort }}": "{{ valuePort }}",{% endif %}
{%- endfor %}

"admin_status": "{{ value.admin_status|default("up") }}",
"mtu": "9100"
}
{%- if ns.update({'firstPrinted': True}) %}{% endif -%}
{%- endfor %}

}
}

65 changes: 65 additions & 0 deletions src/sonic-config-engine/data/l3intf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"DEVICE_METADATA": {
"localhost" : {
"hwsku" : "{{ DEVICE_METADATA.localhost.hwsku }}"
}
},
{% set ns = {'firstPrinted': False} -%}
"PORT": {
{%- for key, value in PORT.items() -%}
{%- if ns.firstPrinted %},{% endif %}

"{{ key }}": {
{%- for keyPort, valuePort in value.items() %}

{% if keyPort != "admin_status" %}"{{ keyPort }}": "{{ valuePort }}",{% endif %}
{%- endfor %}

"admin_status": "{{ value.admin_status|default("up") }}",
"mtu": "9100"
}
{%- if ns.update({'firstPrinted': True}) %}{% endif -%}
{%- endfor %}

},
"LOOPBACK_INTERFACE": {
"Loopback0": {},
"Loopback0|10.1.0.1/32": {}
},
"BGP_NEIGHBOR": {},
"DEVICE_NEIGHBOR": {},
"INTERFACE": {
"Ethernet0": {},
"Ethernet1": {},
"Ethernet2": {},
"Ethernet3": {},
"Ethernet4": {},
"Ethernet5": {},
"Ethernet6": {},
"Ethernet7": {},
"Ethernet8": {},
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is an l3 template did you want to add IP addresses to these interfaces in your usecase?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@VenkatCisco, can you remove this file src/sonic-config-engine/.config_samples.py.swp from this PR ?

Sure, removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since this is an l3 template did you want to add IP addresses to these interfaces in your usecase?

In the review mtg, there was an ask from Guhon and team to not hardcode the ip address etc. Even though the config_samples.py has other areas like generate_t1_sample_config catered to specific needs, this method is made more generic as per request.

"Ethernet9": {},
"Ethernet10": {},
"Ethernet11": {},
"Ethernet12": {},
"Ethernet13": {},
"Ethernet14": {},
"Ethernet15": {},
"Ethernet16": {},
"Ethernet17": {},
"Ethernet18": {},
"Ethernet19": {},
"Ethernet20": {},
"Ethernet21": {},
"Ethernet22": {},
"Ethernet23": {},
"Ethernet24": {},
"Ethernet25": {},
"Ethernet26": {},
"Ethernet27": {},
"Ethernet28": {},
"Ethernet29": {},
"Ethernet30": {},
"Ethernet31": {}
}
}
33 changes: 33 additions & 0 deletions src/sonic-config-engine/tests/l1-l3-sample-port-config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# name lanes alias index speed
Ethernet0 1296,1297,1298,1299 Ethernet0 0 100000
Ethernet1 1300,1301,1302,1303 Ethernet1 1 100000
Ethernet2 1288,1289,1290,1291 Ethernet2 2 100000
Ethernet3 1292,1293,1294,1295 Ethernet3 3 100000
Ethernet4 1280,1281,1282,1283 Ethernet4 4 100000
Ethernet5 1284,1285,1286,1287 Ethernet5 5 100000
Ethernet6 1032,1033,1034,1035 Ethernet6 6 100000
Ethernet7 1036,1037,1038,1039 Ethernet7 7 100000
Ethernet8 1024,1025,1026,1027 Ethernet8 8 100000
Ethernet9 1028,1029,1030,1031 Ethernet9 9 100000
Ethernet10 772,773,774,775 Ethernet10 10 100000
Ethernet11 768,769,770,771 Ethernet11 11 100000
Ethernet12 780,781,782,783 Ethernet12 12 100000
Ethernet13 776,777,778,779 Ethernet13 13 100000
Ethernet14 528,529,530,531 Ethernet14 14 100000
Ethernet15 532,533,534,535 Ethernet15 15 100000
Ethernet16 520,521,522,523 Ethernet16 16 100000
Ethernet17 524,525,526,527 Ethernet17 17 100000
Ethernet18 512,513,514,515 Ethernet18 18 100000
Ethernet19 516,517,518,519 Ethernet19 19 100000
Ethernet20 272,273,274,275 Ethernet20 20 100000
Ethernet21 276,277,278,279 Ethernet21 21 100000
Ethernet22 264,265,266,267 Ethernet22 22 100000
Ethernet23 268,269,270,271 Ethernet23 23 100000
Ethernet24 256,257,258,259 Ethernet24 24 100000
Ethernet25 260,261,262,263 Ethernet25 25 100000
Ethernet26 16,17,18,19 Ethernet26 26 100000
Ethernet27 20,21,22,23 Ethernet27 27 100000
Ethernet28 8,9,10,11 Ethernet28 28 100000
Ethernet29 12,13,14,15 Ethernet29 29 100000
Ethernet30 0,1,2,3 Ethernet30 30 100000
Ethernet31 4,5,6,7 Ethernet31 31 100000
Loading