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

[dash-sai] Update object id manager to support extensions range #589

Merged
merged 2 commits into from
Jun 14, 2024
Merged
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
53 changes: 40 additions & 13 deletions dash-pipeline/SAI/src/objectidmanager.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
#include "objectidmanager.h"
#include "logger.h"

extern "C" {
#include "saimetadata.h"
}

#define SAI_OBJECT_ID_BITS_SIZE (8 * sizeof(sai_object_id_t))

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 +28,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 +68,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 +119,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 +167,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 +268,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 +320,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
Loading