Friday, May 18, 2012

Vyatta+OpenSIPS on Citrix XEN-Server


Setting up Environment

Couple days ago I had to expand my Virtual environment to install more virtual machines and do some more experimentation, so instead of using VMware ESXi, I used Citrix XENServer. 
It was a good experience installing xenserver, just a matter of putting in the installation CD and then following steps.
Once I was done installing the xenserver, the first step was to create new virtual servers inside and setup the internal networking.For networking part the obvious choice was Vyatta (VYATTA CORE 6.4). 
Here is the setup diagram
Virtual Server Space - Network Topology
Setting up ISO Library in XenCenter was really easy. I used the downloaded Vyatta-virtual-64bit ISO anda Ubuntu Server ISO to install both Vyatta - routing and firewall,  and a Ubuntu Server- OpenSIPS server.

I assigned two NICs to Vyatta one being bridged to physical interface to interact with the outer world the second interface is connected to a virtual switch created inside the xenserver to communicate with the internal servers.

OpenSIPS server on the other hand is connected only to the virtual switch and uses the Vyatta router as its gateway. I had to configure NAT on the Vyatta router for this to work.

Here's how we do NAT on Vyatta to let the traffic coming from private network successfully reach out to the internet.
GW-Vyatta:~$configure
GW-Vyatta#set interfaces ethernet eth0 address 172.16.31.101/16 
GW-Vyatta#set system gateway-address 172.16.2.50 
GW-Vyatta#set system name-server 8.8.8.8 
GW-Vyatta#commit
Verify that Router can itself reach out to internet.
GW-Vyatta#ping www.google.com
Start SSH Service on Vyatta router
GW-Vyatta#set service ssh listen-address 172.16.31.101
GW-Vyatta#commit
Configure the LAN interface on eth1.
GW-Vyatta#set interfaces ethernet eth1 address 192.168.30.1/24
GW-Vyatta#commit
Set Masquerade NAT for traffic from LAN to get translated to WAN address.

GW-Vyatta#set nat source rule 5 outbound-interface eth0
GW-Vyatta#set nat source rule 5 source address 192.168.30.0/24
GW-Vyatta#set nat source rule 5 translation address masquerade
GW-Vyatta#commit
Ping some internet destination from the LAN side and see some new translations on Vyatta.



W-Vyatta#run show nat source statistics
Configure SSH access to OpenSIPS Server such that when I SSH on 172.16.31.101 port 22303 it gets translated to internal address 192.168.30.3 port 22.
GW-Vyatta#set nat destination rule 5 inbound-interface eth0
GW-Vyatta#set nat destination rule 5 destination port 22303
GW-Vyatta#set nat destination rule 5 translation address 192.168.30.3
GW-Vyatta#set nat destination rule 5 translation port 22
GW-Vyatta#set nat destination rule 5 protocol tcp
GW-Vyatta#commit
SSH onto the OPenSIPS server via port 172.16.31.101:22303 and see the destination NAT stats.
GW-Vyatta#run show nat destination statistics

GW-Vyatta#save
GW-Vyatta#exit

That was it and I can access internet from my OpenSIPS server and also SSH into my server from outside the virtual environment. The next thing would be to make this setup work with two-way audio. For that I may need to setup VPN or something IDK.

Thursday, May 17, 2012

Installing OpenSIPS on Ubuntu-Server 11.04 (Natty)


OpenSIPS is a SIP server, I don't think I can explain this all myself so copying from the project's main page


What OpenSIPS is
OpenSIPS (Open SIP Server) is a mature Open Source implementation of a SIP server. OpenSIPS is more than a SIP proxy/router as it includes application-level functionalities. OpenSIPS, as a SIP server, is the core component of any SIP-based VoIP solution. With a very flexible and customizable routing engine,OpenSIPS 'unifies voice, video, IM and presence services in a highly efficient way, thanks to its scalable (modular) design.
What OpenSIPS has to offer, comes in a reliable and high-performance flavour - OpenSIPS is one of the fastest SIP servers, with a throughput that confirms it as a solution up to enterprise or carrier-grade class.

Now moving onwards with steps to install the SIP server.

First update the repository and package indexes to install the latest available pakcages.

root@OSIPS_SBC# apt-get update
Install the required libraries/packages
root@OSIPS_SBC# apt-get install build-essential openssl bison flex mysql-server libmysqlclient16 libmysqlclient-dev libsctp-dev openssl libssl-dev libradiusclient-ng-dev libxml2-dev libxml2 libconfuse0 libconfuse-dev libdb-dev libcurl4-gnutls-dev libcurl3 libpostgresql-ocaml-dev libpq-dev unixodbc-dev libpcre3-dev libexpat1-dev libjson0-dev libmemcached-dev libmemcache-dev libxmlrpc-c3-dev libgeoip-dev python-dev libsnmp-dev 


Download and extract opensips source tarball

root@OSIPS_SBC# wget http://opensips.org/pub/opensips/1.7.2/src/opensips-1.7.2_src.tar.gz
root@OSIPS_SBC# tar zxvf opensips-1.7.2_src.tar.gz 
root@OSIPS_SBC# cd opensips-1.7.2-tls/

UPDATE: The newer OpenSIPS version (1.8 onwards) don't need to edit Makefile and select the packages like below. Visit the lastes blog-post on OpenSIPS+Cassandra Integration to see how that works. (Hint: make menuconfig)

Edit "Makefile" to include your required modules.

root@Osips-SBC# vim Makefile

Uncomment the following lines to enable their functionality.
TLS=1
SCTP=1

Include modules to be installed.

Comment out this all directive:

exclude_modules?= b2b_logic jabber cpl-c xmpp rls \
mi_xmlrpc xcap_client db_mysql db_postgres db_unixodbc \
db_oracle db_berkeley aaa_radius osp perl snmpstats \
perlvdb carrierroute mmgeoip presence presence_xml presence_mwi \ presence_dialoginfo pua pua_bla pua_mi pua_usrloc \ 
pua_xmpp pua_dialoginfo ldap h350 identity regex memcached \ db_http json python dialplan

it should look something like this,

exclude_modules?= osp db_oracle \

#exclude_modules?= b2b_logic jabber cpl-c xmpp rls \
#mi_xmlrpc xcap_client db_mysql db_postgres db_unixodbc \
#db_oracle db_berkeley aaa_radius osp perl snmpstats \
#perlvdb carrierroute mmgeoip presence presence_xml\ 
#presence_mwi presence_dialoginfo pua pua_bla pua_mi \ 
#pua_usrloc pua_xmpp pua_dialoginfo ldap h350 identity \
#regex memcached db_http json python dialplan

I've excludede modules for osp and oracle db , as we don;t need those.

save and exit.
Now compile and install OpenSIPS

root@Osips-SBC# make all 
root@Osips-SBC# make install 
Copy default and the int.d startup scripts to relevant directories.
root@Osips-SBC# cd packaging/debian
root@Osips-SBC# cp opensips.default /etc/default/opensips
Edit the default file:
root@Osips-SBC# vim /etc/default/opensips 
SET:
RUN_OPENSIPS=yes
Save and Exit

root@Osips-SBC# cp opensips.init /etc/init.d/opensips
Verify the binary directory of opensips package
root@Osips-SBC# ls /usr/local/sbin/opensips

should show you this output
/usr/local/sbin/opensips

Edit /etc/init.d/opensips to know the path of the opensips executable binary

root@Osips-SBC# vim /etc/init.d/opensips

SET:
DAEMON=/usr/local/sbin/opensips

Create opensips user
root@Osips-SBC# useradd -d /etc/opensips -s /sbin/nologin opensips

SCTP module is required to be loaded in kernel before starting opensips, since e compiled opensips with SCTP support.

root@Osips-SBC# modprobe sctp


START opensips

root@Osips-SBC# /etc/init.d/opensips start
if you get this error:

grep: /etc/opensips/opensips.cfg: No such file or directory
Starting opensips: opensips already running.

Execute the following command.( but first do check with "/var/log/syslog" what is your error.I got error on different configurations directory so I created an symbolic link.)

root@Osips-SBC# ln -s /usr/local/etc/opensips /etc/


Create Database for opensips


root@Osips-SBC# cd /usr/local/etc/opensips 
root@Osips-SBC# vim opensipsctlrc
Uncomment
DBENGINE=MYSQL

Save and Exit
root@Osips-SBC# opensipsdbctl create

MySQL password for root:
INFO: test server charset
INFO: creating database opensips ...
INFO: Core OpenSIPS tables succesfully created.
Install presence related tables? (y/n): y
INFO: creating presence tables into opensips ...
INFO: Presence tables succesfully created.
Install tables for imc cpl siptrace domainpolicy carrierroute userblacklist? (y/n): y
INFO: creating extra tables into opensips ...
INFO: Extra tables succesfully created.
root@Osips-SBC#



Now, Start opensips
root@Osips-SBC# /etc/init.d/opensips start
Starting opensips: opensipsListening on
             udp: 127.0.0.1 [127.0.0.1]:5060
             udp: 192.168.30.3 [192.168.30.3]:5060
             tcp: 127.0.0.1 [127.0.0.1]:5060
             tcp: 192.168.30.3 [192.168.30.3]:5060
             sctp: 127.0.0.1 [127.0.0.1]:5060
             sctp: 192.168.30.3 [192.168.30.3]:5060
Aliases:
             sctp: Osips-SBC:5060
             sctp: localhost:5060
             tcp: Osips-SBC:5060
             tcp: localhost:5060
             udp: Osips-SBC:5060
             udp: localhost:5060

.
root@Osips-SBC#
The "." here signifies that opensips has actually started. If you see anything else like "opensips has started" or "opensips is already running" then see log file for errors.

Verify that opensips is running
root@Osips-SBC# ps -ef | grep opensips


opensips  1140     1  0 14:16 ?        00:00:00 /usr/local/sbin/opensips -P /var/run/opensips/opensips.pid -m 64 -u opensips -g opensips


opensips  1147  1140  0 14:16 ?        00:00:00 /usr/local/sbin/opensips -P /var/run/opensips/opensips.pid -m 64 -u opensips -g opensips
opensips  1148  1140  0 14:16 ?        00:00:00 /usr/local/sbin/opensips -P /var/run/opensips/opensips.pid -m 64 -u opensips -g opensips
opensips  1149  1140  0 14:16 ?        00:00:00 /usr/local/sbin/opensips -P /var/run/opensips/opensips.pid -m 64 -u opensips -g opensips
opensips  1150  1140  0 14:16 ?        00:00:00 /usr/local/sbin/opensips -P /var/run/opensips/opensips.pid -m 64 -u opensips -g opensips
opensips  1151  1140  0 14:16 ?        00:00:00 /usr/local/sbin/opensips -P /var/run/opensips/opensips.pid -m 64 -u opensips -g opensips
opensips  1152  1140  0 14:16 ?        00:00:00 /usr/local/sbin/opensips -P /var/run/opensips/opensips.pid -m 64 -u opensips -g opensips
opensips  1153  1140  0 14:16 ?        00:00:00 /usr/local/sbin/opensips -P /var/run/opensips/opensips.pid -m 64 -u opensips -g opensips
opensips  1154  1140  0 14:16 ?        00:00:00 /usr/local/sbin/opensips -P /var/run/opensips/opensips.pid -m 64 -u opensips -g opensips
opensips  1155  1140  0 14:16 ?        00:00:00 /usr/local/sbin/opensips -P /var/run/opensips/opensips.pid -m 64 -u opensips -g opensips
opensips  1156  1140  0 14:16 ?        00:00:00 /usr/local/sbin/opensips -P /var/run/opensips/opensips.pid -m 64 -u opensips -g opensips
opensips  1157  1140  0 14:16 ?        00:00:00 /usr/local/sbin/opensips -P /var/run/opensips/opensips.pid -m 64 -u opensips -g opensips
opensips  1158  1140  0 14:16 ?        00:00:00 /usr/local/sbin/opensips -P /var/run/opensips/opensips.pid -m 64 -u opensips -g opensips
opensips  1159  1140  0 14:16 ?        00:00:00 /usr/local/sbin/opensips -P /var/run/opensips/opensips.pid -m 64 -u opensips -g opensips
opensips  1160  1140  0 14:16 ?        00:00:00 /usr/local/sbin/opensips -P /var/run/opensips/opensips.pid -m 64 -u opensips -g opensips
opensips  1161  1140  0 14:16 ?        00:00:00 /usr/local/sbin/opensips -P /var/run/opensips/opensips.pid -m 64 -u opensips -g opensips
opensips  1162  1140  0 14:16 ?        00:00:00 /usr/local/sbin/opensips -P /var/run/opensips/opensips.pid -m 64 -u opensips -g opensips
opensips  1163  1140  0 14:16 ?        00:00:00 /usr/local/sbin/opensips -P /var/run/opensips/opensips.pid -m 64 -u opensips -g opensips
opensips  1164  1140  0 14:16 ?        00:00:00 /usr/local/sbin/opensips -P /var/run/opensips/opensips.pid -m 64 -u opensips -g opensips
opensips  1165  1140  0 14:16 ?        00:00:00 /usr/local/sbin/opensips -P /var/run/opensips/opensips.pid -m 64 -u opensips -g opensips
opensips  1166  1140  0 14:16 ?        00:00:00 /usr/local/sbin/opensips -P /var/run/opensips/opensips.pid -m 64 -u opensips -g opensips
opensips  1167  1140  0 14:16 ?        00:00:00 /usr/local/sbin/opensips -P /var/run/opensips/opensips.pid -m 64 -u opensips -g opensips
opensips  1168  1140  0 14:16 ?        00:00:00 /usr/local/sbin/opensips -P /var/run/opensips/opensips.pid -m 64 -u opensips -g opensips
opensips  1169  1140  0 14:16 ?        00:00:00 /usr/local/sbin/opensips -P /var/run/opensips/opensips.pid -m 64 -u opensips -g opensips
opensips  1170  1140  0 14:16 ?        00:00:00 /usr/local/sbin/opensips -P /var/run/opensips/opensips.pid -m 64 -u opensips -g opensips
root      1175  1274  0 14:20 pts/0    00:00:00 grep --color=auto opensips
root@Osips-SBC#

Thats all, you've successfully installed OpenSIPS. Now I'll try to upload some configurations sample file for load-balancing multiple Media-Servers(Asterisks/FreeSWITCH) servers using OpenSIPS.

Friday, March 16, 2012

Asterisk Text-To-Speech Cepstral Setup


Text To Speech Integration
Cepstral + Asterisk

I've been holding onto this post for sometime, wanted to post it with some cool experiment like an IVR based story line which narrates the story and changes the story line according to choices made by listener(DTMF based and then later on Speech Recognition based).

I've now realized that due to extremely busy schedule at job and home I may not get any extra time to make a sample story; insert it into the MySQL DB; make a dialplan for it; create its web end to manage/edit stories and present it here. So instead of delivering it all in one piece its better to take a start from giving our Asterisk server a voice by installing Cepstral TTS engine.

Following are the commands to get going.

Download and Install Cepstral TTS Engine.

#wget http://downloads.cepstral.com/cepstral/i386-linux/Cepstral_Callie-8kHz_i386-linux_5.1.0.tar.gz

#tar zxvf Cepstral_Callie-8kHz_i386-linux_5.1.0.tar.gz

#cd Cepstral_Callie-8kHz_i386-linux_5.1.0

#./install.sh

Download and Install App-Swift.
App_swift is the connector between the asterisk and Cepstral engine.Swift runs from inside asterisk as an application and uses the Cepstral TTS engine running in Linux.

#cd /usr/src/

#wget http://pbxinaflash.net/source/app_swift/app_swift-1.6.2.tar.gz

#tar zxvf app_swift-1.6.2.tar.gz

#cd app_swift-1.6.2/

#make

#make install

Issue this command to let Cepstral recognize the Swift module and let it use its engine.
#echo /opt/swift/lib > /etc/ld.so.conf.d/cepstral.conf

#ldconfig

Thats it and now your TTS engine and Asterisk app_Swift connector should be ready to rock

Test Asterisk for Swift Application.
Now test Asterisk for swift application; On CLI execute the following command
Asterisk*CLI>core show application swift

You should get some long output like below:

-= Info about application 'Swift' =-

[Synopsis]
Speak text through Swift text-to-speech engine.

[Description]
Swift(text) Speaks the given text through the Swift TTS engine.
Returns -1 on hangup or 0 otherwise. User can exit by pressing any key.


Make Dialplan to speak something for you. 

exten => 1234,1,NOOP(--Starting Text-To-Speech Test--)
same => n,Answer()
same => n,Swift(Hello World This is an Asterisk server)
same => n,NoOp(Key pressed: ${SWIFT_DTMF})
same => n,Swift(You pressed ${SWIFT_DTMF}. Goodbye.)
same => n,Hangup()

exten => h,1,Hangup()


Thats all, now make your own dialplan and enjoy talking to your asterisk server. Best thing for Forever Alone guys ;)


References:
http://nerdvittles.com/?p=202