@@ -7,9 +7,15 @@ extern sai_object_id_t gVirtualRouterId;
7
7
8
8
extern sai_next_hop_group_api_t * sai_next_hop_group_api;
9
9
extern sai_route_api_t * sai_route_api;
10
+ extern sai_switch_api_t * sai_switch_api;
10
11
11
12
extern PortsOrch *gPortsOrch ;
12
13
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
+
13
19
RouteOrch::RouteOrch (DBConnector *db, string tableName, NeighOrch *neighOrch) :
14
20
Orch(db, tableName),
15
21
m_neighOrch(neighOrch),
@@ -18,18 +24,48 @@ RouteOrch::RouteOrch(DBConnector *db, string tableName, NeighOrch *neighOrch) :
18
24
{
19
25
SWSS_LOG_ENTER ();
20
26
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
+
21
58
IpPrefix default_ip_prefix (" 0.0.0.0/0" );
22
59
23
60
sai_unicast_route_entry_t unicast_route_entry;
24
61
unicast_route_entry.vr_id = gVirtualRouterId ;
25
62
copy (unicast_route_entry.destination , default_ip_prefix);
26
63
subnet (unicast_route_entry.destination , unicast_route_entry.destination );
27
64
28
- sai_attribute_t attr;
29
65
attr.id = SAI_ROUTE_ATTR_PACKET_ACTION;
30
66
attr.value .s32 = SAI_PACKET_ACTION_DROP;
31
67
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);
33
69
if (status != SAI_STATUS_SUCCESS)
34
70
{
35
71
SWSS_LOG_ERROR (" Failed to create v4 default route with packet action drop" );
@@ -359,9 +395,10 @@ bool RouteOrch::addNextHopGroup(IpAddresses ipAddresses)
359
395
360
396
assert (!hasNextHopGroup (ipAddresses));
361
397
362
- if (m_nextHopGroupCount > NHGRP_MAX_SIZE )
398
+ if (m_nextHopGroupCount >= m_maxNextHopGroupCount )
363
399
{
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." );
365
402
return false ;
366
403
}
367
404
0 commit comments