From 8fd0837aee1842ee4f445278b95d83ec52238464 Mon Sep 17 00:00:00 2001 From: Kumaresh Perumal Date: Tue, 14 May 2024 15:58:04 -0700 Subject: [PATCH] Add support for ECMP and LAG hash offset (#3138) * 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 --- orchagent/switchorch.cpp | 31 +++++++++++++++++++++++++++++-- tests/test_switch.py | 23 +++++++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/orchagent/switchorch.cpp b/orchagent/switchorch.cpp index 06dc36e472..cd6def1ebc 100644 --- a/orchagent/switchorch.cpp +++ b/orchagent/switchorch.cpp @@ -31,7 +31,9 @@ const map 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 switch_tunnel_attribute_map = @@ -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: @@ -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(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(value); + } + break; + default: invalid_attr = true; break; } - if (invalid_attr) + if (invalid_attr || unsupported_attr) { /* break from kfvFieldsValues for loop */ break; diff --git a/tests/test_switch.py b/tests/test_switch.py index 93cfd1389c..652fa46573 100644 --- a/tests/test_switch.py +++ b/tests/test_switch.py @@ -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 @@ -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