From 7cedb09c96327153b557c3755c554e2680001a01 Mon Sep 17 00:00:00 2001 From: Nazarii Hnydyn Date: Mon, 6 Feb 2023 11:14:47 +0200 Subject: [PATCH] [hash] Add Generic Hash YANG model (#13253) - Why I did it Added YANG model as part of Generic Hash feature development - How I did it Added YANG model and UTs - How to verify it make configure PLATFORM=mellanox make target/sonic-mellanox.bin Signed-off-by: Nazarii Hnydyn --- src/sonic-yang-models/doc/Configuration.md | 53 +++++++++++++++ src/sonic-yang-models/setup.py | 2 + .../tests/files/sample_config_db.json | 22 ++++++ .../tests/yang_model_tests/tests/hash.json | 13 ++++ .../yang_model_tests/tests_config/hash.json | 50 ++++++++++++++ .../yang-models/sonic-hash.yang | 67 +++++++++++++++++++ .../yang-models/sonic-pbh.yang | 6 +- .../yang-templates/sonic-types.yang.j2 | 28 +++++++- 8 files changed, 239 insertions(+), 2 deletions(-) create mode 100644 src/sonic-yang-models/tests/yang_model_tests/tests/hash.json create mode 100644 src/sonic-yang-models/tests/yang_model_tests/tests_config/hash.json create mode 100644 src/sonic-yang-models/yang-models/sonic-hash.yang diff --git a/src/sonic-yang-models/doc/Configuration.md b/src/sonic-yang-models/doc/Configuration.md index d2227adb27..69610f4f46 100644 --- a/src/sonic-yang-models/doc/Configuration.md +++ b/src/sonic-yang-models/doc/Configuration.md @@ -27,6 +27,7 @@ Table of Contents * [Device neighbor metada](#device-neighbor-metada) * [DSCP_TO_TC_MAP](#dscp_to_tc_map) * [FLEX_COUNTER_TABLE](#flex_counter_table) + * [Hash](#hash) * [KDUMP](#kdump) * [Kubernetes Master](#kubernetes-master) * [L2 Neighbors](#l2-neighbors) @@ -936,6 +937,58 @@ instance is supported in SONiC. ``` +### Hash + +Generic hash allows user to configure which hash fields are suppose to be used by a hashing algorithm. +The configuration is applied globally for each ECMP and LAG on a switch. + +***ECMP/LAG HASH*** + +``` +{ + "SWITCH_HASH": { + "GLOBAL": { + "ecmp_hash": [ + "DST_MAC", + "SRC_MAC", + "ETHERTYPE", + "IP_PROTOCOL", + "DST_IP", + "SRC_IP", + "L4_DST_PORT", + "L4_SRC_PORT", + "INNER_DST_MAC", + "INNER_SRC_MAC", + "INNER_ETHERTYPE", + "INNER_IP_PROTOCOL", + "INNER_DST_IP", + "INNER_SRC_IP", + "INNER_L4_DST_PORT", + "INNER_L4_SRC_PORT" + ], + "lag_hash": [ + "DST_MAC", + "SRC_MAC", + "ETHERTYPE", + "IP_PROTOCOL", + "DST_IP", + "SRC_IP", + "L4_DST_PORT", + "L4_SRC_PORT", + "INNER_DST_MAC", + "INNER_SRC_MAC", + "INNER_ETHERTYPE", + "INNER_IP_PROTOCOL", + "INNER_DST_IP", + "INNER_SRC_IP", + "INNER_L4_DST_PORT", + "INNER_L4_SRC_PORT" + ] + } + } +} +``` + ### KDUMP ``` diff --git a/src/sonic-yang-models/setup.py b/src/sonic-yang-models/setup.py index 69b27bc90f..2afc3c85f0 100644 --- a/src/sonic-yang-models/setup.py +++ b/src/sonic-yang-models/setup.py @@ -116,6 +116,7 @@ setup( './yang-models/sonic-extension.yang', './yang-models/sonic-flex_counter.yang', './yang-models/sonic-feature.yang', + './yang-models/sonic-hash.yang', './yang-models/sonic-system-defaults.yang', './yang-models/sonic-interface.yang', './yang-models/sonic-kdump.yang', @@ -200,6 +201,7 @@ setup( './cvlyang-models/sonic-extension.yang', './cvlyang-models/sonic-flex_counter.yang', './cvlyang-models/sonic-feature.yang', + './cvlyang-models/sonic-hash.yang', './cvlyang-models/sonic-system-defaults.yang', './cvlyang-models/sonic-interface.yang', './cvlyang-models/sonic-kdump.yang', 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 57a95d867c..f9945175cf 100644 --- a/src/sonic-yang-models/tests/files/sample_config_db.json +++ b/src/sonic-yang-models/tests/files/sample_config_db.json @@ -324,6 +324,28 @@ "AETH_SYNDROME": "0x60/0x60" } }, + "SWITCH_HASH": { + "GLOBAL": { + "ecmp_hash": [ + "DST_IP", + "SRC_IP", + "IP_PROTOCOL", + "L4_DST_PORT", + "L4_SRC_PORT", + "INNER_DST_IP", + "INNER_SRC_IP" + ], + "lag_hash": [ + "DST_IP", + "SRC_IP", + "IP_PROTOCOL", + "L4_DST_PORT", + "L4_SRC_PORT", + "INNER_DST_IP", + "INNER_SRC_IP" + ] + } + }, "DEVICE_METADATA": { "localhost": { "type": "ToRRouter", 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 new file mode 100644 index 0000000000..466ef001e6 --- /dev/null +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/hash.json @@ -0,0 +1,13 @@ +{ + "SWITCH_HASH_VALID": { + "desc": "Configure SWITCH_HASH." + }, + "SWITCH_HASH_INVALID_ECMP_HASH": { + "desc": "Configure invalid ECMP_HASH in SWITCH_HASH.", + "eStrKey": "InvalidValue" + }, + "SWITCH_HASH_INVALID_LAG_HASH": { + "desc": "Configure invalid LAG_HASH 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 new file mode 100644 index 0000000000..67c086f808 --- /dev/null +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/hash.json @@ -0,0 +1,50 @@ +{ + "SWITCH_HASH_VALID": { + "sonic-hash:sonic-hash": { + "sonic-hash:SWITCH_HASH": { + "sonic-hash:GLOBAL": { + "ecmp_hash": [ + "DST_IP", + "SRC_IP", + "IP_PROTOCOL", + "L4_DST_PORT", + "L4_SRC_PORT", + "INNER_DST_IP", + "INNER_SRC_IP" + ], + "lag_hash": [ + "DST_IP", + "SRC_IP", + "IP_PROTOCOL", + "L4_DST_PORT", + "L4_SRC_PORT", + "INNER_DST_IP", + "INNER_SRC_IP" + ] + } + } + } + }, + "SWITCH_HASH_INVALID_ECMP_HASH": { + "sonic-hash:sonic-hash": { + "sonic-hash:SWITCH_HASH": { + "sonic-hash:GLOBAL": { + "ecmp_hash": [ + "INVALID_VALUE" + ] + } + } + } + }, + "SWITCH_HASH_INVALID_LAG_HASH": { + "sonic-hash:sonic-hash": { + "sonic-hash:SWITCH_HASH": { + "sonic-hash:GLOBAL": { + "lag_hash": [ + "INVALID_VALUE" + ] + } + } + } + } +} diff --git a/src/sonic-yang-models/yang-models/sonic-hash.yang b/src/sonic-yang-models/yang-models/sonic-hash.yang new file mode 100644 index 0000000000..84e87cf243 --- /dev/null +++ b/src/sonic-yang-models/yang-models/sonic-hash.yang @@ -0,0 +1,67 @@ +module sonic-hash { + + yang-version 1.1; + + namespace "http://github.com/sonic-net/sonic-hash"; + prefix hash; + + import sonic-types { + prefix stypes; + } + + description "HASH YANG Module for SONiC OS"; + + revision 2022-09-05 { + description "First Revision"; + } + + typedef hash-field { + description "Represents native hash field"; + type stypes:hash-field { + enum IN_PORT; + enum DST_MAC; + enum SRC_MAC; + enum ETHERTYPE; + enum VLAN_ID; + enum IP_PROTOCOL; + enum DST_IP; + enum SRC_IP; + enum L4_DST_PORT; + enum L4_SRC_PORT; + enum INNER_DST_MAC; + enum INNER_SRC_MAC; + enum INNER_ETHERTYPE; + enum INNER_IP_PROTOCOL; + enum INNER_DST_IP; + enum INNER_SRC_IP; + enum INNER_L4_DST_PORT; + enum INNER_L4_SRC_PORT; + } + } + + container sonic-hash { + + container SWITCH_HASH { + + description "SWITCH_HASH part of config_db.json"; + + container GLOBAL { + + leaf-list ecmp_hash { + description "Hash fields for hashing packets going through ECMP"; + type hash:hash-field; + } + + leaf-list lag_hash { + description "Hash fields for hashing packets going through LAG"; + type hash:hash-field; + } + + } + /* end of container GLOBAL */ + } + /* end of container SWITCH_HASH */ + } + /* end of container sonic-hash */ +} +/* end of module sonic-hash */ diff --git a/src/sonic-yang-models/yang-models/sonic-pbh.yang b/src/sonic-yang-models/yang-models/sonic-pbh.yang index 54c728a939..d0c395d4e6 100644 --- a/src/sonic-yang-models/yang-models/sonic-pbh.yang +++ b/src/sonic-yang-models/yang-models/sonic-pbh.yang @@ -9,6 +9,10 @@ module sonic-pbh { prefix inet; } + import sonic-types { + prefix stypes; + } + import sonic-port { prefix port; } @@ -25,7 +29,7 @@ module sonic-pbh { typedef hash-field { description "Represents native hash field"; - type enumeration { + type stypes:hash-field { enum INNER_IP_PROTOCOL; enum INNER_L4_DST_PORT; enum INNER_L4_SRC_PORT; 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 498abb3aae..ee26a7d67b 100644 --- a/src/sonic-yang-models/yang-templates/sonic-types.yang.j2 +++ b/src/sonic-yang-models/yang-templates/sonic-types.yang.j2 @@ -305,7 +305,33 @@ module sonic-types { } } - + typedef hash-field { + description "Represents native hash field"; + type enumeration { + enum IN_PORT; + enum DST_MAC; + enum SRC_MAC; + enum ETHERTYPE; + enum VLAN_ID; + enum IP_PROTOCOL; + enum DST_IP; + enum SRC_IP; + enum L4_DST_PORT; + enum L4_SRC_PORT; + enum INNER_DST_MAC; + enum INNER_SRC_MAC; + enum INNER_ETHERTYPE; + enum INNER_IP_PROTOCOL; + enum INNER_DST_IP; + enum INNER_DST_IPV4; + enum INNER_DST_IPV6; + enum INNER_SRC_IP; + enum INNER_SRC_IPV4; + enum INNER_SRC_IPV6; + enum INNER_L4_DST_PORT; + enum INNER_L4_SRC_PORT; + } + } {% if yang_model_type == "cvl" %} /* Required for CVL */