diff --git a/syncd/syncd.h b/syncd/syncd.h index 2d2aa40416f6..14f9b40aaee2 100644 --- a/syncd/syncd.h +++ b/syncd/syncd.h @@ -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" @@ -71,6 +74,7 @@ std::unordered_map redisGetVidToRidMap(); std::unordered_map redisGetRidToVidMap(); std::vector redisGetAsicStateKeys(); sai_object_id_t redisGetDefaultVirtualRouterId(); +sai_object_id_t redisGetDefaultTrapGroupId(); void redisClearVidToRidMap(); void redisClearRidToVidMap(); diff --git a/syncd/syncd_hard_reinit.cpp b/syncd/syncd_hard_reinit.cpp index ffcafa1b37b4..794f49be0f1c 100644 --- a/syncd/syncd_hard_reinit.cpp +++ b/syncd/syncd_hard_reinit.cpp @@ -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 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(); @@ -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) { diff --git a/syncd/syncd_reinit.cpp b/syncd/syncd_reinit.cpp index 95a1de57f314..740b180bb16d 100644 --- a/syncd/syncd_reinit.cpp +++ b/syncd/syncd_reinit.cpp @@ -118,6 +118,27 @@ std::unordered_map 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(); @@ -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(); @@ -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(); @@ -403,7 +453,7 @@ void redisSetDummyAsicStateForRealObjectId(sai_object_id_t rid) redisCreateRidAndVidMapping(rid, vid); } -void helperCheckVirtualRouterId() +void helperCheckDefaultVirtualRouterId() { SWSS_LOG_ENTER(); @@ -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(); @@ -542,14 +621,15 @@ void onSyncdStart(bool warmStart) std::lock_guard lock(g_mutex); - SWSS_LOG_ENTER(); helperCheckLaneMap(); helperCheckCpuId(); - helperCheckVirtualRouterId(); + helperCheckDefaultVirtualRouterId(); + + helperCheckDefaultTrapGroup(); helperCheckVlanId();