From 4525642ac55897a92b5de37015bc1e4ed3eaa945 Mon Sep 17 00:00:00 2001 From: kcudnik Date: Thu, 13 Jun 2024 18:13:11 +0200 Subject: [PATCH] [dash-sai] Update object id manager to support extensions range Update OID format to support new extensions range base More info in PR: https://github.com/opencomputeproject/SAI/pull/2028 --- dash-pipeline/SAI/src/objectidmanager.cpp | 49 +++++++++++++++++------ 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/dash-pipeline/SAI/src/objectidmanager.cpp b/dash-pipeline/SAI/src/objectidmanager.cpp index d9d2b2b00..f08ef6d9f 100644 --- a/dash-pipeline/SAI/src/objectidmanager.cpp +++ b/dash-pipeline/SAI/src/objectidmanager.cpp @@ -6,7 +6,11 @@ static_assert(SAI_OBJECT_ID_BITS_SIZE == 64, "sai_object_id_t must have 64 bits"); static_assert(sizeof(sai_object_id_t) == sizeof(uint64_t), "SAI object ID size should be uint64_t"); -#define DASH_OID_RESERVED_BITS_SIZE ( 8 ) +#define DASH_OID_RESERVED_BITS_SIZE ( 7 ) + +#define DASH_OBJECT_TYPE_EXTENSIONS_FLAG_BITS_SIZE ( 1 ) +#define DASH_OBJECT_TYPE_EXTENSIONS_FLAG_MAX ( (1ULL << DASH_OBJECT_TYPE_EXTENSIONS_FLAG_BITS_SIZE) - 1 ) +#define DASH_OBJECT_TYPE_EXTENSIONS_FLAG_MASK (DASH_OBJECT_TYPE_EXTENSIONS_FLAG_MAX) #define DASH_OBJECT_TYPE_BITS_SIZE ( 8 ) #define DASH_OBJECT_TYPE_MASK ( (1ULL << DASH_OBJECT_TYPE_BITS_SIZE) - 1 ) @@ -20,7 +24,12 @@ static_assert(sizeof(sai_object_id_t) == sizeof(uint64_t), "SAI object ID size s #define DASH_OBJECT_INDEX_MASK ( (1ULL << DASH_OBJECT_INDEX_BITS_SIZE) - 1 ) #define DASH_OBJECT_INDEX_MAX (DASH_OBJECT_INDEX_MASK) -#define DASH_OBJECT_ID_BITS_SIZE (DASH_OID_RESERVED_BITS_SIZE + DASH_OBJECT_TYPE_BITS_SIZE + DASH_SWITCH_INDEX_BITS_SIZE + DASH_OBJECT_INDEX_BITS_SIZE) +#define DASH_OBJECT_ID_BITS_SIZE ( \ + DASH_OID_RESERVED_BITS_SIZE + \ + DASH_OBJECT_TYPE_EXTENSIONS_FLAG_BITS_SIZE + \ + DASH_OBJECT_TYPE_BITS_SIZE + \ + DASH_SWITCH_INDEX_BITS_SIZE + \ + DASH_OBJECT_INDEX_BITS_SIZE) static_assert(DASH_OBJECT_ID_BITS_SIZE == SAI_OBJECT_ID_BITS_SIZE, "dash object id size must be equal to SAI object id size"); @@ -28,16 +37,15 @@ static_assert(DASH_OBJECT_TYPE_MAX == 0xff, "invalid object type max size"); static_assert(DASH_SWITCH_INDEX_MAX == 0xff, "invalid switch index max size"); static_assert(DASH_OBJECT_INDEX_MAX == 0xffffffffff, "invalid object index max"); -/* - * This condition must be met, since we need to be able to encode SAI object - * type in object id on defined number of bits. - */ -static_assert(SAI_OBJECT_TYPE_EXTENSIONS_RANGE_END < DASH_OBJECT_TYPE_MAX, "dash max object type value must be greater than supported SAI max objeect type value"); +static_assert(SAI_OBJECT_TYPE_MAX < 256, "object type must be possible to encode on 1 byte"); +static_assert((SAI_OBJECT_TYPE_EXTENSIONS_RANGE_END - SAI_OBJECT_TYPE_EXTENSIONS_RANGE_START) < 256, + "extensions object type must be possible to encode on 1 byte"); /* * Current OBJECT ID format: * - * bits 63..56 - reserved (must be zero) + * bits 63..57 - reserved (must be zero) + * bits 56..56 - object type extensions flag * bits 55..48 - SAI object type * bits 47..40 - switch index * bits 39..0 - object index @@ -56,8 +64,12 @@ static_assert(SAI_OBJECT_TYPE_EXTENSIONS_RANGE_END < DASH_OBJECT_TYPE_MAX, "dash #define DASH_GET_OBJECT_TYPE(oid) \ ( (((uint64_t)oid) >> ( DASH_SWITCH_INDEX_BITS_SIZE + DASH_OBJECT_INDEX_BITS_SIZE ) ) & ( DASH_OBJECT_TYPE_MASK ) ) + #define DASH_GET_OBJECT_TYPE_EXTENSIONS_FLAG(oid) \ + ( (((uint64_t)oid) >> ( DASH_OBJECT_TYPE_BITS_SIZE + DASH_SWITCH_INDEX_BITS_SIZE + DASH_OBJECT_INDEX_BITS_SIZE) & ( DASH_OBJECT_TYPE_EXTENSIONS_FLAG_MAX ) ) + #define DASH_TEST_OID (0x0123456789abcdef) +static_assert(DASH_GET_OBJECT_TYPE_EXTENSIONS_FLAG(DASH_TEST_OID) == 0x1, "object type extension flag"); static_assert(DASH_GET_OBJECT_TYPE(DASH_TEST_OID) == 0x23, "test object type"); static_assert(DASH_GET_SWITCH_INDEX(DASH_TEST_OID) == 0x45, "test switch index"); static_assert(DASH_GET_OBJECT_INDEX(DASH_TEST_OID) == 0x6789abcdef, "test object index"); @@ -103,9 +115,11 @@ sai_object_type_t ObjectIdManager::saiObjectTypeQuery( return SAI_OBJECT_TYPE_NULL; } - sai_object_type_t objectType = (sai_object_type_t)(DASH_GET_OBJECT_TYPE(objectId)); + sai_object_type_t objectType = DASH_GET_OBJECT_TYPE_EXTENSIONS_FLAG(objectId) + ? (sai_object_type_t)(DASH_GET_OBJECT_TYPE(objectId) + SAI_OBJECT_TYPE_EXTENSIONS_RANGE_START) + : (sai_object_type_t)(DASH_GET_OBJECT_TYPE(objectId)); - if (objectType == SAI_OBJECT_TYPE_NULL || objectType >= (sai_object_type_t)SAI_OBJECT_TYPE_EXTENSIONS_RANGE_END) + if (sai_metadata_is_object_type_valid(objectType) == false) { DASH_LOG_ERROR("invalid object id 0x%lx", objectId); @@ -149,7 +163,7 @@ sai_object_id_t ObjectIdManager::allocateNewObjectId( { DASH_LOG_ENTER(); - if ((objectType <= SAI_OBJECT_TYPE_NULL) || (objectType >= (sai_object_type_t)SAI_OBJECT_TYPE_EXTENSIONS_RANGE_END)) + if (sai_metadata_is_object_type_valid(objectType) == false) { DASH_LOG_ERROR("invalid objct type: %d", objectType); @@ -250,7 +264,14 @@ sai_object_id_t ObjectIdManager::constructObjectId( { DASH_LOG_ENTER(); + uint64_t extensionsFlag = (uint64_t)objectType >= SAI_OBJECT_TYPE_EXTENSIONS_RANGE_START; + + objectType = extensionsFlag + ? (sai_object_type_t)(objectType - SAI_OBJECT_TYPE_EXTENSIONS_RANGE_START) + : objectType; + return (sai_object_id_t)( + (((uint64_t)extensionsFlag & DASH_OBJECT_TYPE_EXTENSIONS_FLAG_MASK) << ( DASH_OBJECT_TYPE_BITS_SIZE + DASH_SWITCH_INDEX_BITS_SIZE + DASH_OBJECT_INDEX_BITS_SIZE )) | (((uint64_t)objectType & DASH_OBJECT_TYPE_MASK)<< ( DASH_SWITCH_INDEX_BITS_SIZE + DASH_OBJECT_INDEX_BITS_SIZE))| (((uint64_t)switchIndex & DASH_SWITCH_INDEX_MASK)<< ( DASH_OBJECT_INDEX_BITS_SIZE )) | (objectIndex & DASH_OBJECT_INDEX_MASK)); @@ -295,9 +316,11 @@ sai_object_type_t ObjectIdManager::objectTypeQuery( return SAI_OBJECT_TYPE_NULL; } - sai_object_type_t objectType = (sai_object_type_t)(DASH_GET_OBJECT_TYPE(objectId)); + sai_object_type_t objectType = DASH_GET_OBJECT_TYPE_EXTENSIONS_FLAG(objectId) + ? (sai_object_type_t)(DASH_GET_OBJECT_TYPE(objectId) + SAI_OBJECT_TYPE_EXTENSIONS_RANGE_START) + : (sai_object_type_t)(DASH_GET_OBJECT_TYPE(objectId)); - if (objectType == SAI_OBJECT_TYPE_NULL || objectType >= (sai_object_type_t)SAI_OBJECT_TYPE_EXTENSIONS_RANGE_END) + if (sai_metadata_is_object_type_valid(objectType) == false) { DASH_LOG_ERROR("invalid object id 0x%lx", objectId);