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

Conversation

nfranzmeier
Copy link

This feature expands on the SIPP plugin capability so we can run lua scripts from inside SIPP and add/change/delete SIPP variables to be used the XML scripts, adds the ability to add new command line options, adds the capability to use rpc calls to get stats and fixes a memory leak. This was all based on the 3.6 branch.

Here's a summary

  1. Allow a user to create new "EXEC" commands which in this case are used to allow SIPP to interwork with a lua script to allow lua to add functionality to a running SIPP script to do things like lookup values in a DB, do RESTful API queries etc. which can change the values of SIPP variables and then send them back into the running script. In this example the lua function is called my_function.

example: <exec command="luathread@my_function calling [$5] called [$2] />
<log message="retkey [$retkey] calling = [$calling] called = [$called] />

!-- Do a loop looking for the data to be done -->

<nop>
    <action>
            <!-- Delete the shared memory because we're done -->
            <log message="finished!" />
            <log message="luaread@[$retkey] 1" />
            <exec command="luaread@[$retkey] 1" />
    </action>

When the luaread is complete, the values created in the lua script will be available to the running SIPP script for use in the XML.

  1. In order to use a lua script the sipp command line, additional functionality can be added to the command line - also in the plugin. This is done by adding a new dlsym function: "handle_args" which is passed the current SIPP command being processed along with it's argument.

Here is an example of how it will be called: note the -plugin and -lua_file options as well as the -pid_file option.

sipp -plugin libmyapp.so -lua_file sipp_sa.lua -pid_file /var/run/sipp_pg.pid -aa -ringbuffer_files 1000 -ringbuffer_size 50000000 -trace_msg -trace_logs -trace_err -message_file /var/log/sipp/sipp_message_sa.log -message_overwrite false -error_file /var/log/sipp/sipp_error_sa.log -error_overwrite false -calldebug_file /var/log/sipp/log/sipp_debug_sa.log -calldebug_overwrite false -log_file /var/log/sipp/sipp_sa.log -log_overwrite false -m 1000000 -l 1 -i 172.20.2.35 -p 5060 -s 8665988936 -nd -sf ./sa.xml 172.29.31.14

  1. Note that the dlsym "init" has also been expanded to pass in the dlsym handle and the command line args and count so it can also process arguments. The init dlsym command in our example is used to populate an internal table with various API function pointers which contains the new commands luarun - which will fork/exec a lua script, luathread which will run a lua script in a thread and then the results can be obtained using "luaread" as in the XML example above (by polling). See the appDllLoad() function in myapp.cpp.

  2. Another dlsym command was added to allow overriding the automatic handling of messages like OPTIONS in case you want to add SIP headers etc. to those responses.

  3. Added the ability to do rpc calls so that various call stats can be retrieved by other programs or even from the command line using a rpc client program included in the examples directory - sa_ctl.
    For example: sa_ctl get_callcount will retrieve the call counts

  4. Fixed memory leak associated with having AUTO RESPONSE on - leaked during OPTIONS messages

orgads and others added 10 commits October 31, 2021 11:28
Fixes build on CentOS7. Closes SIPp#540 reported by @Xyders.
	a) a plugin which can be built via make myapp which adds the ability to run lua scripts in a thread using exec command luarunthread@function_name arg1 arg2 arg3 etc.
	   and then return a retkey which holds the key to shared memory which can read another variable msgDone to see if the memory has been updated with the results
	   from the thread.
	   example:  <exec command="luathread@my_function calling [$5] called [$2] />
		<log  message="retkey [$retkey] calling = [$calling] called = [$called] />

!-- Do a loop looking for the data to be done -->

 <label id="start_of_loop"/>
    <pause milliseconds="100" />
    <!-- retrieve our variables back from our previous read -->
    <nop>
             <action>
                <log message="luaread@[$retkey] 0" />
                <exec command="luaread@[$retkey] 0" />
                <strcmp assign_to="result" variable="msgDone" value="0" />
                <log message="result for msgDone  check = [$msgDone]"/>
             </action>
   </nop>

  <!-- When we're done processing jump to finished else keep looping -->
  <nop next="finished" test="result"/>

  <!-- Increment the counter and continue looping up to 10 times-->
  <nop>
    <action>
      <add assign_to="counter" value="1"/>
      <test assign_to="flag_limit" variable="counter"
                compare="greater_than_equal" value="100"/>
        <log message="flag_limit=([$flag_limit])" />
    </action>
  </nop>

  <nop next="finished" test="flag_limit" />

  <nop next="start_of_loop"/>

 <label id="finished" />

    <nop>
        <action>
                <!-- Delete the shared memory because we're done -->
                <log message="finished!" />
                <log message="luaread@[$retkey] 1" />
                <exec command="luaread@[$retkey] 1" />
        </action>
  </nop>

	b) The ability to do rpc calls
2. Fixed memory leak associated with having AUTO RESPONSE on - leaked during OPTIONS messages
2. Moved the custom functionality for lua scripting, rpc calls and argument processing into a plugin
3. Added some code to cause sipp to include the lualib if the USE_LUA=1 flag is set when doing the CMAKE - this is so the lua environment can be accessible to lua scripts running in the plugin
… affect any threads started in the plugin

2. Changes some fprintf stderr's to ERROR messages in myapp.cpp
…s so sipp can be customized more

2. Added an example to match the rpc code in myapp.cpp so rpc commands can be exercised from the command line to get call stats and set logging options
@lemenkov
Copy link
Member

lemenkov commented Apr 8, 2024

I love the idea. Could you please rebase this PR on top of current master so we can proceed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants