Chapter 5. Installing KAMAILIO (OpenSER)
Note: You can skip this section if FreeSWITCH is your media server
The latest version of KAMAILIO (OpenSER) you can download here:
http://www.kamailio.org/pub/kamailio/1.4.2/src/kamailio-1.4.2-notls_src....
Do the following:
- Extract files from kamailio-1.4.2-notls_src.tar.gz using following command:
tar xvzf kamailio-1.4.2-notls_src.tar.gz - Go to the directory where you have extracted KAMAILIO files and in the file “Makefile”
- In “Makefile” delete “db_mysql” from exclude_modules
- In the directory where KAMAILIO files are, make following commands:
make allmake install - Make some changes in MySQL Data Base:
a)create new schema: username = “kamailio”, password=” kamailio”, default schema=” kamailio”b)from “kamailio” catalog, choose “trusted”. You will see a table containing four columns. In the first one, type
external IPs of trusted servers (servers with which KAMAILIO will cooperate). Parameter for the second one is “udp”c)from “kamailio” catalog, choose “domain”. You will see a table containing two columns. In the domain column
you should add IP of machine, where KAMAILIO is installs and IPs which you will write as s domain in SIP account settings of soft phone - Make needed changers in file kamailio.cfg.sample. To edit this file type command: and delete “sample” from filename extension
vi /usr/local/etc/kamailio/kamailio.cfg - To launch KAMAILIO type “/usr/local/sbin/kamctl start”. To know more commands for this configuration file type “/usr/local/sbin/kamctl help”
Note: all servers connected to KAMAILIO (i.e., Media Servers, Application Server, Border Controller) need to be defined in the list of trusted servers.
You can make needed changers in MySQL Data Base (like adding IPs in “trusted”) using Linux command line. Information about DB is in the file “kamdbctl”. Type “/usr/local/sbin/kamdbctl help” to know more information.
Editing Configuration File
Make several changes in configuration file kamailio.cfg:
In global configuration parameters set:# bind on a specific interface/port/proto (default bind on all available)
#for example: udp:192.168.45.190:5060
listen=[PROTOCOL:IP:port], where IP – IP of machine where kamailio is installed
#set module path
mpath="/usr/local/lib/kamailio/modules/" – default
In module-specific parameters settings set: # CHANGE database URL
modparam("auth_db|domain|permissions|uri_db|usrloc", "db_url", "mysql://[username]:[pass]@[host]/[db]")
In request routing logic in blocks “route[5]”, route[7]”, “route[8]” set:
route[5] {
xlog("L_DEBUG", "Entering route [5] - change message to redirect it to StarPound\r\n");
if (method=="SUBSCRIBE") {
# change Request-URI to StarPound Server B2BUA IP and port
subst_uri('/^sip:(.*)$/sip:[STARPOUND_SERVER_HOSTNAME]:[STARPOUND_SERVER_PORT]/i');
} else if (method=="REFER" || search("^Replaces:(.*)$") || search("^Referred-By:(.*)$")) {
xlog("L_DEBUG", "route[5] - route REFER to StarPound ...");
# change STARPOUND SERVER HOST NAME and PORT
subst_uri('/^sip:(.*)@(.*)$/sip:hostedpbx@[STARPOUND_SERVER_HOSTNAME]:[STARPOUND_SERVER_PORT]/i');
} else {
if (uri=~"^sip:frm_sbc.*$" && uri == myself) {
if (search("X-SPTo:(.*)agent.[YOUR_DOMAIN]")) {
subst_uri('/^sip:frm_sbc(.*)@(.*)$/sip:\1@[STARPOUND_AGENT_SERVER_HOSTNAME]:[STARPOUND_AGENT_SERVER_PORT]/i');
} else {
# Here we route all calls from Asterisk to 'hostedpbx' application
# 'hostedpbx' inbound route needs to be configured in *# MC
# you can add other matching patterns to route to
# different starpound apps
xlog("L_DEBUG", "route[5] - from sbc and route to pbx3 ...");
subst('/^To:(.*)sip:frm_sbc[1]?(.*)$/To:\1sip:\2/i');
subst_uri('/^sip:(.*)@(.*)$/sip:hostedpbx@[STARPOUNDSERVER_HOSTNAME]:[STARPOUND_SERVER_PORT]/i');
}
} else {
# all other traffic should route to SBC first
# to be firewall friendly
# route to sbc(asterisk) to fix media channel
xlog("L_DEBUG", "route[5] - forward incoming call to Asterisk...");
subst_uri('/^sip:(.*)@(.*)$/sip:frm_kam\1@[ASTERISK_HOST_NAME]:[ASTERISK_SIP_PORT]/i');
}
}
}
route[7] {
xlog("L_DEBUG", "Entering route [7] - verify if destination is AgentB2BUA\r\n");
if (search("^To:(.*)agent.[YOUR_DOMAIN](.*)$")) {
subst_uri('/^sip:(.*)@(.*)$/sip:\1@[STARPOUND_AGENT_SERVER_HOSTNAME]:[STARPOUND_AGENT_SERVER_PORT]/i');
setflag(11);
} else {
xlog("L_DEBUG", "route[7] - not agent domain.\r\n");
}
}
route[8] {
xlog("L_DBG", "Entering route [8] - change message to redirect it to DID Gateway\r\n");
# to DID gateway
subst_uri('/^sip:(.*)@(.*)$/sip:1\1@[DID_GATEWAY_IP]:[DID_GATEWAY_PORT]/i');
}
