From 18f54c91999dda907cde3e37a7cd08f3411fcafd Mon Sep 17 00:00:00 2001 From: Longxiang Lyu <35479537+lolyu@users.noreply.github.com> Date: Thu, 26 May 2022 15:05:45 +0800 Subject: [PATCH] [dualtor][minigraph] Add SoC addr minigraph support (#5614) 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 lolv@microsoft.com 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: SmartCable active-active
192.168.0.3/21
::/0 0.0.0.0/0 ::/0 svcstr-7050-acs-1-Servers0-SC
Server
192.168.0.2/21
fc02:1000::2/64 0.0.0.0/0 Servers0
``` How did you verify/test it? This PR depends on: Azure/sonic-buildimage#10776 --- ansible/library/dual_tor_facts.py | 31 ++++++++++++++++++++++++++++++ ansible/templates/minigraph_png.j2 | 20 ++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/ansible/library/dual_tor_facts.py b/ansible/library/dual_tor_facts.py index 1629959fdb1..76978a2f90b 100644 --- a/ansible/library/dual_tor_facts.py +++ b/ansible/library/dual_tor_facts.py @@ -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): @@ -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 @@ -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 diff --git a/ansible/templates/minigraph_png.j2 b/ansible/templates/minigraph_png.j2 index 51a35cadb19..e93c40c83fa 100644 --- a/ansible/templates/minigraph_png.j2 +++ b/ansible/templates/minigraph_png.j2 @@ -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 %} SmartCable +{% if mux_cable_facts is defined %} + {{ mux_cable_facts[intf_index]['cable_type'] }} +
+ {{ mux_cable_facts[intf_index]['soc_ipv4'] if 'soc_ipv4' in mux_cable_facts[intf_index] else '0.0.0.0/0' }} +
+{% else %}
0.0.0.0/0
+{% endif %} ::/0 @@ -159,12 +168,21 @@
Server +{% if mux_cable_facts is defined %} +
+ {{ mux_cable_facts[intf_index]['server_ipv4'] }} +
+ + {{ mux_cable_facts[intf_index]['server_ipv6'] }} + +{% else %}
{{ server_base_address_v4.format(loop.index + 1) }}/26 -
+ {{ server_base_address_v6.format(loop.index + 1) }}/96 +{% endif %} 0.0.0.0/0