Skip to content

Commit 08fccb0

Browse files
kcudniklguohan
authored andcommitted
Add buffer pool logic and unittests (#381)
* Add cold discovered oids * Add cold discovered oids * Add buffer pool logic and unittests * Bring back logging
1 parent 4d5a7bb commit 08fccb0

10 files changed

+59207
-9
lines changed

syncd/syncd_applyview.cpp

+208-5
Original file line numberDiff line numberDiff line change
@@ -2492,12 +2492,10 @@ std::shared_ptr<SaiObj> findCurrentBestMatchForLag(
24922492
return c.obj;
24932493
}
24942494
}
2495-
2496-
break;
24972495
}
24982496
}
24992497

2500-
SWSS_LOG_WARN("failed to find best candidate for LAG using LAG member and port id");
2498+
SWSS_LOG_WARN("failed to find best candidate for LAG using LAG member and port id: tmp %s", temporaryObj->str_object_id.c_str());
25012499

25022500
return nullptr;
25032501
}
@@ -3213,7 +3211,140 @@ std::shared_ptr<SaiObj> findCurrentBestMatchForHostifTrapGroup(
32133211
return nullptr;
32143212
}
32153213

3216-
std::shared_ptr<SaiObj> findCurrentBestMatchForGenericObjectUsingHeuristic(
3214+
std::shared_ptr<SaiObj> findCurrentBestMatchForBufferPool(
3215+
_In_ const AsicView &currentView,
3216+
_In_ const AsicView &temporaryView,
3217+
_In_ const std::shared_ptr<const SaiObj> &temporaryObj,
3218+
_In_ const std::vector<sai_object_compare_info_t> &candidateObjects)
3219+
{
3220+
SWSS_LOG_ENTER();
3221+
3222+
/*
3223+
* For buffer pool using buffer profile which could be set on ingress
3224+
* priority group or queue. Those two should be already matched.
3225+
*/
3226+
3227+
const auto tmpBufferProfiles = temporaryView.getNotProcessedObjectsByObjectType(SAI_OBJECT_TYPE_BUFFER_PROFILE);
3228+
3229+
for (auto tmpBufferProfile: tmpBufferProfiles)
3230+
{
3231+
auto tmpPoolIdAttr = tmpBufferProfile->tryGetSaiAttr(SAI_BUFFER_PROFILE_ATTR_POOL_ID);
3232+
3233+
if (tmpPoolIdAttr == nullptr)
3234+
continue;
3235+
3236+
if (tmpPoolIdAttr->getOid() != temporaryObj->getVid())
3237+
continue;
3238+
3239+
/*
3240+
* We have temporary buffer profile which uses this buffer pool, let's
3241+
* find ingress priority group or queue on which it could be set.
3242+
*/
3243+
3244+
auto tmpQueues = temporaryView.getObjectsByObjectType(SAI_OBJECT_TYPE_QUEUE);
3245+
3246+
for (auto tmpQueue: tmpQueues)
3247+
{
3248+
auto tmpBufferProfileIdAttr = tmpQueue->tryGetSaiAttr(SAI_QUEUE_ATTR_BUFFER_PROFILE_ID);
3249+
3250+
if (tmpBufferProfileIdAttr == nullptr)
3251+
continue;
3252+
3253+
if (tmpBufferProfileIdAttr->getOid() != tmpBufferProfile->getVid())
3254+
continue;
3255+
3256+
if (tmpQueue->getObjectStatus() != SAI_OBJECT_STATUS_MATCHED)
3257+
continue;
3258+
3259+
// we can use tmp VID since object is matched and both vids are the same
3260+
auto curQueue = currentView.oOids.at(tmpQueue->getVid());
3261+
3262+
auto curBufferProfileIdAttr = curQueue->tryGetSaiAttr(SAI_QUEUE_ATTR_BUFFER_PROFILE_ID);
3263+
3264+
if (curBufferProfileIdAttr == nullptr)
3265+
continue;
3266+
3267+
if (curBufferProfileIdAttr->getOid() == SAI_NULL_OBJECT_ID)
3268+
continue;
3269+
3270+
// we have buffer profile
3271+
3272+
auto curBufferProfile = currentView.oOids.at(curBufferProfileIdAttr->getOid());
3273+
3274+
auto curPoolIdAttr = curBufferProfile->tryGetSaiAttr(SAI_BUFFER_PROFILE_ATTR_POOL_ID);
3275+
3276+
if (curPoolIdAttr == nullptr)
3277+
continue;
3278+
3279+
for (auto c: candidateObjects)
3280+
{
3281+
if (c.obj->getVid() != curPoolIdAttr->getOid())
3282+
continue;
3283+
3284+
SWSS_LOG_INFO("found best BUFFER POOL based on buffer profile and queue %s", c.obj->str_object_id.c_str());
3285+
3286+
return c.obj;
3287+
}
3288+
}
3289+
3290+
/*
3291+
* Queues didn't worked, lets try to use ingress priority groups.
3292+
*/
3293+
3294+
auto tmpIngressPriorityGroups = temporaryView.getObjectsByObjectType(SAI_OBJECT_TYPE_INGRESS_PRIORITY_GROUP);
3295+
3296+
for (auto tmpIngressPriorityGroup: tmpIngressPriorityGroups)
3297+
{
3298+
auto tmpBufferProfileIdAttr = tmpIngressPriorityGroup->tryGetSaiAttr(SAI_INGRESS_PRIORITY_GROUP_ATTR_BUFFER_PROFILE);
3299+
3300+
if (tmpBufferProfileIdAttr == nullptr)
3301+
continue;
3302+
3303+
if (tmpBufferProfileIdAttr->getOid() != tmpBufferProfile->getVid())
3304+
continue;
3305+
3306+
if (tmpIngressPriorityGroup->getObjectStatus() != SAI_OBJECT_STATUS_MATCHED)
3307+
continue;
3308+
3309+
// we can use tmp VID since object is matched and both vids are the same
3310+
auto curIngressPriorityGroup = currentView.oOids.at(tmpIngressPriorityGroup->getVid());
3311+
3312+
auto curBufferProfileIdAttr = curIngressPriorityGroup->tryGetSaiAttr(SAI_INGRESS_PRIORITY_GROUP_ATTR_BUFFER_PROFILE);
3313+
3314+
if (curBufferProfileIdAttr == nullptr)
3315+
continue;
3316+
3317+
if (curBufferProfileIdAttr->getOid() == SAI_NULL_OBJECT_ID)
3318+
continue;
3319+
3320+
// we have buffer profile
3321+
3322+
auto curBufferProfile = currentView.oOids.at(curBufferProfileIdAttr->getOid());
3323+
3324+
auto curPoolIdAttr = curBufferProfile->tryGetSaiAttr(SAI_BUFFER_PROFILE_ATTR_POOL_ID);
3325+
3326+
if (curPoolIdAttr == nullptr)
3327+
continue;
3328+
3329+
for (auto c: candidateObjects)
3330+
{
3331+
if (c.obj->getVid() != curPoolIdAttr->getOid())
3332+
continue;
3333+
3334+
SWSS_LOG_INFO("found best BUFFER POOL based on buffer profile and ingress priority group %s", c.obj->str_object_id.c_str());
3335+
3336+
return c.obj;
3337+
}
3338+
}
3339+
3340+
}
3341+
3342+
SWSS_LOG_NOTICE("failed to find best candidate for BUFFER POOL using buffer profile, ipg and queue");
3343+
3344+
return nullptr;
3345+
}
3346+
3347+
std::shared_ptr<SaiObj> findCurrentBestMatchForGenericObjectUsingGraph(
32173348
_In_ const AsicView &currentView,
32183349
_In_ const AsicView &temporaryView,
32193350
_In_ const std::shared_ptr<const SaiObj> &temporaryObj,
@@ -3253,10 +3384,31 @@ std::shared_ptr<SaiObj> findCurrentBestMatchForGenericObjectUsingHeuristic(
32533384
candidate = findCurrentBestMatchForAclTable(currentView, temporaryView, temporaryObj, candidateObjects);
32543385
break;
32553386

3387+
case SAI_OBJECT_TYPE_BUFFER_POOL:
3388+
candidate = findCurrentBestMatchForBufferPool(currentView, temporaryView, temporaryObj, candidateObjects);
3389+
break;
3390+
32563391
default:
32573392
break;
32583393
}
32593394

3395+
return candidate;
3396+
}
3397+
3398+
std::shared_ptr<SaiObj> findCurrentBestMatchForGenericObjectUsingHeuristic(
3399+
_In_ const AsicView &currentView,
3400+
_In_ const AsicView &temporaryView,
3401+
_In_ const std::shared_ptr<const SaiObj> &temporaryObj,
3402+
_In_ const std::vector<sai_object_compare_info_t> &candidateObjects)
3403+
{
3404+
SWSS_LOG_ENTER();
3405+
3406+
std::shared_ptr<SaiObj> candidate = findCurrentBestMatchForGenericObjectUsingGraph(
3407+
currentView,
3408+
temporaryView,
3409+
temporaryObj,
3410+
candidateObjects);
3411+
32603412
if (candidate != nullptr)
32613413
return candidate;
32623414

@@ -3613,6 +3765,23 @@ std::shared_ptr<SaiObj> findCurrentBestMatchForGenericObject(
36133765
* current view.
36143766
*/
36153767

3768+
/*
3769+
* But at this point also let's try find best candidate using graph paths,
3770+
* since if some attributes are missmatched (like for example more ACLs are
3771+
* created) this can lead to choose wrong LAG and have implications on
3772+
* router interface and so on. So matching by graph path here could be
3773+
* more precise.
3774+
*/
3775+
3776+
auto graphCandidate = findCurrentBestMatchForGenericObjectUsingGraph(
3777+
currentView,
3778+
temporaryView,
3779+
temporaryObj,
3780+
candidateObjects);
3781+
3782+
if (graphCandidate != nullptr)
3783+
return graphCandidate;
3784+
36163785
/*
36173786
* Sort candidate objects by equal attributes in descending order, we know
36183787
* here that we have at least 2 candidates.
@@ -6230,7 +6399,7 @@ void populateExistingObjects(
62306399
* objects on default existing objects, like for example buffer profile
62316400
* on ingress priority group. In this case buffer profile should not
62326401
* be considered as matched object and copied to temporary view, since
6233-
* this object was not decault existing object (on 1st cold boot) so in
6402+
* this object was not default existing object (on 1st cold boot) so in
62346403
* this case it must be processed by comparison logic and matched with
62356404
* possible new buffer profile created in temporary view. This may
62366405
* happen if OA will not care what was set previously on ingress
@@ -6372,6 +6541,38 @@ void updateRedisDatabase(
63726541
SWSS_LOG_NOTICE("updated redis database");
63736542
}
63746543

6544+
void logViewObjectCount(
6545+
_In_ const AsicView &currentView,
6546+
_In_ const AsicView &temporaryView)
6547+
{
6548+
SWSS_LOG_ENTER();
6549+
6550+
bool asic_changes = false;
6551+
6552+
for (int i = SAI_OBJECT_TYPE_NULL + 1; i < SAI_OBJECT_TYPE_MAX; i++)
6553+
{
6554+
sai_object_type_t ot = (sai_object_type_t)i;
6555+
6556+
size_t c = currentView.getObjectsByObjectType(ot).size();
6557+
size_t t = temporaryView.getObjectsByObjectType(ot).size();
6558+
6559+
if (c == t)
6560+
continue;
6561+
6562+
asic_changes = true;
6563+
6564+
SWSS_LOG_WARN("object count for %s on current view %zu is differnt than on temporary view: %zu",
6565+
sai_serialize_object_type(ot).c_str(),
6566+
c,
6567+
t);
6568+
}
6569+
6570+
if (asic_changes)
6571+
{
6572+
SWSS_LOG_WARN("object count is differnt on both view, there will be ASIC OPERATIONS!");
6573+
}
6574+
}
6575+
63756576
sai_status_t syncdApplyView()
63766577
{
63776578
SWSS_LOG_ENTER();
@@ -6512,6 +6713,8 @@ sai_status_t syncdApplyView()
65126713
temp.dumpRef("temp START");
65136714
}
65146715

6716+
logViewObjectCount(current, temp);
6717+
65156718
applyViewTransition(current, temp);
65166719

65176720
SWSS_LOG_NOTICE("ASIC operations to execute: %zu", current.asicGetOperationsCount());

syncd/syncd_hard_reinit.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -278,15 +278,15 @@ void checkAllIds()
278278

279279
/*
280280
* If removing existing object, also make sure we remove it
281-
* from DEFAULTVID map since this object will no longer exists.
281+
* from COLDVIDS map since this object will no longer exists.
282282
*/
283283

284284
if (g_ridToVidMap.find(rid) == g_ridToVidMap.end())
285285
continue;
286286

287287
std::string strVid = sai_serialize_object_id(g_ridToVidMap.at(rid));
288288

289-
SWSS_LOG_INFO("removeing existing VID: %s", strVid.c_str());
289+
SWSS_LOG_INFO("removing existing VID: %s", strVid.c_str());
290290

291291
g_redisClient->hdel(COLDVIDS, strVid);
292292
}

syncd/syncd_saiswitch.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class SaiSwitch
6464
*
6565
* @param rid Real ID to be examined.
6666
*
67-
* @return True if RID was discovered during cald boot init.
67+
* @return True if RID was discovered during cold boot init.
6868
*/
6969
bool isColdBootDiscoveredRid(
7070
_In_ sai_object_id_t rid) const;

tests/brcm.pl

+90
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,98 @@ sub test_brcm_acl_tables
291291
play "acl_tables.rec", 0;
292292
}
293293

294+
sub test_brcm_buffer_pool
295+
{
296+
fresh_start;
297+
298+
# we expect no operations on asic, and all buffer pools will be matched correctly
299+
300+
play "full_buffer.rec";
301+
play "full_buffer_second.rec",0;
302+
}
303+
304+
sub test_brcm_warm_boot_full
305+
{
306+
fresh_start;
307+
308+
play "full.rec";
309+
310+
request_warm_shutdown;
311+
start_syncd_warm;
312+
313+
play "full_second.rec";
314+
315+
request_warm_shutdown;
316+
}
317+
318+
sub test_brcm_warm_boot_empty
319+
{
320+
fresh_start;
321+
322+
play "empty_sw.rec";
323+
324+
request_warm_shutdown;
325+
start_syncd_warm;
326+
327+
play "empty_sw.rec", 0;
328+
329+
request_warm_shutdown;
330+
}
331+
332+
sub test_brcm_warm_boot_small_buffer
333+
{
334+
fresh_start;
335+
336+
play "small_buffer.rec";
337+
338+
request_warm_shutdown;
339+
start_syncd_warm;
340+
341+
play "small_buffer.rec", 0;
342+
343+
request_warm_shutdown;
344+
}
345+
346+
sub test_brcm_warm_boot_full_empty
347+
{
348+
fresh_start;
349+
350+
play "full.rec";
351+
352+
request_warm_shutdown;
353+
start_syncd_warm;
354+
355+
play "empty_sw.rec";
356+
play "empty_sw.rec", 0;
357+
play "full_second.rec";
358+
play "empty_sw.rec";
359+
360+
request_warm_shutdown;
361+
}
362+
363+
sub test_brcm_config_acl
364+
{
365+
fresh_start;
366+
367+
play "config_acl.rec";
368+
play "config_acl.rec", 0;
369+
370+
fresh_start;
371+
372+
play "config_acl2.rec";
373+
play "config_acl2.rec", 0;
374+
}
375+
294376
# RUN TESTS
295377

378+
test_brcm_config_acl;
379+
380+
test_brcm_warm_boot_full_empty;
381+
test_brcm_warm_boot_small_buffer;
382+
test_brcm_warm_boot_empty;
383+
test_brcm_warm_boot_full;
384+
385+
test_brcm_buffer_pool;
296386
test_brcm_acl_tables;
297387
test_brcm_qos_map_order;
298388
test_brcm_lag_no_members;

0 commit comments

Comments
 (0)