Skip to content

Commit 13474d1

Browse files
authored
[sairedis][syncd] VidManager add updateIndex method (#787)
Will be needed for asic compare.
1 parent be8059f commit 13474d1

File tree

6 files changed

+106
-9
lines changed

6 files changed

+106
-9
lines changed

lib/inc/VirtualObjectIdManager.h

+18-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ namespace sairedis
139139
* Returns switch index for given oid. If oid is invalid, returns 0.
140140
*/
141141
static uint32_t getSwitchIndex(
142-
_In_ sai_object_id_t obejctId);
142+
_In_ sai_object_id_t objectId);
143143

144144
/**
145145
* @brief Get global context.
@@ -151,6 +151,23 @@ namespace sairedis
151151
static uint32_t getGlobalContext(
152152
_In_ sai_object_id_t objectId);
153153

154+
/**
155+
* @brief Get object index.
156+
*
157+
* Returns object index.
158+
*/
159+
static uint64_t getObjectIndex(
160+
_In_ sai_object_id_t objectId);
161+
162+
/**
163+
* @brief Update object index.
164+
*
165+
* Returns objects with updated object index.
166+
*/
167+
static sai_object_id_t updateObjectIndex(
168+
_In_ sai_object_id_t objectId,
169+
_In_ uint64_t objectIndex);
170+
154171
private:
155172

156173
/**

lib/src/Sai.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ sai_status_t Sai::set(
199199
// skip metadata if attribute is redis extension attribute
200200

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

204204
bool success = true;
205205

lib/src/VirtualObjectIdManager.cpp

+42-4
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ sai_object_id_t VirtualObjectIdManager::saiSwitchIdQuery(
112112
// TODO don't throw, those 2 functions should never throw
113113
// it doesn't matter whether oid is correct, that will be validated
114114
// in metadata
115-
SWSS_LOG_THROW("invalid object type of oid %s",
115+
SWSS_LOG_THROW("invalid object type of oid %s",
116116
sai_serialize_object_id(objectId).c_str());
117117
}
118118

@@ -309,9 +309,9 @@ sai_object_id_t VirtualObjectIdManager::constructObjectId(
309309
SWSS_LOG_ENTER();
310310

311311
return (sai_object_id_t)(
312-
((uint64_t)switchIndex << (SAI_REDIS_OBJECT_TYPE_BITS_SIZE + SAI_REDIS_GLOBAL_CONTEXT_BITS_SIZE + SAI_REDIS_OBJECT_INDEX_BITS_SIZE)) |
313-
((uint64_t)objectType << (SAI_REDIS_GLOBAL_CONTEXT_BITS_SIZE + SAI_REDIS_OBJECT_INDEX_BITS_SIZE)) |
314-
((uint64_t)globalContext << (SAI_REDIS_OBJECT_INDEX_BITS_SIZE)) |
312+
((uint64_t)switchIndex << (SAI_REDIS_OBJECT_TYPE_BITS_SIZE + SAI_REDIS_GLOBAL_CONTEXT_BITS_SIZE + SAI_REDIS_OBJECT_INDEX_BITS_SIZE)) |
313+
((uint64_t)objectType << (SAI_REDIS_GLOBAL_CONTEXT_BITS_SIZE + SAI_REDIS_OBJECT_INDEX_BITS_SIZE)) |
314+
((uint64_t)globalContext << (SAI_REDIS_OBJECT_INDEX_BITS_SIZE)) |
315315
objectIndex);
316316
}
317317

@@ -388,3 +388,41 @@ uint32_t VirtualObjectIdManager::getGlobalContext(
388388

389389
return (uint32_t)SAI_REDIS_GET_GLOBAL_CONTEXT(switchId);
390390
}
391+
392+
uint64_t VirtualObjectIdManager::getObjectIndex(
393+
_In_ sai_object_id_t objectId)
394+
{
395+
SWSS_LOG_ENTER();
396+
397+
return (uint32_t)SAI_REDIS_GET_OBJECT_INDEX(objectId);
398+
}
399+
400+
sai_object_id_t VirtualObjectIdManager::updateObjectIndex(
401+
_In_ sai_object_id_t objectId,
402+
_In_ uint64_t objectIndex)
403+
{
404+
SWSS_LOG_ENTER();
405+
406+
if (objectId == SAI_NULL_OBJECT_ID)
407+
{
408+
SWSS_LOG_THROW("can't update object index on NULL_OBJECT_ID");
409+
}
410+
411+
if (objectIndex > SAI_REDIS_OBJECT_INDEX_MAX)
412+
{
413+
SWSS_LOG_THROW("object index %lu over maximum %llu", objectIndex, SAI_REDIS_OBJECT_INDEX_MAX);
414+
}
415+
416+
sai_object_type_t objectType = objectTypeQuery(objectId);
417+
418+
if (objectType == SAI_OBJECT_TYPE_NULL)
419+
{
420+
SWSS_LOG_THROW("invalid object type of oid %s",
421+
sai_serialize_object_id(objectId).c_str());
422+
}
423+
424+
uint32_t switchIndex = (uint32_t)SAI_REDIS_GET_SWITCH_INDEX(objectId);
425+
uint32_t globalContext = (uint32_t)SAI_REDIS_GET_GLOBAL_CONTEXT(objectId);
426+
427+
return constructObjectId(objectType, switchIndex, objectIndex, globalContext);
428+
}

syncd/VidManager.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,28 @@ uint32_t VidManager::getGlobalContext(
8181

8282
return sairedis::VirtualObjectIdManager::getGlobalContext(objectId);
8383
}
84+
85+
uint64_t VidManager::getObjectIndex(
86+
_In_ sai_object_id_t objectId)
87+
{
88+
SWSS_LOG_ENTER();
89+
90+
auto swid = sairedis::VirtualObjectIdManager::switchIdQuery(objectId);
91+
92+
if (swid == SAI_NULL_OBJECT_ID)
93+
{
94+
SWSS_LOG_THROW("invalid object id %s",
95+
sai_serialize_object_id(objectId).c_str());
96+
}
97+
98+
return sairedis::VirtualObjectIdManager::getObjectIndex(objectId);
99+
}
100+
101+
sai_object_id_t VidManager::updateObjectIndex(
102+
_In_ sai_object_id_t objectId,
103+
_In_ uint64_t objectIndex)
104+
{
105+
SWSS_LOG_ENTER();
106+
107+
return sairedis::VirtualObjectIdManager::updateObjectIndex(objectId, objectIndex);
108+
}

syncd/VidManager.h

+19-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ namespace syncd
5555
* Throws for invalid object ID.
5656
*/
5757
static uint32_t getSwitchIndex(
58-
_In_ sai_object_id_t obejctId);
58+
_In_ sai_object_id_t objectId);
5959

6060
/**
6161
* @brief Get global context ID.
@@ -69,6 +69,23 @@ namespace syncd
6969
* Throws for invalid object ID.
7070
*/
7171
static uint32_t getGlobalContext(
72-
_In_ sai_object_id_t obejctId);
72+
_In_ sai_object_id_t objectId);
73+
74+
/**
75+
* @brief Get object index.
76+
*
77+
* Returns object index.
78+
*/
79+
static uint64_t getObjectIndex(
80+
_In_ sai_object_id_t objectId);
81+
82+
/**
83+
* @brief Update object index.
84+
*
85+
* Returns objects with updated object index.
86+
*/
87+
static sai_object_id_t updateObjectIndex(
88+
_In_ sai_object_id_t objectId,
89+
_In_ uint64_t objectIndex);
7390
};
7491
}

vslib/inc/RealObjectIdManager.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ namespace saivs
120120
* Returns switch index for given oid. If oid is invalid, returns 0.
121121
*/
122122
static uint32_t getSwitchIndex(
123-
_In_ sai_object_id_t obejctId);
123+
_In_ sai_object_id_t objectId);
124124

125125
private:
126126

0 commit comments

Comments
 (0)