From 6088bd59ded064f392b7618872e1306057b955e1 Mon Sep 17 00:00:00 2001 From: judyjoseph <53951155+judyjoseph@users.noreply.github.com> Date: Wed, 28 Oct 2020 16:41:27 -0700 Subject: [PATCH] [multi-ASIC] BGP internal neighbor table support (#5520) * Initial commit for BGP internal neighbor table support. > Add new template named "internal" for the internal BGP sessions > Add a new table in database "BGP_INTERNAL_NEIGHBOR" > The internal BGP sessions will be stored in this new table "BGP_INTERNAL_NEIGHBOR" * Changes in template generation tests with the introduction of internal neighbor template files. --- .../bgpd/templates/general/instance.conf.j2 | 19 ---- .../bgpd/templates/general/peer-group.conf.j2 | 16 ---- .../bgpd/templates/general/policies.conf.j2 | 11 --- .../bgpd/templates/internal/instance.conf.j2 | 34 ++++++++ .../templates/internal/peer-group.conf.j2 | 24 +++++ .../bgpd/templates/internal/policies.conf.j2 | 27 ++++++ files/image_config/constants/constants.yml | 3 + src/sonic-bgpcfgd/bgpcfgd/main.py | 3 +- .../general/instance.conf/param_ASIC_v6.json | 15 ---- .../general/instance.conf/param_all_v4.json | 5 -- .../general/instance.conf/param_all_v6.json | 5 -- .../general/instance.conf/result_ASIC_v6.conf | 13 --- .../general/instance.conf/result_all_v4.conf | 1 - .../general/instance.conf/result_all_v6.conf | 1 - .../general/peer-group.conf/param_base.json | 3 +- .../general/peer-group.conf/result_all.conf | 10 --- .../general/peer-group.conf/result_base.conf | 10 --- .../data/general/policies.conf/param_all.json | 5 -- .../general/policies.conf/param_base.json | 5 -- .../general/policies.conf/param_deny.json | 5 -- .../general/policies.conf/result_all.conf | 9 -- .../general/policies.conf/result_deny.conf | 9 -- .../internal/instance.conf/param_back_v4.json | 23 +++++ .../internal/instance.conf/param_back_v6.json | 23 +++++ .../instance.conf/param_front_v4.json} | 10 ++- .../instance.conf/param_front_v6.json | 21 +++++ .../instance.conf/result_back_v4.conf | 17 ++++ .../instance.conf/result_back_v6.conf | 17 ++++ .../instance.conf/result_front_v4.conf} | 6 +- .../instance.conf/result_front_v6.conf | 15 ++++ .../internal/peer-group.conf/param_back.json | 8 ++ .../internal/peer-group.conf/param_front.json | 8 ++ .../internal/peer-group.conf/result_back.conf | 20 +++++ .../peer-group.conf/result_front.conf | 18 ++++ .../internal/policies.conf/param_back.json | 8 ++ .../internal/policies.conf/param_front.json | 8 ++ .../internal/policies.conf/result_back.conf | 22 +++++ .../internal/policies.conf/result_front.conf | 16 ++++ src/sonic-config-engine/minigraph.py | 87 ++++++++++++++----- .../tests/test_multinpu_cfggen.py | 17 ++-- 40 files changed, 404 insertions(+), 173 deletions(-) create mode 100644 dockers/docker-fpm-frr/frr/bgpd/templates/internal/instance.conf.j2 create mode 100644 dockers/docker-fpm-frr/frr/bgpd/templates/internal/peer-group.conf.j2 create mode 100644 dockers/docker-fpm-frr/frr/bgpd/templates/internal/policies.conf.j2 delete mode 100644 src/sonic-bgpcfgd/tests/data/general/instance.conf/param_ASIC_v6.json delete mode 100644 src/sonic-bgpcfgd/tests/data/general/instance.conf/result_ASIC_v6.conf create mode 100644 src/sonic-bgpcfgd/tests/data/internal/instance.conf/param_back_v4.json create mode 100644 src/sonic-bgpcfgd/tests/data/internal/instance.conf/param_back_v6.json rename src/sonic-bgpcfgd/tests/data/{general/instance.conf/param_ASIC_v4.json => internal/instance.conf/param_front_v4.json} (51%) create mode 100644 src/sonic-bgpcfgd/tests/data/internal/instance.conf/param_front_v6.json create mode 100644 src/sonic-bgpcfgd/tests/data/internal/instance.conf/result_back_v4.conf create mode 100644 src/sonic-bgpcfgd/tests/data/internal/instance.conf/result_back_v6.conf rename src/sonic-bgpcfgd/tests/data/{general/instance.conf/result_ASIC_v4.conf => internal/instance.conf/result_front_v4.conf} (62%) create mode 100644 src/sonic-bgpcfgd/tests/data/internal/instance.conf/result_front_v6.conf create mode 100644 src/sonic-bgpcfgd/tests/data/internal/peer-group.conf/param_back.json create mode 100644 src/sonic-bgpcfgd/tests/data/internal/peer-group.conf/param_front.json create mode 100644 src/sonic-bgpcfgd/tests/data/internal/peer-group.conf/result_back.conf create mode 100644 src/sonic-bgpcfgd/tests/data/internal/peer-group.conf/result_front.conf create mode 100644 src/sonic-bgpcfgd/tests/data/internal/policies.conf/param_back.json create mode 100644 src/sonic-bgpcfgd/tests/data/internal/policies.conf/param_front.json create mode 100644 src/sonic-bgpcfgd/tests/data/internal/policies.conf/result_back.conf create mode 100644 src/sonic-bgpcfgd/tests/data/internal/policies.conf/result_front.conf diff --git a/dockers/docker-fpm-frr/frr/bgpd/templates/general/instance.conf.j2 b/dockers/docker-fpm-frr/frr/bgpd/templates/general/instance.conf.j2 index e4422a771664..37b91d3a2d76 100644 --- a/dockers/docker-fpm-frr/frr/bgpd/templates/general/instance.conf.j2 +++ b/dockers/docker-fpm-frr/frr/bgpd/templates/general/instance.conf.j2 @@ -15,27 +15,12 @@ ! {% if neighbor_addr | ipv4 %} address-family ipv4 -{% if 'ASIC' in bgp_session['name'] %} - neighbor {{ neighbor_addr }} peer-group PEER_V4_INT -{% else %} neighbor {{ neighbor_addr }} peer-group PEER_V4 -{% endif %} -! -{% if CONFIG_DB__DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' %} - neighbor {{ neighbor_addr }} route-map FROM_BGP_PEER_V4_INT in -{% endif %} ! {% elif neighbor_addr | ipv6 %} address-family ipv6 -{% if 'ASIC' in bgp_session['name'] %} - neighbor {{ neighbor_addr }} peer-group PEER_V6_INT -{% else %} neighbor {{ neighbor_addr }} peer-group PEER_V6 -{% endif %} ! -{% if CONFIG_DB__DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' %} - neighbor {{ neighbor_addr }} route-map FROM_BGP_PEER_V6_INT in -{% endif %} {% endif %} ! {% if bgp_session.has_key('rrclient') and bgp_session['rrclient'] | int != 0 %} @@ -45,10 +30,6 @@ {% if bgp_session.has_key('nhopself') and bgp_session['nhopself'] | int != 0 %} neighbor {{ neighbor_addr }} next-hop-self {% endif %} -! -{% if 'ASIC' in bgp_session['name'] %} - neighbor {{ neighbor_addr }} next-hop-self force -{% endif %} ! neighbor {{ neighbor_addr }} activate exit-address-family diff --git a/dockers/docker-fpm-frr/frr/bgpd/templates/general/peer-group.conf.j2 b/dockers/docker-fpm-frr/frr/bgpd/templates/general/peer-group.conf.j2 index 111b5ceb5f9f..2617cc94c2d2 100644 --- a/dockers/docker-fpm-frr/frr/bgpd/templates/general/peer-group.conf.j2 +++ b/dockers/docker-fpm-frr/frr/bgpd/templates/general/peer-group.conf.j2 @@ -2,46 +2,30 @@ ! template: bgpd/templates/general/peer-group.conf.j2 ! neighbor PEER_V4 peer-group - neighbor PEER_V4_INT peer-group neighbor PEER_V6 peer-group - neighbor PEER_V6_INT peer-group address-family ipv4 {% if CONFIG_DB__DEVICE_METADATA['localhost']['type'] == 'ToRRouter' %} neighbor PEER_V4 allowas-in 1 - neighbor PEER_V4_INT allowas-in 1 {% elif CONFIG_DB__DEVICE_METADATA['localhost']['type'] == 'LeafRouter' %} {% if CONFIG_DB__BGP_BBR['status'] == 'enabled' %} neighbor PEER_V4 allowas-in 1 {% endif %} -{% endif %} -{% if CONFIG_DB__DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' %} - neighbor PEER_V4_INT route-reflector-client {% endif %} neighbor PEER_V4 soft-reconfiguration inbound neighbor PEER_V4 route-map FROM_BGP_PEER_V4 in neighbor PEER_V4 route-map TO_BGP_PEER_V4 out - neighbor PEER_V4_INT soft-reconfiguration inbound - neighbor PEER_V4_INT route-map FROM_BGP_PEER_V4 in - neighbor PEER_V4_INT route-map TO_BGP_PEER_V4 out exit-address-family address-family ipv6 {% if CONFIG_DB__DEVICE_METADATA['localhost']['type'] == 'ToRRouter' %} neighbor PEER_V6 allowas-in 1 - neighbor PEER_V6_INT allowas-in 1 {% elif CONFIG_DB__DEVICE_METADATA['localhost']['type'] == 'LeafRouter' %} {% if CONFIG_DB__BGP_BBR['status'] == 'enabled' %} neighbor PEER_V6 allowas-in 1 {% endif %} -{% endif %} -{% if CONFIG_DB__DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' %} - neighbor PEER_V6_INT route-reflector-client {% endif %} neighbor PEER_V6 soft-reconfiguration inbound neighbor PEER_V6 route-map FROM_BGP_PEER_V6 in neighbor PEER_V6 route-map TO_BGP_PEER_V6 out - neighbor PEER_V6_INT soft-reconfiguration inbound - neighbor PEER_V6_INT route-map FROM_BGP_PEER_V6 in - neighbor PEER_V6_INT route-map TO_BGP_PEER_V6 out exit-address-family ! ! end of template: bgpd/templates/general/peer-group.conf.j2 diff --git a/dockers/docker-fpm-frr/frr/bgpd/templates/general/policies.conf.j2 b/dockers/docker-fpm-frr/frr/bgpd/templates/general/policies.conf.j2 index 4c27db4a466a..04dbc3bc490e 100644 --- a/dockers/docker-fpm-frr/frr/bgpd/templates/general/policies.conf.j2 +++ b/dockers/docker-fpm-frr/frr/bgpd/templates/general/policies.conf.j2 @@ -42,16 +42,5 @@ route-map FROM_BGP_PEER_V6 permit 100 ! route-map TO_BGP_PEER_V6 permit 100 ! -{% if CONFIG_DB__DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' %} -route-map FROM_BGP_PEER_V4_INT permit 2 - set originator-id {{ loopback0_ipv4 | ip }} -! -route-map FROM_BGP_PEER_V6_INT permit 1 - set ipv6 next-hop prefer-global -! -route-map FROM_BGP_PEER_V6_INT permit 2 - set originator-id {{ loopback0_ipv4 | ip }} -{% endif %} -! ! end of template: bgpd/templates/general/policies.conf.j2 ! diff --git a/dockers/docker-fpm-frr/frr/bgpd/templates/internal/instance.conf.j2 b/dockers/docker-fpm-frr/frr/bgpd/templates/internal/instance.conf.j2 new file mode 100644 index 000000000000..49497e4fcaaa --- /dev/null +++ b/dockers/docker-fpm-frr/frr/bgpd/templates/internal/instance.conf.j2 @@ -0,0 +1,34 @@ +! +! template: bgpd/templates/internal/instance.conf.j2 +! + neighbor {{ neighbor_addr }} remote-as {{ bgp_session['asn'] }} + neighbor {{ neighbor_addr }} description {{ bgp_session['name'] }} +! +{% if neighbor_addr | ipv4 %} + address-family ipv4 + neighbor {{ neighbor_addr }} peer-group INTERNAL_PEER_V4 +! +{% if CONFIG_DB__DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' %} + neighbor {{ neighbor_addr }} route-map FROM_BGP_INTERNAL_PEER_V4 in +{% endif %} +! +{% elif neighbor_addr | ipv6 %} + address-family ipv6 + neighbor {{ neighbor_addr }} peer-group INTERNAL_PEER_V6 +! +{% if CONFIG_DB__DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' %} + neighbor {{ neighbor_addr }} route-map FROM_BGP_INTERNAL_PEER_V6 in +{% endif %} +{% endif %} +! +{% if bgp_session.has_key('rrclient') and bgp_session['rrclient'] | int != 0 %} + neighbor {{ neighbor_addr }} route-reflector-client +{% endif %} +! + neighbor {{ neighbor_addr }} next-hop-self force +! + neighbor {{ neighbor_addr }} activate + exit-address-family +! +! end of template: bgpd/templates/internal/instance.conf.j2 +! diff --git a/dockers/docker-fpm-frr/frr/bgpd/templates/internal/peer-group.conf.j2 b/dockers/docker-fpm-frr/frr/bgpd/templates/internal/peer-group.conf.j2 new file mode 100644 index 000000000000..323c13447ed0 --- /dev/null +++ b/dockers/docker-fpm-frr/frr/bgpd/templates/internal/peer-group.conf.j2 @@ -0,0 +1,24 @@ +! +! template: bgpd/templates/internal/peer-group.conf.j2 +! + neighbor INTERNAL_PEER_V4 peer-group + neighbor INTERNAL_PEER_V6 peer-group + address-family ipv4 +{% if CONFIG_DB__DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' %} + neighbor INTERNAL_PEER_V4 route-reflector-client +{% endif %} + neighbor INTERNAL_PEER_V4 soft-reconfiguration inbound + neighbor INTERNAL_PEER_V4 route-map FROM_BGP_INTERNAL_PEER_V4 in + neighbor INTERNAL_PEER_V4 route-map TO_BGP_INTERNAL_PEER_V4 out + exit-address-family + address-family ipv6 +{% if CONFIG_DB__DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' %} + neighbor INTERNAL_PEER_V6 route-reflector-client +{% endif %} + neighbor INTERNAL_PEER_V6 soft-reconfiguration inbound + neighbor INTERNAL_PEER_V6 route-map FROM_BGP_INTERNAL_PEER_V6 in + neighbor INTERNAL_PEER_V6 route-map TO_BGP_INTERNAL_PEER_V6 out + exit-address-family +! +! end of template: bgpd/templates/internal/peer-group.conf.j2 +! diff --git a/dockers/docker-fpm-frr/frr/bgpd/templates/internal/policies.conf.j2 b/dockers/docker-fpm-frr/frr/bgpd/templates/internal/policies.conf.j2 new file mode 100644 index 000000000000..d4db3a97d5fc --- /dev/null +++ b/dockers/docker-fpm-frr/frr/bgpd/templates/internal/policies.conf.j2 @@ -0,0 +1,27 @@ +! +! template: bgpd/templates/internal/policies.conf.j2 +! +! +! +route-map FROM_BGP_INTERNAL_PEER_V4 permit 100 +! +route-map TO_BGP_INTERNAL_PEER_V4 permit 100 +! +! +route-map FROM_BGP_INTERNAL_PEER_V6 permit 1 + set ipv6 next-hop prefer-global +! +route-map FROM_BGP_INTERNAL_PEER_V6 permit 100 +! +route-map TO_BGP_INTERNAL_PEER_V6 permit 100 +! +{% if CONFIG_DB__DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' %} +route-map FROM_BGP_INTERNAL_PEER_V4 permit 2 + set originator-id {{ loopback0_ipv4 | ip }} +! +route-map FROM_BGP_INTERNAL_PEER_V6 permit 2 + set originator-id {{ loopback0_ipv4 | ip }} +{% endif %} +! +! end of template: bgpd/templates/internal/policies.conf.j2 +! diff --git a/files/image_config/constants/constants.yml b/files/image_config/constants/constants.yml index d3b70d4a27ec..ac4b521865c8 100644 --- a/files/image_config/constants/constants.yml +++ b/files/image_config/constants/constants.yml @@ -40,6 +40,9 @@ constants: - ipv4 PEER_V6: - ipv6 + internal: # peer_type + db_table: "BGP_INTERNAL_NEIGHBOR" + template_dir: "internal" monitors: # peer_type enabled: true db_table: "BGP_MONITORS" diff --git a/src/sonic-bgpcfgd/bgpcfgd/main.py b/src/sonic-bgpcfgd/bgpcfgd/main.py index 7bbb6fb768eb..9330330a1b3e 100644 --- a/src/sonic-bgpcfgd/bgpcfgd/main.py +++ b/src/sonic-bgpcfgd/bgpcfgd/main.py @@ -44,6 +44,7 @@ def do_work(): ZebraSetSrc(common_objs, "STATE_DB", swsscommon.STATE_INTERFACE_TABLE_NAME), # Peer Managers BGPPeerMgrBase(common_objs, "CONFIG_DB", swsscommon.CFG_BGP_NEIGHBOR_TABLE_NAME, "general", True), + BGPPeerMgrBase(common_objs, "CONFIG_DB", swsscommon.CFG_BGP_INTERNAL_NEIGHBOR_TABLE_NAME, "internal", False), BGPPeerMgrBase(common_objs, "CONFIG_DB", "BGP_MONITORS", "monitors", False), BGPPeerMgrBase(common_objs, "CONFIG_DB", "BGP_PEER_RANGE", "dynamic", False), # AllowList Managers @@ -81,4 +82,4 @@ def main(): try: sys.exit(rc) except SystemExit: - os._exit(rc) \ No newline at end of file + os._exit(rc) diff --git a/src/sonic-bgpcfgd/tests/data/general/instance.conf/param_ASIC_v6.json b/src/sonic-bgpcfgd/tests/data/general/instance.conf/param_ASIC_v6.json deleted file mode 100644 index 89a4117fdac2..000000000000 --- a/src/sonic-bgpcfgd/tests/data/general/instance.conf/param_ASIC_v6.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "CONFIG_DB__DEVICE_METADATA": { - "localhost": {} - }, - "neighbor_addr": "FC00::", - "bgp_session": { - "asn": "555", - "name": "_ASIC_" - }, - "constants": { - "deployment_id_asn_map": { - "5": "51111" - } - } -} diff --git a/src/sonic-bgpcfgd/tests/data/general/instance.conf/param_all_v4.json b/src/sonic-bgpcfgd/tests/data/general/instance.conf/param_all_v4.json index c2391674a56e..4afd00f38da1 100644 --- a/src/sonic-bgpcfgd/tests/data/general/instance.conf/param_all_v4.json +++ b/src/sonic-bgpcfgd/tests/data/general/instance.conf/param_all_v4.json @@ -1,9 +1,4 @@ { - "CONFIG_DB__DEVICE_METADATA": { - "localhost": { - "sub_role": "BackEnd" - } - }, "neighbor_addr": "10.10.10.10", "bgp_session": { "asn": "555", diff --git a/src/sonic-bgpcfgd/tests/data/general/instance.conf/param_all_v6.json b/src/sonic-bgpcfgd/tests/data/general/instance.conf/param_all_v6.json index d19139a75a88..115f5a32c941 100644 --- a/src/sonic-bgpcfgd/tests/data/general/instance.conf/param_all_v6.json +++ b/src/sonic-bgpcfgd/tests/data/general/instance.conf/param_all_v6.json @@ -1,9 +1,4 @@ { - "CONFIG_DB__DEVICE_METADATA": { - "localhost": { - "sub_role": "BackEnd" - } - }, "neighbor_addr": "fc::10", "bgp_session": { "asn": "555", diff --git a/src/sonic-bgpcfgd/tests/data/general/instance.conf/result_ASIC_v6.conf b/src/sonic-bgpcfgd/tests/data/general/instance.conf/result_ASIC_v6.conf deleted file mode 100644 index 64d14dcd4fa5..000000000000 --- a/src/sonic-bgpcfgd/tests/data/general/instance.conf/result_ASIC_v6.conf +++ /dev/null @@ -1,13 +0,0 @@ -! -! template: bgpd/templates/general/instance.conf.j2 -! - neighbor FC00:: remote-as 555 - neighbor FC00:: description _ASIC_ - address-family ipv6 - neighbor FC00:: peer-group PEER_V6_INT - neighbor FC00:: next-hop-self force - neighbor FC00:: activate - exit-address-family -! -! end of template: bgpd/templates/general/instance.conf.j2 -! diff --git a/src/sonic-bgpcfgd/tests/data/general/instance.conf/result_all_v4.conf b/src/sonic-bgpcfgd/tests/data/general/instance.conf/result_all_v4.conf index 2241bbf34146..a6102cdb87a2 100644 --- a/src/sonic-bgpcfgd/tests/data/general/instance.conf/result_all_v4.conf +++ b/src/sonic-bgpcfgd/tests/data/general/instance.conf/result_all_v4.conf @@ -7,7 +7,6 @@ neighbor 10.10.10.10 shutdown address-family ipv4 neighbor 10.10.10.10 peer-group PEER_V4 - neighbor 10.10.10.10 route-map FROM_BGP_PEER_V4_INT in neighbor 10.10.10.10 route-reflector-client neighbor 10.10.10.10 next-hop-self neighbor 10.10.10.10 activate diff --git a/src/sonic-bgpcfgd/tests/data/general/instance.conf/result_all_v6.conf b/src/sonic-bgpcfgd/tests/data/general/instance.conf/result_all_v6.conf index 7194b0916620..aa06657d91a8 100644 --- a/src/sonic-bgpcfgd/tests/data/general/instance.conf/result_all_v6.conf +++ b/src/sonic-bgpcfgd/tests/data/general/instance.conf/result_all_v6.conf @@ -7,7 +7,6 @@ neighbor fc::10 shutdown address-family ipv6 neighbor fc::10 peer-group PEER_V6 - neighbor fc::10 route-map FROM_BGP_PEER_V6_INT in neighbor fc::10 route-reflector-client neighbor fc::10 next-hop-self neighbor fc::10 activate diff --git a/src/sonic-bgpcfgd/tests/data/general/peer-group.conf/param_base.json b/src/sonic-bgpcfgd/tests/data/general/peer-group.conf/param_base.json index 443b5739201c..efee873fe726 100644 --- a/src/sonic-bgpcfgd/tests/data/general/peer-group.conf/param_base.json +++ b/src/sonic-bgpcfgd/tests/data/general/peer-group.conf/param_base.json @@ -1,8 +1,7 @@ { "CONFIG_DB__DEVICE_METADATA": { "localhost": { - "type": "LeafRouter", - "sub_role": "BackEnd" + "type": "LeafRouter" } }, "CONFIG_DB__BGP_BBR": { diff --git a/src/sonic-bgpcfgd/tests/data/general/peer-group.conf/result_all.conf b/src/sonic-bgpcfgd/tests/data/general/peer-group.conf/result_all.conf index 63211ded8796..afa7201b742a 100644 --- a/src/sonic-bgpcfgd/tests/data/general/peer-group.conf/result_all.conf +++ b/src/sonic-bgpcfgd/tests/data/general/peer-group.conf/result_all.conf @@ -2,28 +2,18 @@ ! template: bgpd/templates/general/peer-group.conf.j2 ! neighbor PEER_V4 peer-group - neighbor PEER_V4_INT peer-group neighbor PEER_V6 peer-group - neighbor PEER_V6_INT peer-group address-family ipv4 neighbor PEER_V4 allowas-in 1 - neighbor PEER_V4_INT allowas-in 1 neighbor PEER_V4 soft-reconfiguration inbound neighbor PEER_V4 route-map FROM_BGP_PEER_V4 in neighbor PEER_V4 route-map TO_BGP_PEER_V4 out - neighbor PEER_V4_INT soft-reconfiguration inbound - neighbor PEER_V4_INT route-map FROM_BGP_PEER_V4 in - neighbor PEER_V4_INT route-map TO_BGP_PEER_V4 out exit-address-family address-family ipv6 neighbor PEER_V6 allowas-in 1 - neighbor PEER_V6_INT allowas-in 1 neighbor PEER_V6 soft-reconfiguration inbound neighbor PEER_V6 route-map FROM_BGP_PEER_V6 in neighbor PEER_V6 route-map TO_BGP_PEER_V6 out - neighbor PEER_V6_INT soft-reconfiguration inbound - neighbor PEER_V6_INT route-map FROM_BGP_PEER_V6 in - neighbor PEER_V6_INT route-map TO_BGP_PEER_V6 out exit-address-family ! ! end of template: bgpd/templates/general/peer-group.conf.j2 diff --git a/src/sonic-bgpcfgd/tests/data/general/peer-group.conf/result_base.conf b/src/sonic-bgpcfgd/tests/data/general/peer-group.conf/result_base.conf index a681e7f08083..3bef9fe4fdc2 100644 --- a/src/sonic-bgpcfgd/tests/data/general/peer-group.conf/result_base.conf +++ b/src/sonic-bgpcfgd/tests/data/general/peer-group.conf/result_base.conf @@ -2,26 +2,16 @@ ! template: bgpd/templates/general/peer-group.conf.j2 ! neighbor PEER_V4 peer-group - neighbor PEER_V4_INT peer-group neighbor PEER_V6 peer-group - neighbor PEER_V6_INT peer-group address-family ipv4 - neighbor PEER_V4_INT route-reflector-client neighbor PEER_V4 soft-reconfiguration inbound neighbor PEER_V4 route-map FROM_BGP_PEER_V4 in neighbor PEER_V4 route-map TO_BGP_PEER_V4 out - neighbor PEER_V4_INT soft-reconfiguration inbound - neighbor PEER_V4_INT route-map FROM_BGP_PEER_V4 in - neighbor PEER_V4_INT route-map TO_BGP_PEER_V4 out exit-address-family address-family ipv6 - neighbor PEER_V6_INT route-reflector-client neighbor PEER_V6 soft-reconfiguration inbound neighbor PEER_V6 route-map FROM_BGP_PEER_V6 in neighbor PEER_V6 route-map TO_BGP_PEER_V6 out - neighbor PEER_V6_INT soft-reconfiguration inbound - neighbor PEER_V6_INT route-map FROM_BGP_PEER_V6 in - neighbor PEER_V6_INT route-map TO_BGP_PEER_V6 out exit-address-family ! ! end of template: bgpd/templates/general/peer-group.conf.j2 diff --git a/src/sonic-bgpcfgd/tests/data/general/policies.conf/param_all.json b/src/sonic-bgpcfgd/tests/data/general/policies.conf/param_all.json index 08f1eef63267..2ed388731ba0 100644 --- a/src/sonic-bgpcfgd/tests/data/general/policies.conf/param_all.json +++ b/src/sonic-bgpcfgd/tests/data/general/policies.conf/param_all.json @@ -1,9 +1,4 @@ { - "CONFIG_DB__DEVICE_METADATA": { - "localhost": { - "sub_role": "BackEnd" - } - }, "loopback0_ipv4": "10.10.10.10/32", "constants": { "bgp": { diff --git a/src/sonic-bgpcfgd/tests/data/general/policies.conf/param_base.json b/src/sonic-bgpcfgd/tests/data/general/policies.conf/param_base.json index 958c9b0fbd4b..b752581e3096 100644 --- a/src/sonic-bgpcfgd/tests/data/general/policies.conf/param_base.json +++ b/src/sonic-bgpcfgd/tests/data/general/policies.conf/param_base.json @@ -1,9 +1,4 @@ { - "CONFIG_DB__DEVICE_METADATA": { - "localhost": { - "sub_role": "NotBackEnd" - } - }, "loopback0_ipv4": "10.10.10.10/32", "constants": { "bgp": { diff --git a/src/sonic-bgpcfgd/tests/data/general/policies.conf/param_deny.json b/src/sonic-bgpcfgd/tests/data/general/policies.conf/param_deny.json index 669810960c92..47cb93082041 100644 --- a/src/sonic-bgpcfgd/tests/data/general/policies.conf/param_deny.json +++ b/src/sonic-bgpcfgd/tests/data/general/policies.conf/param_deny.json @@ -1,9 +1,4 @@ { - "CONFIG_DB__DEVICE_METADATA": { - "localhost": { - "sub_role": "BackEnd" - } - }, "loopback0_ipv4": "10.10.10.10/32", "constants": { "bgp": { diff --git a/src/sonic-bgpcfgd/tests/data/general/policies.conf/result_all.conf b/src/sonic-bgpcfgd/tests/data/general/policies.conf/result_all.conf index 9e6c32b17ead..79f6422961f7 100644 --- a/src/sonic-bgpcfgd/tests/data/general/policies.conf/result_all.conf +++ b/src/sonic-bgpcfgd/tests/data/general/policies.conf/result_all.conf @@ -26,14 +26,5 @@ route-map FROM_BGP_PEER_V6 permit 100 ! route-map TO_BGP_PEER_V6 permit 100 ! -route-map FROM_BGP_PEER_V4_INT permit 2 - set originator-id 10.10.10.10 -! -route-map FROM_BGP_PEER_V6_INT permit 1 - set ipv6 next-hop prefer-global -! -route-map FROM_BGP_PEER_V6_INT permit 2 - set originator-id 10.10.10.10 -! ! end of template: bgpd/templates/general/policies.conf.j2 ! diff --git a/src/sonic-bgpcfgd/tests/data/general/policies.conf/result_deny.conf b/src/sonic-bgpcfgd/tests/data/general/policies.conf/result_deny.conf index 6e0389fc1886..f1427175e063 100644 --- a/src/sonic-bgpcfgd/tests/data/general/policies.conf/result_deny.conf +++ b/src/sonic-bgpcfgd/tests/data/general/policies.conf/result_deny.conf @@ -26,14 +26,5 @@ route-map FROM_BGP_PEER_V6 permit 100 ! route-map TO_BGP_PEER_V6 permit 100 ! -route-map FROM_BGP_PEER_V4_INT permit 2 - set originator-id 10.10.10.10 -! -route-map FROM_BGP_PEER_V6_INT permit 1 - set ipv6 next-hop prefer-global -! -route-map FROM_BGP_PEER_V6_INT permit 2 - set originator-id 10.10.10.10 -! ! end of template: bgpd/templates/general/policies.conf.j2 ! diff --git a/src/sonic-bgpcfgd/tests/data/internal/instance.conf/param_back_v4.json b/src/sonic-bgpcfgd/tests/data/internal/instance.conf/param_back_v4.json new file mode 100644 index 000000000000..c2391674a56e --- /dev/null +++ b/src/sonic-bgpcfgd/tests/data/internal/instance.conf/param_back_v4.json @@ -0,0 +1,23 @@ +{ + "CONFIG_DB__DEVICE_METADATA": { + "localhost": { + "sub_role": "BackEnd" + } + }, + "neighbor_addr": "10.10.10.10", + "bgp_session": { + "asn": "555", + "name": "remote_peer", + "keepalive": "5", + "holdtime": "30", + "admin_status": "down", + "ASIC": "something", + "rrclient": "1", + "nhopself": "1" + }, + "constants": { + "deployment_id_asn_map": { + "5": "51111" + } + } +} diff --git a/src/sonic-bgpcfgd/tests/data/internal/instance.conf/param_back_v6.json b/src/sonic-bgpcfgd/tests/data/internal/instance.conf/param_back_v6.json new file mode 100644 index 000000000000..d19139a75a88 --- /dev/null +++ b/src/sonic-bgpcfgd/tests/data/internal/instance.conf/param_back_v6.json @@ -0,0 +1,23 @@ +{ + "CONFIG_DB__DEVICE_METADATA": { + "localhost": { + "sub_role": "BackEnd" + } + }, + "neighbor_addr": "fc::10", + "bgp_session": { + "asn": "555", + "name": "remote_peer", + "keepalive": "5", + "holdtime": "30", + "admin_status": "down", + "ASIC": "something", + "rrclient": "1", + "nhopself": "1" + }, + "constants": { + "deployment_id_asn_map": { + "5": "51111" + } + } +} diff --git a/src/sonic-bgpcfgd/tests/data/general/instance.conf/param_ASIC_v4.json b/src/sonic-bgpcfgd/tests/data/internal/instance.conf/param_front_v4.json similarity index 51% rename from src/sonic-bgpcfgd/tests/data/general/instance.conf/param_ASIC_v4.json rename to src/sonic-bgpcfgd/tests/data/internal/instance.conf/param_front_v4.json index 1691732b39b4..6f1b5a735355 100644 --- a/src/sonic-bgpcfgd/tests/data/general/instance.conf/param_ASIC_v4.json +++ b/src/sonic-bgpcfgd/tests/data/internal/instance.conf/param_front_v4.json @@ -1,11 +1,17 @@ { "CONFIG_DB__DEVICE_METADATA": { - "localhost": {} + "localhost": { + "sub_role": "FrontEnd" + } }, "neighbor_addr": "10.10.10.10", "bgp_session": { "asn": "555", - "name": "_ASIC_" + "name": "remote_peer", + "keepalive": "5", + "holdtime": "30", + "admin_status": "down", + "ASIC": "something" }, "constants": { "deployment_id_asn_map": { diff --git a/src/sonic-bgpcfgd/tests/data/internal/instance.conf/param_front_v6.json b/src/sonic-bgpcfgd/tests/data/internal/instance.conf/param_front_v6.json new file mode 100644 index 000000000000..becb1f00fbfe --- /dev/null +++ b/src/sonic-bgpcfgd/tests/data/internal/instance.conf/param_front_v6.json @@ -0,0 +1,21 @@ +{ + "CONFIG_DB__DEVICE_METADATA": { + "localhost": { + "sub_role": "FrontEnd" + } + }, + "neighbor_addr": "fc::10", + "bgp_session": { + "asn": "555", + "name": "remote_peer", + "keepalive": "5", + "holdtime": "30", + "admin_status": "down", + "ASIC": "something" + }, + "constants": { + "deployment_id_asn_map": { + "5": "51111" + } + } +} diff --git a/src/sonic-bgpcfgd/tests/data/internal/instance.conf/result_back_v4.conf b/src/sonic-bgpcfgd/tests/data/internal/instance.conf/result_back_v4.conf new file mode 100644 index 000000000000..4664395bbf27 --- /dev/null +++ b/src/sonic-bgpcfgd/tests/data/internal/instance.conf/result_back_v4.conf @@ -0,0 +1,17 @@ +! +! template: bgpd/templates/general/instance.conf.j2 +! + neighbor 10.10.10.10 remote-as 555 + neighbor 10.10.10.10 description remote_peer + neighbor 10.10.10.10 timers 5 30 + neighbor 10.10.10.10 shutdown + address-family ipv4 + neighbor 10.10.10.10 peer-group INTERNAL_PEER_V4 + neighbor 10.10.10.10 route-map FROM_BGP_INTERNAL_PEER_V4 in + neighbor 10.10.10.10 route-reflector-client + neighbor 10.10.10.10 next-hop-self force + neighbor 10.10.10.10 activate + exit-address-family +! +! end of template: bgpd/templates/general/instance.conf.j2 +! diff --git a/src/sonic-bgpcfgd/tests/data/internal/instance.conf/result_back_v6.conf b/src/sonic-bgpcfgd/tests/data/internal/instance.conf/result_back_v6.conf new file mode 100644 index 000000000000..08cffe632815 --- /dev/null +++ b/src/sonic-bgpcfgd/tests/data/internal/instance.conf/result_back_v6.conf @@ -0,0 +1,17 @@ +! +! template: bgpd/templates/general/instance.conf.j2 +! + neighbor fc::10 remote-as 555 + neighbor fc::10 description remote_peer + neighbor fc::10 timers 5 30 + neighbor fc::10 shutdown + address-family ipv6 + neighbor fc::10 peer-group INTERNAL_PEER_V6 + neighbor fc::10 route-map FROM_BGP_INTERNAL_PEER_V6 in + neighbor fc::10 route-reflector-client + neighbor fc::10 next-hop-self force + neighbor fc::10 activate + exit-address-family +! +! end of template: bgpd/templates/general/instance.conf.j2 +! diff --git a/src/sonic-bgpcfgd/tests/data/general/instance.conf/result_ASIC_v4.conf b/src/sonic-bgpcfgd/tests/data/internal/instance.conf/result_front_v4.conf similarity index 62% rename from src/sonic-bgpcfgd/tests/data/general/instance.conf/result_ASIC_v4.conf rename to src/sonic-bgpcfgd/tests/data/internal/instance.conf/result_front_v4.conf index 1e89f822457a..aba5cfac0b1f 100644 --- a/src/sonic-bgpcfgd/tests/data/general/instance.conf/result_ASIC_v4.conf +++ b/src/sonic-bgpcfgd/tests/data/internal/instance.conf/result_front_v4.conf @@ -2,9 +2,11 @@ ! template: bgpd/templates/general/instance.conf.j2 ! neighbor 10.10.10.10 remote-as 555 - neighbor 10.10.10.10 description _ASIC_ + neighbor 10.10.10.10 description remote_peer + neighbor 10.10.10.10 timers 5 30 + neighbor 10.10.10.10 shutdown address-family ipv4 - neighbor 10.10.10.10 peer-group PEER_V4_INT + neighbor 10.10.10.10 peer-group INTERNAL_PEER_V4 neighbor 10.10.10.10 next-hop-self force neighbor 10.10.10.10 activate exit-address-family diff --git a/src/sonic-bgpcfgd/tests/data/internal/instance.conf/result_front_v6.conf b/src/sonic-bgpcfgd/tests/data/internal/instance.conf/result_front_v6.conf new file mode 100644 index 000000000000..362900d57403 --- /dev/null +++ b/src/sonic-bgpcfgd/tests/data/internal/instance.conf/result_front_v6.conf @@ -0,0 +1,15 @@ +! +! template: bgpd/templates/general/instance.conf.j2 +! + neighbor fc::10 remote-as 555 + neighbor fc::10 description remote_peer + neighbor fc::10 timers 5 30 + neighbor fc::10 shutdown + address-family ipv6 + neighbor fc::10 peer-group INTERNAL_PEER_V6 + neighbor fc::10 next-hop-self force + neighbor fc::10 activate + exit-address-family +! +! end of template: bgpd/templates/general/instance.conf.j2 +! diff --git a/src/sonic-bgpcfgd/tests/data/internal/peer-group.conf/param_back.json b/src/sonic-bgpcfgd/tests/data/internal/peer-group.conf/param_back.json new file mode 100644 index 000000000000..c3269a7da0e5 --- /dev/null +++ b/src/sonic-bgpcfgd/tests/data/internal/peer-group.conf/param_back.json @@ -0,0 +1,8 @@ +{ + "CONFIG_DB__DEVICE_METADATA": { + "localhost": { + "type": "LeafRouter", + "sub_role": "BackEnd" + } + } +} diff --git a/src/sonic-bgpcfgd/tests/data/internal/peer-group.conf/param_front.json b/src/sonic-bgpcfgd/tests/data/internal/peer-group.conf/param_front.json new file mode 100644 index 000000000000..2fbedc92c963 --- /dev/null +++ b/src/sonic-bgpcfgd/tests/data/internal/peer-group.conf/param_front.json @@ -0,0 +1,8 @@ +{ + "CONFIG_DB__DEVICE_METADATA": { + "localhost": { + "type": "LeafRouter", + "sub_role": "FrontEnd" + } + } +} diff --git a/src/sonic-bgpcfgd/tests/data/internal/peer-group.conf/result_back.conf b/src/sonic-bgpcfgd/tests/data/internal/peer-group.conf/result_back.conf new file mode 100644 index 000000000000..829cbba8b13f --- /dev/null +++ b/src/sonic-bgpcfgd/tests/data/internal/peer-group.conf/result_back.conf @@ -0,0 +1,20 @@ +! +! template: bgpd/templates/general/peer-group.conf.j2 +! + neighbor INTERNAL_PEER_V4 peer-group + neighbor INTERNAL_PEER_V6 peer-group + address-family ipv4 + neighbor INTERNAL_PEER_V4 route-reflector-client + neighbor INTERNAL_PEER_V4 soft-reconfiguration inbound + neighbor INTERNAL_PEER_V4 route-map FROM_BGP_INTERNAL_PEER_V4 in + neighbor INTERNAL_PEER_V4 route-map TO_BGP_INTERNAL_PEER_V4 out + exit-address-family + address-family ipv6 + neighbor INTERNAL_PEER_V6 route-reflector-client + neighbor INTERNAL_PEER_V6 soft-reconfiguration inbound + neighbor INTERNAL_PEER_V6 route-map FROM_BGP_INTERNAL_PEER_V6 in + neighbor INTERNAL_PEER_V6 route-map TO_BGP_INTERNAL_PEER_V6 out + exit-address-family +! +! end of template: bgpd/templates/general/peer-group.conf.j2 +! diff --git a/src/sonic-bgpcfgd/tests/data/internal/peer-group.conf/result_front.conf b/src/sonic-bgpcfgd/tests/data/internal/peer-group.conf/result_front.conf new file mode 100644 index 000000000000..f23e009483cc --- /dev/null +++ b/src/sonic-bgpcfgd/tests/data/internal/peer-group.conf/result_front.conf @@ -0,0 +1,18 @@ +! +! template: bgpd/templates/general/peer-group.conf.j2 +! + neighbor INTERNAL_PEER_V4 peer-group + neighbor INTERNAL_PEER_V6 peer-group + address-family ipv4 + neighbor INTERNAL_PEER_V4 soft-reconfiguration inbound + neighbor INTERNAL_PEER_V4 route-map FROM_BGP_INTERNAL_PEER_V4 in + neighbor INTERNAL_PEER_V4 route-map TO_BGP_INTERNAL_PEER_V4 out + exit-address-family + address-family ipv6 + neighbor INTERNAL_PEER_V6 soft-reconfiguration inbound + neighbor INTERNAL_PEER_V6 route-map FROM_BGP_INTERNAL_PEER_V6 in + neighbor INTERNAL_PEER_V6 route-map TO_BGP_INTERNAL_PEER_V6 out + exit-address-family +! +! end of template: bgpd/templates/general/peer-group.conf.j2 +! diff --git a/src/sonic-bgpcfgd/tests/data/internal/policies.conf/param_back.json b/src/sonic-bgpcfgd/tests/data/internal/policies.conf/param_back.json new file mode 100644 index 000000000000..148456fe960f --- /dev/null +++ b/src/sonic-bgpcfgd/tests/data/internal/policies.conf/param_back.json @@ -0,0 +1,8 @@ +{ + "CONFIG_DB__DEVICE_METADATA": { + "localhost": { + "sub_role": "BackEnd" + } + }, + "loopback0_ipv4": "10.10.10.10/32" +} \ No newline at end of file diff --git a/src/sonic-bgpcfgd/tests/data/internal/policies.conf/param_front.json b/src/sonic-bgpcfgd/tests/data/internal/policies.conf/param_front.json new file mode 100644 index 000000000000..68c27766d257 --- /dev/null +++ b/src/sonic-bgpcfgd/tests/data/internal/policies.conf/param_front.json @@ -0,0 +1,8 @@ +{ + "CONFIG_DB__DEVICE_METADATA": { + "localhost": { + "sub_role": "FrontkEnd" + } + }, + "loopback0_ipv4": "10.10.10.10/32" +} diff --git a/src/sonic-bgpcfgd/tests/data/internal/policies.conf/result_back.conf b/src/sonic-bgpcfgd/tests/data/internal/policies.conf/result_back.conf new file mode 100644 index 000000000000..def088028d2d --- /dev/null +++ b/src/sonic-bgpcfgd/tests/data/internal/policies.conf/result_back.conf @@ -0,0 +1,22 @@ +! +! template: bgpd/templates/general/policies.conf.j2 +! +route-map FROM_BGP_INTERNAL_PEER_V4 permit 100 +! +route-map TO_BGP_INTERNAL_PEER_V4 permit 100 +! +route-map FROM_BGP_INTERNAL_PEER_V6 permit 1 + set ipv6 next-hop prefer-global +! +route-map FROM_BGP_INTERNAL_PEER_V6 permit 100 +! +route-map TO_BGP_INTERNAL_PEER_V6 permit 100 +! +route-map FROM_BGP_INTERNAL_PEER_V4 permit 2 + set originator-id 10.10.10.10 +! +route-map FROM_BGP_INTERNAL_PEER_V6 permit 2 + set originator-id 10.10.10.10 +! +! end of template: bgpd/templates/general/policies.conf.j2 +! diff --git a/src/sonic-bgpcfgd/tests/data/internal/policies.conf/result_front.conf b/src/sonic-bgpcfgd/tests/data/internal/policies.conf/result_front.conf new file mode 100644 index 000000000000..9cc40fd8b719 --- /dev/null +++ b/src/sonic-bgpcfgd/tests/data/internal/policies.conf/result_front.conf @@ -0,0 +1,16 @@ +! +! template: bgpd/templates/general/policies.conf.j2 +! +route-map FROM_BGP_INTERNAL_PEER_V4 permit 100 +! +route-map TO_BGP_INTERNAL_PEER_V4 permit 100 +! +route-map FROM_BGP_INTERNAL_PEER_V6 permit 1 + set ipv6 next-hop prefer-global +! +route-map FROM_BGP_INTERNAL_PEER_V6 permit 100 +! +route-map TO_BGP_INTERNAL_PEER_V6 permit 100 +! +! end of template: bgpd/templates/general/policies.conf.j2 +! diff --git a/src/sonic-config-engine/minigraph.py b/src/sonic-config-engine/minigraph.py index 3d3bf72463f0..6b241866044c 100644 --- a/src/sonic-config-engine/minigraph.py +++ b/src/sonic-config-engine/minigraph.py @@ -484,8 +484,9 @@ def parse_host_loopback(dpg, hname): lo_intfs = parse_loopback_intf(child) return lo_intfs -def parse_cpg(cpg, hname): +def parse_cpg(cpg, hname, local_devices=[]): bgp_sessions = {} + bgp_internal_sessions = {} myasn = None bgp_peers_with_range = {} for child in cpg: @@ -506,24 +507,47 @@ def parse_cpg(cpg, hname): else: keepalive = 60 nhopself = 1 if session.find(str(QName(ns, "NextHopSelf"))) is not None else 0 + if end_router.lower() == hname.lower(): - bgp_sessions[start_peer.lower()] = { - 'name': start_router, - 'local_addr': end_peer.lower(), - 'rrclient': rrclient, - 'holdtime': holdtime, - 'keepalive': keepalive, - 'nhopself': nhopself - } + if end_router.lower() in local_devices and start_router.lower() in local_devices: + bgp_internal_sessions[start_peer.lower()] = { + 'name': start_router, + 'local_addr': end_peer.lower(), + 'rrclient': rrclient, + 'holdtime': holdtime, + 'keepalive': keepalive, + 'nhopself': nhopself, + 'admin_status': 'up' + } + else: + bgp_sessions[start_peer.lower()] = { + 'name': start_router, + 'local_addr': end_peer.lower(), + 'rrclient': rrclient, + 'holdtime': holdtime, + 'keepalive': keepalive, + 'nhopself': nhopself + } elif start_router.lower() == hname.lower(): - bgp_sessions[end_peer.lower()] = { - 'name': end_router, - 'local_addr': start_peer.lower(), - 'rrclient': rrclient, - 'holdtime': holdtime, - 'keepalive': keepalive, - 'nhopself': nhopself - } + if end_router.lower() in local_devices and start_router.lower() in local_devices: + bgp_internal_sessions[end_peer.lower()] = { + 'name': end_router, + 'local_addr': start_peer.lower(), + 'rrclient': rrclient, + 'holdtime': holdtime, + 'keepalive': keepalive, + 'nhopself': nhopself, + 'admin_status': 'up' + } + else: + bgp_sessions[end_peer.lower()] = { + 'name': end_router, + 'local_addr': start_peer.lower(), + 'rrclient': rrclient, + 'holdtime': holdtime, + 'keepalive': keepalive, + 'nhopself': nhopself + } elif child.tag == str(QName(ns, "Routers")): for router in child.findall(str(QName(ns1, "BGPRouterDeclaration"))): asn = router.find(str(QName(ns1, "ASN"))).text @@ -550,11 +574,16 @@ def parse_cpg(cpg, hname): bgp_session = bgp_sessions[peer] if hostname.lower() == bgp_session['name'].lower(): bgp_session['asn'] = asn + for peer in bgp_internal_sessions: + bgp_internal_session = bgp_internal_sessions[peer] + if hostname.lower() == bgp_internal_session['name'].lower(): + bgp_internal_session['asn'] = asn bgp_monitors = { key: bgp_sessions[key] for key in bgp_sessions if 'asn' in bgp_sessions[key] and bgp_sessions[key]['name'] == 'BGPMonitor' } bgp_sessions = { key: bgp_sessions[key] for key in bgp_sessions if 'asn' in bgp_sessions[key] and int(bgp_sessions[key]['asn']) != 0 } + bgp_internal_sessions = { key: bgp_internal_sessions[key] for key in bgp_internal_sessions if 'asn' in bgp_internal_sessions[key] and int(bgp_internal_sessions[key]['asn']) != 0 } - return bgp_sessions, myasn, bgp_peers_with_range, bgp_monitors + return bgp_sessions, bgp_internal_sessions, myasn, bgp_peers_with_range, bgp_monitors def parse_meta(meta, hname): @@ -865,6 +894,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw hostname = None linkmetas = {} host_lo_intfs = None + local_devices = [] # hostname is the asic_name, get the asic_id from the asic_name if asic_name is not None: @@ -887,12 +917,15 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw port_alias_map.update(alias_map) port_alias_asic_map.update(alias_asic_map) + # Get the local device node from DeviceMetadata + local_devices = parse_asic_meta_get_devices(root) + for child in root: if asic_name is None: if child.tag == str(QName(ns, "DpgDec")): (intfs, lo_intfs, mvrf, mgmt_intf, vlans, vlan_members, pcs, pc_members, acls, vni) = parse_dpg(child, hostname) elif child.tag == str(QName(ns, "CpgDec")): - (bgp_sessions, bgp_asn, bgp_peers_with_range, bgp_monitors) = parse_cpg(child, hostname) + (bgp_sessions, bgp_internal_sessions, bgp_asn, bgp_peers_with_range, bgp_monitors) = parse_cpg(child, hostname) elif child.tag == str(QName(ns, "PngDec")): (neighbors, devices, console_dev, console_port, mgmt_dev, mgmt_port, port_speed_png, console_ports, mux_cable_ports) = parse_png(child, hostname) elif child.tag == str(QName(ns, "UngDec")): @@ -908,8 +941,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw (intfs, lo_intfs, mvrf, mgmt_intf, vlans, vlan_members, pcs, pc_members, acls, vni) = parse_dpg(child, asic_name) host_lo_intfs = parse_host_loopback(child, hostname) elif child.tag == str(QName(ns, "CpgDec")): - (bgp_sessions, bgp_asn, bgp_peers_with_range, bgp_monitors) = parse_cpg(child, asic_name) - enable_internal_bgp_session(bgp_sessions, filename, asic_name) + (bgp_sessions, bgp_internal_sessions, bgp_asn, bgp_peers_with_range, bgp_monitors) = parse_cpg(child, asic_name, local_devices) elif child.tag == str(QName(ns, "PngDec")): (neighbors, devices, port_speed_png) = parse_asic_png(child, asic_name, hostname) elif child.tag == str(QName(ns, "MetadataDeclaration")): @@ -951,6 +983,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw results['BGP_NEIGHBOR'] = bgp_sessions results['BGP_MONITORS'] = bgp_monitors results['BGP_PEER_RANGE'] = bgp_peers_with_range + results['BGP_INTERNAL_NEIGHBOR'] = bgp_internal_sessions if mgmt_routes: # TODO: differentiate v4 and v6 next(iter(mgmt_intf.values()))['forced_mgmt_routes'] = mgmt_routes @@ -1229,6 +1262,18 @@ def parse_asic_sub_role(filename, asic_name): sub_role = parse_asic_meta(child, asic_name) return sub_role +def parse_asic_meta_get_devices(root): + local_devices = [] + + for child in root: + if child.tag == str(QName(ns, "MetadataDeclaration")): + device_metas = child.find(str(QName(ns, "Devices"))) + for device in device_metas.findall(str(QName(ns1, "DeviceMetadata"))): + name = device.find(str(QName(ns1, "Name"))).text.lower() + local_devices.append(name) + + return local_devices + port_alias_map = {} port_alias_asic_map = {} diff --git a/src/sonic-config-engine/tests/test_multinpu_cfggen.py b/src/sonic-config-engine/tests/test_multinpu_cfggen.py index 1802d8d30210..7ed64775111f 100644 --- a/src/sonic-config-engine/tests/test_multinpu_cfggen.py +++ b/src/sonic-config-engine/tests/test_multinpu_cfggen.py @@ -226,16 +226,21 @@ def test_frontend_bgp_neighbor(self): output = json.loads(self.run_script(argument)) self.assertDictEqual(output, \ {'10.0.0.1': {'rrclient': 0, 'name': '01T2', 'local_addr': '10.0.0.0', 'nhopself': 0, 'holdtime': '10', 'asn': '65200', 'keepalive': '3'}, - '10.1.0.0': {'rrclient': 0, 'name': 'ASIC2', 'local_addr': '10.1.0.1', 'nhopself': 0, 'holdtime': '0', 'asn': '65100', 'keepalive': '0', 'admin_status': 'up'}, - 'fc00::2': {'rrclient': 0, 'name': '01T2', 'local_addr': 'fc00::1', 'nhopself': 0, 'holdtime': '10', 'asn': '65200', 'keepalive': '3'}, - '10.1.0.2': {'rrclient': 0, 'name': 'ASIC3', 'local_addr': '10.1.0.3', 'nhopself': 0, 'holdtime': '0', 'asn': '65100', 'keepalive': '0', 'admin_status': 'up'}}) + 'fc00::2': {'rrclient': 0, 'name': '01T2', 'local_addr': 'fc00::1', 'nhopself': 0, 'holdtime': '10', 'asn': '65200', 'keepalive': '3'}}) + + def test_frontend_asic_bgp_neighbor(self): + argument = "-m {} -p {} -n asic0 --var-json \"BGP_INTERNAL_NEIGHBOR\"".format(self.sample_graph, self.port_config[3]) + output = json.loads(self.run_script(argument)) + self.assertDictEqual(output, \ + {'10.1.0.0': {'rrclient': 0, 'name': 'ASIC2', 'local_addr': '10.1.0.1', 'nhopself': 0, 'admin_status': 'up', 'holdtime': '0', 'asn': '65100', 'keepalive': '0'}, + '10.1.0.2': {'rrclient': 0, 'name': 'ASIC3', 'local_addr': '10.1.0.3', 'nhopself': 0, 'admin_status': 'up', 'holdtime': '0', 'asn': '65100', 'keepalive': '0'}}) def test_backend_asic_bgp_neighbor(self): - argument = "-m {} -p {} -n asic3 --var-json \"BGP_NEIGHBOR\"".format(self.sample_graph, self.port_config[3]) + argument = "-m {} -p {} -n asic3 --var-json \"BGP_INTERNAL_NEIGHBOR\"".format(self.sample_graph, self.port_config[3]) output = json.loads(self.run_script(argument)) self.assertDictEqual(output, \ - {'10.1.0.7': {'rrclient': 0, 'name': 'ASIC1', 'local_addr': '10.1.0.6', 'nhopself': 0, 'holdtime': '0', 'asn': '65100', 'keepalive': '0', 'admin_status': 'up'}, - '10.1.0.3': {'rrclient': 0, 'name': 'ASIC0', 'local_addr': '10.1.0.2', 'nhopself': 0, 'holdtime': '0', 'asn': '65100', 'keepalive': '0', 'admin_status': 'up'}}) + {'10.1.0.7': {'rrclient': 0, 'name': 'ASIC1', 'local_addr': '10.1.0.6', 'nhopself': 0, 'admin_status': 'up', 'holdtime': '0', 'asn': '65100', 'keepalive': '0'}, + '10.1.0.3': {'rrclient': 0, 'name': 'ASIC0', 'local_addr': '10.1.0.2', 'nhopself': 0, 'admin_status': 'up', 'holdtime': '0', 'asn': '65100', 'keepalive': '0'}}) def test_device_asic_metadata(self): argument = "-m {} --var-json DEVICE_METADATA".format(self.sample_graph)