A quick introduction to Kamailio - the leading Open Source SIP server (based on OpenSER and SER). Kamailio is quite different than Asterisk, FreeSwitch and many other VoIP platforms - why is that and how do you start getting your head around Kamailio?
1. Ⓒ 2015 Edvina AB, Sollentuna, Sweden
All rights reserved.
Why is Kamailio so
different?
…than FreeSwitch, Asterisk and other PBXs
oej@edvina.net | 2015-02-07 | v1.1
2. Ⓒ 2005-2014 Edvina AB, Sollentuna, Sweden
All rights reserved.
Because it’s
not a PBX.
3. Ⓒ 2015 Edvina AB, Sollentuna, Sweden
All rights reserved.
It’s a SIP router
SIP Request
SIP Response
SIP
The main decision you have to do
when configuring Kamailio
is whether to forward a SIP message,
or respond to a request.
4. Ⓒ 2015 Edvina AB, Sollentuna, Sweden
All rights reserved.
Most PBX’s
doesn't work like that
SIP Call PBX
In these systems, you route calls.
The SIP messaging has been programmed
by a developer. It’s not as flexible as Kamailio.
Nor is it as dangerous…
5. Ⓒ 2015 Edvina AB, Sollentuna, Sweden
All rights reserved.
Most PBX’s
handle media
SIP Call
PBX
Kamailio by default does not handle media.
We have 3rd party products for media
NAT traversal assistance.
RTP media
6. Ⓒ 2015 Edvina AB, Sollentuna, Sweden
All rights reserved.
In Kamailio, we handle SIP
messaging.
REGISTER
SIP
PRACK
INFO
MESSAGE
SUBSCRIBE
NOTIFY
ACK
INVITE
You need to
understand all of SIP
and do the right thing
in every situation.
7. Ⓒ 2015 Edvina AB, Sollentuna, Sweden
All rights reserved.
In Kamailio we handle SIP
transactions
SIP request
SIP
SIP request
SIP request
SIP request
SIP response
SIP response
SIP response
SIP response
This is not a call - but a request and
a response. Kamailio helps to find the right destination.
8. Ⓒ 2015 Edvina AB, Sollentuna, Sweden
All rights reserved.
Some transactions belong
together
SIP request
SIP response
SIP request
SIP response
SIP request
SIP response
This is what we in SIP
call a dialog.Typically a call or a
subscription.
Kamailio by
default does not bother
with dialogs. In your script, you
need to.
9. Ⓒ 2015 Edvina AB, Sollentuna, Sweden
All rights reserved.
Simplified routing script
request_route()
{
xlog(“SIP request: $rm to $run”);
!
if (has_to_tag()) {
route(WITHINDIALOG);
exit;
}
!
if ($fd == MYSELF) {
route(AUTH);
}
!
if (!lookup()) {
sl_send_reply(“404”, “Not found”);
exit;
}
!
t_relay();
}
The request_route starts with an incoming
SIP request. Log what it is!
Find out if it’s in a dialog.
Find out if it’s a known user
- authenticate -
Find out if it’s to a known SIP address
Forward the message
10. Ⓒ 2015 Edvina AB, Sollentuna, Sweden
All rights reserved.
# record routing for dialog forming reque
are routed)
# - remove preloaded route headers
remove_hf("Route");
if (is_method("INVITE|SUBSCRIBE"))
record_route();
!
# account only INVITEs
if (is_method("INVITE")) {
setflag(FLT_ACC); # do accounting
} !
# dispatch requests to foreign domains
route(SIPOUT);
!
### requests for my local domains
!
# handle registrations
route(REGISTRAR);
!
if ($rU==$null) { # request with no User
sl_send_rep
Yes, you write code.
You configure Kamailio by writing
programming logic.
You write in Kamailio’s own
script language
Kamailio modules extend
the language.
The core alone is actually pretty
stupid. But very powerful.
11. Ⓒ 2015 Edvina AB, Sollentuna, Sweden
All rights reserved.
Good to know
Like in many script languages there are
many ways to accomplish the same
result.
Many modules are overlapping.
That’s fine.
12. Ⓒ 2015 Edvina AB, Sollentuna, Sweden
All rights reserved.
Where’s the CLI?
Kamailio doesn’t have a command
line interface where you can see
what’s going on.
We have utilities that communicate
with a running server.
In Kamailio 4.2 we got an event API
module. We still don’t know what will
happen with that.
KAMCMD
KAMCTL
13. Ⓒ 2015 Edvina AB, Sollentuna, Sweden
All rights reserved.
A huge selection of modules
Kamailio has over 100
modules. It’s hard to find the right
set for your need.
Start with the default
configuration and build from
there.
14. Ⓒ 2015 Edvina AB, Sollentuna, Sweden
All rights reserved.
Transaction handling.
Some basic modules
TM & TMX
Stateless handling.
SL
Record Routing
RR
Authentication
AUTH *
Location database
USRLOC
SIP registration
REGISTRAR
Smart routing
DIALPLAN
In-memory hash tables
HTABLE
Pseudovariables
PV
Logging to syslog
XLOG
Denial-of-service attack
prevention
PIKE
Accounting
ACC
APIs
CTL, FIFO
Signalling security
TLS
NAT traversal support
NATHELPER
15. Ⓒ 2015 Edvina AB, Sollentuna, Sweden
All rights reserved.
Modules can depend
on each other
REGISTRAR
USRLOC
The REGISTRAR handles
registrations of devices.
The USRLOC module stores the
registrations and handles lookups.
Dependencies are well documented in each module’s
documentation page.
16. Ⓒ 2015 Edvina AB, Sollentuna, Sweden
All rights reserved.
The core
MEMORY HANDLING
CONFIGURATION
MANAGEMENT
NETWORK TRAFFIC
PROCESS MANAGEMENT
STATISTICS
…much more
The core starts Kamailio, loads
modules and handles a lot of
generic issues.
17. Ⓒ 2015 Edvina AB, Sollentuna, Sweden
All rights reserved.
Kamailio and databases
DB
A standardised data interface.
Used by many modules.
NDB
For new databases, NoSQL.
Not used by modules.
db_mysql
db_text
db_pgsql
ndb_redis
ndb_cassandra
db_oracle
db_sqlite Please check the list of modules for
all available database modules.
ndb_mongodb
18. Ⓒ 2015 Edvina AB, Sollentuna, Sweden
All rights reserved.
SIP authentication
AUTH
AUTH_DB
Database-driven
authentication
Anything
(using variables)
Fetching over HTTP
RADIUS or LDAP
Your own application.
SIP MD5 digest authentication
can be done in multiple ways.
19. Ⓒ 2015 Edvina AB, Sollentuna, Sweden
All rights reserved.
Build your own data model,
don’t just copy.
Alias phone number
Alias phone number
Auth account
desk phone
Auth account
soft phone
Auth account
cell phone
Address of record, THE
SIP address
Don’t assume one SIP account, one
phone number, one set of credentials
20. Ⓒ 2015 Edvina AB, Sollentuna, Sweden
All rights reserved.
Base your model
on existing data
Alias phone numbers
Auth accounts
The SIP server is just one server in your
infrastructure.
LDAP account
Address of record, THE
SIP address
Name, address etc
21. Ⓒ 2015 Edvina AB, Sollentuna, Sweden
All rights reserved.
What? No RELOAD?
There’s no overall RELOAD
command.
Some modules have a
reload command.
Some modules only operate
on database.
22. Ⓒ 2015 Edvina AB, Sollentuna, Sweden
All rights reserved.
Where to start.
Learn SIP in detail.
Read the core cookbook.
Browse through the example
configuration and make sure you
understand it.
1.
2.
3.
Now start building,
add modules as you need them.
4.
23. Ⓒ 2015 Edvina AB, Sollentuna, Sweden
All rights reserved.
Getting help.
Use the mailing list, the IRC
channel or the G+ forum.
Please do not mail developers
directly. Use public channels.
Consultants that can help you are
available on the web site.
Trainings are regularly held, both
basic and advanced.
24. Ⓒ 2015 Edvina AB, Sollentuna, Sweden
All rights reserved.
Common mistakes:
Call routing
Carrierroute
LCR
The carrierroute module is not
the only way to do carrier routing. It’s
just one way, maybe it doesn’t fit your
model.
The LCR module is not the only
module for least cost routing. Discover
all the options and select the one that
fits your business.
25. Ⓒ 2015 Edvina AB, Sollentuna, Sweden
All rights reserved.
Common mistakes:
Call states
Dialog
The DIALOG module adds call
states. Don’t add it by default, you may
not need it.
Having call states makes failover
harder. You may have perfectly good call
states in other servers in your
network.
Adding call states use memory and
makes scalability not impossibly, but
much harder.
26. Ⓒ 2005-2014 Edvina AB, Sollentuna, Sweden
All rights reserved.
Good luck,
Kamailian!
www.kamailio.org
27. EDVINATRAINING CLASSES
• Kamailio from start
• The SIP Protocol
• RTP, RTCP and QoS
• SIP Security
• Scalability
• Many Kamailio labs
CUSTOM
INHOUSE
TRAININGS
• SIP,Asterisk, Kamailio
and much more
• Done at your site,
customized for your
project
• Cost effective when
more than four
students
Find more details at http://edvina.net
• Advanced Kamailio
• SIP trunking
• NAT handling
• WebRTC/SIP
• Testing, debugging
• Scalability
• Many Kamailio labs