Migrating OpenSIPS location table to Kamailio format

From Integrics Wiki
Revision as of 13:34, 18 June 2015 by Danthony (talk | contribs) (Kamailio->OpenSIPS:)
Jump to: navigation, search

Disclaimer

The following comes with no warranty whatsoever. I am not responsible for any data loss or other issues that may arise from following these instructions. Please make backups of all files and test this thoroughly in your lab environment before using it in production.

Overview

This procedure allow the user to migrate between OpenSIPS 1.4.4 and Kamailio 3.3.2 without losing the contents of the location table. This is written for Debian/Ubuntu and may need some changes to work with RedHat/CentOS. It is based on the official doc at http://www.integrics.com/products/enswitch/guides/3.11/en/field/kamailio/opensips/

The official doc uses the "enswitch kamailio_tables" command which drops the location table, causing all registered lines to not be able to receive calls until they re-register. We were able to use this procedure to switch our production system from OpenSIPS to Kamailio with less than 30 seconds of downtime.


For the purposes of this document, sip0 is the primary OpenSIPS/Kamailio server and sip1 is the standby OpenSIPS/Kamailio server.

OpenSIPS->Kamailio:

Do the following on sip0 and sip1

cpan Math::BigInt::FastCalc 
enswitch install kamailio-ha 
vi /etc/kamailio/kamailio.cfg # and set the database URL 


Update haresources on sip0 and sip1:

change "opensips" to "kamailio" in /etc/ha.d/haresources


Stop OpenSIPS on sip0:

sudo /etc/ha.d/resource.d/opensips stop


Remove OpenSIPS init script on sip0 and sip1:

sudo rm /etc/ha.d/resource.d/opensips


Update version for location table on enswitchbd0:

update version set table_version='5' where table_name='location';


Convert OpenSIPS version of location table to work with Kamailio on enswitchdb0:

RENAME TABLE location TO location_old_opensips;
CREATE TABLE `location` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `ruid` varchar(64) NOT NULL DEFAULT ,
 `username` varchar(64) NOT NULL DEFAULT ,
 `domain` varchar(64) DEFAULT NULL,
 `contact` varchar(255) NOT NULL DEFAULT ,
 `received` varchar(128) DEFAULT NULL,
 `path` varchar(128) DEFAULT NULL,
 `expires` datetime NOT NULL DEFAULT '2020-05-28 21:32:15',
 `q` float(10,2) NOT NULL DEFAULT '1.00',
 `callid` varchar(255) NOT NULL DEFAULT 'Default-Call-ID',
 `cseq` int(11) NOT NULL DEFAULT '1',
 `last_modified` datetime NOT NULL DEFAULT '1900-01-01 00:00:01',
 `flags` int(11) NOT NULL DEFAULT '0',
 `cflags` int(11) NOT NULL DEFAULT '0',
 `user_agent` varchar(255) NOT NULL DEFAULT ,
 `socket` varchar(64) DEFAULT NULL,
 `methods` int(11) DEFAULT NULL,
 `instance` varchar(255) DEFAULT NULL,
 `reg_id` int(11) NOT NULL DEFAULT '0',
 `replicate` int(10) unsigned NOT NULL DEFAULT '0',
 `state` tinyint(1) unsigned NOT NULL DEFAULT '0',
 PRIMARY KEY (`id`),
 KEY `account_contact_idx` (`username`,`domain`,`contact`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
SELECT * FROM location_old; 


Add link for Kamailio init script on sip0 and sip1:

sudo ln -sf /opt/enswitch/current/etc/init.d/debian/kamailio /etc/ha.d/resource.d/kamailio


Start Kamailio on sip0:

sudo /etc/ha.d/resource.d/kamailio start


Test calls on sip0:


Run hb_takeover on sip1 and test:

/usr/share/heartbeat/hb_takeover


Run hb_takeover on sip0 and test again:

/usr/share/heartbeat/hb_takeover

Kamailio->OpenSIPS:

Update haresources

change "kamailio" to “opensips” in /etc/ha.d/haresources 


Stop Kamailio:

sudo /etc/ha.d/resource.d/kamailio stop


Remove Kamailio init script:

sudo rm /etc/ha.d/resource.d/kamailio


Update version for location table

update version set table_version='1004' where table_name='location';


Convert Kamailio version of location table to work with OpenSIPS:


RENAME TABLE location TO location_old_kamailio;


CREATE TABLE `location` (
 `username` varchar(64) NOT NULL DEFAULT ,
 `domain` varchar(128) NOT NULL DEFAULT ,
 `contact` varchar(255) NOT NULL DEFAULT ,
 `received` varchar(255) DEFAULT NULL,
 `path` varchar(255) DEFAULT NULL,
 `expires` datetime NOT NULL DEFAULT '2020-01-01 00:00:00',
 `q` float(10,2) NOT NULL DEFAULT '1.00',
 `callid` varchar(255) NOT NULL DEFAULT 'Default-Call-ID',
 `cseq` int(11) NOT NULL DEFAULT '42',
 `last_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
 `replicate` int(10) unsigned NOT NULL DEFAULT '0',
 `state` tinyint(1) unsigned NOT NULL DEFAULT '0',
 `flags` int(11) NOT NULL DEFAULT '0',
 `cflags` int(11) NOT NULL DEFAULT '0',
 `user_agent` varchar(100) NOT NULL DEFAULT ,
 `socket` varchar(128) DEFAULT NULL,
 `methods` int(11) DEFAULT NULL,
 `id` int(10) NOT NULL DEFAULT '0',
 `ruid` varchar(64) NOT NULL DEFAULT ,
 `reg_id` int(11) NOT NULL DEFAULT '0',
 `instance` varchar(255) DEFAULT NULL,
 KEY `username` (`username`,`domain`,`contact`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
SELECT * FROM location_old_kamailio;


Add link for OpenSIPS init script:

sudo ln -sf /opt/enswitch/current/etc/init.d/debian/opensips /etc/ha.d/resource.d/opensips


Start OpenSIPS:

sudo /etc/ha.d/resource.d/opensips start