in vslib/SwitchStateBase.cpp [2941:3094]
bool SwitchStateBase::check_object_default_state(
_In_ sai_object_id_t object_id)
{
SWSS_LOG_ENTER();
sai_object_type_t object_type = objectTypeQuery(object_id);
if (object_type == SAI_OBJECT_TYPE_NULL)
{
SWSS_LOG_ERROR("failed to get object type for oid: %s",
sai_serialize_object_id(object_id).c_str());
return false;
}
auto* oti = sai_metadata_get_object_type_info(object_type);
if (oti == nullptr)
{
SWSS_LOG_THROW("failed to get object type info for object type: %s",
sai_serialize_object_type(object_type).c_str());
}
// iterate over all attributes
for (size_t i = 0; i < oti->attrmetadatalength; i++)
{
auto* meta = oti->attrmetadata[i];
// skip readonly, mandatory on create and non oid attributes
if (meta->isreadonly)
continue;
if (!meta->isoidattribute)
continue;
if (meta->ismandatoryoncreate && meta->iscreateonly)
continue;
// those attributes must be skipped since those dependencies will be automatically broken
if (meta->objecttype == SAI_OBJECT_TYPE_SCHEDULER_GROUP && meta->attrid == SAI_SCHEDULER_GROUP_ATTR_PORT_ID)
continue;
if (meta->objecttype == SAI_OBJECT_TYPE_SCHEDULER_GROUP && meta->attrid == SAI_SCHEDULER_GROUP_ATTR_PARENT_NODE)
continue;
if (meta->objecttype == SAI_OBJECT_TYPE_QUEUE && meta->attrid == SAI_QUEUE_ATTR_PORT)
continue;
if (meta->objecttype == SAI_OBJECT_TYPE_QUEUE && meta->attrid == SAI_QUEUE_ATTR_PARENT_SCHEDULER_NODE)
continue;
if (meta->objecttype == SAI_OBJECT_TYPE_INGRESS_PRIORITY_GROUP && meta->attrid == SAI_INGRESS_PRIORITY_GROUP_ATTR_PORT)
continue;
// here we have only oid/object list attrs and we expect each of this
// attribute will be in default state which for oid is usually NULL,
// and for object list is empty
sai_attribute_t attr;
attr.id = meta->attrid;
sai_status_t status;
std::vector<sai_object_id_t> objlist;
if (meta->attrvaluetype == SAI_ATTR_VALUE_TYPE_OBJECT_ID)
{
// ok
}
else if (meta->attrvaluetype == SAI_ATTR_VALUE_TYPE_OBJECT_LIST)
{
objlist.resize(MAX_OBJLIST_LEN);
attr.value.objlist.count = MAX_OBJLIST_LEN;
attr.value.objlist.list = objlist.data();
}
else
{
// unable to check whether object is in default state, need fix
SWSS_LOG_ERROR("unsupported oid attribute: %s, FIX ME!", meta->attridname);
return false;
}
status = get(object_type, object_id, 1, &attr);
switch (status)
{
case SAI_STATUS_NOT_IMPLEMENTED:
case SAI_STATUS_NOT_SUPPORTED:
continue;
case SAI_STATUS_SUCCESS:
break;
default:
SWSS_LOG_ERROR("unexpected status %s on %s obj %s",
sai_serialize_status(status).c_str(),
meta->attridname,
sai_serialize_object_id(object_id).c_str());
return false;
}
if (meta->attrvaluetype == SAI_ATTR_VALUE_TYPE_OBJECT_ID)
{
if (attr.value.oid != SAI_NULL_OBJECT_ID)
{
SWSS_LOG_ERROR("expected null object id on %s on %s, but got: %s",
meta->attridname,
sai_serialize_object_id(object_id).c_str(),
sai_serialize_object_id(attr.value.oid).c_str());
return false;
}
}
else if (meta->attrvaluetype == SAI_ATTR_VALUE_TYPE_OBJECT_LIST)
{
if (objlist.size())
{
SWSS_LOG_ERROR("expected empty list on %s on %s, contents:",
meta->attridname,
sai_serialize_object_id(object_id).c_str());
for (auto oid: objlist)
{
SWSS_LOG_ERROR(" - oid: %s", sai_serialize_object_id(oid).c_str());
}
return false;
}
}
else
{
// unable to check whether object is in default state, need fix
SWSS_LOG_ERROR("unsupported oid attribute: %s, FIX ME!", meta->attridname);
return false;
}
}
// XXX later there can be issue when we for example add extra queues to
// the port those new queues should be removed by user first before
// removing port, and currently we don't have a way to differentiate those
// object is in default state
return true;
}