Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions src/sonic-yang-models/doc/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -935,6 +936,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

```
Expand Down
2 changes: 2 additions & 0 deletions src/sonic-yang-models/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def run(self):
'./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',
Expand Down Expand Up @@ -199,6 +200,7 @@ def run(self):
'./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',
Expand Down
22 changes: 22 additions & 0 deletions src/sonic-yang-models/tests/files/sample_config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 13 additions & 0 deletions src/sonic-yang-models/tests/yang_model_tests/tests/hash.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
}
}
}
67 changes: 67 additions & 0 deletions src/sonic-yang-models/yang-models/sonic-hash.yang
Original file line number Diff line number Diff line change
@@ -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 */
6 changes: 5 additions & 1 deletion src/sonic-yang-models/yang-models/sonic-pbh.yang
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ module sonic-pbh {
prefix inet;
}

import sonic-types {
prefix stypes;
}

import sonic-port {
prefix port;
}
Expand All @@ -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;
Expand Down
28 changes: 27 additions & 1 deletion src/sonic-yang-models/yang-templates/sonic-types.yang.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down