Skip to content

Commit 59e4d57

Browse files
Round-robin Hash Algorithm (#2078)
Signed-off-by: dkadia-marvell <dkadia@marvell.com>
1 parent 1784b9f commit 59e4d57

9 files changed

Lines changed: 259 additions & 2 deletions
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
# [SAI] Round-robin Hash Algorithm
2+
-------------------------------------------------------------------------------
3+
Title | Round-robin Hash Algorithm
4+
-------------|-----------------------------------------------------------------
5+
Authors | Dhruvkumar Kadia, Ravindranath C K (Marvell)
6+
Status | In review
7+
Type | Standards track
8+
Created | 2024-09-19
9+
SAI-Version | 1.16
10+
-------------------------------------------------------------------------------
11+
12+
## 1.0 Introduction
13+
14+
ECMP or Next hop groups (NHG) and LAG use load balancing techniques to spread the traffic across the various members. The most common load balancing technique is to use hash-based member selection. In this technique, flows are identified by performing a hash on a set of packet fields like the 5-tuple, and then selecting the group member based on the computed hash value.
15+
This technique has been traditionally used since it:
16+
1) ensures packet ordering (since packets of a given flow are always sent out on the same member), and
17+
2) is stateless.
18+
19+
This proposal introduces the new hash algorithm Round-robin.
20+
21+
## 2.0 Behavior
22+
23+
### Existing hash based member selection
24+
For every packet hitting the ECMP/LAG, the egress member is selected based on the computed hash value.
25+
![Hash based member selection](figures/Hash_based.png)
26+
27+
### Existing random member selection
28+
For every packet hitting the ECMP/LAG, the egress member is randomly selected.
29+
![Random member selection](figures/Random.png)
30+
31+
Unlike ARS modes like SAI_ARS_MODE_PER_PACKET_RANDOM, the static member selection modes do not adapt based on the member link status.
32+
33+
### Round-robin member selection
34+
For every packet hitting the ECMP/LAG, the egress member is selected in round robin mode.
35+
![Round-robin member selection](figures/Round_robin.png)
36+
37+
#### Interaction with weighted ECMP
38+
For every packet hitting the ECMP/LAG, the egress member is selected in round robin mode considering the weights of member.
39+
![Round-robin member selection with weighted ecmp](figures/Round_robin_with_weights.png)
40+
41+
## 3.0 SAI Enhancement
42+
43+
A new enums are added to the sai_hash_algorithm_t
44+
New attributes are introduced in the NHG and LAG to allow the user to configure hash algorithm.
45+
Further, an ACL action is introduced to set the hash algorithm.
46+
47+
1) Enum defining the hash algorithm none and round-robin :
48+
```c
49+
/**
50+
* @brief Attribute data for #SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_ALGORITHM
51+
* and #SAI_SWITCH_ATTR_LAG_DEFAULT_HASH_ALGORITHM
52+
*/
53+
typedef enum _sai_hash_algorithm_t
54+
{
55+
...
56+
/** Hash algorithm not set */
57+
SAI_HASH_ALGORITHM_NONE = 7,
58+
59+
/** Round-robin based hash algorithm (per-packet round-robin spraying) */
60+
SAI_HASH_ALGORITHM_ROUND_ROBIN = 8,
61+
62+
} sai_hash_algorithm_t;
63+
```
64+
2) Attributes for ECMP and LAG to set the hash algorithm:
65+
```c
66+
/**
67+
* @brief Attribute id for next hop
68+
*/
69+
typedef enum _sai_next_hop_group_attr_t
70+
{
71+
...
72+
/**
73+
* @brief Next hop group hash algorithm
74+
* Overrides value of SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_ALGORITHM if not set to SAI_HASH_ALGORITHM_NONE
75+
*
76+
* @type sai_hash_algorithm_t
77+
* @flags CREATE_ONLY
78+
* @default SAI_HASH_ALGORITHM_NONE
79+
* @validonly SAI_NEXT_HOP_GROUP_ATTR_TYPE == SAI_NEXT_HOP_GROUP_TYPE_DYNAMIC_UNORDERED_ECMP or SAI_NEXT_HOP_GROUP_ATTR_TYPE == SAI_NEXT_HOP_GROUP_TYPE_DYNAMIC_ORDERED_ECMP
80+
*/
81+
SAI_NEXT_HOP_GROUP_ATTR_HASH_ALGORITHM,
82+
...
83+
} sai_next_hop_group_attr_t;
84+
```
85+
86+
```c
87+
/**
88+
* @brief LAG attribute: List of attributes for LAG object
89+
*/
90+
typedef enum _sai_lag_attr_t
91+
{
92+
...
93+
/**
94+
* @brief LAG hash algorithm
95+
* Overrides value of SAI_SWITCH_ATTR_LAG_DEFAULT_HASH_ALGORITHM if not set to SAI_HASH_ALGORITHM_NONE
96+
*
97+
* @type sai_hash_algorithm_t
98+
* @flags CREATE_ONLY
99+
* @default SAI_HASH_ALGORITHM_NONE
100+
*/
101+
SAI_LAG_ATTR_HASH_ALGORITHM,
102+
...
103+
} sai_lag_attr_t;
104+
```
105+
3) ACL action:
106+
```c
107+
/**
108+
* @brief ACL Action Type
109+
*/
110+
typedef enum _sai_acl_action_type_t
111+
{
112+
...
113+
/** Set ECMP hash algorithm */
114+
SAI_ACL_ACTION_TYPE_SET_ECMP_HASH_ALGORITHM = 0x0000003c,
115+
116+
} sai_acl_action_type_t;
117+
118+
/**
119+
* @brief Attribute Id for sai_acl_entry
120+
*
121+
* @flags ranges
122+
*/
123+
typedef enum _sai_acl_entry_attr_t
124+
{
125+
...
126+
/**
127+
* @brief Set ECMP hash algorithm
128+
*
129+
* @type sai_acl_action_data_t sai_hash_algorithm_t
130+
* @flags CREATE_AND_SET
131+
* @default disabled
132+
*/
133+
SAI_ACL_ENTRY_ATTR_ACTION_SET_ECMP_HASH_ALGORITHM = SAI_ACL_ENTRY_ATTR_ACTION_START + 0x3c,
134+
135+
/**
136+
* @brief End of Rule Actions
137+
*/
138+
SAI_ACL_ENTRY_ATTR_ACTION_END = SAI_ACL_ENTRY_ATTR_ACTION_SET_ECMP_HASH_ALGORITHM,
139+
...
140+
} sai_acl_entry_attr_t;
141+
```
142+
143+
## 4.0 API Example
144+
145+
### Create Switch
146+
```c
147+
...(Existing Attribute)
148+
sai_attr_list[attr_count].id = SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_ALGORITHM;
149+
sai_attr_list[attr_count++].value.u32 = SAI_HASH_ALGORITHM_RANDOM;
150+
sai_create_switch_fn(
151+
&switch_id,
152+
attr_count,
153+
sai_attr_list);
154+
```
155+
156+
### Create Next Hop Group
157+
158+
```c
159+
...(Existing Attribute)
160+
sai_attr_list[attr_count].id = SAI_NEXT_HOP_GROUP_ATTR_HASH_ALGORITHM;
161+
sai_attr_list[attr_count++].value.u32 = SAI_HASH_ALGORITHM_ROUND_ROBIN;
162+
163+
sai_create_next_hop_group_fn(
164+
&nhg_oid,
165+
switch_id,
166+
attr_count,
167+
sai_attr_list);
168+
```
169+
170+
### Create LAG
171+
172+
```c
173+
...(Existing Attribute)
174+
sai_attr_list[attr_count].id = SAI_LAG_ATTR_HASH_ALGORITHM;
175+
sai_attr_list[attr_count++].value.u32 = SAI_HASH_ALGORITHM_ROUND_ROBIN;
176+
177+
sai_create_lag_fn(
178+
&lag_oid,
179+
switch_id,
180+
attr_count,
181+
sai_attr_list);
182+
```
183+
### Create ACL table
184+
```c
185+
count = 0;
186+
sai_attr_list[count].id = SAI_ACL_TABLE_ATTR_ACL_STAGE;
187+
sai_attr_list[count++].value.u32 = SAI_ACL_STAGE_INGRESS;
188+
sai_attr_list[count].id = SAI_ACL_TABLE_ATTR_FIELD_DST_IP;
189+
sai_attr_list[count++].value.booldata = 1;
190+
action_attr_list[0] = SAI_ACL_ACTION_TYPE_SET_ECMP_HASH_ALGORITHM;
191+
sai_action_attr_list.list = action_attr_list;
192+
sai_action_attr_list.count = 1;
193+
sai_attr_list[count].id = SAI_ACL_TABLE_ATTR_ACL_ACTION_TYPE_LIST;
194+
sai_attr_list[count++].value.s32list = sai_action_attr_list;
195+
attr_count = count;
196+
sai_create_acl_table_fn(
197+
&acl_table_id,
198+
switch_id,
199+
attr_count,
200+
sai_attr_list);
201+
```
202+
203+
### Create ACL entry
204+
```c
205+
count=0;
206+
sai_attr_list[count].id = SAI_ACL_ENTRY_ATTR_TABLE_ID;
207+
sai_attr_list[count++].value.oid = acl_table_id;
208+
sai_attr_list[count].id = SAI_ACL_ENTRY_ATTR_FIELD_DST_IP;
209+
sai_attr_list[count++].value.aclfield.data.ip4 = 0x0a000002;
210+
sai_attr_list[count].id = SAI_ACL_ENTRY_ATTR_ACTION_SET_ECMP_HASH_ALGORITHM;
211+
sai_attr_list[count++].value.aclfield.data.u32 = SAI_HASH_ALGORITHM_ROUND_ROBIN;
212+
sai_create_acl_entry_fn(
213+
&acl_entry_id,
214+
switch_id,
215+
attr_count,
216+
sai_attr_list);
217+
```

doc/figures/Hash_based.png

32.2 KB
Loading

doc/figures/Random.png

32.8 KB
Loading

doc/figures/Round_robin.png

32.9 KB
Loading
26.7 KB
Loading

inc/saiacl.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,10 @@ typedef enum _sai_acl_action_type_t
297297

298298
/** Set Packet inner Dst MAC Address */
299299
SAI_ACL_ACTION_TYPE_SET_INNER_DST_MAC = 0x0000003b,
300+
301+
/** Set ECMP hash algorithm */
302+
SAI_ACL_ACTION_TYPE_SET_ECMP_HASH_ALGORITHM = 0x0000003c,
303+
300304
} sai_acl_action_type_t;
301305

302306
/**
@@ -3327,10 +3331,19 @@ typedef enum _sai_acl_entry_attr_t
33273331
*/
33283332
SAI_ACL_ENTRY_ATTR_ACTION_SET_INNER_DST_MAC = SAI_ACL_ENTRY_ATTR_ACTION_START + 0x3b,
33293333

3334+
/**
3335+
* @brief Set ECMP hash algorithm
3336+
*
3337+
* @type sai_acl_action_data_t sai_hash_algorithm_t
3338+
* @flags CREATE_AND_SET
3339+
* @default disabled
3340+
*/
3341+
SAI_ACL_ENTRY_ATTR_ACTION_SET_ECMP_HASH_ALGORITHM = SAI_ACL_ENTRY_ATTR_ACTION_START + 0x3c,
3342+
33303343
/**
33313344
* @brief End of Rule Actions
33323345
*/
3333-
SAI_ACL_ENTRY_ATTR_ACTION_END = SAI_ACL_ENTRY_ATTR_ACTION_SET_INNER_DST_MAC,
3346+
SAI_ACL_ENTRY_ATTR_ACTION_END = SAI_ACL_ENTRY_ATTR_ACTION_SET_ECMP_HASH_ALGORITHM,
33343347

33353348
/**
33363349
* @brief End of ACL Entry attributes

inc/sailag.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,16 @@ typedef enum _sai_lag_attr_t
203203
*/
204204
SAI_LAG_ATTR_ARS_PORT_REASSIGNMENTS,
205205

206+
/**
207+
* @brief LAG hash algorithm
208+
* Overrides value of SAI_SWITCH_ATTR_LAG_DEFAULT_HASH_ALGORITHM if not set to SAI_HASH_ALGORITHM_NONE
209+
*
210+
* @type sai_hash_algorithm_t
211+
* @flags CREATE_ONLY
212+
* @default SAI_HASH_ALGORITHM_NONE
213+
*/
214+
SAI_LAG_ATTR_HASH_ALGORITHM,
215+
206216
/**
207217
* @brief End of attributes
208218
*/

inc/sainexthopgroup.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,17 @@ typedef enum _sai_next_hop_group_attr_t
279279
*/
280280
SAI_NEXT_HOP_GROUP_ATTR_NEXT_HOP_MEMBER_COUNTER_LIST,
281281

282+
/**
283+
* @brief Next hop group hash algorithm
284+
* Overrides value of SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_ALGORITHM if not set to SAI_HASH_ALGORITHM_NONE
285+
*
286+
* @type sai_hash_algorithm_t
287+
* @flags CREATE_ONLY
288+
* @default SAI_HASH_ALGORITHM_NONE
289+
* @validonly SAI_NEXT_HOP_GROUP_ATTR_TYPE == SAI_NEXT_HOP_GROUP_TYPE_DYNAMIC_UNORDERED_ECMP or SAI_NEXT_HOP_GROUP_ATTR_TYPE == SAI_NEXT_HOP_GROUP_TYPE_DYNAMIC_ORDERED_ECMP
290+
*/
291+
SAI_NEXT_HOP_GROUP_ATTR_HASH_ALGORITHM,
292+
282293
/**
283294
* @brief End of attributes
284295
*/

inc/saiswitch.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ typedef enum _sai_hash_algorithm_t
193193
/** XOR-based hash algorithm */
194194
SAI_HASH_ALGORITHM_XOR = 1,
195195

196-
/** Random-based hash algorithm */
196+
/** Random-based hash algorithm (per-packet random spraying) */
197197
SAI_HASH_ALGORITHM_RANDOM = 2,
198198

199199
/** Lower 16-bits of CRC32 based hash algorithm */
@@ -208,6 +208,12 @@ typedef enum _sai_hash_algorithm_t
208208
/** Combination of CRC and XOR based hash algorithm */
209209
SAI_HASH_ALGORITHM_CRC_XOR = 6,
210210

211+
/** Hash algorithm not set */
212+
SAI_HASH_ALGORITHM_NONE = 7,
213+
214+
/** Round-robin based hash algorithm (per-packet round-robin spraying) */
215+
SAI_HASH_ALGORITHM_ROUND_ROBIN = 8,
216+
211217
} sai_hash_algorithm_t;
212218

213219
/**

0 commit comments

Comments
 (0)