SlideShare a Scribd company logo
1 of 22
Download to read offline
Kamailio SIP LUA 
Amoocon 2010 
Rostock, Germany 
Do Your SIP Routing In Lua! 
Daniel-Constantin Mierla 
Co-Founder Kamailio (OpenSER) 
www.asipto.com
Kamailio SIP Lua 
It is all about love 
www.kamailio.org 2 
Wine, moon ... and you 
... hacking SIP
Kamailio SIP Lua 
Instead of introduction 
• if you missed my previous presentation 
• “The SIP Router Project - Asynchronous SIP Routing” 
Links: 
• http://www.kamailio.org 
• http://sip-router.org 
• http://www.lua.org 
www.kamailio.org 3
Kamailio SIP Lua 
Lua 
What is Lua? 
• Lua is a powerful, fast, lightweight, embeddable scripting 
language. 
• Lua combines simple procedural syntax with powerful 
data description constructs based on associative arrays 
and extensible semantics. Lua is dynamically typed, runs by 
interpreting bytecode for a register-based virtual 
machine, and has automatic memory management with 
incremental garbage collection, making it ideal for 
configuration, scripting, and rapid prototyping. 
• http://www.lua.org 
www.kamailio.org 4
Kamailio SIP Lua 
Lua 
Why choose Lua? 
• Lua has been used in many industrial applications (e.g., 
Adobe's Photoshop Lightroom), with an emphasis on 
embedded systems (e.g., the Ginga middleware for digital 
TV in Brazil) and games (e.g., World of Warcraft). Lua is 
currently the leading scripting language in games.. 
• Lua is supported by other telephony engines, e.g., Asterisk 
and FreeSWITCH 
• http://www.lua.org 
www.kamailio.org 5
Kamailio SIP Lua 
Lua 
More about Lua? 
• is fast 
• is portable 
• is embeddable 
• is powerful (but simple) 
• is small 
• is free 
• http://www.lua.org 
www.kamailio.org 6
Kamailio SIP Lua 
Kamailio and SIP routing 
Where we stand today? 
• flexible configuration language, still limited pretty much to 
SIP only 
• the power is in hands (and brain) of administrator 
• SIP specific extensions added mainly by writing C 
modules 
• for the rest: Lua, Perl, Python and Java 
www.kamailio.org 7
Kamailio SIP Lua 
Kamailio and Lua 
Why together? 
• need to integrate with other communication platforms 
• it is about realtime communication, so being fast is 
important 
• routing logic may require non-SIP related operations 
• all characteristics of Lua indicates it a very good candidate 
www.kamailio.org 8
Kamailio SIP Lua 
Kamailio and Lua 
How does it work? 
• load module: app_lua 
• Lua scripts can be loaded at startup or on-the-fly at 
runtime 
• entire Lua scripts can be executed or just functions from 
the scripts 
• Lua scripts have access to SIP messages and config 
variables 
• Lua scripts can return back config variables 
• Lua scripts can execute functions from config file 
http://kamailio.org/docs/modules/devel/modules/app_lua.html 
www.kamailio.org 9
Kamailio SIP Lua 
Kamailio Lua API 
Lua packages 
• package sr 
• access to Kamailio core functions 
• method to execute functions exported by modules 
• container for other sub-packages 
• package sr.hdr 
• header manipulation 
• get, add, remove 
• package sr.pv 
• pseudo-variables manipulation 
• access to all pseudo-variables - hundreds of them 
• package sr.sl 
• exports internal sl module API (stateless reply) 
http://sip-router.org/wiki/api/lua/devel 
www.kamailio.org 10
sr.hdr.append_to_reply("X-Src: " .. sr.pv.get("$si") .. ":" .. sr.pv.get("$sp") .. "rn"); 
Kamailio SIP Lua 
Kamailio Lua API 
Basic example 
Lua script: 
function sr_append_srcaddr_to_reply() 
end 
Kamailio config: 
modparam("app_lua", "load", "/path/to/myscript.lua") 
... 
route { 
... 
if(!lua_run("sr_append_srcaddr_to_reply")) 
{ 
xdbg("SCRIPT: failed to execute lua function!n"); 
} 
... 
} 
www.kamailio.org 11
Kamailio SIP Lua 
SIPWEET 
www.kamailio.org 12
Kamailio SIP Lua 
SIPWEET 
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 
www.kamailio.org 13
Kamailio SIP Lua 
SIPWEET 
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 
www.kamailio.org 14
Kamailio SIP Lua 
SIPWEET 
Config 
loadmodule "app_lua.so" 
loadmodule "rtimer.so" 
loadmodule "sqlops.so" 
loadmodule “mqueue.so” 
# ----- app_lua ----- 
modparam("app_lua", "load", 
"usr/local/etc/kamailio/lua/sipweet.lua") 
# ----- rtimer ----- 
modparam("rtimer", "timer", 
"name=sipweet;interval=60;mode=1;") 
modparam("rtimer", "exec", 
"timer=sipweet;route=SIPWEET;") 
# ----- sqlops ----- 
modparam("sqlops","sqlcon", 
"ca=>mysql://openser:openserrw@localhost/openser") 
# ----- mqueue ----- 
modparam("mqueue", "mqueue", "name=sipweet") 
www.kamailio.org 15
Kamailio SIP Lua 
SIPWEET 
Config 
# Twitter routing 
route[SIPWEET] { 
# consume tweeties 
while(mq_fetch("sipweet")) 
{ 
xlog("Tweeting to $mqk(sipweet) [[$mqv(sipweet)]]n"); 
# get twitter user 
sql_query("ca", 
"select twuser from sipweetusers where sipuser='$mqk(sipweet)'", 
"ra"); 
if($dbr(ra=>rows)>0) 
{ 
$var(twuser) = $dbr(ra=>[0,0]); 
$var(twuser) = $mqv(sipweet); 
if(!lua_runstring("sipweetdm([[$var(twuser)]], [[$var(twmsg)]])")) 
{ 
xdbg("failed to send dm to: $mqk(sipweet) - $var(twuser)!n"); 
} 
} 
} 
} 
www.kamailio.org 16
Kamailio SIP Lua 
SIPWEET 
Config 
# Twitees queuing 
route[TWQUEUE] { 
if(!is_method("INVITE")) 
return; 
mq_add("sipweet", "$rU", "Missed call from $fU [$Tf]"); 
} 
route { 
... 
if(!lookup(“location”)) { 
route(TWQUEUE); 
t_newtran(); 
t_reply("404", "Not Found"); 
exit; 
} 
... 
} 
www.kamailio.org 17
Kamailio SIP Lua 
SIPWEET 
Database table 
CREATE TABLE `sipweetusers` ( 
`id` int(10) unsigned NOT NULL AUTO_INCREMENT, 
`twuser` varchar(64) NOT NULL, 
`sipuser` varchar(64) NOT NULL, 
PRIMARY KEY (`id`), 
UNIQUE KEY (`twuser`), 
UNIQUE KEY (`sipuser`) 
); 
www.kamailio.org 18
Kamailio SIP Lua 
SIPWEET 
Lua script 
-- SIPweet 
-- loading module 
local twitter = require("twitter") 
local initialized = 0 
local me 
function sipweetinit() 
if initialized == 0 then 
me = twitter.Client( "TWUSER", "TWPASSWD" ) 
tret = me:VerifyCredentials() 
initialized = 1 
end 
end 
function sipweetdm(user, txt) 
sipweetinit() 
tret = me:NewDirectMessage(user, txt) 
end 
www.kamailio.org 19
Kamailio SIP Lua 
SIPWEET 
And the messages goes ... 
• nice and quick to your twitter client 
www.kamailio.org 20
Meet us next week in Berlin 
• Developer Meeting, Tue, Jun 8 
• LinuxTag Booth, Jun 9-12 
Kamailio SIP Lua 
SIPWEET 
Concluding 
• This was a proof of concept to do easy twitter integration 
• Kamailio Lua API 
• Asynchronous Twitter Notification System by Config Only 
• Improvements and new services at your imagination 
• or mine - prepare the credit card or a good bottle of wine 
• follow us - cool stuff ahead 
Contact 
•Daniel-Constantin Mierla 
•twitter: miconda 
•daniel@asipto.com 
•http://www.asipto.com 
•http://www.kamailio.org 
Questions? 
www.kamailio.org 21

More Related Content

What's hot

Continuous Integration and Kamailio
Continuous Integration and KamailioContinuous Integration and Kamailio
Continuous Integration and KamailioGiacomo Vacca
 
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
 
Kamailio with Docker and Kubernetes
Kamailio with Docker and KubernetesKamailio with Docker and Kubernetes
Kamailio with Docker and KubernetesPaolo Visintin
 
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
 
Scaling Asterisk with Kamailio
Scaling Asterisk with KamailioScaling Asterisk with Kamailio
Scaling Asterisk with KamailioFred Posner
 
FreeSWITCH as a Kickass SBC
FreeSWITCH as a Kickass SBCFreeSWITCH as a Kickass SBC
FreeSWITCH as a Kickass SBCMoises Silva
 
Using Asterisk and Kamailio for Reliable, Scalable and Secure Communication S...
Using Asterisk and Kamailio for Reliable, Scalable and Secure Communication S...Using Asterisk and Kamailio for Reliable, Scalable and Secure Communication S...
Using Asterisk and Kamailio for Reliable, Scalable and Secure Communication S...Fred Posner
 
Three Ways Kamailio Can Help Your FreeSWITCH Deployment
Three Ways Kamailio Can Help Your FreeSWITCH DeploymentThree Ways Kamailio Can Help Your FreeSWITCH Deployment
Three Ways Kamailio Can Help Your FreeSWITCH DeploymentFred Posner
 
Using Kamailio for Scalability and Security
Using Kamailio for Scalability and SecurityUsing Kamailio for Scalability and Security
Using Kamailio for Scalability and SecurityFred Posner
 
SIP and DNS - federation, failover, load balancing and more
SIP and DNS - federation, failover, load balancing and moreSIP and DNS - federation, failover, load balancing and more
SIP and DNS - federation, failover, load balancing and moreOlle E Johansson
 
FreeSWITCH Cluster by K8s
FreeSWITCH Cluster by K8sFreeSWITCH Cluster by K8s
FreeSWITCH Cluster by K8sChien Cheng Wu
 
FreeSWITCH as a Microservice
FreeSWITCH as a MicroserviceFreeSWITCH as a Microservice
FreeSWITCH as a MicroserviceEvan McGee
 
Getting started with SIP Express Media Server SIP app server and SBC - workshop
Getting started with SIP Express Media Server SIP app server and SBC - workshopGetting started with SIP Express Media Server SIP app server and SBC - workshop
Getting started with SIP Express Media Server SIP app server and SBC - workshopstefansayer
 
SIP Testing with FreeSWITCH
SIP Testing with FreeSWITCHSIP Testing with FreeSWITCH
SIP Testing with FreeSWITCHMoises Silva
 
Faster packet processing in Linux: XDP
Faster packet processing in Linux: XDPFaster packet processing in Linux: XDP
Faster packet processing in Linux: XDPDaniel T. Lee
 
Tutorial: Using GoBGP as an IXP connecting router
Tutorial: Using GoBGP as an IXP connecting routerTutorial: Using GoBGP as an IXP connecting router
Tutorial: Using GoBGP as an IXP connecting routerShu Sugimoto
 

What's hot (20)

Sipwise rtpengine
Sipwise rtpengineSipwise rtpengine
Sipwise rtpengine
 
Continuous Integration and Kamailio
Continuous Integration and KamailioContinuous Integration and Kamailio
Continuous Integration and 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 on Docker
Kamailio on DockerKamailio on Docker
Kamailio on Docker
 
Kamailio with Docker and Kubernetes
Kamailio with Docker and KubernetesKamailio with Docker and Kubernetes
Kamailio with Docker and Kubernetes
 
Kamailio - Load Balancing Load Balancers
Kamailio - Load Balancing Load BalancersKamailio - Load Balancing Load Balancers
Kamailio - Load Balancing Load Balancers
 
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.
 
Scaling Asterisk with Kamailio
Scaling Asterisk with KamailioScaling Asterisk with Kamailio
Scaling Asterisk with Kamailio
 
FreeSWITCH as a Kickass SBC
FreeSWITCH as a Kickass SBCFreeSWITCH as a Kickass SBC
FreeSWITCH as a Kickass SBC
 
Using Asterisk and Kamailio for Reliable, Scalable and Secure Communication S...
Using Asterisk and Kamailio for Reliable, Scalable and Secure Communication S...Using Asterisk and Kamailio for Reliable, Scalable and Secure Communication S...
Using Asterisk and Kamailio for Reliable, Scalable and Secure Communication S...
 
Three Ways Kamailio Can Help Your FreeSWITCH Deployment
Three Ways Kamailio Can Help Your FreeSWITCH DeploymentThree Ways Kamailio Can Help Your FreeSWITCH Deployment
Three Ways Kamailio Can Help Your FreeSWITCH Deployment
 
Using Kamailio for Scalability and Security
Using Kamailio for Scalability and SecurityUsing Kamailio for Scalability and Security
Using Kamailio for Scalability and Security
 
SIP and DNS - federation, failover, load balancing and more
SIP and DNS - federation, failover, load balancing and moreSIP and DNS - federation, failover, load balancing and more
SIP and DNS - federation, failover, load balancing and more
 
Astricon 10 (October 2013) - SIP over WebSocket on Kamailio
Astricon 10 (October 2013) - SIP over WebSocket on KamailioAstricon 10 (October 2013) - SIP over WebSocket on Kamailio
Astricon 10 (October 2013) - SIP over WebSocket on Kamailio
 
FreeSWITCH Cluster by K8s
FreeSWITCH Cluster by K8sFreeSWITCH Cluster by K8s
FreeSWITCH Cluster by K8s
 
FreeSWITCH as a Microservice
FreeSWITCH as a MicroserviceFreeSWITCH as a Microservice
FreeSWITCH as a Microservice
 
Getting started with SIP Express Media Server SIP app server and SBC - workshop
Getting started with SIP Express Media Server SIP app server and SBC - workshopGetting started with SIP Express Media Server SIP app server and SBC - workshop
Getting started with SIP Express Media Server SIP app server and SBC - workshop
 
SIP Testing with FreeSWITCH
SIP Testing with FreeSWITCHSIP Testing with FreeSWITCH
SIP Testing with FreeSWITCH
 
Faster packet processing in Linux: XDP
Faster packet processing in Linux: XDPFaster packet processing in Linux: XDP
Faster packet processing in Linux: XDP
 
Tutorial: Using GoBGP as an IXP connecting router
Tutorial: Using GoBGP as an IXP connecting routerTutorial: Using GoBGP as an IXP connecting router
Tutorial: Using GoBGP as an IXP connecting router
 

Similar to Kamailio - SIP Routing in Lua

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 LuaDaniel-Constantin Mierla
 
Aynchronous Processing in Kamailio Configuration File
Aynchronous Processing in Kamailio Configuration FileAynchronous Processing in Kamailio Configuration File
Aynchronous Processing in Kamailio Configuration FileDaniel-Constantin Mierla
 
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
 
Apache Traffic Server & Lua
Apache Traffic Server & LuaApache Traffic Server & Lua
Apache Traffic Server & LuaKit Chan
 
Introduction to Lua Luajit Openresty Luvit
Introduction to Lua Luajit Openresty LuvitIntroduction to Lua Luajit Openresty Luvit
Introduction to Lua Luajit Openresty LuvitLionel Duboeuf
 
Homer - Workshop at Kamailio World 2017
Homer - Workshop at Kamailio World 2017Homer - Workshop at Kamailio World 2017
Homer - Workshop at Kamailio World 2017Giacomo Vacca
 
Designing High Performance RTC Signaling Servers
Designing High Performance RTC Signaling ServersDesigning High Performance RTC Signaling Servers
Designing High Performance RTC Signaling ServersDaniel-Constantin Mierla
 
An Incomplete Data Tools Landscape for Hackers in 2015
An Incomplete Data Tools Landscape for Hackers in 2015An Incomplete Data Tools Landscape for Hackers in 2015
An Incomplete Data Tools Landscape for Hackers in 2015Wes McKinney
 
Advanced technic for OS upgrading in 3 minutes
Advanced technic for OS upgrading in 3 minutesAdvanced technic for OS upgrading in 3 minutes
Advanced technic for OS upgrading in 3 minutesHiroshi SHIBATA
 
Real-Time Log Analysis with Apache Mesos, Kafka and Cassandra
Real-Time Log Analysis with Apache Mesos, Kafka and CassandraReal-Time Log Analysis with Apache Mesos, Kafka and Cassandra
Real-Time Log Analysis with Apache Mesos, Kafka and CassandraJoe Stein
 
Real-time Streaming Pipelines with FLaNK
Real-time Streaming Pipelines with FLaNKReal-time Streaming Pipelines with FLaNK
Real-time Streaming Pipelines with FLaNKData Con LA
 
ApacheCon NA 2010 - Developing Composite Apps for the Cloud with Apache Tuscany
ApacheCon NA 2010 - Developing Composite Apps for the Cloud with Apache TuscanyApacheCon NA 2010 - Developing Composite Apps for the Cloud with Apache Tuscany
ApacheCon NA 2010 - Developing Composite Apps for the Cloud with Apache TuscanyJean-Sebastien Delfino
 
murakumo Cloud Controller
murakumo Cloud Controllermurakumo Cloud Controller
murakumo Cloud ControllerShingo Kawano
 
Web development with Lua @ Bulgaria Web Summit 2016
Web development with Lua @ Bulgaria Web Summit 2016Web development with Lua @ Bulgaria Web Summit 2016
Web development with Lua @ Bulgaria Web Summit 2016Etiene Dalcol
 
Docker at Shopify: From This-Looks-Fun to Production by Simon Eskildsen (Shop...
Docker at Shopify: From This-Looks-Fun to Production by Simon Eskildsen (Shop...Docker at Shopify: From This-Looks-Fun to Production by Simon Eskildsen (Shop...
Docker at Shopify: From This-Looks-Fun to Production by Simon Eskildsen (Shop...Docker, Inc.
 
Serverless Pune meetup 3
Serverless Pune meetup 3Serverless Pune meetup 3
Serverless Pune meetup 3Vishal Biyani
 
Python the lingua franca of FEWS
Python the lingua franca of FEWSPython the lingua franca of FEWS
Python the lingua franca of FEWSLindsay Millard
 

Similar to Kamailio - SIP Routing in Lua (20)

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
 
Aynchronous Processing in Kamailio Configuration File
Aynchronous Processing in Kamailio Configuration FileAynchronous Processing in Kamailio Configuration File
Aynchronous Processing in Kamailio Configuration File
 
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
 
Apache Traffic Server & Lua
Apache Traffic Server & LuaApache Traffic Server & Lua
Apache Traffic Server & Lua
 
Introduction to Lua Luajit Openresty Luvit
Introduction to Lua Luajit Openresty LuvitIntroduction to Lua Luajit Openresty Luvit
Introduction to Lua Luajit Openresty Luvit
 
SIP Router Project
SIP Router ProjectSIP Router Project
SIP Router Project
 
Homer - Workshop at Kamailio World 2017
Homer - Workshop at Kamailio World 2017Homer - Workshop at Kamailio World 2017
Homer - Workshop at Kamailio World 2017
 
Designing High Performance RTC Signaling Servers
Designing High Performance RTC Signaling ServersDesigning High Performance RTC Signaling Servers
Designing High Performance RTC Signaling Servers
 
Kamailio Updates - VUC 588
Kamailio Updates - VUC 588Kamailio Updates - VUC 588
Kamailio Updates - VUC 588
 
An Incomplete Data Tools Landscape for Hackers in 2015
An Incomplete Data Tools Landscape for Hackers in 2015An Incomplete Data Tools Landscape for Hackers in 2015
An Incomplete Data Tools Landscape for Hackers in 2015
 
Advanced technic for OS upgrading in 3 minutes
Advanced technic for OS upgrading in 3 minutesAdvanced technic for OS upgrading in 3 minutes
Advanced technic for OS upgrading in 3 minutes
 
Knolx session
Knolx sessionKnolx session
Knolx session
 
Real-Time Log Analysis with Apache Mesos, Kafka and Cassandra
Real-Time Log Analysis with Apache Mesos, Kafka and CassandraReal-Time Log Analysis with Apache Mesos, Kafka and Cassandra
Real-Time Log Analysis with Apache Mesos, Kafka and Cassandra
 
Real-time Streaming Pipelines with FLaNK
Real-time Streaming Pipelines with FLaNKReal-time Streaming Pipelines with FLaNK
Real-time Streaming Pipelines with FLaNK
 
ApacheCon NA 2010 - Developing Composite Apps for the Cloud with Apache Tuscany
ApacheCon NA 2010 - Developing Composite Apps for the Cloud with Apache TuscanyApacheCon NA 2010 - Developing Composite Apps for the Cloud with Apache Tuscany
ApacheCon NA 2010 - Developing Composite Apps for the Cloud with Apache Tuscany
 
murakumo Cloud Controller
murakumo Cloud Controllermurakumo Cloud Controller
murakumo Cloud Controller
 
Web development with Lua @ Bulgaria Web Summit 2016
Web development with Lua @ Bulgaria Web Summit 2016Web development with Lua @ Bulgaria Web Summit 2016
Web development with Lua @ Bulgaria Web Summit 2016
 
Docker at Shopify: From This-Looks-Fun to Production by Simon Eskildsen (Shop...
Docker at Shopify: From This-Looks-Fun to Production by Simon Eskildsen (Shop...Docker at Shopify: From This-Looks-Fun to Production by Simon Eskildsen (Shop...
Docker at Shopify: From This-Looks-Fun to Production by Simon Eskildsen (Shop...
 
Serverless Pune meetup 3
Serverless Pune meetup 3Serverless Pune meetup 3
Serverless Pune meetup 3
 
Python the lingua franca of FEWS
Python the lingua franca of FEWSPython the lingua franca of FEWS
Python the lingua franca of FEWS
 

More from Daniel-Constantin Mierla

More from Daniel-Constantin Mierla (14)

FOSDEM 2017 - RTC Services With Lua and Kamailio
FOSDEM 2017 - RTC Services With Lua and KamailioFOSDEM 2017 - RTC Services With Lua and Kamailio
FOSDEM 2017 - RTC Services With Lua and Kamailio
 
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
 
Snappy Kamailio
Snappy KamailioSnappy Kamailio
Snappy Kamailio
 
Kamailio - Surfing Big Waves Of SIP With Style
Kamailio - Surfing Big Waves Of SIP With StyleKamailio - Surfing Big Waves Of SIP With Style
Kamailio - Surfing Big Waves Of SIP With Style
 
SIP Server Optimizations for Mobile Networks
SIP Server Optimizations for Mobile NetworksSIP Server Optimizations for Mobile Networks
SIP Server Optimizations for Mobile Networks
 
Kamailio and VoIP Wild World
Kamailio and VoIP Wild WorldKamailio and VoIP Wild World
Kamailio and VoIP Wild World
 
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
 
Kamailio - Large Unified Communication Platforms
Kamailio - Large Unified Communication PlatformsKamailio - Large Unified Communication Platforms
Kamailio - Large Unified Communication Platforms
 
Kamailio - SIP Servers Everywhere
Kamailio - SIP Servers EverywhereKamailio - SIP Servers Everywhere
Kamailio - SIP Servers Everywhere
 
Kamailio - SIP Firewall for Carrier Grade Traffic
Kamailio - SIP Firewall for Carrier Grade TrafficKamailio - SIP Firewall for Carrier Grade Traffic
Kamailio - SIP Firewall for Carrier Grade Traffic
 
Kamailio - The Story for Asterisk
Kamailio - The Story for AsteriskKamailio - The Story for Asterisk
Kamailio - The Story for Asterisk
 

Recently uploaded

Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfOverkill Security
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 

Recently uploaded (20)

Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 

Kamailio - SIP Routing in Lua

  • 1.
  • 2. Kamailio SIP LUA Amoocon 2010 Rostock, Germany Do Your SIP Routing In Lua! Daniel-Constantin Mierla Co-Founder Kamailio (OpenSER) www.asipto.com
  • 3. Kamailio SIP Lua It is all about love www.kamailio.org 2 Wine, moon ... and you ... hacking SIP
  • 4. Kamailio SIP Lua Instead of introduction • if you missed my previous presentation • “The SIP Router Project - Asynchronous SIP Routing” Links: • http://www.kamailio.org • http://sip-router.org • http://www.lua.org www.kamailio.org 3
  • 5. Kamailio SIP Lua Lua What is Lua? • Lua is a powerful, fast, lightweight, embeddable scripting language. • Lua combines simple procedural syntax with powerful data description constructs based on associative arrays and extensible semantics. Lua is dynamically typed, runs by interpreting bytecode for a register-based virtual machine, and has automatic memory management with incremental garbage collection, making it ideal for configuration, scripting, and rapid prototyping. • http://www.lua.org www.kamailio.org 4
  • 6. Kamailio SIP Lua Lua Why choose Lua? • Lua has been used in many industrial applications (e.g., Adobe's Photoshop Lightroom), with an emphasis on embedded systems (e.g., the Ginga middleware for digital TV in Brazil) and games (e.g., World of Warcraft). Lua is currently the leading scripting language in games.. • Lua is supported by other telephony engines, e.g., Asterisk and FreeSWITCH • http://www.lua.org www.kamailio.org 5
  • 7. Kamailio SIP Lua Lua More about Lua? • is fast • is portable • is embeddable • is powerful (but simple) • is small • is free • http://www.lua.org www.kamailio.org 6
  • 8. Kamailio SIP Lua Kamailio and SIP routing Where we stand today? • flexible configuration language, still limited pretty much to SIP only • the power is in hands (and brain) of administrator • SIP specific extensions added mainly by writing C modules • for the rest: Lua, Perl, Python and Java www.kamailio.org 7
  • 9. Kamailio SIP Lua Kamailio and Lua Why together? • need to integrate with other communication platforms • it is about realtime communication, so being fast is important • routing logic may require non-SIP related operations • all characteristics of Lua indicates it a very good candidate www.kamailio.org 8
  • 10. Kamailio SIP Lua Kamailio and Lua How does it work? • load module: app_lua • Lua scripts can be loaded at startup or on-the-fly at runtime • entire Lua scripts can be executed or just functions from the scripts • Lua scripts have access to SIP messages and config variables • Lua scripts can return back config variables • Lua scripts can execute functions from config file http://kamailio.org/docs/modules/devel/modules/app_lua.html www.kamailio.org 9
  • 11. Kamailio SIP Lua Kamailio Lua API Lua packages • package sr • access to Kamailio core functions • method to execute functions exported by modules • container for other sub-packages • package sr.hdr • header manipulation • get, add, remove • package sr.pv • pseudo-variables manipulation • access to all pseudo-variables - hundreds of them • package sr.sl • exports internal sl module API (stateless reply) http://sip-router.org/wiki/api/lua/devel www.kamailio.org 10
  • 12. sr.hdr.append_to_reply("X-Src: " .. sr.pv.get("$si") .. ":" .. sr.pv.get("$sp") .. "rn"); Kamailio SIP Lua Kamailio Lua API Basic example Lua script: function sr_append_srcaddr_to_reply() end Kamailio config: modparam("app_lua", "load", "/path/to/myscript.lua") ... route { ... if(!lua_run("sr_append_srcaddr_to_reply")) { xdbg("SCRIPT: failed to execute lua function!n"); } ... } www.kamailio.org 11
  • 13. Kamailio SIP Lua SIPWEET www.kamailio.org 12
  • 14. Kamailio SIP Lua SIPWEET 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 www.kamailio.org 13
  • 15. Kamailio SIP Lua SIPWEET 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 www.kamailio.org 14
  • 16. Kamailio SIP Lua SIPWEET Config loadmodule "app_lua.so" loadmodule "rtimer.so" loadmodule "sqlops.so" loadmodule “mqueue.so” # ----- app_lua ----- modparam("app_lua", "load", "usr/local/etc/kamailio/lua/sipweet.lua") # ----- rtimer ----- modparam("rtimer", "timer", "name=sipweet;interval=60;mode=1;") modparam("rtimer", "exec", "timer=sipweet;route=SIPWEET;") # ----- sqlops ----- modparam("sqlops","sqlcon", "ca=>mysql://openser:openserrw@localhost/openser") # ----- mqueue ----- modparam("mqueue", "mqueue", "name=sipweet") www.kamailio.org 15
  • 17. Kamailio SIP Lua SIPWEET Config # Twitter routing route[SIPWEET] { # consume tweeties while(mq_fetch("sipweet")) { xlog("Tweeting to $mqk(sipweet) [[$mqv(sipweet)]]n"); # get twitter user sql_query("ca", "select twuser from sipweetusers where sipuser='$mqk(sipweet)'", "ra"); if($dbr(ra=>rows)>0) { $var(twuser) = $dbr(ra=>[0,0]); $var(twuser) = $mqv(sipweet); if(!lua_runstring("sipweetdm([[$var(twuser)]], [[$var(twmsg)]])")) { xdbg("failed to send dm to: $mqk(sipweet) - $var(twuser)!n"); } } } } www.kamailio.org 16
  • 18. Kamailio SIP Lua SIPWEET Config # Twitees queuing route[TWQUEUE] { if(!is_method("INVITE")) return; mq_add("sipweet", "$rU", "Missed call from $fU [$Tf]"); } route { ... if(!lookup(“location”)) { route(TWQUEUE); t_newtran(); t_reply("404", "Not Found"); exit; } ... } www.kamailio.org 17
  • 19. Kamailio SIP Lua SIPWEET Database table CREATE TABLE `sipweetusers` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `twuser` varchar(64) NOT NULL, `sipuser` varchar(64) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY (`twuser`), UNIQUE KEY (`sipuser`) ); www.kamailio.org 18
  • 20. Kamailio SIP Lua SIPWEET Lua script -- SIPweet -- loading module local twitter = require("twitter") local initialized = 0 local me function sipweetinit() if initialized == 0 then me = twitter.Client( "TWUSER", "TWPASSWD" ) tret = me:VerifyCredentials() initialized = 1 end end function sipweetdm(user, txt) sipweetinit() tret = me:NewDirectMessage(user, txt) end www.kamailio.org 19
  • 21. Kamailio SIP Lua SIPWEET And the messages goes ... • nice and quick to your twitter client www.kamailio.org 20
  • 22. Meet us next week in Berlin • Developer Meeting, Tue, Jun 8 • LinuxTag Booth, Jun 9-12 Kamailio SIP Lua SIPWEET Concluding • This was a proof of concept to do easy twitter integration • Kamailio Lua API • Asynchronous Twitter Notification System by Config Only • Improvements and new services at your imagination • or mine - prepare the credit card or a good bottle of wine • follow us - cool stuff ahead Contact •Daniel-Constantin Mierla •twitter: miconda •daniel@asipto.com •http://www.asipto.com •http://www.kamailio.org Questions? www.kamailio.org 21