Skip to content

Commit

Permalink
update nexthop group support
Browse files Browse the repository at this point in the history
Signed-off-by: Kanji Nakano <[email protected]>
  • Loading branch information
nakano-omw committed Dec 11, 2024
1 parent a8130c9 commit ffdd470
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
24 changes: 13 additions & 11 deletions fpmsyncd/routesync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1678,22 +1678,25 @@ void RouteSync::onRouteMsg(int nlmsg_type, struct nl_object *obj, char *vrf)
NextHopGroup& nhg = itg->second;
if(nhg.group.size() == 0)
{
//Using route-table only for single next-hop
string nexthops, ifnames, weights;
// Using route-table only for single next-hop
string nexthops = nhg.nexthop.empty() ? (rtnl_route_get_family(route_obj) == AF_INET ? "0.0.0.0" : "::") : nhg.nexthop;
string ifnames, weights;

getNextHopGroupFields(nhg, nexthops, ifnames, weights, rtnl_route_get_family(route_obj));
FieldValueTuple gw("nexthop", nexthops.c_str());
FieldValueTuple intf("ifname", ifnames.c_str());
fvVector.push_back(gw);
fvVector.push_back(intf);
SWSS_LOG_DEBUG("NextHop group id %d is a single nexthop address. Filling the route table %s with nexthop and ifname", nhg_id, destipprefix);
getNextHopGroupFields(nhg, nexthops, ifnames, weights, rtnl_route_get_family(route_obj));

FieldValueTuple gw("nexthop", nexthops.c_str());
FieldValueTuple intf("ifname", ifnames.c_str());
fvVector.push_back(gw);
fvVector.push_back(intf);

SWSS_LOG_DEBUG("NextHop group id %d is a single nexthop address. Filling the route table %s with nexthop and ifname", nhg_id, destipprefix);
}
else
{
nhg_id_key = getNextHopGroupKeyAsString(nhg_id);
FieldValueTuple nhg("nexthop_group", nhg_id_key.c_str());
fvVector.push_back(nhg);
updateNextHopGroup(nhg_id);
installNextHopGroup(nhg_id);
}

auto proto_num = rtnl_route_get_protocol(route_obj);
Expand Down Expand Up @@ -2635,7 +2638,7 @@ const string RouteSync::getNextHopGroupKeyAsString(uint32_t id) const
* @arg nh_id nexthop group id
*
*/
void RouteSync::updateNextHopGroup(uint32_t nh_id)
void RouteSync::installNextHopGroup(uint32_t nh_id)
{
auto git = m_nh_groups.find(nh_id);
if(git == m_nh_groups.end())
Expand Down Expand Up @@ -2705,7 +2708,6 @@ void RouteSync::updateNextHopGroupDb(const NextHopGroup& nhg)
}
SWSS_LOG_INFO("NextHopGroup table set: key [%s] nexthop[%s] ifname[%s] weight[%s]", key.c_str(), nexthops.c_str(), ifnames.c_str(), weights.c_str());

//TODO: Take care of warm reboot
m_nexthop_groupTable.set(key.c_str(), fvVector);
}

Expand Down
2 changes: 1 addition & 1 deletion fpmsyncd/routesync.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class RouteSync : public NetMsg
void onNextHopMsg(struct nlmsghdr *h, int len);
/* Get next hop group key */
const string getNextHopGroupKeyAsString(uint32_t id) const;
void updateNextHopGroup(uint32_t nh_id);
void installNextHopGroup(uint32_t nh_id);
void deleteNextHopGroup(uint32_t nh_id);
void updateNextHopGroupDb(const NextHopGroup& nhg);
void getNextHopGroupFields(const NextHopGroup& nhg, string& nexthops, string& ifnames, string& weights, uint8_t af = AF_INET);
Expand Down
6 changes: 3 additions & 3 deletions tests/mock_tests/fpmsyncd/test_routesync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ TEST_F(FpmSyncdResponseTest, TestIPv6NextHopAdd)
ASSERT_TRUE(fieldValues.empty());

// Update the nexthop group to mark it as installed and write to DB
m_mockRouteSync.updateNextHopGroup(test_id);
m_mockRouteSync.installNextHopGroup(test_id);
nexthop_group_table.get(key, fieldValues);

string nexthop, ifname;
Expand Down Expand Up @@ -553,7 +553,7 @@ TEST_F(FpmSyncdResponseTest, TestUpdateNextHopGroupDb)
m_mockRouteSync.m_nh_groups.insert({2, nhg2});
m_mockRouteSync.m_nh_groups.insert({3, group});

m_mockRouteSync.updateNextHopGroup(3);
m_mockRouteSync.installNextHopGroup(3);

auto it = m_mockRouteSync.m_nh_groups.find(3);
ASSERT_NE(it, m_mockRouteSync.m_nh_groups.end());
Expand Down Expand Up @@ -736,7 +736,7 @@ TEST_F(FpmSyncdResponseTest, TestNextHopGroupAdd)
EXPECT_EQ(group[2].second, 3);

// Mark the group as installed and verify DB update
m_mockRouteSync.updateNextHopGroup(group_id);
m_mockRouteSync.installNextHopGroup(group_id);

Table nexthop_group_table(m_db.get(), APP_NEXTHOP_GROUP_TABLE_NAME);
vector<FieldValueTuple> fieldValues;
Expand Down

0 comments on commit ffdd470

Please sign in to comment.