Skip to content

Commit 15b8a6d

Browse files
committed
update nhg
Signed-off-by: Kanji Nakano <kanji.nakano@ntt.com>
1 parent 8f11ace commit 15b8a6d

2 files changed

Lines changed: 16 additions & 14 deletions

File tree

fpmsyncd/routesync.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,7 +1672,7 @@ void RouteSync::onRouteMsg(int nlmsg_type, struct nl_object *obj, char *vrf)
16721672
const auto itg = m_nh_groups.find(nhg_id);
16731673
if(itg == m_nh_groups.end())
16741674
{
1675-
SWSS_LOG_DEBUG("NextHop group id %d not found. Dropping the route %s", nhg_id, destipprefix);
1675+
SWSS_LOG_ERROR("NextHop group id %d not found. Dropping the route %s", nhg_id, destipprefix);
16761676
return;
16771677
}
16781678
NextHopGroup& nhg = itg->second;
@@ -1866,10 +1866,11 @@ void RouteSync::onNextHopMsg(struct nlmsghdr *h, int len)
18661866
SWSS_LOG_INFO("New nexthop group message!");
18671867
struct nexthop_grp *nha_grp = (struct nexthop_grp *)RTA_DATA(tb[NHA_GROUP]);
18681868
grp_count = (int)(RTA_PAYLOAD(tb[NHA_GROUP]) / sizeof(*nha_grp));
1869-
1870-
if(grp_count > MAX_MULTIPATH_NUM)
1869+
if (grp_count > MAX_MULTIPATH_NUM)
1870+
{
1871+
SWSS_LOG_ERROR("Nexthop group count (%d) exceeds the maximum allowed (%d). Clamping to maximum.", grp_count, MAX_MULTIPATH_NUM);
18711872
grp_count = MAX_MULTIPATH_NUM;
1872-
1873+
}
18731874
for (int i = 0; i < grp_count; i++) {
18741875
grp[i].id = nha_grp[i].id;
18751876
/*
@@ -1917,19 +1918,20 @@ void RouteSync::onNextHopMsg(struct nlmsghdr *h, int len)
19171918
}
19181919
}
19191920
}
1920-
if(grp_count)
1921+
if (grp_count > 0)
19211922
{
1922-
vector<pair<uint32_t,uint8_t>> group;
1923-
for(int i = 0; i < grp_count; i++)
1923+
vector<pair<uint32_t, uint8_t>> group(grp_count);
1924+
for (int i = 0; i < grp_count; i++)
19241925
{
1925-
group.push_back(std::make_pair(grp[i].id, grp[i].weight));
1926+
group[i] = std::make_pair(grp[i].id, grp[i].weight);
19261927
}
1928+
19271929
auto it = m_nh_groups.find(id);
1928-
if(it != m_nh_groups.end())
1930+
if (it != m_nh_groups.end())
19291931
{
19301932
NextHopGroup &nhg = it->second;
19311933
nhg.group = group;
1932-
if(nhg.installed)
1934+
if (nhg.installed)
19331935
{
19341936
updateNextHopGroupDb(nhg);
19351937
}
@@ -2630,7 +2632,7 @@ void RouteSync::onWarmStartEnd(DBConnector& applStateDb)
26302632
*/
26312633
const string RouteSync::getNextHopGroupKeyAsString(uint32_t id) const
26322634
{
2633-
return string("ID") + to_string(id);
2635+
return to_string(id);
26342636
}
26352637

26362638
/*

tests/mock_tests/fpmsyncd/test_routesync.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ TEST_F(FpmSyncdResponseTest, TestIPv6NextHopAdd)
381381
Table nexthop_group_table(m_db.get(), APP_NEXTHOP_GROUP_TABLE_NAME);
382382

383383
vector<FieldValueTuple> fieldValues;
384-
string key = "ID" + to_string(test_id);
384+
string key = to_string(test_id);
385385
nexthop_group_table.get(key, fieldValues);
386386

387387
// onNextHopMsg only updates m_nh_groups unless the nhg is marked as installed
@@ -452,8 +452,8 @@ TEST_F(FpmSyncdResponseTest, TestSkipSpecialInterfaces)
452452

453453
TEST_F(FpmSyncdResponseTest, TestNextHopGroupKeyString)
454454
{
455-
EXPECT_EQ(m_mockRouteSync.getNextHopGroupKeyAsString(1), "ID1");
456-
EXPECT_EQ(m_mockRouteSync.getNextHopGroupKeyAsString(1234), "ID1234");
455+
EXPECT_EQ(m_mockRouteSync.getNextHopGroupKeyAsString(1), "1");
456+
EXPECT_EQ(m_mockRouteSync.getNextHopGroupKeyAsString(1234), "1234");
457457
}
458458

459459
TEST_F(FpmSyncdResponseTest, TestGetNextHopGroupFields)

0 commit comments

Comments
 (0)