diff --git a/tests/test_crm.py b/tests/test_crm.py index bd4db74c5f5..c12a1a1d751 100644 --- a/tests/test_crm.py +++ b/tests/test_crm.py @@ -40,583 +40,583 @@ def setReadOnlyAttr(dvs, obj, attr, val): ntf.send("set_ro", key, fvp) +class TestCrm(object): + def test_CrmFdbEntry(self, dvs, testlog): -def test_CrmFdbEntry(dvs, testlog): + # disable ipv6 on Ethernet8 neighbor as once ipv6 link-local address is + # configured, server 2 will send packet which can switch to learn another + # mac and fail the test. + dvs.servers[2].runcmd("sysctl -w net.ipv6.conf.eth0.disable_ipv6=1") + dvs.runcmd("crm config polling interval 1") - # disable ipv6 on Ethernet8 neighbor as once ipv6 link-local address is - # configured, server 2 will send packet which can switch to learn another - # mac and fail the test. - dvs.servers[2].runcmd("sysctl -w net.ipv6.conf.eth0.disable_ipv6=1") - dvs.runcmd("crm config polling interval 1") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY', '1000') - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY', '1000') + time.sleep(2) - time.sleep(2) + # get counters + used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_fdb_entry_used') + avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_fdb_entry_available') - # get counters - used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_fdb_entry_used') - avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_fdb_entry_available') + app_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) + cfg_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) - app_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) - cfg_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + # create a FDB entry + tbl = swsscommon.ProducerStateTable(app_db, "FDB_TABLE") + fvs = swsscommon.FieldValuePairs([("port","Ethernet8"),("type","dynamic")]) + tbl.set("Vlan2:52-54-00-25-06-E9", fvs) - # create a FDB entry - tbl = swsscommon.ProducerStateTable(app_db, "FDB_TABLE") - fvs = swsscommon.FieldValuePairs([("port","Ethernet8"),("type","dynamic")]) - tbl.set("Vlan2:52-54-00-25-06-E9", fvs) + # create vlan + tbl = swsscommon.Table(cfg_db, "VLAN") + fvs = swsscommon.FieldValuePairs([("vlanid", "2")]) + tbl.set("Vlan2", fvs) - # create vlan - tbl = swsscommon.Table(cfg_db, "VLAN") - fvs = swsscommon.FieldValuePairs([("vlanid", "2")]) - tbl.set("Vlan2", fvs) + # create vlan member + tbl = swsscommon.Table(cfg_db, "VLAN_MEMBER") + fvs = swsscommon.FieldValuePairs([("tagging_mode", "untagged")]) + tbl.set("Vlan2|Ethernet8", fvs) - # create vlan member - tbl = swsscommon.Table(cfg_db, "VLAN_MEMBER") - fvs = swsscommon.FieldValuePairs([("tagging_mode", "untagged")]) - tbl.set("Vlan2|Ethernet8", fvs) + # update available counter + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY', '999') - # update available counter - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY', '999') + time.sleep(2) - time.sleep(2) + # get counters + new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_fdb_entry_used') + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_fdb_entry_available') - # get counters - new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_fdb_entry_used') - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_fdb_entry_available') + assert new_used_counter - used_counter == 1 + assert avail_counter - new_avail_counter == 1 - assert new_used_counter - used_counter == 1 - assert avail_counter - new_avail_counter == 1 + # update available counter + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY', '1000') - # update available counter - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY', '1000') + time.sleep(2) - time.sleep(2) + # get counters + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_fdb_entry_available') - # get counters - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_fdb_entry_available') + assert new_avail_counter == avail_counter - assert new_avail_counter == avail_counter + # enable ipv6 on server 2 + dvs.servers[2].runcmd("sysctl -w net.ipv6.conf.eth0.disable_ipv6=0") - # enable ipv6 on server 2 - dvs.servers[2].runcmd("sysctl -w net.ipv6.conf.eth0.disable_ipv6=0") + def test_CrmIpv4Route(self, dvs, testlog): -def test_CrmIpv4Route(dvs, testlog): + config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + intf_tbl = swsscommon.Table(config_db, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) + intf_tbl.set("Ethernet0", fvs) + intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) + dvs.runcmd("ifconfig Ethernet0 up") - config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) - intf_tbl = swsscommon.Table(config_db, "INTERFACE") - fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) - intf_tbl.set("Ethernet0", fvs) - intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) - dvs.runcmd("ifconfig Ethernet0 up") + dvs.runcmd("crm config polling interval 1") - dvs.runcmd("crm config polling interval 1") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_ROUTE_ENTRY', '1000') - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_ROUTE_ENTRY', '1000') + # add static neighbor + dvs.runcmd("ip neigh replace 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") - # add static neighbor - dvs.runcmd("ip neigh replace 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") + db = swsscommon.DBConnector(0, dvs.redis_sock, 0) + ps = swsscommon.ProducerStateTable(db, "ROUTE_TABLE") + fvs = swsscommon.FieldValuePairs([("nexthop","10.0.0.1"), ("ifname", "Ethernet0")]) - db = swsscommon.DBConnector(0, dvs.redis_sock, 0) - ps = swsscommon.ProducerStateTable(db, "ROUTE_TABLE") - fvs = swsscommon.FieldValuePairs([("nexthop","10.0.0.1"), ("ifname", "Ethernet0")]) + time.sleep(2) - time.sleep(2) + # get counters + used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_route_used') + avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_route_available') - # get counters - used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_route_used') - avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_route_available') + # add route and update available counter + ps.set("2.2.2.0/24", fvs) + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_ROUTE_ENTRY', '999') - # add route and update available counter - ps.set("2.2.2.0/24", fvs) - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_ROUTE_ENTRY', '999') + time.sleep(2) - time.sleep(2) + # get counters + new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_route_used') + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_route_available') - # get counters - new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_route_used') - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_route_available') + assert new_used_counter - used_counter == 1 + assert avail_counter - new_avail_counter == 1 - assert new_used_counter - used_counter == 1 - assert avail_counter - new_avail_counter == 1 + # remove route and update available counter + ps._del("2.2.2.0/24") + dvs.runcmd("ip neigh del 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_ROUTE_ENTRY', '1000') - # remove route and update available counter - ps._del("2.2.2.0/24") - dvs.runcmd("ip neigh del 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_ROUTE_ENTRY', '1000') + time.sleep(2) - time.sleep(2) + # get counters + new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_route_used') + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_route_available') - # get counters - new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_route_used') - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_route_available') + assert new_used_counter == used_counter + assert new_avail_counter == avail_counter - assert new_used_counter == used_counter - assert new_avail_counter == avail_counter + intf_tbl._del("Ethernet0|10.0.0.0/31") + time.sleep(2) - intf_tbl._del("Ethernet0|10.0.0.0/31") - time.sleep(2) + def test_CrmIpv6Route(self, dvs, testlog): -def test_CrmIpv6Route(dvs, testlog): + # Enable IPv6 routing + dvs.runcmd("sysctl net.ipv6.conf.all.disable_ipv6=0") + time.sleep(2) - # Enable IPv6 routing - dvs.runcmd("sysctl net.ipv6.conf.all.disable_ipv6=0") - time.sleep(2) + config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + intf_tbl = swsscommon.Table(config_db, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) + intf_tbl.set("Ethernet0", fvs) + intf_tbl.set("Ethernet0|fc00::1/126", fvs) + dvs.runcmd("ifconfig Ethernet0 up") - config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) - intf_tbl = swsscommon.Table(config_db, "INTERFACE") - fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) - intf_tbl.set("Ethernet0", fvs) - intf_tbl.set("Ethernet0|fc00::1/126", fvs) - dvs.runcmd("ifconfig Ethernet0 up") + dvs.servers[0].runcmd("ifconfig eth0 inet6 add fc00::2/126") + dvs.servers[0].runcmd("ip -6 route add default via fc00::1") - dvs.servers[0].runcmd("ifconfig eth0 inet6 add fc00::2/126") - dvs.servers[0].runcmd("ip -6 route add default via fc00::1") + dvs.runcmd("crm config polling interval 1") - dvs.runcmd("crm config polling interval 1") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_ROUTE_ENTRY', '1000') - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_ROUTE_ENTRY', '1000') + # get neighbor and arp entry + dvs.servers[0].runcmd("ping6 -c 4 fc00::1") - # get neighbor and arp entry - dvs.servers[0].runcmd("ping6 -c 4 fc00::1") + db = swsscommon.DBConnector(0, dvs.redis_sock, 0) + ps = swsscommon.ProducerStateTable(db, "ROUTE_TABLE") + fvs = swsscommon.FieldValuePairs([("nexthop","fc00::2"), ("ifname", "Ethernet0")]) - db = swsscommon.DBConnector(0, dvs.redis_sock, 0) - ps = swsscommon.ProducerStateTable(db, "ROUTE_TABLE") - fvs = swsscommon.FieldValuePairs([("nexthop","fc00::2"), ("ifname", "Ethernet0")]) + time.sleep(2) - time.sleep(2) + # get counters + used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_route_used') + avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_route_available') - # get counters - used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_route_used') - avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_route_available') + # add route and update available counter + ps.set("2001::/64", fvs) + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_ROUTE_ENTRY', '999') - # add route and update available counter - ps.set("2001::/64", fvs) - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_ROUTE_ENTRY', '999') + time.sleep(2) - time.sleep(2) + # get counters + new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_route_used') + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_route_available') - # get counters - new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_route_used') - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_route_available') + assert new_used_counter - used_counter == 1 + assert avail_counter - new_avail_counter == 1 - assert new_used_counter - used_counter == 1 - assert avail_counter - new_avail_counter == 1 + # remove route and update available counter + ps._del("2001::/64") + dvs.runcmd("ip -6 neigh del fc00::2 lladdr 11:22:33:44:55:66 dev Ethernet0") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_ROUTE_ENTRY', '1000') - # remove route and update available counter - ps._del("2001::/64") - dvs.runcmd("ip -6 neigh del fc00::2 lladdr 11:22:33:44:55:66 dev Ethernet0") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_ROUTE_ENTRY', '1000') + time.sleep(2) - time.sleep(2) + # get counters + new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_route_used') + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_route_available') - # get counters - new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_route_used') - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_route_available') + assert new_used_counter == used_counter + assert new_avail_counter == avail_counter - assert new_used_counter == used_counter - assert new_avail_counter == avail_counter + intf_tbl._del("Ethernet0|fc00::1/126") + time.sleep(2) - intf_tbl._del("Ethernet0|fc00::1/126") - time.sleep(2) + def test_CrmIpv4Nexthop(self, dvs, testlog): -def test_CrmIpv4Nexthop(dvs, testlog): + config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + intf_tbl = swsscommon.Table(config_db, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) + intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) + intf_tbl.set("Ethernet0", fvs) + dvs.runcmd("ifconfig Ethernet0 up") - config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) - intf_tbl = swsscommon.Table(config_db, "INTERFACE") - fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) - intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) - intf_tbl.set("Ethernet0", fvs) - dvs.runcmd("ifconfig Ethernet0 up") + dvs.runcmd("crm config polling interval 1") - dvs.runcmd("crm config polling interval 1") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEXTHOP_ENTRY', '1000') - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEXTHOP_ENTRY', '1000') + time.sleep(2) - time.sleep(2) + # get counters + used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_nexthop_used') + avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_nexthop_available') - # get counters - used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_nexthop_used') - avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_nexthop_available') + # add nexthop and update available counter + dvs.runcmd("ip neigh replace 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEXTHOP_ENTRY', '999') - # add nexthop and update available counter - dvs.runcmd("ip neigh replace 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEXTHOP_ENTRY', '999') + time.sleep(2) - time.sleep(2) + # get counters + new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_nexthop_used') + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_nexthop_available') - # get counters - new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_nexthop_used') - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_nexthop_available') + assert new_used_counter - used_counter == 1 + assert avail_counter - new_avail_counter == 1 - assert new_used_counter - used_counter == 1 - assert avail_counter - new_avail_counter == 1 + # remove nexthop and update available counter + dvs.runcmd("ip neigh del 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEXTHOP_ENTRY', '1000') - # remove nexthop and update available counter - dvs.runcmd("ip neigh del 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEXTHOP_ENTRY', '1000') + time.sleep(2) - time.sleep(2) + # get counters + new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_nexthop_used') + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_nexthop_available') - # get counters - new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_nexthop_used') - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_nexthop_available') + assert new_used_counter == used_counter + assert new_avail_counter == avail_counter - assert new_used_counter == used_counter - assert new_avail_counter == avail_counter + intf_tbl._del("Ethernet0|10.0.0.0/31") + time.sleep(2) - intf_tbl._del("Ethernet0|10.0.0.0/31") - time.sleep(2) + def test_CrmIpv6Nexthop(self, dvs, testlog): -def test_CrmIpv6Nexthop(dvs, testlog): + # Enable IPv6 routing + dvs.runcmd("sysctl net.ipv6.conf.all.disable_ipv6=0") + time.sleep(2) - # Enable IPv6 routing - dvs.runcmd("sysctl net.ipv6.conf.all.disable_ipv6=0") - time.sleep(2) + config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + intf_tbl = swsscommon.Table(config_db, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) + intf_tbl.set("Ethernet0", fvs) + intf_tbl.set("Ethernet0|fc00::1/126", fvs) + dvs.runcmd("ifconfig Ethernet0 up") - config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) - intf_tbl = swsscommon.Table(config_db, "INTERFACE") - fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) - intf_tbl.set("Ethernet0", fvs) - intf_tbl.set("Ethernet0|fc00::1/126", fvs) - dvs.runcmd("ifconfig Ethernet0 up") + dvs.runcmd("crm config polling interval 1") - dvs.runcmd("crm config polling interval 1") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEXTHOP_ENTRY', '1000') - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEXTHOP_ENTRY', '1000') + time.sleep(2) - time.sleep(2) + # get counters + used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_nexthop_used') + avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_nexthop_available') - # get counters - used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_nexthop_used') - avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_nexthop_available') + # add nexthop and update available counter + dvs.runcmd("ip -6 neigh replace fc00::2 lladdr 11:22:33:44:55:66 dev Ethernet0") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEXTHOP_ENTRY', '999') - # add nexthop and update available counter - dvs.runcmd("ip -6 neigh replace fc00::2 lladdr 11:22:33:44:55:66 dev Ethernet0") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEXTHOP_ENTRY', '999') + time.sleep(2) - time.sleep(2) + # get counters + new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_nexthop_used') + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_nexthop_available') - # get counters - new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_nexthop_used') - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_nexthop_available') + assert new_used_counter - used_counter == 1 + assert avail_counter - new_avail_counter == 1 - assert new_used_counter - used_counter == 1 - assert avail_counter - new_avail_counter == 1 + # remove nexthop and update available counter + dvs.runcmd("ip -6 neigh del fc00::2 lladdr 11:22:33:44:55:66 dev Ethernet0") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEXTHOP_ENTRY', '1000') - # remove nexthop and update available counter - dvs.runcmd("ip -6 neigh del fc00::2 lladdr 11:22:33:44:55:66 dev Ethernet0") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEXTHOP_ENTRY', '1000') + time.sleep(2) - time.sleep(2) + # get counters + new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_nexthop_used') + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_nexthop_available') - # get counters - new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_nexthop_used') - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_nexthop_available') + assert new_used_counter == used_counter + assert new_avail_counter == avail_counter - assert new_used_counter == used_counter - assert new_avail_counter == avail_counter + intf_tbl._del("Ethernet0|fc00::1/126") + time.sleep(2) - intf_tbl._del("Ethernet0|fc00::1/126") - time.sleep(2) + def test_CrmIpv4Neighbor(self, dvs, testlog): -def test_CrmIpv4Neighbor(dvs, testlog): + config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + intf_tbl = swsscommon.Table(config_db, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) + intf_tbl.set("Ethernet0", fvs) + intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) + dvs.runcmd("ifconfig Ethernet0 up") - config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) - intf_tbl = swsscommon.Table(config_db, "INTERFACE") - fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) - intf_tbl.set("Ethernet0", fvs) - intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) - dvs.runcmd("ifconfig Ethernet0 up") + dvs.runcmd("crm config polling interval 1") - dvs.runcmd("crm config polling interval 1") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEIGHBOR_ENTRY', '1000') - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEIGHBOR_ENTRY', '1000') + time.sleep(2) - time.sleep(2) + # get counters + used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_neighbor_used') + avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_neighbor_available') - # get counters - used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_neighbor_used') - avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_neighbor_available') + # add neighbor and update available counter + dvs.runcmd("ip neigh replace 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEIGHBOR_ENTRY', '999') - # add neighbor and update available counter - dvs.runcmd("ip neigh replace 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEIGHBOR_ENTRY', '999') + time.sleep(2) - time.sleep(2) + # get counters + new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_neighbor_used') + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_neighbor_available') - # get counters - new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_neighbor_used') - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_neighbor_available') + assert new_used_counter - used_counter == 1 + assert avail_counter - new_avail_counter == 1 - assert new_used_counter - used_counter == 1 - assert avail_counter - new_avail_counter == 1 + # remove neighbor and update available counter + dvs.runcmd("ip neigh del 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEIGHBOR_ENTRY', '1000') - # remove neighbor and update available counter - dvs.runcmd("ip neigh del 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEIGHBOR_ENTRY', '1000') + time.sleep(2) - time.sleep(2) + # get counters + new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_neighbor_used') + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_neighbor_available') - # get counters - new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_neighbor_used') - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_neighbor_available') + assert new_used_counter == used_counter + assert new_avail_counter == avail_counter - assert new_used_counter == used_counter - assert new_avail_counter == avail_counter + intf_tbl._del("Ethernet0|10.0.0.0/31") + time.sleep(2) - intf_tbl._del("Ethernet0|10.0.0.0/31") - time.sleep(2) + def test_CrmIpv6Neighbor(self, dvs, testlog): -def test_CrmIpv6Neighbor(dvs, testlog): + # Enable IPv6 routing + dvs.runcmd("sysctl net.ipv6.conf.all.disable_ipv6=0") + time.sleep(2) - # Enable IPv6 routing - dvs.runcmd("sysctl net.ipv6.conf.all.disable_ipv6=0") - time.sleep(2) + config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + intf_tbl = swsscommon.Table(config_db, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) + intf_tbl.set("Ethernet0", fvs) + intf_tbl.set("Ethernet0|fc00::1/126", fvs) + dvs.runcmd("ifconfig Ethernet0 up") - config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) - intf_tbl = swsscommon.Table(config_db, "INTERFACE") - fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) - intf_tbl.set("Ethernet0", fvs) - intf_tbl.set("Ethernet0|fc00::1/126", fvs) - dvs.runcmd("ifconfig Ethernet0 up") + dvs.runcmd("crm config polling interval 1") - dvs.runcmd("crm config polling interval 1") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEIGHBOR_ENTRY', '1000') - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEIGHBOR_ENTRY', '1000') + time.sleep(2) - time.sleep(2) + # get counters + used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_neighbor_used') + avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_neighbor_available') - # get counters - used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_neighbor_used') - avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_neighbor_available') + # add neighbor and update available counter + dvs.runcmd("ip -6 neigh replace fc00::2 lladdr 11:22:33:44:55:66 dev Ethernet0") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEIGHBOR_ENTRY', '999') - # add neighbor and update available counter - dvs.runcmd("ip -6 neigh replace fc00::2 lladdr 11:22:33:44:55:66 dev Ethernet0") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEIGHBOR_ENTRY', '999') + time.sleep(2) - time.sleep(2) + # get counters + new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_neighbor_used') + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_neighbor_available') - # get counters - new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_neighbor_used') - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_neighbor_available') + assert new_used_counter - used_counter == 1 + assert avail_counter - new_avail_counter == 1 - assert new_used_counter - used_counter == 1 - assert avail_counter - new_avail_counter == 1 + # remove neighbor and update available counter + dvs.runcmd("ip -6 neigh del fc00::2 lladdr 11:22:33:44:55:66 dev Ethernet0") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEIGHBOR_ENTRY', '1000') - # remove neighbor and update available counter - dvs.runcmd("ip -6 neigh del fc00::2 lladdr 11:22:33:44:55:66 dev Ethernet0") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEIGHBOR_ENTRY', '1000') + time.sleep(2) - time.sleep(2) + # get counters + new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_neighbor_used') + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_neighbor_available') - # get counters - new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_neighbor_used') - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_neighbor_available') + assert new_used_counter == used_counter + assert new_avail_counter == avail_counter - assert new_used_counter == used_counter - assert new_avail_counter == avail_counter + intf_tbl._del("Ethernet0|fc00::1/126") + time.sleep(2) - intf_tbl._del("Ethernet0|fc00::1/126") - time.sleep(2) + def test_CrmNexthopGroup(self, dvs, testlog): -def test_CrmNexthopGroup(dvs, testlog): + config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + intf_tbl = swsscommon.Table(config_db, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) + intf_tbl.set("Ethernet0", fvs) + intf_tbl.set("Ethernet4", fvs) + intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) + intf_tbl.set("Ethernet4|10.0.0.2/31", fvs) + dvs.runcmd("ifconfig Ethernet0 up") + dvs.runcmd("ifconfig Ethernet4 up") - config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) - intf_tbl = swsscommon.Table(config_db, "INTERFACE") - fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) - intf_tbl.set("Ethernet0", fvs) - intf_tbl.set("Ethernet4", fvs) - intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) - intf_tbl.set("Ethernet4|10.0.0.2/31", fvs) - dvs.runcmd("ifconfig Ethernet0 up") - dvs.runcmd("ifconfig Ethernet4 up") + dvs.runcmd("crm config polling interval 1") - dvs.runcmd("crm config polling interval 1") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_ENTRY', '1000') - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_ENTRY', '1000') + # add neighbors + dvs.runcmd("ip neigh replace 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") + dvs.runcmd("ip neigh replace 10.0.0.3 lladdr 11:22:33:44:55:66 dev Ethernet4") - # add neighbors - dvs.runcmd("ip neigh replace 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") - dvs.runcmd("ip neigh replace 10.0.0.3 lladdr 11:22:33:44:55:66 dev Ethernet4") + db = swsscommon.DBConnector(0, dvs.redis_sock, 0) + ps = swsscommon.ProducerStateTable(db, "ROUTE_TABLE") + fvs = swsscommon.FieldValuePairs([("nexthop","10.0.0.1,10.0.0.3"), ("ifname", "Ethernet0,Ethernet4")]) - db = swsscommon.DBConnector(0, dvs.redis_sock, 0) - ps = swsscommon.ProducerStateTable(db, "ROUTE_TABLE") - fvs = swsscommon.FieldValuePairs([("nexthop","10.0.0.1,10.0.0.3"), ("ifname", "Ethernet0,Ethernet4")]) + time.sleep(2) - time.sleep(2) + # get counters + used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_used') + avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_available') - # get counters - used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_used') - avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_available') + # add route and update available counter + ps.set("2.2.2.0/24", fvs) + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_ENTRY', '999') - # add route and update available counter - ps.set("2.2.2.0/24", fvs) - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_ENTRY', '999') + time.sleep(2) - time.sleep(2) + # get counters + new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_used') + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_available') - # get counters - new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_used') - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_available') + assert new_used_counter - used_counter == 1 + assert avail_counter - new_avail_counter == 1 - assert new_used_counter - used_counter == 1 - assert avail_counter - new_avail_counter == 1 + # remove route and update available counter + ps._del("2.2.2.0/24") + dvs.runcmd("ip neigh del 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") + dvs.runcmd("ip neigh del 10.0.0.3 lladdr 11:22:33:44:55:66 dev Ethernet4") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_ENTRY', '1000') - # remove route and update available counter - ps._del("2.2.2.0/24") - dvs.runcmd("ip neigh del 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") - dvs.runcmd("ip neigh del 10.0.0.3 lladdr 11:22:33:44:55:66 dev Ethernet4") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_ENTRY', '1000') + time.sleep(2) - time.sleep(2) + # get counters + new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_used') + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_available') - # get counters - new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_used') - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_available') + assert new_used_counter == used_counter + assert new_avail_counter == avail_counter - assert new_used_counter == used_counter - assert new_avail_counter == avail_counter + intf_tbl._del("Ethernet0|10.0.0.0/31") + intf_tbl._del("Ethernet4|10.0.0.2/31") + time.sleep(2) - intf_tbl._del("Ethernet0|10.0.0.0/31") - intf_tbl._del("Ethernet4|10.0.0.2/31") - time.sleep(2) + def test_CrmNexthopGroupMember(self, dvs, testlog): -def test_CrmNexthopGroupMember(dvs, testlog): + # down, then up to generate port up signal + dvs.servers[0].runcmd("ip link set down dev eth0") == 0 + dvs.servers[1].runcmd("ip link set down dev eth0") == 0 + dvs.servers[0].runcmd("ip link set up dev eth0") == 0 + dvs.servers[1].runcmd("ip link set up dev eth0") == 0 - # down, then up to generate port up signal - dvs.servers[0].runcmd("ip link set down dev eth0") == 0 - dvs.servers[1].runcmd("ip link set down dev eth0") == 0 - dvs.servers[0].runcmd("ip link set up dev eth0") == 0 - dvs.servers[1].runcmd("ip link set up dev eth0") == 0 + config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + intf_tbl = swsscommon.Table(config_db, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) + intf_tbl.set("Ethernet0", fvs) + intf_tbl.set("Ethernet4", fvs) + intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) + intf_tbl.set("Ethernet4|10.0.0.2/31", fvs) + dvs.runcmd("ifconfig Ethernet0 up") + dvs.runcmd("ifconfig Ethernet4 up") - config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) - intf_tbl = swsscommon.Table(config_db, "INTERFACE") - fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) - intf_tbl.set("Ethernet0", fvs) - intf_tbl.set("Ethernet4", fvs) - intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) - intf_tbl.set("Ethernet4|10.0.0.2/31", fvs) - dvs.runcmd("ifconfig Ethernet0 up") - dvs.runcmd("ifconfig Ethernet4 up") + dvs.runcmd("crm config polling interval 1") - dvs.runcmd("crm config polling interval 1") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_MEMBER_ENTRY', '1000') - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_MEMBER_ENTRY', '1000') + # add neighbors + dvs.runcmd("ip neigh replace 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") + dvs.runcmd("ip neigh replace 10.0.0.3 lladdr 11:22:33:44:55:66 dev Ethernet4") - # add neighbors - dvs.runcmd("ip neigh replace 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") - dvs.runcmd("ip neigh replace 10.0.0.3 lladdr 11:22:33:44:55:66 dev Ethernet4") + db = swsscommon.DBConnector(0, dvs.redis_sock, 0) + ps = swsscommon.ProducerStateTable(db, "ROUTE_TABLE") + fvs = swsscommon.FieldValuePairs([("nexthop","10.0.0.1,10.0.0.3"), ("ifname", "Ethernet0,Ethernet4")]) - db = swsscommon.DBConnector(0, dvs.redis_sock, 0) - ps = swsscommon.ProducerStateTable(db, "ROUTE_TABLE") - fvs = swsscommon.FieldValuePairs([("nexthop","10.0.0.1,10.0.0.3"), ("ifname", "Ethernet0,Ethernet4")]) + time.sleep(2) - time.sleep(2) + # get counters + used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_member_used') + avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_member_available') - # get counters - used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_member_used') - avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_member_available') + # add route and update available counter + ps.set("2.2.2.0/24", fvs) + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_MEMBER_ENTRY', '998') - # add route and update available counter - ps.set("2.2.2.0/24", fvs) - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_MEMBER_ENTRY', '998') + time.sleep(2) - time.sleep(2) + # get counters + new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_member_used') + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_member_available') - # get counters - new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_member_used') - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_member_available') + assert new_used_counter - used_counter == 2 + assert avail_counter - new_avail_counter == 2 - assert new_used_counter - used_counter == 2 - assert avail_counter - new_avail_counter == 2 + # remove route and update available counter + ps._del("2.2.2.0/24") + dvs.runcmd("ip neigh del 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") + dvs.runcmd("ip neigh del 10.0.0.3 lladdr 11:22:33:44:55:66 dev Ethernet4") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_MEMBER_ENTRY', '1000') - # remove route and update available counter - ps._del("2.2.2.0/24") - dvs.runcmd("ip neigh del 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") - dvs.runcmd("ip neigh del 10.0.0.3 lladdr 11:22:33:44:55:66 dev Ethernet4") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_MEMBER_ENTRY', '1000') + time.sleep(2) - time.sleep(2) + # get counters + new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_member_used') + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_member_available') - # get counters - new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_member_used') - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_member_available') + assert new_used_counter == used_counter + assert new_avail_counter == avail_counter - assert new_used_counter == used_counter - assert new_avail_counter == avail_counter + intf_tbl._del("Ethernet0|10.0.0.0/31") + intf_tbl._del("Ethernet4|10.0.0.2/31") + time.sleep(2) - intf_tbl._del("Ethernet0|10.0.0.0/31") - intf_tbl._del("Ethernet4|10.0.0.2/31") - time.sleep(2) + def test_CrmAcl(self, dvs, testlog): -def test_CrmAcl(dvs, testlog): + db = swsscommon.DBConnector(4, dvs.redis_sock, 0) + adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) - db = swsscommon.DBConnector(4, dvs.redis_sock, 0) - adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) + dvs.runcmd("crm config polling interval 1") + time.sleep(1) - dvs.runcmd("crm config polling interval 1") - time.sleep(1) + bind_ports = ["Ethernet0", "Ethernet4"] - bind_ports = ["Ethernet0", "Ethernet4"] + old_table_used_counter = getCrmCounterValue(dvs, 'ACL_STATS:INGRESS:PORT', 'crm_stats_acl_table_used') - old_table_used_counter = getCrmCounterValue(dvs, 'ACL_STATS:INGRESS:PORT', 'crm_stats_acl_table_used') + # create ACL table + ttbl = swsscommon.Table(db, "ACL_TABLE") + fvs = swsscommon.FieldValuePairs([("policy_desc", "test"), ("type", "L3"), ("ports", ",".join(bind_ports))]) + ttbl.set("test", fvs) - # create ACL table - ttbl = swsscommon.Table(db, "ACL_TABLE") - fvs = swsscommon.FieldValuePairs([("policy_desc", "test"), ("type", "L3"), ("ports", ",".join(bind_ports))]) - ttbl.set("test", fvs) + # create ACL rule + rtbl = swsscommon.Table(db, "ACL_RULE") + fvs = swsscommon.FieldValuePairs([("priority", "55"), ("PACKET_ACTION", "FORWARD"), ("L4_SRC_PORT", "65000")]) + rtbl.set("test|acl_test_rule", fvs) - # create ACL rule - rtbl = swsscommon.Table(db, "ACL_RULE") - fvs = swsscommon.FieldValuePairs([("priority", "55"), ("PACKET_ACTION", "FORWARD"), ("L4_SRC_PORT", "65000")]) - rtbl.set("test|acl_test_rule", fvs) + time.sleep(2) - time.sleep(2) - - new_table_used_counter = getCrmCounterValue(dvs, 'ACL_STATS:INGRESS:PORT', 'crm_stats_acl_table_used') - table_used_counter = new_table_used_counter - old_table_used_counter - assert table_used_counter == 1 + new_table_used_counter = getCrmCounterValue(dvs, 'ACL_STATS:INGRESS:PORT', 'crm_stats_acl_table_used') + table_used_counter = new_table_used_counter - old_table_used_counter + assert table_used_counter == 1 - # get ACL table key - atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_ACL_TABLE") - acl_tables = [k for k in atbl.getKeys() if k not in dvs.asicdb.default_acl_tables] - key = "ACL_TABLE_STATS:{0}".format(acl_tables[0].replace('oid:', '')) + # get ACL table key + atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_ACL_TABLE") + acl_tables = [k for k in atbl.getKeys() if k not in dvs.asicdb.default_acl_tables] + key = "ACL_TABLE_STATS:{0}".format(acl_tables[0].replace('oid:', '')) - entry_used_counter = getCrmCounterValue(dvs, key, 'crm_stats_acl_entry_used') - assert entry_used_counter == 1 + entry_used_counter = getCrmCounterValue(dvs, key, 'crm_stats_acl_entry_used') + assert entry_used_counter == 1 - cnt_used_counter = getCrmCounterValue(dvs, key, 'crm_stats_acl_counter_used') - assert entry_used_counter == 1 + cnt_used_counter = getCrmCounterValue(dvs, key, 'crm_stats_acl_counter_used') + assert entry_used_counter == 1 - # remove ACL rule - rtbl._del("test|acl_test_rule") + # remove ACL rule + rtbl._del("test|acl_test_rule") - time.sleep(2) + time.sleep(2) - entry_used_counter = getCrmCounterValue(dvs, key, 'crm_stats_acl_entry_used') - assert entry_used_counter == 0 + entry_used_counter = getCrmCounterValue(dvs, key, 'crm_stats_acl_entry_used') + assert entry_used_counter == 0 - cnt_used_counter = getCrmCounterValue(dvs, key, 'crm_stats_acl_counter_used') - assert cnt_used_counter == 0 + cnt_used_counter = getCrmCounterValue(dvs, key, 'crm_stats_acl_counter_used') + assert cnt_used_counter == 0 - # remove ACL table - ttbl._del("test") + # remove ACL table + ttbl._del("test") - time.sleep(2) + time.sleep(2) - new_table_used_counter = getCrmCounterValue(dvs, 'ACL_STATS:INGRESS:PORT', 'crm_stats_acl_table_used') - table_used_counter = new_table_used_counter - old_table_used_counter - assert table_used_counter == 0 + new_table_used_counter = getCrmCounterValue(dvs, 'ACL_STATS:INGRESS:PORT', 'crm_stats_acl_table_used') + table_used_counter = new_table_used_counter - old_table_used_counter + assert table_used_counter == 0 - counters_db = swsscommon.DBConnector(swsscommon.COUNTERS_DB, dvs.redis_sock, 0) - crm_stats_table = swsscommon.Table(counters_db, 'CRM') - keys = crm_stats_table.getKeys() - assert key not in keys + counters_db = swsscommon.DBConnector(swsscommon.COUNTERS_DB, dvs.redis_sock, 0) + crm_stats_table = swsscommon.Table(counters_db, 'CRM') + keys = crm_stats_table.getKeys() + assert key not in keys diff --git a/tests/test_dirbcast.py b/tests/test_dirbcast.py index 12068812ca0..4f966d44cd9 100644 --- a/tests/test_dirbcast.py +++ b/tests/test_dirbcast.py @@ -3,90 +3,91 @@ import re import json -def test_DirectedBroadcast(dvs, testlog): +class TestDirectedBroadcast(object): + def test_DirectedBroadcast(self, dvs, testlog): - db = swsscommon.DBConnector(4, dvs.redis_sock, 0) - adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) + db = swsscommon.DBConnector(4, dvs.redis_sock, 0) + adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) - # create vlan in config db - tbl = swsscommon.Table(db, "VLAN") - fvs = swsscommon.FieldValuePairs([("vlanid", "100")]) - tbl.set("Vlan100", fvs) + # create vlan in config db + tbl = swsscommon.Table(db, "VLAN") + fvs = swsscommon.FieldValuePairs([("vlanid", "100")]) + tbl.set("Vlan100", fvs) - # create a vlan member in config db - tbl = swsscommon.Table(db, "VLAN_MEMBER") - fvs = swsscommon.FieldValuePairs([("tagging_mode", "tagged")]) - tbl.set("Vlan100|Ethernet24", fvs) + # create a vlan member in config db + tbl = swsscommon.Table(db, "VLAN_MEMBER") + fvs = swsscommon.FieldValuePairs([("tagging_mode", "tagged")]) + tbl.set("Vlan100|Ethernet24", fvs) - time.sleep(1) + time.sleep(1) - # create vlan interface in config db - tbl = swsscommon.Table(db, "VLAN_INTERFACE") - fvs = swsscommon.FieldValuePairs([("family", "IPv4")]) - tbl.set("Vlan100", fvs) - tbl.set("Vlan100|192.169.0.1/27", fvs) + # create vlan interface in config db + tbl = swsscommon.Table(db, "VLAN_INTERFACE") + fvs = swsscommon.FieldValuePairs([("family", "IPv4")]) + tbl.set("Vlan100", fvs) + tbl.set("Vlan100|192.169.0.1/27", fvs) - time.sleep(1) + time.sleep(1) - # check vlan in asic db - atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") - keys = atbl.getKeys() - vlan_oid = None + # check vlan in asic db + atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + keys = atbl.getKeys() + vlan_oid = None - for key in keys: - if key == dvs.asicdb.default_vlan_id: - continue + for key in keys: + if key == dvs.asicdb.default_vlan_id: + continue - (status, fvs) = atbl.get(key) - assert status == True + (status, fvs) = atbl.get(key) + assert status == True - if fvs[0][0] == "SAI_VLAN_ATTR_VLAN_ID": - assert fvs[0][1] == '100' - vlan_oid = key + if fvs[0][0] == "SAI_VLAN_ATTR_VLAN_ID": + assert fvs[0][1] == '100' + vlan_oid = key - assert vlan_oid != None + assert vlan_oid != None - # check router interface in asic db - atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE") - keys = atbl.getKeys() - rif_oid = None + # check router interface in asic db + atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE") + keys = atbl.getKeys() + rif_oid = None - for key in keys: - (status, fvs) = atbl.get(key) - assert status == True - for fv in fvs: - if fv[0] == "SAI_ROUTER_INTERFACE_ATTR_VLAN_ID": - assert vlan_oid == fv[1] - rif_oid = key + for key in keys: + (status, fvs) = atbl.get(key) + assert status == True + for fv in fvs: + if fv[0] == "SAI_ROUTER_INTERFACE_ATTR_VLAN_ID": + assert vlan_oid == fv[1] + rif_oid = key - assert rif_oid != None + assert rif_oid != None - # check neighbor entry in asic db - atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY") - keys = atbl.getKeys() - dir_bcast = False + # check neighbor entry in asic db + atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY") + keys = atbl.getKeys() + dir_bcast = False - for key in keys: - neigh = json.loads(key) + for key in keys: + neigh = json.loads(key) - if neigh['ip'] == "192.169.0.31": - dir_bcast = True - assert neigh['rif'] == rif_oid - (status, fvs) = atbl.get(key) - assert status == True - if fvs[0][0] == "SAI_NEIGHBOR_ENTRY_ATTR_DST_MAC_ADDRESS": - assert fvs[0][1] == "FF:FF:FF:FF:FF:FF" + if neigh['ip'] == "192.169.0.31": + dir_bcast = True + assert neigh['rif'] == rif_oid + (status, fvs) = atbl.get(key) + assert status == True + if fvs[0][0] == "SAI_NEIGHBOR_ENTRY_ATTR_DST_MAC_ADDRESS": + assert fvs[0][1] == "FF:FF:FF:FF:FF:FF" - assert dir_bcast + assert dir_bcast - # Explicitly add a neighbor entry with BCAST MAC and check if its in ASIC_DB - dvs.runcmd("ip neigh replace 192.169.0.30 lladdr FF:FF:FF:FF:FF:FF dev Vlan100") + # Explicitly add a neighbor entry with BCAST MAC and check if its in ASIC_DB + dvs.runcmd("ip neigh replace 192.169.0.30 lladdr FF:FF:FF:FF:FF:FF dev Vlan100") - time.sleep(1) + time.sleep(1) - keys = atbl.getKeys() - for key in keys: - neigh = json.loads(key) + keys = atbl.getKeys() + for key in keys: + neigh = json.loads(key) - if neigh['ip'] == "192.169.0.30": - assert False + if neigh['ip'] == "192.169.0.30": + assert False diff --git a/tests/test_fdb.py b/tests/test_fdb.py new file mode 100644 index 00000000000..4e714d2021b --- /dev/null +++ b/tests/test_fdb.py @@ -0,0 +1,374 @@ +from swsscommon import swsscommon +import os +import sys +import time +import json +from distutils.version import StrictVersion + +def create_entry(tbl, key, pairs): + fvs = swsscommon.FieldValuePairs(pairs) + tbl.set(key, fvs) + + # FIXME: better to wait until DB create them + time.sleep(1) + +def create_entry_tbl(db, table, key, pairs): + tbl = swsscommon.Table(db, table) + create_entry(tbl, key, pairs) + +def create_entry_pst(db, table, key, pairs): + tbl = swsscommon.ProducerStateTable(db, table) + create_entry(tbl, key, pairs) + +def how_many_entries_exist(db, table): + tbl = swsscommon.Table(db, table) + return len(tbl.getKeys()) + +class TestFdb(object): + def test_FdbWarmRestartNotifications(self, dvs, testlog): + dvs.setup_db() + + dvs.runcmd("sonic-clear fdb all") + + dvs.runcmd("crm config polling interval 1") + dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY', '1000') + + time.sleep(2) + counter_before = dvs.getCrmCounterValue('STATS', 'crm_stats_fdb_entry_used') + + # create vlan; create vlan member + dvs.create_vlan("6") + dvs.create_vlan_member("6", "Ethernet64") + dvs.create_vlan_member("6", "Ethernet68") + + # Put Ethernet72 and Ethernet76 into vlan 7 in untagged mode, they will have pvid of 7 + # and into vlan8 in tagged mode + dvs.create_vlan("7") + dvs.create_vlan_member("7", "Ethernet72") + dvs.create_vlan_member("7", "Ethernet76") + + dvs.create_vlan("8") + dvs.create_vlan_member_tagged("8", "Ethernet72") + dvs.create_vlan_member_tagged("8", "Ethernet76") + + + # Get mapping between interface name and its bridge port_id + time.sleep(2) + iface_2_bridge_port_id = dvs.get_map_iface_bridge_port_id(dvs.adb) + + # check FDB learning mode + ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', + iface_2_bridge_port_id["Ethernet64"], + [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")]) + assert ok, str(extra) + ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', + iface_2_bridge_port_id["Ethernet68"], + [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")]) + assert ok, str(extra) + + ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', + iface_2_bridge_port_id["Ethernet72"], + [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")]) + assert ok, str(extra) + + ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', + iface_2_bridge_port_id["Ethernet76"], + [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")]) + assert ok, str(extra) + + # check fdb aging attr + ok, extra = dvs.all_table_entry_has_no(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_SWITCH', + ".*", + ["SAI_SWITCH_ATTR_FDB_AGING_TIME"]) + + # bring up vlan and member + dvs.set_interface_status("Vlan6", "up") + dvs.set_interface_status("Vlan7", "up") + dvs.set_interface_status("Vlan8", "up") + + dvs.add_ip_address("Vlan6", "6.6.6.1/24") + dvs.add_ip_address("Vlan7", "7.7.7.1/24") + dvs.add_ip_address("Vlan8", "8.8.8.1/24") + + dvs.set_interface_status("Ethernet64", "up") + dvs.set_interface_status("Ethernet68", "up") + dvs.set_interface_status("Ethernet72", "up") + dvs.set_interface_status("Ethernet76", "up") + dvs.servers[16].runcmd("ifconfig eth0 6.6.6.6/24 up") + dvs.servers[16].runcmd("ip route add default via 6.6.6.1") + dvs.servers[17].runcmd("ifconfig eth0 6.6.6.7/24 up") + dvs.servers[17].runcmd("ip route add default via 6.6.6.1") + + dvs.servers[18].runcmd("vconfig add eth0 8") + dvs.servers[18].runcmd("ifconfig eth0.8 8.8.8.6/24 up") + dvs.servers[18].runcmd("ip route add default via 8.8.8.1") + + dvs.servers[19].runcmd("vconfig add eth0 8") + dvs.servers[19].runcmd("ifconfig eth0.8 8.8.8.7/24 up") + dvs.servers[19].runcmd("ip route add default via 8.8.8.1") + + dvs.servers[18].runcmd("ifconfig eth0 7.7.7.6/24 up") + dvs.servers[18].runcmd("ip route add default via 7.7.7.1") + dvs.servers[19].runcmd("ifconfig eth0 7.7.7.7/24 up") + dvs.servers[19].runcmd("ip route add default via 7.7.7.1") + + # get neighbor and arp entry + time.sleep(2) + rc = dvs.servers[16].runcmd("ping -c 1 6.6.6.7") + assert rc == 0 + rc = dvs.servers[17].runcmd("ping -c 1 6.6.6.6") + assert rc == 0 + + # get neighbor and arp entry + time.sleep(2) + rc = dvs.servers[18].runcmd("ping -c 1 8.8.8.7") + assert rc == 0 + rc = dvs.servers[19].runcmd("ping -c 1 8.8.8.6") + assert rc == 0 + + time.sleep(2) + rc = dvs.servers[18].runcmd("ping -c 1 -I 7.7.7.6 7.7.7.7") + assert rc == 0 + rc = dvs.servers[19].runcmd("ping -c 1 -I 7.7.7.7 7.7.7.6") + assert rc == 0 + + # check that the FDB entries were inserted into ASIC DB + ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", + [], + [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), + ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet64"]), + ] + ) + assert ok, str(extra) + ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", + [], + [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), + ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet68"]), + ] + ) + assert ok, str(extra) + + ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", + [], + [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), + ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet72"]), + ] + ) + assert ok, str(extra) + ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", + [], + [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), + ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet76"]), + ] + ) + assert ok, str(extra) + + time.sleep(2) + counter_inserted = dvs.getCrmCounterValue('STATS', 'crm_stats_fdb_entry_used') + # vlan 6: Ethernet64, Ethernet68; + # vlan 7: Ethernet72, Ethernet76; + # vlan 8 (tagged): Ethernet72, Ethernet76; + # 6 FDB entries wil be created in total + assert counter_inserted - counter_before == 6 + + # check that the FDB entries were inserted into State DB for Ethernet64, Ethernet68 with Vlan6 + ok, extra = dvs.is_table_entry_exists(dvs.sdb, "FDB_TABLE", + "Vlan6:.*", + [("port", "Ethernet64"), + ("type", "dynamic"), + ] + ) + assert ok, str(extra) + ok, extra = dvs.is_table_entry_exists(dvs.sdb, "FDB_TABLE", + "Vlan6:*", + [("port", "Ethernet68"), + ("type", "dynamic"), + ] + ) + assert ok, str(extra) + + # check that the FDB entries were inserted into State DB, + # Vlan7(untagged) in the key for Ethernet72, Ethernet76 + ok, extra = dvs.is_table_entry_exists(dvs.sdb, "FDB_TABLE", + "Vlan7:.*", + [("port", "Ethernet72"), + ("type", "dynamic"), + ] + ) + assert ok, str(extra) + ok, extra = dvs.is_table_entry_exists(dvs.sdb, "FDB_TABLE", + "Vlan7:*", + [("port", "Ethernet76"), + ("type", "dynamic"), + ] + ) + assert ok, str(extra) + + # check that the FDB entries were inserted into State DB, + # Vlan8 (tagged) in the key for Ethernet72, Ethernet76 + ok, extra = dvs.is_table_entry_exists(dvs.sdb, "FDB_TABLE", + "Vlan8:.*", + [("port", "Ethernet72"), + ("type", "dynamic"), + ] + ) + assert ok, str(extra) + ok, extra = dvs.is_table_entry_exists(dvs.sdb, "FDB_TABLE", + "Vlan8:*", + [("port", "Ethernet76"), + ("type", "dynamic"), + ] + ) + assert ok, str(extra) + + # enable warm restart + (exitcode, result) = dvs.runcmd("config warm_restart enable swss") + assert exitcode == 0 + + # freeze orchagent for warm restart + (exitcode, result) = dvs.runcmd("/usr/bin/orchagent_restart_check") + assert result == "RESTARTCHECK succeeded\n" + time.sleep(2) + + try: + # restart orchagent + dvs.stop_swss() + + # check FDB learning mode + ok, extra = dvs.all_table_entry_has(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', + ".*", + [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_DISABLE")]) + assert ok, str(extra) + # check FDB aging time + ok, extra = dvs.all_table_entry_has(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_SWITCH', + ".*", + [("SAI_SWITCH_ATTR_FDB_AGING_TIME", "0")]) + assert ok, str(extra) + + dvs.start_swss() + time.sleep(2) + + # Get mapping between interface name and its bridge port_id + # Note: they are changed + iface_2_bridge_port_id = dvs.get_map_iface_bridge_port_id(dvs.adb) + + # check that the FDB entries were inserted into ASIC DB + ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", + [], + [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), + ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet64"]), + ] + ) + assert ok, str(extra) + ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", + [], + [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), + ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet68"]), + ] + ) + assert ok, str(extra) + + # check that the FDB entries were inserted into ASIC DB + ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", + [], + [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), + ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet72"]), + ] + ) + assert ok, str(extra) + ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", + [], + [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), + ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet76"]), + ] + ) + assert ok, str(extra) + + # check FDB learning mode + ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', + iface_2_bridge_port_id["Ethernet64"], + [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")]) + assert ok, str(extra) + ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', + iface_2_bridge_port_id["Ethernet68"], + [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")]) + assert ok, str(extra) + + ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', + iface_2_bridge_port_id["Ethernet72"], + [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")]) + assert ok, str(extra) + ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', + iface_2_bridge_port_id["Ethernet76"], + [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")]) + assert ok, str(extra) + + time.sleep(2) + counter_restarted = dvs.getCrmCounterValue('STATS', 'crm_stats_fdb_entry_used') + assert counter_inserted == counter_restarted + + # check fdb aging attr + ok, extra = dvs.all_table_entry_has_no(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_SWITCH', + ".*", + ["SAI_SWITCH_ATTR_FDB_AGING_TIME"]) + + finally: + # disable warm restart + dvs.runcmd("config warm_restart disable swss") + # slow down crm polling + dvs.runcmd("crm config polling interval 10000") + + def test_FdbAddedAfterMemberCreated(self, dvs, testlog): + dvs.setup_db() + + dvs.runcmd("sonic-clear fdb all") + time.sleep(2) + + # create a FDB entry in Application DB + create_entry_pst( + dvs.pdb, + "FDB_TABLE", "Vlan2:52-54-00-25-06-E9", + [ + ("port", "Ethernet0"), + ("type", "dynamic"), + ] + ) + + # check that the FDB entry wasn't inserted into ASIC DB + assert how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY") == 0, "The fdb entry leaked to ASIC" + + vlan_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + bp_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") + vm_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + + # create vlan + dvs.create_vlan("2") + dvs.create_vlan_member("2", "Ethernet0") + + # check that the vlan information was propagated + vlan_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + bp_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") + vm_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + + assert vlan_after - vlan_before == 1, "The Vlan2 wasn't created" + assert bp_after - bp_before == 1, "The bridge port wasn't created" + assert vm_after - vm_before == 1, "The vlan member wasn't added" + + # Get mapping between interface name and its bridge port_id + iface_2_bridge_port_id = dvs.get_map_iface_bridge_port_id(dvs.adb) + + # check that the FDB entry was inserted into ASIC DB + assert how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY") == 1, "The fdb entry wasn't inserted to ASIC" + + ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", + [("mac", "52-54-00-25-06-E9"), ("vlan", "2")], + [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), + ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet0"]), + ('SAI_FDB_ENTRY_ATTR_PACKET_ACTION', 'SAI_PACKET_ACTION_FORWARD')] + ) + assert ok, str(extra) + + dvs.runcmd("sonic-clear fdb all") + dvs.remove_vlan_member("2", "Ethernet0") + dvs.remove_vlan("2") + diff --git a/tests/test_fdb_cold.py b/tests/test_fdb_cold.py deleted file mode 100644 index 8ebe7bf8165..00000000000 --- a/tests/test_fdb_cold.py +++ /dev/null @@ -1,80 +0,0 @@ -from swsscommon import swsscommon -import os -import sys -import time -import json -from distutils.version import StrictVersion - -def create_entry(tbl, key, pairs): - fvs = swsscommon.FieldValuePairs(pairs) - tbl.set(key, fvs) - - # FIXME: better to wait until DB create them - time.sleep(1) - -def create_entry_tbl(db, table, key, pairs): - tbl = swsscommon.Table(db, table) - create_entry(tbl, key, pairs) - -def create_entry_pst(db, table, key, pairs): - tbl = swsscommon.ProducerStateTable(db, table) - create_entry(tbl, key, pairs) - -def how_many_entries_exist(db, table): - tbl = swsscommon.Table(db, table) - return len(tbl.getKeys()) - -def test_FDBAddedAfterMemberCreated(dvs, testlog): - dvs.setup_db() - - dvs.runcmd("sonic-clear fdb all") - time.sleep(2) - - # create a FDB entry in Application DB - create_entry_pst( - dvs.pdb, - "FDB_TABLE", "Vlan2:52-54-00-25-06-E9", - [ - ("port", "Ethernet0"), - ("type", "dynamic"), - ] - ) - - # check that the FDB entry wasn't inserted into ASIC DB - assert how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY") == 0, "The fdb entry leaked to ASIC" - - vlan_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") - bp_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") - vm_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") - - # create vlan - dvs.create_vlan("2") - dvs.create_vlan_member("2", "Ethernet0") - - # check that the vlan information was propagated - vlan_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") - bp_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") - vm_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") - - assert vlan_after - vlan_before == 1, "The Vlan2 wasn't created" - assert bp_after - bp_before == 1, "The bridge port wasn't created" - assert vm_after - vm_before == 1, "The vlan member wasn't added" - - # Get mapping between interface name and its bridge port_id - iface_2_bridge_port_id = dvs.get_map_iface_bridge_port_id(dvs.adb) - - # check that the FDB entry was inserted into ASIC DB - assert how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY") == 1, "The fdb entry wasn't inserted to ASIC" - - ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", - [("mac", "52-54-00-25-06-E9"), ("vlan", "2")], - [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), - ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet0"]), - ('SAI_FDB_ENTRY_ATTR_PACKET_ACTION', 'SAI_PACKET_ACTION_FORWARD')] - ) - assert ok, str(extra) - - dvs.runcmd("sonic-clear fdb all") - dvs.remove_vlan_member("2", "Ethernet0") - dvs.remove_vlan("2") - diff --git a/tests/test_fdb_warm.py b/tests/test_fdb_warm.py deleted file mode 100644 index 0754e9628d6..00000000000 --- a/tests/test_fdb_warm.py +++ /dev/null @@ -1,318 +0,0 @@ -from swsscommon import swsscommon -import os -import sys -import time -import json -from distutils.version import StrictVersion - -def create_entry(tbl, key, pairs): - fvs = swsscommon.FieldValuePairs(pairs) - tbl.set(key, fvs) - - # FIXME: better to wait until DB create them - time.sleep(1) - -def create_entry_tbl(db, table, key, pairs): - tbl = swsscommon.Table(db, table) - create_entry(tbl, key, pairs) - -def create_entry_pst(db, table, key, pairs): - tbl = swsscommon.ProducerStateTable(db, table) - create_entry(tbl, key, pairs) - -def how_many_entries_exist(db, table): - tbl = swsscommon.Table(db, table) - return len(tbl.getKeys()) - -def test_fdb_notifications(dvs, testlog): - dvs.setup_db() - - dvs.runcmd("sonic-clear fdb all") - - dvs.runcmd("crm config polling interval 1") - dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY', '1000') - - time.sleep(2) - counter_before = dvs.getCrmCounterValue('STATS', 'crm_stats_fdb_entry_used') - - # create vlan; create vlan member - dvs.create_vlan("6") - dvs.create_vlan_member("6", "Ethernet64") - dvs.create_vlan_member("6", "Ethernet68") - - # Put Ethernet72 and Ethernet76 into vlan 7 in untagged mode, they will have pvid of 7 - # and into vlan8 in tagged mode - dvs.create_vlan("7") - dvs.create_vlan_member("7", "Ethernet72") - dvs.create_vlan_member("7", "Ethernet76") - - dvs.create_vlan("8") - dvs.create_vlan_member_tagged("8", "Ethernet72") - dvs.create_vlan_member_tagged("8", "Ethernet76") - - - # Get mapping between interface name and its bridge port_id - time.sleep(2) - iface_2_bridge_port_id = dvs.get_map_iface_bridge_port_id(dvs.adb) - - # check FDB learning mode - ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', - iface_2_bridge_port_id["Ethernet64"], - [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")]) - assert ok, str(extra) - ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', - iface_2_bridge_port_id["Ethernet68"], - [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")]) - assert ok, str(extra) - - ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', - iface_2_bridge_port_id["Ethernet72"], - [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")]) - assert ok, str(extra) - - ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', - iface_2_bridge_port_id["Ethernet76"], - [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")]) - assert ok, str(extra) - - # check fdb aging attr - ok, extra = dvs.all_table_entry_has_no(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_SWITCH', - ".*", - ["SAI_SWITCH_ATTR_FDB_AGING_TIME"]) - - # bring up vlan and member - dvs.set_interface_status("Vlan6", "up") - dvs.set_interface_status("Vlan7", "up") - dvs.set_interface_status("Vlan8", "up") - - dvs.add_ip_address("Vlan6", "6.6.6.1/24") - dvs.add_ip_address("Vlan7", "7.7.7.1/24") - dvs.add_ip_address("Vlan8", "8.8.8.1/24") - - dvs.set_interface_status("Ethernet64", "up") - dvs.set_interface_status("Ethernet68", "up") - dvs.set_interface_status("Ethernet72", "up") - dvs.set_interface_status("Ethernet76", "up") - dvs.servers[16].runcmd("ifconfig eth0 6.6.6.6/24 up") - dvs.servers[16].runcmd("ip route add default via 6.6.6.1") - dvs.servers[17].runcmd("ifconfig eth0 6.6.6.7/24 up") - dvs.servers[17].runcmd("ip route add default via 6.6.6.1") - - dvs.servers[18].runcmd("vconfig add eth0 8") - dvs.servers[18].runcmd("ifconfig eth0.8 8.8.8.6/24 up") - dvs.servers[18].runcmd("ip route add default via 8.8.8.1") - - dvs.servers[19].runcmd("vconfig add eth0 8") - dvs.servers[19].runcmd("ifconfig eth0.8 8.8.8.7/24 up") - dvs.servers[19].runcmd("ip route add default via 8.8.8.1") - - dvs.servers[18].runcmd("ifconfig eth0 7.7.7.6/24 up") - dvs.servers[18].runcmd("ip route add default via 7.7.7.1") - dvs.servers[19].runcmd("ifconfig eth0 7.7.7.7/24 up") - dvs.servers[19].runcmd("ip route add default via 7.7.7.1") - - # get neighbor and arp entry - time.sleep(2) - rc = dvs.servers[16].runcmd("ping -c 1 6.6.6.7") - assert rc == 0 - rc = dvs.servers[17].runcmd("ping -c 1 6.6.6.6") - assert rc == 0 - - # get neighbor and arp entry - time.sleep(2) - rc = dvs.servers[18].runcmd("ping -c 1 8.8.8.7") - assert rc == 0 - rc = dvs.servers[19].runcmd("ping -c 1 8.8.8.6") - assert rc == 0 - - time.sleep(2) - rc = dvs.servers[18].runcmd("ping -c 1 -I 7.7.7.6 7.7.7.7") - assert rc == 0 - rc = dvs.servers[19].runcmd("ping -c 1 -I 7.7.7.7 7.7.7.6") - assert rc == 0 - - # check that the FDB entries were inserted into ASIC DB - ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", - [], - [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), - ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet64"]), - ] - ) - assert ok, str(extra) - ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", - [], - [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), - ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet68"]), - ] - ) - assert ok, str(extra) - - ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", - [], - [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), - ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet72"]), - ] - ) - assert ok, str(extra) - ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", - [], - [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), - ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet76"]), - ] - ) - assert ok, str(extra) - - time.sleep(2) - counter_inserted = dvs.getCrmCounterValue('STATS', 'crm_stats_fdb_entry_used') - # vlan 6: Ethernet64, Ethernet68; - # vlan 7: Ethernet72, Ethernet76; - # vlan 8 (tagged): Ethernet72, Ethernet76; - # 6 FDB entries wil be created in total - assert counter_inserted - counter_before == 6 - - # check that the FDB entries were inserted into State DB for Ethernet64, Ethernet68 with Vlan6 - ok, extra = dvs.is_table_entry_exists(dvs.sdb, "FDB_TABLE", - "Vlan6:.*", - [("port", "Ethernet64"), - ("type", "dynamic"), - ] - ) - assert ok, str(extra) - ok, extra = dvs.is_table_entry_exists(dvs.sdb, "FDB_TABLE", - "Vlan6:*", - [("port", "Ethernet68"), - ("type", "dynamic"), - ] - ) - assert ok, str(extra) - - # check that the FDB entries were inserted into State DB, - # Vlan7(untagged) in the key for Ethernet72, Ethernet76 - ok, extra = dvs.is_table_entry_exists(dvs.sdb, "FDB_TABLE", - "Vlan7:.*", - [("port", "Ethernet72"), - ("type", "dynamic"), - ] - ) - assert ok, str(extra) - ok, extra = dvs.is_table_entry_exists(dvs.sdb, "FDB_TABLE", - "Vlan7:*", - [("port", "Ethernet76"), - ("type", "dynamic"), - ] - ) - assert ok, str(extra) - - # check that the FDB entries were inserted into State DB, - # Vlan8 (tagged) in the key for Ethernet72, Ethernet76 - ok, extra = dvs.is_table_entry_exists(dvs.sdb, "FDB_TABLE", - "Vlan8:.*", - [("port", "Ethernet72"), - ("type", "dynamic"), - ] - ) - assert ok, str(extra) - ok, extra = dvs.is_table_entry_exists(dvs.sdb, "FDB_TABLE", - "Vlan8:*", - [("port", "Ethernet76"), - ("type", "dynamic"), - ] - ) - assert ok, str(extra) - - # enable warm restart - (exitcode, result) = dvs.runcmd("config warm_restart enable swss") - assert exitcode == 0 - - # freeze orchagent for warm restart - (exitcode, result) = dvs.runcmd("/usr/bin/orchagent_restart_check") - assert result == "RESTARTCHECK succeeded\n" - time.sleep(2) - - try: - # restart orchagent - dvs.stop_swss() - - # check FDB learning mode - ok, extra = dvs.all_table_entry_has(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', - ".*", - [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_DISABLE")]) - assert ok, str(extra) - # check FDB aging time - ok, extra = dvs.all_table_entry_has(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_SWITCH', - ".*", - [("SAI_SWITCH_ATTR_FDB_AGING_TIME", "0")]) - assert ok, str(extra) - - dvs.start_swss() - time.sleep(2) - - # Get mapping between interface name and its bridge port_id - # Note: they are changed - iface_2_bridge_port_id = dvs.get_map_iface_bridge_port_id(dvs.adb) - - # check that the FDB entries were inserted into ASIC DB - ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", - [], - [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), - ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet64"]), - ] - ) - assert ok, str(extra) - ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", - [], - [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), - ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet68"]), - ] - ) - assert ok, str(extra) - - # check that the FDB entries were inserted into ASIC DB - ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", - [], - [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), - ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet72"]), - ] - ) - assert ok, str(extra) - ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", - [], - [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), - ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet76"]), - ] - ) - assert ok, str(extra) - - # check FDB learning mode - ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', - iface_2_bridge_port_id["Ethernet64"], - [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")]) - assert ok, str(extra) - ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', - iface_2_bridge_port_id["Ethernet68"], - [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")]) - assert ok, str(extra) - - ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', - iface_2_bridge_port_id["Ethernet72"], - [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")]) - assert ok, str(extra) - ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', - iface_2_bridge_port_id["Ethernet76"], - [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")]) - assert ok, str(extra) - - time.sleep(2) - counter_restarted = dvs.getCrmCounterValue('STATS', 'crm_stats_fdb_entry_used') - assert counter_inserted == counter_restarted - - # check fdb aging attr - ok, extra = dvs.all_table_entry_has_no(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_SWITCH', - ".*", - ["SAI_SWITCH_ATTR_FDB_AGING_TIME"]) - - finally: - # disable warm restart - dvs.runcmd("config warm_restart disable swss") - # slow down crm polling - dvs.runcmd("crm config polling interval 10000") diff --git a/tests/test_nhg.py b/tests/test_nhg.py index 97a70d571ee..a2bbe5fd1f5 100644 --- a/tests/test_nhg.py +++ b/tests/test_nhg.py @@ -4,134 +4,134 @@ import time import json -def test_route_nhg(dvs, testlog): +class TestNextHopGroup(object): + def test_route_nhg(self, dvs, testlog): + config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + intf_tbl = swsscommon.Table(config_db, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) + intf_tbl.set("Ethernet0", fvs) + intf_tbl.set("Ethernet4", fvs) + intf_tbl.set("Ethernet8", fvs) + intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) + intf_tbl.set("Ethernet4|10.0.0.2/31", fvs) + intf_tbl.set("Ethernet8|10.0.0.4/31", fvs) + dvs.runcmd("ifconfig Ethernet0 up") + dvs.runcmd("ifconfig Ethernet4 up") + dvs.runcmd("ifconfig Ethernet8 up") + + dvs.runcmd("arp -s 10.0.0.1 00:00:00:00:00:01") + dvs.runcmd("arp -s 10.0.0.3 00:00:00:00:00:02") + dvs.runcmd("arp -s 10.0.0.5 00:00:00:00:00:03") + + dvs.servers[0].runcmd("ip link set down dev eth0") == 0 + dvs.servers[1].runcmd("ip link set down dev eth0") == 0 + dvs.servers[2].runcmd("ip link set down dev eth0") == 0 + + dvs.servers[0].runcmd("ip link set up dev eth0") == 0 + dvs.servers[1].runcmd("ip link set up dev eth0") == 0 + dvs.servers[2].runcmd("ip link set up dev eth0") == 0 + + db = swsscommon.DBConnector(0, dvs.redis_sock, 0) + ps = swsscommon.ProducerStateTable(db, "ROUTE_TABLE") + fvs = swsscommon.FieldValuePairs([("nexthop","10.0.0.1,10.0.0.3,10.0.0.5"), ("ifname", "Ethernet0,Ethernet4,Ethernet8")]) + + ps.set("2.2.2.0/24", fvs) - config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) - intf_tbl = swsscommon.Table(config_db, "INTERFACE") - fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) - intf_tbl.set("Ethernet0", fvs) - intf_tbl.set("Ethernet4", fvs) - intf_tbl.set("Ethernet8", fvs) - intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) - intf_tbl.set("Ethernet4|10.0.0.2/31", fvs) - intf_tbl.set("Ethernet8|10.0.0.4/31", fvs) - dvs.runcmd("ifconfig Ethernet0 up") - dvs.runcmd("ifconfig Ethernet4 up") - dvs.runcmd("ifconfig Ethernet8 up") - - dvs.runcmd("arp -s 10.0.0.1 00:00:00:00:00:01") - dvs.runcmd("arp -s 10.0.0.3 00:00:00:00:00:02") - dvs.runcmd("arp -s 10.0.0.5 00:00:00:00:00:03") - - dvs.servers[0].runcmd("ip link set down dev eth0") == 0 - dvs.servers[1].runcmd("ip link set down dev eth0") == 0 - dvs.servers[2].runcmd("ip link set down dev eth0") == 0 - - dvs.servers[0].runcmd("ip link set up dev eth0") == 0 - dvs.servers[1].runcmd("ip link set up dev eth0") == 0 - dvs.servers[2].runcmd("ip link set up dev eth0") == 0 - - db = swsscommon.DBConnector(0, dvs.redis_sock, 0) - ps = swsscommon.ProducerStateTable(db, "ROUTE_TABLE") - fvs = swsscommon.FieldValuePairs([("nexthop","10.0.0.1,10.0.0.3,10.0.0.5"), ("ifname", "Ethernet0,Ethernet4,Ethernet8")]) - - ps.set("2.2.2.0/24", fvs) - - time.sleep(1) + time.sleep(1) - # check if route was propagated to ASIC DB + # check if route was propagated to ASIC DB - adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) + adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) - rtbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY") - nhgtbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_NEXT_HOP_GROUP") - nhg_member_tbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_NEXT_HOP_GROUP_MEMBER") + rtbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY") + nhgtbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_NEXT_HOP_GROUP") + nhg_member_tbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_NEXT_HOP_GROUP_MEMBER") - keys = rtbl.getKeys() + keys = rtbl.getKeys() - found_route = False - for k in keys: - rt_key = json.loads(k) + found_route = False + for k in keys: + rt_key = json.loads(k) - if rt_key['dest'] == "2.2.2.0/24": - found_route = True - break + if rt_key['dest'] == "2.2.2.0/24": + found_route = True + break - assert found_route + assert found_route - # assert the route points to next hop group - (status, fvs) = rtbl.get(k) + # assert the route points to next hop group + (status, fvs) = rtbl.get(k) - for v in fvs: - if v[0] == "SAI_ROUTE_ENTRY_ATTR_NEXT_HOP_ID": - nhgid = v[1] + for v in fvs: + if v[0] == "SAI_ROUTE_ENTRY_ATTR_NEXT_HOP_ID": + nhgid = v[1] - (status, fvs) = nhgtbl.get(nhgid) + (status, fvs) = nhgtbl.get(nhgid) - assert status + assert status - keys = nhg_member_tbl.getKeys() + keys = nhg_member_tbl.getKeys() - assert len(keys) == 3 + assert len(keys) == 3 - for k in keys: - (status, fvs) = nhg_member_tbl.get(k) + for k in keys: + (status, fvs) = nhg_member_tbl.get(k) - for v in fvs: - if v[0] == "SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID": - assert v[1] == nhgid + for v in fvs: + if v[0] == "SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID": + assert v[1] == nhgid - # bring links down one-by-one - for i in [0, 1, 2]: - dvs.servers[i].runcmd("ip link set down dev eth0") == 0 + # bring links down one-by-one + for i in [0, 1, 2]: + dvs.servers[i].runcmd("ip link set down dev eth0") == 0 - time.sleep(1) + time.sleep(1) - tbl = swsscommon.Table(db, "PORT_TABLE") - (status, fvs) = tbl.get("Ethernet%d" % (i * 4)) + tbl = swsscommon.Table(db, "PORT_TABLE") + (status, fvs) = tbl.get("Ethernet%d" % (i * 4)) - assert status == True + assert status == True - oper_status = "unknown" + oper_status = "unknown" - for v in fvs: - if v[0] == "oper_status": - oper_status = v[1] - break + for v in fvs: + if v[0] == "oper_status": + oper_status = v[1] + break - assert oper_status == "down" + assert oper_status == "down" - keys = nhg_member_tbl.getKeys() + keys = nhg_member_tbl.getKeys() - assert len(keys) == 2 - i + assert len(keys) == 2 - i - # bring links up one-by-one - for i in [0, 1, 2]: - dvs.servers[i].runcmd("ip link set up dev eth0") == 0 + # bring links up one-by-one + for i in [0, 1, 2]: + dvs.servers[i].runcmd("ip link set up dev eth0") == 0 - time.sleep(1) + time.sleep(1) - tbl = swsscommon.Table(db, "PORT_TABLE") - (status, fvs) = tbl.get("Ethernet%d" % (i * 4)) + tbl = swsscommon.Table(db, "PORT_TABLE") + (status, fvs) = tbl.get("Ethernet%d" % (i * 4)) - assert status == True + assert status == True - oper_status = "unknown" + oper_status = "unknown" - for v in fvs: - if v[0] == "oper_status": - oper_status = v[1] - break + for v in fvs: + if v[0] == "oper_status": + oper_status = v[1] + break - assert oper_status == "up" + assert oper_status == "up" - keys = nhg_member_tbl.getKeys() + keys = nhg_member_tbl.getKeys() - assert len(keys) == i + 1 + assert len(keys) == i + 1 - for k in keys: - (status, fvs) = nhg_member_tbl.get(k) + for k in keys: + (status, fvs) = nhg_member_tbl.get(k) - for v in fvs: - if v[0] == "SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID": - assert v[1] == nhgid + for v in fvs: + if v[0] == "SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID": + assert v[1] == nhgid diff --git a/tests/test_pfc.py b/tests/test_pfc.py index 8ed9112beab..9a59adf20b5 100644 --- a/tests/test_pfc.py +++ b/tests/test_pfc.py @@ -57,45 +57,45 @@ def getPortAttr(dvs, port_oid, port_attr): return '' +class TestPfc(object): + def test_PfcAsymmetric(self, dvs, testlog): -def test_PfcAsymmetric(dvs, testlog): + port_name = 'Ethernet0' + pfc_queues = [ 3, 4 ] - port_name = 'Ethernet0' - pfc_queues = [ 3, 4 ] + # Configure default PFC + setPortPfc(dvs, port_name, pfc_queues) - # Configure default PFC - setPortPfc(dvs, port_name, pfc_queues) + # Get SAI object ID for the interface + port_oid = getPortOid(dvs, port_name) - # Get SAI object ID for the interface - port_oid = getPortOid(dvs, port_name) + # Verify default PFC is set to configured value + pfc = getPortAttr(dvs, port_oid, 'SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL') + assert pfc == getBitMaskStr(pfc_queues) - # Verify default PFC is set to configured value - pfc = getPortAttr(dvs, port_oid, 'SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL') - assert pfc == getBitMaskStr(pfc_queues) + # Enable asymmetric PFC + setPortPfcAsym(dvs, port_name, 'on') - # Enable asymmetric PFC - setPortPfcAsym(dvs, port_name, 'on') + # Verify PFC mode is set to 'SEPARATE' + pfc_mode = getPortAttr(dvs, port_oid, 'SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_MODE') + assert pfc_mode == 'SAI_PORT_PRIORITY_FLOW_CONTROL_MODE_SEPARATE' - # Verify PFC mode is set to 'SEPARATE' - pfc_mode = getPortAttr(dvs, port_oid, 'SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_MODE') - assert pfc_mode == 'SAI_PORT_PRIORITY_FLOW_CONTROL_MODE_SEPARATE' + # Verify TX PFC is set to previous PFC value + pfc_tx = getPortAttr(dvs, port_oid, 'SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_TX') + assert pfc_tx == pfc - # Verify TX PFC is set to previous PFC value - pfc_tx = getPortAttr(dvs, port_oid, 'SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_TX') - assert pfc_tx == pfc + # Verify RX PFC is set to 0xFF (255) + pfc_rx = getPortAttr(dvs, port_oid, 'SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_RX') + assert pfc_rx == '255' - # Verify RX PFC is set to 0xFF (255) - pfc_rx = getPortAttr(dvs, port_oid, 'SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_RX') - assert pfc_rx == '255' + # Disable asymmetric PFC + setPortPfcAsym(dvs, port_name, 'off') - # Disable asymmetric PFC - setPortPfcAsym(dvs, port_name, 'off') + # Verify PFC mode is set to 'COMBINED' + pfc_mode = getPortAttr(dvs, port_oid, 'SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_MODE') + assert pfc_mode == 'SAI_PORT_PRIORITY_FLOW_CONTROL_MODE_COMBINED' - # Verify PFC mode is set to 'COMBINED' - pfc_mode = getPortAttr(dvs, port_oid, 'SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_MODE') - assert pfc_mode == 'SAI_PORT_PRIORITY_FLOW_CONTROL_MODE_COMBINED' - - # Verify PFC is set to TX PFC value - pfc = getPortAttr(dvs, port_oid, 'SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL') - assert pfc == pfc_tx + # Verify PFC is set to TX PFC value + pfc = getPortAttr(dvs, port_oid, 'SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL') + assert pfc == pfc_tx diff --git a/tests/test_port.py b/tests/test_port.py index cf429ca985a..edf459301c7 100644 --- a/tests/test_port.py +++ b/tests/test_port.py @@ -23,195 +23,195 @@ def test_PortMtu(self, dvs, testlog): if fv[0] == "mtu": assert fv[1] == "9100" -def test_PortNotification(dvs, testlog): + def test_PortNotification(self, dvs, testlog): - dvs.runcmd("ifconfig Ethernet0 10.0.0.0/31 up") == 0 - dvs.runcmd("ifconfig Ethernet4 10.0.0.2/31 up") == 0 + dvs.runcmd("ifconfig Ethernet0 10.0.0.0/31 up") == 0 + dvs.runcmd("ifconfig Ethernet4 10.0.0.2/31 up") == 0 - dvs.servers[0].runcmd("ip link set down dev eth0") == 0 + dvs.servers[0].runcmd("ip link set down dev eth0") == 0 - time.sleep(1) + time.sleep(1) - db = swsscommon.DBConnector(0, dvs.redis_sock, 0) + db = swsscommon.DBConnector(0, dvs.redis_sock, 0) - tbl = swsscommon.Table(db, "PORT_TABLE") + tbl = swsscommon.Table(db, "PORT_TABLE") - (status, fvs) = tbl.get("Ethernet0") + (status, fvs) = tbl.get("Ethernet0") - assert status == True + assert status == True - oper_status = "unknown" + oper_status = "unknown" - for v in fvs: - if v[0] == "oper_status": - oper_status = v[1] - break + for v in fvs: + if v[0] == "oper_status": + oper_status = v[1] + break - assert oper_status == "down" + assert oper_status == "down" - dvs.servers[0].runcmd("ip link set up dev eth0") == 0 + dvs.servers[0].runcmd("ip link set up dev eth0") == 0 - time.sleep(1) + time.sleep(1) - (status, fvs) = tbl.get("Ethernet0") + (status, fvs) = tbl.get("Ethernet0") - assert status == True + assert status == True - oper_status = "unknown" + oper_status = "unknown" - for v in fvs: - if v[0] == "oper_status": - oper_status = v[1] - break + for v in fvs: + if v[0] == "oper_status": + oper_status = v[1] + break - assert oper_status == "up" + assert oper_status == "up" -def test_PortFec(dvs, testlog): + def test_PortFec(self, dvs, testlog): - dvs.runcmd("ifconfig Ethernet0 10.0.0.0/31 up") == 0 - dvs.runcmd("ifconfig Ethernet4 10.0.0.2/31 up") == 0 + dvs.runcmd("ifconfig Ethernet0 10.0.0.0/31 up") == 0 + dvs.runcmd("ifconfig Ethernet4 10.0.0.2/31 up") == 0 - dvs.servers[0].runcmd("ip link set down dev eth0") == 0 + dvs.servers[0].runcmd("ip link set down dev eth0") == 0 - time.sleep(1) + time.sleep(1) - db = swsscommon.DBConnector(0, dvs.redis_sock, 0) - adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) + db = swsscommon.DBConnector(0, dvs.redis_sock, 0) + adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) - tbl = swsscommon.Table(db, "PORT_TABLE") - ptbl = swsscommon.ProducerStateTable(db, "PORT_TABLE") - atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_PORT") + tbl = swsscommon.Table(db, "PORT_TABLE") + ptbl = swsscommon.ProducerStateTable(db, "PORT_TABLE") + atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_PORT") - (status, fvs) = tbl.get("Ethernet0") + (status, fvs) = tbl.get("Ethernet0") - assert status == True + assert status == True - oper_status = "unknown" + oper_status = "unknown" - for v in fvs: - if v[0] == "oper_status": - oper_status = v[1] - break + for v in fvs: + if v[0] == "oper_status": + oper_status = v[1] + break - assert oper_status == "down" + assert oper_status == "down" - dvs.servers[0].runcmd("ip link set up dev eth0") == 0 + dvs.servers[0].runcmd("ip link set up dev eth0") == 0 - time.sleep(1) + time.sleep(1) - (status, fvs) = tbl.get("Ethernet0") + (status, fvs) = tbl.get("Ethernet0") - assert status == True + assert status == True - oper_status = "unknown" + oper_status = "unknown" - for v in fvs: - if v[0] == "oper_status": - oper_status = v[1] - break + for v in fvs: + if v[0] == "oper_status": + oper_status = v[1] + break - assert oper_status == "up" + assert oper_status == "up" - # set fec - fvs = swsscommon.FieldValuePairs([("fec","rs"), ("speed", "1000")]) - ptbl.set("Ethernet0", fvs) + # set fec + fvs = swsscommon.FieldValuePairs([("fec","rs"), ("speed", "1000")]) + ptbl.set("Ethernet0", fvs) - time.sleep(1) + time.sleep(1) - # get fec - (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) - assert status == True + # get fec + (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) + assert status == True - for fv in fvs: - if fv[0] == "SAI_PORT_ATTR_FEC_MODE": - assert fv[1] == "SAI_PORT_FEC_MODE_RS" + for fv in fvs: + if fv[0] == "SAI_PORT_ATTR_FEC_MODE": + assert fv[1] == "SAI_PORT_FEC_MODE_RS" -def test_PortPreemp(dvs, testlog): + def test_PortPreemp(self, dvs, testlog): - pre_name = 'preemphasis' - pre_val = [0x1234,0x2345,0x3456,0x4567] - pre_val_str = str(hex(pre_val[0])) + "," + str(hex(pre_val[1]))+ "," + \ - str(hex(pre_val[2]))+ "," + str(hex(pre_val[3])) + pre_name = 'preemphasis' + pre_val = [0x1234,0x2345,0x3456,0x4567] + pre_val_str = str(hex(pre_val[0])) + "," + str(hex(pre_val[1]))+ "," + \ + str(hex(pre_val[2]))+ "," + str(hex(pre_val[3])) - pre_val_asic = '4:' + str(pre_val[0]) + "," + str(pre_val[1]) + "," + \ - str(pre_val[2]) + "," + str(pre_val[3]) - fvs = swsscommon.FieldValuePairs([(pre_name, pre_val_str)]) - db = swsscommon.DBConnector(0, dvs.redis_sock, 0) - adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) + pre_val_asic = '4:' + str(pre_val[0]) + "," + str(pre_val[1]) + "," + \ + str(pre_val[2]) + "," + str(pre_val[3]) + fvs = swsscommon.FieldValuePairs([(pre_name, pre_val_str)]) + db = swsscommon.DBConnector(0, dvs.redis_sock, 0) + adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) - tbl = swsscommon.Table(db, "PORT_TABLE") - ptbl = swsscommon.ProducerStateTable(db, "PORT_TABLE") - atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_PORT") + tbl = swsscommon.Table(db, "PORT_TABLE") + ptbl = swsscommon.ProducerStateTable(db, "PORT_TABLE") + atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_PORT") - ptbl.set("Ethernet0", fvs) + ptbl.set("Ethernet0", fvs) - time.sleep(1) + time.sleep(1) - # get fec - (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) - assert status == True + # get fec + (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) + assert status == True - for fv in fvs: - if fv[0] == "SAI_PORT_ATTR_SERDES_PREEMPHASIS": - assert fv[1] == pre_val_asic + for fv in fvs: + if fv[0] == "SAI_PORT_ATTR_SERDES_PREEMPHASIS": + assert fv[1] == pre_val_asic -def test_PortIdriver(dvs, testlog): + def test_PortIdriver(self, dvs, testlog): - idrv_name = 'idriver' - idrv_val = [0x1,0x1,0x2,0x2] - idrv_val_str = str(hex(idrv_val[0])) + "," + str(hex(idrv_val[1]))+ "," + \ - str(hex(idrv_val[2]))+ "," + str(hex(idrv_val[3])) + idrv_name = 'idriver' + idrv_val = [0x1,0x1,0x2,0x2] + idrv_val_str = str(hex(idrv_val[0])) + "," + str(hex(idrv_val[1]))+ "," + \ + str(hex(idrv_val[2]))+ "," + str(hex(idrv_val[3])) - idrv_val_asic = '4:' + str(idrv_val[0]) + "," + str(idrv_val[1]) + "," + \ - str(idrv_val[2]) + "," + str(idrv_val[3]) - fvs = swsscommon.FieldValuePairs([(idrv_name, idrv_val_str)]) - db = swsscommon.DBConnector(0, dvs.redis_sock, 0) - adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) + idrv_val_asic = '4:' + str(idrv_val[0]) + "," + str(idrv_val[1]) + "," + \ + str(idrv_val[2]) + "," + str(idrv_val[3]) + fvs = swsscommon.FieldValuePairs([(idrv_name, idrv_val_str)]) + db = swsscommon.DBConnector(0, dvs.redis_sock, 0) + adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) - tbl = swsscommon.Table(db, "PORT_TABLE") - ptbl = swsscommon.ProducerStateTable(db, "PORT_TABLE") - atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_PORT") + tbl = swsscommon.Table(db, "PORT_TABLE") + ptbl = swsscommon.ProducerStateTable(db, "PORT_TABLE") + atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_PORT") - ptbl.set("Ethernet0", fvs) + ptbl.set("Ethernet0", fvs) - time.sleep(1) + time.sleep(1) - # get fec - (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) - assert status == True + # get fec + (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) + assert status == True - for fv in fvs: - if fv[0] == "SAI_PORT_ATTR_SERDES_IDRIVER": - assert fv[1] == idrv_val_asic + for fv in fvs: + if fv[0] == "SAI_PORT_ATTR_SERDES_IDRIVER": + assert fv[1] == idrv_val_asic -def test_PortIpredriver(dvs, testlog): + def test_PortIpredriver(self, dvs, testlog): - ipre_name = 'ipredriver' - ipre_val = [0x2,0x3,0x4,0x5] - ipre_val_str = str(hex(ipre_val[0])) + "," + str(hex(ipre_val[1]))+ "," + \ - str(hex(ipre_val[2]))+ "," + str(hex(ipre_val[3])) + ipre_name = 'ipredriver' + ipre_val = [0x2,0x3,0x4,0x5] + ipre_val_str = str(hex(ipre_val[0])) + "," + str(hex(ipre_val[1]))+ "," + \ + str(hex(ipre_val[2]))+ "," + str(hex(ipre_val[3])) - ipre_val_asic = '4:' + str(ipre_val[0]) + "," + str(ipre_val[1]) + "," + \ - str(ipre_val[2]) + "," + str(ipre_val[3]) - fvs = swsscommon.FieldValuePairs([(ipre_name, ipre_val_str)]) - db = swsscommon.DBConnector(0, dvs.redis_sock, 0) - adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) + ipre_val_asic = '4:' + str(ipre_val[0]) + "," + str(ipre_val[1]) + "," + \ + str(ipre_val[2]) + "," + str(ipre_val[3]) + fvs = swsscommon.FieldValuePairs([(ipre_name, ipre_val_str)]) + db = swsscommon.DBConnector(0, dvs.redis_sock, 0) + adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) - tbl = swsscommon.Table(db, "PORT_TABLE") - ptbl = swsscommon.ProducerStateTable(db, "PORT_TABLE") - atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_PORT") + tbl = swsscommon.Table(db, "PORT_TABLE") + ptbl = swsscommon.ProducerStateTable(db, "PORT_TABLE") + atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_PORT") - ptbl.set("Ethernet0", fvs) + ptbl.set("Ethernet0", fvs) - time.sleep(1) + time.sleep(1) - # get fec - (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) - assert status == True + # get fec + (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) + assert status == True - for fv in fvs: - if fv[0] == "SAI_PORT_ATTR_SERDES_IPREDRIVER": - assert fv[1] == ipre_val_asic + for fv in fvs: + if fv[0] == "SAI_PORT_ATTR_SERDES_IPREDRIVER": + assert fv[1] == ipre_val_asic diff --git a/tests/test_port_an.py b/tests/test_port_an.py new file mode 100644 index 00000000000..67ce59f317a --- /dev/null +++ b/tests/test_port_an.py @@ -0,0 +1,173 @@ +from swsscommon import swsscommon +import time +import os + +class TestPortAutoNeg(object): + def test_PortAutoNegCold(self, dvs, testlog): + + db = swsscommon.DBConnector(0, dvs.redis_sock, 0) + + tbl = swsscommon.ProducerStateTable(db, "PORT_TABLE") + + # set autoneg = false and speed = 1000 + fvs = swsscommon.FieldValuePairs([("autoneg","1"), ("speed", "1000")]) + + tbl.set("Ethernet0", fvs) + + time.sleep(1) + + adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) + + atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_PORT") + (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) + assert status == True + + assert "SAI_PORT_ATTR_AUTO_NEG_MODE" in [fv[0] for fv in fvs] + assert "SAI_PORT_ATTR_ADVERTISED_SPEED" in [fv[0] for fv in fvs] + for fv in fvs: + if fv[0] == "SAI_PORT_ATTR_AUTO_NEG_MODE": + assert fv[1] == "true" + elif fv[0] == "SAI_PORT_ATTR_ADVERTISED_SPEED": + assert fv[1] == "1:1000" + + # set speed = 100 + fvs = swsscommon.FieldValuePairs([("speed", "100")]) + + tbl.set("Ethernet0", fvs) + + time.sleep(1) + + (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) + assert status == True + + for fv in fvs: + if fv[0] == "SAI_PORT_ATTR_AUTO_NEG_MODE": + assert fv[1] == "true" + elif fv[0] == "SAI_PORT_ATTR_ADVERTISED_SPEED": + assert fv[1] == "1:100" + + # change autoneg to false + fvs = swsscommon.FieldValuePairs([("autoneg","0")]) + + tbl.set("Ethernet0", fvs) + + time.sleep(1) + + (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) + assert status == True + + assert "SAI_PORT_ATTR_AUTO_NEG_MODE" in [fv[0] for fv in fvs] + assert "SAI_PORT_ATTR_ADVERTISED_SPEED" in [fv[0] for fv in fvs] + assert "SAI_PORT_ATTR_SPEED" in [fv[0] for fv in fvs] + for fv in fvs: + if fv[0] == "SAI_PORT_ATTR_AUTO_NEG_MODE": + assert fv[1] == "false" + elif fv[0] == "SAI_PORT_ATTR_ADVERTISED_SPEED": + assert fv[1] == "1:100" + elif fv[0] == "SAI_PORT_ATTR_SPEED": + assert fv[1] == "100" + + # set speed = 1000 + fvs = swsscommon.FieldValuePairs([("speed", "1000")]) + + tbl.set("Ethernet0", fvs) + + time.sleep(1) + + (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) + assert status == True + + for fv in fvs: + if fv[0] == "SAI_PORT_ATTR_AUTO_NEG_MODE": + assert fv[1] == "false" + elif fv[0] == "SAI_PORT_ATTR_ADVERTISED_SPEED": + assert fv[1] == "1:100" + elif fv[0] == "SAI_PORT_ATTR_SPEED": + assert fv[1] == "1000" + + def test_PortAutoNegWarm(self, dvs, testlog): + + db = swsscommon.DBConnector(0, dvs.redis_sock, 0) + cdb = swsscommon.DBConnector(4, dvs.redis_sock, 0) + sdb = swsscommon.DBConnector(6, dvs.redis_sock, 0) + + tbl = swsscommon.ProducerStateTable(db, "PORT_TABLE") + ctbl = swsscommon.Table(cdb, "PORT") + stbl = swsscommon.Table(sdb, "PORT_TABLE") + + # set autoneg = true and speed = 1000 + fvs = swsscommon.FieldValuePairs([("autoneg","1"), ("speed", "1000")]) + ctbl.set("Ethernet0", fvs) + + time.sleep(1) + + adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) + + atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_PORT") + (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) + assert status == True + + assert "SAI_PORT_ATTR_AUTO_NEG_MODE" in [fv[0] for fv in fvs] + assert "SAI_PORT_ATTR_ADVERTISED_SPEED" in [fv[0] for fv in fvs] + for fv in fvs: + if fv[0] == "SAI_PORT_ATTR_AUTO_NEG_MODE": + assert fv[1] == "true" + elif fv[0] == "SAI_PORT_ATTR_ADVERTISED_SPEED": + assert fv[1] == "1:1000" + + # set speed = 100 + fvs = swsscommon.FieldValuePairs([("speed", "100")]) + + ctbl.set("Ethernet0", fvs) + + time.sleep(1) + + (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) + assert status == True + + for fv in fvs: + if fv[0] == "SAI_PORT_ATTR_AUTO_NEG_MODE": + assert fv[1] == "true" + elif fv[0] == "SAI_PORT_ATTR_ADVERTISED_SPEED": + assert fv[1] == "1:100" + + # set admin up + cfvs = swsscommon.FieldValuePairs([("admin_status", "up")]) + ctbl.set("Ethernet0", cfvs) + + # enable warm restart + (exitcode, result) = dvs.runcmd("config warm_restart enable swss") + assert exitcode == 0 + + # freeze orchagent for warm restart + (exitcode, result) = dvs.runcmd("/usr/bin/orchagent_restart_check") + assert result == "RESTARTCHECK succeeded\n" + time.sleep(2) + + try: + # restart orchagent + # clean port state + dvs.stop_swss() + ports = stbl.getKeys() + for port in ports: + stbl._del(port) + dvs.start_swss() + time.sleep(2) + + # check ASIC DB after warm restart + (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) + assert status == True + + assert "SAI_PORT_ATTR_AUTO_NEG_MODE" in [fv[0] for fv in fvs] + assert "SAI_PORT_ATTR_ADVERTISED_SPEED" in [fv[0] for fv in fvs] + for fv in fvs: + if fv[0] == "SAI_PORT_ATTR_AUTO_NEG_MODE": + assert fv[1] == "true" + elif fv[0] == "SAI_PORT_ATTR_ADVERTISED_SPEED": + assert fv[1] == "1:100" + + finally: + # disable warm restart + dvs.runcmd("config warm_restart disable swss") + # slow down crm polling + dvs.runcmd("crm config polling interval 10000") diff --git a/tests/test_port_an_cold.py b/tests/test_port_an_cold.py deleted file mode 100644 index 3b4414059a3..00000000000 --- a/tests/test_port_an_cold.py +++ /dev/null @@ -1,85 +0,0 @@ -from swsscommon import swsscommon -import time -import os - -def test_PortAutoNeg(dvs, testlog): - - db = swsscommon.DBConnector(0, dvs.redis_sock, 0) - - tbl = swsscommon.ProducerStateTable(db, "PORT_TABLE") - - # set autoneg = false and speed = 1000 - fvs = swsscommon.FieldValuePairs([("autoneg","1"), ("speed", "1000")]) - - tbl.set("Ethernet0", fvs) - - time.sleep(1) - - adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) - - atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_PORT") - (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) - assert status == True - - assert "SAI_PORT_ATTR_AUTO_NEG_MODE" in [fv[0] for fv in fvs] - assert "SAI_PORT_ATTR_ADVERTISED_SPEED" in [fv[0] for fv in fvs] - for fv in fvs: - if fv[0] == "SAI_PORT_ATTR_AUTO_NEG_MODE": - assert fv[1] == "true" - elif fv[0] == "SAI_PORT_ATTR_ADVERTISED_SPEED": - assert fv[1] == "1:1000" - - # set speed = 100 - fvs = swsscommon.FieldValuePairs([("speed", "100")]) - - tbl.set("Ethernet0", fvs) - - time.sleep(1) - - (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) - assert status == True - - for fv in fvs: - if fv[0] == "SAI_PORT_ATTR_AUTO_NEG_MODE": - assert fv[1] == "true" - elif fv[0] == "SAI_PORT_ATTR_ADVERTISED_SPEED": - assert fv[1] == "1:100" - - # change autoneg to false - fvs = swsscommon.FieldValuePairs([("autoneg","0")]) - - tbl.set("Ethernet0", fvs) - - time.sleep(1) - - (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) - assert status == True - - assert "SAI_PORT_ATTR_AUTO_NEG_MODE" in [fv[0] for fv in fvs] - assert "SAI_PORT_ATTR_ADVERTISED_SPEED" in [fv[0] for fv in fvs] - assert "SAI_PORT_ATTR_SPEED" in [fv[0] for fv in fvs] - for fv in fvs: - if fv[0] == "SAI_PORT_ATTR_AUTO_NEG_MODE": - assert fv[1] == "false" - elif fv[0] == "SAI_PORT_ATTR_ADVERTISED_SPEED": - assert fv[1] == "1:100" - elif fv[0] == "SAI_PORT_ATTR_SPEED": - assert fv[1] == "100" - - # set speed = 1000 - fvs = swsscommon.FieldValuePairs([("speed", "1000")]) - - tbl.set("Ethernet0", fvs) - - time.sleep(1) - - (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) - assert status == True - - for fv in fvs: - if fv[0] == "SAI_PORT_ATTR_AUTO_NEG_MODE": - assert fv[1] == "false" - elif fv[0] == "SAI_PORT_ATTR_ADVERTISED_SPEED": - assert fv[1] == "1:100" - elif fv[0] == "SAI_PORT_ATTR_SPEED": - assert fv[1] == "1000" diff --git a/tests/test_port_an_warm.py b/tests/test_port_an_warm.py deleted file mode 100644 index 50ffbbf8192..00000000000 --- a/tests/test_port_an_warm.py +++ /dev/null @@ -1,90 +0,0 @@ -from swsscommon import swsscommon -import time -import os - -def test_PortAutoNeg_warm(dvs, testlog): - - db = swsscommon.DBConnector(0, dvs.redis_sock, 0) - cdb = swsscommon.DBConnector(4, dvs.redis_sock, 0) - sdb = swsscommon.DBConnector(6, dvs.redis_sock, 0) - - tbl = swsscommon.ProducerStateTable(db, "PORT_TABLE") - ctbl = swsscommon.Table(cdb, "PORT") - stbl = swsscommon.Table(sdb, "PORT_TABLE") - - # set autoneg = true and speed = 1000 - fvs = swsscommon.FieldValuePairs([("autoneg","1"), ("speed", "1000")]) - ctbl.set("Ethernet0", fvs) - - time.sleep(1) - - adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) - - atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_PORT") - (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) - assert status == True - - assert "SAI_PORT_ATTR_AUTO_NEG_MODE" in [fv[0] for fv in fvs] - assert "SAI_PORT_ATTR_ADVERTISED_SPEED" in [fv[0] for fv in fvs] - for fv in fvs: - if fv[0] == "SAI_PORT_ATTR_AUTO_NEG_MODE": - assert fv[1] == "true" - elif fv[0] == "SAI_PORT_ATTR_ADVERTISED_SPEED": - assert fv[1] == "1:1000" - - # set speed = 100 - fvs = swsscommon.FieldValuePairs([("speed", "100")]) - - ctbl.set("Ethernet0", fvs) - - time.sleep(1) - - (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) - assert status == True - - for fv in fvs: - if fv[0] == "SAI_PORT_ATTR_AUTO_NEG_MODE": - assert fv[1] == "true" - elif fv[0] == "SAI_PORT_ATTR_ADVERTISED_SPEED": - assert fv[1] == "1:100" - - # set admin up - cfvs = swsscommon.FieldValuePairs([("admin_status", "up")]) - ctbl.set("Ethernet0", cfvs) - - # enable warm restart - (exitcode, result) = dvs.runcmd("config warm_restart enable swss") - assert exitcode == 0 - - # freeze orchagent for warm restart - (exitcode, result) = dvs.runcmd("/usr/bin/orchagent_restart_check") - assert result == "RESTARTCHECK succeeded\n" - time.sleep(2) - - try: - # restart orchagent - # clean port state - dvs.stop_swss() - ports = stbl.getKeys() - for port in ports: - stbl._del(port) - dvs.start_swss() - time.sleep(2) - - # check ASIC DB after warm restart - (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) - assert status == True - - assert "SAI_PORT_ATTR_AUTO_NEG_MODE" in [fv[0] for fv in fvs] - assert "SAI_PORT_ATTR_ADVERTISED_SPEED" in [fv[0] for fv in fvs] - for fv in fvs: - if fv[0] == "SAI_PORT_ATTR_AUTO_NEG_MODE": - assert fv[1] == "true" - elif fv[0] == "SAI_PORT_ATTR_ADVERTISED_SPEED": - assert fv[1] == "1:100" - - finally: - # disable warm restart - dvs.runcmd("config warm_restart disable swss") - # slow down crm polling - dvs.runcmd("crm config polling interval 10000") diff --git a/tests/test_port_buffer_rel.py b/tests/test_port_buffer_rel.py index 231bec6ddf3..ed21660562a 100644 --- a/tests/test_port_buffer_rel.py +++ b/tests/test_port_buffer_rel.py @@ -2,32 +2,32 @@ import time # The test check that the ports will be up, when the admin state is UP by conf db. +class TestPortBuffer(object): + def test_PortsAreUpAfterBuffers(self, dvs, testlog): + num_ports = 32 + asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) -def test_PortsAreUpAfterBuffers(dvs, testlog): - num_ports = 32 - asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) - conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + conf_port_table = swsscommon.Table(conf_db, "PORT") + asic_port_table = swsscommon.Table(asic_db, "ASIC_STATE:SAI_OBJECT_TYPE_PORT") - conf_port_table = swsscommon.Table(conf_db, "PORT") - asic_port_table = swsscommon.Table(asic_db, "ASIC_STATE:SAI_OBJECT_TYPE_PORT") + # enable all ports + fvs = swsscommon.FieldValuePairs([("admin_status", "up")]) + for i in range(0, num_ports): + conf_port_table.set("Ethernet%d" % (i*4), fvs) - # enable all ports - fvs = swsscommon.FieldValuePairs([("admin_status", "up")]) - for i in range(0, num_ports): - conf_port_table.set("Ethernet%d" % (i*4), fvs) + time.sleep(5) - time.sleep(5) - - # check that the ports are enabled in ASIC - asic_port_records = asic_port_table.getKeys() - assert len(asic_port_records) == (num_ports + 1), "Number of port records doesn't match number of ports" # +CPU port - num_set = 0 - for k in asic_port_records: - status, fvs = asic_port_table.get(k) - assert status, "Got an error when get a key" - for fv in fvs: - if fv[0] == "SAI_PORT_ATTR_ADMIN_STATE": - assert fv[1] == "true", "The port isn't UP as expected" - num_set += 1 - # make sure that state is set for all "num_ports" ports - assert num_set == num_ports, "Not all ports are up" + # check that the ports are enabled in ASIC + asic_port_records = asic_port_table.getKeys() + assert len(asic_port_records) == (num_ports + 1), "Number of port records doesn't match number of ports" # +CPU port + num_set = 0 + for k in asic_port_records: + status, fvs = asic_port_table.get(k) + assert status, "Got an error when get a key" + for fv in fvs: + if fv[0] == "SAI_PORT_ATTR_ADMIN_STATE": + assert fv[1] == "true", "The port isn't UP as expected" + num_set += 1 + # make sure that state is set for all "num_ports" ports + assert num_set == num_ports, "Not all ports are up" diff --git a/tests/test_portchannel.py b/tests/test_portchannel.py index e4875160f99..320cf598e88 100644 --- a/tests/test_portchannel.py +++ b/tests/test_portchannel.py @@ -3,56 +3,57 @@ import re import json -def test_PortChannel(dvs, testlog): +class TestPortchannel(object): + def test_Portchannel(self, dvs, testlog): - # create port channel - db = swsscommon.DBConnector(0, dvs.redis_sock, 0) - ps = swsscommon.ProducerStateTable(db, "LAG_TABLE") - fvs = swsscommon.FieldValuePairs([("admin", "up"), ("mtu", "1500")]) + # create port channel + db = swsscommon.DBConnector(0, dvs.redis_sock, 0) + ps = swsscommon.ProducerStateTable(db, "LAG_TABLE") + fvs = swsscommon.FieldValuePairs([("admin", "up"), ("mtu", "1500")]) - ps.set("PortChannel0001", fvs) + ps.set("PortChannel0001", fvs) - # create port channel member - ps = swsscommon.ProducerStateTable(db, "LAG_MEMBER_TABLE") - fvs = swsscommon.FieldValuePairs([("status", "enabled")]) + # create port channel member + ps = swsscommon.ProducerStateTable(db, "LAG_MEMBER_TABLE") + fvs = swsscommon.FieldValuePairs([("status", "enabled")]) - ps.set("PortChannel0001:Ethernet0", fvs) + ps.set("PortChannel0001:Ethernet0", fvs) - time.sleep(1) + time.sleep(1) - # check asic db - asicdb = swsscommon.DBConnector(1, dvs.redis_sock, 0) + # check asic db + asicdb = swsscommon.DBConnector(1, dvs.redis_sock, 0) - lagtbl = swsscommon.Table(asicdb, "ASIC_STATE:SAI_OBJECT_TYPE_LAG") - lags = lagtbl.getKeys() - assert len(lags) == 1 + lagtbl = swsscommon.Table(asicdb, "ASIC_STATE:SAI_OBJECT_TYPE_LAG") + lags = lagtbl.getKeys() + assert len(lags) == 1 - lagmtbl = swsscommon.Table(asicdb, "ASIC_STATE:SAI_OBJECT_TYPE_LAG_MEMBER") - lagms = lagmtbl.getKeys() - assert len(lagms) == 1 + lagmtbl = swsscommon.Table(asicdb, "ASIC_STATE:SAI_OBJECT_TYPE_LAG_MEMBER") + lagms = lagmtbl.getKeys() + assert len(lagms) == 1 - (status, fvs) = lagmtbl.get(lagms[0]) - for fv in fvs: - if fv[0] == "SAI_LAG_MEMBER_ATTR_LAG_ID": - assert fv[1] == lags[0] - elif fv[0] == "SAI_LAG_MEMBER_ATTR_PORT_ID": - assert dvs.asicdb.portoidmap[fv[1]] == "Ethernet0" - else: - assert False + (status, fvs) = lagmtbl.get(lagms[0]) + for fv in fvs: + if fv[0] == "SAI_LAG_MEMBER_ATTR_LAG_ID": + assert fv[1] == lags[0] + elif fv[0] == "SAI_LAG_MEMBER_ATTR_PORT_ID": + assert dvs.asicdb.portoidmap[fv[1]] == "Ethernet0" + else: + assert False - # remove port channel member - ps = swsscommon.ProducerStateTable(db, "LAG_MEMBER_TABLE") - ps._del("PortChannel0001:Ethernet0") + # remove port channel member + ps = swsscommon.ProducerStateTable(db, "LAG_MEMBER_TABLE") + ps._del("PortChannel0001:Ethernet0") - # remove port channel - ps = swsscommon.ProducerStateTable(db, "LAG_TABLE") - ps._del("PortChannel0001") + # remove port channel + ps = swsscommon.ProducerStateTable(db, "LAG_TABLE") + ps._del("PortChannel0001") - time.sleep(1) + time.sleep(1) - # check asic db - lags = lagtbl.getKeys() - assert len(lags) == 0 + # check asic db + lags = lagtbl.getKeys() + assert len(lags) == 0 - lagms = lagmtbl.getKeys() - assert len(lagms) == 0 + lagms = lagmtbl.getKeys() + assert len(lagms) == 0 diff --git a/tests/test_route.py b/tests/test_route.py index d6f4a502c75..c9928214510 100644 --- a/tests/test_route.py +++ b/tests/test_route.py @@ -4,41 +4,42 @@ import time import json -def test_RouteAdd(dvs, testlog): +class TestRoute(object): + def test_RouteAdd(self, dvs, testlog): - config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) - intf_tbl = swsscommon.Table(config_db, "INTERFACE") - fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) - intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) - intf_tbl.set("Ethernet4|10.0.0.2/31", fvs) - intf_tbl.set("Ethernet0", fvs) - intf_tbl.set("Ethernet4", fvs) - dvs.runcmd("ifconfig Ethernet0 up") - dvs.runcmd("ifconfig Ethernet4 up") + config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + intf_tbl = swsscommon.Table(config_db, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) + intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) + intf_tbl.set("Ethernet4|10.0.0.2/31", fvs) + intf_tbl.set("Ethernet0", fvs) + intf_tbl.set("Ethernet4", fvs) + dvs.runcmd("ifconfig Ethernet0 up") + dvs.runcmd("ifconfig Ethernet4 up") - dvs.servers[0].runcmd("ifconfig eth0 10.0.0.1/31") - dvs.servers[0].runcmd("ip route add default via 10.0.0.0") + dvs.servers[0].runcmd("ifconfig eth0 10.0.0.1/31") + dvs.servers[0].runcmd("ip route add default via 10.0.0.0") - dvs.servers[1].runcmd("ifconfig eth0 10.0.0.3/31") - dvs.servers[1].runcmd("ip route add default via 10.0.0.2") + dvs.servers[1].runcmd("ifconfig eth0 10.0.0.3/31") + dvs.servers[1].runcmd("ip route add default via 10.0.0.2") - # get neighbor and arp entry - dvs.servers[0].runcmd("ping -c 1 10.0.0.3") + # get neighbor and arp entry + dvs.servers[0].runcmd("ping -c 1 10.0.0.3") - db = swsscommon.DBConnector(0, dvs.redis_sock, 0) - ps = swsscommon.ProducerStateTable(db, "ROUTE_TABLE") - fvs = swsscommon.FieldValuePairs([("nexthop","10.0.0.1"), ("ifname", "Ethernet0")]) + db = swsscommon.DBConnector(0, dvs.redis_sock, 0) + ps = swsscommon.ProducerStateTable(db, "ROUTE_TABLE") + fvs = swsscommon.FieldValuePairs([("nexthop","10.0.0.1"), ("ifname", "Ethernet0")]) - pubsub = dvs.SubscribeAsicDbObject("SAI_OBJECT_TYPE_ROUTE_ENTRY") + pubsub = dvs.SubscribeAsicDbObject("SAI_OBJECT_TYPE_ROUTE_ENTRY") - ps.set("2.2.2.0/24", fvs) + ps.set("2.2.2.0/24", fvs) - # check if route was propagated to ASIC DB + # check if route was propagated to ASIC DB - (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsub) + (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsub) - assert len(addobjs) == 1 + assert len(addobjs) == 1 - rt_key = json.loads(addobjs[0]['key']) + rt_key = json.loads(addobjs[0]['key']) - assert rt_key['dest'] == "2.2.2.0/24" + assert rt_key['dest'] == "2.2.2.0/24" diff --git a/tests/test_setro.py b/tests/test_setro.py index 8c962dd20e8..84b004a878b 100644 --- a/tests/test_setro.py +++ b/tests/test_setro.py @@ -4,37 +4,38 @@ import redis from pprint import pprint -def test_SetReadOnlyAttribute(dvs, testlog): +class TestSetRo(object): + def test_SetReadOnlyAttribute(self, dvs, testlog): - db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) - tbl = swsscommon.Table(db, "ASIC_STATE:SAI_OBJECT_TYPE_SWITCH") + tbl = swsscommon.Table(db, "ASIC_STATE:SAI_OBJECT_TYPE_SWITCH") - keys = tbl.getKeys() + keys = tbl.getKeys() - assert len(keys) == 1 + assert len(keys) == 1 - swVid = keys[0] - - r = redis.Redis(unix_socket_path=dvs.redis_sock, db=swsscommon.ASIC_DB) + swVid = keys[0] - swRid = r.hget("VIDTORID", swVid) + r = redis.Redis(unix_socket_path=dvs.redis_sock, db=swsscommon.ASIC_DB) - assert swRid is not None + swRid = r.hget("VIDTORID", swVid) - ntf = swsscommon.NotificationProducer(db, "SAI_VS_UNITTEST_CHANNEL") + assert swRid is not None - fvp = swsscommon.FieldValuePairs() + ntf = swsscommon.NotificationProducer(db, "SAI_VS_UNITTEST_CHANNEL") - ntf.send("enable_unittests", "true", fvp) + fvp = swsscommon.FieldValuePairs() - fvp = swsscommon.FieldValuePairs([('SAI_SWITCH_ATTR_PORT_MAX_MTU', '42')]) + ntf.send("enable_unittests", "true", fvp) - key = "SAI_OBJECT_TYPE_SWITCH:" + swRid + fvp = swsscommon.FieldValuePairs([('SAI_SWITCH_ATTR_PORT_MAX_MTU', '42')]) - print key + key = "SAI_OBJECT_TYPE_SWITCH:" + swRid - ntf.send("set_ro", key, fvp) + print key - # make action on appdb so orchagent will get RO value - # read asic db to see if orchagent behaved correctly + ntf.send("set_ro", key, fvp) + + # make action on appdb so orchagent will get RO value + # read asic db to see if orchagent behaved correctly diff --git a/tests/test_vrf.py b/tests/test_vrf.py index 3dec3e0dc19..a53d498b98c 100644 --- a/tests/test_vrf.py +++ b/tests/test_vrf.py @@ -150,90 +150,90 @@ def packet_action_gen(): r = random.choice(values) return r[0], r[1] - -def test_VRFOrch_Comprehensive(dvs, testlog): - asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) - appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) - - attributes = [ - ('v4', 'SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V4_STATE', boolean_gen), - ('v6', 'SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V6_STATE', boolean_gen), - ('src_mac', 'SAI_VIRTUAL_ROUTER_ATTR_SRC_MAC_ADDRESS', mac_addr_gen), - ('ttl_action', 'SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_TTL1_PACKET_ACTION', packet_action_gen), - ('ip_opt_action', 'SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_IP_OPTIONS_PACKET_ACTION', packet_action_gen), - ('l3_mc_action', 'SAI_VIRTUAL_ROUTER_ATTR_UNKNOWN_L3_MULTICAST_PACKET_ACTION', packet_action_gen), - ] - - random.seed(int(time.clock())) - - for n in xrange(2**len(attributes)): - # generate testcases for all combinations of attributes +class TestVrf(object): + def test_VRFOrch_Comprehensive(self, dvs, testlog): + asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) + + attributes = [ + ('v4', 'SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V4_STATE', boolean_gen), + ('v6', 'SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V6_STATE', boolean_gen), + ('src_mac', 'SAI_VIRTUAL_ROUTER_ATTR_SRC_MAC_ADDRESS', mac_addr_gen), + ('ttl_action', 'SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_TTL1_PACKET_ACTION', packet_action_gen), + ('ip_opt_action', 'SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_IP_OPTIONS_PACKET_ACTION', packet_action_gen), + ('l3_mc_action', 'SAI_VIRTUAL_ROUTER_ATTR_UNKNOWN_L3_MULTICAST_PACKET_ACTION', packet_action_gen), + ] + + random.seed(int(time.clock())) + + for n in xrange(2**len(attributes)): + # generate testcases for all combinations of attributes + req_attr = [] + exp_attr = {} + vrf_name = "vrf_%d" % n + bmask = 0x1 + for an in xrange(len(attributes)): + if (bmask & n) > 0: + req_res, exp_res = attributes[an][2]() + req_attr.append((attributes[an][0], req_res)) + exp_attr[attributes[an][1]] = exp_res + bmask <<= 1 + state = vrf_create(asic_db, appl_db, vrf_name, req_attr, exp_attr) + vrf_remove(asic_db, appl_db, vrf_name, state) + + + def test_VRFOrch(self, dvs, testlog): + asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) + state = vrf_create(asic_db, appl_db, "vrf0", + [ + ], + { + } + ) + vrf_remove(asic_db, appl_db, "vrf0", state) + + state = vrf_create(asic_db, appl_db, "vrf1", + [ + ('v4', 'true'), + ('src_mac', '02:04:06:07:08:09'), + ], + { + 'SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V4_STATE': 'true', + 'SAI_VIRTUAL_ROUTER_ATTR_SRC_MAC_ADDRESS': '02:04:06:07:08:09', + } + ) + vrf_remove(asic_db, appl_db, "vrf1", state) + + def test_VRFOrch_Update(self, dvs, testlog): + asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) + + attributes = [ + ('v4', 'SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V4_STATE', boolean_gen), + ('v6', 'SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V6_STATE', boolean_gen), + ('src_mac', 'SAI_VIRTUAL_ROUTER_ATTR_SRC_MAC_ADDRESS', mac_addr_gen), + ('ttl_action', 'SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_TTL1_PACKET_ACTION', packet_action_gen), + ('ip_opt_action', 'SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_IP_OPTIONS_PACKET_ACTION', packet_action_gen), + ('l3_mc_action', 'SAI_VIRTUAL_ROUTER_ATTR_UNKNOWN_L3_MULTICAST_PACKET_ACTION', packet_action_gen), + ] + + random.seed(int(time.clock())) + + state = vrf_create(asic_db, appl_db, "vrf_a", + [ + ], + { + } + ) + + # try to update each attribute req_attr = [] exp_attr = {} - vrf_name = "vrf_%d" % n - bmask = 0x1 - for an in xrange(len(attributes)): - if (bmask & n) > 0: - req_res, exp_res = attributes[an][2]() - req_attr.append((attributes[an][0], req_res)) - exp_attr[attributes[an][1]] = exp_res - bmask <<= 1 - state = vrf_create(asic_db, appl_db, vrf_name, req_attr, exp_attr) - vrf_remove(asic_db, appl_db, vrf_name, state) - - -def test_VRFOrch(dvs, testlog): - asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) - appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) - state = vrf_create(asic_db, appl_db, "vrf0", - [ - ], - { - } - ) - vrf_remove(asic_db, appl_db, "vrf0", state) - - state = vrf_create(asic_db, appl_db, "vrf1", - [ - ('v4', 'true'), - ('src_mac', '02:04:06:07:08:09'), - ], - { - 'SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V4_STATE': 'true', - 'SAI_VIRTUAL_ROUTER_ATTR_SRC_MAC_ADDRESS': '02:04:06:07:08:09', - } - ) - vrf_remove(asic_db, appl_db, "vrf1", state) - -def test_VRFOrch_Update(dvs, testlog): - asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) - appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) - - attributes = [ - ('v4', 'SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V4_STATE', boolean_gen), - ('v6', 'SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V6_STATE', boolean_gen), - ('src_mac', 'SAI_VIRTUAL_ROUTER_ATTR_SRC_MAC_ADDRESS', mac_addr_gen), - ('ttl_action', 'SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_TTL1_PACKET_ACTION', packet_action_gen), - ('ip_opt_action', 'SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_IP_OPTIONS_PACKET_ACTION', packet_action_gen), - ('l3_mc_action', 'SAI_VIRTUAL_ROUTER_ATTR_UNKNOWN_L3_MULTICAST_PACKET_ACTION', packet_action_gen), - ] - - random.seed(int(time.clock())) - - state = vrf_create(asic_db, appl_db, "vrf_a", - [ - ], - { - } - ) - - # try to update each attribute - req_attr = [] - exp_attr = {} - for attr in attributes: - req_res, exp_res = attr[2]() - req_attr.append((attr[0], req_res)) - exp_attr[attr[1]] = exp_res - vrf_update(asic_db, appl_db, "vrf_a", req_attr, exp_attr, state) + for attr in attributes: + req_res, exp_res = attr[2]() + req_attr.append((attr[0], req_res)) + exp_attr[attr[1]] = exp_res + vrf_update(asic_db, appl_db, "vrf_a", req_attr, exp_attr, state) - vrf_remove(asic_db, appl_db, "vrf_a", state) + vrf_remove(asic_db, appl_db, "vrf_a", state) diff --git a/tests/test_vxlan_tunnel.py b/tests/test_vxlan_tunnel.py index c1306b89667..225a913bb6d 100644 --- a/tests/test_vxlan_tunnel.py +++ b/tests/test_vxlan_tunnel.py @@ -241,69 +241,69 @@ def get_lo(dvs): return lo_id +class TestVxlan(object): + def test_vxlan_term_orch(self, dvs, testlog): + tunnel_map_ids = set() + tunnel_map_entry_ids = set() + tunnel_ids = set() + tunnel_term_ids = set() + tunnel_map_map = {} + vlan_ids = get_exist_entries(dvs, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + loopback_id = get_lo(dvs) -def test_vxlan_term_orch(dvs, testlog): - tunnel_map_ids = set() - tunnel_map_entry_ids = set() - tunnel_ids = set() - tunnel_term_ids = set() - tunnel_map_map = {} - vlan_ids = get_exist_entries(dvs, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") - loopback_id = get_lo(dvs) + create_vlan(dvs, "Vlan50", vlan_ids) + create_vlan(dvs, "Vlan51", vlan_ids) + create_vlan(dvs, "Vlan52", vlan_ids) + create_vlan(dvs, "Vlan53", vlan_ids) + create_vlan(dvs, "Vlan54", vlan_ids) + create_vlan(dvs, "Vlan55", vlan_ids) + create_vlan(dvs, "Vlan56", vlan_ids) + create_vlan(dvs, "Vlan57", vlan_ids) - create_vlan(dvs, "Vlan50", vlan_ids) - create_vlan(dvs, "Vlan51", vlan_ids) - create_vlan(dvs, "Vlan52", vlan_ids) - create_vlan(dvs, "Vlan53", vlan_ids) - create_vlan(dvs, "Vlan54", vlan_ids) - create_vlan(dvs, "Vlan55", vlan_ids) - create_vlan(dvs, "Vlan56", vlan_ids) - create_vlan(dvs, "Vlan57", vlan_ids) + create_vxlan_tunnel(dvs, 'tunnel_1', '10.0.0.1', '100.100.100.1', + tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids, loopback_id) - create_vxlan_tunnel(dvs, 'tunnel_1', '10.0.0.1', '100.100.100.1', - tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids, loopback_id) + create_vxlan_tunnel_entry(dvs, 'tunnel_1', 'entry_1', tunnel_map_map, 'Vlan50', '850', + tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids) - create_vxlan_tunnel_entry(dvs, 'tunnel_1', 'entry_1', tunnel_map_map, 'Vlan50', '850', - tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids) + tunnel_map_map['tunnel_1'] = check_vxlan_tunnel(dvs,'10.0.0.1', '100.100.100.1', + tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids, loopback_id) - tunnel_map_map['tunnel_1'] = check_vxlan_tunnel(dvs,'10.0.0.1', '100.100.100.1', - tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids, loopback_id) + create_vxlan_tunnel(dvs, 'tunnel_2', '11.0.0.2', '101.101.101.2', + tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids, loopback_id) - create_vxlan_tunnel(dvs, 'tunnel_2', '11.0.0.2', '101.101.101.2', - tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids, loopback_id) + create_vxlan_tunnel_entry(dvs, 'tunnel_2', 'entry_1', tunnel_map_map, 'Vlan51', '851', + tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids) - create_vxlan_tunnel_entry(dvs, 'tunnel_2', 'entry_1', tunnel_map_map, 'Vlan51', '851', - tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids) + tunnel_map_map['tunnel_2'] = check_vxlan_tunnel(dvs,'11.0.0.2', '101.101.101.2', + tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids, loopback_id) - tunnel_map_map['tunnel_2'] = check_vxlan_tunnel(dvs,'11.0.0.2', '101.101.101.2', - tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids, loopback_id) + create_vxlan_tunnel(dvs, 'tunnel_3', '12.0.0.3', '0.0.0.0', + tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids, loopback_id) - create_vxlan_tunnel(dvs, 'tunnel_3', '12.0.0.3', '0.0.0.0', - tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids, loopback_id) + create_vxlan_tunnel_entry(dvs, 'tunnel_3', 'entry_1', tunnel_map_map, 'Vlan52', '852', + tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids) - create_vxlan_tunnel_entry(dvs, 'tunnel_3', 'entry_1', tunnel_map_map, 'Vlan52', '852', - tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids) + tunnel_map_map['tunnel_3'] = check_vxlan_tunnel(dvs, '12.0.0.3', '0.0.0.0', + tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids, loopback_id) - tunnel_map_map['tunnel_3'] = check_vxlan_tunnel(dvs, '12.0.0.3', '0.0.0.0', - tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids, loopback_id) + create_vxlan_tunnel(dvs, 'tunnel_4', '15.0.0.5', '0.0.0.0', + tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids, loopback_id, True) - create_vxlan_tunnel(dvs, 'tunnel_4', '15.0.0.5', '0.0.0.0', - tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids, loopback_id, True) + create_vxlan_tunnel_entry(dvs, 'tunnel_4', 'entry_1', tunnel_map_map, 'Vlan53', '853', + tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids) - create_vxlan_tunnel_entry(dvs, 'tunnel_4', 'entry_1', tunnel_map_map, 'Vlan53', '853', - tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids) + tunnel_map_map['tunnel_4'] = check_vxlan_tunnel(dvs, '15.0.0.5', '0.0.0.0', + tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids, loopback_id) - tunnel_map_map['tunnel_4'] = check_vxlan_tunnel(dvs, '15.0.0.5', '0.0.0.0', - tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids, loopback_id) + create_vxlan_tunnel_entry(dvs, 'tunnel_1', 'entry_2', tunnel_map_map, 'Vlan54', '854', + tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids) - create_vxlan_tunnel_entry(dvs, 'tunnel_1', 'entry_2', tunnel_map_map, 'Vlan54', '854', - tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids) + create_vxlan_tunnel_entry(dvs, 'tunnel_2', 'entry_2', tunnel_map_map, 'Vlan55', '855', + tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids) - create_vxlan_tunnel_entry(dvs, 'tunnel_2', 'entry_2', tunnel_map_map, 'Vlan55', '855', - tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids) + create_vxlan_tunnel_entry(dvs, 'tunnel_3', 'entry_2', tunnel_map_map, 'Vlan56', '856', + tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids) - create_vxlan_tunnel_entry(dvs, 'tunnel_3', 'entry_2', tunnel_map_map, 'Vlan56', '856', - tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids) - - create_vxlan_tunnel_entry(dvs, 'tunnel_4', 'entry_2', tunnel_map_map, 'Vlan57', '857', - tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids) + create_vxlan_tunnel_entry(dvs, 'tunnel_4', 'entry_2', tunnel_map_map, 'Vlan57', '857', + tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids) diff --git a/tests/test_warm_reboot.py b/tests/test_warm_reboot.py index e87c644b47f..31795d3dddf 100644 --- a/tests/test_warm_reboot.py +++ b/tests/test_warm_reboot.py @@ -5,6 +5,14 @@ import json import pytest + +# macros for number of interfaces and number of neighbors +# TBD: NUM_NEIGH_PER_INTF >= 128 ips will cause test framework to hang by default kernel settings +# TBD: Need tune gc_thresh1/2/3 at host side of vs docker to support this. +NUM_INTF = 8 +NUM_NEIGH_PER_INTF = 16 #128 +NUM_OF_NEIGHS = (NUM_INTF*NUM_NEIGH_PER_INTF) + # Get restore count of all processes supporting warm restart def swss_get_RestoreCount(dvs, state_db): restore_count = {} @@ -106,213 +114,6 @@ def how_many_entries_exist(db, table): tbl = swsscommon.Table(db, table) return len(tbl.getKeys()) -def test_PortSyncdWarmRestart(dvs, testlog): - - conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) - appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) - state_db = swsscommon.DBConnector(swsscommon.STATE_DB, dvs.redis_sock, 0) - - dvs.runcmd("config warm_restart enable swss") - - dvs.runcmd("ifconfig Ethernet16 up") - dvs.runcmd("ifconfig Ethernet20 up") - - time.sleep(1) - - config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) - intf_tbl = swsscommon.Table(config_db, "INTERFACE") - fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) - intf_tbl.set("Ethernet16|11.0.0.1/29", fvs) - intf_tbl.set("Ethernet20|11.0.0.9/29", fvs) - intf_tbl.set("Ethernet16", fvs) - intf_tbl.set("Ethernet20", fvs) - dvs.runcmd("ifconfig Ethernet16 up") - dvs.runcmd("ifconfig Ethernet20 up") - - dvs.servers[4].runcmd("ip link set down dev eth0") == 0 - dvs.servers[4].runcmd("ip link set up dev eth0") == 0 - dvs.servers[4].runcmd("ifconfig eth0 11.0.0.2/29") - dvs.servers[4].runcmd("ip route add default via 11.0.0.1") - - dvs.servers[5].runcmd("ip link set down dev eth0") == 0 - dvs.servers[5].runcmd("ip link set up dev eth0") == 0 - dvs.servers[5].runcmd("ifconfig eth0 11.0.0.10/29") - dvs.servers[5].runcmd("ip route add default via 11.0.0.9") - - time.sleep(1) - - # Ethernet port oper status should be up - check_port_oper_status(appl_db, "Ethernet16", "up") - check_port_oper_status(appl_db, "Ethernet20", "up") - - # Ping should work between servers via vs vlan interfaces - ping_stats = dvs.servers[4].runcmd("ping -c 1 11.0.0.10") - time.sleep(1) - - neighTbl = swsscommon.Table(appl_db, "NEIGH_TABLE") - (status, fvs) = neighTbl.get("Ethernet16:11.0.0.2") - assert status == True - - (status, fvs) = neighTbl.get("Ethernet20:11.0.0.10") - assert status == True - - restore_count = swss_get_RestoreCount(dvs, state_db) - - # restart portsyncd - dvs.runcmd(['sh', '-c', 'pkill -x portsyncd']) - - pubsub = dvs.SubscribeAsicDbObject("SAI_OBJECT_TYPE") - dvs.runcmd(['sh', '-c', 'supervisorctl start portsyncd']) - - (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) - assert nadd == 0 - assert ndel == 0 - - #new ip on server 5 - dvs.servers[5].runcmd("ifconfig eth0 11.0.0.11/29") - - # Ping should work between servers via vs Ethernet interfaces - ping_stats = dvs.servers[4].runcmd("ping -c 1 11.0.0.11") - - # new neighbor learn on VS - (status, fvs) = neighTbl.get("Ethernet20:11.0.0.11") - assert status == True - - # Port state change reflected in appDB correctly - dvs.servers[6].runcmd("ip link set down dev eth0") == 0 - dvs.servers[6].runcmd("ip link set up dev eth0") == 0 - time.sleep(1) - - check_port_oper_status(appl_db, "Ethernet16", "up") - check_port_oper_status(appl_db, "Ethernet20", "up") - check_port_oper_status(appl_db, "Ethernet24", "up") - - - swss_app_check_RestoreCount_single(state_db, restore_count, "portsyncd") - - intf_tbl._del("Ethernet16|11.0.0.1/29") - intf_tbl._del("Ethernet20|11.0.0.9/29") - intf_tbl._del("Ethernet16") - intf_tbl._del("Ethernet20") - time.sleep(2) - - -def test_VlanMgrdWarmRestart(dvs, testlog): - - conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) - appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) - state_db = swsscommon.DBConnector(swsscommon.STATE_DB, dvs.redis_sock, 0) - - dvs.runcmd("ifconfig Ethernet16 0") - dvs.runcmd("ifconfig Ethernet20 0") - - dvs.runcmd("ifconfig Ethernet16 up") - dvs.runcmd("ifconfig Ethernet20 up") - - time.sleep(1) - - dvs.runcmd("config warm_restart enable swss") - - # create vlan - create_entry_tbl( - conf_db, - "VLAN", "Vlan16", - [ - ("vlanid", "16"), - ] - ) - # create vlan - create_entry_tbl( - conf_db, - "VLAN", "Vlan20", - [ - ("vlanid", "20"), - ] - ) - # create vlan member entry in config db. Don't use Ethernet0/4/8/12 as IP configured on them in previous testing. - create_entry_tbl( - conf_db, - "VLAN_MEMBER", "Vlan16|Ethernet16", - [ - ("tagging_mode", "untagged"), - ] - ) - - create_entry_tbl( - conf_db, - "VLAN_MEMBER", "Vlan20|Ethernet20", - [ - ("tagging_mode", "untagged"), - ] - ) - - time.sleep(1) - - intf_tbl = swsscommon.Table(conf_db, "INTERFACE") - fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) - intf_tbl.set("Vlan16|11.0.0.1/29", fvs) - intf_tbl.set("Vlan20|11.0.0.9/29", fvs) - intf_tbl.set("Vlan16", fvs) - intf_tbl.set("Vlan20", fvs) - dvs.runcmd("ifconfig Vlan16 up") - dvs.runcmd("ifconfig Vlan20 up") - - dvs.servers[4].runcmd("ifconfig eth0 11.0.0.2/29") - dvs.servers[4].runcmd("ip route add default via 11.0.0.1") - - dvs.servers[5].runcmd("ifconfig eth0 11.0.0.10/29") - dvs.servers[5].runcmd("ip route add default via 11.0.0.9") - - time.sleep(1) - - # Ping should work between servers via vs vlan interfaces - ping_stats = dvs.servers[4].runcmd("ping -c 1 11.0.0.10") - time.sleep(1) - - tbl = swsscommon.Table(appl_db, "NEIGH_TABLE") - (status, fvs) = tbl.get("Vlan16:11.0.0.2") - assert status == True - - (status, fvs) = tbl.get("Vlan20:11.0.0.10") - assert status == True - - (exitcode, bv_before) = dvs.runcmd("bridge vlan") - print(bv_before) - - restore_count = swss_get_RestoreCount(dvs, state_db) - - dvs.runcmd(['sh', '-c', 'pkill -x vlanmgrd']) - - pubsub = dvs.SubscribeAsicDbObject("SAI_OBJECT_TYPE") - - dvs.runcmd(['sh', '-c', 'supervisorctl start vlanmgrd']) - time.sleep(2) - - (exitcode, bv_after) = dvs.runcmd("bridge vlan") - assert bv_after == bv_before - - (nadd, ndel) = dvs.CountSubscribedObjects(pubsub, ignore=["SAI_OBJECT_TYPE_FDB_ENTRY"]) - assert nadd == 0 - assert ndel == 0 - - #new ip on server 5 - dvs.servers[5].runcmd("ifconfig eth0 11.0.0.11/29") - - # Ping should work between servers via vs vlan interfaces - ping_stats = dvs.servers[4].runcmd("ping -c 1 11.0.0.11") - - # new neighbor learn on VS - (status, fvs) = tbl.get("Vlan20:11.0.0.11") - assert status == True - - swss_app_check_RestoreCount_single(state_db, restore_count, "vlanmgrd") - - intf_tbl._del("Vlan16|11.0.0.1/29") - intf_tbl._del("Vlan20|11.0.0.9/29") - intf_tbl._del("Vlan16") - intf_tbl._del("Vlan20") - time.sleep(2) - def stop_neighsyncd(dvs): dvs.runcmd(['sh', '-c', 'pkill -x neighsyncd']) @@ -384,593 +185,6 @@ def check_syslog_for_neighbor_entry(dvs, marker, new_cnt, delete_cnt, iptype): else: assert "iptype is unknown" == "" -def test_swss_neighbor_syncup(dvs, testlog): - - appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) - conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) - state_db = swsscommon.DBConnector(swsscommon.STATE_DB, dvs.redis_sock, 0) - - dvs.runcmd("config warm_restart enable swss") - - # - # Testcase1: - # Add neighbor entries in linux kernel, appDB should get all of them - # - - # create neighbor entries (4 ipv4 and 4 ip6, two each on each interface) in linux kernel - intfs = ["Ethernet24", "Ethernet28"] - - for intf in intfs: - # set timeout to be the same as real HW - dvs.runcmd("sysctl -w net.ipv4.neigh.{}.base_reachable_time_ms=1800000".format(intf)) - dvs.runcmd("sysctl -w net.ipv6.neigh.{}.base_reachable_time_ms=1800000".format(intf)) - - #enable ipv6 on docker - dvs.runcmd("sysctl net.ipv6.conf.all.disable_ipv6=0") - - config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) - intf_tbl = swsscommon.Table(config_db, "INTERFACE") - fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) - intf_tbl.set("{}|24.0.0.1/24".format(intfs[0]), fvs) - intf_tbl.set("{}|28.0.0.9/24".format(intfs[1]), fvs) - intf_tbl.set("{}|2400::1/64".format(intfs[0]), fvs) - intf_tbl.set("{}|2800::1/64".format(intfs[1]), fvs) - intf_tbl.set("{}".format(intfs[0]), fvs) - intf_tbl.set("{}".format(intfs[1]), fvs) - intf_tbl.set("{}".format(intfs[0]), fvs) - intf_tbl.set("{}".format(intfs[1]), fvs) - dvs.runcmd("ifconfig {} up".format(intfs[0])) - dvs.runcmd("ifconfig {} up".format(intfs[1])) - - ips = ["24.0.0.2", "24.0.0.3", "28.0.0.2", "28.0.0.3"] - v6ips = ["2400::2", "2400::3", "2800::2", "2800::3"] - - macs = ["00:00:00:00:24:02", "00:00:00:00:24:03", "00:00:00:00:28:02", "00:00:00:00:28:03"] - - for i in range(len(ips)): - dvs.runcmd("ip neigh add {} dev {} lladdr {} nud reachable".format(ips[i], intfs[i/2], macs[i])) - - for i in range(len(v6ips)): - dvs.runcmd("ip -6 neigh add {} dev {} lladdr {} nud reachable".format(v6ips[i], intfs[i/2], macs[i])) - - time.sleep(1) - - # Check the neighbor entries are inserted correctly - db = swsscommon.DBConnector(0, dvs.redis_sock, 0) - tbl = swsscommon.Table(db, "NEIGH_TABLE") - - for i in range(len(ips)): - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) - assert status == True - - for v in fvs: - if v[0] == "neigh": - assert v[1] == macs[i] - if v[0] == "family": - assert v[1] == "IPv4" - - for i in range(len(v6ips)): - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) - assert status == True - - for v in fvs: - if v[0] == "neigh": - assert v[1] == macs[i] - if v[0] == "family": - assert v[1] == "IPv6" - - # - # Testcase 2: - # Restart neighsyncd without change neighbor entries, nothing should be sent to appDB or sairedis, - # appDB should be kept the same. - # - - # get restore_count - restore_count = swss_get_RestoreCount(dvs, state_db) - - # stop neighsyncd and sairedis.rec - stop_neighsyncd(dvs) - del_entry_tbl(state_db, "NEIGH_RESTORE_TABLE", "Flags") - marker = dvs.add_log_marker() - pubsub = dvs.SubscribeAsicDbObject("SAI_OBJECT_TYPE_NEIGHBOR_ENTRY") - start_neighsyncd(dvs) - start_restore_neighbors(dvs) - time.sleep(10) - - # Check the neighbor entries are still in appDB correctly - for i in range(len(ips)): - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) - assert status == True - - for v in fvs: - if v[0] == "neigh": - assert v[1] == macs[i] - if v[0] == "family": - assert v[1] == "IPv4" - - for i in range(len(v6ips)): - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) - assert status == True - - for v in fvs: - if v[0] == "neigh": - assert v[1] == macs[i] - if v[0] == "family": - assert v[1] == "IPv6" - - # check syslog and sairedis.rec file for activities - check_syslog_for_neighbor_entry(dvs, marker, 0, 0, "ipv4") - check_syslog_for_neighbor_entry(dvs, marker, 0, 0, "ipv6") - (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) - assert nadd == 0 - assert ndel == 0 - - # check restore Count - swss_app_check_RestoreCount_single(state_db, restore_count, "neighsyncd") - - # - # Testcase 3: - # stop neighsyncd, delete even nummber ipv4/ipv6 neighbor entries from each interface, warm start neighsyncd. - # the neighsyncd is supposed to sync up the entries from kernel after warm restart - # note: there was an issue for neighbor delete, it will be marked as FAILED instead of deleted in kernel - # but it will send netlink message to be removed from appDB, so it works ok here, - # just that if we want to add the same neighbor again, use "change" instead of "add" - - # get restore_count - restore_count = swss_get_RestoreCount(dvs, state_db) - - # stop neighsyncd - stop_neighsyncd(dvs) - del_entry_tbl(state_db, "NEIGH_RESTORE_TABLE", "Flags") - marker = dvs.add_log_marker() - - # delete even nummber of ipv4/ipv6 neighbor entries from each interface - for i in range(0, len(ips), 2): - dvs.runcmd("ip neigh del {} dev {}".format(ips[i], intfs[i/2])) - - for i in range(0, len(v6ips), 2): - dvs.runcmd("ip -6 neigh del {} dev {}".format(v6ips[i], intfs[i/2])) - - # start neighsyncd again - start_neighsyncd(dvs) - start_restore_neighbors(dvs) - time.sleep(10) - - # check ipv4 and ipv6 neighbors - for i in range(len(ips)): - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) - #should not see deleted neighbor entries - if i % 2 == 0: - assert status == False - continue - else: - assert status == True - - #undeleted entries should still be there. - for v in fvs: - if v[0] == "neigh": - assert v[1] == macs[i] - if v[0] == "family": - assert v[1] == "IPv4" - - for i in range(len(v6ips)): - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) - #should not see deleted neighbor entries - if i % 2 == 0: - assert status == False - continue - else: - assert status == True - - #undeleted entries should still be there. - for v in fvs: - if v[0] == "neigh": - assert v[1] == macs[i] - if v[0] == "family": - assert v[1] == "IPv6" - - # check syslog and sairedis.rec file for activities - # 2 deletes each for ipv4 and ipv6 - # 4 neighbor removal in asic db - check_syslog_for_neighbor_entry(dvs, marker, 0, 2, "ipv4") - check_syslog_for_neighbor_entry(dvs, marker, 0, 2, "ipv6") - (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) - assert nadd == 0 - assert ndel == 4 - - # check restore Count - swss_app_check_RestoreCount_single(state_db, restore_count, "neighsyncd") - - - # - # Testcase 4: - # Stop neighsyncd, add even nummber of ipv4/ipv6 neighbor entries to each interface again, - # Start neighsyncd - # The neighsyncd is supposed to sync up the entries from kernel after warm restart - # Check the timer is not retrieved from configDB since it is not configured - - # get restore_count - restore_count = swss_get_RestoreCount(dvs, state_db) - - # stop neighsyncd - stop_neighsyncd(dvs) - del_entry_tbl(state_db, "NEIGH_RESTORE_TABLE", "Flags") - marker = dvs.add_log_marker() - - # add even nummber of ipv4/ipv6 neighbor entries to each interface - # use "change" if neighbor is in FAILED state - for i in range(0, len(ips), 2): - (rc, output) = dvs.runcmd(['sh', '-c', "ip -4 neigh | grep {}".format(ips[i])]) - print output - if output: - dvs.runcmd("ip neigh change {} dev {} lladdr {} nud reachable".format(ips[i], intfs[i/2], macs[i])) - else: - dvs.runcmd("ip neigh add {} dev {} lladdr {} nud reachable".format(ips[i], intfs[i/2], macs[i])) - - for i in range(0, len(v6ips), 2): - (rc, output) = dvs.runcmd(['sh', '-c', "ip -6 neigh | grep {}".format(v6ips[i])]) - print output - if output: - dvs.runcmd("ip -6 neigh change {} dev {} lladdr {} nud reachable".format(v6ips[i], intfs[i/2], macs[i])) - else: - dvs.runcmd("ip -6 neigh add {} dev {} lladdr {} nud reachable".format(v6ips[i], intfs[i/2], macs[i])) - - # start neighsyncd again - start_neighsyncd(dvs) - start_restore_neighbors(dvs) - time.sleep(10) - - # no neighsyncd timer configured - check_no_neighsyncd_timer(dvs) - - # check ipv4 and ipv6 neighbors, should see all neighbors - for i in range(len(ips)): - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) - assert status == True - for v in fvs: - if v[0] == "neigh": - assert v[1] == macs[i] - if v[0] == "family": - assert v[1] == "IPv4" - - for i in range(len(v6ips)): - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) - assert status == True - for v in fvs: - if v[0] == "neigh": - assert v[1] == macs[i] - if v[0] == "family": - assert v[1] == "IPv6" - - # check syslog and asic db for activities - # 2 news entries for ipv4 and ipv6 each - # 4 neighbor creation in asic db - check_syslog_for_neighbor_entry(dvs, marker, 2, 0, "ipv4") - check_syslog_for_neighbor_entry(dvs, marker, 2, 0, "ipv6") - (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) - assert nadd == 4 - assert ndel == 0 - - # check restore Count - swss_app_check_RestoreCount_single(state_db, restore_count, "neighsyncd") - - # - # Testcase 5: - # Even number of ip4/6 neigbors updated with new mac. - # Odd number of ipv4/6 neighbors removed - # neighbor syncd should sync it up after warm restart - # include the timer settings in this testcase - - # setup timer in configDB - timer_value = "15" - - dvs.runcmd("config warm_restart neighsyncd_timer {}".format(timer_value)) - - # get restore_count - restore_count = swss_get_RestoreCount(dvs, state_db) - - # stop neighsyncd - stop_neighsyncd(dvs) - del_entry_tbl(state_db, "NEIGH_RESTORE_TABLE", "Flags") - marker = dvs.add_log_marker() - - # Even number of ip4/6 neigbors updated with new mac. - # Odd number of ipv4/6 neighbors removed - newmacs = ["00:00:00:01:12:02", "00:00:00:01:12:03", "00:00:00:01:16:02", "00:00:00:01:16:03"] - - for i in range(len(ips)): - if i % 2 == 0: - dvs.runcmd("ip neigh change {} dev {} lladdr {} nud reachable".format(ips[i], intfs[i/2], newmacs[i])) - else: - dvs.runcmd("ip neigh del {} dev {}".format(ips[i], intfs[i/2])) - - for i in range(len(v6ips)): - if i % 2 == 0: - dvs.runcmd("ip -6 neigh change {} dev {} lladdr {} nud reachable".format(v6ips[i], intfs[i/2], newmacs[i])) - else: - dvs.runcmd("ip -6 neigh del {} dev {}".format(v6ips[i], intfs[i/2])) - - # start neighsyncd again - start_neighsyncd(dvs) - start_restore_neighbors(dvs) - time.sleep(10) - - # timer is not expired yet, state should be "restored" - swss_app_check_warmstart_state(state_db, "neighsyncd", "restored") - time.sleep(10) - - # check neigh syncd timer is retrived from configDB - check_neighsyncd_timer(dvs, timer_value) - - # check ipv4 and ipv6 neighbors, should see all neighbors with updated info - for i in range(len(ips)): - if i % 2 == 0: - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) - assert status == True - for v in fvs: - if v[0] == "neigh": - assert v[1] == newmacs[i] - if v[0] == "family": - assert v[1] == "IPv4" - else: - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) - assert status == False - - for i in range(len(v6ips)): - if i % 2 == 0: - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) - assert status == True - for v in fvs: - if v[0] == "neigh": - assert v[1] == newmacs[i] - if v[0] == "family": - assert v[1] == "IPv6" - else: - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) - assert status == False - - time.sleep(2) - - # check syslog and asic db for activities - # 2 news, 2 deletes for ipv4 and ipv6 each - # 4 set, 4 removes for neighbor in asic db - check_syslog_for_neighbor_entry(dvs, marker, 2, 2, "ipv4") - check_syslog_for_neighbor_entry(dvs, marker, 2, 2, "ipv6") - (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) - assert nadd == 4 - assert ndel == 4 - - # check restore Count - swss_app_check_RestoreCount_single(state_db, restore_count, "neighsyncd") - - # post-cleanup - dvs.runcmd("ip -s neigh flush all") - dvs.runcmd("ip -6 -s neigh flush all") - - intf_tbl._del("{}|24.0.0.1/24".format(intfs[0])) - intf_tbl._del("{}|28.0.0.9/24".format(intfs[1])) - intf_tbl._del("{}|2400::1/64".format(intfs[0])) - intf_tbl._del("{}|2800::1/64".format(intfs[1])) - intf_tbl._del("{}".format(intfs[0])) - intf_tbl._del("{}".format(intfs[1])) - intf_tbl._del("{}".format(intfs[0])) - intf_tbl._del("{}".format(intfs[1])) - time.sleep(2) - - -# TODO: The condition of warm restart readiness check is still under discussion. -def test_OrchagentWarmRestartReadyCheck(dvs, testlog): - - time.sleep(1) - - dvs.runcmd("config warm_restart enable swss") - - config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) - intf_tbl = swsscommon.Table(config_db, "INTERFACE") - fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) - intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) - intf_tbl.set("Ethernet4|10.0.0.2/31", fvs) - intf_tbl.set("Ethernet0", fvs) - intf_tbl.set("Ethernet4", fvs) - dvs.runcmd("ifconfig Ethernet0 up") - dvs.runcmd("ifconfig Ethernet4 up") - - dvs.servers[0].runcmd("ifconfig eth0 10.0.0.1/31") - dvs.servers[0].runcmd("ip route add default via 10.0.0.0") - - dvs.servers[1].runcmd("ifconfig eth0 10.0.0.3/31") - dvs.servers[1].runcmd("ip route add default via 10.0.0.2") - - - appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) - ps = swsscommon.ProducerStateTable(appl_db, swsscommon.APP_ROUTE_TABLE_NAME) - fvs = swsscommon.FieldValuePairs([("nexthop","10.0.0.1"), ("ifname", "Ethernet0")]) - - ps.set("2.2.2.0/24", fvs) - - time.sleep(1) - # Should fail, since neighbor for next 10.0.0.1 has not been not resolved yet - (exitcode, result) = dvs.runcmd("/usr/bin/orchagent_restart_check") - assert result == "RESTARTCHECK failed\n" - - # Should succeed, the option for skipPendingTaskCheck -s and noFreeze -n have been provided. - # Wait up to 500 milliseconds for response from orchagent. Default wait time is 1000 milliseconds. - (exitcode, result) = dvs.runcmd("/usr/bin/orchagent_restart_check -n -s -w 500") - assert result == "RESTARTCHECK succeeded\n" - - # get neighbor and arp entry - dvs.servers[1].runcmd("ping -c 1 10.0.0.1") - - time.sleep(1) - (exitcode, result) = dvs.runcmd("/usr/bin/orchagent_restart_check") - assert result == "RESTARTCHECK succeeded\n" - - # Should fail since orchagent has been frozen at last step. - (exitcode, result) = dvs.runcmd("/usr/bin/orchagent_restart_check -n -s -w 500") - assert result == "RESTARTCHECK failed\n" - - # Cleaning previously pushed route-entry to ease life of subsequent testcases. - ps._del("2.2.2.0/24") - time.sleep(1) - - intf_tbl._del("Ethernet0|10.0.0.0/31") - intf_tbl._del("Ethernet4|10.0.0.2/31") - intf_tbl._del("Ethernet0") - intf_tbl._del("Ethernet4") - time.sleep(2) - - # recover for test cases after this one. - dvs.stop_swss() - dvs.start_swss() - time.sleep(5) - -def test_swss_port_state_syncup(dvs, testlog): - - appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) - conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) - state_db = swsscommon.DBConnector(swsscommon.STATE_DB, dvs.redis_sock, 0) - - dvs.runcmd("config warm_restart enable swss") - - tbl = swsscommon.Table(appl_db, swsscommon.APP_PORT_TABLE_NAME) - - restore_count = swss_get_RestoreCount(dvs, state_db) - - # update port admin state - intf_tbl = swsscommon.Table(conf_db, "INTERFACE") - fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) - intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) - intf_tbl.set("Ethernet4|10.0.0.2/31", fvs) - intf_tbl.set("Ethernet8|10.0.0.4/31", fvs) - intf_tbl.set("Ethernet0", fvs) - intf_tbl.set("Ethernet4", fvs) - intf_tbl.set("Ethernet8", fvs) - dvs.runcmd("ifconfig Ethernet0 up") - dvs.runcmd("ifconfig Ethernet4 up") - dvs.runcmd("ifconfig Ethernet8 up") - - dvs.runcmd("arp -s 10.0.0.1 00:00:00:00:00:01") - dvs.runcmd("arp -s 10.0.0.3 00:00:00:00:00:02") - dvs.runcmd("arp -s 10.0.0.5 00:00:00:00:00:03") - - dvs.servers[0].runcmd("ip link set down dev eth0") == 0 - dvs.servers[1].runcmd("ip link set down dev eth0") == 0 - dvs.servers[2].runcmd("ip link set down dev eth0") == 0 - - dvs.servers[2].runcmd("ip link set up dev eth0") == 0 - - time.sleep(3) - - for i in [0, 1, 2]: - (status, fvs) = tbl.get("Ethernet%d" % (i * 4)) - assert status == True - oper_status = "unknown" - for v in fvs: - if v[0] == "oper_status": - oper_status = v[1] - break - if i == 2: - assert oper_status == "up" - else: - assert oper_status == "down" - - intf_tbl._del("Ethernet0|10.0.0.0/31") - intf_tbl._del("Ethernet4|10.0.0.2/31") - intf_tbl._del("Ethernet8|10.0.0.4/31") - intf_tbl._del("Ethernet0") - intf_tbl._del("Ethernet4") - intf_tbl._del("Ethernet8") - time.sleep(2) - - dvs.stop_swss() - time.sleep(3) - - # flap the port oper status for Ethernet0, Ethernet4 and Ethernet8 - dvs.servers[0].runcmd("ip link set down dev eth0") == 0 - dvs.servers[1].runcmd("ip link set down dev eth0") == 0 - dvs.servers[2].runcmd("ip link set down dev eth0") == 0 - - dvs.servers[0].runcmd("ip link set up dev eth0") == 0 - dvs.servers[1].runcmd("ip link set up dev eth0") == 0 - - time.sleep(5) - dbobjs =[(swsscommon.APPL_DB, swsscommon.APP_PORT_TABLE_NAME + ":*"), \ - (swsscommon.STATE_DB, swsscommon.STATE_WARM_RESTART_TABLE_NAME + "|orchagent")] - pubsubDbs = dvs.SubscribeDbObjects(dbobjs) - dvs.start_swss() - start_restore_neighbors(dvs) - time.sleep(10) - - swss_check_RestoreCount(dvs, state_db, restore_count) - - intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) - intf_tbl.set("Ethernet4|10.0.0.2/31", fvs) - intf_tbl.set("Ethernet8|10.0.0.4/31", fvs) - intf_tbl.set("Ethernet0", fvs) - intf_tbl.set("Ethernet4", fvs) - intf_tbl.set("Ethernet8", fvs) - time.sleep(3) - - for i in [0, 1, 2]: - (status, fvs) = tbl.get("Ethernet%d" % (i * 4)) - assert status == True - oper_status = "unknown" - for v in fvs: - if v[0] == "oper_status": - oper_status = v[1] - break - if i == 2: - assert oper_status == "down" - else: - assert oper_status == "up" - - # check the pubsub messages. - # No appDB port table operation should exist before orchagent state restored flag got set. - # appDB port table status sync up happens before WARM_RESTART_TABLE reconciled flag is set - # pubsubMessages is an ordered list of pubsub messages. - pubsubMessages = dvs.GetSubscribedMessages(pubsubDbs) - - portOperStatusChanged = False - # number of times that WARM_RESTART_TABLE|orchagent key was set after the first - # appDB port table operation - orchStateCount = 0 - for message in pubsubMessages: - print message - key = message['channel'].split(':', 1)[1] - print key - if message['data'] != 'hset' and message['data'] != 'del': - continue - if key.find(swsscommon.APP_PORT_TABLE_NAME)==0: - portOperStatusChanged = True - else: - # found one orchagent WARM_RESTART_TABLE operation after appDB port table change - if portOperStatusChanged == True: - orchStateCount += 1; - - # Only WARM_RESTART_TABLE|orchagent state=reconciled operation may exist after port oper status change. - assert orchStateCount == 1 - - #clean up arp - dvs.runcmd("arp -d 10.0.0.1") - dvs.runcmd("arp -d 10.0.0.3") - dvs.runcmd("arp -d 10.0.0.5") - - intf_tbl._del("Ethernet0|10.0.0.0/31") - intf_tbl._del("Ethernet4|10.0.0.2/31") - intf_tbl._del("Ethernet8|10.0.0.4/31") - intf_tbl._del("Ethernet0") - intf_tbl._del("Ethernet4") - intf_tbl._del("Ethernet8") - time.sleep(2) - - -############################################################################# -# # -# Routing Warm-Restart Testing # -# # -############################################################################# - - def set_restart_timer(dvs, db, app_name, value): create_entry_tbl( db, @@ -980,967 +194,1754 @@ def set_restart_timer(dvs, db, app_name, value): ] ) -################################################################################ -# -# Routing warm-restart testcases -# -################################################################################ - - -def test_routing_WarmRestart(dvs, testlog): - - appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) - conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) - state_db = swsscommon.DBConnector(swsscommon.STATE_DB, dvs.redis_sock, 0) - - # Restart-timer to utilize during the following testcases - restart_timer = 15 +# 'ip neigh flush all' won't remove failed entries if number of neighs less than gc_threshold1 +# Also it takes time to remove them completly. +# We use arp off/on to do it +def flush_neigh_entries(dvs): + dvs.runcmd("ip link set group default arp off") + dvs.runcmd("ip link set group default arp on") +# Add neighbor entries on servers connecting to SONiC ports +# ping them to get the neighbor entries +def setup_initial_neighbors(dvs): + for i in range(8, 8+NUM_INTF): + for j in range(NUM_NEIGH_PER_INTF): + dvs.servers[i].runcmd("ip addr add {}.0.0.{}/24 dev eth0".format(i*4, j+2)) + dvs.servers[i].runcmd("ip -6 addr add {}00::{}/64 dev eth0".format(i*4,j+2)) - ############################################################################# - # - # Baseline configuration - # - ############################################################################# + time.sleep(1) + for i in range(8, 8+NUM_INTF): + for j in range(NUM_NEIGH_PER_INTF): + dvs.runcmd(['sh', '-c', "ping -c 1 -W 0 -q {}.0.0.{} > /dev/null 2>&1".format(i*4,j+2)]) + dvs.runcmd(['sh', '-c', "ping6 -c 1 -W 0 -q {}00::{} > /dev/null 2>&1".format(i*4,j+2)]) - # Defining create neighbor entries (4 ipv4 and 4 ip6, two each on each interface) in linux kernel - intfs = ["Ethernet0", "Ethernet4", "Ethernet8"] - - # Enable ipv6 on docker - dvs.runcmd("sysctl net.ipv6.conf.all.disable_ipv6=0") - - # Defining create neighbor entries (4 ipv4 and 4 ip6, two each on each interface) in linux kernel - intf_tbl = swsscommon.Table(conf_db, "INTERFACE") - fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) - intf_tbl.set("{}|111.0.0.1/24".format(intfs[0]), fvs) - intf_tbl.set("{}|1110::1/64".format(intfs[0]), fvs) - intf_tbl.set("{}|122.0.0.1/24".format(intfs[1]), fvs) - intf_tbl.set("{}|1220::1/64".format(intfs[1]), fvs) - intf_tbl.set("{}|133.0.0.1/24".format(intfs[2]), fvs) - intf_tbl.set("{}|1330::1/64".format(intfs[2]), fvs) - intf_tbl.set("{}".format(intfs[0]), fvs) - intf_tbl.set("{}".format(intfs[0]), fvs) - intf_tbl.set("{}".format(intfs[1]), fvs) - intf_tbl.set("{}".format(intfs[1]), fvs) - intf_tbl.set("{}".format(intfs[2]), fvs) - intf_tbl.set("{}".format(intfs[2]), fvs) - dvs.runcmd("ip link set {} up".format(intfs[0])) - dvs.runcmd("ip link set {} up".format(intfs[1])) - dvs.runcmd("ip link set {} up".format(intfs[2])) +# Del half of the ips and a new half of the ips +# note: the first ipv4 can not be deleted only +def del_and_add_neighbors(dvs): + for i in range(8, 8+NUM_INTF): + for j in range(NUM_NEIGH_PER_INTF/2): + dvs.servers[i].runcmd("ip addr del {}.0.0.{}/24 dev eth0".format(i*4, j+NUM_NEIGH_PER_INTF/2+2)) + dvs.servers[i].runcmd("ip -6 addr del {}00::{}/64 dev eth0".format(i*4,j+NUM_NEIGH_PER_INTF/2+2)) + dvs.servers[i].runcmd("ip addr add {}.0.0.{}/24 dev eth0".format(i*4, j+NUM_NEIGH_PER_INTF+2)) + dvs.servers[i].runcmd("ip -6 addr add {}00::{}/64 dev eth0".format(i*4,j+NUM_NEIGH_PER_INTF+2)) - time.sleep(1) +#ping new IPs +def ping_new_ips(dvs): + for i in range(8, 8+NUM_INTF): + for j in range(NUM_NEIGH_PER_INTF/2): + dvs.runcmd(['sh', '-c', "ping -c 1 -W 0 -q {}.0.0.{} > /dev/null 2>&1".format(i*4,j+NUM_NEIGH_PER_INTF+2)]) + dvs.runcmd(['sh', '-c', "ping6 -c 1 -W 0 -q {}00::{} > /dev/null 2>&1".format(i*4,j+NUM_NEIGH_PER_INTF+2)]) - # - # Setting peer's ip-addresses and associated neighbor-entries - # - ips = ["111.0.0.2", "122.0.0.2", "133.0.0.2"] - v6ips = ["1110::2", "1220::2", "1330::2"] - macs = ["00:00:00:00:11:02", "00:00:00:00:12:02", "00:00:00:00:13:02"] +class TestWarmReboot(object): + def test_PortSyncdWarmRestart(self, dvs, testlog): - for i in range(len(ips)): - dvs.runcmd("ip neigh add {} dev {} lladdr {}".format(ips[i], intfs[i%2], macs[i])) + conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) + state_db = swsscommon.DBConnector(swsscommon.STATE_DB, dvs.redis_sock, 0) - for i in range(len(v6ips)): - dvs.runcmd("ip -6 neigh add {} dev {} lladdr {}".format(v6ips[i], intfs[i%2], macs[i])) + dvs.runcmd("config warm_restart enable swss") - time.sleep(1) + dvs.runcmd("ifconfig Ethernet16 up") + dvs.runcmd("ifconfig Ethernet20 up") - # - # Defining baseline IPv4 non-ecmp route-entries - # - dvs.runcmd("ip route add 192.168.1.100/32 nexthop via 111.0.0.2") - dvs.runcmd("ip route add 192.168.1.200/32 nexthop via 122.0.0.2") - dvs.runcmd("ip route add 192.168.1.230/32 nexthop via 133.0.0.2") + time.sleep(1) - # - # Defining baseline IPv4 ecmp route-entries - # - dvs.runcmd("ip route add 192.168.1.1/32 nexthop via 111.0.0.2 nexthop via 122.0.0.2 nexthop via 133.0.0.2") - dvs.runcmd("ip route add 192.168.1.2/32 nexthop via 111.0.0.2 nexthop via 122.0.0.2 nexthop via 133.0.0.2") - dvs.runcmd("ip route add 192.168.1.3/32 nexthop via 111.0.0.2 nexthop via 122.0.0.2") + config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + intf_tbl = swsscommon.Table(config_db, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) + intf_tbl.set("Ethernet16|11.0.0.1/29", fvs) + intf_tbl.set("Ethernet20|11.0.0.9/29", fvs) + intf_tbl.set("Ethernet16", fvs) + intf_tbl.set("Ethernet20", fvs) + dvs.runcmd("ifconfig Ethernet16 up") + dvs.runcmd("ifconfig Ethernet20 up") - # - # Defining baseline IPv6 non-ecmp route-entries - # - dvs.runcmd("ip -6 route add fc00:11:11::1/128 nexthop via 1110::2") - dvs.runcmd("ip -6 route add fc00:12:12::1/128 nexthop via 1220::2") - dvs.runcmd("ip -6 route add fc00:13:13::1/128 nexthop via 1330::2") + dvs.servers[4].runcmd("ip link set down dev eth0") == 0 + dvs.servers[4].runcmd("ip link set up dev eth0") == 0 + dvs.servers[4].runcmd("ifconfig eth0 11.0.0.2/29") + dvs.servers[4].runcmd("ip route add default via 11.0.0.1") - # - # Defining baseline IPv6 ecmp route-entries - # - dvs.runcmd("ip -6 route add fc00:1:1::1/128 nexthop via 1110::2 nexthop via 1220::2 nexthop via 1330::2") - dvs.runcmd("ip -6 route add fc00:2:2::1/128 nexthop via 1110::2 nexthop via 1220::2 nexthop via 1330::2") - dvs.runcmd("ip -6 route add fc00:3:3::1/128 nexthop via 1110::2 nexthop via 1220::2") + dvs.servers[5].runcmd("ip link set down dev eth0") == 0 + dvs.servers[5].runcmd("ip link set up dev eth0") == 0 + dvs.servers[5].runcmd("ifconfig eth0 11.0.0.10/29") + dvs.servers[5].runcmd("ip route add default via 11.0.0.9") - time.sleep(5) + time.sleep(1) - # Enabling some extra logging for troubleshooting purposes - dvs.runcmd("swssloglevel -l INFO -c fpmsyncd") + # Ethernet port oper status should be up + check_port_oper_status(appl_db, "Ethernet16", "up") + check_port_oper_status(appl_db, "Ethernet20", "up") - # Subscribe to pubsub channels for routing-state associated to swss and sairedis dbs - pubsubAppDB = dvs.SubscribeAppDbObject("ROUTE_TABLE") - pubsubAsicDB = dvs.SubscribeAsicDbObject("SAI_OBJECT_TYPE_ROUTE_ENTRY") + # Ping should work between servers via vs vlan interfaces + ping_stats = dvs.servers[4].runcmd("ping -c 1 11.0.0.10") + time.sleep(1) + neighTbl = swsscommon.Table(appl_db, "NEIGH_TABLE") + (status, fvs) = neighTbl.get("Ethernet16:11.0.0.2") + assert status == True - ############################################################################# - # - # Testcase 1. Having routing-warm-reboot disabled, restart zebra and verify - # that the traditional/cold-boot logic is followed. - # - ############################################################################# + (status, fvs) = neighTbl.get("Ethernet20:11.0.0.10") + assert status == True - # Restart zebra - dvs.stop_zebra() - dvs.start_zebra() + restore_count = swss_get_RestoreCount(dvs, state_db) - time.sleep(5) + # restart portsyncd + dvs.runcmd(['sh', '-c', 'pkill -x portsyncd']) - # Verify FSM - swss_app_check_warmstart_state(state_db, "bgp", "") + pubsub = dvs.SubscribeAsicDbObject("SAI_OBJECT_TYPE") + dvs.runcmd(['sh', '-c', 'supervisorctl start portsyncd']) - # Verify that multiple changes are seen in swss and sairedis logs as there's - # no warm-reboot logic in place. - (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) - assert len(addobjs) != 0 + (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) + assert nadd == 0 + assert ndel == 0 - (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) - assert len(addobjs) != 0 + #new ip on server 5 + dvs.servers[5].runcmd("ifconfig eth0 11.0.0.11/29") + # Ping should work between servers via vs Ethernet interfaces + ping_stats = dvs.servers[4].runcmd("ping -c 1 11.0.0.11") - ############################################################################# - # - # Testcase 2. Restart zebra and make no control-plane changes. - # For this and all subsequent test-cases routing-warm-reboot - # feature will be kept enabled. - # - ############################################################################# + # new neighbor learn on VS + (status, fvs) = neighTbl.get("Ethernet20:11.0.0.11") + assert status == True + # Port state change reflected in appDB correctly + dvs.servers[6].runcmd("ip link set down dev eth0") == 0 + dvs.servers[6].runcmd("ip link set up dev eth0") == 0 + time.sleep(1) + + check_port_oper_status(appl_db, "Ethernet16", "up") + check_port_oper_status(appl_db, "Ethernet20", "up") + check_port_oper_status(appl_db, "Ethernet24", "up") + + + swss_app_check_RestoreCount_single(state_db, restore_count, "portsyncd") + + intf_tbl._del("Ethernet16|11.0.0.1/29") + intf_tbl._del("Ethernet20|11.0.0.9/29") + intf_tbl._del("Ethernet16") + intf_tbl._del("Ethernet20") + time.sleep(2) + + + def test_VlanMgrdWarmRestart(self, dvs, testlog): + + conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) + state_db = swsscommon.DBConnector(swsscommon.STATE_DB, dvs.redis_sock, 0) + + dvs.runcmd("ifconfig Ethernet16 0") + dvs.runcmd("ifconfig Ethernet20 0") + + dvs.runcmd("ifconfig Ethernet16 up") + dvs.runcmd("ifconfig Ethernet20 up") + + time.sleep(1) + + dvs.runcmd("config warm_restart enable swss") + + # create vlan + create_entry_tbl( + conf_db, + "VLAN", "Vlan16", + [ + ("vlanid", "16"), + ] + ) + # create vlan + create_entry_tbl( + conf_db, + "VLAN", "Vlan20", + [ + ("vlanid", "20"), + ] + ) + # create vlan member entry in config db. Don't use Ethernet0/4/8/12 as IP configured on them in previous testing. + create_entry_tbl( + conf_db, + "VLAN_MEMBER", "Vlan16|Ethernet16", + [ + ("tagging_mode", "untagged"), + ] + ) + + create_entry_tbl( + conf_db, + "VLAN_MEMBER", "Vlan20|Ethernet20", + [ + ("tagging_mode", "untagged"), + ] + ) + + time.sleep(1) + + intf_tbl = swsscommon.Table(conf_db, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) + intf_tbl.set("Vlan16|11.0.0.1/29", fvs) + intf_tbl.set("Vlan20|11.0.0.9/29", fvs) + intf_tbl.set("Vlan16", fvs) + intf_tbl.set("Vlan20", fvs) + dvs.runcmd("ifconfig Vlan16 up") + dvs.runcmd("ifconfig Vlan20 up") + + dvs.servers[4].runcmd("ifconfig eth0 11.0.0.2/29") + dvs.servers[4].runcmd("ip route add default via 11.0.0.1") + + dvs.servers[5].runcmd("ifconfig eth0 11.0.0.10/29") + dvs.servers[5].runcmd("ip route add default via 11.0.0.9") + + time.sleep(1) + + # Ping should work between servers via vs vlan interfaces + ping_stats = dvs.servers[4].runcmd("ping -c 1 11.0.0.10") + time.sleep(1) + + tbl = swsscommon.Table(appl_db, "NEIGH_TABLE") + (status, fvs) = tbl.get("Vlan16:11.0.0.2") + assert status == True - # Enabling bgp warmrestart and setting restart timer. - # The following two instructions will be substituted by the commented ones - # once the later ones are added to sonic-utilities repo. + (status, fvs) = tbl.get("Vlan20:11.0.0.10") + assert status == True - dvs.runcmd("config warm_restart enable bgp") - dvs.runcmd("config warm_restart bgp_timer {}".format(restart_timer)) + (exitcode, bv_before) = dvs.runcmd("bridge vlan") + print(bv_before) - time.sleep(1) + restore_count = swss_get_RestoreCount(dvs, state_db) - # Restart zebra - dvs.stop_zebra() - dvs.start_zebra() + dvs.runcmd(['sh', '-c', 'pkill -x vlanmgrd']) - # Verify FSM - swss_app_check_warmstart_state(state_db, "bgp", "restored") - time.sleep(restart_timer + 1) - swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + pubsub = dvs.SubscribeAsicDbObject("SAI_OBJECT_TYPE") - # Verify swss changes -- none are expected this time - (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) - assert len(addobjs) == 0 and len(delobjs) == 0 + dvs.runcmd(['sh', '-c', 'supervisorctl start vlanmgrd']) + time.sleep(2) - # Verify swss changes -- none are expected this time - (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) - assert len(addobjs) == 0 and len(delobjs) == 0 + (exitcode, bv_after) = dvs.runcmd("bridge vlan") + assert bv_after == bv_before + (nadd, ndel) = dvs.CountSubscribedObjects(pubsub, ignore=["SAI_OBJECT_TYPE_FDB_ENTRY"]) + assert nadd == 0 + assert ndel == 0 - ############################################################################# - # - # Testcase 3. Restart zebra and add one new non-ecmp IPv4 prefix - # - ############################################################################# + #new ip on server 5 + dvs.servers[5].runcmd("ifconfig eth0 11.0.0.11/29") - # Stop zebra - dvs.stop_zebra() + # Ping should work between servers via vs vlan interfaces + ping_stats = dvs.servers[4].runcmd("ping -c 1 11.0.0.11") - # Add new prefix - dvs.runcmd("ip route add 192.168.100.0/24 nexthop via 111.0.0.2") - time.sleep(1) + # new neighbor learn on VS + (status, fvs) = tbl.get("Vlan20:11.0.0.11") + assert status == True - # Start zebra - dvs.start_zebra() + swss_app_check_RestoreCount_single(state_db, restore_count, "vlanmgrd") - # Verify FSM - swss_app_check_warmstart_state(state_db, "bgp", "restored") - time.sleep(restart_timer + 1) - swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + intf_tbl._del("Vlan16|11.0.0.1/29") + intf_tbl._del("Vlan20|11.0.0.9/29") + intf_tbl._del("Vlan16") + intf_tbl._del("Vlan20") + time.sleep(2) - # Verify the changed prefix is seen in swss - (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) - assert len(addobjs) == 1 and len(delobjs) == 0 - rt_key = json.loads(addobjs[0]['key']) - rt_val = json.loads(addobjs[0]['vals']) - assert rt_key == "192.168.100.0/24" - assert rt_val == {"ifname": "Ethernet0", "nexthop": "111.0.0.2"} + def test_swss_neighbor_syncup(self, dvs, testlog): - # Verify the changed prefix is seen in sairedis - (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) - assert len(addobjs) == 1 and len(delobjs) == 0 - rt_key = json.loads(addobjs[0]['key']) - assert rt_key['dest'] == "192.168.100.0/24" + appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) + conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + state_db = swsscommon.DBConnector(swsscommon.STATE_DB, dvs.redis_sock, 0) + dvs.runcmd("config warm_restart enable swss") - ############################################################################# - # - # Testcase 4. Restart zebra and withdraw one non-ecmp IPv4 prefix - # - ############################################################################# + # + # Testcase1: + # Add neighbor entries in linux kernel, appDB should get all of them + # + # create neighbor entries (4 ipv4 and 4 ip6, two each on each interface) in linux kernel + intfs = ["Ethernet24", "Ethernet28"] - # Stop zebra - dvs.stop_zebra() + for intf in intfs: + # set timeout to be the same as real HW + dvs.runcmd("sysctl -w net.ipv4.neigh.{}.base_reachable_time_ms=1800000".format(intf)) + dvs.runcmd("sysctl -w net.ipv6.neigh.{}.base_reachable_time_ms=1800000".format(intf)) - # Delete prefix - dvs.runcmd("ip route del 192.168.100.0/24 nexthop via 111.0.0.2") - time.sleep(1) + #enable ipv6 on docker + dvs.runcmd("sysctl net.ipv6.conf.all.disable_ipv6=0") - # Start zebra - dvs.start_zebra() + config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + intf_tbl = swsscommon.Table(config_db, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) + intf_tbl.set("{}|24.0.0.1/24".format(intfs[0]), fvs) + intf_tbl.set("{}|28.0.0.9/24".format(intfs[1]), fvs) + intf_tbl.set("{}|2400::1/64".format(intfs[0]), fvs) + intf_tbl.set("{}|2800::1/64".format(intfs[1]), fvs) + intf_tbl.set("{}".format(intfs[0]), fvs) + intf_tbl.set("{}".format(intfs[1]), fvs) + intf_tbl.set("{}".format(intfs[0]), fvs) + intf_tbl.set("{}".format(intfs[1]), fvs) + dvs.runcmd("ifconfig {} up".format(intfs[0])) + dvs.runcmd("ifconfig {} up".format(intfs[1])) - # Verify FSM - swss_app_check_warmstart_state(state_db, "bgp", "restored") - time.sleep(restart_timer + 1) - swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + ips = ["24.0.0.2", "24.0.0.3", "28.0.0.2", "28.0.0.3"] + v6ips = ["2400::2", "2400::3", "2800::2", "2800::3"] - # Verify the changed prefix is seen in swss - (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) - assert len(addobjs) == 0 and len(delobjs) == 1 - rt_key = json.loads(delobjs[0]['key']) - assert rt_key == "192.168.100.0/24" + macs = ["00:00:00:00:24:02", "00:00:00:00:24:03", "00:00:00:00:28:02", "00:00:00:00:28:03"] - # Verify the changed prefix is seen in sairedis - (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) - assert len(addobjs) == 0 and len(delobjs) == 1 - rt_key = json.loads(delobjs[0]['key']) - assert rt_key['dest'] == "192.168.100.0/24" + for i in range(len(ips)): + dvs.runcmd("ip neigh add {} dev {} lladdr {} nud reachable".format(ips[i], intfs[i/2], macs[i])) + for i in range(len(v6ips)): + dvs.runcmd("ip -6 neigh add {} dev {} lladdr {} nud reachable".format(v6ips[i], intfs[i/2], macs[i])) - ############################################################################# - # - # Testcase 5. Restart zebra and add a new IPv4 ecmp-prefix - # - ############################################################################# + time.sleep(1) + # Check the neighbor entries are inserted correctly + db = swsscommon.DBConnector(0, dvs.redis_sock, 0) + tbl = swsscommon.Table(db, "NEIGH_TABLE") - # Stop zebra - dvs.stop_zebra() + for i in range(len(ips)): + (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) + assert status == True - # Add prefix - dvs.runcmd("ip route add 192.168.200.0/24 nexthop via 111.0.0.2 nexthop via 122.0.0.2 nexthop via 133.0.0.2") - time.sleep(1) + for v in fvs: + if v[0] == "neigh": + assert v[1] == macs[i] + if v[0] == "family": + assert v[1] == "IPv4" - # Start zebra - dvs.start_zebra() + for i in range(len(v6ips)): + (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) + assert status == True - # Verify FSM - swss_app_check_warmstart_state(state_db, "bgp", "restored") - time.sleep(restart_timer + 1) - swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + for v in fvs: + if v[0] == "neigh": + assert v[1] == macs[i] + if v[0] == "family": + assert v[1] == "IPv6" - # Verify the changed prefix is seen in swss - (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) - assert len(addobjs) == 1 and len(delobjs) == 0 - rt_key = json.loads(addobjs[0]['key']) - rt_val = json.loads(addobjs[0]['vals']) - assert rt_key == "192.168.200.0/24" - assert rt_val == {"ifname": "Ethernet0,Ethernet4,Ethernet8", "nexthop": "111.0.0.2,122.0.0.2,133.0.0.2"} + # + # Testcase 2: + # Restart neighsyncd without change neighbor entries, nothing should be sent to appDB or sairedis, + # appDB should be kept the same. + # + + # get restore_count + restore_count = swss_get_RestoreCount(dvs, state_db) + + # stop neighsyncd and sairedis.rec + stop_neighsyncd(dvs) + del_entry_tbl(state_db, "NEIGH_RESTORE_TABLE", "Flags") + marker = dvs.add_log_marker() + pubsub = dvs.SubscribeAsicDbObject("SAI_OBJECT_TYPE_NEIGHBOR_ENTRY") + start_neighsyncd(dvs) + start_restore_neighbors(dvs) + time.sleep(10) - # Verify the changed prefix is seen in sairedis - (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) - assert len(addobjs) == 1 and len(delobjs) == 0 - rt_key = json.loads(addobjs[0]['key']) - assert rt_key['dest'] == "192.168.200.0/24" + # Check the neighbor entries are still in appDB correctly + for i in range(len(ips)): + (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) + assert status == True + for v in fvs: + if v[0] == "neigh": + assert v[1] == macs[i] + if v[0] == "family": + assert v[1] == "IPv4" - ############################################################################# - # - # Testcase 6. Restart zebra and delete one existing IPv4 ecmp-prefix. - # - ############################################################################# + for i in range(len(v6ips)): + (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) + assert status == True + for v in fvs: + if v[0] == "neigh": + assert v[1] == macs[i] + if v[0] == "family": + assert v[1] == "IPv6" - # Stop zebra - dvs.stop_zebra() + # check syslog and sairedis.rec file for activities + check_syslog_for_neighbor_entry(dvs, marker, 0, 0, "ipv4") + check_syslog_for_neighbor_entry(dvs, marker, 0, 0, "ipv6") + (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) + assert nadd == 0 + assert ndel == 0 + + # check restore Count + swss_app_check_RestoreCount_single(state_db, restore_count, "neighsyncd") + + # + # Testcase 3: + # stop neighsyncd, delete even nummber ipv4/ipv6 neighbor entries from each interface, warm start neighsyncd. + # the neighsyncd is supposed to sync up the entries from kernel after warm restart + # note: there was an issue for neighbor delete, it will be marked as FAILED instead of deleted in kernel + # but it will send netlink message to be removed from appDB, so it works ok here, + # just that if we want to add the same neighbor again, use "change" instead of "add" + + # get restore_count + restore_count = swss_get_RestoreCount(dvs, state_db) + + # stop neighsyncd + stop_neighsyncd(dvs) + del_entry_tbl(state_db, "NEIGH_RESTORE_TABLE", "Flags") + marker = dvs.add_log_marker() + + # delete even nummber of ipv4/ipv6 neighbor entries from each interface + for i in range(0, len(ips), 2): + dvs.runcmd("ip neigh del {} dev {}".format(ips[i], intfs[i/2])) - # Delete prefix - dvs.runcmd("ip route del 192.168.200.0/24 nexthop via 111.0.0.2 nexthop via 122.0.0.2 nexthop via 133.0.0.2") - time.sleep(1) + for i in range(0, len(v6ips), 2): + dvs.runcmd("ip -6 neigh del {} dev {}".format(v6ips[i], intfs[i/2])) - # Start zebra - dvs.start_zebra() + # start neighsyncd again + start_neighsyncd(dvs) + start_restore_neighbors(dvs) + time.sleep(10) - # Verify FSM - swss_app_check_warmstart_state(state_db, "bgp", "restored") - time.sleep(restart_timer + 1) - swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + # check ipv4 and ipv6 neighbors + for i in range(len(ips)): + (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) + #should not see deleted neighbor entries + if i % 2 == 0: + assert status == False + continue + else: + assert status == True + + #undeleted entries should still be there. + for v in fvs: + if v[0] == "neigh": + assert v[1] == macs[i] + if v[0] == "family": + assert v[1] == "IPv4" - # Verify the changed prefix is seen in swss - (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) - assert len(addobjs) == 0 and len(delobjs) == 1 - rt_key = json.loads(delobjs[0]['key']) - assert rt_key == "192.168.200.0/24" + for i in range(len(v6ips)): + (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) + #should not see deleted neighbor entries + if i % 2 == 0: + assert status == False + continue + else: + assert status == True + + #undeleted entries should still be there. + for v in fvs: + if v[0] == "neigh": + assert v[1] == macs[i] + if v[0] == "family": + assert v[1] == "IPv6" - # Verify the changed prefix is seen in sairedis - (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) - assert len(addobjs) == 0 and len(delobjs) == 1 - rt_key = json.loads(delobjs[0]['key']) - assert rt_key['dest'] == "192.168.200.0/24" + # check syslog and sairedis.rec file for activities + # 2 deletes each for ipv4 and ipv6 + # 4 neighbor removal in asic db + check_syslog_for_neighbor_entry(dvs, marker, 0, 2, "ipv4") + check_syslog_for_neighbor_entry(dvs, marker, 0, 2, "ipv6") + (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) + assert nadd == 0 + assert ndel == 4 + + # check restore Count + swss_app_check_RestoreCount_single(state_db, restore_count, "neighsyncd") + + + # + # Testcase 4: + # Stop neighsyncd, add even nummber of ipv4/ipv6 neighbor entries to each interface again, + # Start neighsyncd + # The neighsyncd is supposed to sync up the entries from kernel after warm restart + # Check the timer is not retrieved from configDB since it is not configured + + # get restore_count + restore_count = swss_get_RestoreCount(dvs, state_db) + + # stop neighsyncd + stop_neighsyncd(dvs) + del_entry_tbl(state_db, "NEIGH_RESTORE_TABLE", "Flags") + marker = dvs.add_log_marker() + + # add even nummber of ipv4/ipv6 neighbor entries to each interface + # use "change" if neighbor is in FAILED state + for i in range(0, len(ips), 2): + (rc, output) = dvs.runcmd(['sh', '-c', "ip -4 neigh | grep {}".format(ips[i])]) + print output + if output: + dvs.runcmd("ip neigh change {} dev {} lladdr {} nud reachable".format(ips[i], intfs[i/2], macs[i])) + else: + dvs.runcmd("ip neigh add {} dev {} lladdr {} nud reachable".format(ips[i], intfs[i/2], macs[i])) + + for i in range(0, len(v6ips), 2): + (rc, output) = dvs.runcmd(['sh', '-c', "ip -6 neigh | grep {}".format(v6ips[i])]) + print output + if output: + dvs.runcmd("ip -6 neigh change {} dev {} lladdr {} nud reachable".format(v6ips[i], intfs[i/2], macs[i])) + else: + dvs.runcmd("ip -6 neigh add {} dev {} lladdr {} nud reachable".format(v6ips[i], intfs[i/2], macs[i])) + + # start neighsyncd again + start_neighsyncd(dvs) + start_restore_neighbors(dvs) + time.sleep(10) + # no neighsyncd timer configured + check_no_neighsyncd_timer(dvs) - ############################################################################# - # - # Testcase 7. Restart zebra and add one new path to an IPv4 ecmp-prefix - # - ############################################################################# + # check ipv4 and ipv6 neighbors, should see all neighbors + for i in range(len(ips)): + (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) + assert status == True + for v in fvs: + if v[0] == "neigh": + assert v[1] == macs[i] + if v[0] == "family": + assert v[1] == "IPv4" + for i in range(len(v6ips)): + (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) + assert status == True + for v in fvs: + if v[0] == "neigh": + assert v[1] == macs[i] + if v[0] == "family": + assert v[1] == "IPv6" - # Stop zebra - dvs.stop_zebra() + # check syslog and asic db for activities + # 2 news entries for ipv4 and ipv6 each + # 4 neighbor creation in asic db + check_syslog_for_neighbor_entry(dvs, marker, 2, 0, "ipv4") + check_syslog_for_neighbor_entry(dvs, marker, 2, 0, "ipv6") + (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) + assert nadd == 4 + assert ndel == 0 + + # check restore Count + swss_app_check_RestoreCount_single(state_db, restore_count, "neighsyncd") + + # + # Testcase 5: + # Even number of ip4/6 neigbors updated with new mac. + # Odd number of ipv4/6 neighbors removed + # neighbor syncd should sync it up after warm restart + # include the timer settings in this testcase + + # setup timer in configDB + timer_value = "15" + + dvs.runcmd("config warm_restart neighsyncd_timer {}".format(timer_value)) + + # get restore_count + restore_count = swss_get_RestoreCount(dvs, state_db) + + # stop neighsyncd + stop_neighsyncd(dvs) + del_entry_tbl(state_db, "NEIGH_RESTORE_TABLE", "Flags") + marker = dvs.add_log_marker() + + # Even number of ip4/6 neigbors updated with new mac. + # Odd number of ipv4/6 neighbors removed + newmacs = ["00:00:00:01:12:02", "00:00:00:01:12:03", "00:00:00:01:16:02", "00:00:00:01:16:03"] + + for i in range(len(ips)): + if i % 2 == 0: + dvs.runcmd("ip neigh change {} dev {} lladdr {} nud reachable".format(ips[i], intfs[i/2], newmacs[i])) + else: + dvs.runcmd("ip neigh del {} dev {}".format(ips[i], intfs[i/2])) + + for i in range(len(v6ips)): + if i % 2 == 0: + dvs.runcmd("ip -6 neigh change {} dev {} lladdr {} nud reachable".format(v6ips[i], intfs[i/2], newmacs[i])) + else: + dvs.runcmd("ip -6 neigh del {} dev {}".format(v6ips[i], intfs[i/2])) + + # start neighsyncd again + start_neighsyncd(dvs) + start_restore_neighbors(dvs) + time.sleep(10) - # Add new path - dvs.runcmd("ip route del 192.168.1.3/32 nexthop via 111.0.0.2 nexthop via 122.0.0.2") - dvs.runcmd("ip route add 192.168.1.3/32 nexthop via 111.0.0.2 nexthop via 122.0.0.2 nexthop via 133.0.0.2") - time.sleep(1) + # timer is not expired yet, state should be "restored" + swss_app_check_warmstart_state(state_db, "neighsyncd", "restored") + time.sleep(10) - # Start zebra - dvs.start_zebra() + # check neigh syncd timer is retrived from configDB + check_neighsyncd_timer(dvs, timer_value) + + # check ipv4 and ipv6 neighbors, should see all neighbors with updated info + for i in range(len(ips)): + if i % 2 == 0: + (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) + assert status == True + for v in fvs: + if v[0] == "neigh": + assert v[1] == newmacs[i] + if v[0] == "family": + assert v[1] == "IPv4" + else: + (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) + assert status == False + + for i in range(len(v6ips)): + if i % 2 == 0: + (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) + assert status == True + for v in fvs: + if v[0] == "neigh": + assert v[1] == newmacs[i] + if v[0] == "family": + assert v[1] == "IPv6" + else: + (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) + assert status == False + + time.sleep(2) + + # check syslog and asic db for activities + # 2 news, 2 deletes for ipv4 and ipv6 each + # 4 set, 4 removes for neighbor in asic db + check_syslog_for_neighbor_entry(dvs, marker, 2, 2, "ipv4") + check_syslog_for_neighbor_entry(dvs, marker, 2, 2, "ipv6") + (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) + assert nadd == 4 + assert ndel == 4 + + # check restore Count + swss_app_check_RestoreCount_single(state_db, restore_count, "neighsyncd") + + # post-cleanup + dvs.runcmd("ip -s neigh flush all") + dvs.runcmd("ip -6 -s neigh flush all") + + intf_tbl._del("{}|24.0.0.1/24".format(intfs[0])) + intf_tbl._del("{}|28.0.0.9/24".format(intfs[1])) + intf_tbl._del("{}|2400::1/64".format(intfs[0])) + intf_tbl._del("{}|2800::1/64".format(intfs[1])) + intf_tbl._del("{}".format(intfs[0])) + intf_tbl._del("{}".format(intfs[1])) + intf_tbl._del("{}".format(intfs[0])) + intf_tbl._del("{}".format(intfs[1])) + time.sleep(2) + + + # TODO: The condition of warm restart readiness check is still under discussion. + def test_OrchagentWarmRestartReadyCheck(self, dvs, testlog): + + time.sleep(1) + + dvs.runcmd("config warm_restart enable swss") + + config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + intf_tbl = swsscommon.Table(config_db, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) + intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) + intf_tbl.set("Ethernet4|10.0.0.2/31", fvs) + intf_tbl.set("Ethernet0", fvs) + intf_tbl.set("Ethernet4", fvs) + dvs.runcmd("ifconfig Ethernet0 up") + dvs.runcmd("ifconfig Ethernet4 up") + + dvs.servers[0].runcmd("ifconfig eth0 10.0.0.1/31") + dvs.servers[0].runcmd("ip route add default via 10.0.0.0") + + dvs.servers[1].runcmd("ifconfig eth0 10.0.0.3/31") + dvs.servers[1].runcmd("ip route add default via 10.0.0.2") + + + appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) + ps = swsscommon.ProducerStateTable(appl_db, swsscommon.APP_ROUTE_TABLE_NAME) + fvs = swsscommon.FieldValuePairs([("nexthop","10.0.0.1"), ("ifname", "Ethernet0")]) + + ps.set("2.2.2.0/24", fvs) + + time.sleep(1) + # Should fail, since neighbor for next 10.0.0.1 has not been not resolved yet + (exitcode, result) = dvs.runcmd("/usr/bin/orchagent_restart_check") + assert result == "RESTARTCHECK failed\n" + + # Should succeed, the option for skipPendingTaskCheck -s and noFreeze -n have been provided. + # Wait up to 500 milliseconds for response from orchagent. Default wait time is 1000 milliseconds. + (exitcode, result) = dvs.runcmd("/usr/bin/orchagent_restart_check -n -s -w 500") + assert result == "RESTARTCHECK succeeded\n" + + # get neighbor and arp entry + dvs.servers[1].runcmd("ping -c 1 10.0.0.1") + + time.sleep(1) + (exitcode, result) = dvs.runcmd("/usr/bin/orchagent_restart_check") + assert result == "RESTARTCHECK succeeded\n" + + # Should fail since orchagent has been frozen at last step. + (exitcode, result) = dvs.runcmd("/usr/bin/orchagent_restart_check -n -s -w 500") + assert result == "RESTARTCHECK failed\n" + + # Cleaning previously pushed route-entry to ease life of subsequent testcases. + ps._del("2.2.2.0/24") + time.sleep(1) + + intf_tbl._del("Ethernet0|10.0.0.0/31") + intf_tbl._del("Ethernet4|10.0.0.2/31") + intf_tbl._del("Ethernet0") + intf_tbl._del("Ethernet4") + time.sleep(2) + + # recover for test cases after this one. + dvs.stop_swss() + dvs.start_swss() + time.sleep(5) + + def test_swss_port_state_syncup(self, dvs, testlog): - # Verify FSM - swss_app_check_warmstart_state(state_db, "bgp", "restored") - time.sleep(restart_timer + 1) - swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) + conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + state_db = swsscommon.DBConnector(swsscommon.STATE_DB, dvs.redis_sock, 0) - # Verify the changed prefix is seen in swss - (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) - assert len(addobjs) == 1 and len(delobjs) == 0 - rt_key = json.loads(addobjs[0]['key']) - rt_val = json.loads(addobjs[0]['vals']) - assert rt_key == "192.168.1.3" - assert rt_val == {"ifname": "Ethernet0,Ethernet4,Ethernet8", "nexthop": "111.0.0.2,122.0.0.2,133.0.0.2"} + dvs.runcmd("config warm_restart enable swss") + + tbl = swsscommon.Table(appl_db, swsscommon.APP_PORT_TABLE_NAME) - # Verify the changed prefix is seen in sairedis - (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) - assert len(addobjs) == 1 and len(delobjs) == 0 - rt_key = json.loads(addobjs[0]['key']) - assert rt_key['dest'] == "192.168.1.3/32" + restore_count = swss_get_RestoreCount(dvs, state_db) + # update port admin state + intf_tbl = swsscommon.Table(conf_db, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) + intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) + intf_tbl.set("Ethernet4|10.0.0.2/31", fvs) + intf_tbl.set("Ethernet8|10.0.0.4/31", fvs) + intf_tbl.set("Ethernet0", fvs) + intf_tbl.set("Ethernet4", fvs) + intf_tbl.set("Ethernet8", fvs) + dvs.runcmd("ifconfig Ethernet0 up") + dvs.runcmd("ifconfig Ethernet4 up") + dvs.runcmd("ifconfig Ethernet8 up") - ############################################################################# - # - # Testcase 8. Restart zebra and delete one ecmp-path from an IPv4 ecmp-prefix. - # - ############################################################################# + dvs.runcmd("arp -s 10.0.0.1 00:00:00:00:00:01") + dvs.runcmd("arp -s 10.0.0.3 00:00:00:00:00:02") + dvs.runcmd("arp -s 10.0.0.5 00:00:00:00:00:03") + dvs.servers[0].runcmd("ip link set down dev eth0") == 0 + dvs.servers[1].runcmd("ip link set down dev eth0") == 0 + dvs.servers[2].runcmd("ip link set down dev eth0") == 0 - # Stop zebra - dvs.stop_zebra() + dvs.servers[2].runcmd("ip link set up dev eth0") == 0 - # Delete ecmp-path - dvs.runcmd("ip route del 192.168.1.3/32 nexthop via 111.0.0.2 nexthop via 122.0.0.2 nexthop via 133.0.0.2") - dvs.runcmd("ip route add 192.168.1.3/32 nexthop via 111.0.0.2 nexthop via 122.0.0.2") - time.sleep(1) + time.sleep(3) - # Start zebra - dvs.start_zebra() + for i in [0, 1, 2]: + (status, fvs) = tbl.get("Ethernet%d" % (i * 4)) + assert status == True + oper_status = "unknown" + for v in fvs: + if v[0] == "oper_status": + oper_status = v[1] + break + if i == 2: + assert oper_status == "up" + else: + assert oper_status == "down" + + intf_tbl._del("Ethernet0|10.0.0.0/31") + intf_tbl._del("Ethernet4|10.0.0.2/31") + intf_tbl._del("Ethernet8|10.0.0.4/31") + intf_tbl._del("Ethernet0") + intf_tbl._del("Ethernet4") + intf_tbl._del("Ethernet8") + time.sleep(2) + + dvs.stop_swss() + time.sleep(3) + + # flap the port oper status for Ethernet0, Ethernet4 and Ethernet8 + dvs.servers[0].runcmd("ip link set down dev eth0") == 0 + dvs.servers[1].runcmd("ip link set down dev eth0") == 0 + dvs.servers[2].runcmd("ip link set down dev eth0") == 0 + + dvs.servers[0].runcmd("ip link set up dev eth0") == 0 + dvs.servers[1].runcmd("ip link set up dev eth0") == 0 + + time.sleep(5) + dbobjs =[(swsscommon.APPL_DB, swsscommon.APP_PORT_TABLE_NAME + ":*"), \ + (swsscommon.STATE_DB, swsscommon.STATE_WARM_RESTART_TABLE_NAME + "|orchagent")] + pubsubDbs = dvs.SubscribeDbObjects(dbobjs) + dvs.start_swss() + start_restore_neighbors(dvs) + time.sleep(10) - # Verify FSM - swss_app_check_warmstart_state(state_db, "bgp", "restored") - time.sleep(restart_timer + 1) - swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + swss_check_RestoreCount(dvs, state_db, restore_count) - # Verify the changed prefix is seen in swss - (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) - assert len(addobjs) == 1 and len(delobjs) == 0 - rt_key = json.loads(addobjs[0]['key']) - rt_val = json.loads(addobjs[0]['vals']) - assert rt_key == "192.168.1.3" - assert rt_val == {"ifname": "Ethernet0,Ethernet4", "nexthop": "111.0.0.2,122.0.0.2"} + intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) + intf_tbl.set("Ethernet4|10.0.0.2/31", fvs) + intf_tbl.set("Ethernet8|10.0.0.4/31", fvs) + intf_tbl.set("Ethernet0", fvs) + intf_tbl.set("Ethernet4", fvs) + intf_tbl.set("Ethernet8", fvs) + time.sleep(3) - # Verify the changed prefix is seen in sairedis - (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) - assert len(addobjs) == 1 and len(delobjs) == 0 - rt_key = json.loads(addobjs[0]['key']) - assert rt_key['dest'] == "192.168.1.3/32" + for i in [0, 1, 2]: + (status, fvs) = tbl.get("Ethernet%d" % (i * 4)) + assert status == True + oper_status = "unknown" + for v in fvs: + if v[0] == "oper_status": + oper_status = v[1] + break + if i == 2: + assert oper_status == "down" + else: + assert oper_status == "up" + + # check the pubsub messages. + # No appDB port table operation should exist before orchagent state restored flag got set. + # appDB port table status sync up happens before WARM_RESTART_TABLE reconciled flag is set + # pubsubMessages is an ordered list of pubsub messages. + pubsubMessages = dvs.GetSubscribedMessages(pubsubDbs) + + portOperStatusChanged = False + # number of times that WARM_RESTART_TABLE|orchagent key was set after the first + # appDB port table operation + orchStateCount = 0 + for message in pubsubMessages: + print message + key = message['channel'].split(':', 1)[1] + print key + if message['data'] != 'hset' and message['data'] != 'del': + continue + if key.find(swsscommon.APP_PORT_TABLE_NAME)==0: + portOperStatusChanged = True + else: + # found one orchagent WARM_RESTART_TABLE operation after appDB port table change + if portOperStatusChanged == True: + orchStateCount += 1; + + # Only WARM_RESTART_TABLE|orchagent state=reconciled operation may exist after port oper status change. + assert orchStateCount == 1 + + #clean up arp + dvs.runcmd("arp -d 10.0.0.1") + dvs.runcmd("arp -d 10.0.0.3") + dvs.runcmd("arp -d 10.0.0.5") + + intf_tbl._del("Ethernet0|10.0.0.0/31") + intf_tbl._del("Ethernet4|10.0.0.2/31") + intf_tbl._del("Ethernet8|10.0.0.4/31") + intf_tbl._del("Ethernet0") + intf_tbl._del("Ethernet4") + intf_tbl._del("Ethernet8") + time.sleep(2) ############################################################################# - # - # Testcase 9. Restart zebra and add one new non-ecmp IPv6 prefix - # + # # + # Routing Warm-Restart Testing # + # # ############################################################################# - # Stop zebra - dvs.stop_zebra() + ################################################################################ + # + # Routing warm-restart testcases + # + ################################################################################ + + + def test_routing_WarmRestart(self, dvs, testlog): + + appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) + conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + state_db = swsscommon.DBConnector(swsscommon.STATE_DB, dvs.redis_sock, 0) + + # Restart-timer to utilize during the following testcases + restart_timer = 15 + + + ############################################################################# + # + # Baseline configuration + # + ############################################################################# + + + # Defining create neighbor entries (4 ipv4 and 4 ip6, two each on each interface) in linux kernel + intfs = ["Ethernet0", "Ethernet4", "Ethernet8"] + + # Enable ipv6 on docker + dvs.runcmd("sysctl net.ipv6.conf.all.disable_ipv6=0") - # Add prefix - dvs.runcmd("ip -6 route add fc00:4:4::1/128 nexthop via 1110::2") - time.sleep(1) + # Defining create neighbor entries (4 ipv4 and 4 ip6, two each on each interface) in linux kernel + intf_tbl = swsscommon.Table(conf_db, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) + intf_tbl.set("{}|111.0.0.1/24".format(intfs[0]), fvs) + intf_tbl.set("{}|1110::1/64".format(intfs[0]), fvs) + intf_tbl.set("{}|122.0.0.1/24".format(intfs[1]), fvs) + intf_tbl.set("{}|1220::1/64".format(intfs[1]), fvs) + intf_tbl.set("{}|133.0.0.1/24".format(intfs[2]), fvs) + intf_tbl.set("{}|1330::1/64".format(intfs[2]), fvs) + intf_tbl.set("{}".format(intfs[0]), fvs) + intf_tbl.set("{}".format(intfs[0]), fvs) + intf_tbl.set("{}".format(intfs[1]), fvs) + intf_tbl.set("{}".format(intfs[1]), fvs) + intf_tbl.set("{}".format(intfs[2]), fvs) + intf_tbl.set("{}".format(intfs[2]), fvs) + dvs.runcmd("ip link set {} up".format(intfs[0])) + dvs.runcmd("ip link set {} up".format(intfs[1])) + dvs.runcmd("ip link set {} up".format(intfs[2])) - # Start zebra - dvs.start_zebra() + time.sleep(1) - # Verify FSM - swss_app_check_warmstart_state(state_db, "bgp", "restored") - time.sleep(restart_timer + 1) - swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + # + # Setting peer's ip-addresses and associated neighbor-entries + # + ips = ["111.0.0.2", "122.0.0.2", "133.0.0.2"] + v6ips = ["1110::2", "1220::2", "1330::2"] + macs = ["00:00:00:00:11:02", "00:00:00:00:12:02", "00:00:00:00:13:02"] - # Verify the changed prefix is seen in swss - (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) - assert len(addobjs) == 1 and len(delobjs) == 0 - rt_key = json.loads(addobjs[0]['key']) - rt_val = json.loads(addobjs[0]['vals']) - assert rt_key == "fc00:4:4::1" - assert rt_val == {"ifname": "Ethernet0", "nexthop": "1110::2"} + for i in range(len(ips)): + dvs.runcmd("ip neigh add {} dev {} lladdr {}".format(ips[i], intfs[i%2], macs[i])) - # Verify the changed prefix is seen in sairedis - (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) - assert len(addobjs) == 1 and len(delobjs) == 0 - rt_key = json.loads(addobjs[0]['key']) - assert rt_key['dest'] == "fc00:4:4::1/128" + for i in range(len(v6ips)): + dvs.runcmd("ip -6 neigh add {} dev {} lladdr {}".format(v6ips[i], intfs[i%2], macs[i])) + time.sleep(1) - ############################################################################# - # - # Testcase 10. Restart zebra and withdraw one non-ecmp IPv6 prefix - # - ############################################################################# + # + # Defining baseline IPv4 non-ecmp route-entries + # + dvs.runcmd("ip route add 192.168.1.100/32 nexthop via 111.0.0.2") + dvs.runcmd("ip route add 192.168.1.200/32 nexthop via 122.0.0.2") + dvs.runcmd("ip route add 192.168.1.230/32 nexthop via 133.0.0.2") - # Stop zebra - dvs.stop_zebra() + # + # Defining baseline IPv4 ecmp route-entries + # + dvs.runcmd("ip route add 192.168.1.1/32 nexthop via 111.0.0.2 nexthop via 122.0.0.2 nexthop via 133.0.0.2") + dvs.runcmd("ip route add 192.168.1.2/32 nexthop via 111.0.0.2 nexthop via 122.0.0.2 nexthop via 133.0.0.2") + dvs.runcmd("ip route add 192.168.1.3/32 nexthop via 111.0.0.2 nexthop via 122.0.0.2") - # Delete prefix - dvs.runcmd("ip -6 route del fc00:4:4::1/128 nexthop via 1110::2") - time.sleep(1) + # + # Defining baseline IPv6 non-ecmp route-entries + # + dvs.runcmd("ip -6 route add fc00:11:11::1/128 nexthop via 1110::2") + dvs.runcmd("ip -6 route add fc00:12:12::1/128 nexthop via 1220::2") + dvs.runcmd("ip -6 route add fc00:13:13::1/128 nexthop via 1330::2") - # Start zebra - dvs.start_zebra() + # + # Defining baseline IPv6 ecmp route-entries + # + dvs.runcmd("ip -6 route add fc00:1:1::1/128 nexthop via 1110::2 nexthop via 1220::2 nexthop via 1330::2") + dvs.runcmd("ip -6 route add fc00:2:2::1/128 nexthop via 1110::2 nexthop via 1220::2 nexthop via 1330::2") + dvs.runcmd("ip -6 route add fc00:3:3::1/128 nexthop via 1110::2 nexthop via 1220::2") - # Verify FSM - swss_app_check_warmstart_state(state_db, "bgp", "restored") - time.sleep(restart_timer + 1) - swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + time.sleep(5) + + # Enabling some extra logging for troubleshooting purposes + dvs.runcmd("swssloglevel -l INFO -c fpmsyncd") + + # Subscribe to pubsub channels for routing-state associated to swss and sairedis dbs + pubsubAppDB = dvs.SubscribeAppDbObject("ROUTE_TABLE") + pubsubAsicDB = dvs.SubscribeAsicDbObject("SAI_OBJECT_TYPE_ROUTE_ENTRY") - # Verify the changed prefix is seen in swss - (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) - assert len(addobjs) == 0 and len(delobjs) == 1 - rt_key = json.loads(delobjs[0]['key']) - assert rt_key == "fc00:4:4::1" - # Verify the changed prefix is seen in sairedis - (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) - assert len(addobjs) == 0 and len(delobjs) == 1 - rt_key = json.loads(delobjs[0]['key']) - assert rt_key['dest'] == "fc00:4:4::1/128" + ############################################################################# + # + # Testcase 1. Having routing-warm-reboot disabled, restart zebra and verify + # that the traditional/cold-boot logic is followed. + # + ############################################################################# + + # Restart zebra + dvs.stop_zebra() + dvs.start_zebra() + + time.sleep(5) + + # Verify FSM + swss_app_check_warmstart_state(state_db, "bgp", "") + + # Verify that multiple changes are seen in swss and sairedis logs as there's + # no warm-reboot logic in place. + (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) + assert len(addobjs) != 0 + + (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) + assert len(addobjs) != 0 + + + ############################################################################# + # + # Testcase 2. Restart zebra and make no control-plane changes. + # For this and all subsequent test-cases routing-warm-reboot + # feature will be kept enabled. + # + ############################################################################# + + + # Enabling bgp warmrestart and setting restart timer. + # The following two instructions will be substituted by the commented ones + # once the later ones are added to sonic-utilities repo. + + dvs.runcmd("config warm_restart enable bgp") + dvs.runcmd("config warm_restart bgp_timer {}".format(restart_timer)) + + time.sleep(1) + # Restart zebra + dvs.stop_zebra() + dvs.start_zebra() - ############################################################################# - # - # Testcase 11. Restart fpmsyncd and make no control-plane changes. - # - ############################################################################# + # Verify FSM + swss_app_check_warmstart_state(state_db, "bgp", "restored") + time.sleep(restart_timer + 1) + swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + # Verify swss changes -- none are expected this time + (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) + assert len(addobjs) == 0 and len(delobjs) == 0 - # Stop fpmsyncd - dvs.stop_fpmsyncd() + # Verify swss changes -- none are expected this time + (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) + assert len(addobjs) == 0 and len(delobjs) == 0 - # Start fpmsyncd - dvs.start_fpmsyncd() - # Verify FSM - swss_app_check_warmstart_state(state_db, "bgp", "restored") - time.sleep(restart_timer + 1) - swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + ############################################################################# + # + # Testcase 3. Restart zebra and add one new non-ecmp IPv4 prefix + # + ############################################################################# + + # Stop zebra + dvs.stop_zebra() + + # Add new prefix + dvs.runcmd("ip route add 192.168.100.0/24 nexthop via 111.0.0.2") + time.sleep(1) - # Verify swss changes -- none are expected this time - (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) - assert len(addobjs) == 0 and len(delobjs) == 0 + # Start zebra + dvs.start_zebra() - # Verify sairedis changes -- none are expected this time - (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) - assert len(addobjs) == 0 and len(delobjs) == 0 + # Verify FSM + swss_app_check_warmstart_state(state_db, "bgp", "restored") + time.sleep(restart_timer + 1) + swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + # Verify the changed prefix is seen in swss + (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) + assert len(addobjs) == 1 and len(delobjs) == 0 + rt_key = json.loads(addobjs[0]['key']) + rt_val = json.loads(addobjs[0]['vals']) + assert rt_key == "192.168.100.0/24" + assert rt_val == {"ifname": "Ethernet0", "nexthop": "111.0.0.2"} - ############################################################################# - # - # Testcase 12. Restart fpmsyncd and add one new non-ecmp IPv4 prefix - # - ############################################################################# + # Verify the changed prefix is seen in sairedis + (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) + assert len(addobjs) == 1 and len(delobjs) == 0 + rt_key = json.loads(addobjs[0]['key']) + assert rt_key['dest'] == "192.168.100.0/24" - # Stop fpmsyncd - dvs.stop_fpmsyncd() + ############################################################################# + # + # Testcase 4. Restart zebra and withdraw one non-ecmp IPv4 prefix + # + ############################################################################# - # Add new prefix - dvs.runcmd("ip route add 192.168.100.0/24 nexthop via 111.0.0.2") - time.sleep(1) - # Start fpmsyncd - dvs.start_fpmsyncd() + # Stop zebra + dvs.stop_zebra() - # Verify FSM - swss_app_check_warmstart_state(state_db, "bgp", "restored") - time.sleep(restart_timer + 1) - swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + # Delete prefix + dvs.runcmd("ip route del 192.168.100.0/24 nexthop via 111.0.0.2") + time.sleep(1) - # Verify the changed prefix is seen in swss - (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) - assert len(addobjs) == 1 and len(delobjs) == 0 - rt_key = json.loads(addobjs[0]['key']) - rt_val = json.loads(addobjs[0]['vals']) - assert rt_key == "192.168.100.0/24" - assert rt_val == {"ifname": "Ethernet0", "nexthop": "111.0.0.2"} + # Start zebra + dvs.start_zebra() - # Verify the changed prefix is seen in sairedis - (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) - assert len(addobjs) == 1 and len(delobjs) == 0 - rt_key = json.loads(addobjs[0]['key']) - assert rt_key['dest'] == "192.168.100.0/24" + # Verify FSM + swss_app_check_warmstart_state(state_db, "bgp", "restored") + time.sleep(restart_timer + 1) + swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + # Verify the changed prefix is seen in swss + (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) + assert len(addobjs) == 0 and len(delobjs) == 1 + rt_key = json.loads(delobjs[0]['key']) + assert rt_key == "192.168.100.0/24" - ############################################################################# - # - # Testcase 13. Restart fpmsyncd and withdraw one non-ecmp IPv4 prefix - # - ############################################################################# + # Verify the changed prefix is seen in sairedis + (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) + assert len(addobjs) == 0 and len(delobjs) == 1 + rt_key = json.loads(delobjs[0]['key']) + assert rt_key['dest'] == "192.168.100.0/24" - # Stop fpmsyncd - dvs.stop_fpmsyncd() + ############################################################################# + # + # Testcase 5. Restart zebra and add a new IPv4 ecmp-prefix + # + ############################################################################# - # Delete prefix - dvs.runcmd("ip route del 192.168.100.0/24 nexthop via 111.0.0.2") - time.sleep(1) - # Start fpmsyncd - dvs.start_fpmsyncd() + # Stop zebra + dvs.stop_zebra() + + # Add prefix + dvs.runcmd("ip route add 192.168.200.0/24 nexthop via 111.0.0.2 nexthop via 122.0.0.2 nexthop via 133.0.0.2") + time.sleep(1) + + # Start zebra + dvs.start_zebra() - # Verify FSM - swss_app_check_warmstart_state(state_db, "bgp", "restored") - time.sleep(restart_timer + 1) - swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + # Verify FSM + swss_app_check_warmstart_state(state_db, "bgp", "restored") + time.sleep(restart_timer + 1) + swss_app_check_warmstart_state(state_db, "bgp", "reconciled") - # Verify the changed prefix is seen in swss - (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) - assert len(addobjs) == 0 and len(delobjs) == 1 - rt_key = json.loads(delobjs[0]['key']) - assert rt_key == "192.168.100.0/24" + # Verify the changed prefix is seen in swss + (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) + assert len(addobjs) == 1 and len(delobjs) == 0 + rt_key = json.loads(addobjs[0]['key']) + rt_val = json.loads(addobjs[0]['vals']) + assert rt_key == "192.168.200.0/24" + assert rt_val == {"ifname": "Ethernet0,Ethernet4,Ethernet8", "nexthop": "111.0.0.2,122.0.0.2,133.0.0.2"} + + # Verify the changed prefix is seen in sairedis + (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) + assert len(addobjs) == 1 and len(delobjs) == 0 + rt_key = json.loads(addobjs[0]['key']) + assert rt_key['dest'] == "192.168.200.0/24" + + + ############################################################################# + # + # Testcase 6. Restart zebra and delete one existing IPv4 ecmp-prefix. + # + ############################################################################# + + + # Stop zebra + dvs.stop_zebra() + + # Delete prefix + dvs.runcmd("ip route del 192.168.200.0/24 nexthop via 111.0.0.2 nexthop via 122.0.0.2 nexthop via 133.0.0.2") + time.sleep(1) + + # Start zebra + dvs.start_zebra() + + # Verify FSM + swss_app_check_warmstart_state(state_db, "bgp", "restored") + time.sleep(restart_timer + 1) + swss_app_check_warmstart_state(state_db, "bgp", "reconciled") - # Verify the changed prefix is seen in sairedis - (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) - assert len(addobjs) == 0 and len(delobjs) == 1 - rt_key = json.loads(delobjs[0]['key']) - assert rt_key['dest'] == "192.168.100.0/24" + # Verify the changed prefix is seen in swss + (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) + assert len(addobjs) == 0 and len(delobjs) == 1 + rt_key = json.loads(delobjs[0]['key']) + assert rt_key == "192.168.200.0/24" + # Verify the changed prefix is seen in sairedis + (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) + assert len(addobjs) == 0 and len(delobjs) == 1 + rt_key = json.loads(delobjs[0]['key']) + assert rt_key['dest'] == "192.168.200.0/24" - ############################################################################# - # - # Testcase 14. Restart zebra and add/remove a new non-ecmp IPv4 prefix. As - # the 'delete' instruction would arrive after the 'add' one, no - # changes should be pushed down to SwSS. - # - ############################################################################# + ############################################################################# + # + # Testcase 7. Restart zebra and add one new path to an IPv4 ecmp-prefix + # + ############################################################################# + + + # Stop zebra + dvs.stop_zebra() + + # Add new path + dvs.runcmd("ip route del 192.168.1.3/32 nexthop via 111.0.0.2 nexthop via 122.0.0.2") + dvs.runcmd("ip route add 192.168.1.3/32 nexthop via 111.0.0.2 nexthop via 122.0.0.2 nexthop via 133.0.0.2") + time.sleep(1) + + # Start zebra + dvs.start_zebra() + + # Verify FSM + swss_app_check_warmstart_state(state_db, "bgp", "restored") + time.sleep(restart_timer + 1) + swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + + # Verify the changed prefix is seen in swss + (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) + assert len(addobjs) == 1 and len(delobjs) == 0 + rt_key = json.loads(addobjs[0]['key']) + rt_val = json.loads(addobjs[0]['vals']) + assert rt_key == "192.168.1.3" + assert rt_val == {"ifname": "Ethernet0,Ethernet4,Ethernet8", "nexthop": "111.0.0.2,122.0.0.2,133.0.0.2"} + + # Verify the changed prefix is seen in sairedis + (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) + assert len(addobjs) == 1 and len(delobjs) == 0 + rt_key = json.loads(addobjs[0]['key']) + assert rt_key['dest'] == "192.168.1.3/32" + + + ############################################################################# + # + # Testcase 8. Restart zebra and delete one ecmp-path from an IPv4 ecmp-prefix. + # + ############################################################################# + + + # Stop zebra + dvs.stop_zebra() + + # Delete ecmp-path + dvs.runcmd("ip route del 192.168.1.3/32 nexthop via 111.0.0.2 nexthop via 122.0.0.2 nexthop via 133.0.0.2") + dvs.runcmd("ip route add 192.168.1.3/32 nexthop via 111.0.0.2 nexthop via 122.0.0.2") + time.sleep(1) + + # Start zebra + dvs.start_zebra() + + # Verify FSM + swss_app_check_warmstart_state(state_db, "bgp", "restored") + time.sleep(restart_timer + 1) + swss_app_check_warmstart_state(state_db, "bgp", "reconciled") - # Restart zebra - dvs.stop_zebra() - dvs.start_zebra() + # Verify the changed prefix is seen in swss + (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) + assert len(addobjs) == 1 and len(delobjs) == 0 + rt_key = json.loads(addobjs[0]['key']) + rt_val = json.loads(addobjs[0]['vals']) + assert rt_key == "192.168.1.3" + assert rt_val == {"ifname": "Ethernet0,Ethernet4", "nexthop": "111.0.0.2,122.0.0.2"} - # Add/delete new prefix - dvs.runcmd("ip route add 192.168.100.0/24 nexthop via 111.0.0.2") - time.sleep(1) - dvs.runcmd("ip route del 192.168.100.0/24 nexthop via 111.0.0.2") - time.sleep(1) + # Verify the changed prefix is seen in sairedis + (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) + assert len(addobjs) == 1 and len(delobjs) == 0 + rt_key = json.loads(addobjs[0]['key']) + assert rt_key['dest'] == "192.168.1.3/32" - # Verify FSM - swss_app_check_warmstart_state(state_db, "bgp", "restored") - time.sleep(restart_timer + 1) - swss_app_check_warmstart_state(state_db, "bgp", "reconciled") - # Verify swss changes -- none are expected this time - (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) - assert len(addobjs) == 0 and len(delobjs) == 0 + ############################################################################# + # + # Testcase 9. Restart zebra and add one new non-ecmp IPv6 prefix + # + ############################################################################# + + + # Stop zebra + dvs.stop_zebra() - # Verify swss changes -- none are expected this time - (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) - assert len(addobjs) == 0 and len(delobjs) == 0 + # Add prefix + dvs.runcmd("ip -6 route add fc00:4:4::1/128 nexthop via 1110::2") + time.sleep(1) + # Start zebra + dvs.start_zebra() - ############################################################################# - # - # Testcase 15. Restart zebra and generate an add/remove/add for new non-ecmp - # IPv4 prefix. Verify that only the second 'add' instruction is - # honored and the corresponding update passed down to SwSS. - # - ############################################################################# + # Verify FSM + swss_app_check_warmstart_state(state_db, "bgp", "restored") + time.sleep(restart_timer + 1) + swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + # Verify the changed prefix is seen in swss + (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) + assert len(addobjs) == 1 and len(delobjs) == 0 + rt_key = json.loads(addobjs[0]['key']) + rt_val = json.loads(addobjs[0]['vals']) + assert rt_key == "fc00:4:4::1" + assert rt_val == {"ifname": "Ethernet0", "nexthop": "1110::2"} - # Restart zebra - dvs.stop_zebra() - dvs.start_zebra() + # Verify the changed prefix is seen in sairedis + (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) + assert len(addobjs) == 1 and len(delobjs) == 0 + rt_key = json.loads(addobjs[0]['key']) + assert rt_key['dest'] == "fc00:4:4::1/128" + + + ############################################################################# + # + # Testcase 10. Restart zebra and withdraw one non-ecmp IPv6 prefix + # + ############################################################################# + + # Stop zebra + dvs.stop_zebra() - marker1 = dvs.add_log_marker("/var/log/swss/swss.rec") - marker2 = dvs.add_log_marker("/var/log/swss/sairedis.rec") + # Delete prefix + dvs.runcmd("ip -6 route del fc00:4:4::1/128 nexthop via 1110::2") + time.sleep(1) - # Add/delete new prefix - dvs.runcmd("ip route add 192.168.100.0/24 nexthop via 111.0.0.2") - time.sleep(1) - dvs.runcmd("ip route del 192.168.100.0/24 nexthop via 111.0.0.2") - time.sleep(1) - dvs.runcmd("ip route add 192.168.100.0/24 nexthop via 122.0.0.2") - time.sleep(1) + # Start zebra + dvs.start_zebra() - # Verify FSM - swss_app_check_warmstart_state(state_db, "bgp", "restored") - time.sleep(restart_timer + 1) - swss_app_check_warmstart_state(state_db, "bgp", "reconciled") - - # Verify the changed prefix is seen in swss - (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) - assert len(addobjs) == 1 and len(delobjs) == 0 - rt_key = json.loads(addobjs[0]['key']) - rt_val = json.loads(addobjs[0]['vals']) - assert rt_key == "192.168.100.0/24" - assert rt_val == {"ifname": "Ethernet4", "nexthop": "122.0.0.2"} - - # Verify the changed prefix is seen in sairedis - (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) - assert len(addobjs) == 1 and len(delobjs) == 0 - rt_key = json.loads(addobjs[0]['key']) - assert rt_key['dest'] == "192.168.100.0/24" - - intf_tbl._del("{}|111.0.0.1/24".format(intfs[0])) - intf_tbl._del("{}|1110::1/64".format(intfs[0])) - intf_tbl._del("{}|122.0.0.1/24".format(intfs[1])) - intf_tbl._del("{}|1220::1/64".format(intfs[1])) - intf_tbl._del("{}|133.0.0.1/24".format(intfs[2])) - intf_tbl._del("{}|1330::1/64".format(intfs[2])) - intf_tbl._del("{}".format(intfs[0])) - intf_tbl._del("{}".format(intfs[0])) - intf_tbl._del("{}".format(intfs[1])) - intf_tbl._del("{}".format(intfs[1])) - intf_tbl._del("{}".format(intfs[2])) - intf_tbl._del("{}".format(intfs[2])) - time.sleep(2) + # Verify FSM + swss_app_check_warmstart_state(state_db, "bgp", "restored") + time.sleep(restart_timer + 1) + swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + # Verify the changed prefix is seen in swss + (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) + assert len(addobjs) == 0 and len(delobjs) == 1 + rt_key = json.loads(delobjs[0]['key']) + assert rt_key == "fc00:4:4::1" -# macros for number of interfaces and number of neighbors -# TBD: NUM_NEIGH_PER_INTF >= 128 ips will cause test framework to hang by default kernel settings -# TBD: Need tune gc_thresh1/2/3 at host side of vs docker to support this. -NUM_INTF = 8 -NUM_NEIGH_PER_INTF = 16 #128 -NUM_OF_NEIGHS = (NUM_INTF*NUM_NEIGH_PER_INTF) + # Verify the changed prefix is seen in sairedis + (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) + assert len(addobjs) == 0 and len(delobjs) == 1 + rt_key = json.loads(delobjs[0]['key']) + assert rt_key['dest'] == "fc00:4:4::1/128" -# 'ip neigh flush all' won't remove failed entries if number of neighs less than gc_threshold1 -# Also it takes time to remove them completly. -# We use arp off/on to do it -def flush_neigh_entries(dvs): - dvs.runcmd("ip link set group default arp off") - dvs.runcmd("ip link set group default arp on") -# Add neighbor entries on servers connecting to SONiC ports -# ping them to get the neighbor entries -def setup_initial_neighbors(dvs): - for i in range(8, 8+NUM_INTF): - for j in range(NUM_NEIGH_PER_INTF): - dvs.servers[i].runcmd("ip addr add {}.0.0.{}/24 dev eth0".format(i*4, j+2)) - dvs.servers[i].runcmd("ip -6 addr add {}00::{}/64 dev eth0".format(i*4,j+2)) + ############################################################################# + # + # Testcase 11. Restart fpmsyncd and make no control-plane changes. + # + ############################################################################# + + + # Stop fpmsyncd + dvs.stop_fpmsyncd() + + # Start fpmsyncd + dvs.start_fpmsyncd() - time.sleep(1) + # Verify FSM + swss_app_check_warmstart_state(state_db, "bgp", "restored") + time.sleep(restart_timer + 1) + swss_app_check_warmstart_state(state_db, "bgp", "reconciled") - for i in range(8, 8+NUM_INTF): - for j in range(NUM_NEIGH_PER_INTF): - dvs.runcmd(['sh', '-c', "ping -c 1 -W 0 -q {}.0.0.{} > /dev/null 2>&1".format(i*4,j+2)]) - dvs.runcmd(['sh', '-c', "ping6 -c 1 -W 0 -q {}00::{} > /dev/null 2>&1".format(i*4,j+2)]) + # Verify swss changes -- none are expected this time + (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) + assert len(addobjs) == 0 and len(delobjs) == 0 -# Del half of the ips and a new half of the ips -# note: the first ipv4 can not be deleted only -def del_and_add_neighbors(dvs): - for i in range(8, 8+NUM_INTF): - for j in range(NUM_NEIGH_PER_INTF/2): - dvs.servers[i].runcmd("ip addr del {}.0.0.{}/24 dev eth0".format(i*4, j+NUM_NEIGH_PER_INTF/2+2)) - dvs.servers[i].runcmd("ip -6 addr del {}00::{}/64 dev eth0".format(i*4,j+NUM_NEIGH_PER_INTF/2+2)) - dvs.servers[i].runcmd("ip addr add {}.0.0.{}/24 dev eth0".format(i*4, j+NUM_NEIGH_PER_INTF+2)) - dvs.servers[i].runcmd("ip -6 addr add {}00::{}/64 dev eth0".format(i*4,j+NUM_NEIGH_PER_INTF+2)) + # Verify sairedis changes -- none are expected this time + (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) + assert len(addobjs) == 0 and len(delobjs) == 0 -#ping new IPs -def ping_new_ips(dvs): - for i in range(8, 8+NUM_INTF): - for j in range(NUM_NEIGH_PER_INTF/2): - dvs.runcmd(['sh', '-c', "ping -c 1 -W 0 -q {}.0.0.{} > /dev/null 2>&1".format(i*4,j+NUM_NEIGH_PER_INTF+2)]) - dvs.runcmd(['sh', '-c', "ping6 -c 1 -W 0 -q {}00::{} > /dev/null 2>&1".format(i*4,j+NUM_NEIGH_PER_INTF+2)]) -def test_system_warmreboot_neighbor_syncup(dvs, testlog): + ############################################################################# + # + # Testcase 12. Restart fpmsyncd and add one new non-ecmp IPv4 prefix + # + ############################################################################# - appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) - conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) - state_db = swsscommon.DBConnector(swsscommon.STATE_DB, dvs.redis_sock, 0) - #enable ipv6 on docker - dvs.runcmd("sysctl net.ipv6.conf.all.disable_ipv6=0") + # Stop fpmsyncd + dvs.stop_fpmsyncd() + + # Add new prefix + dvs.runcmd("ip route add 192.168.100.0/24 nexthop via 111.0.0.2") + time.sleep(1) - # flush all neighs first - flush_neigh_entries(dvs) - time.sleep(5) + # Start fpmsyncd + dvs.start_fpmsyncd() + + # Verify FSM + swss_app_check_warmstart_state(state_db, "bgp", "restored") + time.sleep(restart_timer + 1) + swss_app_check_warmstart_state(state_db, "bgp", "reconciled") - dvs.runcmd("config warm_restart enable system") + # Verify the changed prefix is seen in swss + (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) + assert len(addobjs) == 1 and len(delobjs) == 0 + rt_key = json.loads(addobjs[0]['key']) + rt_val = json.loads(addobjs[0]['vals']) + assert rt_key == "192.168.100.0/24" + assert rt_val == {"ifname": "Ethernet0", "nexthop": "111.0.0.2"} - # Test neighbors on NUM_INTF (e,g 8) interfaces - # Ethernet32/36/.../60, with ip: 32.0.0.1/24... 60.0.0.1/24 - # ipv6: 3200::1/64...6000::1/64 - # bring up the servers'interfaces and assign NUM_NEIGH_PER_INTF (e,g 128) ips per interface - macs = [] - intf_tbl = swsscommon.Table(conf_db, "INTERFACE") - fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) - for i in range(8, 8+NUM_INTF): - # set timeout to be the same as real HW - # set stale timer bigger to avoid testbed difference related timing issues. - # set ip on server facing interfaces - # bring servers' interface up, save the macs - dvs.runcmd("sysctl -w net.ipv4.neigh.Ethernet{}.base_reachable_time_ms=1800000".format(i*4)) - dvs.runcmd("sysctl -w net.ipv6.neigh.Ethernet{}.base_reachable_time_ms=1800000".format(i*4)) - dvs.runcmd("sysctl -w net.ipv4.neigh.Ethernet{}.gc_stale_time=180".format(i*4)) - dvs.runcmd("sysctl -w net.ipv6.neigh.Ethernet{}.gc_stale_time=180".format(i*4)) - dvs.runcmd("ip addr flush dev Ethernet{}".format(i*4)) - intf_tbl.set("Ethernet{}|{}.0.0.1/24".format(i*4, i*4), fvs) - intf_tbl.set("Ethernet{}|{}00::1/64".format(i*4, i*4), fvs) - intf_tbl.set("Ethernet{}".format(i*4, i*4), fvs) - intf_tbl.set("Ethernet{}".format(i*4, i*4), fvs) - dvs.runcmd("ip link set Ethernet{} up".format(i*4, i*4)) - dvs.servers[i].runcmd("ip link set up dev eth0") - dvs.servers[i].runcmd("ip addr flush dev eth0") - #result = dvs.servers[i].runcmd_output("ifconfig eth0 | grep HWaddr | awk '{print $NF}'") - result = dvs.servers[i].runcmd_output("cat /sys/class/net/eth0/address") - macs.append(result.strip()) + # Verify the changed prefix is seen in sairedis + (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) + assert len(addobjs) == 1 and len(delobjs) == 0 + rt_key = json.loads(addobjs[0]['key']) + assert rt_key['dest'] == "192.168.100.0/24" - # - # Testcase 1: - # Setup initial neigbors - setup_initial_neighbors(dvs) - # Check the neighbor entries are inserted correctly - db = swsscommon.DBConnector(0, dvs.redis_sock, 0) - tbl = swsscommon.Table(db, "NEIGH_TABLE") + ############################################################################# + # + # Testcase 13. Restart fpmsyncd and withdraw one non-ecmp IPv4 prefix + # + ############################################################################# + + + # Stop fpmsyncd + dvs.stop_fpmsyncd() + + # Delete prefix + dvs.runcmd("ip route del 192.168.100.0/24 nexthop via 111.0.0.2") + time.sleep(1) + + # Start fpmsyncd + dvs.start_fpmsyncd() + + # Verify FSM + swss_app_check_warmstart_state(state_db, "bgp", "restored") + time.sleep(restart_timer + 1) + swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + + # Verify the changed prefix is seen in swss + (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) + assert len(addobjs) == 0 and len(delobjs) == 1 + rt_key = json.loads(delobjs[0]['key']) + assert rt_key == "192.168.100.0/24" + + # Verify the changed prefix is seen in sairedis + (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) + assert len(addobjs) == 0 and len(delobjs) == 1 + rt_key = json.loads(delobjs[0]['key']) + assert rt_key['dest'] == "192.168.100.0/24" + + + ############################################################################# + # + # Testcase 14. Restart zebra and add/remove a new non-ecmp IPv4 prefix. As + # the 'delete' instruction would arrive after the 'add' one, no + # changes should be pushed down to SwSS. + # + ############################################################################# + + + # Restart zebra + dvs.stop_zebra() + dvs.start_zebra() + + # Add/delete new prefix + dvs.runcmd("ip route add 192.168.100.0/24 nexthop via 111.0.0.2") + time.sleep(1) + dvs.runcmd("ip route del 192.168.100.0/24 nexthop via 111.0.0.2") + time.sleep(1) + + # Verify FSM + swss_app_check_warmstart_state(state_db, "bgp", "restored") + time.sleep(restart_timer + 1) + swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + + # Verify swss changes -- none are expected this time + (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) + assert len(addobjs) == 0 and len(delobjs) == 0 + + # Verify swss changes -- none are expected this time + (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) + assert len(addobjs) == 0 and len(delobjs) == 0 + + + ############################################################################# + # + # Testcase 15. Restart zebra and generate an add/remove/add for new non-ecmp + # IPv4 prefix. Verify that only the second 'add' instruction is + # honored and the corresponding update passed down to SwSS. + # + ############################################################################# + + + # Restart zebra + dvs.stop_zebra() + dvs.start_zebra() + + marker1 = dvs.add_log_marker("/var/log/swss/swss.rec") + marker2 = dvs.add_log_marker("/var/log/swss/sairedis.rec") + + # Add/delete new prefix + dvs.runcmd("ip route add 192.168.100.0/24 nexthop via 111.0.0.2") + time.sleep(1) + dvs.runcmd("ip route del 192.168.100.0/24 nexthop via 111.0.0.2") + time.sleep(1) + dvs.runcmd("ip route add 192.168.100.0/24 nexthop via 122.0.0.2") + time.sleep(1) + + # Verify FSM + swss_app_check_warmstart_state(state_db, "bgp", "restored") + time.sleep(restart_timer + 1) + swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + + # Verify the changed prefix is seen in swss + (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) + assert len(addobjs) == 1 and len(delobjs) == 0 + rt_key = json.loads(addobjs[0]['key']) + rt_val = json.loads(addobjs[0]['vals']) + assert rt_key == "192.168.100.0/24" + assert rt_val == {"ifname": "Ethernet4", "nexthop": "122.0.0.2"} + + # Verify the changed prefix is seen in sairedis + (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) + assert len(addobjs) == 1 and len(delobjs) == 0 + rt_key = json.loads(addobjs[0]['key']) + assert rt_key['dest'] == "192.168.100.0/24" + + intf_tbl._del("{}|111.0.0.1/24".format(intfs[0])) + intf_tbl._del("{}|1110::1/64".format(intfs[0])) + intf_tbl._del("{}|122.0.0.1/24".format(intfs[1])) + intf_tbl._del("{}|1220::1/64".format(intfs[1])) + intf_tbl._del("{}|133.0.0.1/24".format(intfs[2])) + intf_tbl._del("{}|1330::1/64".format(intfs[2])) + intf_tbl._del("{}".format(intfs[0])) + intf_tbl._del("{}".format(intfs[0])) + intf_tbl._del("{}".format(intfs[1])) + intf_tbl._del("{}".format(intfs[1])) + intf_tbl._del("{}".format(intfs[2])) + intf_tbl._del("{}".format(intfs[2])) + time.sleep(2) + + def test_system_warmreboot_neighbor_syncup(self, dvs, testlog): + + appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) + conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + state_db = swsscommon.DBConnector(swsscommon.STATE_DB, dvs.redis_sock, 0) + + #enable ipv6 on docker + dvs.runcmd("sysctl net.ipv6.conf.all.disable_ipv6=0") + + # flush all neighs first + flush_neigh_entries(dvs) + time.sleep(5) + + dvs.runcmd("config warm_restart enable system") + + # Test neighbors on NUM_INTF (e,g 8) interfaces + # Ethernet32/36/.../60, with ip: 32.0.0.1/24... 60.0.0.1/24 + # ipv6: 3200::1/64...6000::1/64 + # bring up the servers'interfaces and assign NUM_NEIGH_PER_INTF (e,g 128) ips per interface + macs = [] + intf_tbl = swsscommon.Table(conf_db, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) + for i in range(8, 8+NUM_INTF): + # set timeout to be the same as real HW + # set stale timer bigger to avoid testbed difference related timing issues. + # set ip on server facing interfaces + # bring servers' interface up, save the macs + dvs.runcmd("sysctl -w net.ipv4.neigh.Ethernet{}.base_reachable_time_ms=1800000".format(i*4)) + dvs.runcmd("sysctl -w net.ipv6.neigh.Ethernet{}.base_reachable_time_ms=1800000".format(i*4)) + dvs.runcmd("sysctl -w net.ipv4.neigh.Ethernet{}.gc_stale_time=180".format(i*4)) + dvs.runcmd("sysctl -w net.ipv6.neigh.Ethernet{}.gc_stale_time=180".format(i*4)) + dvs.runcmd("ip addr flush dev Ethernet{}".format(i*4)) + intf_tbl.set("Ethernet{}|{}.0.0.1/24".format(i*4, i*4), fvs) + intf_tbl.set("Ethernet{}|{}00::1/64".format(i*4, i*4), fvs) + intf_tbl.set("Ethernet{}".format(i*4, i*4), fvs) + intf_tbl.set("Ethernet{}".format(i*4, i*4), fvs) + dvs.runcmd("ip link set Ethernet{} up".format(i*4, i*4)) + dvs.servers[i].runcmd("ip link set up dev eth0") + dvs.servers[i].runcmd("ip addr flush dev eth0") + #result = dvs.servers[i].runcmd_output("ifconfig eth0 | grep HWaddr | awk '{print $NF}'") + result = dvs.servers[i].runcmd_output("cat /sys/class/net/eth0/address") + macs.append(result.strip()) + + # + # Testcase 1: + # Setup initial neigbors + setup_initial_neighbors(dvs) + + # Check the neighbor entries are inserted correctly + db = swsscommon.DBConnector(0, dvs.redis_sock, 0) + tbl = swsscommon.Table(db, "NEIGH_TABLE") + + # number of neighbors should match what we configured + # ipv4/ipv6 entries and loopback + check_redis_neigh_entries(dvs, tbl, 2*NUM_OF_NEIGHS) + + # All neighbor entries should match + for i in range(8, 8+NUM_INTF): + for j in range(NUM_NEIGH_PER_INTF): + (status, fvs) = tbl.get("Ethernet{}:{}.0.0.{}".format(i*4, i*4, j+2)) + assert status == True + for v in fvs: + if v[0] == "family": + assert v[1] == "IPv4" + if v[0] == "neigh": + assert v[1] == macs[i-8] + + (status, fvs) = tbl.get("Ethernet{}:{}00::{}".format(i*4, i*4, j+2)) + assert status == True + for v in fvs: + if v[0] == "family": + assert v[1] == "IPv6" + if v[0] == "neigh": + assert v[1] == macs[i-8] + + # + # Testcase 2: + # Stop neighsyncd, appDB entries should be reserved + # flush kernel neigh table to simulate warm reboot + # start neighsyncd, start restore_neighbors service to restore the neighbor table in kernel + # check all neighbors learned in kernel + # no changes should be there in syslog and sairedis.rec + + # get restore_count + restore_count = swss_get_RestoreCount(dvs, state_db) + + # stop neighsyncd and sairedis.rec + stop_neighsyncd(dvs) + del_entry_tbl(state_db, "NEIGH_RESTORE_TABLE", "Flags") + time.sleep(3) + flush_neigh_entries(dvs) + time.sleep(3) + + # check neighbors are gone + check_kernel_reachable_neigh_num(dvs, 0) + + # start neighsyncd and restore_neighbors + marker = dvs.add_log_marker() + pubsub = dvs.SubscribeAsicDbObject("SAI_OBJECT_TYPE_NEIGHBOR_ENTRY") + start_neighsyncd(dvs) + start_restore_neighbors(dvs) + + # should finish the store within 10 seconds + time.sleep(10) - # number of neighbors should match what we configured - # ipv4/ipv6 entries and loopback - check_redis_neigh_entries(dvs, tbl, 2*NUM_OF_NEIGHS) + check_kernel_reachable_v4_neigh_num(dvs, NUM_OF_NEIGHS) + check_kernel_reachable_v6_neigh_num(dvs, NUM_OF_NEIGHS) - # All neighbor entries should match - for i in range(8, 8+NUM_INTF): - for j in range(NUM_NEIGH_PER_INTF): - (status, fvs) = tbl.get("Ethernet{}:{}.0.0.{}".format(i*4, i*4, j+2)) - assert status == True - for v in fvs: - if v[0] == "family": - assert v[1] == "IPv4" - if v[0] == "neigh": - assert v[1] == macs[i-8] + # check syslog and sairedis.rec file for activities + check_syslog_for_neighbor_entry(dvs, marker, 0, 0, "ipv4") + check_syslog_for_neighbor_entry(dvs, marker, 0, 0, "ipv6") + (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) + assert nadd == 0 + assert ndel == 0 - (status, fvs) = tbl.get("Ethernet{}:{}00::{}".format(i*4, i*4, j+2)) - assert status == True - for v in fvs: - if v[0] == "family": - assert v[1] == "IPv6" - if v[0] == "neigh": - assert v[1] == macs[i-8] + # check restore Count + swss_app_check_RestoreCount_single(state_db, restore_count, "neighsyncd") - # - # Testcase 2: - # Stop neighsyncd, appDB entries should be reserved - # flush kernel neigh table to simulate warm reboot - # start neighsyncd, start restore_neighbors service to restore the neighbor table in kernel - # check all neighbors learned in kernel - # no changes should be there in syslog and sairedis.rec - - # get restore_count - restore_count = swss_get_RestoreCount(dvs, state_db) - - # stop neighsyncd and sairedis.rec - stop_neighsyncd(dvs) - del_entry_tbl(state_db, "NEIGH_RESTORE_TABLE", "Flags") - time.sleep(3) - flush_neigh_entries(dvs) - time.sleep(3) - - # check neighbors are gone - check_kernel_reachable_neigh_num(dvs, 0) - - # start neighsyncd and restore_neighbors - marker = dvs.add_log_marker() - pubsub = dvs.SubscribeAsicDbObject("SAI_OBJECT_TYPE_NEIGHBOR_ENTRY") - start_neighsyncd(dvs) - start_restore_neighbors(dvs) - - # should finish the store within 10 seconds - time.sleep(10) - - check_kernel_reachable_v4_neigh_num(dvs, NUM_OF_NEIGHS) - check_kernel_reachable_v6_neigh_num(dvs, NUM_OF_NEIGHS) - - # check syslog and sairedis.rec file for activities - check_syslog_for_neighbor_entry(dvs, marker, 0, 0, "ipv4") - check_syslog_for_neighbor_entry(dvs, marker, 0, 0, "ipv6") - (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) - assert nadd == 0 - assert ndel == 0 - - # check restore Count - swss_app_check_RestoreCount_single(state_db, restore_count, "neighsyncd") + # + # Testcase 3: + # Stop neighsyncd, appDB entries should be reserved + # flush kernel neigh table to simulate warm reboot + # Remove half of ips of servers' interfaces, add new half of ips + # start neighsyncd, start restore_neighbors service to restore the neighbor table in kernel + # check all new neighbors learned in kernel + # no changes should be there in syslog and sairedis.rec - # - # Testcase 3: - # Stop neighsyncd, appDB entries should be reserved - # flush kernel neigh table to simulate warm reboot - # Remove half of ips of servers' interfaces, add new half of ips - # start neighsyncd, start restore_neighbors service to restore the neighbor table in kernel - # check all new neighbors learned in kernel - # no changes should be there in syslog and sairedis.rec + # get restore_count + restore_count = swss_get_RestoreCount(dvs, state_db) - # get restore_count - restore_count = swss_get_RestoreCount(dvs, state_db) + # stop neighsyncd and sairedis.rec + stop_neighsyncd(dvs) + del_entry_tbl(state_db, "NEIGH_RESTORE_TABLE", "Flags") + time.sleep(3) - # stop neighsyncd and sairedis.rec - stop_neighsyncd(dvs) - del_entry_tbl(state_db, "NEIGH_RESTORE_TABLE", "Flags") - time.sleep(3) + del_and_add_neighbors(dvs) - del_and_add_neighbors(dvs) + flush_neigh_entries(dvs) + time.sleep(3) - flush_neigh_entries(dvs) - time.sleep(3) + # check neighbors are gone + check_kernel_reachable_neigh_num(dvs, 0) - # check neighbors are gone - check_kernel_reachable_neigh_num(dvs, 0) + # start neighsyncd and restore_neighbors + marker = dvs.add_log_marker() + start_neighsyncd(dvs) + start_restore_neighbors(dvs) - # start neighsyncd and restore_neighbors - marker = dvs.add_log_marker() - start_neighsyncd(dvs) - start_restore_neighbors(dvs) + # should finish the store within 10 seconds + time.sleep(10) - # should finish the store within 10 seconds - time.sleep(10) + check_kernel_reachable_v4_neigh_num(dvs, NUM_OF_NEIGHS/2) + check_kernel_reachable_v6_neigh_num(dvs, NUM_OF_NEIGHS/2) - check_kernel_reachable_v4_neigh_num(dvs, NUM_OF_NEIGHS/2) - check_kernel_reachable_v6_neigh_num(dvs, NUM_OF_NEIGHS/2) + check_kernel_stale_v4_neigh_num(dvs, NUM_OF_NEIGHS/2) + check_kernel_stale_v6_neigh_num(dvs, NUM_OF_NEIGHS/2) - check_kernel_stale_v4_neigh_num(dvs, NUM_OF_NEIGHS/2) - check_kernel_stale_v6_neigh_num(dvs, NUM_OF_NEIGHS/2) + # check syslog and sairedis.rec file for activities + check_syslog_for_neighbor_entry(dvs, marker, 0, 0, "ipv4") + check_syslog_for_neighbor_entry(dvs, marker, 0, 0, "ipv6") + (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) + assert nadd == 0 + assert ndel == 0 - # check syslog and sairedis.rec file for activities - check_syslog_for_neighbor_entry(dvs, marker, 0, 0, "ipv4") - check_syslog_for_neighbor_entry(dvs, marker, 0, 0, "ipv6") - (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) - assert nadd == 0 - assert ndel == 0 + # check restore Count + swss_app_check_RestoreCount_single(state_db, restore_count, "neighsyncd") - # check restore Count - swss_app_check_RestoreCount_single(state_db, restore_count, "neighsyncd") + # Test case 4: + # ping the new ips, should get it into appDB + marker = dvs.add_log_marker() - # Test case 4: - # ping the new ips, should get it into appDB - marker = dvs.add_log_marker() + ping_new_ips(dvs) - ping_new_ips(dvs) + check_kernel_reachable_v4_neigh_num(dvs, NUM_OF_NEIGHS) + check_kernel_reachable_v6_neigh_num(dvs, NUM_OF_NEIGHS) - check_kernel_reachable_v4_neigh_num(dvs, NUM_OF_NEIGHS) - check_kernel_reachable_v6_neigh_num(dvs, NUM_OF_NEIGHS) + check_kernel_stale_v4_neigh_num(dvs, NUM_OF_NEIGHS/2) + check_kernel_stale_v6_neigh_num(dvs, NUM_OF_NEIGHS/2) - check_kernel_stale_v4_neigh_num(dvs, NUM_OF_NEIGHS/2) - check_kernel_stale_v6_neigh_num(dvs, NUM_OF_NEIGHS/2) + check_redis_neigh_entries(dvs, tbl, 2*(NUM_OF_NEIGHS+NUM_OF_NEIGHS/2)) - check_redis_neigh_entries(dvs, tbl, 2*(NUM_OF_NEIGHS+NUM_OF_NEIGHS/2)) + (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) + assert nadd == NUM_OF_NEIGHS #ipv4 and ipv6 + assert ndel == 0 - (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) - assert nadd == NUM_OF_NEIGHS #ipv4 and ipv6 - assert ndel == 0 + # Remove stale entries manually + for i in range(8, 8+NUM_INTF): + for j in range(NUM_NEIGH_PER_INTF/2): + dvs.runcmd(['sh', '-c', "ip neigh del {}.0.0.{} dev Ethernet{}".format(i*4,j+NUM_NEIGH_PER_INTF/2+2, i*4)]) + dvs.runcmd(['sh', '-c', "ip -6 neigh del {}00::{} dev Ethernet{}".format(i*4,j+NUM_NEIGH_PER_INTF/2+2, i*4)]) - # Remove stale entries manually - for i in range(8, 8+NUM_INTF): - for j in range(NUM_NEIGH_PER_INTF/2): - dvs.runcmd(['sh', '-c', "ip neigh del {}.0.0.{} dev Ethernet{}".format(i*4,j+NUM_NEIGH_PER_INTF/2+2, i*4)]) - dvs.runcmd(['sh', '-c', "ip -6 neigh del {}00::{} dev Ethernet{}".format(i*4,j+NUM_NEIGH_PER_INTF/2+2, i*4)]) + time.sleep(5) - time.sleep(5) + check_kernel_reachable_v4_neigh_num(dvs, NUM_OF_NEIGHS) + check_kernel_reachable_v6_neigh_num(dvs, NUM_OF_NEIGHS) - check_kernel_reachable_v4_neigh_num(dvs, NUM_OF_NEIGHS) - check_kernel_reachable_v6_neigh_num(dvs, NUM_OF_NEIGHS) + check_kernel_stale_v4_neigh_num(dvs, 0) + check_kernel_stale_v6_neigh_num(dvs, 0) - check_kernel_stale_v4_neigh_num(dvs, 0) - check_kernel_stale_v6_neigh_num(dvs, 0) + check_redis_neigh_entries(dvs, tbl, 2*NUM_OF_NEIGHS) - check_redis_neigh_entries(dvs, tbl, 2*NUM_OF_NEIGHS) + (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) + assert nadd == 0 + assert ndel == NUM_OF_NEIGHS #ipv4 and ipv6 - (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) - assert nadd == 0 - assert ndel == NUM_OF_NEIGHS #ipv4 and ipv6 + # + # Testcase 5: + # Stop neighsyncd, appDB entries should be reserved + # flush kernel neigh table to simulate warm reboot + # keep half of the interface down + # start neighsyncd, start restore_neighbors service to restore the neighbor table in kernel + # check all new neighbors with interface up to be learned in kernel + # syslog/sai log should show half of the entries stale/deleted - # - # Testcase 5: - # Stop neighsyncd, appDB entries should be reserved - # flush kernel neigh table to simulate warm reboot - # keep half of the interface down - # start neighsyncd, start restore_neighbors service to restore the neighbor table in kernel - # check all new neighbors with interface up to be learned in kernel - # syslog/sai log should show half of the entries stale/deleted + # get restore_count + restore_count = swss_get_RestoreCount(dvs, state_db) - # get restore_count - restore_count = swss_get_RestoreCount(dvs, state_db) + # stop neighsyncd and sairedis.rec + stop_neighsyncd(dvs) + del_entry_tbl(state_db, "NEIGH_RESTORE_TABLE", "Flags") + time.sleep(3) - # stop neighsyncd and sairedis.rec - stop_neighsyncd(dvs) - del_entry_tbl(state_db, "NEIGH_RESTORE_TABLE", "Flags") - time.sleep(3) + flush_neigh_entries(dvs) + time.sleep(3) - flush_neigh_entries(dvs) - time.sleep(3) + # check neighbors are gone + check_kernel_reachable_neigh_num(dvs, 0) - # check neighbors are gone - check_kernel_reachable_neigh_num(dvs, 0) + # bring down half of the links + for i in range(8, 8+NUM_INTF/2): + dvs.runcmd("ip link set down dev Ethernet{}".format(i*4)) - # bring down half of the links - for i in range(8, 8+NUM_INTF/2): - dvs.runcmd("ip link set down dev Ethernet{}".format(i*4)) + # start neighsyncd and restore_neighbors + marker = dvs.add_log_marker() + start_neighsyncd(dvs) + start_restore_neighbors(dvs) - # start neighsyncd and restore_neighbors - marker = dvs.add_log_marker() - start_neighsyncd(dvs) - start_restore_neighbors(dvs) + # restore for up interfaces should be done within 10 seconds + time.sleep(10) - # restore for up interfaces should be done within 10 seconds - time.sleep(10) + check_kernel_reachable_v4_neigh_num(dvs, NUM_OF_NEIGHS/2) + check_kernel_reachable_v6_neigh_num(dvs, NUM_OF_NEIGHS/2) - check_kernel_reachable_v4_neigh_num(dvs, NUM_OF_NEIGHS/2) - check_kernel_reachable_v6_neigh_num(dvs, NUM_OF_NEIGHS/2) + restoretbl = swsscommon.Table(state_db, swsscommon.STATE_NEIGH_RESTORE_TABLE_NAME) - restoretbl = swsscommon.Table(state_db, swsscommon.STATE_NEIGH_RESTORE_TABLE_NAME) + # waited 10 above already + i = 10 + while (not kernel_restore_neighs_done(restoretbl)): + print "Waiting for kernel neighbors restore process done: {} seconds".format(i) + time.sleep(10) + i += 10 - # waited 10 above already - i = 10 - while (not kernel_restore_neighs_done(restoretbl)): - print "Waiting for kernel neighbors restore process done: {} seconds".format(i) time.sleep(10) - i += 10 - - time.sleep(10) - # check syslog and sairedis.rec file for activities - check_syslog_for_neighbor_entry(dvs, marker, 0, NUM_OF_NEIGHS/2, "ipv4") - check_syslog_for_neighbor_entry(dvs, marker, 0, NUM_OF_NEIGHS/2, "ipv6") - (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) - assert nadd == 0 - assert ndel == NUM_OF_NEIGHS + # check syslog and sairedis.rec file for activities + check_syslog_for_neighbor_entry(dvs, marker, 0, NUM_OF_NEIGHS/2, "ipv4") + check_syslog_for_neighbor_entry(dvs, marker, 0, NUM_OF_NEIGHS/2, "ipv6") + (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) + assert nadd == 0 + assert ndel == NUM_OF_NEIGHS - # check restore Count - swss_app_check_RestoreCount_single(state_db, restore_count, "neighsyncd") + # check restore Count + swss_app_check_RestoreCount_single(state_db, restore_count, "neighsyncd") - # disable system warm restart - dvs.runcmd("config warm_restart disable system") + # disable system warm restart + dvs.runcmd("config warm_restart disable system") - for i in range(8, 8+NUM_INTF): - intf_tbl._del("Ethernet{}|{}.0.0.1/24".format(i*4, i*4)) - intf_tbl._del("Ethernet{}|{}00::1/64".format(i*4, i*4)) - intf_tbl._del("Ethernet{}".format(i*4, i*4)) - intf_tbl._del("Ethernet{}".format(i*4, i*4)) + for i in range(8, 8+NUM_INTF): + intf_tbl._del("Ethernet{}|{}.0.0.1/24".format(i*4, i*4)) + intf_tbl._del("Ethernet{}|{}00::1/64".format(i*4, i*4)) + intf_tbl._del("Ethernet{}".format(i*4, i*4)) + intf_tbl._del("Ethernet{}".format(i*4, i*4))