Skip to content

Commit d78b528

Browse files
authored
[MuxOrch] Enabling neighbor when adding in active state (sonic-net#2601)
* [MuxOrch] Enabling neighbor when adding in active state What I did: called enable when adding a neighbor in active state Why I did it: NH routes weren't being updated if they existed in standby state before neighbor is added
1 parent 4ebdad1 commit d78b528

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

orchagent/muxorch.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,8 @@ void MuxCable::updateNeighbor(NextHopKey nh, bool add)
567567

568568
void MuxNbrHandler::update(NextHopKey nh, sai_object_id_t tunnelId, bool add, MuxState state)
569569
{
570+
uint32_t num_routes = 0;
571+
570572
SWSS_LOG_INFO("Neigh %s on %s, add %d, state %d",
571573
nh.ip_address.to_string().c_str(), nh.alias.c_str(), add, state);
572574

@@ -592,6 +594,7 @@ void MuxNbrHandler::update(NextHopKey nh, sai_object_id_t tunnelId, bool add, Mu
592594
case MuxState::MUX_STATE_ACTIVE:
593595
neighbors_[nh.ip_address] = gNeighOrch->getLocalNextHopId(nh);
594596
gNeighOrch->enableNeighbor(nh);
597+
gRouteOrch->updateNextHopRoutes(nh, num_routes);
595598
break;
596599
case MuxState::MUX_STATE_STANDBY:
597600
neighbors_[nh.ip_address] = tunnelId;

orchagent/neighorch.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,14 @@ void NeighOrch::decreaseNextHopRefCount(const NextHopKey &nexthop, uint32_t coun
591591
assert(hasNextHop(nexthop));
592592
if (m_syncdNextHops.find(nexthop) != m_syncdNextHops.end())
593593
{
594+
if ((m_syncdNextHops[nexthop].ref_count - (int)count) < 0)
595+
{
596+
SWSS_LOG_ERROR("Ref count cannot be negative for next_hop_id: 0x%" PRIx64 " with ip: %s and alias: %s",
597+
m_syncdNextHops[nexthop].next_hop_id, nexthop.ip_address.to_string().c_str(), nexthop.alias.c_str());
598+
// Reset refcount to 0 to match expected value
599+
m_syncdNextHops[nexthop].ref_count = 0;
600+
return;
601+
}
594602
m_syncdNextHops[nexthop].ref_count -= count;
595603
}
596604
}

tests/test_mux.py

+74
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,72 @@ def create_and_test_route(self, appdb, asicdb, dvs, dvs_route):
537537

538538
ps._del(rtprefix)
539539

540+
def create_and_test_NH_routes(self, appdb, asicdb, dvs, dvs_route, mac):
541+
'''
542+
Tests case where neighbor is removed in standby and added in active with route
543+
'''
544+
nh_route = "2.2.2.0/24"
545+
nh_route_ipv6 = "2023::/64"
546+
neigh_ip = self.SERV1_IPV4
547+
neigh_ipv6 = self.SERV1_IPV6
548+
apdb = dvs.get_app_db()
549+
550+
# Setup
551+
self.set_mux_state(appdb, "Ethernet0", "active")
552+
self.add_neighbor(dvs, neigh_ip, mac)
553+
self.add_neighbor(dvs, neigh_ipv6, mac)
554+
dvs.runcmd(
555+
"vtysh -c \"configure terminal\" -c \"ip route " + nh_route +
556+
" " + neigh_ip + "\""
557+
)
558+
dvs.runcmd(
559+
"vtysh -c \"configure terminal\" -c \"ipv6 route " + nh_route_ipv6 +
560+
" " + neigh_ipv6 + "\""
561+
)
562+
apdb.wait_for_entry("ROUTE_TABLE", nh_route)
563+
rtkeys = dvs_route.check_asicdb_route_entries([nh_route])
564+
rtkeys_ipv6 = dvs_route.check_asicdb_route_entries([nh_route_ipv6])
565+
self.check_nexthop_in_asic_db(asicdb, rtkeys[0])
566+
self.check_nexthop_in_asic_db(asicdb, rtkeys_ipv6[0])
567+
568+
# Set state to standby and delete neighbor
569+
self.set_mux_state(appdb, "Ethernet0", "standby")
570+
self.check_nexthop_in_asic_db(asicdb, rtkeys[0], True)
571+
self.check_nexthop_in_asic_db(asicdb, rtkeys_ipv6[0], True)
572+
573+
self.del_neighbor(dvs, neigh_ip)
574+
self.del_neighbor(dvs, neigh_ipv6)
575+
self.check_nexthop_in_asic_db(asicdb, rtkeys[0], True)
576+
self.check_nexthop_in_asic_db(asicdb, rtkeys_ipv6[0], True)
577+
578+
# Set state to active, learn neighbor again
579+
self.set_mux_state(appdb, "Ethernet0", "active")
580+
self.check_nexthop_in_asic_db(asicdb, rtkeys[0], True)
581+
self.check_nexthop_in_asic_db(asicdb, rtkeys_ipv6[0], True)
582+
583+
self.add_neighbor(dvs, neigh_ip, mac)
584+
self.add_neighbor(dvs, neigh_ipv6, mac)
585+
self.check_nexthop_in_asic_db(asicdb, rtkeys[0])
586+
self.check_nexthop_in_asic_db(asicdb, rtkeys_ipv6[0])
587+
dvs.runcmd(
588+
"ip neigh flush " + neigh_ip
589+
)
590+
dvs.runcmd(
591+
"ip neigh flush " + neigh_ipv6
592+
)
593+
594+
# Cleanup
595+
dvs.runcmd(
596+
"vtysh -c \"configure terminal\" -c \"no ip route " + nh_route +
597+
" " + neigh_ip + "\""
598+
)
599+
dvs.runcmd(
600+
"vtysh -c \"configure terminal\" -c \"no ipv6 route " + nh_route_ipv6 +
601+
" " + neigh_ipv6 + "\""
602+
)
603+
self.del_neighbor(dvs, neigh_ip)
604+
self.del_neighbor(dvs, neigh_ipv6)
605+
540606
def get_expected_sai_qualifiers(self, portlist, dvs_acl):
541607
expected_sai_qualifiers = {
542608
"SAI_ACL_ENTRY_ATTR_PRIORITY": self.ACL_PRIORITY,
@@ -1099,6 +1165,14 @@ def test_Route(self, dvs, dvs_route, testlog):
10991165

11001166
self.create_and_test_route(appdb, asicdb, dvs, dvs_route)
11011167

1168+
def test_NH(self, dvs, dvs_route, intf_fdb_map, setup_peer_switch, setup_tunnel, testlog):
1169+
""" test NH routes and mux state change """
1170+
appdb = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0)
1171+
asicdb = dvs.get_asic_db()
1172+
mac = intf_fdb_map["Ethernet0"]
1173+
1174+
self.create_and_test_NH_routes(appdb, asicdb, dvs, dvs_route, mac)
1175+
11021176
def test_acl(self, dvs, dvs_acl, testlog):
11031177
""" test acl and mux state change """
11041178

0 commit comments

Comments
 (0)