From 71da2ba7027685e8e922686d7ab49788fa3a394b Mon Sep 17 00:00:00 2001 From: Azarack Date: Thu, 13 Jul 2023 18:56:15 +0000 Subject: [PATCH 1/5] adding test and test plan --- docs/testplan/BGP-4-Byte_AS_Translation.md | 56 ++++ tests/bgp/templates/bgp_id.template | 4 + tests/bgp/test_bgp_4-byte_as_trans.py | 284 +++++++++++++++++++++ 3 files changed, 344 insertions(+) create mode 100644 docs/testplan/BGP-4-Byte_AS_Translation.md create mode 100644 tests/bgp/templates/bgp_id.template create mode 100644 tests/bgp/test_bgp_4-byte_as_trans.py diff --git a/docs/testplan/BGP-4-Byte_AS_Translation.md b/docs/testplan/BGP-4-Byte_AS_Translation.md new file mode 100644 index 0000000000..4ff39a9308 --- /dev/null +++ b/docs/testplan/BGP-4-Byte_AS_Translation.md @@ -0,0 +1,56 @@ +- [Overview](#overview) + - [Scope](#scope) + - [Testbed](#testbed) +- [Setup configuration](#setup-configuration) +- [Test cases](#test-cases) + +# Test name + +BGP Session Flaps + +## Overview + +The goal of this test is to verify that the CPU and memory do not spike during cycles of BGP sessions flapping. + +### Scope + +The test is targeting a running SONIC system with fully functioning configuration. The purpose of the test is to test for 4-Byte AS translation. + +### Related DUT CLI commands + +| Command | Comment | +| ------- | ------- | +|Configuration commands| +| N/A | | +|Show commands| +| show ip bgp summary | Dispaly current memory statistics, can be done with ipv6 too | + +### Related DUT configuration files + +N/A + +### Related SAI APIs + +N/A + +## Test structure +### Setup configuration + +This test requires BGP neighbors to be configured and established. + +### Configuration scripts + +N/A + +## Test cases +### Test case #1 - 4-byte AS Translation + +#### Test objective + +Have a single neighbor configured with 4-byte ASN. +Step 1: Configure DUT and neighbor with 4-Byte ASN +Step 2: Verify 4-byte BGP session between DUT and neighbor is established +Step 3: Verify BGP is established for 4-byte neighbor and down for 2-byte neighbors +Step 3: Configure DUT to use 2-byte local-ASN for 2-byte neighbors +Step 4: Verify BGP is now established for 4-byte neighbor AND 2-byte neighbors +Step 5: Verify 2-byte neighbors receive routes from upstream 4-byte routers diff --git a/tests/bgp/templates/bgp_id.template b/tests/bgp/templates/bgp_id.template new file mode 100644 index 0000000000..09228b8096 --- /dev/null +++ b/tests/bgp/templates/bgp_id.template @@ -0,0 +1,4 @@ +Value router_id (\d+.\d+.\d+.\d+) + +Start + ^BGP router identifier\s+${router_id} diff --git a/tests/bgp/test_bgp_4-byte_as_trans.py b/tests/bgp/test_bgp_4-byte_as_trans.py new file mode 100644 index 0000000000..a355073d9c --- /dev/null +++ b/tests/bgp/test_bgp_4-byte_as_trans.py @@ -0,0 +1,284 @@ +''' + +The test case will verify that the DUT supports 4-byte AS Number translation. + +Step 1: Configure DUT and neighbor with 4-Byte ASN +Step 2: Verify 4-byte BGP session between DUT and neighbor is established +Step 3: Verify BGP is established for 4-byte neighbor and down for 2-byte neighbors +Step 3: Configure DUT to use 2-byte local-ASN for 2-byte neighbors +Step 4: Verify BGP is now established for 4-byte neighbor AND 2-byte neighbors +Step 5: Verify 2-byte neighbors receive routes from upstream 4-byte routers + + +''' +import logging + +import pytest +import time +import textfsm +from tests.common.config_reload import config_reload + +logger = logging.getLogger(__name__) +dut_4byte_asn = 400003 +neighbor_4byte_asn = 400001 +bgp_sleep = 60 +bgp_id_textfsm = "./bgp/templates/bgp_id.template" + +pytestmark = [ + pytest.mark.topology('t2') +] + + +@pytest.fixture(scope='module') +def setup(tbinfo, nbrhosts, duthosts, rand_one_dut_hostname, enum_rand_one_frontend_asic_index, request): + # verify neighbors are type sonic + if request.config.getoption("neighbor_type") != "sonic": + pytest.skip("Neighbor type must be sonic") + duthost = duthosts[rand_one_dut_hostname] + asic_index = enum_rand_one_frontend_asic_index + namespace = duthost.get_namespace_from_asic_id(asic_index) + dut_asn = tbinfo['topo']['properties']['configuration_properties']['common']['dut_asn'] + tor1 = duthost.shell("show lldp table")['stdout'].split("\n")[3].split()[1] + tor2 = duthost.shell("show lldp table")['stdout'].split("\n")[5].split()[1] + + tor_neighbors = dict() + skip_hosts = duthost.get_asic_namespace_list() + bgp_facts = duthost.bgp_facts(instance_id=asic_index)['ansible_facts'] + neigh_asn = dict() + + # verify sessions are established and gather neighbor information + for k, v in bgp_facts['bgp_neighbors'].items(): + if v['description'].lower() not in skip_hosts: + if v['description'] == tor1: + if v['ip_version'] == 4: + neigh_ip_v4 = k + peer_group_v4 = v['peer group'] + elif v['ip_version'] == 6: + neigh_ip_v6 = k + peer_group_v6 = v['peer group'] + if v['description'] == tor2: + if v['ip_version'] == 4: + neigh2_ip_v4 = k + elif v['ip_version'] == 6: + neigh2_ip_v6 = k + assert v['state'] == 'established' + neigh_asn[v['description']] = v['remote AS'] + tor_neighbors[v['description']] = nbrhosts[v['description']]["host"] + + dut_ip_v4 = tbinfo['topo']['properties']['configuration'][tor1]['bgp']['peers'][dut_asn][0] + dut_ip_v6 = tbinfo['topo']['properties']['configuration'][tor1]['bgp']['peers'][dut_asn][1] + + dut_ip_bgp_sum = duthost.shell('show ip bgp summary')['stdout'] + neigh_ip_bgp_sum = nbrhosts[tor1]["host"].shell('show ip bgp summary')['stdout'] + neigh2_ip_bgp_sum = nbrhosts[tor1]["host"].shell('show ip bgp summary')['stdout'] + with open(bgp_id_textfsm) as template: + fsm = textfsm.TextFSM(template) + dut_bgp_id = fsm.ParseText(dut_ip_bgp_sum)[0][0] + neigh_bgp_id = fsm.ParseText(neigh_ip_bgp_sum)[1][0] + neigh2_bgp_id = fsm.ParseText(neigh2_ip_bgp_sum)[1][0] + + dut_ipv4_network = duthost.shell("show run bgp | grep 'ip prefix-list'")['stdout'].split()[6] + dut_ipv6_network = duthost.shell("show run bgp | grep 'ipv6 prefix-list'")['stdout'].split()[6] + neigh_ipv4_network = nbrhosts[tor1]["host"].shell("show run bgp | grep 'ip prefix-list'")['stdout'].split()[6] + neigh_ipv6_network = nbrhosts[tor1]["host"].shell("show run bgp | grep 'ipv6 prefix-list'")['stdout'].split()[6] + + setup_info = { + 'duthost': duthost, + 'neighhost': tor_neighbors[tor1], + 'neigh2host': tor_neighbors[tor2], + 'tor1': tor1, + 'tor2': tor2, + 'dut_asn': dut_asn, + 'neigh_asn': neigh_asn[tor1], + 'neigh2_asn': neigh_asn[tor2], + 'asn_dict': neigh_asn, + 'neighbors': tor_neighbors, + 'namespace': namespace, + 'dut_ip_v4': dut_ip_v4, + 'dut_ip_v6': dut_ip_v6, + 'neigh_ip_v4': neigh_ip_v4, + 'neigh_ip_v6': neigh_ip_v6, + 'neigh2_ip_v4': neigh2_ip_v4, + 'neigh2_ip_v6': neigh2_ip_v6, + 'peer_group_v4': peer_group_v4, + 'peer_group_v6': peer_group_v6, + 'asic_index': asic_index, + 'dut_bgp_id': dut_bgp_id, + 'neigh_bgp_id': neigh_bgp_id, + 'neigh2_bgp_id': neigh2_bgp_id, + 'dut_ipv4_network': dut_ipv4_network, + 'dut_ipv6_network': dut_ipv6_network, + 'neigh_ipv4_network': neigh_ipv4_network, + 'neigh_ipv6_network': neigh_ipv6_network + } + + logger.info("DUT BGP Config: {}".format(duthost.shell("show run bgp", module_ignore_errors=True)['stdout'])) + logger.info("Neighbor BGP Config: {}".format(nbrhosts[tor1]["host"].shell("show run bgp")['stdout'])) + logger.info('Setup_info: {}'.format(setup_info)) + + yield setup_info + + # restore config to original state + config_reload(duthost) + config_reload(tor_neighbors[tor1], is_dut=False) + + # verify sessions are established + bgp_facts = duthost.bgp_facts(instance_id=asic_index)['ansible_facts'] + for k, v in bgp_facts['bgp_neighbors'].items(): + if v['description'].lower() not in skip_hosts: + logger.debug(v['description']) + assert v['state'] == 'established' + + +def test_4_byte_asn_translation(setup): + cmd = 'vtysh -n {} \ + -c "config" \ + -c "no router bgp {}" \ + -c "router bgp {}" \ + -c "bgp router-id {}" \ + -c "bgp log-neighbor-changes" \ + -c "no bgp ebgp-requires-policy" \ + -c "no bgp default ipv4-unicast" \ + -c "bgp bestpath as-path multipath-relax" \ + -c "neighbor {} peer-group" \ + -c "neighbor {} peer-group" \ + -c "neighbor {} remote-as {}" \ + -c "neighbor {} peer-group {}" \ + -c "neighbor {} description {}" \ + -c "neighbor {} timers 3 10" \ + -c "neighbor {} timers connect 10" \ + -c "neighbor {} remote-as {}" \ + -c "neighbor {} peer-group {}" \ + -c "neighbor {} description {}" \ + -c "neighbor {} timers 3 10" \ + -c "neighbor {} timers connect 10" \ + -c "neighbor {} remote-as {}" \ + -c "neighbor {} peer-group {}" \ + -c "neighbor {} description {}" \ + -c "neighbor {} timers 3 10" \ + -c "neighbor {} timers connect 10" \ + -c "neighbor {} remote-as {}" \ + -c "neighbor {} peer-group {}" \ + -c "neighbor {} description {}" \ + -c "neighbor {} timers 3 10" \ + -c "neighbor {} timers connect 10" \ + -c "address-family ipv4 unicast" \ + -c "network {}" \ + -c "neighbor {} soft-reconfiguration inbound" \ + -c "neighbor {} route-map FROM_BGP_PEER_V4 in" \ + -c "neighbor {} route-map TO_BGP_PEER_V4 out" \ + -c "neighbor {} activate" \ + -c "neighbor {} activate" \ + -c "maximum-paths 64" \ + -c "exit-address-family" \ + -c "address-family ipv6 unicast" \ + -c "network {}" \ + -c "neighbor {} soft-reconfiguration inbound" \ + -c "neighbor {} route-map FROM_BGP_PEER_V6 in" \ + -c "neighbor {} route-map TO_BGP_PEER_V6 out" \ + -c "neighbor {} activate" \ + -c "neighbor {} activate" \ + -c "maximum-paths 64" \ + -c "exit-address-family" \ + '.format(setup['namespace'], setup['dut_asn'], dut_4byte_asn, setup['dut_bgp_id'], + setup['peer_group_v4'], setup['peer_group_v6'], setup['neigh_ip_v4'], neighbor_4byte_asn, + setup['neigh_ip_v4'], setup['peer_group_v4'], setup['neigh_ip_v4'], setup['tor1'], setup['neigh_ip_v4'], + setup['neigh_ip_v4'], setup['neigh_ip_v6'], neighbor_4byte_asn, setup['neigh_ip_v6'], + setup['peer_group_v6'], setup['neigh_ip_v6'], setup['tor1'], setup['neigh_ip_v6'], setup['neigh_ip_v6'], + setup['neigh2_ip_v4'], setup['neigh2_asn'], setup['neigh2_ip_v4'], setup['peer_group_v4'], + setup['neigh2_ip_v4'], setup['tor2'], setup['neigh2_ip_v4'], setup['neigh2_ip_v4'], setup['neigh2_ip_v6'], + setup['neigh2_asn'], setup['neigh2_ip_v6'], setup['peer_group_v6'], setup['neigh2_ip_v6'], setup['tor2'], + setup['neigh2_ip_v6'], setup['neigh2_ip_v6'], setup['dut_ipv4_network'], setup['peer_group_v4'], + setup['peer_group_v4'], setup['peer_group_v4'], setup['neigh_ip_v4'], setup['neigh2_ip_v4'], + setup['dut_ipv6_network'], setup['peer_group_v6'], setup['peer_group_v6'], setup['peer_group_v6'], + setup['neigh_ip_v6'], setup['neigh2_ip_v6']) + logger.debug(setup['duthost'].shell(cmd, module_ignore_errors=True)) + + cmd = 'vtysh \ + -c "config" \ + -c "no router bgp {}" \ + -c "router bgp {}" \ + -c "bgp router-id {}" \ + -c "bgp log-neighbor-changes" \ + -c "no bgp ebgp-requires-policy" \ + -c "no bgp default ipv4-unicast" \ + -c "bgp bestpath as-path multipath-relax" \ + -c "neighbor {} peer-group" \ + -c "neighbor {} peer-group" \ + -c "neighbor {} remote-as {}" \ + -c "neighbor {} peer-group {}" \ + -c "neighbor {} description {}" \ + -c "neighbor {} timers 3 10" \ + -c "neighbor {} timers connect 10" \ + -c "neighbor {} remote-as {}" \ + -c "neighbor {} peer-group {}" \ + -c "neighbor {} description {}" \ + -c "neighbor {} timers 3 10" \ + -c "neighbor {} timers connect 10" \ + -c "address-family ipv4 unicast" \ + -c "network {}" \ + -c "neighbor {} soft-reconfiguration inbound" \ + -c "neighbor {} route-map FROM_BGP_PEER_V4 in" \ + -c "neighbor {} route-map TO_BGP_PEER_V4 out" \ + -c "neighbor {} activate" \ + -c "maximum-paths 64" \ + -c "exit-address-family" \ + -c "address-family ipv6 unicast" \ + -c "network {}" \ + -c "neighbor {} soft-reconfiguration inbound" \ + -c "neighbor {} route-map FROM_BGP_PEER_V6 in" \ + -c "neighbor {} route-map TO_BGP_PEER_V6 out" \ + -c "neighbor {} activate" \ + -c "maximum-paths 64" \ + -c "exit-address-family" \ + '.format(setup['neigh_asn'], neighbor_4byte_asn, setup['neigh_bgp_id'], + setup['peer_group_v4'], setup['peer_group_v6'], setup['dut_ip_v4'], dut_4byte_asn, setup['dut_ip_v4'], + setup['peer_group_v4'], setup['dut_ip_v4'], 'DUT', setup['dut_ip_v4'], setup['dut_ip_v4'], + setup['dut_ip_v6'], dut_4byte_asn, setup['dut_ip_v6'], setup['peer_group_v6'], setup['dut_ip_v6'], 'DUT', + setup['dut_ip_v6'], setup['dut_ip_v6'], setup['neigh_ipv4_network'], setup['peer_group_v4'], + setup['peer_group_v4'], setup['peer_group_v4'], setup['dut_ip_v4'], setup['neigh_ipv6_network'], + setup['peer_group_v6'], setup['peer_group_v6'], setup['peer_group_v6'], setup['dut_ip_v6']) + + logger.debug(setup['neighhost'].shell(cmd, module_ignore_errors=True)) + + logger.info("DUT BGP Config: {}".format(setup['duthost'].shell("show run bgp")['stdout'])) + logger.info("Neighbor BGP Config: {}".format(setup['neighhost'].shell("show run bgp")['stdout'])) + + time.sleep(bgp_sleep) + + # verify session to 4-byte neighbor is established and 2-byte neighbor is down + bgp_facts = setup['duthost'].bgp_facts(instance_id=setup['asic_index'])['ansible_facts'] + for k, v in bgp_facts['bgp_neighbors'].items(): + if v['description'].lower() == setup['tor1']: + logger.debug(v['description']) + assert v['state'] == 'established' + elif v['description'].lower() == setup['tor2']: + logger.debug(v['description']) + assert v['state'] != 'established' + + # Configure DUT to use 2-byte local-ASN for 2-byte neighbors + cmd = 'vtysh -n {} \ + -c "config" \ + -c "router bgp {}" \ + -c "neighbor {} local-as {}" \ + -c "neighbor {} local-as {}" \ + '.format(setup['namespace'], dut_4byte_asn, setup['peer_group_v4'], setup['dut_asn'], setup['peer_group_v6'], + setup['dut_asn']) + logger.debug(setup['duthost'].shell(cmd, module_ignore_errors=True)) + cmd = 'vtysh -n {} -c "clear bgp *"'.format(setup['namespace']) + logger.debug(setup['duthost'].shell(cmd, module_ignore_errors=True)) + + time.sleep(bgp_sleep) + + # verify session to 4-byte and 2-byte neighbor is established + bgp_facts = setup['duthost'].bgp_facts(instance_id=setup['asic_index'])['ansible_facts'] + for k, v in bgp_facts['bgp_neighbors'].items(): + if v['description'].lower() == setup['tor1']: + logger.debug(v['description']) + assert v['state'] == 'established' + elif v['description'].lower() == setup['tor2']: + logger.debug(v['description']) + assert v['state'] == 'established' + + cmd = 'vtysh -c "show bgp ipv4 all neighbors {}" received-routes'.format(setup['neigh_ipv4_network']) + logger.debug(setup['neigh2host'].shell(cmd, module_ignore_errors=True)) From 145fef784fc9e35cfca82d5a936343a79ec36f28 Mon Sep 17 00:00:00 2001 From: Azarack Date: Wed, 13 Dec 2023 16:06:08 +0000 Subject: [PATCH 2/5] change to use random frontend dut --- tests/bgp/test_bgp_4-byte_as_trans.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/bgp/test_bgp_4-byte_as_trans.py b/tests/bgp/test_bgp_4-byte_as_trans.py index a355073d9c..e55b420fd0 100644 --- a/tests/bgp/test_bgp_4-byte_as_trans.py +++ b/tests/bgp/test_bgp_4-byte_as_trans.py @@ -30,11 +30,11 @@ @pytest.fixture(scope='module') -def setup(tbinfo, nbrhosts, duthosts, rand_one_dut_hostname, enum_rand_one_frontend_asic_index, request): +def setup(tbinfo, nbrhosts, duthosts, enum_frontend_dut_hostname, enum_rand_one_frontend_asic_index, request): # verify neighbors are type sonic if request.config.getoption("neighbor_type") != "sonic": pytest.skip("Neighbor type must be sonic") - duthost = duthosts[rand_one_dut_hostname] + duthost = duthosts[enum_frontend_dut_hostname] asic_index = enum_rand_one_frontend_asic_index namespace = duthost.get_namespace_from_asic_id(asic_index) dut_asn = tbinfo['topo']['properties']['configuration_properties']['common']['dut_asn'] From ba54ccfea5092b7968672a78bbd9922b182c58d1 Mon Sep 17 00:00:00 2001 From: Azarack Date: Tue, 19 Mar 2024 21:00:17 +0000 Subject: [PATCH 3/5] adding clarification for route-map and updating tor and namespace --- tests/bgp/test_bgp_4-byte_as_trans.py | 96 ++++++++++++++------------- 1 file changed, 51 insertions(+), 45 deletions(-) diff --git a/tests/bgp/test_bgp_4-byte_as_trans.py b/tests/bgp/test_bgp_4-byte_as_trans.py index e55b420fd0..29f41d049a 100644 --- a/tests/bgp/test_bgp_4-byte_as_trans.py +++ b/tests/bgp/test_bgp_4-byte_as_trans.py @@ -21,7 +21,7 @@ logger = logging.getLogger(__name__) dut_4byte_asn = 400003 neighbor_4byte_asn = 400001 -bgp_sleep = 60 +bgp_sleep = 120 bgp_id_textfsm = "./bgp/templates/bgp_id.template" pytestmark = [ @@ -36,12 +36,17 @@ def setup(tbinfo, nbrhosts, duthosts, enum_frontend_dut_hostname, enum_rand_one_ pytest.skip("Neighbor type must be sonic") duthost = duthosts[enum_frontend_dut_hostname] asic_index = enum_rand_one_frontend_asic_index - namespace = duthost.get_namespace_from_asic_id(asic_index) + + if duthost.is_multi_asic: + cli_options = "-n " + duthost.get_namespace_from_asic_id(asic_index) + else: + cli_options = '' + dut_asn = tbinfo['topo']['properties']['configuration_properties']['common']['dut_asn'] - tor1 = duthost.shell("show lldp table")['stdout'].split("\n")[3].split()[1] - tor2 = duthost.shell("show lldp table")['stdout'].split("\n")[5].split()[1] + neigh1 = duthost.shell("show lldp table")['stdout'].split("\n")[3].split()[1] + neigh2 = duthost.shell("show lldp table")['stdout'].split("\n")[5].split()[1] - tor_neighbors = dict() + neighbors = dict() skip_hosts = duthost.get_asic_namespace_list() bgp_facts = duthost.bgp_facts(instance_id=asic_index)['ansible_facts'] neigh_asn = dict() @@ -49,28 +54,28 @@ def setup(tbinfo, nbrhosts, duthosts, enum_frontend_dut_hostname, enum_rand_one_ # verify sessions are established and gather neighbor information for k, v in bgp_facts['bgp_neighbors'].items(): if v['description'].lower() not in skip_hosts: - if v['description'] == tor1: + if v['description'] == neigh1: if v['ip_version'] == 4: neigh_ip_v4 = k peer_group_v4 = v['peer group'] elif v['ip_version'] == 6: neigh_ip_v6 = k peer_group_v6 = v['peer group'] - if v['description'] == tor2: + if v['description'] == neigh2: if v['ip_version'] == 4: neigh2_ip_v4 = k elif v['ip_version'] == 6: neigh2_ip_v6 = k assert v['state'] == 'established' neigh_asn[v['description']] = v['remote AS'] - tor_neighbors[v['description']] = nbrhosts[v['description']]["host"] + neighbors[v['description']] = nbrhosts[v['description']]["host"] - dut_ip_v4 = tbinfo['topo']['properties']['configuration'][tor1]['bgp']['peers'][dut_asn][0] - dut_ip_v6 = tbinfo['topo']['properties']['configuration'][tor1]['bgp']['peers'][dut_asn][1] + dut_ip_v4 = tbinfo['topo']['properties']['configuration'][neigh1]['bgp']['peers'][dut_asn][0] + dut_ip_v6 = tbinfo['topo']['properties']['configuration'][neigh1]['bgp']['peers'][dut_asn][1] dut_ip_bgp_sum = duthost.shell('show ip bgp summary')['stdout'] - neigh_ip_bgp_sum = nbrhosts[tor1]["host"].shell('show ip bgp summary')['stdout'] - neigh2_ip_bgp_sum = nbrhosts[tor1]["host"].shell('show ip bgp summary')['stdout'] + neigh_ip_bgp_sum = nbrhosts[neigh1]["host"].shell('show ip bgp summary')['stdout'] + neigh2_ip_bgp_sum = nbrhosts[neigh1]["host"].shell('show ip bgp summary')['stdout'] with open(bgp_id_textfsm) as template: fsm = textfsm.TextFSM(template) dut_bgp_id = fsm.ParseText(dut_ip_bgp_sum)[0][0] @@ -79,21 +84,21 @@ def setup(tbinfo, nbrhosts, duthosts, enum_frontend_dut_hostname, enum_rand_one_ dut_ipv4_network = duthost.shell("show run bgp | grep 'ip prefix-list'")['stdout'].split()[6] dut_ipv6_network = duthost.shell("show run bgp | grep 'ipv6 prefix-list'")['stdout'].split()[6] - neigh_ipv4_network = nbrhosts[tor1]["host"].shell("show run bgp | grep 'ip prefix-list'")['stdout'].split()[6] - neigh_ipv6_network = nbrhosts[tor1]["host"].shell("show run bgp | grep 'ipv6 prefix-list'")['stdout'].split()[6] + neigh_ipv4_network = nbrhosts[neigh1]["host"].shell("show run bgp | grep 'ip prefix-list'")['stdout'].split()[6] + neigh_ipv6_network = nbrhosts[neigh1]["host"].shell("show run bgp | grep 'ipv6 prefix-list'")['stdout'].split()[6] setup_info = { 'duthost': duthost, - 'neighhost': tor_neighbors[tor1], - 'neigh2host': tor_neighbors[tor2], - 'tor1': tor1, - 'tor2': tor2, + 'neighhost': neighbors[neigh1], + 'neigh2host': neighbors[neigh2], + 'neigh1': neigh1, + 'neigh2': neigh2, 'dut_asn': dut_asn, - 'neigh_asn': neigh_asn[tor1], - 'neigh2_asn': neigh_asn[tor2], + 'neigh_asn': neigh_asn[neigh1], + 'neigh2_asn': neigh_asn[neigh2], 'asn_dict': neigh_asn, - 'neighbors': tor_neighbors, - 'namespace': namespace, + 'neighbors': neighbors, + 'cli_options': cli_options, 'dut_ip_v4': dut_ip_v4, 'dut_ip_v6': dut_ip_v6, 'neigh_ip_v4': neigh_ip_v4, @@ -112,15 +117,15 @@ def setup(tbinfo, nbrhosts, duthosts, enum_frontend_dut_hostname, enum_rand_one_ 'neigh_ipv6_network': neigh_ipv6_network } - logger.info("DUT BGP Config: {}".format(duthost.shell("show run bgp", module_ignore_errors=True)['stdout'])) - logger.info("Neighbor BGP Config: {}".format(nbrhosts[tor1]["host"].shell("show run bgp")['stdout'])) - logger.info('Setup_info: {}'.format(setup_info)) + logger.debug("DUT BGP Config: {}".format(duthost.shell("show run bgp", module_ignore_errors=True)['stdout'])) + logger.debug("Neighbor BGP Config: {}".format(nbrhosts[neigh1]["host"].shell("show run bgp")['stdout'])) + logger.debug('Setup_info: {}'.format(setup_info)) yield setup_info # restore config to original state config_reload(duthost) - config_reload(tor_neighbors[tor1], is_dut=False) + config_reload(neighbors[neigh1], is_dut=False) # verify sessions are established bgp_facts = duthost.bgp_facts(instance_id=asic_index)['ansible_facts'] @@ -131,7 +136,8 @@ def setup(tbinfo, nbrhosts, duthosts, enum_frontend_dut_hostname, enum_rand_one_ def test_4_byte_asn_translation(setup): - cmd = 'vtysh -n {} \ + # copy existing BGP config to a new 4-byte ASN. Use existing route-maps for consistancy. + cmd = 'vtysh{} \ -c "config" \ -c "no router bgp {}" \ -c "router bgp {}" \ @@ -180,18 +186,18 @@ def test_4_byte_asn_translation(setup): -c "neighbor {} activate" \ -c "maximum-paths 64" \ -c "exit-address-family" \ - '.format(setup['namespace'], setup['dut_asn'], dut_4byte_asn, setup['dut_bgp_id'], + '.format(setup['cli_options'], setup['dut_asn'], dut_4byte_asn, setup['dut_bgp_id'], setup['peer_group_v4'], setup['peer_group_v6'], setup['neigh_ip_v4'], neighbor_4byte_asn, - setup['neigh_ip_v4'], setup['peer_group_v4'], setup['neigh_ip_v4'], setup['tor1'], setup['neigh_ip_v4'], + setup['neigh_ip_v4'], setup['peer_group_v4'], setup['neigh_ip_v4'], setup['neigh1'], setup['neigh_ip_v4'], setup['neigh_ip_v4'], setup['neigh_ip_v6'], neighbor_4byte_asn, setup['neigh_ip_v6'], - setup['peer_group_v6'], setup['neigh_ip_v6'], setup['tor1'], setup['neigh_ip_v6'], setup['neigh_ip_v6'], + setup['peer_group_v6'], setup['neigh_ip_v6'], setup['neigh1'], setup['neigh_ip_v6'], setup['neigh_ip_v6'], setup['neigh2_ip_v4'], setup['neigh2_asn'], setup['neigh2_ip_v4'], setup['peer_group_v4'], - setup['neigh2_ip_v4'], setup['tor2'], setup['neigh2_ip_v4'], setup['neigh2_ip_v4'], setup['neigh2_ip_v6'], - setup['neigh2_asn'], setup['neigh2_ip_v6'], setup['peer_group_v6'], setup['neigh2_ip_v6'], setup['tor2'], - setup['neigh2_ip_v6'], setup['neigh2_ip_v6'], setup['dut_ipv4_network'], setup['peer_group_v4'], - setup['peer_group_v4'], setup['peer_group_v4'], setup['neigh_ip_v4'], setup['neigh2_ip_v4'], - setup['dut_ipv6_network'], setup['peer_group_v6'], setup['peer_group_v6'], setup['peer_group_v6'], - setup['neigh_ip_v6'], setup['neigh2_ip_v6']) + setup['neigh2_ip_v4'], setup['neigh2'], setup['neigh2_ip_v4'], setup['neigh2_ip_v4'], + setup['neigh2_ip_v6'], setup['neigh2_asn'], setup['neigh2_ip_v6'], setup['peer_group_v6'], + setup['neigh2_ip_v6'], setup['neigh2'], setup['neigh2_ip_v6'], setup['neigh2_ip_v6'], + setup['dut_ipv4_network'], setup['peer_group_v4'], setup['peer_group_v4'], setup['peer_group_v4'], + setup['neigh_ip_v4'], setup['neigh2_ip_v4'], setup['dut_ipv6_network'], setup['peer_group_v6'], + setup['peer_group_v6'], setup['peer_group_v6'], setup['neigh_ip_v6'], setup['neigh2_ip_v6']) logger.debug(setup['duthost'].shell(cmd, module_ignore_errors=True)) cmd = 'vtysh \ @@ -241,31 +247,31 @@ def test_4_byte_asn_translation(setup): logger.debug(setup['neighhost'].shell(cmd, module_ignore_errors=True)) - logger.info("DUT BGP Config: {}".format(setup['duthost'].shell("show run bgp")['stdout'])) - logger.info("Neighbor BGP Config: {}".format(setup['neighhost'].shell("show run bgp")['stdout'])) + logger.debug("DUT BGP Config: {}".format(setup['duthost'].shell("show run bgp")['stdout'])) + logger.debug("Neighbor BGP Config: {}".format(setup['neighhost'].shell("show run bgp")['stdout'])) time.sleep(bgp_sleep) # verify session to 4-byte neighbor is established and 2-byte neighbor is down bgp_facts = setup['duthost'].bgp_facts(instance_id=setup['asic_index'])['ansible_facts'] for k, v in bgp_facts['bgp_neighbors'].items(): - if v['description'].lower() == setup['tor1']: + if v['description'].lower() == setup['neigh1']: logger.debug(v['description']) assert v['state'] == 'established' - elif v['description'].lower() == setup['tor2']: + elif v['description'].lower() == setup['neigh2']: logger.debug(v['description']) assert v['state'] != 'established' # Configure DUT to use 2-byte local-ASN for 2-byte neighbors - cmd = 'vtysh -n {} \ + cmd = 'vtysh{} \ -c "config" \ -c "router bgp {}" \ -c "neighbor {} local-as {}" \ -c "neighbor {} local-as {}" \ - '.format(setup['namespace'], dut_4byte_asn, setup['peer_group_v4'], setup['dut_asn'], setup['peer_group_v6'], + '.format(setup['cli_options'], dut_4byte_asn, setup['peer_group_v4'], setup['dut_asn'], setup['peer_group_v6'], setup['dut_asn']) logger.debug(setup['duthost'].shell(cmd, module_ignore_errors=True)) - cmd = 'vtysh -n {} -c "clear bgp *"'.format(setup['namespace']) + cmd = 'vtysh{} -c "clear bgp *"'.format(setup['cli_options']) logger.debug(setup['duthost'].shell(cmd, module_ignore_errors=True)) time.sleep(bgp_sleep) @@ -273,10 +279,10 @@ def test_4_byte_asn_translation(setup): # verify session to 4-byte and 2-byte neighbor is established bgp_facts = setup['duthost'].bgp_facts(instance_id=setup['asic_index'])['ansible_facts'] for k, v in bgp_facts['bgp_neighbors'].items(): - if v['description'].lower() == setup['tor1']: + if v['description'].lower() == setup['neigh1']: logger.debug(v['description']) assert v['state'] == 'established' - elif v['description'].lower() == setup['tor2']: + elif v['description'].lower() == setup['neigh2']: logger.debug(v['description']) assert v['state'] == 'established' From 6d3aea6ecfe767c7aea7a5e079ddd70f0365e610 Mon Sep 17 00:00:00 2001 From: Azarack Date: Wed, 20 Mar 2024 13:18:39 +0000 Subject: [PATCH 4/5] adding neighbor cli options --- tests/bgp/test_bgp_4-byte_as_trans.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/bgp/test_bgp_4-byte_as_trans.py b/tests/bgp/test_bgp_4-byte_as_trans.py index 29f41d049a..65d81233b1 100644 --- a/tests/bgp/test_bgp_4-byte_as_trans.py +++ b/tests/bgp/test_bgp_4-byte_as_trans.py @@ -38,7 +38,7 @@ def setup(tbinfo, nbrhosts, duthosts, enum_frontend_dut_hostname, enum_rand_one_ asic_index = enum_rand_one_frontend_asic_index if duthost.is_multi_asic: - cli_options = "-n " + duthost.get_namespace_from_asic_id(asic_index) + cli_options = " -n " + duthost.get_namespace_from_asic_id(asic_index) else: cli_options = '' @@ -69,6 +69,10 @@ def setup(tbinfo, nbrhosts, duthosts, enum_frontend_dut_hostname, enum_rand_one_ assert v['state'] == 'established' neigh_asn[v['description']] = v['remote AS'] neighbors[v['description']] = nbrhosts[v['description']]["host"] + if neighbors[neigh1].is_multi_asic: + neigh_cli_options = " -n " + neigh1.get_namespace_from_asic_id(asic_index) + else: + neigh_cli_options = '' dut_ip_v4 = tbinfo['topo']['properties']['configuration'][neigh1]['bgp']['peers'][dut_asn][0] dut_ip_v6 = tbinfo['topo']['properties']['configuration'][neigh1]['bgp']['peers'][dut_asn][1] @@ -99,6 +103,7 @@ def setup(tbinfo, nbrhosts, duthosts, enum_frontend_dut_hostname, enum_rand_one_ 'asn_dict': neigh_asn, 'neighbors': neighbors, 'cli_options': cli_options, + 'neigh_cli_options': neigh_cli_options, 'dut_ip_v4': dut_ip_v4, 'dut_ip_v6': dut_ip_v6, 'neigh_ip_v4': neigh_ip_v4, @@ -200,7 +205,8 @@ def test_4_byte_asn_translation(setup): setup['peer_group_v6'], setup['peer_group_v6'], setup['neigh_ip_v6'], setup['neigh2_ip_v6']) logger.debug(setup['duthost'].shell(cmd, module_ignore_errors=True)) - cmd = 'vtysh \ + # configure 4-byte ASN on neighbor device, reusing the established BGP config and route-maps + cmd = 'vtysh{} \ -c "config" \ -c "no router bgp {}" \ -c "router bgp {}" \ @@ -237,7 +243,7 @@ def test_4_byte_asn_translation(setup): -c "neighbor {} activate" \ -c "maximum-paths 64" \ -c "exit-address-family" \ - '.format(setup['neigh_asn'], neighbor_4byte_asn, setup['neigh_bgp_id'], + '.format(setup['neigh_cli_options'], setup['neigh_asn'], neighbor_4byte_asn, setup['neigh_bgp_id'], setup['peer_group_v4'], setup['peer_group_v6'], setup['dut_ip_v4'], dut_4byte_asn, setup['dut_ip_v4'], setup['peer_group_v4'], setup['dut_ip_v4'], 'DUT', setup['dut_ip_v4'], setup['dut_ip_v4'], setup['dut_ip_v6'], dut_4byte_asn, setup['dut_ip_v6'], setup['peer_group_v6'], setup['dut_ip_v6'], 'DUT', From abb7a18bc76a815a70b14f60cdf843cff24ef5d4 Mon Sep 17 00:00:00 2001 From: Azarack Date: Wed, 17 Jul 2024 14:47:09 +0000 Subject: [PATCH 5/5] Updating name and overview --- docs/testplan/BGP-4-Byte_AS_Translation.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/testplan/BGP-4-Byte_AS_Translation.md b/docs/testplan/BGP-4-Byte_AS_Translation.md index 4ff39a9308..496e9643eb 100644 --- a/docs/testplan/BGP-4-Byte_AS_Translation.md +++ b/docs/testplan/BGP-4-Byte_AS_Translation.md @@ -6,11 +6,11 @@ # Test name -BGP Session Flaps +BGP 4-Byte AS Translation ## Overview -The goal of this test is to verify that the CPU and memory do not spike during cycles of BGP sessions flapping. +The goal of this test is to verify that the 4-byte to 2-byte AS translation feature operates as expected. ### Scope