LogicApp
Logic Application Configuration
The N2SVCD Logic Application is an extensible, general-purpose application which runs Lua scripts to perform control logic. The scripts can be initiated by various inbound agents, via Lua Services.
Lua scripts running within LogicApp may perform additional actions by calling upon Lua Agents.
This page describes general information about configuring LogicApp
. Please
refer to the relevant Service or Agent
documentation for examples and API specifications for each of the different use-cases.
A sample LogicApp configuration entry is as follows:
<?xml version="1.0" encoding="utf-8"?>
<n2svcd>
...
<applications>
...
<application name="Logic" module="LogicApp">
<include>
<lib>../apps/logic/lib</lib>
</include>
<parameters>
<parameter name="trace_level" value="0"/>
<parameter name="edr_enabled" value="1"/>
<parameter name="edr_directory" value="/tmp/edr"/>
<parameter name="lua_script_dir" value="../../n2sip/demo/logic"/>
<parameter name="lua_script_check_secs" value="5"/>
<parameter name="lua_lib_path" value="../lua/lib/?.lua;../../n2sip/lua/lib/?.lua"/>
<parameter name="default_smpp_app_name" value="SMPP-Client-Tester"/>
<parameter name="default_rest_app_name" value="REST-CLIENT"/>
<parameter name="default_outcall_app_name" value="IVR"/>
</parameters>
<config>
<services>
<service module="IvrApp::IvrIncallLuaService" libs="../../n2sip/apps/ivr/lib">
<triggers>
<trigger called_prefix="800" script_name="800_digit_menu"/>
<trigger called_prefix="811" script_name="811_rest"/>
<trigger called_prefix="822" script_name="822_smpp"/>
<trigger called_prefix="900" script_name="900_mca"/>
</triggers>
</service>
<service module="RestServerApp::RestLuaService" libs="../apps/rest_s/lib"/>
</services>
<agents>
<agent module="RestClientApp::RestLuaAgent" libs="../apps/rest_c/lib"/>
<agent module="SMPPApp::SMPPLuaAgent" libs="../apps/smpp/lib"/>
<agent module="IvrApp::IvrOutcallLuaAgent" libs="../../n2sip/apps/ivr/lib"/>
</agents>
</config>
</application>
...
</application>
...
</n2svcd>
Configuration Details
In addition to the common Application configuration parameters,
the application
element attributes for a Logic Application instance may include the below. For details of the various parameter
types used, refer to Common Configuration.
Parameter Name | Type | XML Type | Description |
---|---|---|---|
module
|
String | Attribute |
[Required] LogicApp
|
include.lib
|
String | Element |
[Required] ../apps/logic/lib
|
parameters
|
Array | Element |
[Required] As per Common Configuration Application parameters .
|
.edr_prefix
|
String | Attribute |
As per common Application configuration for edr_prefix .(Default = n2logic )
|
.nil_marker
|
String | Attribute |
If configured, this becomes a special string which is used to represent nil within
Logic processing. Under normal processing, a table member with a nil value returned
from Lua logic will be ignored. If a nil_marker is configured then any undef value
present in n2svcd will have this string value when converted into Lua. Conversely
any time this string value is returned from Lua, it will be converted into undef
within n2svcd internal processing.(Default = none) |
.lua_lib_path
|
String | Attribute |
Additional paths to search when loading Lua libraries with the require statement.This has the same rules as the LUA_PATH environment variable, i.e. must use ?.lua .Multiple paths may be separated with a ; semicolon. This path will be added to the
Lua library path configured for the LuaApp.(Default = empty) |
.lua_clib_path
|
String | Attribute |
Additional paths to search when loading Lua C-libraries with the require statement.This has the same rules as the LUA_CPATH environment variable, i.e. must use ?.so .Multiple paths may be separated with a ; semicolon. This path will be added to the
Lua C-library path configured for the LuaApp.(Default = empty) |
.lua_script_dir
|
String | Attribute |
The list of directories containing the Lua scripts available for execution. Multiple
paths may be separated with a ; semicolon. If the same script exists in multiple
directories, then a warning will be generated and the earliest directory in the list
will take precedence.The service library is responsible for determining the name of the script file to load. Refer to the documentation for each individual service library for further details. (Default = /var/lib/n2svcd/lua_scripts )
|
.lua_script_check_secs
|
Integer | Attribute |
How often should we check the disk to see if a Lua script has changed? Setting this value to 0 will disable checking.
(Default = 60 )
|
.default_<action>_app_name
|
String | Attribute |
Agents will use a parameter of this form to configure the name of the Agent Application
which will perform its activity, e.g. default_rest_app_name is used by the
RestClientLuaAgent to specify which RestClientApp will handle outbound REST Client actions.
Refer to the documentation for the specific Lua Agent to determine which values it uses.(Default = Agent Actions cannot talk to Agent Applications) |
.<action>_app_name_<route>
|
String | Attribute |
Agents use the concept of "routes" to handle case such as the need to communicate
with more than one end-point. Refer to the documentation for the specific Lua Agent
for more information. (Default = Agent Actions use only the default route) |
config
|
Object | Element | This is a container for extended configuration for the LogicApp. |
.services
|
Array of service Objects
|
Element | Defines the configured Services for this LogicApp. At least one service must be defined in order to use the LogicApp. One LogicApp may handle more than one service. |
.agents
|
Array of agent Objects
|
Element | Defines the configured Agents for this LogicApp. Agents are not required in order to execute a LogicApp Lua Script, but they can extend the functionality available. |
Service Configuration
A Lua Service Library handles an inbound message from a Service Application and uses the contents of that message to:
- Determine which Lua script to execute, and
- Determine what arguments to supply to that executing Lua script.
When the Lua script completes, the Lua Service Library may send back a final response the originating application.
This section describes the common configuration for adding a Lua Service Library to the Logic Application. For more information on per-Service configuration, please refer to the individual documentation for each Service Library.
A service
entry within the services
element of the LogicApp configuration has
the following attributes:
Parameter Name | Type | XML Type | Description |
---|---|---|---|
module
|
String | Attribute | [Required] The module name containing the Lua Service Library code. |
libs
|
String | Attribute |
Optional library path to include when searching for the module for this Service Library.
|
Many Lua Service Libraries also define additional configuration elements within the
service
element. Refer to the per-Service Library documentation for details.
Agent Configuration
A Lua Agent is used to send messages to an AgentApp, typically for the purpose of communicating with external agents. The Lua script execution will suspend while the agent waits for its response.
This section describes the common configuration for adding a Lua Agent to the Logic Application. For more information on per-Agent configuration, please refer to the individual documentation for each Agent Library.
An agent
entry within the agents
element of the LogicApp configuration has
the following attributes:
Parameter Name | Type | XML Type | Description |
---|---|---|---|
module
|
String | Attribute | [Required] The module name containing the Lua Agent code. |
libs
|
String | Attribute |
Optional library path to include when searching for the module for this Agent.
|
A Lua Agent typically also requires the configuration of a default_<action>_app_name
entry
specifying the name of the AgentApp which will receive the messages sent by the Lua Agent.
Refer to the per-Agent documentation for details.
Message Handling
In addition to the common Application management messages, the LogicApp uses the following messages:
- DB Messages (
DB-REQUEST
outbound). - DIAMETER-C Messages (
DIAMETER-C-REQUEST
outbound). - FOX-C Messages (
FOX-C-REQUEST
outbound). - REST-C Messages (
REST-C-REQUEST
outbound). - REST-S Messages (
REST-S-REQUEST
inbound). - SMPP-C Messages (
SMPP-C-REQUEST
outbound). - SMPP-S Messages (
SMPP-S-REQUEST
inbound). - SOAP-C Messages (
SOAP-C-REQUEST
outbound). - SOAP-S Messages (
SOAP-S-REQUEST
inbound). - TCAP Messages (
TCAP-BEGIN
inbound).