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

gen-mg broken for multi-asic kvm - issue #4343 #4420

Merged
merged 2 commits into from
Oct 13, 2021
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
87 changes: 51 additions & 36 deletions ansible/TestbedProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,47 +492,62 @@ def makeLab(data, devices, testbed, outfile):
except AttributeError:
print("\t\t" + host + " asics_host_ipv6 not found")

try: #get voq_inband_ip
voq_inband_ip = dev.get("voq_inband_ip")
if voq_inband_ip is not None:
entry += "\tvoq_inband_ip=" + str( voq_inband_ip )
except AttributeError:
print("\t\t" + host + " voq_inband_ip not found")

try: #get voq_inband_ipv6
voq_inband_ipv6 = dev.get("voq_inband_ipv6")
if voq_inband_ipv6 is not None:
entry += "\tvoq_inband_ipv6=" + str( voq_inband_ipv6 )
except AttributeError:
print("\t\t" + host + " voq_inband_ipv6 not found")

try: #get voq_inband_intf
voq_inband_intf = dev.get("voq_inband_intf")
if voq_inband_intf is not None:
entry += "\tvoq_inband_intf=" + str( voq_inband_intf )
except AttributeError:
print("\t\t" + host + " voq_inband_intf not found")

try: #get voq_inband_type
voq_inband_type = dev.get("voq_inband_type")
if voq_inband_type is not None:
entry += "\tvoq_inband_type=" + str( voq_inband_type )
except AttributeError:
print("\t\t" + host + " voq_inband_type not found")

try: #get switch_type
switch_type = dev.get("switch_type")
if switch_type is not None:
entry += "\tswitch_type=" + str( switch_type )
except AttributeError:
print("\t\t" + host + " switch_type not found")
entry += "\tswitch_type=" + str( switch_type )
if switch_type == 'voq' and card_type != 'supervisor':
if num_asics is None:
num_asics = 1

# All fields are a list. For single asic the list is of size 1.
switchids = dev.get("switchids") # switchids, single asic example "[4]", 3 asic example "[4,6,8]"
voq_inband_ip = dev.get("voq_inband_ip") # voq_inband_ip
voq_inband_ipv6 = dev.get("voq_inband_ipv6") # voq_inband_ipv6
voq_inband_intf = dev.get("voq_inband_intf") # voq_inband_intf
voq_inband_type = dev.get("voq_inband_type") # voq_inband_type
max_cores = dev.get("max_cores") # max cores
lo4096_ip = dev.get("loopback4096_ip") # loopback4096_ip
lo4096_ipv6 = dev.get("loopback4096_ipv6") # loopback4096_ipv6
num_cores_per_asic = dev.get("num_cores_per_asic", 1) # number of cores per asic - to be used in calculating the switchids, assuming to be the same for all linecards

# Add fields
if switchids is None:
switchids = [start_switchid + (asic_id * num_cores_per_asic) for asic_id in range(num_asics)]
entry += "\tswitchids=" + str(switchids)

if voq_inband_ip is None:
voq_inband_ip = ["1.1.1.{}/32".format(start_switchid + asic_id) for asic_id in range(num_asics)]
entry += "\tvoq_inband_ip=" + str(voq_inband_ip)

if voq_inband_ipv6 is None:
voq_inband_ip = ["1111::1:{}/128".format(start_switchid + asic_id) for asic_id in range(num_asics)]
entry += "\tvoq_inband_ipv6=" + str(voq_inband_ip)

if voq_inband_intf is None:
voq_inband_intf = ["Ethernet-IB{}".format(asic_id) for asic_id in range(num_asics)]
entry += "\tvoq_inband_intf=" + str(voq_inband_intf)

if voq_inband_type is None:
voq_inband_type = "port"
entry += "\tvoq_inband_type=" + voq_inband_type

if max_cores is None:
max_cores = 48
entry += "\tmax_cores=" + str(max_cores)

if lo4096_ip is None:
lo4096_ip = ["8.0.0.{}/32".format(start_switchid + asic_id) for asic_id in range(num_asics)]
entry += "\tloopback4096_ip=" + lo4096_ip

if lo4096_ipv6 is None:
lo4096_ipv6 = ["2603:10e2:400::{}/128".format(start_switchid + asic_id) for asic_id in range(num_asics)]
entry += "\tloopback4096_ipv6=" + lo4096_ipv6

start_switchid += (num_asics * num_cores_per_asic)

try: #get max_cores
max_cores = dev.get("max_cores")
if max_cores is not None:
entry += "\tmax_cores=" + str( max_cores )
except AttributeError:
print("\t\t" + host + " max_cores not found")
print("\t\t" + host + " switch_type not found")

try: #get os
os = dev.get("os")
Expand Down
7 changes: 3 additions & 4 deletions ansible/config_sonic_basedon_testbed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
hwsku: "{{ hwsku }}"
card_type: "{{ card_type | default('fixed') }}"
hostname: "{{ inventory_hostname | default('') }}"
start_switchid: "{{ start_switchid | default(0) }}"
switchids: "{{ switchids | default([]) }}"
when: deploy is defined and deploy|bool == true

- name: find interface name mapping and individual interface speed if defined with local data
Expand All @@ -92,7 +92,7 @@
num_asic: "{{ num_asics }}"
card_type: "{{ card_type | default('fixed') }}"
hostname: "{{ inventory_hostname | default('') }}"
start_switchid: "{{ start_switchid | default(0) }}"
switchids: "{{ switchids | default([]) }}"
delegate_to: localhost
when: deploy is not defined or deploy|bool == false

Expand All @@ -110,8 +110,7 @@

- name: set all VoQ information for iBGP
set_fact:
all_inbands: "{{ all_inbands | default( [] ) + [ hostvars[item]['voq_inband_ip'] ] }}"
all_hostnames: "{{ all_hostnames | default( [] ) + [ item ] }}"
all_inbands: "{{ all_inbands | default( {} ) | combine( { item : hostvars[item]['voq_inband_ip']}) }}"
when: hostvars[item]['voq_inband_ip'] is defined
loop: "{{ ansible_play_batch }}"

Expand Down
5 changes: 3 additions & 2 deletions ansible/library/fabric_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

RETURN = '''
ansible_facts{
fabric_info: [{'asicname': 'ASIC0', 'ip_prefix': '10.1.0.1/32', 'ip6_prefix': 'FC00:1::1/128'},
{'asicname': 'ASIC1', 'ip_prefix': '10.1.0.2/32', 'ip6_prefix': 'FC00:1::2/128'}]
fabric_info: [{'asicname': 'ASIC0', 'asic_id': 0, 'ip_prefix': '10.1.0.1/32', 'ip6_prefix': 'FC00:1::1/128'},
{'asicname': 'ASIC1', 'asic_id': 1, 'ip_prefix': '10.1.0.2/32', 'ip6_prefix': 'FC00:1::2/128'}]
}
'''

Expand Down Expand Up @@ -55,6 +55,7 @@ def main():
next_v4addr = str( ipaddress.IPv4Address(v4base + asic_id) )
next_v6addr = str( ipaddress.IPv6Address(v6base + asic_id) )
data = { 'asicname': key,
'asic_id' : asic_id,
'ip_prefix': next_v4addr + "/" + v4pfx[-1],
'ip6_prefix': next_v6addr + "/" + v6pfx[-1] }
fabric_info.append( data )
Expand Down
18 changes: 9 additions & 9 deletions ansible/library/port_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ def get_portmap(self, asic_id=None, include_internal=False,
port_coreid_index = -1
port_core_portid_index = -1
num_voq_index = -1
# default to ASIC0 as minigraph.py parsing code has that assumption.
asic_name = "ASIC0" if asic_id is None else "ASIC" + str(asic_id)
# default to Asic0 as minigraph.py parsing code has that assumption.
asic_name = "Asic0" if asic_id is None else "asic" + str(asic_id)

filename = self.get_portconfig_path(asic_id)
if filename is None:
Expand Down Expand Up @@ -209,7 +209,7 @@ def main():
include_internal=dict(required=False, type='bool', default=False),
card_type=dict(type='str', required=False),
hostname=dict(type='str', required=False),
start_switchid=dict(type='int', required=False)
switchids=dict(type='list', required=False)
),
supports_check_mode=True
)
Expand All @@ -235,10 +235,10 @@ def main():
'sysports': sysports})
return
allmap = SonicPortAliasMap(m_args['hwsku'])
start_switchid = 0
if 'start_switchid' in m_args and m_args['start_switchid'] != None:
start_switchid = int(m_args['start_switchid'])
# When this script is invoked on sonic-mgmt docker, num_asic
switchids = None
if 'switchids' in m_args and m_args['switchids'] != None and len(m_args['switchids']):
switchids = m_args['switchids']
# When this script is invoked on sonic-mgmt docker, num_asic
# parameter is passed.
if m_args['num_asic'] is not None:
num_asic = m_args['num_asic']
Expand All @@ -264,8 +264,8 @@ def main():
if 'hostname' in m_args:
hostname = m_args['hostname']
for asic_id in range(num_asic):
if asic_id is not None:
switchid = start_switchid + asic_id
if switchids and asic_id is not None:
switchid = switchids[asic_id]
if num_asic == 1:
asic_id = None
(aliases_asic, portmap_asic, aliasmap_asic, portspeed_asic, front_panel_asic, asicifnames_asic,
Expand Down
99 changes: 76 additions & 23 deletions ansible/templates/minigraph_cpg.j2
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,40 @@
{% endfor %}
{% endif %}
{% if switch_type is defined and switch_type == 'voq' %}
{% for all_idx in range(all_inbands|length) %}
{% if voq_inband_ip != all_inbands[all_idx] %}
{% set voq_peers = dict() %}
{% for asic_id in range(num_asics) %}
{% if num_asics == 1 %}
{% set start_rtr = inventory_hostname %}
{% else %}
{% set start_rtr = "ASIC" + asic_id|string %}
{% endif %}
{% for a_linecard in all_inbands %}
{% for idx in range(all_inbands[a_linecard]|length) %}
{% if voq_inband_ip[asic_id] != all_inbands[a_linecard][idx] %}
<BGPSession>
<StartRouter>{{ inventory_hostname }}</StartRouter>
<StartPeer>{{ voq_inband_ip.split('/')[0] }}</StartPeer>
<EndRouter>{{ all_hostnames[all_idx] }}</EndRouter>
<EndPeer>{{ all_inbands[all_idx].split('/')[0] }}</EndPeer>
<StartRouter>{{ start_rtr }}</StartRouter>
<StartPeer>{{ voq_inband_ip[asic_id].split('/')[0] }}</StartPeer>
{% if all_inbands[a_linecard]|length == 1 %}
{% set end_rtr = a_linecard %}
{% else %}
{% if a_linecard == inventory_hostname %}
{% set end_rtr = "ASIC" + idx|string %}
{% else %}
{% set end_rtr = a_linecard + "-ASIC" + idx|string %}
{% endif %}
{% endif %}
{% set _ = voq_peers.update({ all_inbands[a_linecard][idx].split('/')[0] : end_rtr }) %}
<EndRouter>{{ end_rtr }}</EndRouter>
<EndPeer>{{ all_inbands[a_linecard][idx].split('/')[0] }}</EndPeer>
<Multihop>1</Multihop>
<HoldTime>0</HoldTime>
<KeepAliveTime>0</KeepAliveTime>
<VoQChassisInternal>true</VoQChassisInternal>
</BGPSession>
{% endif %}
{% endfor %}
{% endfor %}
{% endfor %}
{% endif %}
</PeeringSessions>
<Routers xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution">
Expand All @@ -112,16 +132,14 @@
</BGPPeer>
{% endif %}
{% endfor %}
{% if switch_type is defined and switch_type == 'voq' %}
{% for all_idx in range(all_inbands|length) %}
{% if voq_inband_ip != all_inbands[all_idx] %}
{% if num_asics == 1 and switch_type is defined and switch_type == 'voq' %}
{% for a_voq_peer in voq_peers %}
<BGPPeer>
<Address>{{ all_inbands[all_idx].split('/')[0] }}</Address>
<Address>{{ a_voq_peer }}</Address>
<RouteMapIn i:nil="true"/>
<RouteMapOut i:nil="true"/>
<Vrf i:nil="true"/>
</BGPPeer>
{% endif %}
{% endfor %}
{% endif %}
{% if 'tor' in vm_topo_config['dut_type'] | lower %}
Expand All @@ -147,17 +165,6 @@
</a:Peers>
<a:RouteMaps/>
</a:BGPRouterDeclaration>
{% if switch_type is defined and switch_type == 'voq' %}
{% for all_idx in range(all_inbands|length) %}
{% if voq_inband_ip != all_inbands[all_idx] %}
<a:BGPRouterDeclaration>
<a:ASN>{{ vm_topo_config['dut_asn'] }}</a:ASN>
<a:Hostname>{{ all_hostnames[all_idx] }}</a:Hostname>
<a:RouteMaps/>
</a:BGPRouterDeclaration>
{% endif %}
{% endfor %}
{% endif %}
{% for index in range( vms_number) %}
{% if vm_topo_config['vm'][vms[index]]['intfs'][dut_index|int]|length > 0 %}
<a:BGPRouterDeclaration>
Expand All @@ -174,7 +181,7 @@
<a:Hostname>{{ asic }}</a:Hostname>
<a:Peers>
{% for index in range( vms_number) %}
{% if vm_asic_ifnames[vms[index]][0].split('-')[1] == asic %}
{% if vms[index] in vm_asic_ifnames and vm_asic_ifnames[vms[index]][0].split('-')[1] == asic %}
<BGPPeer>
<Address>{{ vm_topo_config['vm'][vms[index]]['peer_ipv4'][dut_index|int] }}</Address>
<RouteMapIn i:nil="true"/>
Expand All @@ -197,6 +204,52 @@
<a:RouteMaps/>
</a:BGPRouterDeclaration>
{% endfor %}
{% if switch_type is defined and switch_type == 'voq' %}
{% for a_linecard in all_inbands %}
{% if a_linecard != inventory_hostname %}
{% for idx in range(all_inbands[a_linecard]|length) %}
<a:BGPRouterDeclaration>
<a:ASN>{{ vm_topo_config['dut_asn'] }}</a:ASN>
<a:Hostname>{{ voq_peers[all_inbands[a_linecard][idx].split('/')[0]] }}</a:Hostname>
<a:RouteMaps/>
</a:BGPRouterDeclaration>
{% endfor %}
{% endif %}
{% endfor %}
{% if num_asics > 1 %}
{% for asic_id in range(num_asics) %}
{% set asic_name = "ASIC" + asic_id|string %}
<a:BGPRouterDeclaration>
<a:ASN>{{ vm_topo_config['dut_asn'] }}</a:ASN>
<a:Hostname>{{ asic_name }}</a:Hostname>
<a:Peers>
{% for index in range( vms_number) %}
{% if vms[index] in vm_asic_ifnames and vm_asic_ifnames[vms[index]][0].split('-')[1] == asic_name %}
<BGPPeer>
<Address>{{ vm_topo_config['vm'][vms[index]]['peer_ipv4'][dut_index|int] }}</Address>
<RouteMapIn i:nil="true"/>
<RouteMapOut i:nil="true"/>
<Vrf i:nil="true"/>
</BGPPeer>
{% endif %}
{% endfor %}
{% for a_linecard in all_inbands %}
{% for idx in range(all_inbands[a_linecard]|length) %}
{% if voq_inband_ip[asic_id] != all_inbands[a_linecard][idx] %}
<BGPPeer>
<Address>{{ all_inbands[a_linecard][idx] }}</Address>
<RouteMapIn i:nil="true"/>
<RouteMapOut i:nil="true"/>
<Vrf i:nil="true"/>
</BGPPeer>
{% endif %}
{% endfor %}
{% endfor %}
</a:Peers>
</a:BGPRouterDeclaration>
{% endfor %}
{% endif %}
{% endif %}
</Routers>
</CpgDec>

Loading