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

Feat/lua plugin #577

Open
wants to merge 10 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
34 changes: 31 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ option(USE_SSL "Build with SIPS support" OFF)
option(USE_SCTP "Build with SCTP support" OFF)
option(USE_PCAP "Build with PCAP playback support" OFF)
option(USE_GSL "Build with improved statistical support" ON)
option(USE_LUA "Build with lua support for plugins" ON)

file(GLOB all_SRCS
"${PROJECT_SOURCE_DIR}/src/*.cpp"
Expand Down Expand Up @@ -74,25 +75,50 @@ if(USE_SSL)
add_definitions("-DUSE_TLS -DUSE_OPENSSL")
endif()

if (USE_LUA)
add_definitions("-DUSE_LUA")
endif()

if(USE_PCAP)
add_definitions("-DPCAPPLAY")
find_library(PCAP_LIBRARY pcap)
if(PCAP_LIBRARY)
add_definitions("-DPCAPPLAY")
else()
message(FATAL_ERROR "libpcap not found")
endif()
endif(USE_PCAP)

if(USE_GSL)
find_library(GSL_LIBRARY gsl)
if(GSL_LIBRARY)
add_definitions("-DHAVE_GSL")
endif(GSL_LIBRARY)
else()
message(FATAL_ERROR "libgsl not found")
endif()
endif(USE_GSL)

if(USE_SCTP)
add_definitions("-DUSE_SCTP")
find_library(SCTP_LIBRARY sctp)
if(SCTP_LIBRARY)
add_definitions("-DUSE_SCTP")
else()
message(FATAL_ERROR "libsctp not found")
endif()
endif(USE_SCTP)

list(REMOVE_ITEM all_SRCS
"${PROJECT_SOURCE_DIR}/src/myapp.cpp")

list(REMOVE_ITEM all_SRCS
"${PROJECT_SOURCE_DIR}/src/sipp-rpc_xdr.c")

# add the executable
link_directories("/usr/local/lib")
add_executable(sipp ${all_SRCS} "${PROJECT_SOURCE_DIR}/src/sipp.cpp")
add_executable(sipp_unittest EXCLUDE_FROM_ALL ${all_SRCS} "${PROJECT_SOURCE_DIR}/src/sipp_unittest.cpp")
target_link_libraries(sipp -rdynamic -fPIC -dl -llua5.3 )
add_library(myapp SHARED ${PROJECT_SOURCE_DIR}/src/myapp.cpp ${PROJECT_SOURCE_DIR}/src/sipp-rpc_xdr.c )
target_link_libraries(myapp -rdynamic -fPIC -dl -llua5.3 -lcurl -lrt -lcrypto -lperconaserverclient )
target_compile_definitions(sipp_unittest PUBLIC "-DGTEST")

# add version
Expand Down Expand Up @@ -161,6 +187,8 @@ else()
message(FATAL_ERROR "libcurses / libncurses was not found; please install devel package")
endif()

include_directories(${LUA_LIBRARY_INCLUDE_DIR} ${CURL_LIBRARY_INCLUDE_DIR} ${MYSQL_LIBRARY_INCLUDE_DIR})

find_library(RT_LIBRARY NAMES rt)
if(RT_LIBRARY)
target_link_libraries(sipp ${RT_LIBRARY})
Expand Down
204 changes: 204 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
@AM_GIT_VERSION@

bin_PROGRAMS = sipp

TESTS = sipp_unittest

check_PROGRAMS = $(TESTS)

DEFAULT_INCLUDES = -I. -I$(top_builddir)/include -I/usr/include/lua5.3 -I/usr/include/x86_64-linux-gnu/curl -I/usr/include/mysql
AM_CFLAGS=-I$(srcdir)/include -Wall -pedantic
AM_CXXFLAGS=-I$(srcdir)/include -Wall -pedantic

CLEANFILES =
EXTRA_DIST = \
$(srcdir)/src/fortune.cpp \
$(srcdir)/LICENSE.txt \
$(srcdir)/README.md \
$(srcdir)/THANKS \
$(srcdir)/sipp.dtd \
$(srcdir)/cpplint.py

if HAVE_OPENSSL
DEFS += -DUSE_OPENSSL
ssl_incl = \
include/sslcommon.h
ssl_SOURCES = \
$(ssl_incl) \
src/sslinit.c \
src/sslthreadsafe.c
endif

if HAVE_PCAP
DEFS += -DPCAPPLAY
pcap_incl = \
include/prepare_pcap.h \
include/send_packets.h
pcap_SOURCES = \
$(pcap_incl) \
src/prepare_pcap.c \
src/send_packets.c
endif

if HAVE_RTP
DEFS += -DRTP_STREAM
rtp_SOURCES = \
src/rtpstream.cpp \
include/rtpstream.hpp
endif

if HAVE_SCTP
DEFS += -DUSE_SCTP
endif

if HAVE_GSL
DEFS += -DHAVE_GSL
endif

if HAVE_EPOLL
DEFS += -DHAVE_EPOLL
endif

common_incl = \
include/comp.h \
include/infile.hpp \
include/listener.hpp \
include/logger.hpp \
include/md5.h \
include/message.hpp \
include/milenage.h \
include/call_generation_task.hpp \
include/ratetask.hpp \
include/reporttask.hpp \
include/rijndael.h \
include/scenario.hpp \
include/sip_parser.hpp \
include/screen.hpp \
include/socket.hpp \
include/socketowner.hpp \
include/stat.hpp \
include/strings.hpp \
include/task.hpp \
include/time.hpp \
include/variables.hpp \
include/watchdog.hpp \
include/xp_parser.h \
include/sipp_rpc.h \
include/actions.hpp \
include/call.hpp \
include/auth.hpp \
include/deadcall.hpp

common_SOURCES = \
src/actions.cpp \
src/auth.cpp \
src/comp.c \
src/call.cpp \
src/apifunc.cpp \
src/customfuncs.cpp \
src/deadcall.cpp \
src/infile.cpp \
src/listener.cpp \
src/logger.cpp \
src/md5.c \
src/message.cpp \
src/milenage.c \
src/call_generation_task.cpp \
src/ratetask.cpp \
src/reporttask.cpp \
src/rijndael.c \
src/scenario.cpp \
src/sip_parser.cpp \
src/screen.cpp \
src/socket.cpp \
src/socketowner.cpp \
src/stat.cpp \
src/strings.cpp \
src/task.cpp \
src/time.cpp \
src/variables.cpp \
src/watchdog.cpp \
src/xp_parser.c \
src/sipp-rpc_xdr.c \
$(common_incl) \
$(ssl_SOURCES) \
$(pcap_SOURCES) \
$(rtp_SOURCES)

sipp_SOURCES = \
$(common_SOURCES) \
src/sipp.cpp \
include/sipp.hpp

sipp_CFLAGS = $(AM_CFLAGS) @GSL_CFLAGS@
sipp_CXXFLAGS = $(AM_CXXFLAGS) @GSL_CXXFLAGS@
sipp_LDADD = @LIBOBJS@ @GSL_LIBS@

# call.cpp and sipp.cpp use version.h; see AM_GIT_VERSION.
src/call.cpp: include/version.h
src/sipp.cpp: include/version.h

# Make a shared library to use as a plugin
myapp: myapp.so

src/myapp.o: src/myapp.cpp
$(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) -rdynamic -fPIC $(CPPFLAGS) $(sipp_CXXFLAGS) $(CXXFLAGS) -c src/myapp.cpp -o src/myapp.o
echo "done building shared custom app"


myapp.so: src/myapp.o
g++ -rdynamic -fPIC -shared $(SO_OPTION) src/myapp.o $(LIBS) -o $@


gtest_SOURCES = \
gtest/src/gtest-death-test.cc \
gtest/src/gtest-filepath.cc \
gtest/src/gtest-internal-inl.h \
gtest/src/gtest-port.cc \
gtest/src/gtest-printers.cc \
gtest/src/gtest-test-part.cc \
gtest/src/gtest-typed-test.cc \
gtest/src/gtest.cc \
gmock/src/gmock-internal-utils.cc \
gmock/src/gmock-matchers.cc

sipp_unittest_SOURCES = \
$(common_SOURCES) \
src/sipp_unittest.cpp \
src/xp_parser_ut.cpp \
$(gtest_SOURCES)

sipp_unittest_CFLAGS = $(AM_CFLAGS) -DGTEST=1 \
-I$(srcdir)/gtest/include \
-I$(srcdir)/gmock/include \
-I$(srcdir)/gtest \
-I$(srcdir)/gmock \
@GSL_CFLAGS@

sipp_unittest_CXXFLAGS = $(AM_CXXFLAGS) -DGTEST=1 \
-I$(srcdir)/gtest/include \
-I$(srcdir)/gmock/include \
-I$(srcdir)/gtest \
-I$(srcdir)/gmock \
@GSL_CXXFLAGS@

sipp_unittest_LDADD = @LIBOBJS@ @GSL_LIBS@

# Ensure that after a reconfigure the source is cleaned.
.autoclean: Makefile
make clean
echo > .autoclean
BUILT_SOURCES = .autoclean

if HAVE_HELP2MAN
man_MANS = sipp.1
CLEANFILES += $(man_MANS)

sipp.1: ./sipp $(sipp_SOURCES)
$(HELP2MAN) --output=$@ -v "-v" --no-info \
--name='SIP testing tool and traffic generator' \
./sipp
else
sipp.1:
@echo "Warning: help2man not available, no man page is created."
endif
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ and for now, it only works on Alpine Linux.

To build a static binary, pass `-DBUILD_STATIC=1` to cmake.

Note for trustid - normally we build with: build.sh --with-openssl

# Support

I try and be responsive to issues raised on Github, and there's [a
Expand Down
15 changes: 15 additions & 0 deletions README_DEMO_PLUGIN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
A demo of the plugin functionality of sipp with a simple lua script can be found in the docs directory.
1. sipp_demo.sh - this will executing uas_w_script.xml
2. uas_w_script.xml

Just send a call to it to see it utlize a plugin

To create and use the plugin -
1. enable LUA and then build sipp with whatever other options you want to use.
example:
cmake . -DCMAKE_BUILD_TYPE=Debug -DUSE_GSL=0 -DUSE_SSL=1 -DUSE_SCTP=0 -DUSE_PCAP=0 -DUSE_LUA=1
2. Use the -plugin option to specify the location of your plugin. There is a demo plugin in myapp.cpp which can be used the create libmyapp.so
3. The demo plugin adds functionality to interpret the new sipp flags -lua_file and -pid to record the pid of the file and to specify which lua script will be used
4. The xml to call the lua script and retrieve values can be found in the xml file uas_w_script.xml


Loading