Skip to content

Commit 8bc54d7

Browse files
theasianpianistCarl Keene
authored and
Carl Keene
committed
[sonic-config-engine]: Update L2 preset for dualtor (sonic-net#7215)
- When generating L2 preset, check for dual ToR setting from CLI option `-a '{"is_dualtor": true}'` - When dual ToR is specified, add subtype field to DEVICE_METADATA table - When dual ToR is specified, add MUX_CABLE, TUNNEL, LOOPBACK_INTERFACE, and PEER_SWITCH tables
1 parent a97fbc1 commit 8bc54d7

File tree

4 files changed

+966
-1
lines changed

4 files changed

+966
-1
lines changed

src/sonic-config-engine/config_samples.py

+47-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1+
import sys
2+
3+
from ipaddress import ip_interface
14
from natsort import natsorted
25

6+
#TODO: Remove once Python 2 support is removed
7+
if sys.version_info.major == 3:
8+
UNICODE_TYPE = str
9+
else:
10+
UNICODE_TYPE = unicode
11+
312
def generate_t1_sample_config(data):
413
data['DEVICE_METADATA']['localhost']['hostname'] = 'sonic'
514
data['DEVICE_METADATA']['localhost']['type'] = 'LeafRouter'
@@ -39,11 +48,48 @@ def generate_empty_config(data):
3948
return new_data
4049

4150
def generate_l2_config(data):
51+
if 'is_dualtor' in data and data['is_dualtor']:
52+
is_dualtor = True
53+
data.pop('is_dualtor')
54+
else:
55+
is_dualtor = False
4256
data['VLAN'] = {'Vlan1000': {'vlanid': '1000'}}
4357
data['VLAN_MEMBER'] = {}
44-
for port in natsorted(data['PORT']):
58+
if is_dualtor:
59+
data['DEVICE_METADATA']['localhost']['subtype'] = 'DualToR'
60+
data['LOOPBACK_INTERFACE'] = {
61+
'Loopback2': {},
62+
'Loopback2|3.3.3.3': {}
63+
}
64+
data['MUX_CABLE'] = {}
65+
data['PEER_SWITCH'] = {
66+
"peer_switch_hostname": {
67+
"address_ipv4": "1.1.1.1"
68+
}
69+
}
70+
data['TUNNEL'] = {
71+
"MuxTunnel0": {
72+
"dscp_mode": "uniform",
73+
"dst_ip": "2.2.2.2",
74+
"ecn_mode": "copy_from_outer",
75+
"encap_ecn_mode": "standard",
76+
"ttl_mode": "pipe",
77+
"tunnel_type": "IPINIP"
78+
}
79+
}
80+
81+
server_ipv4_base = ip_interface(UNICODE_TYPE('192.168.0.1/32'))
82+
server_ipv6_base = ip_interface(UNICODE_TYPE('fc02:1000::1/128'))
83+
for i, port in enumerate(natsorted(data['PORT'])):
4584
data['PORT'][port].setdefault('admin_status', 'up')
4685
data['VLAN_MEMBER']['Vlan1000|{}'.format(port)] = {'tagging_mode': 'untagged'}
86+
if is_dualtor:
87+
mux_cable_entry = {
88+
'server_ipv4': str(server_ipv4_base + i),
89+
'server_ipv6': str(server_ipv6_base + i),
90+
'state': 'auto'
91+
}
92+
data['MUX_CABLE'][port] = mux_cable_entry
4793
return data
4894

4995
_sample_generators = {

0 commit comments

Comments
 (0)