|
| 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 | + |
| 26 | + |
| 27 | +### Existing random member selection |
| 28 | +For every packet hitting the ECMP/LAG, the egress member is randomly selected. |
| 29 | + |
| 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 | + |
| 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 | + |
| 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 | + ``` |
0 commit comments