Skip to content

Commit

Permalink
Add support for ECMP and LAG hash offset (#3138)
Browse files Browse the repository at this point in the history
* Add support for ECMP and LAG hash offset
What I did
Add support to update ECMP and LAG hash offset. Orchagent checks for SAI attribute capability and configure the offset values.

Why I did it
To avoid ECMP hash imbalance across T0 and T1s, different hash offsets can be configured.

How I verified it
sonic-mgmt tests ipfwd/test_nhop_group.py
  • Loading branch information
kperumalbfn authored and mssonicbld committed Jul 3, 2024
1 parent 66b9dac commit 8fd0837
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
31 changes: 29 additions & 2 deletions orchagent/switchorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ const map<string, sai_switch_attr_t> switch_attribute_map =
{"fdb_aging_time", SAI_SWITCH_ATTR_FDB_AGING_TIME},
{"debug_shell_enable", SAI_SWITCH_ATTR_SWITCH_SHELL_ENABLE},
{"vxlan_port", SAI_SWITCH_ATTR_VXLAN_DEFAULT_PORT},
{"vxlan_router_mac", SAI_SWITCH_ATTR_VXLAN_DEFAULT_ROUTER_MAC}
{"vxlan_router_mac", SAI_SWITCH_ATTR_VXLAN_DEFAULT_ROUTER_MAC},
{"ecmp_hash_offset", SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_OFFSET},
{"lag_hash_offset", SAI_SWITCH_ATTR_LAG_DEFAULT_HASH_OFFSET}
};

const map<string, sai_switch_tunnel_attr_t> switch_tunnel_attribute_map =
Expand Down Expand Up @@ -401,6 +403,8 @@ void SwitchOrch::doAppSwitchTableTask(Consumer &consumer)

MacAddress mac_addr;
bool invalid_attr = false;
bool ret = false;
bool unsupported_attr = false;
switch (attr.id)
{
case SAI_SWITCH_ATTR_FDB_UNICAST_MISS_PACKET_ACTION:
Expand Down Expand Up @@ -438,11 +442,34 @@ void SwitchOrch::doAppSwitchTableTask(Consumer &consumer)
memcpy(attr.value.mac, mac_addr.getMac(), sizeof(sai_mac_t));
break;

case SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_OFFSET:
ret = querySwitchCapability(SAI_OBJECT_TYPE_SWITCH, SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_OFFSET);
if (ret == false)
{
unsupported_attr = true;
}
else
{
attr.value.u8 = to_uint<uint8_t>(value);
}
break;
case SAI_SWITCH_ATTR_LAG_DEFAULT_HASH_OFFSET:
ret = querySwitchCapability(SAI_OBJECT_TYPE_SWITCH, SAI_SWITCH_ATTR_LAG_DEFAULT_HASH_OFFSET);
if (ret == false)
{
unsupported_attr = true;
}
else
{
attr.value.u8 = to_uint<uint8_t>(value);
}
break;

default:
invalid_attr = true;
break;
}
if (invalid_attr)
if (invalid_attr || unsupported_attr)
{
/* break from kfvFieldsValues for loop */
break;
Expand Down
23 changes: 23 additions & 0 deletions tests/test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,27 @@ def vxlan_switch_test(dvs, oid, port, mac, mask, sport):
)


def ecmp_lag_hash_offset_test(dvs, oid, lag_offset, ecmp_offset):
app_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0)
create_entry_pst(
app_db,
"SWITCH_TABLE", ':', "switch",
[
("ecmp_hash_offset", ecmp_offset),
("lag_hash_offset", lag_offset)
],
)
time.sleep(2)

asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0)
check_object(asic_db, "ASIC_STATE:SAI_OBJECT_TYPE_SWITCH", oid,
{
'SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_OFFSET': ecmp_offset,
'SAI_SWITCH_ATTR_LAG_DEFAULT_HASH_OFFSET': lag_offset,
}
)


class TestSwitch(object):
'''
Test- Check switch attributes
Expand All @@ -75,6 +96,8 @@ def test_switch_attribute(self, dvs, testlog):

vxlan_switch_test(dvs, switch_oid, "56789", "00:0A:0B:0C:0D:0E", "15", "56789")

ecmp_lag_hash_offset_test(dvs, switch_oid, "10", "10")


# Add Dummy always-pass test at end as workaroud
# for issue when Flaky fail on final test it invokes module tear-down before retrying
Expand Down

0 comments on commit 8fd0837

Please sign in to comment.