SlideShare una empresa de Scribd logo
1 de 34
Descargar para leer sin conexión
Surfing BigWaves of SIP with Style
Daniel-Constantin Mierla @miconda - www.asipto.com - Co-Founder Kamailio
October 2015
a very large set of features
kamailio
continuos development since 2001
2002 Jun 2005 Jul 2008 Aug 2008 Nov 2008
SIP Express Router (SER)
OpenSER Kamailio
Other Forks...
Same application: Kamailio - SER
Oct 2009 Jan 2010
v3.0.0
Integration
Completed
v1.5.0
Sep 2011Sep 2001
First
Line
Of
Code
Open
Source
GPL
FhG
Fokus
Institute
Berlin
rename
Awarded
Best Open
Source
Networking
Software
2009
By InfoWorld
10
Years
Jun 2012
v3.3.0
ITSPA
UK
Award
Mar 2013
v4.0.0
Kamailio
v4.1.0
Dec 2013
………. v4.2.0
Oct 2014
now over 100 on github
June 2015
v4.3.0
not designed as a typical telephony engine
open source sip server
framework - toolkit
SIP signalling routing
• fast
• reliable
• flexible
In other words
• not initiating calls
• not answering calls
• no audio-video processing
Key Features
✤ Modular SIP Poxy, 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
Dealing with high
SIP traffic volume
Detect and require a retry after a while
Increase performances of a Kamailio
instance
Scale the RTC platform
detect and require a retry after a while
Registration
sip registrar tunings
REGISTER
(contact address)
REGISTER
(contact address)
(credentials)
401
(authentication req)
200 OK
(contact addresses)
SIP Registrar
Require user's
authentication
Authenticate user
Save contact address
Confirm registration
✤ registration storms
✤ reply to retry after
✤ randomize expires value
…
modparam("registrar", "expires_range", 30) # expires within [0.7*expires .. expires]
modparam("registrar", "retry_after", 30)
…
$var(retry) = 10 + ($RANDOM mod 300);
append_to_reply(“Retry-After: rn”);
send_reply(“500”, “Try later”);
…
Authentication
sip authentication tunings
INVITE B@Y
Alice Server Y
407 Proxy Authentication Required
Proxy-Authenticate:....
....realm=X,nonce=aaa
Proxy X
INVITE B@Y
Proxy-Authorization:....
....user=A,realm=X,uri=B@Y,
....nonce=aaa,response=bbb
INVITE B@Y
Proxy-Authorization:....
....user=alice,realm=X,uri=b@Y,
....nonce=aaa,response=bbb
401 Unauthorized
WWW-Authenticate:....
....realm=Y,nonce=ccc
401 Unauthorized
WWW-Authenticate:....
....realm=Y,nonce=ccc
INVITE B@Y
Proxy-Authorization:....
....user=A,realm=X,uri=B@Y,
....nonce=aaa,response=bbb
Authorization: ....
....user=A,realm=Y,uri=B@Y
....nonce=ccc,response=ddd
INVITE B@Y
Proxy-Authorization:....
....user=A,realm=X,uri=B@Y,
....nonce=aaa,response=bbb
Authorization: ....
....user=A,realm=Y,uri=B@Y
....nonce=ccc,response=ddd
✤ caching user profile
✤ password and other attributes
✤ check first the cache, if not found, then fetch from database and store in memory
…
loadmodule "auth.so"
loadmodule “auth_db.so"
loadmodule "htable.so"
…
modparam("auth_db", "db_url", DBURL)
modparam("auth_db", "calculate_ha1", yes)
modparam("auth_db", "password_column", "password")
modparam("auth_db", "load_credentials", “$avp(password)=password”)
modparam("auth_db", "use_domain", MULTIDOMAIN)
…
modparam("htable", "htable", "users=>size=10;autoexpire=300;")
…
…
route[AUTH] {
….
if (is_method("REGISTER") || from_uri==myself)
{
# authenticate requests
if($sht(users=>$fU)!=$null) {
if (!pv_auth_check(“$fd”, “$sht(users=>$fU)”, “0”, ”1”)) {
auth_challenge("$fd", "0");
exit;
}
} else {
if (!auth_check("$fd", "subscriber", "1")) {
auth_challenge("$fd", "0");
exit;
}
$sht(users=>$fU) = $avp(password);
}
# user authenticated - remove auth header
if(!is_method("REGISTER|PUBLISH"))
consume_credentials();
}
…
✤ client certificate or key based authentication
✤ avoid the auth challenge extra round trip
✤ tls with client certificate
✤ auth_xkey module
…
modparam("auth_xkeys", "xkey", "id=abc;name=xyz;value=secret;expires=72000")
…
…
auth_xkeys_add("X-My-Key", "abc", "sha256", "$Ri:$fu:$ru:$hdr(CSeq)");
…
if(!auth_xkeys_add("X-My-Key", "abc", "sha256", "$si:$fu:$ru:$hdr(CSeq)")) {
send_reply("403", "Forbidden");
exit;
}
remove_hf("X-My-Key");
…
Forwarding
sip proxy tunings
alice
bob
proxy
server
INVITE
sip:b@sipserver.net
INVITE
sip:b@newaddress.ip
100 Trying
100 Trying
200 OK
200 OK
180 Ringing
✤ pipelimit
✤ reply with retry after
✤ send redirect to another node
…
$var(retry) = 10 + ($RANDOM mod 300);
append_to_reply(“Retry-After: rn”);
send_reply(“503”, “Try later”);
…
…
$var(limit) = 20;
if (!pl_check("$au", "TAILDROP", "$var(limit)")) {
pl_drop(“10”, “60”);
exit;
}
…
…
if (!pl_check("$au", "TAILDROP", "$var(limit)")) {
$ru = “sip:” + $rU + “@newserver.net”;
send_reply(“302”, “Moved temporarily”);
exit;
}
…
increase performances of a sip server instance
✤ timer processes
✤ lazy operations for many modules
✤ keep alives, cleaning expired data
✤ increase (or reduce) the timer interval
…
modparam("usrloc", "timer_procs", 4)
…
modparam("nathelper", "natping_processes", 6)
…
modparam("dialog", "timer_procs", 4)
modparam("dialog", "ka_timer", 10)
modparam("dialog", "ka_interval", 300)
…
✤ internal hash sizes
✤ indexing of data in memory
✤ location records (usrloc), dialogs, generic hash tables
…
modparam("usrloc", "hash_size", 12)
…
modparam("htable", "htable", “a=>size=4;autoexpire=7200;")
modparam("htable", "htable", "b=>size=8;")
…
modparam("dispatcher", "ds_hash_size", 9)
…
https://en.wikipedia.org/wiki/Hash_table
Hash Table Head
name:test
size: 2
key: alice
slots
“xyz”
0
1
2
3
key: bob
123
key: john
“1ab”
✤ asynchronous processing
✤ delegate the execution to other workers than sip routing processes
✤ async module
✤ tmx (suspend) - mqueue (transmit) - rtimer (process)
✤ async database queries (mysql)
✤ async http/jsonrpc interactions
…
async_workers=4
…
modparam("sqlops","sqlcon","ca=>dbdriver://username:password@dbhost/dbname")
sql_query_async("ca", "delete from domain");
…
modparam("acc", "db_insert_mode", 2)
…
http://www.kamailio.org/events/2014-KamailioWorld/day2/26-Daniel-Constantin.Mierla-Kamailio.cfg-Async.pdf
✤ bonus
✤ children
✤ number of worker processes
✤ tcp - tls
✤ max connections
✤ file description limits
✤ internal dns caching
✤ blacklisting
✤ don’t forget
✤ database indexes
✤ syslog asynchronous mode
✤ dns infrastructure availability
✤ api services responsiveness
scale the rtc platform
dispatcher module
• list of balancing nodes from file or database
• monitoring of nodes (activate/inactivate
automatically)
• re-route in case of failure
• various algorithms: hashing, weight distribution, round
robin, call load distribution, priority routing
• reload list of nodes without restart
# 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>n");
t_on_failure("RTF_DISPATCH");
route(RELAY);
exit;
}
# Re-route in case of failure
failure_route[RTF_DISPATCH] {
if (t_is_canceled()) {
exit;
}
# next node - only for 500 or local timeout
if (t_check_status(“500") || (t_branch_timeout() && !t_branch_replied())) {
if(ds_next_dst()) {
t_on_failure("RTF_DISPATCH");
route(RELAY);
exit;
}
}
}
Load balancing
Parallel Forking
request_route {
...
append_branch(“sip:103@kamailio.org”);
append_branch(“sip:104@kamailio.org”);
$var(newdst) = “sip:105@kamailio.org”;
append_branch(“$var(newdst)”);
t_relay();
}
Serial Forking
request_route {
...
$ru = “sip:102@kamailio.org”;
$xavp(newdst) = “sip:103@kamailio.org”;
$xavp(newdst) = “sip:104@kamailio.org”;
t_on_failure(“RETRY”);
t_relay();
}
failure_route[RETRY] {
if (t_is_canceled()) {
exit;
}
if($xavp(newdst) != $null) {
$ru = $xavp(newdst);
$xavp(newdst) = $null;
t_on_failure(“RETRY”);
t_relay();
exit;
}
}
Externalize services
the sip routing basics
✤ lack of resources (e.g., development)
✤ centralized management
✤ large volume of data
✤ number portability database
✤ billing, dids routing, etc
❖ fetching the next routing hops
❖ raw data
❖ http/rpc results + parsing
❖ structured data
❖ rtjson
❖ processing
❖ synchronous
❖ config wait & act
❖ asynchronous
❖ evapi, mqueue & rtimer
Building Blocks
❖ kamailio config - combine:
❖ evapi
❖ jansson
❖ rtjson
❖ external application
❖ node.js
❖ json data response
❖ predfined structure
http://kb.asipto.com/kamailio:k43-async-sip-routing-nodejs
Platform Scalability
USERS
CALLS
USERS
CALLS
USERS
CALLS
forking
✤ not found on local location table and not coming from the other nodes
✤ set destination to the other nodes (update $ru and append_branch())
✤ parallel forking (or serial forking with low transmission timeout)
USERS
CALLS
USERS
CALLS
USERS
CALLS
replication
central node
- redirect server
- proxy without record routing
# Handle SIP registrations
route[REGISTRAR] {
if (is_method("REGISTER")) {
if(isflagset(FLT_NATS)) {
setbflag(FLB_NATB);
# uncomment next line to do SIP NAT pinging
## setbflag(FLB_NATSIPPING);
}
if (!save("location"))
sl_reply_error();
$uac_req(method)=“KUSRLOC"
$uac_req(ruri)="sip:store@centralnode.kamailio.org";
$uac_req(furi)="sip:server@server1.kamailio.org";
$uac_req(hdrs)="Content-Type: text/kusrlocrn";
pv_printf(“$uac_req(body)”, "$fu@fd");
uac_send_req();
exit;
}
}
route[TOMAIN] {
$du = "sip:CENTRALNODEIP";
route(RELAY);
exit;
}
# USER location service
route[LOCATION] {
#!ifdef WITH_SPEEDDIAL
# search for short dialing - 2-digit extension
if($rU=~"^[0-9][0-9]$")
if(sd_lookup("speed_dial"))
route(SIPOUT);
#!endif
#!ifdef WITH_ALIASDB
# search in DB-based aliases
if(alias_db_lookup("dbaliases"))
route(SIPOUT);
#!endif
$avp(oexten) = $rU;
if (!lookup("location")) {
if(src_ip!=CENTRALNODEIP)
route(TOMAIN);
...
}
modparam(“htable”, “htable”, “kusrloc=>size=10;autoexpire=7200;”)
...
request_route {
# add here ip authorization, etc…
# handle location update notification
if(method=="KUSRLOC" && $rU=="store") {
$sht(kusrloc=>$rb) = “sip:” + $si + “:” + $sp + “;transport=” + $pr;
send_reply("200", "Stored");
exit;
}
# handle standard SIP requests
if($sht(kusrloc=>$rU@$rd)!=$null) {
$du = $sht(kusrloc=>$rU@$rd);
t_relay();
exit;
}
send_reply(“404”, “Not found”);
exit;
}
forking
replication
www.kamailio.org
tutorials
mailing lists
reference documentation
http://www.asipto.com/sw/kamailio-admin-book/
http://www.kamailioworld.com
YouTube KamailioWorld Channel
https://www.youtube.com/channel/UCElq4JNTPd7bs2vbfAAYVJA
Kamailio World 2016 - Planning a Special Edition
Kamailio Project
15 YEARS OF DEVELOPMENT
2001-2016
from SER to Kamailio
www.kamailioworld.com
Thank you!
Questions?
@miconda

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Kamailio and VoIP Wild World
Kamailio and VoIP Wild WorldKamailio and VoIP Wild World
Kamailio and VoIP Wild World
 
Expanding Asterisk with Kamailio
Expanding Asterisk with KamailioExpanding Asterisk with Kamailio
Expanding Asterisk with Kamailio
 
Kamailio - Secure Communication
Kamailio - Secure CommunicationKamailio - Secure Communication
Kamailio - Secure Communication
 
Static Typing in Vault
Static Typing in VaultStatic Typing in Vault
Static Typing in Vault
 
Securing Prometheus exporters using HashiCorp Vault
Securing Prometheus exporters using HashiCorp VaultSecuring Prometheus exporters using HashiCorp Vault
Securing Prometheus exporters using HashiCorp Vault
 
PSGI and Plack from first principles
PSGI and Plack from first principlesPSGI and Plack from first principles
PSGI and Plack from first principles
 
Bootstrapping multidc observability stack
Bootstrapping multidc observability stackBootstrapping multidc observability stack
Bootstrapping multidc observability stack
 
Apache::LogFormat::Compiler YAPC::Asia 2013 Tokyo LT-Thon
Apache::LogFormat::Compiler YAPC::Asia 2013 Tokyo LT-ThonApache::LogFormat::Compiler YAPC::Asia 2013 Tokyo LT-Thon
Apache::LogFormat::Compiler YAPC::Asia 2013 Tokyo LT-Thon
 
How to build a High Performance PSGI/Plack Server
How to build a High Performance PSGI/Plack Server How to build a High Performance PSGI/Plack Server
How to build a High Performance PSGI/Plack Server
 
Puppet and the HashiStack
Puppet and the HashiStackPuppet and the HashiStack
Puppet and the HashiStack
 
Lua tech talk
Lua tech talkLua tech talk
Lua tech talk
 
Ground Control to Nomad Job Dispatch
Ground Control to Nomad Job DispatchGround Control to Nomad Job Dispatch
Ground Control to Nomad Job Dispatch
 
Zabbix Console
Zabbix ConsoleZabbix Console
Zabbix Console
 
On UnQLite
On UnQLiteOn UnQLite
On UnQLite
 
Bootstrapping multidc observability stack
Bootstrapping multidc observability stackBootstrapping multidc observability stack
Bootstrapping multidc observability stack
 
Roll Your Own API Management Platform with nginx and Lua
Roll Your Own API Management Platform with nginx and LuaRoll Your Own API Management Platform with nginx and Lua
Roll Your Own API Management Platform with nginx and Lua
 
Testing your infrastructure with litmus
Testing your infrastructure with litmusTesting your infrastructure with litmus
Testing your infrastructure with litmus
 
{{more}} Kibana4
{{more}} Kibana4{{more}} Kibana4
{{more}} Kibana4
 
Observability with Consul Connect
Observability with Consul ConnectObservability with Consul Connect
Observability with Consul Connect
 
Redis And python at pycon_2011
Redis And python at pycon_2011Redis And python at pycon_2011
Redis And python at pycon_2011
 

Similar a Kamailio - Surfing Big Waves Of SIP With Style

Intravert Server side processing for Cassandra
Intravert Server side processing for CassandraIntravert Server side processing for Cassandra
Intravert Server side processing for Cassandra
Edward Capriolo
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup Performance
Justin Cataldo
 
Web Performance Workshop - Velocity London 2013
Web Performance Workshop - Velocity London 2013Web Performance Workshop - Velocity London 2013
Web Performance Workshop - Velocity London 2013
Andy Davies
 

Similar a Kamailio - Surfing Big Waves Of SIP With Style (20)

Kamailio and VoIP Wild World
Kamailio and VoIP Wild WorldKamailio and VoIP Wild World
Kamailio and VoIP Wild World
 
Go Web Development
Go Web DevelopmentGo Web Development
Go Web Development
 
Kamailio - SIP Servers Everywhere
Kamailio - SIP Servers EverywhereKamailio - SIP Servers Everywhere
Kamailio - SIP Servers Everywhere
 
Presto anatomy
Presto anatomyPresto anatomy
Presto anatomy
 
[245] presto 내부구조 파헤치기
[245] presto 내부구조 파헤치기[245] presto 내부구조 파헤치기
[245] presto 내부구조 파헤치기
 
Intravert Server side processing for Cassandra
Intravert Server side processing for CassandraIntravert Server side processing for Cassandra
Intravert Server side processing for Cassandra
 
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup Performance
 
Express Presentation
Express PresentationExpress Presentation
Express Presentation
 
Leveraging Hadoop in your PostgreSQL Environment
Leveraging Hadoop in your PostgreSQL EnvironmentLeveraging Hadoop in your PostgreSQL Environment
Leveraging Hadoop in your PostgreSQL Environment
 
Monitoring with Prometheus
Monitoring with PrometheusMonitoring with Prometheus
Monitoring with Prometheus
 
HashiConf Digital 2020: HashiCorp Vault configuration as code via HashiCorp T...
HashiConf Digital 2020: HashiCorp Vault configuration as code via HashiCorp T...HashiConf Digital 2020: HashiCorp Vault configuration as code via HashiCorp T...
HashiConf Digital 2020: HashiCorp Vault configuration as code via HashiCorp T...
 
How Secure Are Docker Containers?
How Secure Are Docker Containers?How Secure Are Docker Containers?
How Secure Are Docker Containers?
 
Web Performance Workshop - Velocity London 2013
Web Performance Workshop - Velocity London 2013Web Performance Workshop - Velocity London 2013
Web Performance Workshop - Velocity London 2013
 
Monitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
Monitoring Your ISP Using InfluxDB Cloud and Raspberry PiMonitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
Monitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
 
Play vs Rails
Play vs RailsPlay vs Rails
Play vs Rails
 
Building and Scaling Node.js Applications
Building and Scaling Node.js ApplicationsBuilding and Scaling Node.js Applications
Building and Scaling Node.js Applications
 
KazooCon 2014 - Playing Kazoo Dudka Style
KazooCon 2014 - Playing Kazoo Dudka StyleKazooCon 2014 - Playing Kazoo Dudka Style
KazooCon 2014 - Playing Kazoo Dudka Style
 
Building an ML Platform with Ray and MLflow
Building an ML Platform with Ray and MLflowBuilding an ML Platform with Ray and MLflow
Building an ML Platform with Ray and MLflow
 
KISSY 的昨天、今天与明天
KISSY 的昨天、今天与明天KISSY 的昨天、今天与明天
KISSY 的昨天、今天与明天
 

Más de Daniel-Constantin Mierla

Más de Daniel-Constantin Mierla (12)

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
 
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 - Large Unified Communication Platforms
Kamailio - Large Unified Communication PlatformsKamailio - Large Unified Communication Platforms
Kamailio - Large Unified Communication Platforms
 
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
 
Kamailio - The Story for Asterisk
Kamailio - The Story for AsteriskKamailio - The Story for Asterisk
Kamailio - The Story for Asterisk
 

Último

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
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...
 
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
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

Kamailio - Surfing Big Waves Of SIP With Style

  • 1. Surfing BigWaves of SIP with Style Daniel-Constantin Mierla @miconda - www.asipto.com - Co-Founder Kamailio October 2015
  • 2. a very large set of features kamailio continuos development since 2001 2002 Jun 2005 Jul 2008 Aug 2008 Nov 2008 SIP Express Router (SER) OpenSER Kamailio Other Forks... Same application: Kamailio - SER Oct 2009 Jan 2010 v3.0.0 Integration Completed v1.5.0 Sep 2011Sep 2001 First Line Of Code Open Source GPL FhG Fokus Institute Berlin rename Awarded Best Open Source Networking Software 2009 By InfoWorld 10 Years Jun 2012 v3.3.0 ITSPA UK Award Mar 2013 v4.0.0 Kamailio v4.1.0 Dec 2013 ………. v4.2.0 Oct 2014 now over 100 on github June 2015 v4.3.0
  • 3. not designed as a typical telephony engine open source sip server framework - toolkit SIP signalling routing • fast • reliable • flexible In other words • not initiating calls • not answering calls • no audio-video processing
  • 4. Key Features ✤ Modular SIP Poxy, 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
  • 5. Dealing with high SIP traffic volume Detect and require a retry after a while Increase performances of a Kamailio instance Scale the RTC platform
  • 6. detect and require a retry after a while
  • 7. Registration sip registrar tunings REGISTER (contact address) REGISTER (contact address) (credentials) 401 (authentication req) 200 OK (contact addresses) SIP Registrar Require user's authentication Authenticate user Save contact address Confirm registration
  • 8. ✤ registration storms ✤ reply to retry after ✤ randomize expires value … modparam("registrar", "expires_range", 30) # expires within [0.7*expires .. expires] modparam("registrar", "retry_after", 30) … $var(retry) = 10 + ($RANDOM mod 300); append_to_reply(“Retry-After: rn”); send_reply(“500”, “Try later”); …
  • 9. Authentication sip authentication tunings INVITE B@Y Alice Server Y 407 Proxy Authentication Required Proxy-Authenticate:.... ....realm=X,nonce=aaa Proxy X INVITE B@Y Proxy-Authorization:.... ....user=A,realm=X,uri=B@Y, ....nonce=aaa,response=bbb INVITE B@Y Proxy-Authorization:.... ....user=alice,realm=X,uri=b@Y, ....nonce=aaa,response=bbb 401 Unauthorized WWW-Authenticate:.... ....realm=Y,nonce=ccc 401 Unauthorized WWW-Authenticate:.... ....realm=Y,nonce=ccc INVITE B@Y Proxy-Authorization:.... ....user=A,realm=X,uri=B@Y, ....nonce=aaa,response=bbb Authorization: .... ....user=A,realm=Y,uri=B@Y ....nonce=ccc,response=ddd INVITE B@Y Proxy-Authorization:.... ....user=A,realm=X,uri=B@Y, ....nonce=aaa,response=bbb Authorization: .... ....user=A,realm=Y,uri=B@Y ....nonce=ccc,response=ddd
  • 10. ✤ caching user profile ✤ password and other attributes ✤ check first the cache, if not found, then fetch from database and store in memory … loadmodule "auth.so" loadmodule “auth_db.so" loadmodule "htable.so" … modparam("auth_db", "db_url", DBURL) modparam("auth_db", "calculate_ha1", yes) modparam("auth_db", "password_column", "password") modparam("auth_db", "load_credentials", “$avp(password)=password”) modparam("auth_db", "use_domain", MULTIDOMAIN) … modparam("htable", "htable", "users=>size=10;autoexpire=300;") …
  • 11. … route[AUTH] { …. if (is_method("REGISTER") || from_uri==myself) { # authenticate requests if($sht(users=>$fU)!=$null) { if (!pv_auth_check(“$fd”, “$sht(users=>$fU)”, “0”, ”1”)) { auth_challenge("$fd", "0"); exit; } } else { if (!auth_check("$fd", "subscriber", "1")) { auth_challenge("$fd", "0"); exit; } $sht(users=>$fU) = $avp(password); } # user authenticated - remove auth header if(!is_method("REGISTER|PUBLISH")) consume_credentials(); } …
  • 12. ✤ client certificate or key based authentication ✤ avoid the auth challenge extra round trip ✤ tls with client certificate ✤ auth_xkey module … modparam("auth_xkeys", "xkey", "id=abc;name=xyz;value=secret;expires=72000") … … auth_xkeys_add("X-My-Key", "abc", "sha256", "$Ri:$fu:$ru:$hdr(CSeq)"); … if(!auth_xkeys_add("X-My-Key", "abc", "sha256", "$si:$fu:$ru:$hdr(CSeq)")) { send_reply("403", "Forbidden"); exit; } remove_hf("X-My-Key"); …
  • 14. ✤ pipelimit ✤ reply with retry after ✤ send redirect to another node … $var(retry) = 10 + ($RANDOM mod 300); append_to_reply(“Retry-After: rn”); send_reply(“503”, “Try later”); … … $var(limit) = 20; if (!pl_check("$au", "TAILDROP", "$var(limit)")) { pl_drop(“10”, “60”); exit; } … … if (!pl_check("$au", "TAILDROP", "$var(limit)")) { $ru = “sip:” + $rU + “@newserver.net”; send_reply(“302”, “Moved temporarily”); exit; } …
  • 15. increase performances of a sip server instance
  • 16. ✤ timer processes ✤ lazy operations for many modules ✤ keep alives, cleaning expired data ✤ increase (or reduce) the timer interval … modparam("usrloc", "timer_procs", 4) … modparam("nathelper", "natping_processes", 6) … modparam("dialog", "timer_procs", 4) modparam("dialog", "ka_timer", 10) modparam("dialog", "ka_interval", 300) …
  • 17. ✤ internal hash sizes ✤ indexing of data in memory ✤ location records (usrloc), dialogs, generic hash tables … modparam("usrloc", "hash_size", 12) … modparam("htable", "htable", “a=>size=4;autoexpire=7200;") modparam("htable", "htable", "b=>size=8;") … modparam("dispatcher", "ds_hash_size", 9) … https://en.wikipedia.org/wiki/Hash_table Hash Table Head name:test size: 2 key: alice slots “xyz” 0 1 2 3 key: bob 123 key: john “1ab”
  • 18. ✤ asynchronous processing ✤ delegate the execution to other workers than sip routing processes ✤ async module ✤ tmx (suspend) - mqueue (transmit) - rtimer (process) ✤ async database queries (mysql) ✤ async http/jsonrpc interactions … async_workers=4 … modparam("sqlops","sqlcon","ca=>dbdriver://username:password@dbhost/dbname") sql_query_async("ca", "delete from domain"); … modparam("acc", "db_insert_mode", 2) … http://www.kamailio.org/events/2014-KamailioWorld/day2/26-Daniel-Constantin.Mierla-Kamailio.cfg-Async.pdf
  • 19. ✤ bonus ✤ children ✤ number of worker processes ✤ tcp - tls ✤ max connections ✤ file description limits ✤ internal dns caching ✤ blacklisting
  • 20. ✤ don’t forget ✤ database indexes ✤ syslog asynchronous mode ✤ dns infrastructure availability ✤ api services responsiveness
  • 21. scale the rtc platform
  • 22. dispatcher module • list of balancing nodes from file or database • monitoring of nodes (activate/inactivate automatically) • re-route in case of failure • various algorithms: hashing, weight distribution, round robin, call load distribution, priority routing • reload list of nodes without restart # 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>n"); t_on_failure("RTF_DISPATCH"); route(RELAY); exit; } # Re-route in case of failure failure_route[RTF_DISPATCH] { if (t_is_canceled()) { exit; } # next node - only for 500 or local timeout if (t_check_status(“500") || (t_branch_timeout() && !t_branch_replied())) { if(ds_next_dst()) { t_on_failure("RTF_DISPATCH"); route(RELAY); exit; } } } Load balancing
  • 23. Parallel Forking request_route { ... append_branch(“sip:103@kamailio.org”); append_branch(“sip:104@kamailio.org”); $var(newdst) = “sip:105@kamailio.org”; append_branch(“$var(newdst)”); t_relay(); } Serial Forking request_route { ... $ru = “sip:102@kamailio.org”; $xavp(newdst) = “sip:103@kamailio.org”; $xavp(newdst) = “sip:104@kamailio.org”; t_on_failure(“RETRY”); t_relay(); } failure_route[RETRY] { if (t_is_canceled()) { exit; } if($xavp(newdst) != $null) { $ru = $xavp(newdst); $xavp(newdst) = $null; t_on_failure(“RETRY”); t_relay(); exit; } } Externalize services the sip routing basics ✤ lack of resources (e.g., development) ✤ centralized management ✤ large volume of data ✤ number portability database ✤ billing, dids routing, etc
  • 24. ❖ fetching the next routing hops ❖ raw data ❖ http/rpc results + parsing ❖ structured data ❖ rtjson ❖ processing ❖ synchronous ❖ config wait & act ❖ asynchronous ❖ evapi, mqueue & rtimer Building Blocks
  • 25. ❖ kamailio config - combine: ❖ evapi ❖ jansson ❖ rtjson ❖ external application ❖ node.js ❖ json data response ❖ predfined structure http://kb.asipto.com/kamailio:k43-async-sip-routing-nodejs
  • 26. Platform Scalability USERS CALLS USERS CALLS USERS CALLS forking ✤ not found on local location table and not coming from the other nodes ✤ set destination to the other nodes (update $ru and append_branch()) ✤ parallel forking (or serial forking with low transmission timeout)
  • 28. # Handle SIP registrations route[REGISTRAR] { if (is_method("REGISTER")) { if(isflagset(FLT_NATS)) { setbflag(FLB_NATB); # uncomment next line to do SIP NAT pinging ## setbflag(FLB_NATSIPPING); } if (!save("location")) sl_reply_error(); $uac_req(method)=“KUSRLOC" $uac_req(ruri)="sip:store@centralnode.kamailio.org"; $uac_req(furi)="sip:server@server1.kamailio.org"; $uac_req(hdrs)="Content-Type: text/kusrlocrn"; pv_printf(“$uac_req(body)”, "$fu@fd"); uac_send_req(); exit; } } route[TOMAIN] { $du = "sip:CENTRALNODEIP"; route(RELAY); exit; } # USER location service route[LOCATION] { #!ifdef WITH_SPEEDDIAL # search for short dialing - 2-digit extension if($rU=~"^[0-9][0-9]$") if(sd_lookup("speed_dial")) route(SIPOUT); #!endif #!ifdef WITH_ALIASDB # search in DB-based aliases if(alias_db_lookup("dbaliases")) route(SIPOUT); #!endif $avp(oexten) = $rU; if (!lookup("location")) { if(src_ip!=CENTRALNODEIP) route(TOMAIN); ... }
  • 29. modparam(“htable”, “htable”, “kusrloc=>size=10;autoexpire=7200;”) ... request_route { # add here ip authorization, etc… # handle location update notification if(method=="KUSRLOC" && $rU=="store") { $sht(kusrloc=>$rb) = “sip:” + $si + “:” + $sp + “;transport=” + $pr; send_reply("200", "Stored"); exit; } # handle standard SIP requests if($sht(kusrloc=>$rU@$rd)!=$null) { $du = $sht(kusrloc=>$rU@$rd); t_relay(); exit; } send_reply(“404”, “Not found”); exit; }
  • 34. Kamailio World 2016 - Planning a Special Edition Kamailio Project 15 YEARS OF DEVELOPMENT 2001-2016 from SER to Kamailio www.kamailioworld.com Thank you! Questions? @miconda