Skip to content

Commit

Permalink
Handle default trap group and remove vlan members (sonic-net#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik authored and Shuotian Cheng committed Oct 1, 2016
1 parent eb9ebab commit 2b7b029
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 4 deletions.
4 changes: 4 additions & 0 deletions syncd/syncd.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,15 @@ extern "C" {

#define UNREFERENCED_PARAMETER(X)

#define DEFAULT_VLAN_NUMBER 1

#define VIDTORID "VIDTORID"
#define RIDTOVID "RIDTOVID"
#define VIDCOUNTER "VIDCOUNTER"
#define LANES "LANES"
#define HIDDEN "HIDDEN"
#define DEFAULT_VIRTUAL_ROUTER_ID "DEFAULT_VIRTUAL_ROUTER_ID"
#define DEFAULT_TRAP_GROUP_ID "DEFAULT_TRAP_GROUP_ID"
#define CPU_PORT_ID "CPU_PORT_ID"

#define NOTIFY_SAI_INIT_VIEW "SAI_INIT_VIEW"
Expand All @@ -71,6 +74,7 @@ std::unordered_map<sai_object_id_t, sai_object_id_t> redisGetVidToRidMap();
std::unordered_map<sai_object_id_t, sai_object_id_t> redisGetRidToVidMap();
std::vector<std::string> redisGetAsicStateKeys();
sai_object_id_t redisGetDefaultVirtualRouterId();
sai_object_id_t redisGetDefaultTrapGroupId();
void redisClearVidToRidMap();
void redisClearRidToVidMap();

Expand Down
78 changes: 77 additions & 1 deletion syncd/syncd_hard_reinit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,58 @@ void checkAllIds()
redisSetVidAndRidMap(g_translated);
}

void saiRemoveDefaultVlanMembers()
{
SWSS_LOG_ENTER();

// after asic init, all ports are vlan 1 members
// we will remove them to not complicate reinit
// if user want to add vlan 1, then it needs to be
// done explicitly.

const auto& portList = saiGetPortList();

std::vector<sai_object_id_t> vlanMemberList;

vlanMemberList.resize(portList.size());

sai_attribute_t attr;

attr.id = SAI_VLAN_ATTR_MEMBER_LIST;

attr.value.objlist.count = vlanMemberList.size();
attr.value.objlist.list = vlanMemberList.data();

sai_status_t status = sai_vlan_api->get_vlan_attribute(DEFAULT_VLAN_NUMBER, 1, &attr);

if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to obtain vlan %d members", DEFAULT_VLAN_NUMBER);

exit_and_notify(EXIT_FAILURE);
}

vlanMemberList.resize(attr.value.objlist.count);

for (auto &vm: vlanMemberList)
{
status = sai_vlan_api->remove_vlan_member(vm);

if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to remove vlan member 0x%llx from vland %d", vm, DEFAULT_VLAN_NUMBER);

exit_and_notify(EXIT_FAILURE);
}
}
}

void hardReinit()
{
SWSS_LOG_ENTER();

saiRemoveDefaultVlanMembers();

// repopulate asic view from redis db after hard asic initialize

g_vidToRidMap = redisGetVidToRidMap();
Expand Down Expand Up @@ -272,10 +320,38 @@ sai_object_id_t processSingleVid(sai_object_id_t vid)
rid = defaultVirtualRouterId;

createObject = false;

SWSS_LOG_INFO("default virtual router will not be created, processed VID %llx to RID %llx", vid, rid);
}

}
else if (objectType == SAI_OBJECT_TYPE_TRAP_GROUP)
{
auto it = g_vidToRidMap.find(vid);

if (it == g_vidToRidMap.end())
{
SWSS_LOG_ERROR("failed to find VID %llx in VIDTORID map", vid);

exit_and_notify(EXIT_FAILURE);
}

sai_object_id_t trapGroupRid = it->second;

sai_object_id_t defaultTrapGroupId = redisGetDefaultTrapGroupId();

if (trapGroupRid == defaultTrapGroupId)
{
// this is default trap group id
// we don't need to create it, just set attributes

rid = defaultTrapGroupId;

createObject = false;

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)
{
Expand Down
86 changes: 83 additions & 3 deletions syncd/syncd_reinit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,27 @@ std::unordered_map<sai_uint32_t, sai_object_id_t> saiGetHardwareLaneMap()
return map;
}

sai_object_id_t saiGetDefaultTrapGroup()
{

SWSS_LOG_ENTER();

sai_attribute_t attr;

attr.id = SAI_SWITCH_ATTR_DEFAULT_TRAP_GROUP;

sai_status_t status = sai_switch_api->get_switch_attribute(1, &attr);

if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("failed to get switch default trap group %d", status);

exit_and_notify(EXIT_FAILURE);
}

return attr.value.oid;
}

sai_object_id_t saiGetDefaultVirtualRouter()
{
SWSS_LOG_ENTER();
Expand Down Expand Up @@ -329,6 +350,24 @@ sai_object_id_t redisGetDefaultVirtualRouterId()
return vr_id;
}

sai_object_id_t redisGetDefaultTrapGroupId()
{
SWSS_LOG_ENTER();

auto redisVrId = g_redisClient->hget(HIDDEN, DEFAULT_TRAP_GROUP_ID);

if (redisVrId == NULL)
return SAI_NULL_OBJECT_ID;

sai_object_id_t vr_id;

int index = 0;

sai_deserialize_primitive(*redisVrId, index, vr_id);

return vr_id;
}

sai_object_id_t redisGetCpuId()
{
SWSS_LOG_ENTER();
Expand Down Expand Up @@ -358,6 +397,17 @@ void redisSetDefaultVirtualRouterId(sai_object_id_t vr_id)
g_redisClient->hset(HIDDEN, DEFAULT_VIRTUAL_ROUTER_ID, strVrId);
}

void redisSetDefaultTrapGroup(sai_object_id_t vr_id)
{
SWSS_LOG_ENTER();

std::string strVrId;

sai_serialize_primitive(vr_id, strVrId);

g_redisClient->hset(HIDDEN, DEFAULT_TRAP_GROUP_ID, strVrId);
}

void redisCreateRidAndVidMapping(sai_object_id_t rid, sai_object_id_t vid)
{
SWSS_LOG_ENTER();
Expand Down Expand Up @@ -403,7 +453,7 @@ void redisSetDummyAsicStateForRealObjectId(sai_object_id_t rid)
redisCreateRidAndVidMapping(rid, vid);
}

void helperCheckVirtualRouterId()
void helperCheckDefaultVirtualRouterId()
{
SWSS_LOG_ENTER();

Expand Down Expand Up @@ -431,6 +481,35 @@ void helperCheckVirtualRouterId()
}
}


void helperCheckDefaultTrapGroup()
{
SWSS_LOG_ENTER();

sai_object_id_t tgId = saiGetDefaultTrapGroup();

sai_object_id_t redisTgId = redisGetDefaultTrapGroupId();

if (redisTgId == SAI_NULL_OBJECT_ID)
{
redisSetDummyAsicStateForRealObjectId(tgId);

SWSS_LOG_INFO("redis default trap group is not defined yet");

redisSetDefaultTrapGroup(tgId);

redisTgId = tgId;
}

if (tgId != redisTgId)
{
// if this happens, we need to remap VIDTORID and RIDTOVID
SWSS_LOG_ERROR("FIXME: default trap group id differs: %llx vs %llx, ids must be remapped", tgId, redisTgId);

exit_and_notify(EXIT_FAILURE);
}
}

void redisSetCpuId(sai_object_id_t cpuId)
{
SWSS_LOG_ENTER();
Expand Down Expand Up @@ -542,14 +621,15 @@ void onSyncdStart(bool warmStart)

std::lock_guard<std::mutex> lock(g_mutex);


SWSS_LOG_ENTER();

helperCheckLaneMap();

helperCheckCpuId();

helperCheckVirtualRouterId();
helperCheckDefaultVirtualRouterId();

helperCheckDefaultTrapGroup();

helperCheckVlanId();

Expand Down

0 comments on commit 2b7b029

Please sign in to comment.