|
| 1 | +import time |
| 2 | +import pytest |
| 3 | + |
| 4 | +pytestmark = [ |
| 5 | + pytest.mark.topology('t0', 't1') |
| 6 | +] |
| 7 | + |
| 8 | +WAIT_TIME = 5 |
| 9 | + |
| 10 | + |
| 11 | +def test_uN_config(duthosts, enum_frontend_dut_hostname, enum_rand_one_asic_index): |
| 12 | + duthost = duthosts[enum_frontend_dut_hostname] |
| 13 | + asic_index = enum_rand_one_asic_index |
| 14 | + |
| 15 | + if duthost.is_multi_asic: |
| 16 | + cli_options = " -n " + duthost.get_namespace_from_asic_id(asic_index) |
| 17 | + else: |
| 18 | + cli_options = '' |
| 19 | + |
| 20 | + sonic_db_cli = "sonic-db-cli" + cli_options |
| 21 | + vtysh_shell = "vtysh" + cli_options |
| 22 | + |
| 23 | + # add a locator configuration entry |
| 24 | + duthost.command(sonic_db_cli + " CONFIG_DB HSET SRV6_MY_LOCATORS\\|loc1 prefix fcbb:bbbb:1::") |
| 25 | + # add a uN sid configuration entry |
| 26 | + duthost.command(sonic_db_cli + |
| 27 | + " CONFIG_DB HSET SRV6_MY_SIDS\\|loc1\\|fcbb:bbbb:1::/48 action uN decap_dscp_mode pipe") |
| 28 | + time.sleep(WAIT_TIME) |
| 29 | + |
| 30 | + frr_config = duthost.command(vtysh_shell + " -c \"show running-config\"")["stdout"] |
| 31 | + |
| 32 | + # verify that bgpcfgd generates FRR config correctly |
| 33 | + assert "locator loc1" in frr_config |
| 34 | + assert "sid fcbb:bbbb:1::/48 locator loc1 behavior uN" in frr_config |
| 35 | + |
| 36 | + appl_db_my_sids = duthost.command(sonic_db_cli + " APPL_DB keys SRV6_MY_SID_TABLE*")["stdout"] |
| 37 | + |
| 38 | + # verify that APPL_DB gets programmed by FRR correctly |
| 39 | + assert "SRV6_MY_SID_TABLE:32:16:0:0:fcbb:bbbb:1::" in appl_db_my_sids |
| 40 | + assert "un" == duthost.command(sonic_db_cli + |
| 41 | + " APPL_DB hget SRV6_MY_SID_TABLE:32:16:0:0:fcbb:bbbb:1:: action")["stdout"] |
| 42 | + |
| 43 | + # delete the configurations |
| 44 | + duthost.command(sonic_db_cli + " CONFIG_DB DEL SRV6_MY_LOCATORS\\|loc1") |
| 45 | + duthost.command(sonic_db_cli + " CONFIG_DB DEL SRV6_MY_SIDS\\|loc1\\|fcbb:bbbb:1::/48") |
| 46 | + time.sleep(WAIT_TIME) |
| 47 | + |
| 48 | + frr_config = duthost.command(vtysh_shell + " -c \"show running-config\"")["stdout"] |
| 49 | + |
| 50 | + # verify that bgpcfgd deletes relevant FRR config |
| 51 | + assert "locator loc1" not in frr_config |
| 52 | + assert "sid fcbb:bbbb:1::/48 locator loc1 behavior uN" not in frr_config |
| 53 | + |
| 54 | + appl_db_my_sids = duthost.command(sonic_db_cli + " APPL_DB keys SRV6_MY_SID_TABLE*")["stdout"] |
| 55 | + |
| 56 | + # verify that the APPL_DB entry gets cleaned correctly |
| 57 | + assert "SRV6_MY_SID_TABLE:32:16:0:0:fcbb:bbbb:1::" not in appl_db_my_sids |
| 58 | + |
| 59 | + |
| 60 | +def test_uDT46_config(duthosts, enum_frontend_dut_hostname, enum_rand_one_asic_index): |
| 61 | + duthost = duthosts[enum_frontend_dut_hostname] |
| 62 | + asic_index = enum_rand_one_asic_index |
| 63 | + |
| 64 | + if duthost.is_multi_asic: |
| 65 | + cli_options = " -n " + duthost.get_namespace_from_asic_id(asic_index) |
| 66 | + else: |
| 67 | + cli_options = '' |
| 68 | + |
| 69 | + sonic_db_cli = "sonic-db-cli" + cli_options |
| 70 | + vtysh_shell = "vtysh" + cli_options |
| 71 | + |
| 72 | + # add Vrf1 config |
| 73 | + duthost.command("config vrf add Vrf1") |
| 74 | + duthost.command("sysctl -w net.vrf.strict_mode=1") |
| 75 | + |
| 76 | + # add a locator configuration entry |
| 77 | + duthost.command(sonic_db_cli + " CONFIG_DB HSET SRV6_MY_LOCATORS\\|loc1 prefix fcbb:bbbb:1::") |
| 78 | + # add a uDT46 sid configuration entry |
| 79 | + duthost.command(sonic_db_cli + " CONFIG_DB HSET SRV6_MY_SIDS\\|loc1\\|fcbb:bbbb:1:2::/64 \ |
| 80 | + action uDT46 decap_vrf Vrf1 decap_dscp_mode uniform") |
| 81 | + time.sleep(WAIT_TIME) |
| 82 | + |
| 83 | + frr_config = duthost.command(vtysh_shell + " -c \"show running-config\"")["stdout"] |
| 84 | + |
| 85 | + # verify that bgpcfgd generates FRR config correctly |
| 86 | + assert "locator loc1" in frr_config |
| 87 | + assert "sid fcbb:bbbb:1:2::/64 locator loc1 behavior uDT46 vrf Vrf1" in frr_config |
| 88 | + |
| 89 | + appl_db_my_sids = duthost.command(sonic_db_cli + " APPL_DB keys SRV6_MY_SID_TABLE*")["stdout"] |
| 90 | + |
| 91 | + # verify that APPL_DB gets programmed by FRR correctly |
| 92 | + assert "SRV6_MY_SID_TABLE:32:16:16:0:fcbb:bbbb:1:2::" in appl_db_my_sids |
| 93 | + assert "udt46" == duthost.command(sonic_db_cli + |
| 94 | + " APPL_DB hget SRV6_MY_SID_TABLE:32:16:16:0:fcbb:bbbb:1:2:: action")["stdout"] |
| 95 | + assert "Vrf1" == duthost.command(sonic_db_cli + |
| 96 | + " APPL_DB hget SRV6_MY_SID_TABLE:32:16:16:0:fcbb:bbbb:1:2:: vrf")["stdout"] |
| 97 | + |
| 98 | + # delete the configurations |
| 99 | + duthost.command(sonic_db_cli + " CONFIG_DB DEL SRV6_MY_LOCATORS\\|loc1") |
| 100 | + duthost.command(sonic_db_cli + " CONFIG_DB DEL SRV6_MY_SIDS\\|loc1\\|fcbb:bbbb:1:2::/64") |
| 101 | + time.sleep(WAIT_TIME) |
| 102 | + |
| 103 | + frr_config = duthost.command(vtysh_shell + " -c \"show running-config\"")["stdout"] |
| 104 | + |
| 105 | + # verify that bgpcfgd deletes relevant FRR config |
| 106 | + assert "locator loc1" not in frr_config |
| 107 | + assert "sid fcbb:bbbb:1:2::/64 locator loc1 behavior uDT46 vrf Vrf1" not in frr_config |
| 108 | + |
| 109 | + appl_db_my_sids = duthost.command(sonic_db_cli + " APPL_DB keys SRV6_MY_SID_TABLE*")["stdout"] |
| 110 | + |
| 111 | + # verify that the APPL_DB entry gets cleaned correctly |
| 112 | + assert "SRV6_MY_SID_TABLE:32:16:16:0:fcbb:bbbb:1:2::" not in appl_db_my_sids |
| 113 | + |
| 114 | + # delete the Vrf config |
| 115 | + duthost.command("config vrf del Vrf1") |
0 commit comments