Skip to content

Commit 9ff81be

Browse files
authored
[meta] Add api version on each attribute (opencomputeproject#2100)
Will be handy to be able to query specific attributes based on libsai version returned from vendor
1 parent 83d1f3b commit 9ff81be

File tree

8 files changed

+177
-3
lines changed

8 files changed

+177
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ meta/sai.thrift
2929
meta/sai_adapter.py
3030
meta/sai_rpc_server.cpp
3131
meta/sai_rpc_frontend
32+
meta/saiattrversion.h
3233

3334
# temporary files
3435
**/*~

meta/Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,13 @@ xml: $(DEPS) Doxyfile Doxyfile.compat $(CONSTHEADERS)
121121

122122
EXTRA = acronyms.txt aspell.en.pws *.pm *.cap
123123

124+
saiattrversion.h: $(DEPS) attrversion.sh
125+
./attrversion.sh
126+
124127
saimetadatasize.h: $(DEPS)
125128
./size.sh
126129

127-
saimetadatatest.c saimetadata.c saimetadata.h: xml $(XMLDEPS) parse.pl $(CONSTHEADERS) $(EXTRA)
130+
saimetadatatest.c saimetadata.c saimetadata.h: xml $(XMLDEPS) parse.pl $(CONSTHEADERS) $(EXTRA) saiattrversion.h
128131
perl -I. parse.pl
129132

130133
RPC_MODULES=$(shell find rpc -type f -name "*.pm")
@@ -190,7 +193,7 @@ sai_rpc_frontend: rpc sai_rpc_frontend.cpp sai_rpc_frontend.main.cpp sai_rpc_ser
190193

191194
clean:
192195
rm -f *.o *~ .*~ *.tmp .*.swp .*.swo *.bak sai*.gv sai*.svg *.o.symbols doxygen*.db *.so
193-
rm -f saimetadata.h saimetadatasize.h saimetadata.c saimetadatatest.c saiswig.i
196+
rm -f saimetadata.h saimetadatasize.h saimetadata.c saimetadatatest.c saiswig.i saiattrversion.h
194197
rm -f saisanitycheck saimetadatatest saiserializetest saidepgraphgen sai_rpc_frontend
195198
rm -f sai.thrift sai_rpc_server.cpp sai_adapter.py
196199
rm -f *.gcda *.gcno *.gcov

meta/aspell.en.pws

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ netdevs
128128
netlink
129129
nexthop
130130
nexthopgroup
131+
nextrelease
131132
NPUs
132133
objlist
133134
offsetof

meta/attrversion.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
#
3+
# Copyright (c) 2021 Microsoft Open Technologies, Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License. You may obtain
7+
# a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR
10+
# CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
11+
# LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS
12+
# FOR A PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT.
13+
#
14+
# See the Apache Version 2.0 License for specific language governing
15+
# permissions and limitations under the License.
16+
#
17+
# Microsoft would like to thank the following companies for their review and
18+
# assistance with these files: Intel Corporation, Mellanox Technologies Ltd,
19+
# Dell Products, L.P., Facebook, Inc., Marvell International Ltd.
20+
#
21+
# @file attrversion.sh
22+
#
23+
# @brief This module defines attr version script
24+
#
25+
26+
OUTPUT="saiattrversion.h"
27+
28+
if ! git rev-parse --git-dir > /dev/null 2>&1; then
29+
30+
echo "WARNING: this is not git repository, will skip generating saiattrversion.h"
31+
cat /dev/null > $OUTPUT
32+
exit
33+
fi
34+
35+
# since api sai_query_api_version was introduced at v1.10.0 and we are enum
36+
# backward compatible from v1.9.0 then it make sense to list all attributes
37+
# version at v1.10.0, since it's min version to query vendor for api version
38+
39+
BASE="v1.10.0"
40+
41+
set -e
42+
43+
TAGS=$(git tag --sort=v:refname | grep -P "^v\d+\.\d+.\d+$" | sed -n -e '/'$BASE'/,$p'; echo HEAD)
44+
45+
(for tag in $TAGS; do git grep -P "^\s+SAI_\w+_ATTR_" $tag ../inc ../experimental | cat; done;
46+
grep -P "^\s+SAI_\w+_ATTR_" ../inc/sai*h ../experimental/sai*h | perl -npe '$_.="HEAD:"' ) | \
47+
perl -ne '/^(\S+):..\/(\S+)\/\S+.h:\s+(SAI_\w+_ATTR_\w+)/; print "#define $3 \"$1\" /* $2 */\n" if not defined $h{$3};$h{$3}=1' > $OUTPUT

meta/parse.pl

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
our %GLOBAL_APIS = ();
7070
our %OBJECT_TYPE_BULK_MAP = ();
7171
our %SAI_ENUMS_CUSTOM_RANGES = ();
72+
our %ATTR_API_VER = ();
7273

7374
my $FLAGS = "MANDATORY_ON_CREATE|CREATE_ONLY|CREATE_AND_SET|READ_ONLY|KEY";
7475
my $ENUM_FLAGS_TYPES = "(none|strict|mixed|ranges|free)";
@@ -2294,6 +2295,46 @@ sub ProcessIsExtensionAttr
22942295
return "false";
22952296
}
22962297

2298+
sub ProcessApiVersion
2299+
{
2300+
my ($attr, $type) = @_;
2301+
2302+
# for those attributes use the same version as MIN, since those
2303+
# attributes are auto generated
2304+
2305+
$attr = "SAI_ACL_ENTRY_ATTR_USER_DEFINED_FIELD_GROUP_MIN"
2306+
if ($attr =~ /^SAI_ACL_ENTRY_ATTR_USER_DEFINED_FIELD_GROUP_\d+$/);
2307+
2308+
$attr = "SAI_ACL_TABLE_ATTR_USER_DEFINED_FIELD_GROUP_MIN"
2309+
if ($attr =~ /^SAI_ACL_TABLE_ATTR_USER_DEFINED_FIELD_GROUP_\d+$/);
2310+
2311+
if (not defined $ATTR_API_VER{$attr} and scalar(keys%ATTR_API_VER) != 0)
2312+
{
2313+
LogWarning "no version defined for $attr in saiattrversion.h";
2314+
2315+
return "SAI_VERSION(0,0,0)";
2316+
}
2317+
2318+
return "SAI_VERSION(0,0,0)" if not defined $ATTR_API_VER{$attr};
2319+
2320+
return "SAI_VERSION($1,$2,$3)" if $ATTR_API_VER{$attr} =~ /^v(\d+)\.(\d+)\.(\d+)$/;
2321+
2322+
LogInfo "Setting $attr version to SAI_API_VERSION (future release)";
2323+
2324+
return "SAI_API_VERSION";
2325+
}
2326+
2327+
sub ProcessNextRelease
2328+
{
2329+
my ($attr, $type) = @_;
2330+
2331+
return "false" if not defined $ATTR_API_VER{$attr};
2332+
2333+
return "false" if $ATTR_API_VER{$attr} =~ /^v(\d+)\.(\d+)\.(\d+)$/;
2334+
2335+
return "true";
2336+
}
2337+
22972338
sub ProcessSingleObjectType
22982339
{
22992340
my ($typedef, $objecttype) = @_;
@@ -2355,6 +2396,8 @@ sub ProcessSingleObjectType
23552396
my $isresourcetype = ProcessIsResourceType($attr, $meta{isresourcetype});
23562397
my $isdeprecated = ProcessIsDeprecatedType($attr, $meta{deprecated});
23572398
my $isrelaxed = ProcessRelaxedType($attr, $meta{relaxed});
2399+
my $apiversion = ProcessApiVersion($attr);
2400+
my $nextrelease = ProcessNextRelease($attr);
23582401

23592402
my $ismandatoryoncreate = ($flags =~ /MANDATORY/) ? "true" : "false";
23602403
my $iscreateonly = ($flags =~ /CREATE_ONLY/) ? "true" : "false";
@@ -2413,7 +2456,8 @@ sub ProcessSingleObjectType
24132456
WriteSource ".isresourcetype = $isresourcetype,";
24142457
WriteSource ".isdeprecated = $isdeprecated,";
24152458
WriteSource ".isconditionrelaxed = $isrelaxed,";
2416-
WriteSource ".iscustom = ($attr >= 0x10000000) && ($attr < 0x20000000)";
2459+
WriteSource ".apiversion = $apiversion,";
2460+
WriteSource ".nextrelease = $nextrelease,";
24172461

24182462
WriteSource "};";
24192463

@@ -2467,6 +2511,15 @@ sub CreateMetadata
24672511
}
24682512
}
24692513

2514+
sub ProcessAttrVersion
2515+
{
2516+
WriteSectionComment "Have attr versions";
2517+
2518+
my $count = scalar(keys%ATTR_API_VER);
2519+
2520+
WriteHeader "#define SAI_METADATA_HAVE_ATTR_VERSION ($count)";
2521+
}
2522+
24702523
sub ProcessSaiStatus
24712524
{
24722525
my $filename = "../inc/saistatus.h";
@@ -4371,6 +4424,24 @@ sub ExtractObjectTypeBulkMap
43714424
%OBJECT_TYPE_BULK_MAP = %otmap;
43724425
}
43734426

4427+
sub ExtractAttrApiVersion
4428+
{
4429+
my $data = ReadHeaderFile("saiattrversion.h");
4430+
4431+
my @lines = split/\n/,$data;
4432+
4433+
for my $line (@lines)
4434+
{
4435+
if (not $line =~ /#define (SAI_\w+_ATTR_\w+) "(v\d+\.\d+\.\d+|HEAD)"/)
4436+
{
4437+
LogError "invalid line in saiattrversion.h: $line";
4438+
next;
4439+
}
4440+
4441+
$ATTR_API_VER{$1} = $2;
4442+
}
4443+
}
4444+
43744445
sub CheckObjectTypeStatitics
43754446
{
43764447
#
@@ -5534,6 +5605,8 @@ sub CreateDefineMaxConditionsLen
55345605

55355606
ExtractStatsFunctionMap();
55365607

5608+
ExtractAttrApiVersion();
5609+
55375610
ExtractUnionsInfo();
55385611

55395612
CheckHeadersStyle() if not defined $optionDisableStyleCheck;
@@ -5552,6 +5625,8 @@ sub CreateDefineMaxConditionsLen
55525625

55535626
WriteHeaderHeader();
55545627

5628+
ProcessAttrVersion();
5629+
55555630
ProcessSaiStatus();
55565631

55575632
ProcessExtraRangeDefines();

meta/saimetadatatypes.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,6 +1292,29 @@ typedef struct _sai_attr_metadata_t
12921292
*/
12931293
bool iscustom;
12941294

1295+
/**
1296+
* @brief Specifies API version at which attribute was introduced.
1297+
*
1298+
* If no version is available, then this value will be SAI_VERSION(0,0,0).
1299+
*
1300+
* This field should be used with nextrelease field.
1301+
*/
1302+
sai_api_version_t apiversion;
1303+
1304+
/**
1305+
* @brief Specified whether attribute will be present in next API release.
1306+
*
1307+
* It may happen that there are new attributes defined after stable release,
1308+
* and they will be part of next release. In this case API version will
1309+
* have value of current API version and nextrelease set to true.
1310+
*
1311+
* For example, if attr is defined between v1.14 and v1.15, then API
1312+
* version will be v1.15 and next release is false. If attr is defined on
1313+
* top of v1.15 and there is not next release defined, then API version
1314+
* will be v1.15 and next release set to true.
1315+
*/
1316+
bool nextrelease;
1317+
12951318
} sai_attr_metadata_t;
12961319

12971320
/*

meta/saisanitycheck.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3470,6 +3470,27 @@ void check_attr_condition_relaxed(
34703470
}
34713471
}
34723472

3473+
void check_attr_version(
3474+
_In_ const sai_attr_metadata_t* md)
3475+
{
3476+
META_LOG_ENTER();
3477+
3478+
if (SAI_METADATA_HAVE_ATTR_VERSION)
3479+
{
3480+
META_ASSERT_TRUE(md->apiversion > SAI_VERSION(0,0,0), "expected version to be defined");
3481+
3482+
if (md->nextrelease)
3483+
{
3484+
META_LOG_DEBUG("%s: nextrelease == true", md->attridname);
3485+
}
3486+
}
3487+
else
3488+
{
3489+
META_ASSERT_TRUE(md->apiversion == SAI_VERSION(0,0,0), "expected version to be zero");
3490+
META_ASSERT_TRUE(md->nextrelease == false, "expected nextrelease to be false");
3491+
}
3492+
}
3493+
34733494
void check_single_attribute(
34743495
_In_ const sai_attr_metadata_t* md)
34753496
{
@@ -3517,6 +3538,7 @@ void check_single_attribute(
35173538
check_attr_mixed_condition(md);
35183539
check_attr_mixed_validonly(md);
35193540
check_attr_condition_relaxed(md);
3541+
check_attr_version(md);
35203542

35213543
define_attr(md);
35223544
}

meta/style.pm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,7 @@ sub CheckMetadataSourceFiles
689689
next if $file eq "saimetadata.c";
690690
next if $file eq "saimetadatatest.c";
691691
next if $file eq "saimetadatasize.h";
692+
next if $file eq "saiattrversion.h";
692693
next if $file eq "sai_rpc_server.cpp";
693694

694695
next if $file =~ /swig|wrap/;
@@ -911,6 +912,7 @@ sub CheckHeadersStyle
911912
{
912913
next if $header eq "saimetadata.h"; # skip auto generated header
913914
next if $header eq "saimetadatasize.h"; # skip auto generated header
915+
next if $header eq "saiattrversion.h"; # skip auto generated header
914916

915917
my $data = ReadHeaderFile($header);
916918

0 commit comments

Comments
 (0)