@@ -223,11 +223,14 @@ def check_neigh_in_asic_db(self, asicdb, ip, expected=True):
223223
224224 return ''
225225
226- def check_tnl_nexthop_in_asic_db (self , asicdb , expected = 1 ):
226+ def check_tnl_nexthop_in_asic_db (self , asicdb , expected = None ):
227227
228228 global tunnel_nh_id
229229
230- nh = asicdb .wait_for_n_keys (self .ASIC_NEXTHOP_TABLE , expected )
230+ if expected :
231+ nh = asicdb .wait_for_n_keys (self .ASIC_NEXTHOP_TABLE , expected )
232+ else :
233+ nh = asicdb .get_keys (self .ASIC_NEXTHOP_TABLE )
231234
232235 for key in nh :
233236 fvs = asicdb .get_entry (self .ASIC_NEXTHOP_TABLE , key )
@@ -525,12 +528,15 @@ def create_and_test_fdb(self, appdb, asicdb, dvs, dvs_route):
525528
526529 self .del_fdb (dvs , "00-00-00-00-00-11" )
527530
528- def create_and_test_route (self , appdb , asicdb , dvs , dvs_route ):
529-
531+ def create_and_test_route (self , appdb , asicdb , dvs , dvs_route , mac_Ethernet0 , mac_Ethernet4 ):
530532 self .set_mux_state (appdb , "Ethernet0" , "active" )
531533
532534 rtprefix = "2.3.4.0/24"
533535
536+ # Make sure neighbor is present
537+ self .add_neighbor (dvs , self .SERV1_IPV4 , mac_Ethernet0 )
538+ self .add_neighbor (dvs , self .SERV2_IPV4 , mac_Ethernet0 )
539+
534540 dvs .runcmd (
535541 "vtysh -c \" configure terminal\" -c \" ip route " + rtprefix +
536542 " " + self .SERV1_IPV4 + "\" "
@@ -546,6 +552,7 @@ def create_and_test_route(self, appdb, asicdb, dvs, dvs_route):
546552 # Change Mux state to Standby and verify route pointing to Tunnel
547553 self .set_mux_state (appdb , "Ethernet0" , "standby" )
548554
555+ self .check_tnl_nexthop_in_asic_db (asicdb )
549556 self .check_nexthop_in_asic_db (asicdb , rtkeys [0 ], True )
550557
551558 # Change Mux state back to Active and verify route is not pointing to Tunnel
@@ -581,6 +588,39 @@ def create_and_test_route(self, appdb, asicdb, dvs, dvs_route):
581588 " " + self .SERV1_IPV4 + "\" "
582589 )
583590
591+ def create_and_test_route_learned_before_neighbor (self , appdb , asicdb , dvs , dvs_route , mac ):
592+ rtprefix = "2.3.4.0/24"
593+ neigh = "192.168.0.110"
594+ mux_port = "Ethernet0"
595+
596+ nexthop_map = {"active" : neigh , "standby" : tunnel_nh_id }
597+ toggle_map = {"active" : "standby" , "standby" : "active" }
598+
599+ for state in ["standby" , "active" ]:
600+ try :
601+ current_state = state
602+ self .set_mux_state (appdb , mux_port , current_state )
603+
604+ self .add_route (dvs , rtprefix , [neigh ])
605+ time .sleep (1 )
606+ self .add_neighbor (dvs , neigh , mac )
607+
608+ # Confirm route is pointing to tunnel nh
609+ self .check_route_nexthop (dvs_route , asicdb , rtprefix , nexthop_map [current_state ], (current_state == "standby" ))
610+
611+ # Toggle the mux a few times
612+ current_state = toggle_map [current_state ]
613+ self .set_mux_state (appdb , mux_port , current_state )
614+ self .check_route_nexthop (dvs_route , asicdb , rtprefix , nexthop_map [current_state ], (current_state == "standby" ))
615+
616+ current_state = toggle_map [current_state ]
617+ self .set_mux_state (appdb , mux_port , current_state )
618+ self .check_route_nexthop (dvs_route , asicdb , rtprefix , nexthop_map [current_state ], (current_state == "standby" ))
619+
620+ finally :
621+ self .del_route (dvs , rtprefix )
622+ self .del_neighbor (dvs , neigh )
623+
584624 def multi_nexthop_check (self , asicdb , dvs_route , route , nexthops , mux_states , non_mux_nexthop = None , expect_active = None ):
585625 """
586626 Checks if multi-mux route points to an active nexthop or tunnel.
@@ -1574,7 +1614,6 @@ def setup(self, dvs):
15741614 self .remove_qos_map (db , swsscommon .CFG_DSCP_TO_TC_MAP_TABLE_NAME , dscp_to_tc_map_oid )
15751615 self .remove_qos_map (db , swsscommon .CFG_TC_TO_PRIORITY_GROUP_MAP_TABLE_NAME , tc_to_pg_map_oid )
15761616
1577-
15781617 def test_Tunnel (self , dvs , setup_tunnel , restore_tunnel , testlog , setup ):
15791618 """ test IPv4 Mux tunnel creation """
15801619 db = swsscommon .DBConnector (swsscommon .APPL_DB , dvs .redis_sock , 0 )
@@ -1602,6 +1641,73 @@ def test_Peer(self, dvs, setup_peer_switch, setup_tunnel, setup, testlog):
16021641
16031642 self .create_and_test_peer (asicdb , encap_tc_to_dscp_map_id , encap_tc_to_queue_map_id )
16041643
1644+ def test_neighbor_learned_before_mux_config (self , dvs , dvs_route , setup , setup_vlan , setup_peer_switch , setup_tunnel , testlog ):
1645+ """ test neighbors learned before mux config """
1646+ test_ip_v4 = "192.168.0.110"
1647+ test_ip_v6 = "fc02:1000::110"
1648+
1649+ toggle_map = {"active" : "standby" , "standby" : "active" }
1650+
1651+ asicdb = dvs .get_asic_db ()
1652+ config_db = dvs .get_config_db ()
1653+ appdb = swsscommon .DBConnector (swsscommon .APPL_DB , dvs .redis_sock , 0 )
1654+
1655+ dvs .runcmd ("ip neigh flush all" )
1656+ for create_route in [False , True ]:
1657+ for state in ["active" , "standby" ]:
1658+ try :
1659+ current_state = state
1660+
1661+ # Step 1.a: add neighbor on port
1662+ self .add_fdb (dvs , "Ethernet4" , "00-00-00-11-11-11" )
1663+
1664+ self .add_neighbor (dvs , test_ip_v4 , "00:00:00:11:11:11" )
1665+ self .check_neigh_in_asic_db (asicdb , test_ip_v4 , expected = True )
1666+
1667+ self .add_neighbor (dvs , test_ip_v6 , "00:00:00:11:11:11" )
1668+ self .check_neigh_in_asic_db (asicdb , test_ip_v6 , expected = True )
1669+
1670+ if create_route :
1671+ # Step 1.b: Create a route pointing to the neighbor
1672+ self .add_route (dvs , "11.11.11.11/32" , ["192.168.0.100" ])
1673+
1674+ # Step 2: configure mux port and verify neighbor state.
1675+ self .set_mux_state (appdb , "Ethernet4" , current_state )
1676+ fvs = {"server_ipv4" : self .SERV2_IPV4 + self .IPV4_MASK ,
1677+ "server_ipv6" : self .SERV2_IPV6 + self .IPV6_MASK }
1678+ config_db .create_entry (self .CONFIG_MUX_CABLE , "Ethernet4" , fvs )
1679+
1680+ self .check_neigh_in_asic_db (asicdb , test_ip_v4 , expected = (current_state != "standby" ))
1681+ self .check_tunnel_route_in_app_db (dvs , [test_ip_v4 + self .IPV4_MASK ], expected = (current_state == "standby" ))
1682+ self .check_neigh_in_asic_db (asicdb , test_ip_v6 , expected = (current_state != "standby" ))
1683+ self .check_tunnel_route_in_app_db (dvs , [test_ip_v6 + self .IPV6_MASK ], expected = (current_state == "standby" ))
1684+
1685+ # Step 3: toggle mux state and verify neighbor state.
1686+ current_state = toggle_map [current_state ]
1687+ self .set_mux_state (appdb , "Ethernet4" , current_state )
1688+
1689+ self .check_neigh_in_asic_db (asicdb , test_ip_v4 , expected = (current_state != "standby" ))
1690+ self .check_tunnel_route_in_app_db (dvs , [test_ip_v4 + self .IPV4_MASK ], expected = (current_state == "standby" ))
1691+ self .check_neigh_in_asic_db (asicdb , test_ip_v6 , expected = (current_state != "standby" ))
1692+ self .check_tunnel_route_in_app_db (dvs , [test_ip_v6 + self .IPV6_MASK ], expected = (current_state == "standby" ))
1693+
1694+ # Step 4: toggle mux state back to initial state and verify neighbor state.
1695+ current_state = toggle_map [current_state ]
1696+ self .set_mux_state (appdb , "Ethernet4" , current_state )
1697+
1698+ self .check_neigh_in_asic_db (asicdb , test_ip_v4 , expected = (current_state != "standby" ))
1699+ self .check_tunnel_route_in_app_db (dvs , [test_ip_v4 + self .IPV4_MASK ], expected = (current_state == "standby" ))
1700+ self .check_neigh_in_asic_db (asicdb , test_ip_v6 , expected = (current_state != "standby" ))
1701+ self .check_tunnel_route_in_app_db (dvs , [test_ip_v6 + self .IPV6_MASK ], expected = (current_state == "standby" ))
1702+
1703+ finally :
1704+ if create_route :
1705+ self .del_route (dvs , "11.11.11.11/32" )
1706+ self .del_neighbor (dvs , test_ip_v4 )
1707+ self .del_neighbor (dvs , test_ip_v6 )
1708+ config_db .delete_entry (self .CONFIG_MUX_CABLE , "Ethernet4" )
1709+ dvs .runcmd ("ip neigh flush all" )
1710+
16051711 def test_Neighbor (self , dvs , dvs_route , setup_vlan , setup_mux_cable , testlog ):
16061712 """ test Neighbor entries and mux state change """
16071713
@@ -1619,13 +1725,16 @@ def test_Fdb(self, dvs, dvs_route, testlog):
16191725
16201726 self .create_and_test_fdb (appdb , asicdb , dvs , dvs_route )
16211727
1622- def test_Route (self , dvs , dvs_route , testlog ):
1728+ def test_Route (self , dvs , intf_fdb_map , dvs_route , setup , setup_vlan , setup_peer_switch , setup_tunnel , setup_mux_cable , testlog ):
16231729 """ test Route entries and mux state change """
16241730
16251731 appdb = swsscommon .DBConnector (swsscommon .APPL_DB , dvs .redis_sock , 0 )
16261732 asicdb = dvs .get_asic_db ()
1733+ mac_Ethernet0 = intf_fdb_map ["Ethernet0" ]
1734+ mac_Ethernet4 = intf_fdb_map ["Ethernet4" ]
16271735
1628- self .create_and_test_route (appdb , asicdb , dvs , dvs_route )
1736+ self .create_and_test_route (appdb , asicdb , dvs , dvs_route , mac_Ethernet0 , mac_Ethernet4 )
1737+ self .create_and_test_route_learned_before_neighbor (appdb , asicdb , dvs , dvs_route , mac_Ethernet0 )
16291738
16301739 def test_NH (self , dvs , dvs_route , intf_fdb_map , setup , setup_mux_cable ,
16311740 setup_peer_switch , setup_tunnel , testlog ):
@@ -1635,7 +1744,7 @@ def test_NH(self, dvs, dvs_route, intf_fdb_map, setup, setup_mux_cable,
16351744 mac = intf_fdb_map ["Ethernet0" ]
16361745
16371746 # get tunnel nexthop
1638- self .check_tnl_nexthop_in_asic_db (asicdb , 5 )
1747+ self .check_tnl_nexthop_in_asic_db (asicdb )
16391748
16401749 self .create_and_test_NH_routes (appdb , asicdb , dvs , dvs_route , mac )
16411750
0 commit comments