Skip to content

Commit

Permalink
[dash] Refactor libsai (#438)
Browse files Browse the repository at this point in the history
* [dash] Refactor style for saiapi template and add logs

For better understanding which attributes are not implemented yet

* [dash] Move generate_dash_api.sh script to proper Makefile

We will need makefile for movind source that don't need templates

* [dash] Move out non template files to src directory

This will separate files that nedd actual processing from files that are
pure sources

* [dash] Add Makefile include files dependencies

For faster compilation

* [dash] Dash SAI add quad generic api skeleton

For base non dash apis

* [dash] Add dash quad macros for quad SAI api

Will be handy when adding support for more base objects

* [dash] Extract port apis to separate file

To make code more clear

* [dash] Extract switch apis to separate file

* [dash] Add ObjectIdManager class

For managing all objects oids

* [dash] Start using ObjectIdManager in DashSai

For better managing all oids

* [dash] Add dummy SAI base APIs

Will be needed for swss orchagent to start properly

* [dash] Fix vnet_out test

It require to create switch first

* Use actual switch id

* Address comments
  • Loading branch information
kcudnik authored Sep 17, 2023
1 parent 5cc19b0 commit 1729021
Show file tree
Hide file tree
Showing 27 changed files with 1,008 additions and 223 deletions.
4 changes: 2 additions & 2 deletions dash-pipeline/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ sai-headers: p4 docker-saithrift-bldr-image-exists | SAI/SAI
--name build_sai-$(USER) \
-u $(HOST_USER):$(HOST_GROUP) \
-w /SAI $(DOCKER_SAITHRIFT_BLDR_IMG) \
./generate_dash_api.sh
make

sai-meta:
@echo "Generate SAI metadata..."
Expand Down Expand Up @@ -271,7 +271,7 @@ DOCKER_RUN_SAITHRIFT_SRVR =\

run-saithrift-server:
$(DOCKER_RUN_SAITHRIFT_SRVR) \
./saiserver
bash -c './saiserver'

kill-saithrift-server:
-docker kill dash-saithrift-server-$(USER)
Expand Down
28 changes: 11 additions & 17 deletions dash-pipeline/SAI/Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
dashone: test.cpp
g++ \
-I SAI/inc \
-I SAI/experimental/ \
-o test test.cpp saidash.cpp \
-L/usr/local/lib/ \
-lpthread \
-lpiprotogrpc \
-lpiprotobuf \
-lprotobuf \
-lgrpc++ \
-lgrpc \
-lpiall \
-lpi_dummy \
-lpthread \
-labsl_synchronization \
-g

all: copysrc
./sai_api_gen.py \
/bmv2/dash_pipeline.bmv2/dash_pipeline_p4rt.json \
--ignore-tables=appliance,eni_meter,slb_decap \
dash

copysrc:
install -CDv src/Makefile src/*h src/*cpp lib/

.PHONY: clean
clean:
rm -f lib/*
5 changes: 0 additions & 5 deletions dash-pipeline/SAI/generate_dash_api.sh

This file was deleted.

10 changes: 1 addition & 9 deletions dash-pipeline/SAI/sai_api_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,17 +382,10 @@ def write_sai_impl_files(sai_api):
sai_impl_str = sai_impl_tm.render(tables = sai_api[TABLES_TAG], app_name = sai_api['app_name'], header_prefix = header_prefix)
write_if_different('./lib/sai' + sai_api['app_name'].replace('_', '') + '.cpp',sai_impl_str)

def write_sai_makefile(sai_api_name_list, sai_api_full_name_list):
env = Environment(loader=FileSystemLoader('.'))
makefile_tm = env.get_template('/templates/Makefile.j2')
makefile_str = makefile_tm.render(api_names = sai_api_name_list)

write_if_different('./lib/Makefile',makefile_str)

def write_sai_fixed_api_files(sai_api_full_name_list):
env = Environment(loader=FileSystemLoader('.'))

for filename in ['utils.cpp', 'utils.h', 'saifixedapis.cpp', 'saiimpl.h', 'logger.h', 'logger.cpp', 'saidash.h', 'dashsai.h', 'dashsai.cpp', 'config.h', 'config.cpp']:
for filename in ['saifixedapis.cpp', 'saiimpl.h']:
env = Environment(loader=FileSystemLoader('.'), trim_blocks=True, lstrip_blocks=True)
sai_impl_tm = env.get_template('/templates/%s.j2' % filename)
sai_impl_str = sai_impl_tm.render(tables = sai_api[TABLES_TAG], app_name = sai_api['app_name'], api_names = sai_api_full_name_list)
Expand Down Expand Up @@ -555,7 +548,6 @@ def write_sai_files(sai_api):
write_if_different('./SAI/experimental/saitypesextensions.h',''.join(new_lines))


write_sai_makefile(sai_api_name_list, sai_api_full_name_list)
write_sai_fixed_api_files(sai_api_full_name_list)

if args.print_sai_lib:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# DASH libsai.so Makefile
# THIS MAKEFILE IS AUTO-GENERATED FROM templates/Makefile.j2
# DO NOT MODIFY

CXXFLAGS_COMMON=
CXXFLAGS_COMMON+= -ansi
CXXFLAGS_COMMON+= -fPIC
Expand Down Expand Up @@ -58,11 +54,18 @@ SAI_OBJS_PATHS=$(addprefix $(SAI_DIR)/,$(SAI_OBJS))
DASH_SAI_SRCS=$(wildcard *.cpp)
DASH_SAI_OBJS=$(DASH_SAI_SRCS:.cpp=.o)

%.o: %.cpp
g++ $(SAI_INC) $(GXX_FLAGS) $(CXXFLAGS_COMMON) -c $< -o $@

all: libsai.so

%.d: %.cpp
g++ $(SAI_INC) $(GXX_FLAGS) $(CXXFLAGS_COMMON) -M $^ -o $@

DEPS := $(DASH_SAI_OBJS:.o=.d)

-include $(DEPS)

%.o: %.cpp
g++ $(SAI_INC) $(GXX_FLAGS) $(CXXFLAGS_COMMON) -MMD -c $< -o $@

libsai.so: $(SAI_OBJS_PATHS) $(DASH_SAI_OBJS)
g++ -shared -g -o $@ $^

Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 1729021

Please sign in to comment.