From 8e7aa23e54f42b9070dc4bad997b5076e761b3ce Mon Sep 17 00:00:00 2001 From: Suvarna Meenakshi Date: Thu, 15 Jun 2023 18:14:20 +0000 Subject: [PATCH 01/10] [SNMP][IPv6]: Fix SNMP IPv6 reachability issue in certain scenario Modify snmpd.conf to start snmpd to listen on specific management and loopback ips instead of listening on any ip. Signed-off-by: Suvarna Meenakshi --- dockers/docker-snmp/snmpd.conf.j2 | 28 +++++++++++++++++++++++++++- dockers/docker-snmp/start.sh | 4 ++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/dockers/docker-snmp/snmpd.conf.j2 b/dockers/docker-snmp/snmpd.conf.j2 index 585fb5353e5b..10049a07a1d1 100644 --- a/dockers/docker-snmp/snmpd.conf.j2 +++ b/dockers/docker-snmp/snmpd.conf.j2 @@ -13,12 +13,38 @@ # AGENT BEHAVIOUR # -# Listen for connections on all ip addresses, including eth0, ipv4 lo +# Listen for connections on ip addresses based on configuration # +# if SNMP_AGENT_ADDRESS_CONFIG is present +# use SNMP_AGENT_ADDRESS_CONFIG +# elif either MGMT_INTERFACE or LOOPBACK_INTERFACE +# use management and loopback ip addresses +# use docker0 ipv4 and ipv6 address +# else if none of the above config is present +# listen on any IP + {% if SNMP_AGENT_ADDRESS_CONFIG %} {% for (agentip, port, vrf) in SNMP_AGENT_ADDRESS_CONFIG %} agentAddress {{ agentip }}{% if port %}:{{ port }}{% endif %}{% if vrf %}%{{ vrf }}{% endif %}{{ "" }} {% endfor %} +{% elif MGMT_INTERFACE is defined or LOOPBACK_INTERFACE is defined%} +{% if MGMT_INTERFACE is defined %} +{% for if, ip in MGMT_INTERFACE %} +agentAddress {{ ip.split('/')[0] }} +{% endfor %} +{% endif %} +{% if LOOPBACK_INTERFACE is defined %} +{% for lo in LOOPBACK_INTERFACE %} +{% if lo | length == 2 %} +agentAddress {{ lo[1].split('/')[0] }} +{% endif %} +{% endfor %} +{% endif %} +# Listen on docker0 IP address to support multi-asic platform +{% if docker0_v4 and docker0_v6 %} +agentAddress {{ docker0_v4 }} +agentAddress {{ docker0_v6 }} +{% endif %} {% else %} agentAddress udp:161 agentAddress udp6:161 diff --git a/dockers/docker-snmp/start.sh b/dockers/docker-snmp/start.sh index aefd0bfc3db6..348c774a0ff7 100755 --- a/dockers/docker-snmp/start.sh +++ b/dockers/docker-snmp/start.sh @@ -16,11 +16,15 @@ mkdir -p /etc/ssw /etc/snmp # Parse snmp.yml and insert the data in Config DB /usr/bin/snmp_yml_to_configdb.py +DOCKER0_V4=$(ip -4 addr show docker0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}') +DOCKER0_V6=$(ip -6 addr show docker0 scope global | grep -oP '(?<=inet6\s)[0-9a-fA-F:]+') +ADD_PARAM=$(printf '%s {"docker0_v4":"%s","docker0_v6":"%s"}' "-a" "$DOCKER0_V4" "$DOCKER0_V6") SONIC_CFGGEN_ARGS=" \ -d \ -y /etc/sonic/sonic_version.yml \ -t /usr/share/sonic/templates/sysDescription.j2,/etc/ssw/sysDescription \ -t /usr/share/sonic/templates/snmpd.conf.j2,/etc/snmp/snmpd.conf \ + $ADD_PARAM \ " sonic-cfggen $SONIC_CFGGEN_ARGS From cf2f69d53e9916b3357de47a0940dc1ef7e3803a Mon Sep 17 00:00:00 2001 From: Suvarna Meenakshi Date: Thu, 15 Jun 2023 20:39:19 +0000 Subject: [PATCH 02/10] snmpd to listen on loopback0 ip only if interface exists. Loopback0 will not exist on multi-asic platform on host namespace. Signed-off-by: Suvarna Meenakshi --- dockers/docker-snmp/snmpd.conf.j2 | 2 +- dockers/docker-snmp/start.sh | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/dockers/docker-snmp/snmpd.conf.j2 b/dockers/docker-snmp/snmpd.conf.j2 index 10049a07a1d1..f8579b345d41 100644 --- a/dockers/docker-snmp/snmpd.conf.j2 +++ b/dockers/docker-snmp/snmpd.conf.j2 @@ -33,7 +33,7 @@ agentAddress {{ agentip }}{% if port %}:{{ port }}{% endif %}{% if vrf %}%{{ vrf agentAddress {{ ip.split('/')[0] }} {% endfor %} {% endif %} -{% if LOOPBACK_INTERFACE is defined %} +{% if LOOPBACK_INTERFACE is defined and loopback0_exists %} {% for lo in LOOPBACK_INTERFACE %} {% if lo | length == 2 %} agentAddress {{ lo[1].split('/')[0] }} diff --git a/dockers/docker-snmp/start.sh b/dockers/docker-snmp/start.sh index 348c774a0ff7..1b56bc25bd9d 100755 --- a/dockers/docker-snmp/start.sh +++ b/dockers/docker-snmp/start.sh @@ -18,7 +18,14 @@ mkdir -p /etc/ssw /etc/snmp DOCKER0_V4=$(ip -4 addr show docker0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}') DOCKER0_V6=$(ip -6 addr show docker0 scope global | grep -oP '(?<=inet6\s)[0-9a-fA-F:]+') -ADD_PARAM=$(printf '%s {"docker0_v4":"%s","docker0_v6":"%s"}' "-a" "$DOCKER0_V4" "$DOCKER0_V6") +# Loopback0 interface will not exist on multi-asic device +if ip link show Loopback0 >/dev/null 2>&1; then + LOOPBACK0_EXITS=true +fi + +ADD_PARAM=$(printf '%s {"docker0_v4":"%s","docker0_v6":"%s","loopback0_exists":"%s"}' \ + "-a" "$DOCKER0_V4" "$DOCKER0_V6" "$LOOPBACK0_EXITS") + SONIC_CFGGEN_ARGS=" \ -d \ -y /etc/sonic/sonic_version.yml \ From 8b1359f64b1684bd8bc4b57602ea7610d0b4a111 Mon Sep 17 00:00:00 2001 From: Suvarna Meenakshi Date: Wed, 21 Jun 2023 18:32:32 +0000 Subject: [PATCH 03/10] Update minigraph parser to update SNMP_AGENT_ADDRESS_CONFIG table with Management IP and Loopback0 IP address so that snmpd will listen on management IP and Loopback0Ip instead of listening on any IP. Update snmpd.conf to listen on Management IP and Loopback0 IP for single-asic platform and management IP and docker0 Ip for multi-asic platform. Signed-off-by: Suvarna Meenakshi --- dockers/docker-snmp/snmpd.conf.j2 | 42 +++++++++++----------------- dockers/docker-snmp/start.sh | 8 +----- src/sonic-config-engine/minigraph.py | 11 ++++++++ 3 files changed, 29 insertions(+), 32 deletions(-) diff --git a/dockers/docker-snmp/snmpd.conf.j2 b/dockers/docker-snmp/snmpd.conf.j2 index f8579b345d41..f16e71b2f9da 100644 --- a/dockers/docker-snmp/snmpd.conf.j2 +++ b/dockers/docker-snmp/snmpd.conf.j2 @@ -13,43 +13,35 @@ # AGENT BEHAVIOUR # -# Listen for connections on ip addresses based on configuration +# Listen for connections on all ip addresses, including eth0, ipv4 lo # -# if SNMP_AGENT_ADDRESS_CONFIG is present -# use SNMP_AGENT_ADDRESS_CONFIG -# elif either MGMT_INTERFACE or LOOPBACK_INTERFACE -# use management and loopback ip addresses -# use docker0 ipv4 and ipv6 address -# else if none of the above config is present -# listen on any IP +{% set loip = [] %} +{% if LOOPBACK_INTERFACE is defined and (NAMESPACE_COUNT is defined and NAMESPACE_COUNT|int > 1) %} +{% for lo in LOOPBACK_INTERFACE %} +{% if lo | length == 2 and 'Loopback0' in lo[0] %} +{% if loip.append(lo[1].split('/')[0]) %}{% endif %} +{% endif %} +{% endfor %} +{% endif %} {% if SNMP_AGENT_ADDRESS_CONFIG %} +{% set protocol = 'udp' %} {% for (agentip, port, vrf) in SNMP_AGENT_ADDRESS_CONFIG %} -agentAddress {{ agentip }}{% if port %}:{{ port }}{% endif %}{% if vrf %}%{{ vrf }}{% endif %}{{ "" }} -{% endfor %} -{% elif MGMT_INTERFACE is defined or LOOPBACK_INTERFACE is defined%} -{% if MGMT_INTERFACE is defined %} -{% for if, ip in MGMT_INTERFACE %} -agentAddress {{ ip.split('/')[0] }} -{% endfor %} +{% if ':' in agentip %} +{% set protocol = 'udp6' %} {% endif %} -{% if LOOPBACK_INTERFACE is defined and loopback0_exists %} -{% for lo in LOOPBACK_INTERFACE %} -{% if lo | length == 2 %} -agentAddress {{ lo[1].split('/')[0] }} +{% if not agentip in loip %} +agentAddress {{ protocol }}:[{{ agentip }}]{% if port %}:{{ port }}{% endif %}{% if vrf %}%{{ vrf }}{% endif %}{{ "" }} {% endif %} {% endfor %} -{% endif %} -# Listen on docker0 IP address to support multi-asic platform -{% if docker0_v4 and docker0_v6 %} -agentAddress {{ docker0_v4 }} -agentAddress {{ docker0_v6 }} +{% if NAMESPACE_COUNT is defined and NAMESPACE_COUNT|int > 1 %} +agentAddress udp:[{{ docker0_v4 }}]:161 +agentAddress udp6:[{{ docker0_v6 }}]:161 {% endif %} {% else %} agentAddress udp:161 agentAddress udp6:161 {% endif %} - ############################################################################### # # ACCESS CONTROL diff --git a/dockers/docker-snmp/start.sh b/dockers/docker-snmp/start.sh index 1b56bc25bd9d..d80a6e4317e1 100755 --- a/dockers/docker-snmp/start.sh +++ b/dockers/docker-snmp/start.sh @@ -18,13 +18,7 @@ mkdir -p /etc/ssw /etc/snmp DOCKER0_V4=$(ip -4 addr show docker0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}') DOCKER0_V6=$(ip -6 addr show docker0 scope global | grep -oP '(?<=inet6\s)[0-9a-fA-F:]+') -# Loopback0 interface will not exist on multi-asic device -if ip link show Loopback0 >/dev/null 2>&1; then - LOOPBACK0_EXITS=true -fi - -ADD_PARAM=$(printf '%s {"docker0_v4":"%s","docker0_v6":"%s","loopback0_exists":"%s"}' \ - "-a" "$DOCKER0_V4" "$DOCKER0_V6" "$LOOPBACK0_EXITS") +ADD_PARAM=$(printf '%s {"docker0_v4":"%s","docker0_v6":"%s","NAMESPACE_COUNT":"%s"}' "-a" "$DOCKER0_V4" "$DOCKER0_V6" "$NAMESPACE_COUNT") SONIC_CFGGEN_ARGS=" \ -d \ diff --git a/src/sonic-config-engine/minigraph.py b/src/sonic-config-engine/minigraph.py index be1a77205fc4..e89e83ba1a72 100644 --- a/src/sonic-config-engine/minigraph.py +++ b/src/sonic-config-engine/minigraph.py @@ -1700,6 +1700,17 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw results['LOOPBACK_INTERFACE'][host_lo_intf[0]] = {} results['MGMT_VRF_CONFIG'] = mvrf + + # Set SNMP_AGENT_ADDRESS_CONFIG to Management IP and Loopback0 IP + if asic_name is None: + results['SNMP_AGENT_ADDRESS_CONFIG'] = {} + for mgmt_if in results['MGMT_INTERFACE'].keys(): + snmp_key = mgmt_if[1].split('/')[0] + '|161|' + results['SNMP_AGENT_ADDRESS_CONFIG'][snmp_key] = {} + for loip in results['LOOPBACK_INTERFACE']: + if len(loip) == 2 and loip[0] == 'Loopback0': + snmp_key = loip[1].split('/')[0] + '|161|' + results['SNMP_AGENT_ADDRESS_CONFIG'][snmp_key] = {} phyport_intfs = {} vlan_intfs = {} From 6d0c64f8fe8b58db7af78c7f9cde4855f33b002f Mon Sep 17 00:00:00 2001 From: Suvarna Meenakshi Date: Tue, 27 Jun 2023 08:14:20 +0000 Subject: [PATCH 04/10] Add unit-test for minigraph change. Signed-off-by: Suvarna Meenakshi (cherry picked from commit d033b032e9632587abec05f7000278593888efcd) --- src/sonic-config-engine/tests/mock_tables/dbconnector.py | 7 +++++++ src/sonic-config-engine/tests/test_cfggen.py | 9 +++++++++ src/sonic-config-engine/tests/test_multinpu_cfggen.py | 9 +++++++++ 3 files changed, 25 insertions(+) diff --git a/src/sonic-config-engine/tests/mock_tables/dbconnector.py b/src/sonic-config-engine/tests/mock_tables/dbconnector.py index 2b152c36a06a..9e766294d6c2 100644 --- a/src/sonic-config-engine/tests/mock_tables/dbconnector.py +++ b/src/sonic-config-engine/tests/mock_tables/dbconnector.py @@ -140,6 +140,12 @@ def keys(self, pattern='*'): # Find every key that matches the pattern return [key for key in self.redis if regex.match(key)] +def get_docker0_ip(): + if multi_asic.is_multi_asic(): + return '240.127.1.1', 'fd00::1' + else: + return None, None + swsssdk.interface.DBInterface._subscribe_keyspace_notification = _subscribe_keyspace_notification mockredis.MockRedis.config_set = config_set redis.StrictRedis = SwssSyncClient @@ -147,3 +153,4 @@ def keys(self, pattern='*'): swsscommon.SonicV2Connector = SonicV2Connector swsscommon.ConfigDBConnector = ConfigDBConnector swsscommon.ConfigDBPipeConnector = ConfigDBPipeConnector +multi_asic.get_docker0_ip = get_docker0_ip diff --git a/src/sonic-config-engine/tests/test_cfggen.py b/src/sonic-config-engine/tests/test_cfggen.py index 28257c02ba50..b8adb80a3113 100644 --- a/src/sonic-config-engine/tests/test_cfggen.py +++ b/src/sonic-config-engine/tests/test_cfggen.py @@ -1087,6 +1087,15 @@ def test_minigraph_400g_to_100G_speed(self): ) ) + def testsnmp_agent_address_config(self): + argument = ['-m', self.sample_graph, '-p', self.port_config, '-v', 'SNMP_AGENT_ADDRESS_CONFIG.keys()|list'] + output = self.run_script(argument) + import pdb; pdb.set_trace() + self.assertEqual( + utils.liststr_to_dict(output.strip()), + utils.liststr_to_dict("['192.168.200.15|161|', '100.0.0.6|161|']") + ) + def test_minigraph_cisco_400g_to_100G_speed(self): argument = ["-m", self.sample_cisco_100_graph, "-p", self.sample_cisco_port_config_400g, "-v", "PORT"] self.assertTrue(self.yang.validate(argument)) diff --git a/src/sonic-config-engine/tests/test_multinpu_cfggen.py b/src/sonic-config-engine/tests/test_multinpu_cfggen.py index bc4227f85d52..9edb01d1b8cd 100644 --- a/src/sonic-config-engine/tests/test_multinpu_cfggen.py +++ b/src/sonic-config-engine/tests/test_multinpu_cfggen.py @@ -214,6 +214,15 @@ def test_backend_asic_portchannel_intf(self): utils.liststr_to_dict("['PortChannel4013', 'PortChannel4013|10.1.0.2/31', 'PortChannel4014', 'PortChannel4014|10.1.0.6/31']") ) + def testsnmp_agent_address_config(self): + argument = ['-m', self.sample_graph, '-p', self.sample_port_config, '-v', 'SNMP_AGENT_ADDRESS_CONFIG.keys()|list'] + output = self.run_script(argument) + import pdb; pdb.set_trace() + self.assertEqual( + utils.liststr_to_dict(output.strip()), + utils.liststr_to_dict("['10.1.0.32|161|', '3.10.147.150|161|', 'FC00:2::32|161|', 'FC00:1::32|161|']") + ) + def test_frontend_asic_ports(self): argument = ["-m", self.sample_graph, "-p", self.port_config[0], "-n", "asic0", "--var-json", "PORT"] output = json.loads(self.run_script(argument)) From 27ed71e2262df12c94aa3f191f4e56c80581e523 Mon Sep 17 00:00:00 2001 From: Suvarna Meenakshi Date: Tue, 27 Jun 2023 08:26:53 +0000 Subject: [PATCH 05/10] Update minigraph parser and add unit-test. Signed-off-by: Suvarna Meenakshi --- src/sonic-config-engine/minigraph.py | 24 +++++++++++++++---- src/sonic-config-engine/tests/test_cfggen.py | 18 +++++++------- .../tests/test_multinpu_cfggen.py | 18 +++++++------- 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/src/sonic-config-engine/minigraph.py b/src/sonic-config-engine/minigraph.py index e89e83ba1a72..a11029814773 100644 --- a/src/sonic-config-engine/minigraph.py +++ b/src/sonic-config-engine/minigraph.py @@ -1701,15 +1701,31 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw results['MGMT_VRF_CONFIG'] = mvrf - # Set SNMP_AGENT_ADDRESS_CONFIG to Management IP and Loopback0 IP + # Update SNMP_AGENT_ADDRESS_CONFIG with Management IP and Loopback0 IP + # for single-asic platform. + # Update SNMP_AGENT_ADDRESS_CONFIG with Management IP and docker0 IP + # for multi-asic platform. + results['SNMP_AGENT_ADDRESS_CONFIG'] = {} if asic_name is None: results['SNMP_AGENT_ADDRESS_CONFIG'] = {} for mgmt_if in results['MGMT_INTERFACE'].keys(): snmp_key = mgmt_if[1].split('/')[0] + '|161|' results['SNMP_AGENT_ADDRESS_CONFIG'][snmp_key] = {} - for loip in results['LOOPBACK_INTERFACE']: - if len(loip) == 2 and loip[0] == 'Loopback0': - snmp_key = loip[1].split('/')[0] + '|161|' + docker0_v4, docker0_v6 = get_docker0_ip() + if docker0_v4 is None and docker0_v6 is None: + # Add Loopback0 IP as agent address for single asic + for loip in results['LOOPBACK_INTERFACE']: + if len(loip) == 2 and loip[0] == 'Loopback0': + snmp_key = loip[1].split('/')[0] + '|161|' + results['SNMP_AGENT_ADDRESS_CONFIG'][snmp_key] = {} + else: + # docker0 ip address is available for multi-asic + # Add docker0 IP address as agent address + if docker0_v4: + snmp_key = docker0_v4 + '|161|' + results['SNMP_AGENT_ADDRESS_CONFIG'][snmp_key] = {} + if docker0_v6: + snmp_key = docker0_v6 + '|161|' results['SNMP_AGENT_ADDRESS_CONFIG'][snmp_key] = {} phyport_intfs = {} diff --git a/src/sonic-config-engine/tests/test_cfggen.py b/src/sonic-config-engine/tests/test_cfggen.py index b8adb80a3113..fabfe60edd9e 100644 --- a/src/sonic-config-engine/tests/test_cfggen.py +++ b/src/sonic-config-engine/tests/test_cfggen.py @@ -1087,15 +1087,6 @@ def test_minigraph_400g_to_100G_speed(self): ) ) - def testsnmp_agent_address_config(self): - argument = ['-m', self.sample_graph, '-p', self.port_config, '-v', 'SNMP_AGENT_ADDRESS_CONFIG.keys()|list'] - output = self.run_script(argument) - import pdb; pdb.set_trace() - self.assertEqual( - utils.liststr_to_dict(output.strip()), - utils.liststr_to_dict("['192.168.200.15|161|', '100.0.0.6|161|']") - ) - def test_minigraph_cisco_400g_to_100G_speed(self): argument = ["-m", self.sample_cisco_100_graph, "-p", self.sample_cisco_port_config_400g, "-v", "PORT"] self.assertTrue(self.yang.validate(argument)) @@ -1118,3 +1109,12 @@ def test_minigraph_cisco_400G_to_400G_speed(self): "{'Ethernet0': {'lanes': '2304,2305,2306,2307', 'alias': 'etp0a', 'index': '0', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA01T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet4': {'lanes': '2308,2309,2310,2311', 'alias': 'etp0b', 'index': '0', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA02T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet8': {'lanes': '2320,2321,2322,2323', 'alias': 'etp1a', 'index': '1', 'speed': '100000', 'fec': 'rs', 'description': 'etp1a', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet12': {'lanes': '2324,2325,2326,2327', 'alias': 'etp1b', 'index': '1', 'speed': '100000', 'fec': 'rs', 'description': 'etp1b', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet16': {'lanes': '2312,2313,2314,2315', 'alias': 'etp2a', 'index': '2', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA03T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet20': {'lanes': '2316,2317,2318,2319', 'alias': 'etp2b', 'index': '2', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA04T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet24': {'lanes': '2056,2057,2058,2059', 'alias': 'etp3a', 'index': '3', 'speed': '100000', 'fec': 'rs', 'description': 'etp3a', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet28': {'lanes': '2060,2061,2062,2063', 'alias': 'etp3b', 'index': '3', 'speed': '100000', 'fec': 'rs', 'description': 'etp3b', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet32': {'lanes': '1792,1793,1794,1795', 'alias': 'etp4a', 'index': '4', 'speed': '100000', 'fec': 'rs', 'description': 'etp4a', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet36': {'lanes': '1796,1797,1798,1799', 'alias': 'etp4b', 'index': '4', 'speed': '100000', 'fec': 'rs', 'description': 'etp4b', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet40': {'lanes': '2048,2049,2050,2051', 'alias': 'etp5a', 'index': '5', 'speed': '100000', 'fec': 'rs', 'description': 'etp5a', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet44': {'lanes': '2052,2053,2054,2055', 'alias': 'etp5b', 'index': '5', 'speed': '100000', 'fec': 'rs', 'description': 'etp5b', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet48': {'lanes': '2560,2561,2562,2563', 'alias': 'etp6a', 'index': '6', 'speed': '100000', 'fec': 'rs', 'description': 'etp6a', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet52': {'lanes': '2564,2565,2566,2567', 'alias': 'etp6b', 'index': '6', 'speed': '100000', 'fec': 'rs', 'description': 'etp6b', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet56': {'lanes': '2824,2825,2826,2827', 'alias': 'etp7a', 'index': '7', 'speed': '100000', 'fec': 'rs', 'description': 'etp7a', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet60': {'lanes': '2828,2829,2830,2831', 'alias': 'etp7b', 'index': '7', 'speed': '100000', 'fec': 'rs', 'description': 'etp7b', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet64': {'lanes': '2832,2833,2834,2835', 'alias': 'etp8a', 'index': '8', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA05T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet68': {'lanes': '2836,2837,2838,2839', 'alias': 'etp8b', 'index': '8', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA06T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet72': {'lanes': '2816,2817,2818,2819', 'alias': 'etp9a', 'index': '9', 'speed': '100000', 'fec': 'rs', 'description': 'etp9a', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet76': {'lanes': '2820,2821,2822,2823', 'alias': 'etp9b', 'index': '9', 'speed': '100000', 'fec': 'rs', 'description': 'etp9b', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet80': {'lanes': '2568,2569,2570,2571', 'alias': 'etp10a', 'index': '10', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA07T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet84': {'lanes': '2572,2573,2574,2575', 'alias': 'etp10b', 'index': '10', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA08T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet88': {'lanes': '2576,2577,2578,2579', 'alias': 'etp11a', 'index': '11', 'speed': '100000', 'fec': 'rs', 'description': 'etp11a', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet92': {'lanes': '2580,2581,2582,2583', 'alias': 'etp11b', 'index': '11', 'speed': '100000', 'fec': 'rs', 'description': 'etp11b', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet96': {'lanes': '1536,1537,1538,1539,1540,1541,1542,1543', 'alias': 'etp12', 'index': '12', 'speed': '400000', 'description': 'ARISTA01T2:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet104': {'lanes': '1800,1801,1802,1803,1804,1805,1806,1807', 'alias': 'etp13', 'index': '13', 'speed': '400000', 'description': 'ARISTA01T2:Ethernet2', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet112': {'lanes': '1552,1553,1554,1555,1556,1557,1558,1559', 'alias': 'etp14', 'index': '14', 'speed': '400000', 'description': 'ARISTA03T2:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet120': {'lanes': '1544,1545,1546,1547,1548,1549,1550,1551', 'alias': 'etp15', 'index': '15', 'speed': '400000', 'description': 'ARISTA03T2:Ethernet2', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet128': {'lanes': '1296,1297,1298,1299,1300,1301,1302,1303', 'alias': 'etp16', 'index': '16', 'speed': '400000', 'description': 'ARISTA05T2:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet136': {'lanes': '1288,1289,1290,1291,1292,1293,1294,1295', 'alias': 'etp17', 'index': '17', 'speed': '400000', 'description': 'ARISTA05T2:Ethernet2', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet144': {'lanes': '1280,1281,1282,1283,1284,1285,1286,1287', 'alias': 'etp18', 'index': '18', 'speed': '400000', 'description': 'ARISTA07T2:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet152': {'lanes': '1032,1033,1034,1035,1036,1037,1038,1039', 'alias': 'etp19', 'index': '19', 'speed': '400000', 'description': 'ARISTA07T2:Ethernet2', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet160': {'lanes': '264,265,266,267', 'alias': 'etp20a', 'index': '20', 'speed': '100000', 'fec': 'rs', 'description': 'etp20a', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet164': {'lanes': '268,269,270,271', 'alias': 'etp20b', 'index': '20', 'speed': '100000', 'fec': 'rs', 'description': 'etp20b', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet168': {'lanes': '272,273,274,275', 'alias': 'etp21a', 'index': '21', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA09T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet172': {'lanes': '276,277,278,279', 'alias': 'etp21b', 'index': '21', 'speed': '100000', 'fec': 'rs', 'description': 'etp21b', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet176': {'lanes': '16,17,18,19', 'alias': 'etp22a', 'index': '22', 'speed': '100000', 'fec': 'rs', 'description': 'etp22a', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet180': {'lanes': '20,21,22,23', 'alias': 'etp22b', 'index': '22', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA10T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet184': {'lanes': '0,1,2,3', 'alias': 'etp23a', 'index': '23', 'speed': '100000', 'fec': 'rs', 'description': 'etp23a', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet188': {'lanes': '4,5,6,7', 'alias': 'etp23b', 'index': '23', 'speed': '100000', 'fec': 'rs', 'description': 'etp23b', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet192': {'lanes': '256,257,258,259', 'alias': 'etp24a', 'index': '24', 'speed': '100000', 'fec': 'rs', 'description': 'etp24a', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet196': {'lanes': '260,261,262,263', 'alias': 'etp24b', 'index': '24', 'speed': '100000', 'fec': 'rs', 'description': 'etp24b', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet200': {'lanes': '8,9,10,11', 'alias': 'etp25a', 'index': '25', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA11T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet204': {'lanes': '12,13,14,15', 'alias': 'etp25b', 'index': '25', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA12T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet208': {'lanes': '1024,1025,1026,1027', 'alias': 'etp26a', 'index': '26', 'speed': '100000', 'fec': 'rs', 'description': 'etp26a', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet212': {'lanes': '1028,1029,1030,1031', 'alias': 'etp26b', 'index': '26', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA13T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet216': {'lanes': '768,769,770,771', 'alias': 'etp27a', 'index': '27', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA14T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet220': {'lanes': '772,773,774,775', 'alias': 'etp27b', 'index': '27', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA15T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet224': {'lanes': '524,525,526,527', 'alias': 'etp28a', 'index': '28', 'speed': '100000', 'fec': 'rs', 'description': 'etp28a', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet228': {'lanes': '520,521,522,523', 'alias': 'etp28b', 'index': '28', 'speed': '100000', 'fec': 'rs', 'description': 'etp28b', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet232': {'lanes': '776,777,778,779', 'alias': 'etp29a', 'index': '29', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA16T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet236': {'lanes': '780,781,782,783', 'alias': 'etp29b', 'index': '29', 'speed': '100000', 'fec': 'rs', 'description': 'etp29b', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet240': {'lanes': '516,517,518,519', 'alias': 'etp30a', 'index': '30', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA17T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet244': {'lanes': '512,513,514,515', 'alias': 'etp30b', 'index': '30', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA18T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet248': {'lanes': '528,529,530,531', 'alias': 'etp31a', 'index': '31', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA19T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet252': {'lanes': '532,533,534,535', 'alias': 'etp31b', 'index': '31', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA20T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}}" ) ) + + def testsnmp_agent_address_config(self): + argument = ['-m', self.sample_graph, '-p', self.port_config, '-v', 'SNMP_AGENT_ADDRESS_CONFIG.keys()|list'] + output = self.run_script(argument) + import pdb; pdb.set_trace() + self.assertEqual( + utils.liststr_to_dict(output.strip()), + utils.liststr_to_dict("['192.168.200.15|161|', '100.0.0.6|161|']") + ) diff --git a/src/sonic-config-engine/tests/test_multinpu_cfggen.py b/src/sonic-config-engine/tests/test_multinpu_cfggen.py index 9edb01d1b8cd..ad9e20dbf49a 100644 --- a/src/sonic-config-engine/tests/test_multinpu_cfggen.py +++ b/src/sonic-config-engine/tests/test_multinpu_cfggen.py @@ -214,15 +214,6 @@ def test_backend_asic_portchannel_intf(self): utils.liststr_to_dict("['PortChannel4013', 'PortChannel4013|10.1.0.2/31', 'PortChannel4014', 'PortChannel4014|10.1.0.6/31']") ) - def testsnmp_agent_address_config(self): - argument = ['-m', self.sample_graph, '-p', self.sample_port_config, '-v', 'SNMP_AGENT_ADDRESS_CONFIG.keys()|list'] - output = self.run_script(argument) - import pdb; pdb.set_trace() - self.assertEqual( - utils.liststr_to_dict(output.strip()), - utils.liststr_to_dict("['10.1.0.32|161|', '3.10.147.150|161|', 'FC00:2::32|161|', 'FC00:1::32|161|']") - ) - def test_frontend_asic_ports(self): argument = ["-m", self.sample_graph, "-p", self.port_config[0], "-n", "asic0", "--var-json", "PORT"] output = json.loads(self.run_script(argument)) @@ -558,5 +549,14 @@ def test_no_asic_in_graph(self): output = json.loads(self.run_script(argument, check_stderr=False, validateYang=False)) self.assertDictEqual(output, {}) + def testsnmp_agent_address_config(self): + argument = ['-m', self.sample_graph, '-p', self.sample_port_config, '-v', 'SNMP_AGENT_ADDRESS_CONFIG.keys()|list'] + output = self.run_script(argument) + import pdb; pdb.set_trace() + self.assertEqual( + utils.liststr_to_dict(output.strip()), + utils.liststr_to_dict("['10.1.0.32|161|', '3.10.147.150|161|', 'FC00:2::32|161|', 'FC00:1::32|161|']") + ) + def tearDown(self): os.environ["CFGGEN_UNIT_TESTING"] = "" From da40251f9f3367967e7a11f6fafba11b49342465 Mon Sep 17 00:00:00 2001 From: Suvarna Meenakshi Date: Tue, 27 Jun 2023 08:31:37 +0000 Subject: [PATCH 06/10] Moved logic to minigraph parser to add right IP addresses. Update snmpd.conf template to support ipv6 address. Signed-off-by: Suvarna Meenakshi --- dockers/docker-snmp/snmpd.conf.j2 | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/dockers/docker-snmp/snmpd.conf.j2 b/dockers/docker-snmp/snmpd.conf.j2 index f16e71b2f9da..da79a7b42358 100644 --- a/dockers/docker-snmp/snmpd.conf.j2 +++ b/dockers/docker-snmp/snmpd.conf.j2 @@ -15,33 +15,20 @@ # Listen for connections on all ip addresses, including eth0, ipv4 lo # -{% set loip = [] %} -{% if LOOPBACK_INTERFACE is defined and (NAMESPACE_COUNT is defined and NAMESPACE_COUNT|int > 1) %} -{% for lo in LOOPBACK_INTERFACE %} -{% if lo | length == 2 and 'Loopback0' in lo[0] %} -{% if loip.append(lo[1].split('/')[0]) %}{% endif %} -{% endif %} -{% endfor %} -{% endif %} - {% if SNMP_AGENT_ADDRESS_CONFIG %} -{% set protocol = 'udp' %} {% for (agentip, port, vrf) in SNMP_AGENT_ADDRESS_CONFIG %} {% if ':' in agentip %} {% set protocol = 'udp6' %} +{% else %} +{% set protocol = 'udp' %} {% endif %} -{% if not agentip in loip %} agentAddress {{ protocol }}:[{{ agentip }}]{% if port %}:{{ port }}{% endif %}{% if vrf %}%{{ vrf }}{% endif %}{{ "" }} -{% endif %} {% endfor %} -{% if NAMESPACE_COUNT is defined and NAMESPACE_COUNT|int > 1 %} -agentAddress udp:[{{ docker0_v4 }}]:161 -agentAddress udp6:[{{ docker0_v6 }}]:161 -{% endif %} {% else %} agentAddress udp:161 agentAddress udp6:161 {% endif %} + ############################################################################### # # ACCESS CONTROL From 6859d0d7ea8e6594a30b32cfa2656ae6157bd66b Mon Sep 17 00:00:00 2001 From: Suvarna Meenakshi Date: Tue, 27 Jun 2023 08:33:39 +0000 Subject: [PATCH 07/10] Remove logic to get docker0 ip. Signed-off-by: Suvarna Meenakshi --- dockers/docker-snmp/start.sh | 5 ----- 1 file changed, 5 deletions(-) diff --git a/dockers/docker-snmp/start.sh b/dockers/docker-snmp/start.sh index d80a6e4317e1..aefd0bfc3db6 100755 --- a/dockers/docker-snmp/start.sh +++ b/dockers/docker-snmp/start.sh @@ -16,16 +16,11 @@ mkdir -p /etc/ssw /etc/snmp # Parse snmp.yml and insert the data in Config DB /usr/bin/snmp_yml_to_configdb.py -DOCKER0_V4=$(ip -4 addr show docker0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}') -DOCKER0_V6=$(ip -6 addr show docker0 scope global | grep -oP '(?<=inet6\s)[0-9a-fA-F:]+') -ADD_PARAM=$(printf '%s {"docker0_v4":"%s","docker0_v6":"%s","NAMESPACE_COUNT":"%s"}' "-a" "$DOCKER0_V4" "$DOCKER0_V6" "$NAMESPACE_COUNT") - SONIC_CFGGEN_ARGS=" \ -d \ -y /etc/sonic/sonic_version.yml \ -t /usr/share/sonic/templates/sysDescription.j2,/etc/ssw/sysDescription \ -t /usr/share/sonic/templates/snmpd.conf.j2,/etc/snmp/snmpd.conf \ - $ADD_PARAM \ " sonic-cfggen $SONIC_CFGGEN_ARGS From e9cdf0a8dd77be048706735b79b20ebab1f616b3 Mon Sep 17 00:00:00 2001 From: Suvarna Meenakshi Date: Tue, 27 Jun 2023 08:41:46 +0000 Subject: [PATCH 08/10] Modify function name Signed-off-by: Suvarna Meenakshi --- src/sonic-config-engine/minigraph.py | 3 ++- src/sonic-config-engine/tests/mock_tables/dbconnector.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/sonic-config-engine/minigraph.py b/src/sonic-config-engine/minigraph.py index a11029814773..0c295be14f65 100644 --- a/src/sonic-config-engine/minigraph.py +++ b/src/sonic-config-engine/minigraph.py @@ -15,6 +15,7 @@ from portconfig import get_port_config from sonic_py_common.interface import backplane_prefix +from sonic_py_common.multi_asic import get_docker0_ips # TODO: Remove this once we no longer support Python 2 if sys.version_info.major == 3: @@ -1711,7 +1712,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw for mgmt_if in results['MGMT_INTERFACE'].keys(): snmp_key = mgmt_if[1].split('/')[0] + '|161|' results['SNMP_AGENT_ADDRESS_CONFIG'][snmp_key] = {} - docker0_v4, docker0_v6 = get_docker0_ip() + docker0_v4, docker0_v6 = get_docker0_ips() if docker0_v4 is None and docker0_v6 is None: # Add Loopback0 IP as agent address for single asic for loip in results['LOOPBACK_INTERFACE']: diff --git a/src/sonic-config-engine/tests/mock_tables/dbconnector.py b/src/sonic-config-engine/tests/mock_tables/dbconnector.py index 9e766294d6c2..66bb5b8c4aca 100644 --- a/src/sonic-config-engine/tests/mock_tables/dbconnector.py +++ b/src/sonic-config-engine/tests/mock_tables/dbconnector.py @@ -140,7 +140,7 @@ def keys(self, pattern='*'): # Find every key that matches the pattern return [key for key in self.redis if regex.match(key)] -def get_docker0_ip(): +def get_docker0_ips(): if multi_asic.is_multi_asic(): return '240.127.1.1', 'fd00::1' else: @@ -153,4 +153,4 @@ def get_docker0_ip(): swsscommon.SonicV2Connector = SonicV2Connector swsscommon.ConfigDBConnector = ConfigDBConnector swsscommon.ConfigDBPipeConnector = ConfigDBPipeConnector -multi_asic.get_docker0_ip = get_docker0_ip +multi_asic.get_docker0_ips = get_docker0_ips From 40ba8f13c9959b64fff0ea5d69e310c2592b55b9 Mon Sep 17 00:00:00 2001 From: Suvarna Meenakshi Date: Thu, 29 Jun 2023 01:23:11 +0000 Subject: [PATCH 09/10] Modify to simpler change to easily backport to other branches. Signed-off-by: Suvarna Meenakshi --- dockers/docker-snmp/snmpd.conf.j2 | 31 ++++++++-- dockers/docker-snmp/start.sh | 3 + src/sonic-config-engine/minigraph.py | 56 ++++++++----------- .../tests/mock_tables/dbconnector.py | 7 --- src/sonic-config-engine/tests/test_cfggen.py | 15 ++--- .../tests/test_multinpu_cfggen.py | 20 ++++--- 6 files changed, 67 insertions(+), 65 deletions(-) diff --git a/dockers/docker-snmp/snmpd.conf.j2 b/dockers/docker-snmp/snmpd.conf.j2 index da79a7b42358..b0c37c5dd98f 100644 --- a/dockers/docker-snmp/snmpd.conf.j2 +++ b/dockers/docker-snmp/snmpd.conf.j2 @@ -13,17 +13,36 @@ # AGENT BEHAVIOUR # -# Listen for connections on all ip addresses, including eth0, ipv4 lo +# Listen for connections on all ip addresses, including eth0, ipv4 lo for multi-asic platform +# Listen on managment and loopback0 ips for single asic platform # +{% macro protocol(ip_addr) %} +{%- if ':' in ip_addr -%} +{{ 'udp6' }} +{%- else -%} +{{ 'udp' }} +{%- endif -%} +{% endmacro %} + {% if SNMP_AGENT_ADDRESS_CONFIG %} {% for (agentip, port, vrf) in SNMP_AGENT_ADDRESS_CONFIG %} -{% if ':' in agentip %} -{% set protocol = 'udp6' %} -{% else %} -{% set protocol = 'udp' %} +agentAddress {{ protocol(agentip) }}:[{{ agentip }}]{% if port %}:{{ port }}{% endif %}{% if vrf %}%{{ vrf }}{% endif %}{{ "" }} +{% endfor %} +{% elif NAMESPACE_COUNT is not defined or NAMESPACE_COUNT|int <= 1 %} +{% if MGMT_INTERFACE is defined %} +{% for if, ip in MGMT_INTERFACE %} +{% set agentip = ip.split('/')[0] %} +agentAddress {{ protocol(agentip) }}:[{{ agentip }}]:161 +{% endfor %} +{% endif %} +{% if LOOPBACK_INTERFACE is defined %} +{% for lo in LOOPBACK_INTERFACE %} +{% if lo | length == 2 %} +{% set agentip = lo[1].split('/')[0] %} +agentAddress {{ protocol(agentip) }}:[{{ agentip }}]:161 {% endif %} -agentAddress {{ protocol }}:[{{ agentip }}]{% if port %}:{{ port }}{% endif %}{% if vrf %}%{{ vrf }}{% endif %}{{ "" }} {% endfor %} +{% endif %} {% else %} agentAddress udp:161 agentAddress udp6:161 diff --git a/dockers/docker-snmp/start.sh b/dockers/docker-snmp/start.sh index aefd0bfc3db6..559cdfdc341e 100755 --- a/dockers/docker-snmp/start.sh +++ b/dockers/docker-snmp/start.sh @@ -16,11 +16,14 @@ mkdir -p /etc/ssw /etc/snmp # Parse snmp.yml and insert the data in Config DB /usr/bin/snmp_yml_to_configdb.py +ADD_PARAM=$(printf '%s {"NAMESPACE_COUNT":"%s"}' "-a" "$NAMESPACE_COUNT") + SONIC_CFGGEN_ARGS=" \ -d \ -y /etc/sonic/sonic_version.yml \ -t /usr/share/sonic/templates/sysDescription.j2,/etc/ssw/sysDescription \ -t /usr/share/sonic/templates/snmpd.conf.j2,/etc/snmp/snmpd.conf \ + $ADD_PARAM \ " sonic-cfggen $SONIC_CFGGEN_ARGS diff --git a/src/sonic-config-engine/minigraph.py b/src/sonic-config-engine/minigraph.py index 0c295be14f65..558c7e24e929 100644 --- a/src/sonic-config-engine/minigraph.py +++ b/src/sonic-config-engine/minigraph.py @@ -13,9 +13,8 @@ from natsort import natsorted, ns as natsortns -from portconfig import get_port_config +from portconfig import get_port_config, get_fabric_port_config, get_fabric_monitor_config from sonic_py_common.interface import backplane_prefix -from sonic_py_common.multi_asic import get_docker0_ips # TODO: Remove this once we no longer support Python 2 if sys.version_info.major == 3: @@ -57,12 +56,12 @@ 'BMCDATA': { "ACTIONS": "PACKET_ACTION,COUNTER", "BIND_POINTS": "PORT", - "MATCHES": "SRC_IP,DST_IP,ETHER_TYPE,IP_TYPE,IP_PROTOCOL,IN_PORTS,TCP_FLAGS", + "MATCHES": "SRC_IP,DST_IP,ETHER_TYPE,IP_TYPE,IP_PROTOCOL,IN_PORTS,L4_SRC_PORT,L4_DST_PORT,L4_SRC_PORT_RANGE,L4_DST_PORT_RANGE", }, 'BMCDATAV6': { "ACTIONS": "PACKET_ACTION,COUNTER", "BIND_POINTS": "PORT", - "MATCHES": "SRC_IPV6,DST_IPV6,ETHER_TYPE,IP_TYPE,IP_PROTOCOL,IN_PORTS,TCP_FLAGS", + "MATCHES": "SRC_IPV6,DST_IPV6,ETHER_TYPE,IP_TYPE,IP_PROTOCOL,IN_PORTS,L4_SRC_PORT,L4_DST_PORT,L4_SRC_PORT_RANGE,L4_DST_PORT_RANGE", } } @@ -994,6 +993,7 @@ def parse_meta(meta, hname): dhcp_servers = [] dhcpv6_servers = [] ntp_servers = [] + dns_nameservers = [] tacacs_servers = [] mgmt_routes = [] erspan_dst = [] @@ -1024,6 +1024,8 @@ def parse_meta(meta, hname): dhcp_servers = value_group elif name == "NtpResources": ntp_servers = value_group + elif name == "DnsNameserverResources": + dns_nameservers = value_group elif name == "SyslogResources": syslog_servers = value_group elif name == "TacacsServer": @@ -1062,7 +1064,7 @@ def parse_meta(meta, hname): qos_profile = value elif name == "RackMgmtMap": rack_mgmt_map = value - return syslog_servers, dhcp_servers, dhcpv6_servers, ntp_servers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id, region, cloudtype, resource_type, downstream_subrole, switch_id, switch_type, max_cores, kube_data, macsec_profile, downstream_redundancy_types, redundancy_type, qos_profile, rack_mgmt_map + return syslog_servers, dhcp_servers, dhcpv6_servers, ntp_servers, dns_nameservers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id, region, cloudtype, resource_type, downstream_subrole, switch_id, switch_type, max_cores, kube_data, macsec_profile, downstream_redundancy_types, redundancy_type, qos_profile, rack_mgmt_map def parse_linkmeta(meta, hname): @@ -1437,7 +1439,7 @@ def select_mmu_profiles(profile, platform, hwsku): # Main functions # ############################################################################### -def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hwsku_config_file=None): +def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hwsku_config_file=None, fabric_port_config_file=None ): """ Parse minigraph xml file. Keyword arguments: @@ -1446,6 +1448,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw port_config_file -- port config file name asic_name -- asic name; to parse multi-asic device minigraph to generate asic specific configuration. + fabric_port_config_file -- fabric port config file name """ root = ET.parse(filename).getroot() @@ -1488,6 +1491,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw dhcp_servers = [] dhcpv6_servers = [] ntp_servers = [] + dns_nameservers = [] tacacs_servers = [] mgmt_routes = [] erspan_dst = [] @@ -1543,7 +1547,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw elif child.tag == str(QName(ns, "UngDec")): (u_neighbors, u_devices, _, _, _, _, _, _) = parse_png(child, hostname, None) elif child.tag == str(QName(ns, "MetadataDeclaration")): - (syslog_servers, dhcp_servers, dhcpv6_servers, ntp_servers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id, region, cloudtype, resource_type, downstream_subrole, switch_id, switch_type, max_cores, kube_data, macsec_profile, downstream_redundancy_types, redundancy_type, qos_profile, rack_mgmt_map) = parse_meta(child, hostname) + (syslog_servers, dhcp_servers, dhcpv6_servers, ntp_servers, dns_nameservers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id, region, cloudtype, resource_type, downstream_subrole, switch_id, switch_type, max_cores, kube_data, macsec_profile, downstream_redundancy_types, redundancy_type, qos_profile, rack_mgmt_map) = parse_meta(child, hostname) elif child.tag == str(QName(ns, "LinkMetadataDeclaration")): linkmetas = parse_linkmeta(child, hostname) elif child.tag == str(QName(ns, "DeviceInfos")): @@ -1701,33 +1705,6 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw results['LOOPBACK_INTERFACE'][host_lo_intf[0]] = {} results['MGMT_VRF_CONFIG'] = mvrf - - # Update SNMP_AGENT_ADDRESS_CONFIG with Management IP and Loopback0 IP - # for single-asic platform. - # Update SNMP_AGENT_ADDRESS_CONFIG with Management IP and docker0 IP - # for multi-asic platform. - results['SNMP_AGENT_ADDRESS_CONFIG'] = {} - if asic_name is None: - results['SNMP_AGENT_ADDRESS_CONFIG'] = {} - for mgmt_if in results['MGMT_INTERFACE'].keys(): - snmp_key = mgmt_if[1].split('/')[0] + '|161|' - results['SNMP_AGENT_ADDRESS_CONFIG'][snmp_key] = {} - docker0_v4, docker0_v6 = get_docker0_ips() - if docker0_v4 is None and docker0_v6 is None: - # Add Loopback0 IP as agent address for single asic - for loip in results['LOOPBACK_INTERFACE']: - if len(loip) == 2 and loip[0] == 'Loopback0': - snmp_key = loip[1].split('/')[0] + '|161|' - results['SNMP_AGENT_ADDRESS_CONFIG'][snmp_key] = {} - else: - # docker0 ip address is available for multi-asic - # Add docker0 IP address as agent address - if docker0_v4: - snmp_key = docker0_v4 + '|161|' - results['SNMP_AGENT_ADDRESS_CONFIG'][snmp_key] = {} - if docker0_v6: - snmp_key = docker0_v6 + '|161|' - results['SNMP_AGENT_ADDRESS_CONFIG'][snmp_key] = {} phyport_intfs = {} vlan_intfs = {} @@ -1899,6 +1876,16 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw results['PORT'] = ports results['CONSOLE_PORT'] = console_ports + # Get the global fabric monitoring data + fabric_monitor = get_fabric_monitor_config(hwsku=hwsku, asic_name=asic_name) + if bool( fabric_monitor ): + results[ 'FABRIC_MONITOR' ] = fabric_monitor + + # parse fabric + fabric_ports = get_fabric_port_config(hwsku=hwsku, platform=platform, fabric_port_config_file=fabric_port_config_file, asic_name=asic_name, hwsku_config_file=hwsku_config_file) + if bool( fabric_ports ): + results['FABRIC_PORT'] = fabric_ports + if port_config_file: port_set = set(ports.keys()) for (pc_name, pc_member) in list(pc_members.keys()): @@ -2012,6 +1999,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw results['DHCP_SERVER'] = dict((item, {}) for item in dhcp_servers) results['DHCP_RELAY'] = dhcp_relay_table results['NTP_SERVER'] = dict((item, {}) for item in ntp_servers) + results['DNS_NAMESERVER'] = dict((item, {}) for item in dns_nameservers) results['TACPLUS_SERVER'] = dict((item, {'priority': '1', 'tcp_port': '49'}) for item in tacacs_servers) if len(acl_table_types) > 0: results['ACL_TABLE_TYPE'] = acl_table_types diff --git a/src/sonic-config-engine/tests/mock_tables/dbconnector.py b/src/sonic-config-engine/tests/mock_tables/dbconnector.py index 66bb5b8c4aca..2b152c36a06a 100644 --- a/src/sonic-config-engine/tests/mock_tables/dbconnector.py +++ b/src/sonic-config-engine/tests/mock_tables/dbconnector.py @@ -140,12 +140,6 @@ def keys(self, pattern='*'): # Find every key that matches the pattern return [key for key in self.redis if regex.match(key)] -def get_docker0_ips(): - if multi_asic.is_multi_asic(): - return '240.127.1.1', 'fd00::1' - else: - return None, None - swsssdk.interface.DBInterface._subscribe_keyspace_notification = _subscribe_keyspace_notification mockredis.MockRedis.config_set = config_set redis.StrictRedis = SwssSyncClient @@ -153,4 +147,3 @@ def get_docker0_ips(): swsscommon.SonicV2Connector = SonicV2Connector swsscommon.ConfigDBConnector = ConfigDBConnector swsscommon.ConfigDBPipeConnector = ConfigDBPipeConnector -multi_asic.get_docker0_ips = get_docker0_ips diff --git a/src/sonic-config-engine/tests/test_cfggen.py b/src/sonic-config-engine/tests/test_cfggen.py index fabfe60edd9e..50e3c2758a1e 100644 --- a/src/sonic-config-engine/tests/test_cfggen.py +++ b/src/sonic-config-engine/tests/test_cfggen.py @@ -57,6 +57,7 @@ def tearDown(self): def run_script(self, argument, check_stderr=False, verbose=False): print('\n Running sonic-cfggen ' + ' '.join(argument)) + self.assertTrue(self.yang.validate(argument)) if check_stderr: output = subprocess.check_output(self.script_file + argument, stderr=subprocess.STDOUT) else: @@ -695,6 +696,11 @@ def test_metadata_ntp(self): output = self.run_script(argument) self.assertEqual(utils.to_dict(output.strip()), utils.to_dict("{'10.0.10.1': {}, '10.0.10.2': {}}")) + def test_metadata_dns_nameserver(self): + argument = ['-m', self.sample_graph_metadata, '-p', self.port_config, '-v', "DNS_NAMESERVER"] + output = self.run_script(argument) + self.assertEqual(utils.to_dict(output.strip()), utils.to_dict("{'20.2.2.2': {}, '30.3.3.3': {}}")) + def test_minigraph_vnet(self, **kwargs): graph_file = kwargs.get('graph_file', self.sample_graph_simple) argument = ['-m', graph_file, '-p', self.port_config, '-v', "VNET"] @@ -1109,12 +1115,3 @@ def test_minigraph_cisco_400G_to_400G_speed(self): "{'Ethernet0': {'lanes': '2304,2305,2306,2307', 'alias': 'etp0a', 'index': '0', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA01T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet4': {'lanes': '2308,2309,2310,2311', 'alias': 'etp0b', 'index': '0', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA02T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet8': {'lanes': '2320,2321,2322,2323', 'alias': 'etp1a', 'index': '1', 'speed': '100000', 'fec': 'rs', 'description': 'etp1a', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet12': {'lanes': '2324,2325,2326,2327', 'alias': 'etp1b', 'index': '1', 'speed': '100000', 'fec': 'rs', 'description': 'etp1b', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet16': {'lanes': '2312,2313,2314,2315', 'alias': 'etp2a', 'index': '2', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA03T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet20': {'lanes': '2316,2317,2318,2319', 'alias': 'etp2b', 'index': '2', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA04T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet24': {'lanes': '2056,2057,2058,2059', 'alias': 'etp3a', 'index': '3', 'speed': '100000', 'fec': 'rs', 'description': 'etp3a', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet28': {'lanes': '2060,2061,2062,2063', 'alias': 'etp3b', 'index': '3', 'speed': '100000', 'fec': 'rs', 'description': 'etp3b', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet32': {'lanes': '1792,1793,1794,1795', 'alias': 'etp4a', 'index': '4', 'speed': '100000', 'fec': 'rs', 'description': 'etp4a', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet36': {'lanes': '1796,1797,1798,1799', 'alias': 'etp4b', 'index': '4', 'speed': '100000', 'fec': 'rs', 'description': 'etp4b', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet40': {'lanes': '2048,2049,2050,2051', 'alias': 'etp5a', 'index': '5', 'speed': '100000', 'fec': 'rs', 'description': 'etp5a', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet44': {'lanes': '2052,2053,2054,2055', 'alias': 'etp5b', 'index': '5', 'speed': '100000', 'fec': 'rs', 'description': 'etp5b', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet48': {'lanes': '2560,2561,2562,2563', 'alias': 'etp6a', 'index': '6', 'speed': '100000', 'fec': 'rs', 'description': 'etp6a', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet52': {'lanes': '2564,2565,2566,2567', 'alias': 'etp6b', 'index': '6', 'speed': '100000', 'fec': 'rs', 'description': 'etp6b', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet56': {'lanes': '2824,2825,2826,2827', 'alias': 'etp7a', 'index': '7', 'speed': '100000', 'fec': 'rs', 'description': 'etp7a', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet60': {'lanes': '2828,2829,2830,2831', 'alias': 'etp7b', 'index': '7', 'speed': '100000', 'fec': 'rs', 'description': 'etp7b', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet64': {'lanes': '2832,2833,2834,2835', 'alias': 'etp8a', 'index': '8', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA05T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet68': {'lanes': '2836,2837,2838,2839', 'alias': 'etp8b', 'index': '8', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA06T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet72': {'lanes': '2816,2817,2818,2819', 'alias': 'etp9a', 'index': '9', 'speed': '100000', 'fec': 'rs', 'description': 'etp9a', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet76': {'lanes': '2820,2821,2822,2823', 'alias': 'etp9b', 'index': '9', 'speed': '100000', 'fec': 'rs', 'description': 'etp9b', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet80': {'lanes': '2568,2569,2570,2571', 'alias': 'etp10a', 'index': '10', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA07T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet84': {'lanes': '2572,2573,2574,2575', 'alias': 'etp10b', 'index': '10', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA08T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet88': {'lanes': '2576,2577,2578,2579', 'alias': 'etp11a', 'index': '11', 'speed': '100000', 'fec': 'rs', 'description': 'etp11a', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet92': {'lanes': '2580,2581,2582,2583', 'alias': 'etp11b', 'index': '11', 'speed': '100000', 'fec': 'rs', 'description': 'etp11b', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet96': {'lanes': '1536,1537,1538,1539,1540,1541,1542,1543', 'alias': 'etp12', 'index': '12', 'speed': '400000', 'description': 'ARISTA01T2:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet104': {'lanes': '1800,1801,1802,1803,1804,1805,1806,1807', 'alias': 'etp13', 'index': '13', 'speed': '400000', 'description': 'ARISTA01T2:Ethernet2', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet112': {'lanes': '1552,1553,1554,1555,1556,1557,1558,1559', 'alias': 'etp14', 'index': '14', 'speed': '400000', 'description': 'ARISTA03T2:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet120': {'lanes': '1544,1545,1546,1547,1548,1549,1550,1551', 'alias': 'etp15', 'index': '15', 'speed': '400000', 'description': 'ARISTA03T2:Ethernet2', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet128': {'lanes': '1296,1297,1298,1299,1300,1301,1302,1303', 'alias': 'etp16', 'index': '16', 'speed': '400000', 'description': 'ARISTA05T2:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet136': {'lanes': '1288,1289,1290,1291,1292,1293,1294,1295', 'alias': 'etp17', 'index': '17', 'speed': '400000', 'description': 'ARISTA05T2:Ethernet2', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet144': {'lanes': '1280,1281,1282,1283,1284,1285,1286,1287', 'alias': 'etp18', 'index': '18', 'speed': '400000', 'description': 'ARISTA07T2:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet152': {'lanes': '1032,1033,1034,1035,1036,1037,1038,1039', 'alias': 'etp19', 'index': '19', 'speed': '400000', 'description': 'ARISTA07T2:Ethernet2', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet160': {'lanes': '264,265,266,267', 'alias': 'etp20a', 'index': '20', 'speed': '100000', 'fec': 'rs', 'description': 'etp20a', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet164': {'lanes': '268,269,270,271', 'alias': 'etp20b', 'index': '20', 'speed': '100000', 'fec': 'rs', 'description': 'etp20b', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet168': {'lanes': '272,273,274,275', 'alias': 'etp21a', 'index': '21', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA09T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet172': {'lanes': '276,277,278,279', 'alias': 'etp21b', 'index': '21', 'speed': '100000', 'fec': 'rs', 'description': 'etp21b', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet176': {'lanes': '16,17,18,19', 'alias': 'etp22a', 'index': '22', 'speed': '100000', 'fec': 'rs', 'description': 'etp22a', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet180': {'lanes': '20,21,22,23', 'alias': 'etp22b', 'index': '22', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA10T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet184': {'lanes': '0,1,2,3', 'alias': 'etp23a', 'index': '23', 'speed': '100000', 'fec': 'rs', 'description': 'etp23a', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet188': {'lanes': '4,5,6,7', 'alias': 'etp23b', 'index': '23', 'speed': '100000', 'fec': 'rs', 'description': 'etp23b', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet192': {'lanes': '256,257,258,259', 'alias': 'etp24a', 'index': '24', 'speed': '100000', 'fec': 'rs', 'description': 'etp24a', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet196': {'lanes': '260,261,262,263', 'alias': 'etp24b', 'index': '24', 'speed': '100000', 'fec': 'rs', 'description': 'etp24b', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet200': {'lanes': '8,9,10,11', 'alias': 'etp25a', 'index': '25', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA11T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet204': {'lanes': '12,13,14,15', 'alias': 'etp25b', 'index': '25', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA12T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet208': {'lanes': '1024,1025,1026,1027', 'alias': 'etp26a', 'index': '26', 'speed': '100000', 'fec': 'rs', 'description': 'etp26a', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet212': {'lanes': '1028,1029,1030,1031', 'alias': 'etp26b', 'index': '26', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA13T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet216': {'lanes': '768,769,770,771', 'alias': 'etp27a', 'index': '27', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA14T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet220': {'lanes': '772,773,774,775', 'alias': 'etp27b', 'index': '27', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA15T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet224': {'lanes': '524,525,526,527', 'alias': 'etp28a', 'index': '28', 'speed': '100000', 'fec': 'rs', 'description': 'etp28a', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet228': {'lanes': '520,521,522,523', 'alias': 'etp28b', 'index': '28', 'speed': '100000', 'fec': 'rs', 'description': 'etp28b', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet232': {'lanes': '776,777,778,779', 'alias': 'etp29a', 'index': '29', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA16T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet236': {'lanes': '780,781,782,783', 'alias': 'etp29b', 'index': '29', 'speed': '100000', 'fec': 'rs', 'description': 'etp29b', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off'}, 'Ethernet240': {'lanes': '516,517,518,519', 'alias': 'etp30a', 'index': '30', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA17T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet244': {'lanes': '512,513,514,515', 'alias': 'etp30b', 'index': '30', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA18T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet248': {'lanes': '528,529,530,531', 'alias': 'etp31a', 'index': '31', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA19T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}, 'Ethernet252': {'lanes': '532,533,534,535', 'alias': 'etp31b', 'index': '31', 'speed': '100000', 'fec': 'rs', 'description': 'ARISTA20T0:Ethernet1', 'mtu': '9100', 'tpid': '0x8100', 'pfc_asym': 'off', 'admin_status': 'up'}}" ) ) - - def testsnmp_agent_address_config(self): - argument = ['-m', self.sample_graph, '-p', self.port_config, '-v', 'SNMP_AGENT_ADDRESS_CONFIG.keys()|list'] - output = self.run_script(argument) - import pdb; pdb.set_trace() - self.assertEqual( - utils.liststr_to_dict(output.strip()), - utils.liststr_to_dict("['192.168.200.15|161|', '100.0.0.6|161|']") - ) diff --git a/src/sonic-config-engine/tests/test_multinpu_cfggen.py b/src/sonic-config-engine/tests/test_multinpu_cfggen.py index ad9e20dbf49a..7026dfa84a61 100644 --- a/src/sonic-config-engine/tests/test_multinpu_cfggen.py +++ b/src/sonic-config-engine/tests/test_multinpu_cfggen.py @@ -150,6 +150,17 @@ def test_metadata_ntp(self): print("Log:asic{} sku {}".format(asic,output)) self.assertDictEqual(output, {}) + def test_metadata_dns_nameserver(self): + argument = ['-m', self.sample_graph, '-p', self.sample_port_config, '--var-json', "DNS_NAMESERVER"] + output = json.loads(self.run_script(argument)) + self.assertDictEqual(output, {'1.1.1.1': {}, '8.8.8.8': {}}) + #DNS_NAMESERVER data is present only in the host config + argument = ['-m', self.sample_graph, '--var-json', "DNS_NAMESERVER"] + for asic in range(NUM_ASIC): + output = json.loads(self.run_script_for_asic(argument, asic, self.port_config[asic])) + print("Log:asic{} sku {}".format(asic,output)) + self.assertDictEqual(output, {}) + def test_mgmt_port(self): argument = ['-m', self.sample_graph, '-p', self.sample_port_config, '--var-json', "MGMT_PORT"] output = json.loads(self.run_script(argument)) @@ -549,14 +560,5 @@ def test_no_asic_in_graph(self): output = json.loads(self.run_script(argument, check_stderr=False, validateYang=False)) self.assertDictEqual(output, {}) - def testsnmp_agent_address_config(self): - argument = ['-m', self.sample_graph, '-p', self.sample_port_config, '-v', 'SNMP_AGENT_ADDRESS_CONFIG.keys()|list'] - output = self.run_script(argument) - import pdb; pdb.set_trace() - self.assertEqual( - utils.liststr_to_dict(output.strip()), - utils.liststr_to_dict("['10.1.0.32|161|', '3.10.147.150|161|', 'FC00:2::32|161|', 'FC00:1::32|161|']") - ) - def tearDown(self): os.environ["CFGGEN_UNIT_TESTING"] = "" From 817396c593210acf8b1ac5dfeeaac7ba26db9006 Mon Sep 17 00:00:00 2001 From: Suvarna Meenakshi Date: Tue, 11 Jul 2023 21:23:52 +0000 Subject: [PATCH 10/10] Modify as per review comment Signed-off-by: Suvarna Meenakshi --- dockers/docker-snmp/snmpd.conf.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dockers/docker-snmp/snmpd.conf.j2 b/dockers/docker-snmp/snmpd.conf.j2 index b0c37c5dd98f..cf7f8f385138 100644 --- a/dockers/docker-snmp/snmpd.conf.j2 +++ b/dockers/docker-snmp/snmpd.conf.j2 @@ -17,7 +17,7 @@ # Listen on managment and loopback0 ips for single asic platform # {% macro protocol(ip_addr) %} -{%- if ':' in ip_addr -%} +{%- if ip_addr|ipv6 -%} {{ 'udp6' }} {%- else -%} {{ 'udp' }}