void check_attr_existing_objects()

in meta/saisanitycheck.c [2511:2673]


void check_attr_existing_objects(
        _In_ const sai_attr_metadata_t* md)
{
    META_LOG_ENTER();

    /*
     * Purpose of this test it to find attributes on objects existing already
     * on the switch with attributes that are mandatory on create and create
     * and set.  Those attributes can be changed by user from previous value,
     * and this causes problem for comparison logic to bring those objects to
     * default value. We need to store those initial values of created objects
     * somewhere.
     *
     * Worth notice, that this is only helper, since metadata on attributes
     * where default value for oid attribute is SAI_NULL_OBJECT_ID, but maybe
     * on the switch vendor actually assigned some value, so default value will
     * not be NULL after creation.
     */

    if (sai_metadata_get_object_type_info(md->objecttype)->isnonobjectid)
    {
        if (md->storedefaultvalue)
        {
            /*
             * Currently disabled since we need more complicated logic in parser
             * and we assume non object id's are not created at the switch by
             * internal components.
             *
             * META_MD_ASSERT_FAIL(md, "store default val should be not present on non object id");
             */
        }

        return;
    }

    if (md->defaultvaluetype == SAI_DEFAULT_VALUE_TYPE_VENDOR_SPECIFIC ||
            md->defaultvaluetype == SAI_DEFAULT_VALUE_TYPE_ATTR_VALUE)
    {
        /*
         * For attr value we can make restriction that value also needs to be
         * CREATE_AND_SET, since some of those values are read only.
         */

        if (!md->storedefaultvalue)
        {
            META_MD_ASSERT_FAIL(md, "vendor/attrvalue specific values needs to be stored");
        }

        META_LOG_DEBUG("vendor/attrvalue specific values needs to be stored %s", md->attridname);

        return;
    }

    if (!SAI_HAS_FLAG_MANDATORY_ON_CREATE(md->flags) || !SAI_HAS_FLAG_CREATE_AND_SET(md->flags))
    {
        return;
    }

    if (!md->storedefaultvalue)
    {
        META_MD_ASSERT_FAIL(md, "default value needs to be stored");
    }

    META_LOG_DEBUG("MANDATORY_ON_CREATE|CREATE_AND_SET values needs to be stored %s", md->attridname);

    /*
     * If attribute is mandatory on create and create and set then there is no
     * default value on created object, and user can change it's value so in
     * comparison logic we will need to maintain this state somewhere as
     * default.
     *
     * Actually even if object is create only and is created on the switch we
     * need to keep it's value for future reference count in metadata db.
     */

    /*
     * Currently we are limiting value types on existing objects that are
     * mandatory on create to primitive values.
     */

    switch (md->attrvaluetype)
    {
        case SAI_ATTR_VALUE_TYPE_INT32:
        case SAI_ATTR_VALUE_TYPE_INT8:
        case SAI_ATTR_VALUE_TYPE_IP_ADDRESS:
        case SAI_ATTR_VALUE_TYPE_MAC:
        case SAI_ATTR_VALUE_TYPE_UINT16:
        case SAI_ATTR_VALUE_TYPE_UINT32:
        case SAI_ATTR_VALUE_TYPE_UINT64:
        case SAI_ATTR_VALUE_TYPE_UINT8:

            /*
             * Primitives we can skip for now, just left as was set by user
             * with warning in syslog.
             */

            break;

        case SAI_ATTR_VALUE_TYPE_OBJECT_ID:

            if (md->allownullobjectid)
            {
                /*
                 * If object allows NULL object id then we assume that this can
                 * be used as default value.
                 */

                return;
            }

            /*
             * When type is object id we need to store it's previous value
             * since we will not be able to bring it to default.
             */

            META_LOG_DEBUG("Default value (oid) needs to be stored %s", md->attridname);

            break;

        case SAI_ATTR_VALUE_TYPE_QOS_MAP_LIST:

            /*
             * Allow qos maps list to enable editing qos map values.
             * Since on switch initialization there are no qos map objects (all switch qos
             * maps attributes are null) this shouldn't be a problem.
             */

            break;

        case SAI_ATTR_VALUE_TYPE_UINT32_LIST:

            /*
             * Allow for TAM histogram bin boundary
             */

            break;

        case SAI_ATTR_VALUE_TYPE_OBJECT_LIST:

            /*
             * Allow object list for selected objects (for now).
             */

            if (md->objecttype == SAI_OBJECT_TYPE_MIRROR_SESSION)
            {
                break;
            }

            META_MD_ASSERT_FAIL(md, "object list is not supported on this object type");

        case SAI_ATTR_VALUE_TYPE_POINTER:

            /*
             * Allow pointer for switch register read and write API's.
             */

            break;

        default:

            META_MD_ASSERT_FAIL(md, "not supported attr value type on existing object");
    }
}