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

Merge vector packet processing (vpp) from sonic-platform-vpp with virtual switch #1473

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ CXXFLAGS="$SAVED_FLAGS"

AC_SUBST(CXXFLAGS_COMMON)

# -lvlibapi -lvapiclient -lvppapiclient -lvlibmemoryclient -lsvm -lvppinfra -lvlib -lvatplugin
# -lvapiclient -lsvm -lvatplugin
AC_CHECK_LIB([vlib], [main], [AC_SUBST(VPP_LIBS, "-lvlib -lvlibapi -lvppapiclient -lvlibmemoryclient -lvppinfra")])
AM_CONDITIONAL([USE_VPP], [test "x$VPP_LIBS" != "x"])

AC_ARG_WITH(extra-libsai-ldflags,
[ --with-extra-libsai-ldflags=FLAGS
extra libsai.so flags for vendor library],
Expand Down
2 changes: 1 addition & 1 deletion saidiscovery/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ AM_CXXFLAGS = $(SAIINC) -I$(top_srcdir)/meta -I$(top_srcdir)/lib
bin_PROGRAMS = saidiscovery

if SAIVS
SAILIB=-L$(top_srcdir)/vslib/.libs -lsaivs
SAILIB=-L$(top_srcdir)/vslib/.libs -lsaivs $(VPP_LIBS)
else
SAILIB=-lsai
endif
Expand Down
2 changes: 1 addition & 1 deletion saisdkdump/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ AM_CXXFLAGS = $(SAIINC)
bin_PROGRAMS = saisdkdump

if SAIVS
SAILIB=-L$(top_srcdir)/vslib/.libs -lsaivs
SAILIB=-L$(top_srcdir)/vslib/.libs -lsaivs $(VPP_LIBS)
else
SAILIB=-lsai
endif
Expand Down
6 changes: 3 additions & 3 deletions syncd/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ SUBDIRS = . tests
AM_CXXFLAGS = $(SAIINC) -I$(top_srcdir)/lib -I$(top_srcdir)/vslib

if SAIVS
SAILIB=-L$(top_srcdir)/vslib/.libs -lsaivs
SAILIB=-L$(top_srcdir)/vslib/.libs -lsaivs $(VPP_LIBS)
else
SAILIB=-lsai
endif
Expand Down Expand Up @@ -94,7 +94,7 @@ libSyncdRequestShutdown_a_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMO
syncd_request_shutdown_SOURCES = syncd_request_shutdown.cpp
syncd_request_shutdown_CPPFLAGS = $(CODE_COVERAGE_CPPFLAGS)
syncd_request_shutdown_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) $(CODE_COVERAGE_CXXFLAGS)
syncd_request_shutdown_LDADD = libSyncdRequestShutdown.a $(top_srcdir)/lib/libSaiRedis.a -lhiredis -lswsscommon -lpthread $(CODE_COVERAGE_LIBS)
syncd_request_shutdown_LDADD = libSyncdRequestShutdown.a $(top_srcdir)/lib/libSaiRedis.a -lhiredis -lswsscommon -lpthread $(CODE_COVERAGE_LIBS) $(VPP_LIBS)

libMdioIpcClient_a_SOURCES = MdioIpcClient.cpp

Expand All @@ -111,7 +111,7 @@ syncd_tests_SOURCES = tests.cpp
syncd_tests_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON)
syncd_tests_LDFLAGS = -Wl,-rpath,$(top_srcdir)/lib/.libs -Wl,-rpath,$(top_srcdir)/meta/.libs
syncd_tests_LDADD = libSyncd.a -lhiredis -lswsscommon -lpthread -L$(top_srcdir)/lib/.libs -lsairedis \
-L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -lzmq $(CODE_COVERAGE_LIBS)
-L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -lzmq $(CODE_COVERAGE_LIBS) $(VPP_LIBS)

TESTS = syncd_tests

Expand Down
2 changes: 1 addition & 1 deletion syncd/tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ tests_CXXFLAGS = \
tests_LDADD = \
$(top_srcdir)/syncd/libSyncd.a $(top_srcdir)/lib/libSaiRedis.a $(top_srcdir)/syncd/libSyncdRequestShutdown.a \
-L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -L$(top_srcdir)/vslib/.libs -lsaivs \
-lhiredis -lswsscommon -lpthread -lzmq $(LDADD_GTEST) $(CODE_COVERAGE_LIBS)
-lhiredis -lswsscommon -lpthread -lzmq $(LDADD_GTEST) $(CODE_COVERAGE_LIBS) $(VPP_LIBS)

TESTS = tests
2 changes: 1 addition & 1 deletion tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ AM_CXXFLAGS = $(SAIINC) -I$(top_srcdir)/lib -I$(top_srcdir)/vslib

bin_PROGRAMS = vssyncd tests testclient testdash_gtest

SAILIB=-L$(top_srcdir)/vslib/.libs -lsaivs
SAILIB=-L$(top_srcdir)/vslib/.libs -lsaivs $(VPP_LIBS)

vssyncd_SOURCES = main.cpp
vssyncd_CPPFLAGS = $(CODE_COVERAGE_CPPFLAGS)
Expand Down
1 change: 1 addition & 0 deletions tests/aspellcheck.pl
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ sub RunAspell
next if $file =~ m!/python/.+wrap.cpp!;
next if $file =~ m!/pyext/.+wrap.cpp!;
next if $file =~ m!sai_(redis|proxy|vs|stub).cpp!;
next if $file =~ m!vslib/vpp/!;

my $data = ReadFile $file;

Expand Down
2 changes: 1 addition & 1 deletion unittest/syncd/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ tests_SOURCES = main.cpp \
tests_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON)
tests_LDFLAGS = -Wl,-rpath,$(top_srcdir)/lib/.libs -Wl,-rpath,$(top_srcdir)/meta/.libs
tests_LDADD = $(LDADD_GTEST) $(top_srcdir)/syncd/libSyncdRequestShutdown.a $(top_srcdir)/syncd/libSyncd.a $(top_srcdir)/vslib/libSaiVS.a $(top_srcdir)/syncd/libMdioIpcClient.a \
-lhiredis -lswsscommon -lnl-genl-3 -lnl-nf-3 -lnl-route-3 -lnl-3 -lpthread -L$(top_srcdir)/lib/.libs -lsairedis -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -lzmq $(CODE_COVERAGE_LIBS)
-lhiredis -lswsscommon -lnl-genl-3 -lnl-nf-3 -lnl-route-3 -lnl-3 -lpthread -L$(top_srcdir)/lib/.libs -lsairedis -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -lzmq $(CODE_COVERAGE_LIBS) $(VPP_LIBS)

TESTS = tests
2 changes: 1 addition & 1 deletion unittest/vslib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ tests_SOURCES = main.cpp \

tests_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) -fno-access-control
tests_LDADD = $(LDADD_GTEST) $(top_srcdir)/vslib/libSaiVS.a -lhiredis -lswsscommon -lnl-genl-3 -lnl-nf-3 -lnl-route-3 -lnl-3 \
-lpthread -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -lzmq $(CODE_COVERAGE_LIBS)
-lpthread -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -lzmq $(CODE_COVERAGE_LIBS) $(VPP_LIBS)

TESTS = tests
20 changes: 16 additions & 4 deletions vslib/HostInterfaceInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ HostInterfaceInfo::HostInterfaceInfo(
{
SWSS_LOG_ENTER();

m_run_thread = true;

m_e2t = std::make_shared<std::thread>(&HostInterfaceInfo::veth2tap_fun, this);
m_t2e = std::make_shared<std::thread>(&HostInterfaceInfo::tap2veth_fun, this);
m_run_thread = false;
}

HostInterfaceInfo::~HostInterfaceInfo()
Expand Down Expand Up @@ -77,6 +74,21 @@ HostInterfaceInfo::~HostInterfaceInfo()
SWSS_LOG_NOTICE("joined threads for hostif: %s", m_name.c_str());
}

void HostInterfaceInfo::runThreads()
{
SWSS_LOG_ENTER();

if (m_run_thread)
{
return;
}

m_run_thread = true;

m_e2t = std::make_shared<std::thread>(&HostInterfaceInfo::veth2tap_fun, this);
m_t2e = std::make_shared<std::thread>(&HostInterfaceInfo::tap2veth_fun, this);
}

void HostInterfaceInfo::async_process_packet_for_fdb_event(
_In_ const uint8_t *data,
_In_ size_t size) const
Expand Down
2 changes: 2 additions & 0 deletions vslib/HostInterfaceInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ namespace saivs
bool uninstallTap2EthFilter(
_In_ std::shared_ptr<TrafficFilter> filter);

void runThreads();

private:

void veth2tap_fun();
Expand Down
50 changes: 48 additions & 2 deletions vslib/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
AM_CXXFLAGS = $(SAIINC) -I$(top_srcdir)/lib -I/usr/include/libnl3

if USE_VPP
AM_CXXFLAGS += -Ivpp -DUSE_VPP
endif

CFLAGS_COMMON= -fPIC -pipe -Wall -Wcast-align -Wcast-qual -Wconversion -Wdisabled-optimization -Werror -Wextra -Wfloat-equal -Wformat=2 -Wformat-nonliteral -Wformat-security -Wformat-y2k -Wimport -Winit-self -Wno-inline -Winvalid-pch -Wmissing-field-initializers -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn -Wno-aggregate-return -Wno-padded -Wno-switch-enum -Wno-unused-parameter -Wpacked -Wpointer-arith -Wredundant-decls -Wshadow -Wstack-protector -Wstrict-aliasing=3 -Wswitch -Wswitch-default -Wunreachable-code -Wunused -Wvariadic-macros -Wwrite-strings -Wno-switch-default -Wconversion -Wno-psabi -Wcast-align=strict

# TODO those are currently disabled flags from C files untill all warnings will be fixed
DISABLED_FLAGS= \
-Wno-unused-function \
-Wno-sign-conversion \
-Wno-conversion \
-Wno-unused-variable \
-Wno-sign-compare \
-Wno-shadow \
-Wno-discarded-qualifiers \
-Wno-redundant-decls \
-Wno-cast-align \
-Wno-pointer-sign \
-Wno-stringop-truncation \
-Wno-cast-qual
Comment on lines +10 to +22
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yue-fred-gao can you look at those warnings? i disabled those since *c files in vppxlate/*c developer produce a lot of warnings which are treated as errors by our convention, and for many of them, i don't know what was actual developer intention, and without any unittests provided on that i don't want to change any of this code

@yue-fred-gao will you be able to help to eliminate those warnings ?

also what is a purpose of vppxlate directory? is there any purpose of that on other repo? or this is specifically designed to for vpp in sairedis/buildimage ? is there specific requirement that this code needs to be in C and not cpp ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created an issue (sonic-net/sonic-platform-vpp#149) to track this.
vppxlate is the vpp API adaptation layer. It is specifically for vpp. There is some history that I don't know but I guess vpp APIs are C code so C is used here.


# TODO fix multiple paths
AM_CFLAGS = -I/usr/include/vpp_plugins -fPIC $(CFLAGS_COMMON) $(DISABLED_FLAGS) -I.

lib_LTLIBRARIES = libsaivs.la

noinst_LIBRARIES = libSaiVS.a

# TODO: move vppxlate to proper lib and namespaces

libSaiVS_a_SOURCES = \
Buffer.cpp \
ContextConfigContainer.cpp \
Expand Down Expand Up @@ -61,6 +87,26 @@ libSaiVS_a_SOURCES = \
VirtualSwitchSaiInterfaceFdb.cpp \
VirtualSwitchSaiInterfacePort.cpp

if USE_VPP
libSaiVS_a_SOURCES +=\
vpp/SaiObjectDB.cpp \
vpp/SwitchVpp.cpp \
vpp/SwitchVppAcl.cpp \
vpp/SwitchVppNexthop.cpp \
vpp/SwitchVppUtils.cpp \
vpp/SwitchVppFdb.cpp \
vpp/SwitchVppRif.cpp \
vpp/SwitchVppBfd.cpp \
vpp/SwitchVppHostif.cpp \
vpp/SwitchVppRoute.cpp \
vpp/SwitchVppNbr.cpp \
vpp/TunnelManager.cpp \
vpp/vppxlate/SaiVppXlate.c \
vpp/vppxlate/SaiVppStats.c \
vpp/vppxlate/SaiAclStats.c \
vpp/vppxlate/SaiIntfStats.c
endif

BUILT_SOURCES = sai_vs.cpp

sai_vs.cpp: ../stub.pl $(top_srcdir)/SAI/meta/saimetadata.c
Expand All @@ -76,12 +122,12 @@ libSaiVS_a_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) $(CODE_COVER

libsaivs_la_CPPFLAGS = $(CODE_COVERAGE_CPPFLAGS)
libsaivs_la_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) $(CODE_COVERAGE_CXXFLAGS)
libsaivs_la_LIBADD = -lhiredis -lswsscommon libSaiVS.a $(CODE_COVERAGE_LIBS)
libsaivs_la_LIBADD = -lhiredis -lswsscommon libSaiVS.a $(CODE_COVERAGE_LIBS) $(VPP_LIBS)

bin_PROGRAMS = tests

tests_SOURCES = tests.cpp
tests_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON)
tests_LDADD = -lhiredis -lswsscommon -lpthread libsaivs.la -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -lzmq
tests_LDADD = -lhiredis -lswsscommon -lpthread libsaivs.la -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -lzmq $(VPP_LIBS)

TESTS = tests
5 changes: 5 additions & 0 deletions vslib/SwitchConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ bool SwitchConfig::parseSwitchType(
*/
switchType = SAI_VS_SWITCH_TYPE_NVDA_MBF2H536C;
}
else if (st == SAI_VALUE_VS_SWITCH_TYPE_VPP)
{
switchType = SAI_VS_SWITCH_TYPE_VPP;
}
else
{
std::vector<std::string> vals {
Expand All @@ -99,6 +103,7 @@ bool SwitchConfig::parseSwitchType(
SAI_VALUE_VS_SWITCH_TYPE_MLNX2700,
SAI_VALUE_VS_SWITCH_TYPE_NVDA_MBF2H536C,
SAI_VALUE_VS_SWITCH_TYPE_DPU_SIMU_2P
SAI_VALUE_VS_SWITCH_TYPE_VPP,
};

SWSS_LOG_ERROR("unknown switch type: '%s', expected (%s)",
Expand Down
2 changes: 2 additions & 0 deletions vslib/SwitchConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ namespace saivs

SAI_VS_SWITCH_TYPE_NVDA_MBF2H536C,

SAI_VS_SWITCH_TYPE_VPP,

} sai_vs_switch_type_t;

typedef enum _sai_vs_boot_type_t
Expand Down
2 changes: 1 addition & 1 deletion vslib/SwitchState.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace saivs

public:

sai_status_t getStatsExt(
virtual sai_status_t getStatsExt(
_In_ sai_object_type_t obejct_type,
_In_ sai_object_id_t object_id,
_In_ uint32_t number_of_counters,
Expand Down
24 changes: 13 additions & 11 deletions vslib/SwitchStateBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ namespace saivs
_In_ const sai_system_port_config_t *sys_port_cfg_list);

sai_status_t create_voqs();

sai_status_t create_voq_per_sysport(
_In_ sai_object_id_t sys_port_id);

sai_status_t set_system_port_list();

public:
Expand Down Expand Up @@ -294,7 +296,7 @@ namespace saivs
_In_ sai_bulk_op_error_mode_t mode,
_Out_ sai_status_t *object_statuses);

virtual sai_status_t queryAttrEnumValuesCapability(
virtual sai_status_t queryAttrEnumValuesCapability(
_In_ sai_object_id_t switch_id,
_In_ sai_object_type_t object_type,
_In_ sai_attr_id_t attr_id,
Expand Down Expand Up @@ -324,7 +326,7 @@ namespace saivs
_In_ const std::string &serializedObjectId,
_In_ const sai_attribute_t* attr);

private:
protected:

sai_object_type_t objectTypeQuery(
_In_ sai_object_id_t objectId);
Expand All @@ -334,7 +336,7 @@ namespace saivs

public:

void processFdbEntriesForAging();
virtual void processFdbEntriesForAging();

private: // fdb related

Expand Down Expand Up @@ -373,16 +375,16 @@ namespace saivs

protected: // custom port

sai_status_t createPort(
virtual sai_status_t createPort(
_In_ sai_object_id_t object_id,
_In_ sai_object_id_t switch_id,
_In_ uint32_t attr_count,
_In_ const sai_attribute_t *attr_list);

sai_status_t removePort(
virtual sai_status_t removePort(
_In_ sai_object_id_t objectId);

sai_status_t setPort(
virtual sai_status_t setPort(
_In_ sai_object_id_t objectId,
_In_ const sai_attribute_t* attr);

Expand Down Expand Up @@ -460,14 +462,14 @@ namespace saivs
sai_status_t removeHostif(
_In_ sai_object_id_t objectId);

sai_status_t vs_remove_hostif_tap_interface(
virtual sai_status_t vs_remove_hostif_tap_interface(
_In_ sai_object_id_t hostif_id);

sai_status_t vs_create_hostif_tap_interface(
virtual sai_status_t vs_create_hostif_tap_interface(
_In_ uint32_t attr_count,
_In_ const sai_attribute_t *attr_list);

bool hostif_create_tap_veth_forwarding(
virtual bool hostif_create_tap_veth_forwarding(
_In_ const std::string &tapname,
_In_ int tapfd,
_In_ sai_object_id_t port_id);
Expand Down Expand Up @@ -502,7 +504,7 @@ namespace saivs
_In_ sai_port_oper_status_t status,
_In_ bool force);

bool hasIfIndex(
virtual bool hasIfIndex(
_In_ int ifIndex) const;

bool vs_get_oper_speed(
Expand Down Expand Up @@ -538,7 +540,7 @@ namespace saivs

protected:

sai_status_t setAclEntry(
virtual sai_status_t setAclEntry(
_In_ sai_object_id_t entry_id,
_In_ const sai_attribute_t* attr);

Expand Down
2 changes: 2 additions & 0 deletions vslib/SwitchStateBaseHostif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,8 @@ bool SwitchStateBase::hostif_create_tap_veth_forwarding(
port_id,
m_switchConfig->m_eventQueue);

m_hostif_info_map[tapname]->runThreads();

SWSS_LOG_NOTICE("setup forward rule for %s succeeded", tapname.c_str());

return true;
Expand Down
Loading
Loading