Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[meta] Add custom range start/end to sai_object_type_t and sai_api_t as workaround for internal enum size #1926

Merged
merged 2 commits into from
Nov 17, 2023
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
6 changes: 6 additions & 0 deletions inc/sai.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ typedef enum _sai_api_t
SAI_API_ARS_PROFILE = 49, /**<sai_ars_api_profile_t */
SAI_API_TWAMP = 50, /**< sai_twamp_api_t */
SAI_API_MAX, /**< total number of APIs */

/** Custom range base value */
SAI_API_CUSTOM_RANGE_START = 256,

/** End of custom range base */
SAI_API_CUSTOM_RANGE_END
} sai_api_t;

/**
Expand Down
10 changes: 9 additions & 1 deletion inc/saitypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,15 @@ typedef enum _sai_object_type_t
SAI_OBJECT_TYPE_ARS = 104,
SAI_OBJECT_TYPE_ACL_TABLE_CHAIN_GROUP = 105,
SAI_OBJECT_TYPE_TWAMP_SESSION = 106,
SAI_OBJECT_TYPE_MAX, /* Must remain in last position */

/** Must remain in last position */
SAI_OBJECT_TYPE_MAX,

/** Custom range base value */
SAI_OBJECT_TYPE_CUSTOM_RANGE_START = 256,

/** End of custom range base */
SAI_OBJECT_TYPE_CUSTOM_RANGE_END
} sai_object_type_t;

typedef struct _sai_u8_list_t
Expand Down
2 changes: 2 additions & 0 deletions meta/saisanitycheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -5538,6 +5538,8 @@ void check_object_type_extension_max_value()
*/

META_ASSERT_TRUE(SAI_OBJECT_TYPE_EXTENSIONS_MAX < 256, "max object type can be 255 to be encoded on single byte");

META_ASSERT_TRUE(SAI_OBJECT_TYPE_MAX < SAI_OBJECT_TYPE_EXTENSIONS_MAX, "max object must be less than max extensions");
}

void check_global_apis()
Expand Down
12 changes: 6 additions & 6 deletions meta/saiserializetest.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,9 @@ void test_serialize_enum()

ASSERT_STR_EQ(buf, "-1", res);

res = sai_serialize_enum(buf, &sai_metadata_enum_sai_object_type_t, 128);
res = sai_serialize_enum(buf, &sai_metadata_enum_sai_object_type_t, 228);

ASSERT_STR_EQ(buf, "128", res);
ASSERT_STR_EQ(buf, "228", res);

/* test all enums */

Expand Down Expand Up @@ -1551,10 +1551,10 @@ void test_serialize_enum_list()

ASSERT_STR_EQ(buf, "{\"count\":2,\"list\":[\"SAI_OBJECT_TYPE_PORT\",\"-1\"]}", res);

ot[1] = 128;
ot[1] = 228;

res = sai_serialize_enum_list(buf, &sai_metadata_enum_sai_object_type_t, &list);
ASSERT_STR_EQ(buf, "{\"count\":2,\"list\":[\"SAI_OBJECT_TYPE_PORT\",\"128\"]}", res);
ASSERT_STR_EQ(buf, "{\"count\":2,\"list\":[\"SAI_OBJECT_TYPE_PORT\",\"228\"]}", res);

ot[1] = SAI_OBJECT_TYPE_LAG;
res = sai_serialize_enum_list(buf, NULL, &list);
Expand Down Expand Up @@ -1592,12 +1592,12 @@ void test_deserialize_enum_list()
list.list = NULL;
list.count = 0;

buf = "{\"count\":2,\"list\":[\"SAI_OBJECT_TYPE_PORT\",\"128\"]}";
buf = "{\"count\":2,\"list\":[\"SAI_OBJECT_TYPE_PORT\",\"228\"]}";
res = sai_deserialize_enum_list(buf, &sai_metadata_enum_sai_object_type_t, &list);
ASSERT_TRUE(res == (int)strlen(buf), "expected true");
ASSERT_TRUE(list.count == 2, "expected true");
ASSERT_TRUE(list.list[0] == SAI_OBJECT_TYPE_PORT, "expected true");
ASSERT_TRUE(list.list[1] == 128, "expected true");
ASSERT_TRUE(list.list[1] == 228, "expected true");
free(list.list);
list.list = NULL;
list.count = 0;
Expand Down