Skip to content

Commit

Permalink
[dash-sai] Update object id manager to support extensions range
Browse files Browse the repository at this point in the history
Update OID format to support new extensions range base
More info in PR: opencomputeproject/SAI#2028
  • Loading branch information
kcudnik committed Jun 13, 2024
1 parent fafe00f commit 4525642
Showing 1 changed file with 36 additions and 13 deletions.
49 changes: 36 additions & 13 deletions dash-pipeline/SAI/src/objectidmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -20,24 +24,28 @@ 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");

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
Expand All @@ -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");
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 4525642

Please sign in to comment.