ERLANG Module Seudin Kasumovic Edited by Seudin Kasumovic Copyright © 2015 Bicom Systems Ltd. __________________________________________________________________ Table of Contents 1. Admin Guide 1. Overview 2. Dependencies 2.1. Kamailio Modules 2.2. External Libraries or Applications 3. Parameters 3.1. no_cnodes (int) 3.2. cnode_alivename (str) 3.3. cnode_host (str) 3.4. erlang_nodename (str) 3.5. cookie (str) 3.6. trace_level (int) 3.7. rpc_reply_with_struct (int) 4. Exported pseudo variables 4.1. Overview 4.2. Attributes 4.3. $erl_atom(name) 4.4. $erl_list(name) 4.5. $erl_tuple(name) 4.6. $erl_pid(name) 4.7. $erl_ref(name) 4.8. $erl_xbuff(name) 5. Functions 5.1. erl_rpc(mod,fun,args,reply) 5.2. erl_reg_send(server,msg) 5.3. erl_send(pid,msg) 5.4. erl_reply(msg) 6. Event routes 6.1. Registered pseudo process 6.2. event_route[erlang:self] 2. Using Kamailio from Erlang 1. RPC calls from Erlang 3. Developer Guide 1. Available Functions 1.1. erl_load_api(erl_api) 1.2. rpc(reply,module,function,args) 1.3. reg_send(server,msg) 1.4. send(pid,msg) 1.5. reply(msg) 1.6. xavp2xbuff(xbuff,xavp) 1.7. xbuff2xavp(xavp,xbuff) List of Examples 1.1. Set no_cnodes parameter 1.2. Set cnode_alivename parameter 1.3. Set cnode_host parameter 1.4. Set erlang_nodename parameter 1.5. Set cookie parameter 1.6. Set trace_level parameter 1.7. Example of using attribute length 1.8. Example of using attributes type and format 1.9. Example set and print to log $erl_atom 1.10. Example of using $erl_list 1.11. Example of using erl_tuple 1.12. Example of using $erl_pid 1.13. Example of using erl_ref 1.14. Example of using $erl_xbuff 1.15. Example of using erl_rpc 1.16. Example of using erl_reg_send 1.17. Example of using erl_send 1.18. Example of use erl_reply 1.19. Example of registered process 1.20. Example of using default event route 2.1. Example of RPC call from erlang shell with no response 2.2. Example, check is line registered 2.3. Example get config variable 2.4. Example get dialog statistics 3.1. Example of using API Chapter 1. Admin Guide Table of Contents 1. Overview 2. Dependencies 2.1. Kamailio Modules 2.2. External Libraries or Applications 3. Parameters 3.1. no_cnodes (int) 3.2. cnode_alivename (str) 3.3. cnode_host (str) 3.4. erlang_nodename (str) 3.5. cookie (str) 3.6. trace_level (int) 3.7. rpc_reply_with_struct (int) 4. Exported pseudo variables 4.1. Overview 4.2. Attributes 4.3. $erl_atom(name) 4.4. $erl_list(name) 4.5. $erl_tuple(name) 4.6. $erl_pid(name) 4.7. $erl_ref(name) 4.8. $erl_xbuff(name) 5. Functions 5.1. erl_rpc(mod,fun,args,reply) 5.2. erl_reg_send(server,msg) 5.3. erl_send(pid,msg) 5.4. erl_reply(msg) 6. Event routes 6.1. Registered pseudo process 6.2. event_route[erlang:self] 1. Overview Erlang is a general-purpose programming language and runtime environment. Erlang has built-in support for concurrency, distribution and fault tolerance. This module provides interact with Erlang node. The module allows sending, receiving Erlang messages and RPC calls between each other. 2. Dependencies 2.1. Kamailio Modules 2.2. External Libraries or Applications 2.1. Kamailio Modules The following modules must be loaded before this module: * None 2.2. External Libraries or Applications The following libraries or applications must be installed before running Kamailio with this module loaded: * ei - Erlang interface C library. The routines for handling the Erlang binary term format and communicate with with distributed Erlang. For more details see Erlang Interface Reference Manual * epmd - Erlang Port Mapper Daemon. This daemon acts as a name server on all hosts involved in distributed Erlang computations. For more details see Erlang Port Mapper Daemon Manual. epmd must running on the same host where Kamailio is running. Erlang does not need to be installed on the same host where Kamailio is running. 3. Parameters 3.1. no_cnodes (int) 3.2. cnode_alivename (str) 3.3. cnode_host (str) 3.4. erlang_nodename (str) 3.5. cookie (str) 3.6. trace_level (int) 3.7. rpc_reply_with_struct (int) 3.1. no_cnodes (int) Number of erlang C node processes to be started to handle the communication tasks. A C node is a C program written to act as a hidden node in a distributed Erlang system. Default value is 1. Example 1.1. Set no_cnodes parameter ... modparam("erlang", "no_cnodes", 2) ... 3.2. cnode_alivename (str) alivename is the registered name of the Kamailio process. Note, if the no_cnodes greater then 1, then alivename of Kamailio process will be suffixed with number. Example 1.2. Set cnode_alivename parameter ... modparam("erlang", "cnode_alivename", "proxy") ... 3.3. cnode_host (str) C node host is the name of the machine we're running on. If long names are to be used, it should be fully qualified. Example 1.3. Set cnode_host parameter ... modparam("erlang", "cnode_host", "kamailio.lan") ... 3.4. erlang_nodename (str) The format of the node name is an name@host where name is the name given by the user and host is the full host name if long names are used, or the first part of the host name if short names are used. Example 1.4. Set erlang_nodename parameter ... modparam("erlang", "erlang_nodename", "node1@erlang.lan") ... 3.5. cookie (str) Each node has its own magic cookie. When a nodes tries to connect to another node, the magic cookies are compared If they do not match, the connected node rejects the connection. Example 1.5. Set cookie parameter ... modparam("erlang", "cookie", "secretcookie") ... 3.6. trace_level (int) Used to set tracing on the distribution. The parameter is different verbosity level. A higher level means more information. Useful in development, but in production should be disabled. The different tracelevels has the following messages: 1. Verbose error messages 2. Above messages and verbose warning messages 3. Above messages and progress reports for connection handling 4. Above messages and progress reports for communication 5. Above messages and progress reports for data conversion Default value is 0, no verbose is set. To see trace log on stdout, Kamailio must be started with -E option. Example 1.6. Set trace_level parameter ... modparam("erlang", "trace_level", 5) ... 3.7. rpc_reply_with_struct (int) Prepend Erlang atom struct in RPC Kamailio reply where RPC struct is generated. Some libraries for converting erlang term in JSON require atom struct as first element in tuple to convert list of properties into javscript object. Default value is 0 (disabled). 4. Exported pseudo variables 4.1. Overview 4.2. Attributes 4.3. $erl_atom(name) 4.4. $erl_list(name) 4.5. $erl_tuple(name) 4.6. $erl_pid(name) 4.7. $erl_ref(name) 4.8. $erl_xbuff(name) 4.1. Overview Erlang provides a number of data types but not all of them are supported by Kamailio. This module provides several of them as pseudo variables. These pseudo variables allow user to create Erlang message or function arguments and receive result from Erlang node. Some Erlang variables can contain other data types, so we introduced several attributes to determine type, length, or get formatted output useful for debug, quick compare or put into the log. 4.2. Attributes Exported pseudo variable has several attributes to get type, length and formatted output readable by transformations or user. Pseudo variable by self determine variable type, but we need to know what type on some position is. * type get variable type. Possible types are: atom, integer, list, string, tuple, pid and ref. * length get length of list or tuple. * format Prints a term, in clear text. It tries to resemble the term printing in the Erlang shell. Example 1.7. Example of using attribute length ... xlogl("L_DEBUG","The number of elements in list L: $erl_list(L=>length)\n"); xlogl("L_DEBUG","The number of elements in tuple T: $erl_tuple(T=>length)\n"); ... > example of log output: DEBUG: