diff --git a/lib/inc/VirtualObjectIdManager.h b/lib/inc/VirtualObjectIdManager.h index c46f70c86579..02c7c0767c5a 100644 --- a/lib/inc/VirtualObjectIdManager.h +++ b/lib/inc/VirtualObjectIdManager.h @@ -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. @@ -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: /** diff --git a/lib/src/Sai.cpp b/lib/src/Sai.cpp index 246f9796b503..489741c3c2c0 100644 --- a/lib/src/Sai.cpp +++ b/lib/src/Sai.cpp @@ -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; diff --git a/lib/src/VirtualObjectIdManager.cpp b/lib/src/VirtualObjectIdManager.cpp index 8c6201100c28..54eed364b9ef 100644 --- a/lib/src/VirtualObjectIdManager.cpp +++ b/lib/src/VirtualObjectIdManager.cpp @@ -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()); } @@ -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); } @@ -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); +} diff --git a/syncd/VidManager.cpp b/syncd/VidManager.cpp index a2b4be0d8ae2..1a21dbc39e39 100644 --- a/syncd/VidManager.cpp +++ b/syncd/VidManager.cpp @@ -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); +} diff --git a/syncd/VidManager.h b/syncd/VidManager.h index d3f8b401592e..ce78ba57eb2f 100644 --- a/syncd/VidManager.h +++ b/syncd/VidManager.h @@ -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. @@ -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); }; } diff --git a/vslib/inc/RealObjectIdManager.h b/vslib/inc/RealObjectIdManager.h index 2bb8a02d90b8..51e193901599 100644 --- a/vslib/inc/RealObjectIdManager.h +++ b/vslib/inc/RealObjectIdManager.h @@ -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: