Sunday, June 23, 2013

My Book: Implementing Citrix XenServer Quickstarter

Implementing Citrix XenServer Quickstarter
Last week was a happy week for me since my book got published by Packt Publish, its really a big achievement for me to have a book published internationally on some technical topic. It feels awesome to be an author.

It all started from my blog post on Vyatta+OpenSIPS on Citrix XEN-Server when it caught attention of an Author Relation Executive from Packt Publishing, a well known publisher for technical books. I was contacted and was subsequently asked to write a 100 page book on the Citrix XenServer.

So my work with this book started around Oct,2012  A lot of things changed around me while writing this book; I changed my job, got married, got busy in personal startup as a vendor of a star product for a big Telecom here. And meanwhile all these, this book got a little bit delayed. I personally thank Yogesh Dalvi the Editor, and Sneha Modi the Project Coordinator of this book who tolerated with me throughout this book happily.

Summary of the Book:
As the title suggests this book is a Quick Starter guide for Citrix XenServer, anyone who knows about clouds and virtualization and wants to get involved with this wide spreading technologies should take this book as a beginner to interim level guide. Citrix is a giant leader in providing cloud based solutions, there are other great products as well see this link.

I've tried to keep things as simple as possible to understand and not use the really techy jargon. Like usual approach the starting chapters introduce the history of XenServer, and my personal introduction with virtualization. Since this is a quick starter book so the immediate goals are to setup a Citrix XenServer host and then find out what can be done to create virtual machines; where to place those virtual machines; storage concepts and their usage in our Virtual machines setup.
Daily maintenance like, creating and deploying snapshots, templates and importing virtual machines are covered besides topic like cloning, network connectivity,  and importance of XenServer tools.

This book explains the management of a VM resources like CPU, Memory, storage. Specialized networking concepts are also explained like Network pools, VLANs, NIC Bonding, and introduction to Virtual Switches and Routers. Advanced topics related to Citrix XenServer such as High Availability, Role Based Admin Control, and conversion of Physical machine to Virtual machine are briefly introduced in the last chapter.

Acknowledgements:
Besides being thankful to God, and my loving Parents, I'd like to say my heartiest thanks to my dear Wife who really helped me completing the last few lingering chapters, I love you my sweet Wife. Then I want to thank my colleagues and friends at Vopium who not only appreciated this book-writing but also helped me in multiple ways to dedicate my time on this book. I'm thankful to Mr. Husnain from HR team; Mr. Imran Iqbal   Head of Operations who appreciated, allowed, and applauded this activity; Mr. Haroon Scrum Master who provisioned me with only enough projects to be able to give time to writing this; Mr. Shahzad Senior Manager VoIP team as being my Mentor; then Mr. Abdul Basit, my Manager VoIP who gave me permissions and assisted me in starting up with this book. My friend Salman, Faheem, Rizwan, and Qasim who made fun of me and made me feel 'encouraged' to continue writing(:P).

Thank you all. I am really grateful and very much appreciate the help to avail this opportunity.

Saturday, June 8, 2013

Book Review: FreeSWITCH 1.2

FreeSWITCH 1.2 Second Edition
Build robust, high-performance telephony systems 
using FreeSWITCH

I raised my hand when the reviewers for the new FreeSWITCH book  were wanted and hence this is my very first effort in writing a book review on FreeSWITCH which I really like and love to work with.

Anthony Minessale The Father of FreeSWITCH , Michael S Collins from Barracuda Networks, Darren Schreiber CEO & Co-founder 2600Hz, and Raymond Chandler also from Barracuda Networks are the authors of this book.

What is FreeSWITCH:
Quoting from the book,
FreeSWITCH 1.2
"FreeSWITCH is a scalable softswitch. In practical terms, this means that it can do anything a traditional PBX can do and much more. It can (and does) act as the core switching software for commercial carriers. It can scale up to handle thousands of simultaneous calls. It can also scale down to act as a simple softphone for your laptop or personal computer. It can also work in a cluster of servers. FreeSWITCH is the telephony engine that powers the CudaTel Communication Server from Barracuda Networks. "

What FreeSWITCH is NOT:
Again quoting the authors here,
"FreeSWITCH is not a proxy server. If you need proxy server functionality, then consider OpenSIPS, Kamailio, Repro, or other similar software. FreeSWITCH is a back-to-back user agent or B2BUA. In this regard, it is similar to Asterisk and other IP PBX software."

Compared to the previous book, FreeSWITCH 1.0.6, which was released three years ago, this one contains updates which happened all these years. FreeSWITCH is getting more feature rich, scalable, and reliable as the opensource community grows and hence this book is essentially an updated revision of the previous book. There are new chapters covering more details like mod_xml_curl is now a separate chapter explaining its usage for creating dynamic configurations. Similarly the mod_httapi is detailed in chapter 11 this module is developed last year.

I really appreciate the addition of chapter 12,13 on Handling NAT and VoIP Security respectively. I believe these two chapters are more important for beginners on FreeSWITCH as they face NAT issues right when they start using FreeSWITCH, and once they do get through this stage the insecure nature of their deployment becomes their top most priority. A very good detailed explanation on how to secure the Server at Network layer, and Application layer with separate methods to secure the Signalling and Media.

As expected and naturally the first chapter deals with the introduction of the application's architecture and how different module types are connected to the central core and there are further loadable modules which enable their respective functionality into the system.
The image on the right is self explanatory on how different modules are independent of each other and this modular approach enables FreeSWITCH to be a scalable system where the core handles the switching part only. In next chapter Installation, and starting up of FS is detailed on different operating systems including Windows.

If you're a beginner and want to understand the working of FS then you need to attend to Chapter 3 very carefully. I personally refreshed some very basic but important concepts related to XML dialplan and use of channel variables from this chapter. This chapter teaches us exactly how to interact with FreeSWITCH using it Command Line Interface plus Sort of Hello-world configuration handling in the form of:
•  Configuring different phones to work with FreeSWITCH
•  Calling various default extensions in the system

I really like the way the chapters are written progressing step by step, I enjoyed adding up a new SIP user in the User Directory. Defining user groups, routing to newly created dialplan in XML, testing the voicemail really made me smile. Looking at the gateway configurations, integrating my test FreeSWITCH with my CISCO gateway and making calls IN/OUT was fun. Chapter 4 was indeed addition to my knowledge and skills related to FS.
[Tip: execute 'sofia profile external restart reloadxml' to add the gateway.]

I was impressed to know that FreeSWITCH has more than 140 Dialplan applications.

LUA is one of my favorite language and honestly I got introduced to LUA from FreeSWITCH. Since then I enjoy writing complex FreeSWITCH application using LUA. We do however need some XML in our deployments but most of the time I find myself working in LUA. I was happy to see full chapters on both LUA and XML advance concepts. Click on the book thumbnail to Preview the chapter on Dialplan scripting with LUA.

I really appreciate the effort put in by the authors and reviewers, a very big help for anyone who wish to get closer to the FreeSWITCH VoIP Servers. A very well written book focusing every step required to start using the FS without hurdles.

Looking forward to read books like these from OpenSource VoIP community. I hope to implement the given examples myself in upcoming weekends and post my experiences.

Thursday, June 6, 2013

Asterisk Dialplan and Redis Integration

I came across this very strange task that I need to have the asterisk get/set data from Redis. My initial thought was this is easy, just going to plug in a perl AGI, use redis connector and everything will be super cool. BUT the condition was I've to stay within the extensions.conf. Yes, I did try convince everyone around but to no avail. NO AGIs, use anything else however I want.

So what I did was create a small shell script which behaves as an API for Redis, and use the Asterisk System() application to GET/SET my desired memcached values.

root@asterisk1:~# vim /etc/asterisk/redis.pl

Insert the following lines in there, add more commands to it see this link: http://search.cpan.org/dist/Redis/lib/Redis.pm

#!/usr/bin/perl

my $redis_db = $ARGV[0];
my $command = $ARGV[1];
my $keyname = $ARGV[2];
my $value = $ARGV[3];

# PERL MODULE
require Redis;
my $redis = Redis->new(server => '127.0.0.1:6379');

if($redis_db > 0 && $redis_db < 16){
        $redis->select("$redis_db");
} else {
        print "using Default Redis DB\n";
}
if($command eq "GET"){
        $val=$redis->get("$keyname");
        print "$val";
}
if($command eq "SET" && $value != ""){
        $redis->set("$keyname" => "$value");
}
if($command eq "INCR"){
 $redis->incr("$keyname");
}

if($command eq "DECR"){
 $redis->decr("$keyname");
}

if($command eq "DECRBY"){
 $redis->decrby("$keyname",$value);
}
if($command eq "DEL"){
$redis->del("$keyname" ) || warn "key doesn't exist";
}
$redis->quit;

Save and Exit;

give permissions to this script.

root@asterisk1:~# chmod 755 /etc/asterisk/redis.pl

Now in Dialplan I call System() Application like this.

exten => _XXX,1,SET(CALLS=${SHELL(/etc/asterisk/redis.pl 1 GET ${CALLERID(num)})})
same => n,NOOP(The Caller:${CALLERID(num)} has ${CALLS} calls in the system)
same => n,Answer()
same => n,System(/etc/asterisk/redis.pl 1 INCR ${CALLERID(num)})
same => n,NOOP(Do some dialplan actions as you want)
...
...
exten => h,1,System(/etc/asterisk/redis.pl 1 DECR ${CALLERID(num)})
exten => h,n,Hangup()

Thats all. Now I can keep realtime track of the active calls for any user/trunk/carrier etc etc from my dialplan. The real beauty of using this shared Redis Memcache store is that I've like 8 asterisk servers, all of them using the same Redis store and all of them are aware of the current number of calls from/to a particular user.

I've also used it to share the Statuses of Queues and Conference rooms residing on special servers with normal IVR servers. Without using this shared store I can only think of using a Database used by all and I believe that doesn't perform well when multiple users are accessing and modifying the same field concurrently especially when the usage is heavy.