Skip to content

Commit

Permalink
[sairedis][syncd] VidManager add updateIndex method (sonic-net#787)
Browse files Browse the repository at this point in the history
Will be needed for asic compare.
  • Loading branch information
kcudnik committed Feb 8, 2021
1 parent be8059f commit 13474d1
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 9 deletions.
19 changes: 18 additions & 1 deletion lib/inc/VirtualObjectIdManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ namespace sairedis
* Returns switch index for given oid. If oid is invalid, returns 0.
*/
static uint32_t getSwitchIndex(
_In_ sai_object_id_t obejctId);
_In_ sai_object_id_t objectId);

/**
* @brief Get global context.
Expand All @@ -151,6 +151,23 @@ namespace sairedis
static uint32_t getGlobalContext(
_In_ sai_object_id_t objectId);

/**
* @brief Get object index.
*
* Returns object index.
*/
static uint64_t getObjectIndex(
_In_ sai_object_id_t objectId);

/**
* @brief Update object index.
*
* Returns objects with updated object index.
*/
static sai_object_id_t updateObjectIndex(
_In_ sai_object_id_t objectId,
_In_ uint64_t objectIndex);

private:

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/src/Sai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ sai_status_t Sai::set(
// skip metadata if attribute is redis extension attribute

// TODO this is setting on all contexts, but maybe we want one specific?
// and do set on all if obejctId == NULL
// and do set on all if objectId == NULL

bool success = true;

Expand Down
46 changes: 42 additions & 4 deletions lib/src/VirtualObjectIdManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ sai_object_id_t VirtualObjectIdManager::saiSwitchIdQuery(
// TODO don't throw, those 2 functions should never throw
// it doesn't matter whether oid is correct, that will be validated
// in metadata
SWSS_LOG_THROW("invalid object type of oid %s",
SWSS_LOG_THROW("invalid object type of oid %s",
sai_serialize_object_id(objectId).c_str());
}

Expand Down Expand Up @@ -309,9 +309,9 @@ sai_object_id_t VirtualObjectIdManager::constructObjectId(
SWSS_LOG_ENTER();

return (sai_object_id_t)(
((uint64_t)switchIndex << (SAI_REDIS_OBJECT_TYPE_BITS_SIZE + SAI_REDIS_GLOBAL_CONTEXT_BITS_SIZE + SAI_REDIS_OBJECT_INDEX_BITS_SIZE)) |
((uint64_t)objectType << (SAI_REDIS_GLOBAL_CONTEXT_BITS_SIZE + SAI_REDIS_OBJECT_INDEX_BITS_SIZE)) |
((uint64_t)globalContext << (SAI_REDIS_OBJECT_INDEX_BITS_SIZE)) |
((uint64_t)switchIndex << (SAI_REDIS_OBJECT_TYPE_BITS_SIZE + SAI_REDIS_GLOBAL_CONTEXT_BITS_SIZE + SAI_REDIS_OBJECT_INDEX_BITS_SIZE)) |
((uint64_t)objectType << (SAI_REDIS_GLOBAL_CONTEXT_BITS_SIZE + SAI_REDIS_OBJECT_INDEX_BITS_SIZE)) |
((uint64_t)globalContext << (SAI_REDIS_OBJECT_INDEX_BITS_SIZE)) |
objectIndex);
}

Expand Down Expand Up @@ -388,3 +388,41 @@ uint32_t VirtualObjectIdManager::getGlobalContext(

return (uint32_t)SAI_REDIS_GET_GLOBAL_CONTEXT(switchId);
}

uint64_t VirtualObjectIdManager::getObjectIndex(
_In_ sai_object_id_t objectId)
{
SWSS_LOG_ENTER();

return (uint32_t)SAI_REDIS_GET_OBJECT_INDEX(objectId);
}

sai_object_id_t VirtualObjectIdManager::updateObjectIndex(
_In_ sai_object_id_t objectId,
_In_ uint64_t objectIndex)
{
SWSS_LOG_ENTER();

if (objectId == SAI_NULL_OBJECT_ID)
{
SWSS_LOG_THROW("can't update object index on NULL_OBJECT_ID");
}

if (objectIndex > SAI_REDIS_OBJECT_INDEX_MAX)
{
SWSS_LOG_THROW("object index %lu over maximum %llu", objectIndex, SAI_REDIS_OBJECT_INDEX_MAX);
}

sai_object_type_t objectType = objectTypeQuery(objectId);

if (objectType == SAI_OBJECT_TYPE_NULL)
{
SWSS_LOG_THROW("invalid object type of oid %s",
sai_serialize_object_id(objectId).c_str());
}

uint32_t switchIndex = (uint32_t)SAI_REDIS_GET_SWITCH_INDEX(objectId);
uint32_t globalContext = (uint32_t)SAI_REDIS_GET_GLOBAL_CONTEXT(objectId);

return constructObjectId(objectType, switchIndex, objectIndex, globalContext);
}
25 changes: 25 additions & 0 deletions syncd/VidManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,28 @@ uint32_t VidManager::getGlobalContext(

return sairedis::VirtualObjectIdManager::getGlobalContext(objectId);
}

uint64_t VidManager::getObjectIndex(
_In_ sai_object_id_t objectId)
{
SWSS_LOG_ENTER();

auto swid = sairedis::VirtualObjectIdManager::switchIdQuery(objectId);

if (swid == SAI_NULL_OBJECT_ID)
{
SWSS_LOG_THROW("invalid object id %s",
sai_serialize_object_id(objectId).c_str());
}

return sairedis::VirtualObjectIdManager::getObjectIndex(objectId);
}

sai_object_id_t VidManager::updateObjectIndex(
_In_ sai_object_id_t objectId,
_In_ uint64_t objectIndex)
{
SWSS_LOG_ENTER();

return sairedis::VirtualObjectIdManager::updateObjectIndex(objectId, objectIndex);
}
21 changes: 19 additions & 2 deletions syncd/VidManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace syncd
* Throws for invalid object ID.
*/
static uint32_t getSwitchIndex(
_In_ sai_object_id_t obejctId);
_In_ sai_object_id_t objectId);

/**
* @brief Get global context ID.
Expand All @@ -69,6 +69,23 @@ namespace syncd
* Throws for invalid object ID.
*/
static uint32_t getGlobalContext(
_In_ sai_object_id_t obejctId);
_In_ sai_object_id_t objectId);

/**
* @brief Get object index.
*
* Returns object index.
*/
static uint64_t getObjectIndex(
_In_ sai_object_id_t objectId);

/**
* @brief Update object index.
*
* Returns objects with updated object index.
*/
static sai_object_id_t updateObjectIndex(
_In_ sai_object_id_t objectId,
_In_ uint64_t objectIndex);
};
}
2 changes: 1 addition & 1 deletion vslib/inc/RealObjectIdManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ namespace saivs
* Returns switch index for given oid. If oid is invalid, returns 0.
*/
static uint32_t getSwitchIndex(
_In_ sai_object_id_t obejctId);
_In_ sai_object_id_t objectId);

private:

Expand Down

0 comments on commit 13474d1

Please sign in to comment.