Skip to content

Commit

Permalink
[dualtor][minigraph] Add SoC addr minigraph support (#5614)
Browse files Browse the repository at this point in the history
Approach
What is the motivation for this PR?
Add minigraph generation support to include mux cable type and soc address details.

Signed-off-by: Longxiang Lyu [email protected]

How did you do it?
Include mux_cable_facts into dual_tor_facts
```
modify minigraph templates to include mux cable type and soc address details with the following schema proposal:
      <Device i:type="SmartCable">
        <ElementType>SmartCable</ElementType>
        <SubType>active-active</SubType>
        <Address xmlns:d5p1="Microsoft.Search.Autopilot.NetMux">
          <d5p1:IPPrefix>192.168.0.3/21</d5p1:IPPrefix>
        </Address>
        <AddressV6 xmlns:d5p1="Microsoft.Search.Autopilot.NetMux">
          <d5p1:IPPrefix>::/0</d5p1:IPPrefix>
        </AddressV6>
        <ManagementAddress xmlns:d5p1="Microsoft.Search.Autopilot.NetMux">
          <d5p1:IPPrefix>0.0.0.0/0</d5p1:IPPrefix>
        </ManagementAddress>
        <ManagementAddressV6 xmlns:d5p1="Microsoft.Search.Autopilot.NetMux">
          <d5p1:IPPrefix>::/0</d5p1:IPPrefix>
        </ManagementAddressV6>
        <SerialNumber i:nil="true" />
        <Hostname>svcstr-7050-acs-1-Servers0-SC</Hostname>
      </Device>
      <Device i:type="Server">
        <ElementType>Server</ElementType>
        <Address xmlns:d5p1="Microsoft.Search.Autopilot.NetMux">
          <d5p1:IPPrefix>192.168.0.2/21</d5p1:IPPrefix>
        </Address> 
        <AddressV6 xmlns:d5p1="Microsoft.Search.Autopilot.NetMux">
          <d5p1:IPPrefix>fc02:1000::2/64</d5p1:IPPrefix>
        </AddressV6>
        <ManagementAddress xmlns:d5p1="Microsoft.Search.Autopilot.NetMux">
          <d5p1:IPPrefix>0.0.0.0/0</d5p1:IPPrefix>
        </ManagementAddress>
        <Hostname>Servers0</Hostname>
      </Device>
```
How did you verify/test it?
This PR depends on: sonic-net/sonic-buildimage#10776
  • Loading branch information
lolyu authored May 26, 2022
1 parent 99ef5c3 commit 18f54c9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
31 changes: 31 additions & 0 deletions ansible/library/dual_tor_facts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
import os
import yaml

from collections import defaultdict

try:
from ansible.module_utils.dualtor_utils import generate_mux_cable_facts
except ImportError:
# Add parent dir for using outside Ansible
import sys
sys.path.append('..')
from ansible.module_utils.dualtor_utils import generate_mux_cable_facts


def load_topo_file(topo_name):
"""Load topo definition yaml file."""
topo_file = "vars/topo_%s.yml" % topo_name
if not os.path.exists(topo_file):
raise ValueError("Topo file %s not exists" % topo_file)
with open(topo_file) as fd:
return yaml.safe_load(fd)


class DualTorParser:

def __init__(self, hostname, testbed_facts, host_vars, vm_config, port_alias, vlan_intfs):
Expand Down Expand Up @@ -64,6 +86,14 @@ def generate_cable_names(self):

self.dual_tor_facts['cables'] = cables

def generate_mux_cable_facts(self):
topo_name = self.testbed_facts["topo"]
# use mux_cable_facts only for dualtor mixed topologies
if "mixed" in topo_name:
topology = load_topo_file(topo_name)["topology"]
mux_cable_facts = generate_mux_cable_facts(topology=topology)
self.dual_tor_facts["mux_cable_facts"] = mux_cable_facts

def get_dual_tor_facts(self):
'''
Gathers facts related to a dual ToR configuration
Expand All @@ -73,6 +103,7 @@ def get_dual_tor_facts(self):
self.parse_tor_position()
self.generate_cable_names()
self.parse_loopback_ips()
self.generate_mux_cable_facts()

return self.dual_tor_facts

Expand Down
20 changes: 19 additions & 1 deletion ansible/templates/minigraph_png.j2
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,21 @@
{% set server_base_address_v6 = (vlan_configs.values() | list)[0]['prefix_v6'] %}
{% set server_base_address_v6 = server_base_address_v6 | ipaddr('network') %}
{% set server_base_address_v6 = ':'.join(server_base_address_v6.split(':')[:-1]) + ':{:x}' %}
{% set mux_cable_facts = dual_tor_facts['mux_cable_facts'] if 'mux_cable_facts' in dual_tor_facts %}
{% for cable in dual_tor_facts['cables'] %}
{% set intf_index = port_alias.index(cable['dut_intf'])|string %}
<Device i:type="SmartCable">
<ElementType>SmartCable</ElementType>
{% if mux_cable_facts is defined %}
<SubType>{{ mux_cable_facts[intf_index]['cable_type'] }}</SubType>
<Address xmlns:d5p1="Microsoft.Search.Autopilot.NetMux">
<d5p1:IPPrefix>{{ mux_cable_facts[intf_index]['soc_ipv4'] if 'soc_ipv4' in mux_cable_facts[intf_index] else '0.0.0.0/0' }}</d5p1:IPPrefix>
</Address>
{% else %}
<Address xmlns:d5p1="Microsoft.Search.Autopilot.NetMux">
<d5p1:IPPrefix>0.0.0.0/0</d5p1:IPPrefix>
</Address>
{% endif %}
<AddressV6 xmlns:d5p1="Microsoft.Search.Autopilot.NetMux">
<d5p1:IPPrefix>::/0</d5p1:IPPrefix>
</AddressV6>
Expand All @@ -159,12 +168,21 @@
</Device>
<Device i:type="Server">
<ElementType>Server</ElementType>
{% if mux_cable_facts is defined %}
<Address xmlns:d5p1="Microsoft.Search.Autopilot.NetMux">
<d5p1:IPPrefix>{{ mux_cable_facts[intf_index]['server_ipv4'] }}</d5p1:IPPrefix>
</Address>
<AddressV6 xmlns:d5p1="Microsoft.Search.Autopilot.NetMux">
<d5p1:IPPrefix>{{ mux_cable_facts[intf_index]['server_ipv6'] }}</d5p1:IPPrefix>
</AddressV6>
{% else %}
<Address xmlns:d5p1="Microsoft.Search.Autopilot.NetMux">
<d5p1:IPPrefix>{{ server_base_address_v4.format(loop.index + 1) }}/26</d5p1:IPPrefix>
</Address>
</Address>
<AddressV6 xmlns:d5p1="Microsoft.Search.Autopilot.NetMux">
<d5p1:IPPrefix>{{ server_base_address_v6.format(loop.index + 1) }}/96</d5p1:IPPrefix>
</AddressV6>
{% endif %}
<ManagementAddress xmlns:d5p1="Microsoft.Search.Autopilot.NetMux">
<d5p1:IPPrefix>0.0.0.0/0</d5p1:IPPrefix>
</ManagementAddress>
Expand Down

0 comments on commit 18f54c9

Please sign in to comment.