Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cherry-pick 1.10][SAI-PTF] Enable saiserverv2 with syncd-rpc and fix saithriftv2 build #1587

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ else
SAITHRIFT_PATH=test/saithrift
endif

# Passed to genrpc.pl via "make saithrift-build":
GEN_SAIRPC_OPTS?=

# Passed to meta/Makefile via "make saithrift-build, can specify add'l libraries along with libsai
SAIRPC_EXTRA_LIBS?=

.PHONY: test doc clean

doc:
Expand All @@ -37,7 +43,7 @@ test:
make -C test

saithrift-build:
make -C $(SAITHRIFT_PATH)
SAIRPC_EXTRA_LIBS="$(SAIRPC_EXTRA_LIBS)" GEN_SAIRPC_OPTS=$(GEN_SAIRPC_OPTS) make -C $(SAITHRIFT_PATH)

saithrift-install: saithrift-build
make -C $(SAITHRIFT_PATH) install
Expand Down
5 changes: 4 additions & 1 deletion meta/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
# @brief This module defines SAI Metadata Makefile
#

# Passed to genrpc.pl:
GEN_SAIRPC_OPTS?=

WARNINGS = \
-ansi \
-Wall \
Expand Down Expand Up @@ -100,7 +103,7 @@ saimetadatatest.c saimetadata.c saimetadata.h: xml $(XMLDEPS) parse.pl $(CONSTHE
perl -I. parse.pl

rpc sai.thrift sai_rpc_server.cpp sai_adapter.py: xml $(XMLDEPS) gensairpc.pl
perl -Irpc gensairpc.pl
perl -Irpc gensairpc.pl $(GEN_SAIRPC_OPTS)

HEADERS = saimetadata.h $(CONSTHEADERS)

Expand Down
6 changes: 5 additions & 1 deletion meta/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ Parser also forces headers to be well formated when adding new code.
To test your changes just type:

```sh
make
[GEN_SAIRPC_OPTS=<option flags>] make
```
e.g.
```
GEN_SAIRPC_OPTS="-ve" make
```
18 changes: 11 additions & 7 deletions meta/gensairpc.README
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ USAGE

DEPENDENCIES
Ubuntu packages:

libtemplate-perl
libconst-fast-perl
libmoosex-aliases-perl
libnamespace-autoclean-perl
libgetopt-long-descriptive-perl

```
[sudo] apt-get install -y \
libtemplate-perl \
libconst-fast-perl \
libmoosex-aliases-perl \
libnamespace-autoclean-perl \
libgetopt-long-descriptive-perl \
doxygen \
graphviz \
aspell-en
```
2 changes: 1 addition & 1 deletion meta/gensairpc.pl
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ sub generate_server_template_from_skeleton {

# Define global variable before "class"
print {$server_template}
"\nextern sai_object_id_t switch_id;\nsai_object_id_t switch_id;\n\n\n";
"\nextern sai_object_id_t switch_id;\nsai_object_id_t switch_id;\nextern sai_object_id_t gSwitchId;\n\n\n";

# Define helper functions
print {$server_template} "[% PROCESS helper_functions %]\n\n\n";
Expand Down
29 changes: 28 additions & 1 deletion meta/templates/sai_rpc_server_functions.tt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@
[% END -%]
[%- END -%]

[%- BLOCK check_sai_function -%]
[% name = function.name; UNLESS methods.$name %]
[% END -%]
if ([% api %]_api->[% name = function.name; GET methods.$name %] == (void *)0) {
std::cerr << "NULL ptr: [% api %]_api->[% name = function.name; GET methods.$name %]" << std::endl;
[%- PROCESS throw_null_api_exception %]
}

[%- END -%]

[%- ######################################################################## -%]

[%- ######################################################################## -%]
Expand All @@ -54,6 +64,12 @@
if (switch_id != NULL) {
return switch_id;
}

//check if the switch created in syncd
if (gSwitchId != NULL) {
switch_id = gSwitchId;
return switch_id;
}

[%- END -%]

Expand Down Expand Up @@ -110,7 +126,7 @@
[%- ######################################################################## -%]

[%- BLOCK sai_api_query -%]
status = sai_api_query(SAI_API_[% api.upper %], (void **)&[% api %]_api);
status = sai_api_query(static_cast<sai_api_t>(SAI_API_[% api.upper %]), (void **)&[% api %]_api);
if (status != SAI_STATUS_SUCCESS) {
[%- PROCESS return_error indentation = 3 status_variable = 'status' %]
}
Expand All @@ -127,6 +143,14 @@
[% indent %]throw e;
[%- END -%]

[%- BLOCK throw_null_api_exception -%]
[%- indentation = indentation || 2; tab = 2; indent = ' '; indent = indent.repeat(tab*indentation) %]

[% indent %]sai_thrift_exception e;
[% indent %]e.status = SAI_STATUS_NOT_IMPLEMENTED;
[% indent %]throw e;
[%- END -%]

[%- ######################################################################## -%]

[%- ######################################################################## -%]
Expand Down Expand Up @@ -345,6 +369,9 @@

[%- PROCESS preprocess_arguments %]

[%- # Ensure function ptr not NULL -%]
[% name = function.name; UNLESS methods.$name %]//[% END %][% PROCESS check_sai_function -%]

[%- # Now just call the function -%]
[% name = function.name; UNLESS methods.$name %]//[% END %]status = [% PROCESS call_sai_function -%]

Expand Down
4 changes: 2 additions & 2 deletions meta/templates/sai_rpc_server_helper_functions.tt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void sai_thrift_parse_[% object %]_attributes(const std::vector<sai_thrift_attri
for (uint32_t i = 0; i < thrift_attr_list.size(); i++, it++) {
attribute = (sai_thrift_attribute_t)*it;
attr_list[i].id = attribute.id;
convert_attr_thrift_to_sai(SAI_OBJECT_TYPE_[% object.upper %], attribute, &attr_list[i]);
convert_attr_thrift_to_sai(static_cast<sai_object_type_t>(SAI_OBJECT_TYPE_[% object.upper %]), attribute, &attr_list[i]);
}
[% END -%]

Expand All @@ -85,7 +85,7 @@ void sai_thrift_deparse_[% object %]_attributes(sai_attribute_t *attr_list,

for (uint32_t i = 0; i < attr_count; i++, it++) {
sai_thrift_attribute_t attribute;
convert_attr_sai_to_thrift(SAI_OBJECT_TYPE_[% object.upper %], attr_list[i], attribute);
convert_attr_sai_to_thrift(static_cast<sai_object_type_t>(SAI_OBJECT_TYPE_[% object.upper %]), attr_list[i], attribute);
thrift_attr_list.push_back(attribute);
}
[% END -%]
Expand Down
7 changes: 5 additions & 2 deletions test/saithriftv2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ CPPFLAGS = -I$(SAI_HEADER_DIR) -I. -std=c++11
CPPFLAGS += -O0 -ggdb


# specify add'l libraries along with libsai
SAIRPC_EXTRA_LIBS?=

ifeq ($(platform),MLNX)
CDEFS = -DMLNXSAI
else
Expand Down Expand Up @@ -90,7 +93,7 @@ $(ODIR)/sai_rpc_server.o: ../../meta/sai_rpc_frontend.cpp
$(CXX) $(CPPFLAGS) -c $^ -o $@ $(CPPFLAGS) -I./gen-cpp -I../../meta -I../../inc -I../../experimental

$(ODIR)/saiserver.o: src/saiserver.cpp $(CPP_SOURCES) directories
$(CXX) $(CPPFLAGS) -c src/saiserver.cpp -o $@ $(CPPFLAGS) $(CDEFS) -I./gen-cpp -I../../inc
$(CXX) $(CPPFLAGS) -c src/saiserver.cpp -o $@ $(CPPFLAGS) $(CDEFS) -I./gen-cpp -I../../inc -I../../experimental

$(ODIR)/librpcserver.a: $(ODIR)/sai_rpc.o $(ODIR)/sai_types.o $(ODIR)/sai_constants.o $(ODIR)/sai_rpc_server.o
ar rcs $(ODIR)/librpcserver.a $^
Expand All @@ -100,7 +103,7 @@ clientlib: $(PY_SOURCES) $(SAI_PY_HEADERS)

saiserver: $(ODIR)/saiserver.o $(ODIR)/librpcserver.a
$(CXX) $(LDFLAGS) $(ODIR)/sai_rpc_server.o $(ODIR)/saiserver.o -o $@ \
$(ODIR)/librpcserver.a $(LIBS)
$(ODIR)/librpcserver.a $(LIBS) $(SAIRPC_EXTRA_LIBS)

install-lib: $(ODIR)/librpcserver.a
$(INSTALL) -D $(ODIR)/librpcserver.a $(DESTDIR)/usr/lib/librpcserver.a
Expand Down