Skip to content

Commit 5ae03ed

Browse files
author
Shuotian Cheng
authored
[orchagent]: Add query of NUMBER_OF_ECMP_GROUPS in routeorch (sonic-net#194)
* [orchagent]: Add query of NUMBER_OF_ECMP_GROUPS in routeorch Instead of using the default value of 128, query the switch first to get the NUMBER_OF_ECMP_GROUPS and use this value as the maximum supported number of next hop groups. If the query fails, the default value of 128 will be used. Also fix the corner case by changing '>' to '>=' when checking the number of next hop groups.
1 parent b697f3b commit 5ae03ed

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

orchagent/routeorch.cpp

+41-4
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@ extern sai_object_id_t gVirtualRouterId;
77

88
extern sai_next_hop_group_api_t* sai_next_hop_group_api;
99
extern sai_route_api_t* sai_route_api;
10+
extern sai_switch_api_t* sai_switch_api;
1011

1112
extern PortsOrch *gPortsOrch;
1213

14+
/* Default maximum number of next hop groups */
15+
#define DEFAULT_NUMBER_OF_ECMP_GROUPS 128
16+
#define DEFAULT_MAX_ECMP_GROUP_SIZE 32
17+
#define MLNX_PLATFORM_SUBSTRING "mlnx"
18+
1319
RouteOrch::RouteOrch(DBConnector *db, string tableName, NeighOrch *neighOrch) :
1420
Orch(db, tableName),
1521
m_neighOrch(neighOrch),
@@ -18,18 +24,48 @@ RouteOrch::RouteOrch(DBConnector *db, string tableName, NeighOrch *neighOrch) :
1824
{
1925
SWSS_LOG_ENTER();
2026

27+
sai_attribute_t attr;
28+
attr.id = SAI_SWITCH_ATTR_NUMBER_OF_ECMP_GROUPS;
29+
30+
sai_status_t status = sai_switch_api->get_switch_attribute(1, &attr);
31+
if (status != SAI_STATUS_SUCCESS)
32+
{
33+
SWSS_LOG_WARN("Failed to get switch attribute number of ECMP groups. \
34+
Use default value. rv:%d", status);
35+
m_maxNextHopGroupCount = DEFAULT_NUMBER_OF_ECMP_GROUPS;
36+
}
37+
else
38+
{
39+
m_maxNextHopGroupCount = attr.value.s32;
40+
41+
/*
42+
* ASIC specific workaround to re-calculate maximum ECMP groups
43+
* according to diferent ECMP mode used.
44+
*
45+
* On Mellanox platform, the maximum ECMP groups returned is the value
46+
* under the condition that the ECMP group size is 1. Deviding this
47+
* number by DEFAULT_MAX_ECMP_GROUP_SIZE gets the maximum number of
48+
* ECMP groups when the maximum ECMP group size is 32.
49+
*/
50+
char *platform = getenv("platform");
51+
if (platform && strstr(platform, MLNX_PLATFORM_SUBSTRING))
52+
{
53+
m_maxNextHopGroupCount /= DEFAULT_MAX_ECMP_GROUP_SIZE;
54+
}
55+
}
56+
SWSS_LOG_NOTICE("Maximum number of ECMP groups supported is %d", m_maxNextHopGroupCount);
57+
2158
IpPrefix default_ip_prefix("0.0.0.0/0");
2259

2360
sai_unicast_route_entry_t unicast_route_entry;
2461
unicast_route_entry.vr_id = gVirtualRouterId;
2562
copy(unicast_route_entry.destination, default_ip_prefix);
2663
subnet(unicast_route_entry.destination, unicast_route_entry.destination);
2764

28-
sai_attribute_t attr;
2965
attr.id = SAI_ROUTE_ATTR_PACKET_ACTION;
3066
attr.value.s32 = SAI_PACKET_ACTION_DROP;
3167

32-
sai_status_t status = sai_route_api->create_route(&unicast_route_entry, 1, &attr);
68+
status = sai_route_api->create_route(&unicast_route_entry, 1, &attr);
3369
if (status != SAI_STATUS_SUCCESS)
3470
{
3571
SWSS_LOG_ERROR("Failed to create v4 default route with packet action drop");
@@ -359,9 +395,10 @@ bool RouteOrch::addNextHopGroup(IpAddresses ipAddresses)
359395

360396
assert(!hasNextHopGroup(ipAddresses));
361397

362-
if (m_nextHopGroupCount > NHGRP_MAX_SIZE)
398+
if (m_nextHopGroupCount >= m_maxNextHopGroupCount)
363399
{
364-
SWSS_LOG_DEBUG("Failed to create next hop group. Exceeding maximum number of next hop groups.\n");
400+
SWSS_LOG_DEBUG("Failed to create new next hop group. \
401+
Reaching maximum number of next hop groups.");
365402
return false;
366403
}
367404

orchagent/routeorch.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
using namespace std;
1616
using namespace swss;
1717

18-
/* Maximum next hop group number */
19-
#define NHGRP_MAX_SIZE 128
20-
2118
struct NextHopGroupEntry
2219
{
2320
sai_object_id_t next_hop_group_id; // next hop group id
@@ -59,6 +56,7 @@ class RouteOrch : public Orch, public Subject
5956
NeighOrch *m_neighOrch;
6057

6158
int m_nextHopGroupCount;
59+
int m_maxNextHopGroupCount;
6260
bool m_resync;
6361

6462
RouteTable m_syncdRoutes;

0 commit comments

Comments
 (0)