SlideShare uma empresa Scribd logo
1 de 39
Baixar para ler offline
building rtc services with lua and kamailio
Daniel-Constantin Mierla
Co-Founder Kamailio Project
www.asipto.com
@miconda
๏ www.kamailio.org
๏ open source sip server
๏ aka sip router or sip proxy
๏ focus in scalability and flexibility
๏ sip (session initiation protocol)
๏ ietf open standard - rfc3261
๏ https://tools.ietf.org/html/rfc3261
© asipto.comFOSDEM 2017 - Brussels
๏ can be used for:
๏ voice (ip telephony - voip)
๏ video
๏ instant messaging
๏ presence
๏ other rtc (gaming, desktop sharing, …)
๏ secure communications (TLS), IPv4/IPv6
๏ quite similar packet structure to http
๏ adopted by ITU/3GPP (signaling for voice in 4G+)
© asipto.comFOSDEM 2017 - Brussels
SIP CALL
© asipto.com
INVITE
100 Trying
180 Ringing
200 OK
ACK
BYE
200 OK
MEDIA STREAMS
Alice Bob
Early Dialog
Establish Dialog
Start Media
Media Session Media Session
Establish Dialog
Initiate Dialog
Start Media
Destroy Dialog
Stop Media
Destroy Dialog
Stop Media
Waiting For UAC
Decision
FOSDEM 2017 - Brussels
voip call maps over sip dialog
sip dialog is a sequence of sip transactions
sip transaction is a sip request and one or many responses
SIP REQUEST
© asipto.comFOSDEM 2017 - Brussels
INVITE
INVITE sip:user@sipserver.com SIP/2.0Start line
Message headers
Message body
Via: SIP/2.0/UDP 10.10.10.10:5060;branch=z9hG4bKxy
From: "Me" <sip:me@sipserver.org>;tag=a012
To: "User" <sip:user@sipserver.org>
Call-ID: d@10.10.10.10
CSeq: 1 INVITE
Contact: <sip:10.10.10.10:5060>
User-Agent: SIPTelephone
Content-Type: application/sdp
Content-Length: 251
v=0
o=audio1 0 0 IN IP4 10.10.10.10
s=session
c=IN IP4 10.10.10.10
m=audio 54742 RTP/AVP 4 3
a=rtpmap:4 G723/8000
a=rtpmap:3 GSM/8000
SIP RESPONSE
© asipto.comFOSDEM 2017 - Brussels
INVITE
sip response == sip reply
SIP/2.0 200 OKStart line
Message headers
Message body
Via: SIP/2.0/UDP 10.10.10.10:5060;branch=z9hG4bKxy
From: "Me" <sip:me@sipserver.org>;tag=a012
To: "User" <sip:user@sipserver.org>;tag=b034
Call-ID: d@10.10.10.10
CSeq: 1 INVITE
Contact: <sip:10.10.10.20:5060>
User-Agent: SIPSoftPhone
Content-Type: application/sdp
Content-Length: 123
v=0
o=audio2 0 0 IN IP4 10.10.10.20
s=session
c=IN IP4 10.10.10.20
m=audio 62043 RTP/AVP 0 4
๏ the base role of kamailio
๏ routing SIP packets: requests and responses
© asipto.comFOSDEM 2017 - Brussels
alice bob
media server
gateway apps
FEATURES
© asipto.com
✤ Modular SIP Proxy, Registrar and Redirect server
✤ Designed for scalability and flexibility
✤ IPv4, IPv6, UDP, TCP, TLS, SCTP, WebSocket
✤ NAT Traversal, internal and external caching engines
✤ JSON, XMLRPC, HTTP APIs
✤ IMS Extensions, SIP-I/SIP-T, IM & Presence
✤ SQL and NoSQL backends
✤ Asynchronous processing (TCP/TLS, SIP routing), external event API
✤ Embedded interpreters (Lua, Perl, Python, .Net, Java)
✤ Load balancing, LCR, DID routing, Number portability, …
FOSDEM 2017 - Brussels
OWN CFG SCRIPTING LANGUAGE
#!KAMAILIO
debug=2
log_stderror=yes
listen=udp:127.0.0.1
loadmodule “rr.so”
loadmodule “sl.so”
loadmodule “pv.so”
loadmodule “textops.so”
loadmodule “siputils.so”
modparam(“rr”, “append_fromtag”, 1)
# load modules
request_route {
route(WITHINDLG);
if(is_method(“INVITE”)) {
$du = “sip:127.0.0.1:9”;
record_route();
forward();
exit;
}
sl_send_reply(“403”, “Not allowed”);
exit;
}
route[WITHINDLG] {
if(!has_totag()) return;
if(loose_route()) {
forward();
exit;
}
sl_send_reply(“404”, “Not here”);
exit;
}
๏ comments
๏ preprocessor directive
๏ core parameters
๏ custom core parameters
๏ load modules
๏ module parameters
๏ routing blocks
➡ expressions
➡ conditions
➡ actions
➡ control statements
➡ subroutes
© asipto.com
kamailio.cfg
FOSDEM 2017 - Brussels
KAMAILIO.CFG LANGUAGE
๏ initial design in 2001-2002
➡ targeting optimization for sip routing
๏ characteristics
➡ sort of pre-compilation at startup
➡ linear execution
➡ routing blocks similar to functions
➡ specific routing blocks executed on various events
๏ limitations
➡ only int and string values
➡ requires C coding (sometime lex and yacc) to extend it
➡ startup pre-compilation not designed for reload
© asipto.comFOSDEM 2017 - Brussels
LUA IN KAMAILIO
๏ https://www.lua.org
๏ app_lua module added in January 2010
➡ embedding the lua interpreter
➡ targeting execution of lua snippets
➡ using functions from inside routing blocks of kamailio.cfg
๏ exported a new module to lua - sr - with many submodule
➡ sr.hdr, sr.pv, sr.sl, …
๏ limitations
➡ it required C coding inside app_lua for extending the lua sr
module
© asipto.comFOSDEM 2017 - Brussels
https://www.kamailio.org/docs/modules/stable/modules/app_lua.html
EXECUTING LUA INSIDE KAMAILIO.CFG
© asipto.comFOSDEM 2017 - Brussels
…
function sr_append_fu_to_reply()
sr.hdr.append_to_reply("P-From: " .. sr.pv.get("$fu") .. "rn");
end
…
…
modparam("app_lua", "load", "/usr/local/etc/kamailio/lua/myscript.lua")
…
request_route {
…
if(!lua_run(“sr_append_fu_to_reply")) {
xdbg("SCRIPT: failed to execute lua function!n");
}
…
}
…
myscript.lua
kamailio.cfg
interpreter
http
jsonrpc
sip
custom
json
xml
serialization
document
apps
transport control
json
jansson
rtjson
xmlops
transformations
utils
http_client
jsonrpc-c
evapi
uac
native
lua
python
javascript
perl - .net - java
© asipto.com
OVERCOMING LIMITATIONS
๏ main kamailio.cfg scripting limitations
➡ reload and language extensions
๏ kamailio.cfg sections at runtime
➡ passive: global parameters and module sections (attributes)
➡ active: routing blocks (actions)
๏ solution - kamailio v5.0
➡ allow use of lua for the entire active part (actions)
© asipto.comFOSDEM 2017 - Brussels
kemi
kamailio embedded interface
a framework that allows selecting
your favourite scripting language
for writing sip routing rules
ROUTING LOGIC
USING DIFFERENT
INTERPRETERS
FOSDEM 2017 - Brussels © asipto.com
KAMAILIO 5.0
KEMI & KAMAILIO.CFG
© asipto.com
• not affected
➡ core parameters
➡ loading modules
➡ module parameters
• new
➡ specify the language for routing rules (routing blocks)
➡ cfgengine=“language”
➡ at this moment, language can be: native, lua, javascript, python
➡ default is ‘native’
➡ ‘lua’ requires ‘app_lua’ module
➡ ‘python’ requires ‘app_python’ module
➡ ‘javascript’ requires ‘app_jsdt’ module
FOSDEM 2017 - Brussels
KEMI & LUA
๏ new lua module
➡ KSR
๏ characteristics
➡ automatic exports of new functions to KSR
➡ no C coding anymore in app_lua
➡ routing blocks entirely written in lua
๏ backward compatible
➡ sr module still available
➡ embedded execution inside kamailio.cfg still possible
© asipto.comFOSDEM 2017 - Brussels
NATIVE VS. LUA
© asipto.comFOSDEM 2017 - Brussels
request_route {
# per request initial checks
route(REQINIT);
# NAT detection
route(NATDETECT);
# CANCEL processing
if (is_method("CANCEL")) {
if (t_check_trans()) {
route(RELAY);
}
exit;
}
# handle requests within SIP dialogs
route(WITHINDLG);
function ksr_request_route()
-- per request initial checks
ksr_route_reqinit();
-- NAT detection
ksr_route_natdetect();
-- CANCEL processing
if KSR.pv.get("$rm") == "CANCEL" then
if KSR.tm.t_check_trans()>0 then
ksr_route_relay();
end
return 1;
end
-- handle requests within SIP dialogs
ksr_route_withindlg();
NATIVE VS. LUA
© asipto.comFOSDEM 2017 - Brussels
# Caller NAT detection
route[NATDETECT] {
force_rport();
if (nat_uac_test("19")) {
if (is_method("REGISTER")) {
fix_nated_register();
} else {
if(is_first_hop())
set_contact_alias();
}
setflag(FLT_NATS);
}
return;
}
-- Caller NAT detection
function ksr_route_natdetect()
KSR.force_rport();
if KSR.nathelper.nat_uac_test(19)>0 then
if KSR.pv.get("$rm")=="REGISTER" then
KSR.nathelper.fix_nated_register();
elseif KSR.siputils.is_first_hop()>0 then
KSR.nathelper.set_contact_alias();
end
KSR.setflag(FLT_NATS);
end
return 1;
end
SIP ROUTING IN LUA
© asipto.comFOSDEM 2017 - Brussels
https://github.com/kamailio/kamailio/blob/master/misc/examples/kemi/kamailio-basic-kemi-lua.lua
https://github.com/kamailio/kamailio/blob/master/misc/examples/kemi/kamailio-basic-kemi.cfg
๏ features
➡ detect scanning attacks and block DoS attacks
➡ authentication
➡ authorization
➡ accounting
➡ location service
➡ nat traversal
© asipto.com
DEVELOPER MODE
LUA FOR SIP ROUTING
FOSDEM 2017 - Brussels
IMPORTANT
๏ fast, very fast
➡ handle thousands of call setups per second
➡ critical feature
๏ dynamic
➡ KSR exports a matter of loaded native kamailio modules
๏ preserve experience
➡ stop execution or routing script
© asipto.comFOSDEM 2017 - Brussels
STOP ROUTING SCRIPT EXECUTION
๏ native kamailio.cfg
➡ exit
๏ lua
➡ libc exit results in killing kamailio - not wanted
๏ solution
➡ KSR.x.exit()
➡ workaround using lua error()
© asipto.comFOSDEM 2017 - Brussels
KSR.X.EXIT()
© asipto.comFOSDEM 2017 - Brussels
static str _sr_kemi_lua_exit_string = str_init("~~ksr~exit~~");
str* sr_kemi_lua_exit_string_get(void)
{
return &_sr_kemi_lua_exit_string;
}
static int sr_kemi_lua_exit (lua_State *L)
{
str *s;
LM_DBG("script exit calln");
s = sr_kemi_lua_exit_string_get();
lua_getglobal(L, "error");
lua_pushstring(L, s->s);
lua_call(L, 1, 0);
return 0;
}
KSR.X.EXIT()
© asipto.comFOSDEM 2017 - Brussels
…
ret = lua_pcall(_sr_L_env.LL, n, 0, 0);
if(ret!=0) {
txt.s = (char*)lua_tostring(_sr_L_env.LL, -1);
if(txt.s!=NULL) {
if(strcmp(txt.s[n], _sr_kemi_lua_exit_string.s[n]) !=0 ) {
LM_ERR("error from Lua: %sn", txt.s);
} else {
LM_DBG("ksr error call from Lua: %sn", txt.s);
}
} else {
LM_ERR("error from Lua: unknownn");
}
lua_pop(_sr_L_env.LL, 1);
if(n==1) {
return 1;
} else {
LM_ERR("error executing: %s (err: %d)n", func, ret);
return -1;
}
}
…
DYNAMIC & FAST
© asipto.com
void lua_sr_kemi_register_module(lua_State *L, str *mname, int midx)
{
int ret;
#define LUA_SR_SBUF_SIZE 1024
char sbuf[LUA_SR_SBUF_SIZE];
ret = snprintf(sbuf, LUA_SR_SBUF_SIZE-1,
"KSR.%.*s = {}n"
"KSR.%.*s.__index = function (table, key)n"
" return function (...)n"
" return KSR_MOD_C('%.*s', %d, key, ...)n"
" endn"
"endn"
"setmetatable(KSR.%.*s, KSR.%.*s)n",
mname->len, mname->s,
mname->len, mname->s,
mname->len, mname->s,
midx,
mname->len, mname->s,
mname->len, mname->s
);
ret = luaL_dostring(L, sbuf);
LM_DBG("pushing lua KSR.%.*s table definition returned %dn",
mname->len, mname->s, ret);
}
initial approach
FOSDEM 2017 - Brussels
DYNAMIC & FAST
© asipto.com
initial approach
FOSDEM 2017 - Brussels
๏ everything is a hash table in Lua
➡ including modules
๏ dive into internals
➡ change the indexing function of module hash table
DYNAMIC & FAST
© asipto.com
int sr_kemi_KSR_MOD_C(lua_State* L)
{
str mname;
int midx;
str fname;
mname.s = (char*)lua_tostring(L, 1);
midx = lua_tointeger(L, 2);
fname.s = (char*)lua_tostring(L, 3);
if(mname.s==NULL || fname.s==NULL) {
LM_ERR("null params: %p %pn", mname.s, fname.s);
return app_lua_return_false(L);
}
mname.len = strlen(mname.s);
fname.len = strlen(fname.s);
LM_DBG("module function execution of: %s.%s (%d)n",
mname.s, fname.s, midx);
return sr_kemi_exec_func(L, &mname, midx, &fname);
}
initial approach
FOSDEM 2017 - Brussels
CONCERNS
๏ for each execution of a KSR function, search
in the list of exports by module and function
name
๏ Lua should be better at indexing its functions
➡ avoid not benefiting of improvements done by Lua
๏ optimization
➡ provide an index for KSR submodule
© asipto.comFOSDEM 2017 - Brussels
DYNAMIC & FAST
๏ estimated 1024 max KSR functions
๏ auto generated 1024 Lua exports functions
๏ index KSR functions in one-to-one relation
© asipto.comFOSDEM 2017 - Brussels
final approach
DYNAMIC & FAST
© asipto.com
final approach
FOSDEM 2017 - Brussels
Exported To Lua Internal Kamailio Structure
sr_kemi_lua_exec_func_0 sr_kemi_lua_export_t(t_relay)
… …
sr_kemi_lua_exec_func_100 sr_kemi_lua_export_t(sl_send_reply)
… …
null null
… …
DYNAMIC & FAST
© asipto.com
static int sr_kemi_lua_exec_func_0(lua_State *L)
{
return sr_kemi_lua_exec_func(L, 0);
}
…
static int sr_kemi_lua_exec_func_1023(lua_State *L)
{
return sr_kemi_lua_exec_func(L, 1023);
}
…
typedef struct sr_kemi_lua_export {
lua_CFunction pfunc;
sr_kemi_t *ket;
} sr_kemi_lua_export_t;
static sr_kemi_lua_export_t _sr_kemi_lua_export_list[] = {
{ sr_kemi_lua_exec_func_0, NULL},
…
{ sr_kemi_lua_exec_func_1023, NULL},
{NULL, NULL}
};
final approach
FOSDEM 2017 - Brussels
DYNAMIC & FAST
© asipto.com
sr_kemi_t *sr_kemi_lua_export_get(int idx)
{
if(idx<0 || idx>=SR_KEMI_LUA_EXPORT_SIZE)
return NULL;
return _sr_kemi_lua_export_list[idx].ket;
}
…
int sr_kemi_lua_exec_func(lua_State* L, int eidx)
{
sr_kemi_t *ket;
ket = sr_kemi_lua_export_get(eidx);
return sr_kemi_lua_exec_func_ex(L, ket, 0);
}
final approach
FOSDEM 2017 - Brussels
PERFORMANCES
© asipto.com
final approach
FOSDEM 2017 - Brussels
๏ testing system
➡ VirtualBox with 2GB or RAM and 2 processors, having Linux
Mint as guest OS.The host was a MAC OS X running on a
Mid 2012 model of Macbook Pro
๏ results
➡ INTERPRETER - AVERAGE - MIN - MAX
➡ NATIVE - 302.275 - 6 - 3824
➡ LUA - 308.32 - 6 - 3596
LUA BENEFITS
© asipto.comFOSDEM 2017 - Brussels
๏ documentation of the programming language
๏ independent evolution and new features
๏ larger set of extensions
๏ sensitive, but: coroutines, threads, …
๏ routing script reload
SIPWEET
© asipto.comFOSDEM 2017 - Brussels
Send tweets on SIP events
• missed call notification
• instant messaging
• reminders
Monitor tweets for SIP services
• tweet-to-dial
• reminder setup
• scheduled calls
• profile update
Design
• Lua twitter library
• Twitter operation is an HTTP request
• can take some time to be processed
• we cannot afford that when processing SIP signaling
• solution: use asynchronous processing
• config file message queue
• dedicated process for twitter operations
• Kamailio modules
• app_lua
• mqueue
• rtimer
• sqlops
• Sample implementation
• notification of a missed call
• use of Twitter direct message
SIPWEET
© asipto.comFOSDEM 2017 - Brussels
Database table
CREATE TABLE `sipweetusers` (
`twuser` varchar(64) NOT NULL,
`sipuser` varchar(64) NOT NULL,
UNIQUE KEY (`twuser`),
UNIQUE KEY (`sipuser`)
);
Lua script
-- SIPweet
-- loading module
require("twitter")
local initialized = 0
local mytw
function sipweetinit()
if initialized == 0 then
mytw = twitter.client("Consumer Key",
"Consumer Secret",
"OAuth Token",
"OAuth Token Secret");
initialized = 1
end
end
function sipweetdm(userid, message)
sipweetinit()
mytw:sendMessage{ user = userid, text = message }
end
[[select twuser from sipweetusers
where sipuser=‘]]
.. KSR.pv.get("$rU") .. [[‘]]
sipweetdm(twuser, [[Missed call from]]
.. KSR.pv.get("$fU") )
RESOURCES
© asipto.comFOSDEM 2017 - Brussels
๏ https://www.lua.org
๏ https://www.kamailio.org
๏ https://www.kamailio.org/docs/modules/devel/modules/app_lua.html
๏ https://www.kamailio.org/docs/modules/devel/modules/app_lua.html#app_lua.r.list
๏ https://www.kamailio.org/docs/modules/devel/modules/app_lua.html#app_lua.r.reload
๏ https://www.kamailio.org/wiki/embeddedapi/devel/lua
© asipto.com
THANK YOU!!!
QUESTIONS?
Daniel-Constantin Mierla
Co-Founder Kamailio Project
www.kamailio.org
www.asipto.com
@miconda
FOSDEM 2017 - Brussels

Mais conteúdo relacionado

Mais procurados

Expanding Asterisk with Kamailio
Expanding Asterisk with KamailioExpanding Asterisk with Kamailio
Expanding Asterisk with KamailioFred Posner
 
SIP Attack Handling (Kamailio World 2021)
SIP Attack Handling (Kamailio World 2021)SIP Attack Handling (Kamailio World 2021)
SIP Attack Handling (Kamailio World 2021)Fred Posner
 
typemap in Perl/XS
typemap in Perl/XS  typemap in Perl/XS
typemap in Perl/XS charsbar
 
Kamailioworld 2018 - Modular and test driven SIP Routing with Lua
Kamailioworld 2018 - Modular and test driven SIP Routing with LuaKamailioworld 2018 - Modular and test driven SIP Routing with Lua
Kamailioworld 2018 - Modular and test driven SIP Routing with LuaSebastian Damm
 
Rihards Olups - Encrypting Daemon Traffic With Zabbix 3.0
Rihards Olups - Encrypting Daemon Traffic With Zabbix 3.0Rihards Olups - Encrypting Daemon Traffic With Zabbix 3.0
Rihards Olups - Encrypting Daemon Traffic With Zabbix 3.0Zabbix
 
Puppet and the HashiStack
Puppet and the HashiStackPuppet and the HashiStack
Puppet and the HashiStackBram Vogelaar
 
Phpconf 2013 - Agile Telephony Applications with PAMI and PAGI
Phpconf 2013 - Agile Telephony Applications with PAMI and PAGIPhpconf 2013 - Agile Telephony Applications with PAMI and PAGI
Phpconf 2013 - Agile Telephony Applications with PAMI and PAGIMarcelo Gornstein
 
Rouault imbert alpc_rpc_pacsec
Rouault imbert alpc_rpc_pacsecRouault imbert alpc_rpc_pacsec
Rouault imbert alpc_rpc_pacsecPacSecJP
 
Bootstrapping multidc observability stack
Bootstrapping multidc observability stackBootstrapping multidc observability stack
Bootstrapping multidc observability stackBram Vogelaar
 
Simple callcenter platform with PHP
Simple callcenter platform with PHPSimple callcenter platform with PHP
Simple callcenter platform with PHPMorten Amundsen
 
Devel::NYTProf 2009-07 (OUTDATED, see 201008)
Devel::NYTProf 2009-07 (OUTDATED, see 201008)Devel::NYTProf 2009-07 (OUTDATED, see 201008)
Devel::NYTProf 2009-07 (OUTDATED, see 201008)Tim Bunce
 
Codified PostgreSQL Schema
Codified PostgreSQL SchemaCodified PostgreSQL Schema
Codified PostgreSQL SchemaSean Chittenden
 
Integrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suiteIntegrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suiteBram Vogelaar
 
For the Greater Good: Leveraging VMware's RPC Interface for fun and profit by...
For the Greater Good: Leveraging VMware's RPC Interface for fun and profit by...For the Greater Good: Leveraging VMware's RPC Interface for fun and profit by...
For the Greater Good: Leveraging VMware's RPC Interface for fun and profit by...CODE BLUE
 
php & performance
 php & performance php & performance
php & performancesimon8410
 

Mais procurados (20)

Kamailio - Secure Communication
Kamailio - Secure CommunicationKamailio - Secure Communication
Kamailio - Secure Communication
 
Kamailio - SIP Servers Everywhere
Kamailio - SIP Servers EverywhereKamailio - SIP Servers Everywhere
Kamailio - SIP Servers Everywhere
 
Expanding Asterisk with Kamailio
Expanding Asterisk with KamailioExpanding Asterisk with Kamailio
Expanding Asterisk with Kamailio
 
SIP Attack Handling (Kamailio World 2021)
SIP Attack Handling (Kamailio World 2021)SIP Attack Handling (Kamailio World 2021)
SIP Attack Handling (Kamailio World 2021)
 
Kamailio and VoIP Wild World
Kamailio and VoIP Wild WorldKamailio and VoIP Wild World
Kamailio and VoIP Wild World
 
SIP Tutorial/Workshop 3
SIP Tutorial/Workshop 3SIP Tutorial/Workshop 3
SIP Tutorial/Workshop 3
 
Kamailio - The Story for Asterisk
Kamailio - The Story for AsteriskKamailio - The Story for Asterisk
Kamailio - The Story for Asterisk
 
typemap in Perl/XS
typemap in Perl/XS  typemap in Perl/XS
typemap in Perl/XS
 
Kamailioworld 2018 - Modular and test driven SIP Routing with Lua
Kamailioworld 2018 - Modular and test driven SIP Routing with LuaKamailioworld 2018 - Modular and test driven SIP Routing with Lua
Kamailioworld 2018 - Modular and test driven SIP Routing with Lua
 
Rihards Olups - Encrypting Daemon Traffic With Zabbix 3.0
Rihards Olups - Encrypting Daemon Traffic With Zabbix 3.0Rihards Olups - Encrypting Daemon Traffic With Zabbix 3.0
Rihards Olups - Encrypting Daemon Traffic With Zabbix 3.0
 
Puppet and the HashiStack
Puppet and the HashiStackPuppet and the HashiStack
Puppet and the HashiStack
 
Phpconf 2013 - Agile Telephony Applications with PAMI and PAGI
Phpconf 2013 - Agile Telephony Applications with PAMI and PAGIPhpconf 2013 - Agile Telephony Applications with PAMI and PAGI
Phpconf 2013 - Agile Telephony Applications with PAMI and PAGI
 
Rouault imbert alpc_rpc_pacsec
Rouault imbert alpc_rpc_pacsecRouault imbert alpc_rpc_pacsec
Rouault imbert alpc_rpc_pacsec
 
Bootstrapping multidc observability stack
Bootstrapping multidc observability stackBootstrapping multidc observability stack
Bootstrapping multidc observability stack
 
Simple callcenter platform with PHP
Simple callcenter platform with PHPSimple callcenter platform with PHP
Simple callcenter platform with PHP
 
Devel::NYTProf 2009-07 (OUTDATED, see 201008)
Devel::NYTProf 2009-07 (OUTDATED, see 201008)Devel::NYTProf 2009-07 (OUTDATED, see 201008)
Devel::NYTProf 2009-07 (OUTDATED, see 201008)
 
Codified PostgreSQL Schema
Codified PostgreSQL SchemaCodified PostgreSQL Schema
Codified PostgreSQL Schema
 
Integrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suiteIntegrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suite
 
For the Greater Good: Leveraging VMware's RPC Interface for fun and profit by...
For the Greater Good: Leveraging VMware's RPC Interface for fun and profit by...For the Greater Good: Leveraging VMware's RPC Interface for fun and profit by...
For the Greater Good: Leveraging VMware's RPC Interface for fun and profit by...
 
php & performance
 php & performance php & performance
php & performance
 

Destaque

Kamailio - Large Unified Communication Platforms
Kamailio - Large Unified Communication PlatformsKamailio - Large Unified Communication Platforms
Kamailio - Large Unified Communication PlatformsDaniel-Constantin Mierla
 
FreeSWITCH as a Kickass SBC
FreeSWITCH as a Kickass SBCFreeSWITCH as a Kickass SBC
FreeSWITCH as a Kickass SBCMoises Silva
 
Scaling FreeSWITCH Performance
Scaling FreeSWITCH PerformanceScaling FreeSWITCH Performance
Scaling FreeSWITCH PerformanceMoises Silva
 
2600Hz - Tuning Kazoo to 10,000 Handsets - KazooCon 2015
2600Hz - Tuning Kazoo to 10,000 Handsets - KazooCon 20152600Hz - Tuning Kazoo to 10,000 Handsets - KazooCon 2015
2600Hz - Tuning Kazoo to 10,000 Handsets - KazooCon 20152600Hz
 
Why is Kamailio so different? An introduction.
Why is Kamailio so different? An introduction.Why is Kamailio so different? An introduction.
Why is Kamailio so different? An introduction.Olle E Johansson
 

Destaque (6)

Snappy Kamailio
Snappy KamailioSnappy Kamailio
Snappy Kamailio
 
Kamailio - Large Unified Communication Platforms
Kamailio - Large Unified Communication PlatformsKamailio - Large Unified Communication Platforms
Kamailio - Large Unified Communication Platforms
 
FreeSWITCH as a Kickass SBC
FreeSWITCH as a Kickass SBCFreeSWITCH as a Kickass SBC
FreeSWITCH as a Kickass SBC
 
Scaling FreeSWITCH Performance
Scaling FreeSWITCH PerformanceScaling FreeSWITCH Performance
Scaling FreeSWITCH Performance
 
2600Hz - Tuning Kazoo to 10,000 Handsets - KazooCon 2015
2600Hz - Tuning Kazoo to 10,000 Handsets - KazooCon 20152600Hz - Tuning Kazoo to 10,000 Handsets - KazooCon 2015
2600Hz - Tuning Kazoo to 10,000 Handsets - KazooCon 2015
 
Why is Kamailio so different? An introduction.
Why is Kamailio so different? An introduction.Why is Kamailio so different? An introduction.
Why is Kamailio so different? An introduction.
 

Semelhante a FOSDEM 2017 - RTC Services With Lua and Kamailio

Homer - Workshop at Kamailio World 2017
Homer - Workshop at Kamailio World 2017Homer - Workshop at Kamailio World 2017
Homer - Workshop at Kamailio World 2017Giacomo Vacca
 
Skydive, real-time network analyzer, container integration
Skydive, real-time network analyzer, container integrationSkydive, real-time network analyzer, container integration
Skydive, real-time network analyzer, container integrationSylvain Afchain
 
Server side JavaScript: going all the way
Server side JavaScript: going all the wayServer side JavaScript: going all the way
Server side JavaScript: going all the wayOleg Podsechin
 
Kamailio with Docker and Kubernetes
Kamailio with Docker and KubernetesKamailio with Docker and Kubernetes
Kamailio with Docker and KubernetesPaolo Visintin
 
How to Leverage Go for Your Networking Needs
How to Leverage Go for Your Networking NeedsHow to Leverage Go for Your Networking Needs
How to Leverage Go for Your Networking NeedsDigitalOcean
 
Presto anatomy
Presto anatomyPresto anatomy
Presto anatomyDongmin Yu
 
DevOps in PHP environment
DevOps in PHP environmentDevOps in PHP environment
DevOps in PHP environmentEvaldo Felipe
 
nuclio Overview October 2017
nuclio Overview October 2017nuclio Overview October 2017
nuclio Overview October 2017iguazio
 
OSMC 2014: Monitoring VoIP Systems | Sebastian Damm
OSMC 2014: Monitoring VoIP Systems | Sebastian DammOSMC 2014: Monitoring VoIP Systems | Sebastian Damm
OSMC 2014: Monitoring VoIP Systems | Sebastian DammNETWAYS
 
Monitoring VoIP Systems
Monitoring VoIP SystemsMonitoring VoIP Systems
Monitoring VoIP Systemssipgate
 
Non-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.jsNon-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.jsMarcus Frödin
 
iguazio - nuclio overview to CNCF (Sep 25th 2017)
iguazio - nuclio overview to CNCF (Sep 25th 2017)iguazio - nuclio overview to CNCF (Sep 25th 2017)
iguazio - nuclio overview to CNCF (Sep 25th 2017)Eran Duchan
 
Automating the Network
Automating the NetworkAutomating the Network
Automating the NetworkPuppet
 
Open Source Tools for the Systems Administrator
Open Source Tools for the Systems AdministratorOpen Source Tools for the Systems Administrator
Open Source Tools for the Systems AdministratorCharles Profitt
 
[245] presto 내부구조 파헤치기
[245] presto 내부구조 파헤치기[245] presto 내부구조 파헤치기
[245] presto 내부구조 파헤치기NAVER D2
 
Xdp and ebpf_maps
Xdp and ebpf_mapsXdp and ebpf_maps
Xdp and ebpf_mapslcplcp1
 

Semelhante a FOSDEM 2017 - RTC Services With Lua and Kamailio (20)

Homer - Workshop at Kamailio World 2017
Homer - Workshop at Kamailio World 2017Homer - Workshop at Kamailio World 2017
Homer - Workshop at Kamailio World 2017
 
Skydive, real-time network analyzer, container integration
Skydive, real-time network analyzer, container integrationSkydive, real-time network analyzer, container integration
Skydive, real-time network analyzer, container integration
 
Server side JavaScript: going all the way
Server side JavaScript: going all the wayServer side JavaScript: going all the way
Server side JavaScript: going all the way
 
Kamailio with Docker and Kubernetes
Kamailio with Docker and KubernetesKamailio with Docker and Kubernetes
Kamailio with Docker and Kubernetes
 
JS everywhere 2011
JS everywhere 2011JS everywhere 2011
JS everywhere 2011
 
How to Leverage Go for Your Networking Needs
How to Leverage Go for Your Networking NeedsHow to Leverage Go for Your Networking Needs
How to Leverage Go for Your Networking Needs
 
Skydive 5/07/2016
Skydive 5/07/2016Skydive 5/07/2016
Skydive 5/07/2016
 
Presto anatomy
Presto anatomyPresto anatomy
Presto anatomy
 
DevOps in PHP environment
DevOps in PHP environmentDevOps in PHP environment
DevOps in PHP environment
 
nuclio Overview October 2017
nuclio Overview October 2017nuclio Overview October 2017
nuclio Overview October 2017
 
OSMC 2014: Monitoring VoIP Systems | Sebastian Damm
OSMC 2014: Monitoring VoIP Systems | Sebastian DammOSMC 2014: Monitoring VoIP Systems | Sebastian Damm
OSMC 2014: Monitoring VoIP Systems | Sebastian Damm
 
Monitoring VoIP Systems
Monitoring VoIP SystemsMonitoring VoIP Systems
Monitoring VoIP Systems
 
Non-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.jsNon-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.js
 
iguazio - nuclio overview to CNCF (Sep 25th 2017)
iguazio - nuclio overview to CNCF (Sep 25th 2017)iguazio - nuclio overview to CNCF (Sep 25th 2017)
iguazio - nuclio overview to CNCF (Sep 25th 2017)
 
Automating the Network
Automating the NetworkAutomating the Network
Automating the Network
 
Open Source Tools for the Systems Administrator
Open Source Tools for the Systems AdministratorOpen Source Tools for the Systems Administrator
Open Source Tools for the Systems Administrator
 
Osol Pgsql
Osol PgsqlOsol Pgsql
Osol Pgsql
 
Jaap : node, npm & grunt
Jaap : node, npm & gruntJaap : node, npm & grunt
Jaap : node, npm & grunt
 
[245] presto 내부구조 파헤치기
[245] presto 내부구조 파헤치기[245] presto 내부구조 파헤치기
[245] presto 내부구조 파헤치기
 
Xdp and ebpf_maps
Xdp and ebpf_mapsXdp and ebpf_maps
Xdp and ebpf_maps
 

Mais de Daniel-Constantin Mierla

Mais de Daniel-Constantin Mierla (9)

TAD Summit 2016 - The Mobile World Up Side Down
TAD Summit 2016 - The Mobile World Up Side DownTAD Summit 2016 - The Mobile World Up Side Down
TAD Summit 2016 - The Mobile World Up Side Down
 
SIP Server Optimizations for Mobile Networks
SIP Server Optimizations for Mobile NetworksSIP Server Optimizations for Mobile Networks
SIP Server Optimizations for Mobile Networks
 
Kamailio - SIP Routing in Lua
Kamailio - SIP Routing in LuaKamailio - SIP Routing in Lua
Kamailio - SIP Routing in Lua
 
10 Years SER - Awards
10 Years SER - Awards10 Years SER - Awards
10 Years SER - Awards
 
Sculpturing SIP World
Sculpturing SIP WorldSculpturing SIP World
Sculpturing SIP World
 
CPDL - Charging Plan Definition Language
CPDL - Charging Plan Definition LanguageCPDL - Charging Plan Definition Language
CPDL - Charging Plan Definition Language
 
SER - SIP Express Router
SER - SIP Express RouterSER - SIP Express Router
SER - SIP Express Router
 
SIP Router Project
SIP Router ProjectSIP Router Project
SIP Router Project
 
Kamailio - Unifying SIP and Web Worlds with Lua
Kamailio - Unifying SIP and Web Worlds with LuaKamailio - Unifying SIP and Web Worlds with Lua
Kamailio - Unifying SIP and Web Worlds with Lua
 

Último

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 

Último (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 

FOSDEM 2017 - RTC Services With Lua and Kamailio

  • 1. building rtc services with lua and kamailio Daniel-Constantin Mierla Co-Founder Kamailio Project www.asipto.com @miconda
  • 2. ๏ www.kamailio.org ๏ open source sip server ๏ aka sip router or sip proxy ๏ focus in scalability and flexibility ๏ sip (session initiation protocol) ๏ ietf open standard - rfc3261 ๏ https://tools.ietf.org/html/rfc3261 © asipto.comFOSDEM 2017 - Brussels
  • 3. ๏ can be used for: ๏ voice (ip telephony - voip) ๏ video ๏ instant messaging ๏ presence ๏ other rtc (gaming, desktop sharing, …) ๏ secure communications (TLS), IPv4/IPv6 ๏ quite similar packet structure to http ๏ adopted by ITU/3GPP (signaling for voice in 4G+) © asipto.comFOSDEM 2017 - Brussels
  • 4. SIP CALL © asipto.com INVITE 100 Trying 180 Ringing 200 OK ACK BYE 200 OK MEDIA STREAMS Alice Bob Early Dialog Establish Dialog Start Media Media Session Media Session Establish Dialog Initiate Dialog Start Media Destroy Dialog Stop Media Destroy Dialog Stop Media Waiting For UAC Decision FOSDEM 2017 - Brussels voip call maps over sip dialog sip dialog is a sequence of sip transactions sip transaction is a sip request and one or many responses
  • 5. SIP REQUEST © asipto.comFOSDEM 2017 - Brussels INVITE INVITE sip:user@sipserver.com SIP/2.0Start line Message headers Message body Via: SIP/2.0/UDP 10.10.10.10:5060;branch=z9hG4bKxy From: "Me" <sip:me@sipserver.org>;tag=a012 To: "User" <sip:user@sipserver.org> Call-ID: d@10.10.10.10 CSeq: 1 INVITE Contact: <sip:10.10.10.10:5060> User-Agent: SIPTelephone Content-Type: application/sdp Content-Length: 251 v=0 o=audio1 0 0 IN IP4 10.10.10.10 s=session c=IN IP4 10.10.10.10 m=audio 54742 RTP/AVP 4 3 a=rtpmap:4 G723/8000 a=rtpmap:3 GSM/8000
  • 6. SIP RESPONSE © asipto.comFOSDEM 2017 - Brussels INVITE sip response == sip reply SIP/2.0 200 OKStart line Message headers Message body Via: SIP/2.0/UDP 10.10.10.10:5060;branch=z9hG4bKxy From: "Me" <sip:me@sipserver.org>;tag=a012 To: "User" <sip:user@sipserver.org>;tag=b034 Call-ID: d@10.10.10.10 CSeq: 1 INVITE Contact: <sip:10.10.10.20:5060> User-Agent: SIPSoftPhone Content-Type: application/sdp Content-Length: 123 v=0 o=audio2 0 0 IN IP4 10.10.10.20 s=session c=IN IP4 10.10.10.20 m=audio 62043 RTP/AVP 0 4
  • 7. ๏ the base role of kamailio ๏ routing SIP packets: requests and responses © asipto.comFOSDEM 2017 - Brussels alice bob media server gateway apps
  • 8. FEATURES © asipto.com ✤ Modular SIP Proxy, Registrar and Redirect server ✤ Designed for scalability and flexibility ✤ IPv4, IPv6, UDP, TCP, TLS, SCTP, WebSocket ✤ NAT Traversal, internal and external caching engines ✤ JSON, XMLRPC, HTTP APIs ✤ IMS Extensions, SIP-I/SIP-T, IM & Presence ✤ SQL and NoSQL backends ✤ Asynchronous processing (TCP/TLS, SIP routing), external event API ✤ Embedded interpreters (Lua, Perl, Python, .Net, Java) ✤ Load balancing, LCR, DID routing, Number portability, … FOSDEM 2017 - Brussels
  • 9. OWN CFG SCRIPTING LANGUAGE #!KAMAILIO debug=2 log_stderror=yes listen=udp:127.0.0.1 loadmodule “rr.so” loadmodule “sl.so” loadmodule “pv.so” loadmodule “textops.so” loadmodule “siputils.so” modparam(“rr”, “append_fromtag”, 1) # load modules request_route { route(WITHINDLG); if(is_method(“INVITE”)) { $du = “sip:127.0.0.1:9”; record_route(); forward(); exit; } sl_send_reply(“403”, “Not allowed”); exit; } route[WITHINDLG] { if(!has_totag()) return; if(loose_route()) { forward(); exit; } sl_send_reply(“404”, “Not here”); exit; } ๏ comments ๏ preprocessor directive ๏ core parameters ๏ custom core parameters ๏ load modules ๏ module parameters ๏ routing blocks ➡ expressions ➡ conditions ➡ actions ➡ control statements ➡ subroutes © asipto.com kamailio.cfg FOSDEM 2017 - Brussels
  • 10. KAMAILIO.CFG LANGUAGE ๏ initial design in 2001-2002 ➡ targeting optimization for sip routing ๏ characteristics ➡ sort of pre-compilation at startup ➡ linear execution ➡ routing blocks similar to functions ➡ specific routing blocks executed on various events ๏ limitations ➡ only int and string values ➡ requires C coding (sometime lex and yacc) to extend it ➡ startup pre-compilation not designed for reload © asipto.comFOSDEM 2017 - Brussels
  • 11. LUA IN KAMAILIO ๏ https://www.lua.org ๏ app_lua module added in January 2010 ➡ embedding the lua interpreter ➡ targeting execution of lua snippets ➡ using functions from inside routing blocks of kamailio.cfg ๏ exported a new module to lua - sr - with many submodule ➡ sr.hdr, sr.pv, sr.sl, … ๏ limitations ➡ it required C coding inside app_lua for extending the lua sr module © asipto.comFOSDEM 2017 - Brussels https://www.kamailio.org/docs/modules/stable/modules/app_lua.html
  • 12. EXECUTING LUA INSIDE KAMAILIO.CFG © asipto.comFOSDEM 2017 - Brussels … function sr_append_fu_to_reply() sr.hdr.append_to_reply("P-From: " .. sr.pv.get("$fu") .. "rn"); end … … modparam("app_lua", "load", "/usr/local/etc/kamailio/lua/myscript.lua") … request_route { … if(!lua_run(“sr_append_fu_to_reply")) { xdbg("SCRIPT: failed to execute lua function!n"); } … } … myscript.lua kamailio.cfg
  • 14. OVERCOMING LIMITATIONS ๏ main kamailio.cfg scripting limitations ➡ reload and language extensions ๏ kamailio.cfg sections at runtime ➡ passive: global parameters and module sections (attributes) ➡ active: routing blocks (actions) ๏ solution - kamailio v5.0 ➡ allow use of lua for the entire active part (actions) © asipto.comFOSDEM 2017 - Brussels
  • 15. kemi kamailio embedded interface a framework that allows selecting your favourite scripting language for writing sip routing rules ROUTING LOGIC USING DIFFERENT INTERPRETERS FOSDEM 2017 - Brussels © asipto.com KAMAILIO 5.0
  • 16. KEMI & KAMAILIO.CFG © asipto.com • not affected ➡ core parameters ➡ loading modules ➡ module parameters • new ➡ specify the language for routing rules (routing blocks) ➡ cfgengine=“language” ➡ at this moment, language can be: native, lua, javascript, python ➡ default is ‘native’ ➡ ‘lua’ requires ‘app_lua’ module ➡ ‘python’ requires ‘app_python’ module ➡ ‘javascript’ requires ‘app_jsdt’ module FOSDEM 2017 - Brussels
  • 17. KEMI & LUA ๏ new lua module ➡ KSR ๏ characteristics ➡ automatic exports of new functions to KSR ➡ no C coding anymore in app_lua ➡ routing blocks entirely written in lua ๏ backward compatible ➡ sr module still available ➡ embedded execution inside kamailio.cfg still possible © asipto.comFOSDEM 2017 - Brussels
  • 18. NATIVE VS. LUA © asipto.comFOSDEM 2017 - Brussels request_route { # per request initial checks route(REQINIT); # NAT detection route(NATDETECT); # CANCEL processing if (is_method("CANCEL")) { if (t_check_trans()) { route(RELAY); } exit; } # handle requests within SIP dialogs route(WITHINDLG); function ksr_request_route() -- per request initial checks ksr_route_reqinit(); -- NAT detection ksr_route_natdetect(); -- CANCEL processing if KSR.pv.get("$rm") == "CANCEL" then if KSR.tm.t_check_trans()>0 then ksr_route_relay(); end return 1; end -- handle requests within SIP dialogs ksr_route_withindlg();
  • 19. NATIVE VS. LUA © asipto.comFOSDEM 2017 - Brussels # Caller NAT detection route[NATDETECT] { force_rport(); if (nat_uac_test("19")) { if (is_method("REGISTER")) { fix_nated_register(); } else { if(is_first_hop()) set_contact_alias(); } setflag(FLT_NATS); } return; } -- Caller NAT detection function ksr_route_natdetect() KSR.force_rport(); if KSR.nathelper.nat_uac_test(19)>0 then if KSR.pv.get("$rm")=="REGISTER" then KSR.nathelper.fix_nated_register(); elseif KSR.siputils.is_first_hop()>0 then KSR.nathelper.set_contact_alias(); end KSR.setflag(FLT_NATS); end return 1; end
  • 20. SIP ROUTING IN LUA © asipto.comFOSDEM 2017 - Brussels https://github.com/kamailio/kamailio/blob/master/misc/examples/kemi/kamailio-basic-kemi-lua.lua https://github.com/kamailio/kamailio/blob/master/misc/examples/kemi/kamailio-basic-kemi.cfg ๏ features ➡ detect scanning attacks and block DoS attacks ➡ authentication ➡ authorization ➡ accounting ➡ location service ➡ nat traversal
  • 21. © asipto.com DEVELOPER MODE LUA FOR SIP ROUTING FOSDEM 2017 - Brussels
  • 22. IMPORTANT ๏ fast, very fast ➡ handle thousands of call setups per second ➡ critical feature ๏ dynamic ➡ KSR exports a matter of loaded native kamailio modules ๏ preserve experience ➡ stop execution or routing script © asipto.comFOSDEM 2017 - Brussels
  • 23. STOP ROUTING SCRIPT EXECUTION ๏ native kamailio.cfg ➡ exit ๏ lua ➡ libc exit results in killing kamailio - not wanted ๏ solution ➡ KSR.x.exit() ➡ workaround using lua error() © asipto.comFOSDEM 2017 - Brussels
  • 24. KSR.X.EXIT() © asipto.comFOSDEM 2017 - Brussels static str _sr_kemi_lua_exit_string = str_init("~~ksr~exit~~"); str* sr_kemi_lua_exit_string_get(void) { return &_sr_kemi_lua_exit_string; } static int sr_kemi_lua_exit (lua_State *L) { str *s; LM_DBG("script exit calln"); s = sr_kemi_lua_exit_string_get(); lua_getglobal(L, "error"); lua_pushstring(L, s->s); lua_call(L, 1, 0); return 0; }
  • 25. KSR.X.EXIT() © asipto.comFOSDEM 2017 - Brussels … ret = lua_pcall(_sr_L_env.LL, n, 0, 0); if(ret!=0) { txt.s = (char*)lua_tostring(_sr_L_env.LL, -1); if(txt.s!=NULL) { if(strcmp(txt.s[n], _sr_kemi_lua_exit_string.s[n]) !=0 ) { LM_ERR("error from Lua: %sn", txt.s); } else { LM_DBG("ksr error call from Lua: %sn", txt.s); } } else { LM_ERR("error from Lua: unknownn"); } lua_pop(_sr_L_env.LL, 1); if(n==1) { return 1; } else { LM_ERR("error executing: %s (err: %d)n", func, ret); return -1; } } …
  • 26. DYNAMIC & FAST © asipto.com void lua_sr_kemi_register_module(lua_State *L, str *mname, int midx) { int ret; #define LUA_SR_SBUF_SIZE 1024 char sbuf[LUA_SR_SBUF_SIZE]; ret = snprintf(sbuf, LUA_SR_SBUF_SIZE-1, "KSR.%.*s = {}n" "KSR.%.*s.__index = function (table, key)n" " return function (...)n" " return KSR_MOD_C('%.*s', %d, key, ...)n" " endn" "endn" "setmetatable(KSR.%.*s, KSR.%.*s)n", mname->len, mname->s, mname->len, mname->s, mname->len, mname->s, midx, mname->len, mname->s, mname->len, mname->s ); ret = luaL_dostring(L, sbuf); LM_DBG("pushing lua KSR.%.*s table definition returned %dn", mname->len, mname->s, ret); } initial approach FOSDEM 2017 - Brussels
  • 27. DYNAMIC & FAST © asipto.com initial approach FOSDEM 2017 - Brussels ๏ everything is a hash table in Lua ➡ including modules ๏ dive into internals ➡ change the indexing function of module hash table
  • 28. DYNAMIC & FAST © asipto.com int sr_kemi_KSR_MOD_C(lua_State* L) { str mname; int midx; str fname; mname.s = (char*)lua_tostring(L, 1); midx = lua_tointeger(L, 2); fname.s = (char*)lua_tostring(L, 3); if(mname.s==NULL || fname.s==NULL) { LM_ERR("null params: %p %pn", mname.s, fname.s); return app_lua_return_false(L); } mname.len = strlen(mname.s); fname.len = strlen(fname.s); LM_DBG("module function execution of: %s.%s (%d)n", mname.s, fname.s, midx); return sr_kemi_exec_func(L, &mname, midx, &fname); } initial approach FOSDEM 2017 - Brussels
  • 29. CONCERNS ๏ for each execution of a KSR function, search in the list of exports by module and function name ๏ Lua should be better at indexing its functions ➡ avoid not benefiting of improvements done by Lua ๏ optimization ➡ provide an index for KSR submodule © asipto.comFOSDEM 2017 - Brussels
  • 30. DYNAMIC & FAST ๏ estimated 1024 max KSR functions ๏ auto generated 1024 Lua exports functions ๏ index KSR functions in one-to-one relation © asipto.comFOSDEM 2017 - Brussels final approach
  • 31. DYNAMIC & FAST © asipto.com final approach FOSDEM 2017 - Brussels Exported To Lua Internal Kamailio Structure sr_kemi_lua_exec_func_0 sr_kemi_lua_export_t(t_relay) … … sr_kemi_lua_exec_func_100 sr_kemi_lua_export_t(sl_send_reply) … … null null … …
  • 32. DYNAMIC & FAST © asipto.com static int sr_kemi_lua_exec_func_0(lua_State *L) { return sr_kemi_lua_exec_func(L, 0); } … static int sr_kemi_lua_exec_func_1023(lua_State *L) { return sr_kemi_lua_exec_func(L, 1023); } … typedef struct sr_kemi_lua_export { lua_CFunction pfunc; sr_kemi_t *ket; } sr_kemi_lua_export_t; static sr_kemi_lua_export_t _sr_kemi_lua_export_list[] = { { sr_kemi_lua_exec_func_0, NULL}, … { sr_kemi_lua_exec_func_1023, NULL}, {NULL, NULL} }; final approach FOSDEM 2017 - Brussels
  • 33. DYNAMIC & FAST © asipto.com sr_kemi_t *sr_kemi_lua_export_get(int idx) { if(idx<0 || idx>=SR_KEMI_LUA_EXPORT_SIZE) return NULL; return _sr_kemi_lua_export_list[idx].ket; } … int sr_kemi_lua_exec_func(lua_State* L, int eidx) { sr_kemi_t *ket; ket = sr_kemi_lua_export_get(eidx); return sr_kemi_lua_exec_func_ex(L, ket, 0); } final approach FOSDEM 2017 - Brussels
  • 34. PERFORMANCES © asipto.com final approach FOSDEM 2017 - Brussels ๏ testing system ➡ VirtualBox with 2GB or RAM and 2 processors, having Linux Mint as guest OS.The host was a MAC OS X running on a Mid 2012 model of Macbook Pro ๏ results ➡ INTERPRETER - AVERAGE - MIN - MAX ➡ NATIVE - 302.275 - 6 - 3824 ➡ LUA - 308.32 - 6 - 3596
  • 35. LUA BENEFITS © asipto.comFOSDEM 2017 - Brussels ๏ documentation of the programming language ๏ independent evolution and new features ๏ larger set of extensions ๏ sensitive, but: coroutines, threads, … ๏ routing script reload
  • 36. SIPWEET © asipto.comFOSDEM 2017 - Brussels Send tweets on SIP events • missed call notification • instant messaging • reminders Monitor tweets for SIP services • tweet-to-dial • reminder setup • scheduled calls • profile update Design • Lua twitter library • Twitter operation is an HTTP request • can take some time to be processed • we cannot afford that when processing SIP signaling • solution: use asynchronous processing • config file message queue • dedicated process for twitter operations • Kamailio modules • app_lua • mqueue • rtimer • sqlops • Sample implementation • notification of a missed call • use of Twitter direct message
  • 37. SIPWEET © asipto.comFOSDEM 2017 - Brussels Database table CREATE TABLE `sipweetusers` ( `twuser` varchar(64) NOT NULL, `sipuser` varchar(64) NOT NULL, UNIQUE KEY (`twuser`), UNIQUE KEY (`sipuser`) ); Lua script -- SIPweet -- loading module require("twitter") local initialized = 0 local mytw function sipweetinit() if initialized == 0 then mytw = twitter.client("Consumer Key", "Consumer Secret", "OAuth Token", "OAuth Token Secret"); initialized = 1 end end function sipweetdm(userid, message) sipweetinit() mytw:sendMessage{ user = userid, text = message } end [[select twuser from sipweetusers where sipuser=‘]] .. KSR.pv.get("$rU") .. [[‘]] sipweetdm(twuser, [[Missed call from]] .. KSR.pv.get("$fU") )
  • 38. RESOURCES © asipto.comFOSDEM 2017 - Brussels ๏ https://www.lua.org ๏ https://www.kamailio.org ๏ https://www.kamailio.org/docs/modules/devel/modules/app_lua.html ๏ https://www.kamailio.org/docs/modules/devel/modules/app_lua.html#app_lua.r.list ๏ https://www.kamailio.org/docs/modules/devel/modules/app_lua.html#app_lua.r.reload ๏ https://www.kamailio.org/wiki/embeddedapi/devel/lua
  • 39. © asipto.com THANK YOU!!! QUESTIONS? Daniel-Constantin Mierla Co-Founder Kamailio Project www.kamailio.org www.asipto.com @miconda FOSDEM 2017 - Brussels