Skip to content

Commit

Permalink
[sonic-config-engine]: Update L2 preset for dualtor (sonic-net#7215)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
theasianpianist authored and raphaelt-nvidia committed May 13, 2021
1 parent 0833c13 commit 85e7c1e
Show file tree
Hide file tree
Showing 4 changed files with 966 additions and 1 deletion.
48 changes: 47 additions & 1 deletion src/sonic-config-engine/config_samples.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import sys

from ipaddress import ip_interface
from natsort import natsorted

#TODO: Remove once Python 2 support is removed
if sys.version_info.major == 3:
UNICODE_TYPE = str
else:
UNICODE_TYPE = unicode

def generate_t1_sample_config(data):
data['DEVICE_METADATA']['localhost']['hostname'] = 'sonic'
data['DEVICE_METADATA']['localhost']['type'] = 'LeafRouter'
Expand Down Expand Up @@ -39,11 +48,48 @@ def generate_empty_config(data):
return new_data

def generate_l2_config(data):
if 'is_dualtor' in data and data['is_dualtor']:
is_dualtor = True
data.pop('is_dualtor')
else:
is_dualtor = False
data['VLAN'] = {'Vlan1000': {'vlanid': '1000'}}
data['VLAN_MEMBER'] = {}
for port in natsorted(data['PORT']):
if is_dualtor:
data['DEVICE_METADATA']['localhost']['subtype'] = 'DualToR'
data['LOOPBACK_INTERFACE'] = {
'Loopback2': {},
'Loopback2|3.3.3.3': {}
}
data['MUX_CABLE'] = {}
data['PEER_SWITCH'] = {
"peer_switch_hostname": {
"address_ipv4": "1.1.1.1"
}
}
data['TUNNEL'] = {
"MuxTunnel0": {
"dscp_mode": "uniform",
"dst_ip": "2.2.2.2",
"ecn_mode": "copy_from_outer",
"encap_ecn_mode": "standard",
"ttl_mode": "pipe",
"tunnel_type": "IPINIP"
}
}

server_ipv4_base = ip_interface(UNICODE_TYPE('192.168.0.1/32'))
server_ipv6_base = ip_interface(UNICODE_TYPE('fc02:1000::1/128'))
for i, port in enumerate(natsorted(data['PORT'])):
data['PORT'][port].setdefault('admin_status', 'up')
data['VLAN_MEMBER']['Vlan1000|{}'.format(port)] = {'tagging_mode': 'untagged'}
if is_dualtor:
mux_cable_entry = {
'server_ipv4': str(server_ipv4_base + i),
'server_ipv6': str(server_ipv6_base + i),
'state': 'auto'
}
data['MUX_CABLE'][port] = mux_cable_entry
return data

_sample_generators = {
Expand Down
Loading

0 comments on commit 85e7c1e

Please sign in to comment.