SlideShare a Scribd company logo
Astricon 2020 Fred Posner
Scaling with Kamailio
Using Kamailio and Asterisk to
Create Secure and Scalable Solutions
Astricon 2020 Fred Posner
Kamawhat?
●
Kah-mah-illie-oh
●
Hawaiian Word
●
To communicate
Astricon 2020 Fred Posner
Who am I?
●
Fred Posner
●
qxork.com
●
@fredposner
●
Consultant
Astricon 2020 Fred Posner
Agenda
●
What is Kamailio?
●
What’s new in
Kamailio 5.4?
●
Common Deployment
Scenarios
●
Examples
Astricon 2020 Fred Posner
What is Kamailio?
Astricon 2020 Fred Posner
Astricon 2020 Fred Posner
What is Kamailio
●
SIP proxy server
●
SIP registrar server
●
SIP location server
●
SIP application server
●
SIP dispatcher server
●
SIP websocket server
Astricon 2020 Fred Posner
What isn’t Kamailio?
Astricon 2020 Fred Posner
Kamailio cannot be...
●
B2BUA
●
SIP Phone
●
Media server*
Astricon 2020 Fred Posner
Selected Benefits
●
Open Source
●
Longevity
●
Small Footprint
●
Interoperability
●
Fast
●
Modular
Astricon 2020 Fred Posner
Kamailio is Modular
Astricon 2020 Fred Posner
Selected Modules: HTABLE
●
Hash Table Module
●
Stored in shared
memory
●
Custom cache system
●
Replication via DMQ
Astricon 2020 Fred Posner
Selected Modules: KEMI
●
Python
●
LUA
●
JavaScript
●
Ruby
●
Squirrel
●
https://kamailio.org/docs/
tutorials/devel/kamailio-
kemi-framework/
●
Use other scripting
languages to write SIP
routing
Astricon 2020 Fred Posner
Selected Modules: DMQ
●
Distributed Message
Queue
●
Replicate data to
other Kamailio nodes
Astricon 2020 Fred Posner
Selected Modules: Dispatcher
●
SIP Load Balancer
●
Stateless, Lightweight
●
Various Algorithms
●
New: Latency based
dispatching
Astricon 2020 Fred Posner
What’s new in 5.4?
Astricon 2020 Fred Posner
New Modules: Kafka / DLGS
●
Produces and sends
messages to a Kafka
server
●
Tracks dialogs in
stateless mode
Astricon 2020 Fred Posner
New Modules: MQTT / SECSIPID
●
Bidirectional
publish/subscribe
communication to a
MQTT Broker
●
STIR and SHAKEN IETF
extensions for SIP
(RFC8224, RFC 8588)
Astricon 2020 Fred Posner
New in 5.4
●
New modules: 5
●
Updated modules: 70
●
KEMI optimizations
●
Core updates
●
And mucho, mucho mas
Astricon 2020 Fred Posner
Common Deployment Scenarios
Astricon 2020 Fred Posner
Simple Edge Router
Astricon 2020 Fred Posner
Bridge
Astricon 2020 Fred Posner
Bridge
Astricon 2020 Fred Posner
Dispatcher / Load Balancer
Astricon 2020 Fred Posner
Dispatcher / Load Balancer
Astricon 2020 Fred Posner
Astricon 2020 Fred Posner
Astricon 2020 Fred Posner
Astricon 2020 Fred Posner
Examples
Astricon 2020 Fred Posner
Blocking by User-Agent - $ua
if($ua =~ "friendly-scanner|sipcli|sipvicious|VaxSIPUserAgent") {
# silent drop for scanners - uncomment next line if want to reply
# sl_send_reply("200", "OK");
exit;
}
Astricon 2020 Fred Posner
Adding to HTABLE
if($sht(ipban=>$si)!=$null) {
# ip is already blocked
xdbg("request from blocked IP - $rm from $fu (IP:$si:$sp)n");
exit;
}
...
if($ua =~ "friendly-scanner|sipcli|sipvicious|VaxSIPUserAgent") {
$sht(ipban=>$si) = 1;
# silent drop for scanners - uncomment next line if want to reply
# sl_send_reply("200", "OK");
exit;
}
Astricon 2020 Fred Posner
Dispatching Requests
# Dispatch requests
route[DISPATCH] {
# round robin dispatching on gateways group '1'
if(!ds_select_dst("1", "4")) {
send_reply("404", "No destination");
exit;
}
xdbg("--- SCRIPT: going to <$ru> via <$du> (attrs: $xavp(_dsdst_=>attrs))n");
t_on_failure("RTF_DISPATCH");
route(RELAY);
exit;
}
Astricon 2020 Fred Posner
Dispatching Requests
# Try next destionations in failure route
failure_route[RTF_DISPATCH] {
if (t_is_canceled()) {
exit;
}
# next DST - only for 500 or local timeout
if (t_check_status("500")
or (t_branch_timeout() and !t_branch_replied())) {
if(ds_next_dst()) {
xdbg("--- SCRIPT: retrying to <$ru> via <$du> (attrs: $xavp(_dsdst_=>attrs))n");
t_on_failure("RTF_DISPATCH");
route(RELAY);
exit;
}
}
}
Astricon 2020 Fred Posner
Dispatching Requests
event_route[dispatcher:dst-down] {
xlog("L_ERR", "Destination down: $rm
$ru ($du)n");
http_client_query("$var(pagerduty)",
"$var(response)");
}
Astricon 2020 Fred Posner
Failure Routes FTW
●
Check for reply, CANCEL, status code
●
Can be set as needed
if (t_check_status("5[0-9][0-9]")){
# I do not like the 5xx responses,
# so I give another chance to "foobar.com",
# and I drop all the replies to make sure that
# they are not forwarded to the caller.
t_drop_replies();
rewritehostport("foobar.com");
append_branch();
t_relay();
}
Astricon 2020 Fred Posner
Fail / Reply / Branching / Serial
●
Status checks
●
CANCEL checks
●
Use your own logic to supply what to do
●
Great also for PSTN
Astricon 2020 Fred Posner
Thank You!
●
kamailio.org
●
Mail lists, IRC, Matrix
●
YouTube (kamailioworld)
●
@kamailio

More Related Content

ODP
Expanding Asterisk with Kamailio
ODP
Using Asterisk and Kamailio for Reliable, Scalable and Secure Communication S...
PDF
Kamailio - API Based SIP Routing
PDF
Using Kamailio for Scalability and Security
PDF
SIP Attack Handling (Kamailio World 2021)
PDF
rtpengine - Media Relaying and Beyond
PDF
rtpengine and kamailio - or how to simulate calls at scale
PDF
Kamailio, FreeSWITCH, and You
Expanding Asterisk with Kamailio
Using Asterisk and Kamailio for Reliable, Scalable and Secure Communication S...
Kamailio - API Based SIP Routing
Using Kamailio for Scalability and Security
SIP Attack Handling (Kamailio World 2021)
rtpengine - Media Relaying and Beyond
rtpengine and kamailio - or how to simulate calls at scale
Kamailio, FreeSWITCH, and You

What's hot (20)

PDF
Three Ways Kamailio Can Help Your FreeSWITCH Deployment
PDF
Kamailio - SIP Routing in Lua
PDF
Kamailio with Docker and Kubernetes
PDF
Sipwise rtpengine
PDF
Kamailio :: A Quick Introduction
PDF
Kamalio and Asterisk: What, Why & How
PDF
Kamailio on Docker
PDF
Continuous Integration and Kamailio
ODP
Phpconf 2013 - Agile Telephony Applications with PAMI and PAGI
PDF
SIPREC RTPEngine Media Forking
PDF
Mikrotik Fastpath vs Fasttrack
PDF
Kamailio - Load Balancing Load Balancers
PDF
Homer metrics | LORENZO MANGANI Y FEDERICO CABIDDU - VoIP2DAY 2017
PDF
High Availability PostgreSQL with Zalando Patroni
PDF
gRPC: The Story of Microservices at Square
PDF
Kamailio - Secure Communication
PDF
Kamailio - SIP Firewall for Carrier Grade Traffic
PDF
Astricon 10 (October 2013) - SIP over WebSocket on Kamailio
PDF
Aynchronous Processing in Kamailio Configuration File
PDF
gRPC Overview
Three Ways Kamailio Can Help Your FreeSWITCH Deployment
Kamailio - SIP Routing in Lua
Kamailio with Docker and Kubernetes
Sipwise rtpengine
Kamailio :: A Quick Introduction
Kamalio and Asterisk: What, Why & How
Kamailio on Docker
Continuous Integration and Kamailio
Phpconf 2013 - Agile Telephony Applications with PAMI and PAGI
SIPREC RTPEngine Media Forking
Mikrotik Fastpath vs Fasttrack
Kamailio - Load Balancing Load Balancers
Homer metrics | LORENZO MANGANI Y FEDERICO CABIDDU - VoIP2DAY 2017
High Availability PostgreSQL with Zalando Patroni
gRPC: The Story of Microservices at Square
Kamailio - Secure Communication
Kamailio - SIP Firewall for Carrier Grade Traffic
Astricon 10 (October 2013) - SIP over WebSocket on Kamailio
Aynchronous Processing in Kamailio Configuration File
gRPC Overview
Ad

More from Fred Posner (7)

PDF
Security Asterisk or FreePBX with APIBAN
PDF
Protect Kamailio Against DoS Attacks With APIBan
PDF
Kamailio, FreeSWITCH, and the Half-Blood Prince
PDF
CommCon 2020: Kamailio for RTC Stability, Scaling, and Security
PPTX
Introduction to Kamailio (TADSummit 2020 Asia)
PDF
Three Ways Kamailio Can Help Your Asterisk Deployment
PDF
Advanced SIP: Communicating with Humans (Kamailio World 2019)
Security Asterisk or FreePBX with APIBAN
Protect Kamailio Against DoS Attacks With APIBan
Kamailio, FreeSWITCH, and the Half-Blood Prince
CommCon 2020: Kamailio for RTC Stability, Scaling, and Security
Introduction to Kamailio (TADSummit 2020 Asia)
Three Ways Kamailio Can Help Your Asterisk Deployment
Advanced SIP: Communicating with Humans (Kamailio World 2019)
Ad

Recently uploaded (20)

PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Encapsulation theory and applications.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Electronic commerce courselecture one. Pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Encapsulation theory and applications.pdf
The AUB Centre for AI in Media Proposal.docx
sap open course for s4hana steps from ECC to s4
Reach Out and Touch Someone: Haptics and Empathic Computing
Machine learning based COVID-19 study performance prediction
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Electronic commerce courselecture one. Pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Network Security Unit 5.pdf for BCA BBA.
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Programs and apps: productivity, graphics, security and other tools
MIND Revenue Release Quarter 2 2025 Press Release
Review of recent advances in non-invasive hemoglobin estimation
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Unlocking AI with Model Context Protocol (MCP)
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Chapter 3 Spatial Domain Image Processing.pdf

Scaling Asterisk with Kamailio

  • 1. Astricon 2020 Fred Posner Scaling with Kamailio Using Kamailio and Asterisk to Create Secure and Scalable Solutions
  • 2. Astricon 2020 Fred Posner Kamawhat? ● Kah-mah-illie-oh ● Hawaiian Word ● To communicate
  • 3. Astricon 2020 Fred Posner Who am I? ● Fred Posner ● qxork.com ● @fredposner ● Consultant
  • 4. Astricon 2020 Fred Posner Agenda ● What is Kamailio? ● What’s new in Kamailio 5.4? ● Common Deployment Scenarios ● Examples
  • 5. Astricon 2020 Fred Posner What is Kamailio?
  • 7. Astricon 2020 Fred Posner What is Kamailio ● SIP proxy server ● SIP registrar server ● SIP location server ● SIP application server ● SIP dispatcher server ● SIP websocket server
  • 8. Astricon 2020 Fred Posner What isn’t Kamailio?
  • 9. Astricon 2020 Fred Posner Kamailio cannot be... ● B2BUA ● SIP Phone ● Media server*
  • 10. Astricon 2020 Fred Posner Selected Benefits ● Open Source ● Longevity ● Small Footprint ● Interoperability ● Fast ● Modular
  • 11. Astricon 2020 Fred Posner Kamailio is Modular
  • 12. Astricon 2020 Fred Posner Selected Modules: HTABLE ● Hash Table Module ● Stored in shared memory ● Custom cache system ● Replication via DMQ
  • 13. Astricon 2020 Fred Posner Selected Modules: KEMI ● Python ● LUA ● JavaScript ● Ruby ● Squirrel ● https://kamailio.org/docs/ tutorials/devel/kamailio- kemi-framework/ ● Use other scripting languages to write SIP routing
  • 14. Astricon 2020 Fred Posner Selected Modules: DMQ ● Distributed Message Queue ● Replicate data to other Kamailio nodes
  • 15. Astricon 2020 Fred Posner Selected Modules: Dispatcher ● SIP Load Balancer ● Stateless, Lightweight ● Various Algorithms ● New: Latency based dispatching
  • 16. Astricon 2020 Fred Posner What’s new in 5.4?
  • 17. Astricon 2020 Fred Posner New Modules: Kafka / DLGS ● Produces and sends messages to a Kafka server ● Tracks dialogs in stateless mode
  • 18. Astricon 2020 Fred Posner New Modules: MQTT / SECSIPID ● Bidirectional publish/subscribe communication to a MQTT Broker ● STIR and SHAKEN IETF extensions for SIP (RFC8224, RFC 8588)
  • 19. Astricon 2020 Fred Posner New in 5.4 ● New modules: 5 ● Updated modules: 70 ● KEMI optimizations ● Core updates ● And mucho, mucho mas
  • 20. Astricon 2020 Fred Posner Common Deployment Scenarios
  • 21. Astricon 2020 Fred Posner Simple Edge Router
  • 22. Astricon 2020 Fred Posner Bridge
  • 23. Astricon 2020 Fred Posner Bridge
  • 24. Astricon 2020 Fred Posner Dispatcher / Load Balancer
  • 25. Astricon 2020 Fred Posner Dispatcher / Load Balancer
  • 29. Astricon 2020 Fred Posner Examples
  • 30. Astricon 2020 Fred Posner Blocking by User-Agent - $ua if($ua =~ "friendly-scanner|sipcli|sipvicious|VaxSIPUserAgent") { # silent drop for scanners - uncomment next line if want to reply # sl_send_reply("200", "OK"); exit; }
  • 31. Astricon 2020 Fred Posner Adding to HTABLE if($sht(ipban=>$si)!=$null) { # ip is already blocked xdbg("request from blocked IP - $rm from $fu (IP:$si:$sp)n"); exit; } ... if($ua =~ "friendly-scanner|sipcli|sipvicious|VaxSIPUserAgent") { $sht(ipban=>$si) = 1; # silent drop for scanners - uncomment next line if want to reply # sl_send_reply("200", "OK"); exit; }
  • 32. Astricon 2020 Fred Posner Dispatching Requests # Dispatch requests route[DISPATCH] { # round robin dispatching on gateways group '1' if(!ds_select_dst("1", "4")) { send_reply("404", "No destination"); exit; } xdbg("--- SCRIPT: going to <$ru> via <$du> (attrs: $xavp(_dsdst_=>attrs))n"); t_on_failure("RTF_DISPATCH"); route(RELAY); exit; }
  • 33. Astricon 2020 Fred Posner Dispatching Requests # Try next destionations in failure route failure_route[RTF_DISPATCH] { if (t_is_canceled()) { exit; } # next DST - only for 500 or local timeout if (t_check_status("500") or (t_branch_timeout() and !t_branch_replied())) { if(ds_next_dst()) { xdbg("--- SCRIPT: retrying to <$ru> via <$du> (attrs: $xavp(_dsdst_=>attrs))n"); t_on_failure("RTF_DISPATCH"); route(RELAY); exit; } } }
  • 34. Astricon 2020 Fred Posner Dispatching Requests event_route[dispatcher:dst-down] { xlog("L_ERR", "Destination down: $rm $ru ($du)n"); http_client_query("$var(pagerduty)", "$var(response)"); }
  • 35. Astricon 2020 Fred Posner Failure Routes FTW ● Check for reply, CANCEL, status code ● Can be set as needed if (t_check_status("5[0-9][0-9]")){ # I do not like the 5xx responses, # so I give another chance to "foobar.com", # and I drop all the replies to make sure that # they are not forwarded to the caller. t_drop_replies(); rewritehostport("foobar.com"); append_branch(); t_relay(); }
  • 36. Astricon 2020 Fred Posner Fail / Reply / Branching / Serial ● Status checks ● CANCEL checks ● Use your own logic to supply what to do ● Great also for PSTN
  • 37. Astricon 2020 Fred Posner Thank You! ● kamailio.org ● Mail lists, IRC, Matrix ● YouTube (kamailioworld) ● @kamailio