Skip to content

Commit

Permalink
Assign explicit integer values to Hash enum fields
Browse files Browse the repository at this point in the history
Problem
========

Consider a scenario where an application (adapter host) using SAI spec X
(say) warmboots to an application using new SAI spec Y (say).

If an enum is extended between X and Y with fields inserted "in between"
rather than "at the end" of the enum, the old fields can get "renumbered".
However, the SAI implementation (adapter) continues to return old enums
for previously returned objects thereby breaking the warmboot.

Possible approaches
===================

We discussed this during June 24, 2021 weekly SAI meeting and observed:

- This can e avoided by mandating that any new inserts to an enum will be
"at the end" (this could mean at the end of _END block). This will keep
the enum field values the same.
- However, that will come at the cost of readability: newly added fields
may be related to existing fields and thus for readability, those fields
belong togeter. Adding those to the end scatters the related fields
across the enum.

Solution
=========

Thus, we agreed to go with the below approach:
- Every enum field will have an explicit integer value assigned to it.
- Insertions can be "in between" (maintains readability) but the next
available unused integer value would be used for the new insertions.
- Thus, once an integer is assigned to an enum field, it does not change
with spec revision thereby not breaking warmboot.
- Between SAI spec 1.6.5 to 1.8.1, saihash.h and saiacl.h had new enms
inserted "in between".

Those will be "fixed" by assigning integer values to enum fields.

This fix will be applied to top of the sai.git tree.
This fix will then be ported to 1.8.1 and 1.8.2 will be released.

This patch
===========

Specifically, below patch was first introduced in v1.7.0 and inserted enum fields 'in betweeen':
21bdb48

- In 1.6.5: SAI_NATIVE_HASH_FIELD_L4_SRC_PORT is 7, SAI_NATIVE_HASH_FIELD_L4_DST_PORT is 8.
- In 1.8.1: SAI_NATIVE_HASH_FIELD_L4_SRC_PORT is 15, SAI_NATIVE_HASH_FIELD_L4_DST_PORT is 16.

If the application configured SAI_NATIVE_HASH_FIELD_L4_SRC_PORT (7)
prior to warmboot, even after warmboot, a query returns 7 which no
longer means SAI_NATIVE_HASH_FIELD_L4_SRC_PORT in 1.8.1.

This patch fixes it by assigning explicit integer values, and thus
SAI_NATIVE_HASH_FIELD_L4_SRC_PORT continues to be 7 in newer SAI specs
as well.
  • Loading branch information
shri-khare committed Jun 29, 2021
1 parent 0fd3d54 commit 8f2a3c8
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions inc/saihash.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ typedef enum _sai_native_hash_field_t
* in case for encapsulated packets.
* Used for both IPv4 and IPv6
*/
SAI_NATIVE_HASH_FIELD_SRC_IP,
SAI_NATIVE_HASH_FIELD_SRC_IP = 0x00000000,

/**
* @brief Native hash field destination IP.
Expand All @@ -54,123 +54,123 @@ typedef enum _sai_native_hash_field_t
* in case for encapsulated packets.
* Used for both IPv4 and IPv6
*/
SAI_NATIVE_HASH_FIELD_DST_IP,
SAI_NATIVE_HASH_FIELD_DST_IP = 0x00000001,

/** Native hash field inner source IP */
SAI_NATIVE_HASH_FIELD_INNER_SRC_IP,
SAI_NATIVE_HASH_FIELD_INNER_SRC_IP = 0x00000002,

/** Native hash field inner destination IP */
SAI_NATIVE_HASH_FIELD_INNER_DST_IP,
SAI_NATIVE_HASH_FIELD_INNER_DST_IP = 0x00000003,

/**
* @brief Native hash field source IPv4.
*
* Also, refers to the outer source IPv4
* in case for encapsulated packets
*/
SAI_NATIVE_HASH_FIELD_SRC_IPV4,
SAI_NATIVE_HASH_FIELD_SRC_IPV4 = 0x00000019,

/**
* @brief Native hash field destination IPv4
*
* Also, refers to the outer source IPv4
* in case for encapsulated packets
*/
SAI_NATIVE_HASH_FIELD_DST_IPV4,
SAI_NATIVE_HASH_FIELD_DST_IPV4 = 0x0000001a,

/**
* @brief Native hash field source IPv6.
*
* Also, refers to the outer source IPv6
* in case for encapsulated packets
*/
SAI_NATIVE_HASH_FIELD_SRC_IPV6,
SAI_NATIVE_HASH_FIELD_SRC_IPV6 = 0x0000001b,

/**
* @brief Native hash field destination IPv6
*
* Also, refers to the outer source IPv6
* in case for encapsulated packets
*/
SAI_NATIVE_HASH_FIELD_DST_IPV6,
SAI_NATIVE_HASH_FIELD_DST_IPV6 = 0x0000001c,

/** Native hash field inner source IPv4 */
SAI_NATIVE_HASH_FIELD_INNER_SRC_IPV4,
SAI_NATIVE_HASH_FIELD_INNER_SRC_IPV4 = 0x0000001d,

/** Native hash field inner destination IPv4 */
SAI_NATIVE_HASH_FIELD_INNER_DST_IPV4,
SAI_NATIVE_HASH_FIELD_INNER_DST_IPV4 = 0x0000001e,

/** Native hash field inner source IPv6 */
SAI_NATIVE_HASH_FIELD_INNER_SRC_IPV6,
SAI_NATIVE_HASH_FIELD_INNER_SRC_IPV6 = 0x0000001f,

/** Native hash field inner destination IPv6 */
SAI_NATIVE_HASH_FIELD_INNER_DST_IPV6,
SAI_NATIVE_HASH_FIELD_INNER_DST_IPV6 = 0x00000020,

/** Native hash field vlan id */
SAI_NATIVE_HASH_FIELD_VLAN_ID,
SAI_NATIVE_HASH_FIELD_VLAN_ID = 0x00000004,

/** Native hash field IP protocol */
SAI_NATIVE_HASH_FIELD_IP_PROTOCOL,
SAI_NATIVE_HASH_FIELD_IP_PROTOCOL = 0x00000005,

/** Native hash field Ethernet type */
SAI_NATIVE_HASH_FIELD_ETHERTYPE,
SAI_NATIVE_HASH_FIELD_ETHERTYPE = 0x00000006,

/** Native hash field L4 source port */
SAI_NATIVE_HASH_FIELD_L4_SRC_PORT,
SAI_NATIVE_HASH_FIELD_L4_SRC_PORT = 0x00000007,

/** Native hash field L4 destination port */
SAI_NATIVE_HASH_FIELD_L4_DST_PORT,
SAI_NATIVE_HASH_FIELD_L4_DST_PORT = 0x00000008,

/** Native hash field source MAC */
SAI_NATIVE_HASH_FIELD_SRC_MAC,
SAI_NATIVE_HASH_FIELD_SRC_MAC = 0x00000009,

/** Native hash field destination MAC */
SAI_NATIVE_HASH_FIELD_DST_MAC,
SAI_NATIVE_HASH_FIELD_DST_MAC = 0x0000000a,

/** Native hash field source port */
SAI_NATIVE_HASH_FIELD_IN_PORT,
SAI_NATIVE_HASH_FIELD_IN_PORT = 0x0000000b,

/** Native hash field inner IP protocol */
SAI_NATIVE_HASH_FIELD_INNER_IP_PROTOCOL,
SAI_NATIVE_HASH_FIELD_INNER_IP_PROTOCOL = 0x0000000c,

/** Native hash field inner Ethernet type */
SAI_NATIVE_HASH_FIELD_INNER_ETHERTYPE,
SAI_NATIVE_HASH_FIELD_INNER_ETHERTYPE = 0x0000000d,

/** Native hash field inner L4 source port */
SAI_NATIVE_HASH_FIELD_INNER_L4_SRC_PORT,
SAI_NATIVE_HASH_FIELD_INNER_L4_SRC_PORT = 0x0000000e,

/** Native hash field inner L4 destination port */
SAI_NATIVE_HASH_FIELD_INNER_L4_DST_PORT,
SAI_NATIVE_HASH_FIELD_INNER_L4_DST_PORT = 0x0000000f,

/** Native hash field inner source MAC */
SAI_NATIVE_HASH_FIELD_INNER_SRC_MAC,
SAI_NATIVE_HASH_FIELD_INNER_SRC_MAC = 0x00000010,

/** Native hash field inner destination MAC */
SAI_NATIVE_HASH_FIELD_INNER_DST_MAC,
SAI_NATIVE_HASH_FIELD_INNER_DST_MAC = 0x00000011,

/** Native hash field entire MPLS label stack */
SAI_NATIVE_HASH_FIELD_MPLS_LABEL_ALL,
SAI_NATIVE_HASH_FIELD_MPLS_LABEL_ALL = 0x00000012,

/** Native hash field the top MPLS label */
SAI_NATIVE_HASH_FIELD_MPLS_LABEL_0,
SAI_NATIVE_HASH_FIELD_MPLS_LABEL_0 = 0x00000013,

/** Native hash field second MPLS label from the top */
SAI_NATIVE_HASH_FIELD_MPLS_LABEL_1,
SAI_NATIVE_HASH_FIELD_MPLS_LABEL_1 = 0x00000014,

/** Native hash field third MPLS label from the top */
SAI_NATIVE_HASH_FIELD_MPLS_LABEL_2,
SAI_NATIVE_HASH_FIELD_MPLS_LABEL_2 = 0x00000015,

/** Native hash field fourth MPLS label from the top */
SAI_NATIVE_HASH_FIELD_MPLS_LABEL_3,
SAI_NATIVE_HASH_FIELD_MPLS_LABEL_3 = 0x00000016,

/** Native hash field fifth MPLS label from the top */
SAI_NATIVE_HASH_FIELD_MPLS_LABEL_4,
SAI_NATIVE_HASH_FIELD_MPLS_LABEL_4 = 0x00000017,

/** Native hash field IPv6 flow label */
SAI_NATIVE_HASH_FIELD_IPV6_FLOW_LABEL,
SAI_NATIVE_HASH_FIELD_IPV6_FLOW_LABEL = 0x00000018,

/** No field - for compatibility, must be last */
SAI_NATIVE_HASH_FIELD_NONE,
SAI_NATIVE_HASH_FIELD_NONE = 0x00000021,

} sai_native_hash_field_t;

Expand Down

0 comments on commit 8f2a3c8

Please sign in to comment.