Skip to content

Commit

Permalink
Refactor isDefaultFunction into lambda functions (sonic-net#83)
Browse files Browse the repository at this point in the history
* Refactor isDefaultFunction into lambda functions

* Refactor isDefaultQueueId/isDefaultPriorityGroupId into lambda functions
  • Loading branch information
qiluo-msft authored and kcudnik committed Oct 11, 2016
1 parent 4258663 commit b392300
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 46 deletions.
12 changes: 3 additions & 9 deletions syncd/syncd.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <thread>
#include <mutex>
#include <thread>
#include <set>

#include <unistd.h>
#include <execinfo.h>
Expand All @@ -15,7 +16,6 @@

#ifdef SAITHRIFT
#include <utility>
#include <set>
#include <algorithm>
#include <switch_sai_rpc_server.h>
#endif // SAITHRIFT
Expand Down Expand Up @@ -65,6 +65,8 @@ extern "C" {
extern void exit_and_notify(int status) __attribute__ ((__noreturn__));

extern std::mutex g_mutex;
extern std::set<sai_object_id_t> g_defaultPriorityGroupsRids;
extern std::set<sai_object_id_t> g_defaultQueuesRids;

void onSyncdStart(bool warmStart);
void hardReinit();
Expand Down Expand Up @@ -175,12 +177,4 @@ std::unordered_map<sai_uint32_t, sai_object_id_t> redisGetLaneMap();

std::vector<sai_object_id_t> saiGetPortList();

typedef bool (*isDefaultFunction)(sai_object_id_t);

bool isDefaultQueueId(sai_object_id_t queueId);
bool isDefaultPriorityGroupId(sai_object_id_t pgId);
bool isDefaultVirtualRouterId(sai_object_id_t id);
bool isDefaultTrapGroupId(sai_object_id_t id);
bool isDefaultPortId(sai_object_id_t id);

#endif // __SYNCD_H__
13 changes: 7 additions & 6 deletions syncd/syncd_hard_reinit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,12 @@ void hardReinit()
checkAllIds();
}

template<typename FUN>
bool shouldSkipCreateion(
sai_object_id_t vid,
sai_object_id_t& rid,
bool& createObject,
isDefaultFunction fun)
FUN fun)
{
auto it = g_vidToRidMap.find(vid);

Expand Down Expand Up @@ -330,35 +331,35 @@ sai_object_id_t processSingleVid(sai_object_id_t vid)

if (objectType == SAI_OBJECT_TYPE_VIRTUAL_ROUTER)
{
if (shouldSkipCreateion(vid, rid, createObject, isDefaultVirtualRouterId))
if (shouldSkipCreateion(vid, rid, createObject, [](sai_object_id_t id) { return id == redisGetDefaultVirtualRouterId(); }))
{
SWSS_LOG_INFO("default virtual router will not be created, processed VID %llx to RID %llx", vid, rid);
}
}
else if (objectType == SAI_OBJECT_TYPE_QUEUE)
{
if (shouldSkipCreateion(vid, rid, createObject, isDefaultQueueId))
if (shouldSkipCreateion(vid, rid, createObject, [&](sai_object_id_t queueId) { return g_defaultQueuesRids.find(queueId) != g_defaultQueuesRids.end(); }))
{
SWSS_LOG_DEBUG("default queue will not be created, processed VID %llx to RID %llx", vid, rid);
}
}
else if (objectType == SAI_OBJECT_TYPE_PRIORITY_GROUP)
{
if (shouldSkipCreateion(vid, rid, createObject, isDefaultPriorityGroupId))
if (shouldSkipCreateion(vid, rid, createObject, [&](sai_object_id_t pgId) { return g_defaultPriorityGroupsRids.find(pgId) != g_defaultPriorityGroupsRids.end(); }))
{
SWSS_LOG_DEBUG("default priority group will not be created, processed VID %llx to RID %llx", vid, rid);
}
}
else if (objectType == SAI_OBJECT_TYPE_TRAP_GROUP)
{
if (shouldSkipCreateion(vid, rid, createObject, isDefaultTrapGroupId))
if (shouldSkipCreateion(vid, rid, createObject, [](sai_object_id_t id) { return id == redisGetDefaultTrapGroupId(); }))
{
SWSS_LOG_INFO("default trap group will not be created, processed VID %llx to RID %llx", vid, rid);
}
}
else if (objectType == SAI_OBJECT_TYPE_PORT)
{
if (shouldSkipCreateion(vid, rid, createObject, isDefaultPortId))
if (shouldSkipCreateion(vid, rid, createObject, [](sai_object_id_t) { return true; }))
{
SWSS_LOG_INFO("port will not be created, processed VID %llx to RID %llx", vid, rid);
}
Expand Down
31 changes: 0 additions & 31 deletions syncd/syncd_reinit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,11 +675,6 @@ std::vector<sai_object_id_t> saiGetPortQueues(sai_object_id_t portId)
// later we need to have this in redis with port mapping
std::set<sai_object_id_t> g_defaultQueuesRids;

bool isDefaultQueueId(sai_object_id_t queueId)
{
return g_defaultQueuesRids.find(queueId) != g_defaultQueuesRids.end();
}

void helperCheckQueuesIds()
{
SWSS_LOG_ENTER();
Expand Down Expand Up @@ -765,11 +760,6 @@ std::vector<sai_object_id_t> saiGetPortPriorityGroups(sai_object_id_t portId)
// later we need to have this in redis with port mapping
std::set<sai_object_id_t> g_defaultPriorityGroupsRids;

bool isDefaultPriorityGroupId(sai_object_id_t pgId)
{
return g_defaultPriorityGroupsRids.find(pgId) != g_defaultPriorityGroupsRids.end();
}

void helperCheckPriorityGroupsIds()
{
SWSS_LOG_ENTER();
Expand All @@ -795,27 +785,6 @@ void helperCheckPriorityGroupsIds()
}
}

bool isDefaultVirtualRouterId(sai_object_id_t id)
{
sai_object_id_t defaultVirtualRouterId = redisGetDefaultVirtualRouterId();

return id == defaultVirtualRouterId;
}

bool isDefaultTrapGroupId(sai_object_id_t id)
{
sai_object_id_t defaultTrapGroupId = redisGetDefaultTrapGroupId();

return id == defaultTrapGroupId;
}

bool isDefaultPortId(sai_object_id_t id)
{
// currenty all ports are considered default

return true;
}

void onSyncdStart(bool warmStart)
{
// it may happen that after initialize we will receive
Expand Down

0 comments on commit b392300

Please sign in to comment.