Skip to content

Commit

Permalink
Add support for scheduler groups and trap group workaround (sonic-net…
Browse files Browse the repository at this point in the history
…#127)

* Add support for scheduler groups and trap group workaround

* Apply default routes first on syncd reinit

* Address comments

* Address comments
  • Loading branch information
kcudnik authored Nov 18, 2016
1 parent b78beb8 commit ac3ede5
Show file tree
Hide file tree
Showing 5 changed files with 301 additions and 27 deletions.
2 changes: 2 additions & 0 deletions meta/sai_meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ class SaiAttrWrapper

~SaiAttrWrapper()
{
SWSS_LOG_ENTER();

sai_deserialize_free_attribute_value(m_meta->serializationtype, m_attr);
}

Expand Down
10 changes: 8 additions & 2 deletions syncd/syncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1324,13 +1324,19 @@ int main(int argc, char **argv)

gProfileMap[SAI_KEY_BOOT_TYPE] = std::to_string(options.startType);

sai_api_initialize(0, (service_method_table_t*)&test_services);
sai_status_t status = sai_api_initialize(0, (service_method_table_t*)&test_services);

if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("fail to sai_api_initialize: %d", status);
exit_and_notify(EXIT_FAILURE);
}

populate_sai_apis();

initialize_common_api_pointers();

sai_status_t status = sai_switch_api->initialize_switch(0, "", "", &switch_notifications);
status = sai_switch_api->initialize_switch(0, "", "", &switch_notifications);

if (status != SAI_STATUS_SUCCESS)
{
Expand Down
1 change: 1 addition & 0 deletions syncd/syncd.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ 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_defaultSchedulerGroupsRids;
extern std::set<sai_object_id_t> g_defaultQueuesRids;

void onSyncdStart(bool warmStart);
Expand Down
162 changes: 138 additions & 24 deletions syncd/syncd_hard_reinit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void processVlans();
void processNeighbors();
void processOids();
void processFdbs();
void processRoutes();
void processRoutes(bool defaultOnly);
void processTraps();

sai_object_type_t getObjectTypeFromAsicKey(const std::string &key);
Expand Down Expand Up @@ -266,8 +266,9 @@ void hardReinit()
processFdbs();
processNeighbors();
processOids();
processRoutes();
processTraps();
processRoutes(true);
processRoutes(false);

checkAllIds();
}
Expand Down Expand Up @@ -300,6 +301,82 @@ bool shouldSkipCreateion(
return false;
}

void trapGroupWorkaround(
sai_object_id_t vid,
sai_object_id_t& rid,
bool& createObject,
uint32_t attrCount,
const sai_attribute_t* attrList)
{
SWSS_LOG_ENTER();

if (createObject)
{
createObject = false; // force to "SET" left attributes
}
else
{
// default trap group
return;
}

sai_object_type_t objectType = SAI_OBJECT_TYPE_TRAP_GROUP;

SWSS_LOG_INFO("creating trap group and setting attributes 1 by 1 as workaround");

const sai_attribute_t* queue_attr = get_attribute_by_id(SAI_HOSTIF_TRAP_GROUP_ATTR_QUEUE, attrCount, attrList);

if (queue_attr == NULL)
{
SWSS_LOG_ERROR("missing QUEUE attribute on TRAP_GROUP creation even if it's not MANDATORY");

exit_and_notify(EXIT_FAILURE);
}

create_fn create = common_create[objectType];

if (create == NULL)
{
SWSS_LOG_ERROR("create function is not defined for object type %llx", objectType);

exit_and_notify(EXIT_FAILURE);
}

sai_status_t status = create(&rid, 1, queue_attr);

if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("failed to create TRAP_GROUP %s", sai_serialize_status(status).c_str());

exit_and_notify(EXIT_FAILURE);
}

SWSS_LOG_DEBUG("created TRAP_GROUP, processed VID %llx to RID %llx", objectType, vid, rid);
}

void listFailedAttributes(
sai_object_type_t objectType,
uint32_t attrCount,
const sai_attribute_t* attrList)
{
SWSS_LOG_ENTER();

for (uint32_t idx = 0; idx < attrCount; idx++)
{
const sai_attribute_t *attr = &attrList[idx];

auto meta = get_attribute_metadata(objectType, attr->id);

if (meta == NULL)
{
SWSS_LOG_ERROR("failed to get atribute metadata %d %d", objectType, attr->id);
exit_and_notify(EXIT_FAILURE);
}

SWSS_LOG_ERROR("%s = %s", meta->attridname, sai_serialize_attr_value(*meta, *attr).c_str());
}
}

sai_object_id_t processSingleVid(sai_object_id_t vid)
{
SWSS_LOG_ENTER();
Expand Down Expand Up @@ -328,6 +405,25 @@ sai_object_id_t processSingleVid(sai_object_id_t vid)

std::string strVid = sai_serialize_object_id(vid);

auto oit = g_oids.find(strVid);

if (oit == g_oids.end())
{
SWSS_LOG_ERROR("failed to find VID %s in OIDs map", strVid.c_str());

exit_and_notify(EXIT_FAILURE);
}

std::string asicKey = oit->second;;

std::shared_ptr<SaiAttributeList> list = g_attributesLists[asicKey];

processAttributesForOids(objectType, list); // recursion

sai_attribute_t *attrList = list->get_attr_list();

uint32_t attrCount = list->get_attr_count();

bool createObject = true;

if (objectType == SAI_OBJECT_TYPE_VIRTUAL_ROUTER)
Expand All @@ -351,12 +447,21 @@ sai_object_id_t processSingleVid(sai_object_id_t vid)
SWSS_LOG_DEBUG("default priority group will not be created, processed VID %llx to RID %llx", vid, rid);
}
}
else if (objectType == SAI_OBJECT_TYPE_SCHEDULER_GROUP)
{
if (shouldSkipCreateion(vid, rid, createObject, [&](sai_object_id_t sgId) { return g_defaultSchedulerGroupsRids.find(sgId) != g_defaultSchedulerGroupsRids.end(); }))
{
SWSS_LOG_DEBUG("default scheduler 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, [](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);
}

trapGroupWorkaround(vid, rid, createObject, attrCount, attrList);
}
else if (objectType == SAI_OBJECT_TYPE_PORT)
{
Expand All @@ -366,25 +471,6 @@ sai_object_id_t processSingleVid(sai_object_id_t vid)
}
}

auto oit = g_oids.find(strVid);

if (oit == g_oids.end())
{
SWSS_LOG_ERROR("failed to find VID %s in OIDs map", strVid.c_str());

exit_and_notify(EXIT_FAILURE);
}

std::string asicKey = oit->second;;

std::shared_ptr<SaiAttributeList> list = g_attributesLists[asicKey];

processAttributesForOids(objectType, list); // recursion

sai_attribute_t *attrList = list->get_attr_list();

uint32_t attrCount = list->get_attr_count();

if (createObject)
{
create_fn create = common_create[objectType];
Expand All @@ -402,6 +488,8 @@ sai_object_id_t processSingleVid(sai_object_id_t vid)
{
SWSS_LOG_ERROR("failed to create object %s: %s", sai_serialize_object_type(objectType).c_str(), sai_serialize_status(status).c_str());

listFailedAttributes(objectType, attrCount, attrList);

exit_and_notify(EXIT_FAILURE);
}

Expand All @@ -421,7 +509,19 @@ sai_object_id_t processSingleVid(sai_object_id_t vid)

if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("failed to set attribute for object type %llx attr id %llx: %d", objectType, attr->id, status);
auto meta = get_attribute_metadata(objectType, attr->id);

if (meta == NULL)
{
SWSS_LOG_ERROR("failed to get atribute metadata %d %d", objectType, attr->id);
exit_and_notify(EXIT_FAILURE);
}

SWSS_LOG_ERROR(
"failed to set %s value %s: %s",
meta->attridname,
sai_serialize_attr_value(*meta, *attr).c_str(),
sai_serialize_status(status).c_str());

exit_and_notify(EXIT_FAILURE);
}
Expand Down Expand Up @@ -717,15 +817,24 @@ sai_unicast_route_entry_t getRouteEntryFromString(const std::string &strRouteEnt
return routeEntry;
}

void processRoutes()
void processRoutes(bool defaultOnly)
{
SWSS_LOG_ENTER();

SWSS_LOG_TIMER("apply routes");

for (auto &kv: g_routes)
{
const std::string &strRouteEntry = kv.first;
const std::string &asicKey = kv.second;

bool isDefault = strRouteEntry.find("/0") != std::string::npos;

if (defaultOnly ^ isDefault)
{
continue;
}

sai_unicast_route_entry_t routeEntry = getRouteEntryFromString(strRouteEntry);

routeEntry.vr_id = processSingleVid(routeEntry.vr_id);
Expand All @@ -742,7 +851,12 @@ void processRoutes()

if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("failed to create_route_entry: %d", status);
SWSS_LOG_ERROR(
"failed to create ROUTE %s: %s",
sai_serialize_route_entry(routeEntry).c_str(),
sai_serialize_status(status).c_str());

listFailedAttributes(SAI_OBJECT_TYPE_ROUTE, attrCount, attrList);

exit_and_notify(EXIT_FAILURE);
}
Expand Down
Loading

0 comments on commit ac3ede5

Please sign in to comment.