Skip to content

Commit debb18c

Browse files
committed
Add default object map after switch init
1 parent d688e7e commit debb18c

File tree

3 files changed

+87
-6
lines changed

3 files changed

+87
-6
lines changed

syncd/syncd_applyview.cpp

+31-6
Original file line numberDiff line numberDiff line change
@@ -3998,22 +3998,45 @@ bool performObjectSetTransition(
39983998
if (meta->objecttype == SAI_OBJECT_TYPE_SCHEDULER_GROUP &&
39993999
meta->attrid == SAI_SCHEDULER_GROUP_ATTR_SCHEDULER_PROFILE_ID)
40004000
{
4001-
// XXX this is workaround, FIXME
4002-
4003-
SWSS_LOG_WARN("workaround for %s, we will bring default value as NULL, but need previous from dep TREE, FIXME",
4004-
meta->attridname);
4005-
40064001
/*
40074002
* This attribute can hold reference to user created
40084003
* objects which maybe required to be destroyed, thats why
40094004
* we need to bring real value. What if real value were
40104005
* removed?
40114006
*/
40124007

4008+
sai_object_id_t def = SAI_NULL_OBJECT_ID;
4009+
4010+
auto sw = switches.begin()->second;
4011+
4012+
sai_object_id_t vid = currentBestMatch->getVid();
4013+
4014+
if (currentView.hasVid(vid))
4015+
{
4016+
// scheduler_group RID
4017+
sai_object_id_t rid = currentView.vidToRid.at(vid);
4018+
4019+
rid = sw->getDefaultValueForOidAttr(rid, SAI_SCHEDULER_GROUP_ATTR_SCHEDULER_PROFILE_ID);
4020+
4021+
if (rid != SAI_NULL_OBJECT_ID && currentView.hasRid(rid))
4022+
{
4023+
/*
4024+
* We found default value
4025+
*/
4026+
4027+
SWSS_LOG_DEBUG("found default rid %s, vid %s for %s",
4028+
sai_serialize_object_id(rid).c_str(),
4029+
sai_serialize_object_id(vid).c_str(),
4030+
meta->attridname);
4031+
4032+
def = currentView.ridToVid.at(rid);
4033+
}
4034+
}
4035+
40134036
sai_attribute_t defattr;
40144037

40154038
defattr.id = meta->attrid;
4016-
defattr.value.oid = SAI_NULL_OBJECT_ID;
4039+
defattr.value.oid = def;
40174040

40184041
std::string str_attr_value = sai_serialize_attr_value(*meta, defattr, false);
40194042

@@ -5521,6 +5544,8 @@ void executeOperationsOnAsic(
55215544

55225545
try
55235546
{
5547+
swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_INFO);
5548+
55245549
SWSS_LOG_TIMER("asic apply");
55255550

55265551
for (const auto &op: currentView.asicGetOperations())

syncd/syncd_saiswitch.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,8 @@ void SaiSwitch::saiDiscover(
951951
continue;
952952
}
953953

954+
m_defaultOidMap[rid][attr.id] = attr.value.oid;
955+
954956
if (!md->allownullobjectid && attr.value.oid == SAI_NULL_OBJECT_ID)
955957
{
956958
// SWSS_LOG_WARN("got null on %s, but not allowed", md->attridname);
@@ -1168,6 +1170,29 @@ void SaiSwitch::helperInternalOids()
11681170
}
11691171
}
11701172

1173+
sai_object_id_t SaiSwitch::getDefaultValueForOidAttr(
1174+
_In_ sai_object_id_t rid,
1175+
_In_ sai_attr_id_t attr_id)
1176+
{
1177+
SWSS_LOG_ENTER();
1178+
1179+
auto it = m_defaultOidMap.find(rid);
1180+
1181+
if (it == m_defaultOidMap.end())
1182+
{
1183+
return SAI_NULL_OBJECT_ID;
1184+
}
1185+
1186+
auto ita = it->second.find(attr_id);
1187+
1188+
if (ita == it->second.end())
1189+
{
1190+
return SAI_NULL_OBJECT_ID;
1191+
}
1192+
1193+
return ita->second;
1194+
}
1195+
11711196
/*
11721197
* NOTE: If real ID will change during hard restarts, then we need to remap all
11731198
* VID/RID, but we can only do that if we will save entire tree with all

syncd/syncd_saiswitch.h

+31
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,18 @@ class SaiSwitch
145145
void getDefaultMacAddress(
146146
_Out_ sai_mac_t& mac);
147147

148+
/**
149+
* @brief Gets default value of attribute for given object.
150+
*
151+
* This applies to objects discovered after switch init like
152+
* SAI_SCHEDULER_GROUP_ATTR_SCHEDULER_PROFILE_ID.
153+
*
154+
* If object or attribute is not found, SAI_NULL_OBJECT_ID is returned.
155+
*/
156+
sai_object_id_t getDefaultValueForOidAttr(
157+
_In_ sai_object_id_t rid,
158+
_In_ sai_attr_id_t attr_id);
159+
148160
private:
149161

150162
/*
@@ -298,6 +310,25 @@ class SaiSwitch
298310

299311
std::string getRedisLanesKey() const;
300312
std::string getRedisHiddenKey() const;
313+
314+
/**
315+
* @brief Default oid map.
316+
*
317+
* This map will contain default created objects and all their "oid"
318+
* attributes and it's default value. This will be needed for bringing
319+
* default values.
320+
*
321+
* TODO later on we need to make this for all attributes.
322+
*
323+
* Example:
324+
* SAI_OBJECT_TYPE_SCHEDULER: oid:0x16
325+
*
326+
* SAI_OBJECT_TYPE_SCHEDULER_GROUP: oid:0x17
327+
* SAI_SCHEDULER_GROUP_ATTR_SCHEDULER_PROFILE_ID: oid:0x16
328+
*
329+
* m_defaultOidMap[0x17][SAI_SCHEDULER_GROUP_ATTR_SCHEDULER_PROFILE_ID] == 0x16
330+
*/
331+
std::unordered_map<sai_object_id_t, std::unordered_map<sai_attr_id_t, sai_object_id_t>> m_defaultOidMap;
301332
};
302333

303334
extern std::map<sai_object_id_t, std::shared_ptr<SaiSwitch>> switches;

0 commit comments

Comments
 (0)