Skip to content

Commit

Permalink
[orchagent]: Add query of NUMBER_OF_ECMP_GROUPS in routeorch (sonic-n…
Browse files Browse the repository at this point in the history
…et#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.
  • Loading branch information
Shuotian Cheng authored Apr 19, 2017
1 parent b697f3b commit 5ae03ed
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
45 changes: 41 additions & 4 deletions orchagent/routeorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ extern sai_object_id_t gVirtualRouterId;

extern sai_next_hop_group_api_t* sai_next_hop_group_api;
extern sai_route_api_t* sai_route_api;
extern sai_switch_api_t* sai_switch_api;

extern PortsOrch *gPortsOrch;

/* Default maximum number of next hop groups */
#define DEFAULT_NUMBER_OF_ECMP_GROUPS 128
#define DEFAULT_MAX_ECMP_GROUP_SIZE 32
#define MLNX_PLATFORM_SUBSTRING "mlnx"

RouteOrch::RouteOrch(DBConnector *db, string tableName, NeighOrch *neighOrch) :
Orch(db, tableName),
m_neighOrch(neighOrch),
Expand All @@ -18,18 +24,48 @@ RouteOrch::RouteOrch(DBConnector *db, string tableName, NeighOrch *neighOrch) :
{
SWSS_LOG_ENTER();

sai_attribute_t attr;
attr.id = SAI_SWITCH_ATTR_NUMBER_OF_ECMP_GROUPS;

sai_status_t status = sai_switch_api->get_switch_attribute(1, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_WARN("Failed to get switch attribute number of ECMP groups. \
Use default value. rv:%d", status);
m_maxNextHopGroupCount = DEFAULT_NUMBER_OF_ECMP_GROUPS;
}
else
{
m_maxNextHopGroupCount = attr.value.s32;

/*
* ASIC specific workaround to re-calculate maximum ECMP groups
* according to diferent ECMP mode used.
*
* On Mellanox platform, the maximum ECMP groups returned is the value
* under the condition that the ECMP group size is 1. Deviding this
* number by DEFAULT_MAX_ECMP_GROUP_SIZE gets the maximum number of
* ECMP groups when the maximum ECMP group size is 32.
*/
char *platform = getenv("platform");
if (platform && strstr(platform, MLNX_PLATFORM_SUBSTRING))
{
m_maxNextHopGroupCount /= DEFAULT_MAX_ECMP_GROUP_SIZE;
}
}
SWSS_LOG_NOTICE("Maximum number of ECMP groups supported is %d", m_maxNextHopGroupCount);

IpPrefix default_ip_prefix("0.0.0.0/0");

sai_unicast_route_entry_t unicast_route_entry;
unicast_route_entry.vr_id = gVirtualRouterId;
copy(unicast_route_entry.destination, default_ip_prefix);
subnet(unicast_route_entry.destination, unicast_route_entry.destination);

sai_attribute_t attr;
attr.id = SAI_ROUTE_ATTR_PACKET_ACTION;
attr.value.s32 = SAI_PACKET_ACTION_DROP;

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

assert(!hasNextHopGroup(ipAddresses));

if (m_nextHopGroupCount > NHGRP_MAX_SIZE)
if (m_nextHopGroupCount >= m_maxNextHopGroupCount)
{
SWSS_LOG_DEBUG("Failed to create next hop group. Exceeding maximum number of next hop groups.\n");
SWSS_LOG_DEBUG("Failed to create new next hop group. \
Reaching maximum number of next hop groups.");
return false;
}

Expand Down
4 changes: 1 addition & 3 deletions orchagent/routeorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
using namespace std;
using namespace swss;

/* Maximum next hop group number */
#define NHGRP_MAX_SIZE 128

struct NextHopGroupEntry
{
sai_object_id_t next_hop_group_id; // next hop group id
Expand Down Expand Up @@ -59,6 +56,7 @@ class RouteOrch : public Orch, public Subject
NeighOrch *m_neighOrch;

int m_nextHopGroupCount;
int m_maxNextHopGroupCount;
bool m_resync;

RouteTable m_syncdRoutes;
Expand Down

0 comments on commit 5ae03ed

Please sign in to comment.