Skip to content

Commit

Permalink
Add switch notification attributes list to metadata (#886)
Browse files Browse the repository at this point in the history
* Add switch notification attributes list to metadata

* Add define and sanity checks
  • Loading branch information
kcudnik authored and lguohan committed Nov 8, 2018
1 parent 9d00364 commit b8f6ba8
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
35 changes: 35 additions & 0 deletions meta/parse.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3278,6 +3278,39 @@ sub CreateNotificationEnum
CreateEnumHelperMethod("sai_switch_notification_type_t");
}

sub CreateSwitchNotificationAttributesList
{
#
# create notification attributes list for easy use on places where only
# notifications must be processed instead of looping through all switch
# attributes
#

WriteSectionComment "SAI Switch Notification Attributes List";

WriteHeader "extern const sai_attr_metadata_t* const sai_metadata_switch_notify_attr[];";
WriteSource "const sai_attr_metadata_t* const sai_metadata_switch_notify_attr[] = {";

for my $name (sort keys %NOTIFICATIONS)
{
next if not $name =~ /^sai_(\w+)_notification_fn/;

WriteSource "&sai_metadata_attr_SAI_SWITCH_ATTR_" . uc($1) . "_NOTIFY,";
}

WriteSource "NULL";
WriteSource "};";

my $count = scalar(keys %NOTIFICATIONS);

WriteHeader "extern const size_t sai_metadata_switch_notify_attr_count;";
WriteSource "const size_t sai_metadata_switch_notify_attr_count = $count;";

WriteSectionComment "Define SAI_METADATA_SWITCH_NOTIFY_ATTR_COUNT";

WriteHeader "#define SAI_METADATA_SWITCH_NOTIFY_ATTR_COUNT $count";
}

sub WriteHeaderHeader
{
WriteSectionComment "AUTOGENERATED FILE! DO NOT EDIT";
Expand Down Expand Up @@ -3502,6 +3535,8 @@ sub MergeExtensionsEnums

CreateNotificationEnum();

CreateSwitchNotificationAttributesList();

CreateSerializeMethods();

WriteHeaderFotter();
Expand Down
32 changes: 32 additions & 0 deletions meta/saisanitycheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -4368,9 +4368,39 @@ void check_acl_user_defined_field()

void check_label_size()
{
SAI_META_LOG_ENTER();

META_ASSERT_TRUE(sizeof(sai_label_id_t) == sizeof(uint32_t), "label is expected to be 32 bit");
}

void check_switch_notify_list()
{
SAI_META_LOG_ENTER();

size_t i;

for (i = 0; i < sai_metadata_switch_notify_attr_count; ++i)
{
META_ASSERT_NOT_NULL(sai_metadata_switch_notify_attr[i]);
}

/* check for NULL guard */

META_ASSERT_NULL(sai_metadata_switch_notify_attr[i]);
}

void check_defines()
{
SAI_META_LOG_ENTER();

/*
* Check if defines are equal to their static values.
*/

META_ASSERT_TRUE(SAI_METADATA_SWITCH_NOTIFY_ATTR_COUNT == sai_metadata_switch_notify_attr_count, "notify define must be equal");
META_ASSERT_TRUE(SAI_METADATA_SWITCH_NOTIFY_ATTR_COUNT > 3, "there must be at least 3 notifications defined");
}

int main(int argc, char **argv)
{
debug = (argc > 1);
Expand Down Expand Up @@ -4411,6 +4441,8 @@ int main(int argc, char **argv)
check_get_attr_metadata();
check_acl_user_defined_field();
check_label_size();
check_switch_notify_list();
check_defines();

i = SAI_OBJECT_TYPE_NULL + 1;

Expand Down

0 comments on commit b8f6ba8

Please sign in to comment.