From c99ec1f80a65f0d4f7c32e792e7dd38775d5c2e9 Mon Sep 17 00:00:00 2001 From: Nazarii Hnydyn Date: Mon, 20 Nov 2023 17:43:58 +0200 Subject: [PATCH] [hash] Add ECMP/LAG Hash Algorithm YANG model (#17079) - Why I did it Added YANG model as part of Generic Hash feature development - How I did it Added YANG model - How to verify it 1. Add UT 2. Verified manually with the feature qualification Signed-off-by: Nazarii Hnydyn --- src/sonic-yang-models/doc/Configuration.md | 6 +++-- .../tests/files/sample_config_db.json | 4 +++- .../tests/yang_model_tests/tests/hash.json | 8 +++++++ .../yang_model_tests/tests_config/hash.json | 22 ++++++++++++++++++- .../yang-models/sonic-hash.yang | 14 ++++++++++++ .../yang-templates/sonic-types.yang.j2 | 13 +++++++++++ 6 files changed, 63 insertions(+), 4 deletions(-) diff --git a/src/sonic-yang-models/doc/Configuration.md b/src/sonic-yang-models/doc/Configuration.md index 33fda784c5..a28ffa5c57 100644 --- a/src/sonic-yang-models/doc/Configuration.md +++ b/src/sonic-yang-models/doc/Configuration.md @@ -1194,7 +1194,7 @@ The FG_NHG_PREFIX table provides the FG_NHG_PREFIX for which FG behavior is desi ### Hash -Generic hash allows user to configure which hash fields are suppose to be used by a hashing algorithm. +Generic hash allows user to configure various aspects of hashing algorithm. The configuration is applied globally for each ECMP and LAG on a switch. ***ECMP/LAG HASH*** @@ -1238,7 +1238,9 @@ The configuration is applied globally for each ECMP and LAG on a switch. "INNER_SRC_IP", "INNER_L4_DST_PORT", "INNER_L4_SRC_PORT" - ] + ], + "ecmp_hash_algorithm": "CRC", + "lag_hash_algorithm": "CRC" } } } diff --git a/src/sonic-yang-models/tests/files/sample_config_db.json b/src/sonic-yang-models/tests/files/sample_config_db.json index b831142ec4..4eba94e72f 100644 --- a/src/sonic-yang-models/tests/files/sample_config_db.json +++ b/src/sonic-yang-models/tests/files/sample_config_db.json @@ -339,7 +339,9 @@ "L4_SRC_PORT", "INNER_DST_IP", "INNER_SRC_IP" - ] + ], + "ecmp_hash_algorithm": "CRC", + "lag_hash_algorithm": "XOR" } }, "DEVICE_METADATA": { diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/hash.json b/src/sonic-yang-models/tests/yang_model_tests/tests/hash.json index 466ef001e6..469abe72f5 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests/hash.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/hash.json @@ -9,5 +9,13 @@ "SWITCH_HASH_INVALID_LAG_HASH": { "desc": "Configure invalid LAG_HASH in SWITCH_HASH.", "eStrKey": "InvalidValue" + }, + "SWITCH_HASH_INVALID_ECMP_HASH_ALGORITHM": { + "desc": "Configure invalid ECMP_HASH_ALGORITHM in SWITCH_HASH.", + "eStrKey": "InvalidValue" + }, + "SWITCH_HASH_INVALID_LAG_HASH_ALGORITHM": { + "desc": "Configure invalid LAG_HASH_ALGORITHM in SWITCH_HASH.", + "eStrKey": "InvalidValue" } } diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/hash.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/hash.json index 67c086f808..e9e3def956 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests_config/hash.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/hash.json @@ -20,7 +20,9 @@ "L4_SRC_PORT", "INNER_DST_IP", "INNER_SRC_IP" - ] + ], + "ecmp_hash_algorithm": "CRC", + "lag_hash_algorithm": "XOR" } } } @@ -46,5 +48,23 @@ } } } + }, + "SWITCH_HASH_INVALID_ECMP_HASH_ALGORITHM": { + "sonic-hash:sonic-hash": { + "sonic-hash:SWITCH_HASH": { + "sonic-hash:GLOBAL": { + "ecmp_hash_algorithm": "INVALID_VALUE" + } + } + } + }, + "SWITCH_HASH_INVALID_LAG_HASH_ALGORITHM": { + "sonic-hash:sonic-hash": { + "sonic-hash:SWITCH_HASH": { + "sonic-hash:GLOBAL": { + "lag_hash_algorithm": "INVALID_VALUE" + } + } + } } } diff --git a/src/sonic-yang-models/yang-models/sonic-hash.yang b/src/sonic-yang-models/yang-models/sonic-hash.yang index 84e87cf243..d95f824069 100644 --- a/src/sonic-yang-models/yang-models/sonic-hash.yang +++ b/src/sonic-yang-models/yang-models/sonic-hash.yang @@ -11,6 +11,10 @@ module sonic-hash { description "HASH YANG Module for SONiC OS"; + revision 2023-09-25 { + description "Added hashing algorithm configuration"; + } + revision 2022-09-05 { description "First Revision"; } @@ -57,6 +61,16 @@ module sonic-hash { type hash:hash-field; } + leaf ecmp_hash_algorithm { + description "Hash algorithm for hashing packets going through ECMP"; + type stypes:hash-algorithm; + } + + leaf lag_hash_algorithm { + description "Hash algorithm for hashing packets going through LAG"; + type stypes:hash-algorithm; + } + } /* end of container GLOBAL */ } diff --git a/src/sonic-yang-models/yang-templates/sonic-types.yang.j2 b/src/sonic-yang-models/yang-templates/sonic-types.yang.j2 index 4a81da6ed3..4007a386b3 100644 --- a/src/sonic-yang-models/yang-templates/sonic-types.yang.j2 +++ b/src/sonic-yang-models/yang-templates/sonic-types.yang.j2 @@ -334,6 +334,19 @@ module sonic-types { } } + typedef hash-algorithm { + description "Represents hash algorithm"; + type enumeration { + enum CRC; + enum XOR; + enum RANDOM; + enum CRC_32LO; + enum CRC_32HI; + enum CRC_CCITT; + enum CRC_XOR; + } + } + typedef timezone-name-type { type string; description