Wednesday, November 21, 2012

How big is IPv6?

IPv6 uses 128-bit addressing allowing 2128 addresses.

Analogy 1: Size based analogy

Say 1 IP address is equivalent to 1 picometer ( 10-12 meter = 0.000000000001 meter )
IPv4 is the size of an ant:  232 picometer = 4.29mm  
IPv6 is ridiculously large: (2128) picometers = 35 Billion light years
Note: 1 light year = 9.4605284 × 1012 kilometers = 5.87849981 × 1012 miles

Analogy 2: Weight based analogy
Say 1 speck of dust weighs 1 microgram
Mass of the Earth = 5.98 x 1027 grams = 5.98 x 1033 microgram

Say Earth is made up of the dust particles

Total amount of the dust particles in Earth = 5.98 x 1033 which is equivalent to 2112

Total number of IPv6 Addresses: 2128

IPv6 address space is good enough to assign an IP address to each dust particles in  2(128-112)=216= 65536 planets the size of the earth.

IPv6 address space allocation looks wasteful but it is so beautiful that you don't have to worry about conserving IP addresses any more as you can get ridiculously huge amount of address space. Now you can focus more on managing network rather than managing network address space itself. With that being said, proper IPv6 address planning is crucial otherwise it can get ugly and become a nightmare.

Wise principle to follow while doing IPv6 Address planning: Forget about IPv4 thinking, like address conservation, subnets, legacy class concepts, subnet masks (simply remember how to use CIDR style notation), etc. 

IPv6 is 128 bits. Make life simple. Break it into two 64 bits. First 64 bits for network and second 64 bits for interface.You can break first 64 network bits into Global Unicast Prefix(48 bits) and Subnet(64 minus 48 = 16 bits).

More yet to come... 

Thursday, March 8, 2012

Shared Line Appearance/Bridged Line Appearance in Asterisk

1.    Design Overview:

When someone calls Boss’ line, it will ring Boss’ as well as Assistants’ phone (Asterisk SLA/conference function and Line Trunking allows this feature).
Assistants can see the presence of their Boss’ line (Presence feature on Polycom phone and Asterisk HINT allows this).  Assistants can pick up the call by pressing the line button. Boss can join the conversation by pressing the line button as well (Barge In function, Asterisk Conference and Line Trunking allows us to do this)
You can simply put a call on hold from one phone and pick it up from another. Also, if multiple phones press the key for the shared extension, they will all be bridged into the same call(Asterisk SLA/conference function allows this feature).

2.    Terminologies:
  • Asterisk Technologies/Channels/Devices: There are various technologies/channels/devices available in Asterisk.
                & more ….

           Defined  Local channel that lands the call in ‘disa’ extension of context [SLA_Outbound] in extensions.conf
  • DISA:  DISA (Direct Inward System Access) allows someone calling in from outside the telephone switch(PBX) to obtain an “internal” system dialtone and dial calls as if from one of the extensions attached to the telephone switch.  Check more @
  • SLA: Shared Line Appearance
  • BLA: Bridged Line Appearance
  • Station: It is any SIP phone that will be using SLA
  • Trunk:  It is a literal trunk or shared extension that will be appearing on two or more stations
  • SLAStation() : Shared Line Appearance Station application. It should be executed by an SLA station. The argument to this application depends on how the call was initiated. If the phone was just taken off hook, then the argument ‘station’ should be just the station name. If the call was initiated by pressing a line key, then the station name should be preceded by an underscore and the trunk name associated with that line button.
      exten =>20000, n,SLAStation(20000)
      exten => 20000_line1,1,SLAStation(20000_line1)
  •  SLATrunk(): Shared Line Appearance Trunk application. This application takes care of ringing of all the appropriate stations.   

exten => 20000,1,Verbose(1,### Dialing trunk line1)
        same => n,Goto(sla,1)

exten => sla,1,SLATrunk(line1)

3.    Implementation:
  • Check if all the required Asterisk applications are installed properly
SLA application uses two key technologies: Device State Processing and Conferencing. Conferencing uses MeetMe() application. MeetMe() application is offered by app_meetme module. App_meetme module requires DAHDI to be installed (even if you don’t use PRIs).
You have to load dahdi and dahdi_dummy before you start asterisk. You can check if those are loaded or not.
# lsmod|grep dahdi
dahdi                 210879  0
crc_ccitt               1651  1 dahdi

If you don’t get output like above, you might want to load it manually
#modprobe dahdi
#modprobe dahdi_dummy

Now check if app_meetme module is loaded or not.
*CLI> module show like
Module                         Description                              Use Count                  MeetMe conference bridge                 0
1 modules loaded

[If it says 0 modules loaded, double check if dahdi and dahdi_dummy are loaded successfully or not. You might also get “WARNING[15929]: app_meetme.c:1228 build_conf: Unable to open DAHDI pseudo device” for not having dahdi_dummy]
Check if SLAStation() and SLATrunk() applications are available
*CLI> core show applications like SLA
    -= Matching Asterisk Applications =-
    -= 2 Applications Matching =-

  • Asterisk Configuration
You have to understand and edit sla.conf, extensions.conf and sip.conf.

Trunks and Stations are defined in sla.conf. Mapping of devices to trunks and stations are also done here.
Station: It is any SIP phone that will be using SLA
Trunk:  It is a literal trunk or shared extension that will be appearing on two or more stations




[station](!)  ;Template for stations 

[20000](station)   ;Note:section name do not need to match SIP device name


Trunk must be tied up with a device. Otherwise it will crash asterisk.

Here, we defined
•    two trunks [line1] and [line2]
•    two stations [20000] and [20001]   

If you watch very closely on above configuration, you will see that
•    trunk [line1] is tied up with device=Local/disa@SLA_Outbound
•    stations [20000] and [20001] are tied up with  device=SIP/20000
and device=SIP/20001 and will use trunk [line1] as defined in [station](!)  template

In our current scenario, we will not be using trunk [line2] to simplify the demonstration.

You can verify those by executing ‘sla’ commands in asterisk
*CLI> sla show trunks

=== Configured SLA Trunks ===================================
=== ---------------------------------------------------------
=== Trunk Name:       line1
=== ==> Device:       Local/disa@SLA_Outbound
=== ==> AutoContext:  (none)
=== ==> RingTimeout:  (none)
=== ==> BargeAllowed: Yes
=== ==> HoldAccess:   Open
=== ==> Stations ...
===    ==> Station name: 20000
===    ==> Station name: 20001
===    ==> Station name: 20002
=== ---------------------------------------------------------
=== ---------------------------------------------------------
=== Trunk Name:       line2
=== ==> Device:       Local/disa@SLA_Outbound
=== ==> AutoContext:  (none)
=== ==> RingTimeout:  (none)
=== ==> BargeAllowed: Yes
=== ==> HoldAccess:   Open
=== ==> Stations ...
=== ---------------------------------------------------------

*CLI> sla show stations

=== Configured SLA Stations =================================
=== ---------------------------------------------------------
=== Station Name:    20000
=== ==> Device:      SIP/20000
=== ==> AutoContext: (none)
=== ==> RingTimeout: (none)
=== ==> RingDelay:   (none)
=== ==> HoldAccess:  Open
=== ==> Trunks ...
===    ==> Trunk Name: line1
===       ==> State:       SLA_TRUNK_STATE_IDLE
===       ==> RingTimeout: (none)
===       ==> RingDelay:   (none)
=== ---------------------------------------------------------
=== ---------------------------------------------------------
=== Station Name:    20001
=== ==> Device:      SIP/20001
=== ==> AutoContext: (none)
=== ==> RingTimeout: (none)
=== ==> RingDelay:   (none)
=== ==> HoldAccess:  Open
=== ==> Trunks ...
===    ==> Trunk Name: line1
===       ==> State:       SLA_TRUNK_STATE_IDLE
===       ==> RingTimeout: (none)
===       ==> RingDelay:   (none)
=== ---------------------------------------------------------

Asterisk dialplan (extensions.conf) allows to setup extension state hints and extensions that define how calls get into and out of an SLA setup.

exten => 20000,1,Verbose(1,### Incoming Call to extension${EXTEN})
        same => n, Dial(SIP/${EXTEN})

exten => 20000_line1,hint,SLA:20000_line1

exten => 20000_line1,1,SLAStation(20000_line1)) ;This puts the call thru' disa@SLA_Outbound as it forces the call thru' the trunk
exten => 20001,1,Verbose(1,### Incoming Call to SLAStation)
        same => n, Dial(SIP/${EXTEN})

exten => _X.,1,Verbose(1,### Incoming Call from ${CALLERID(name)} : ${CALLERID(num)}) 


exten => disa,1,DISA(no-password,SLA_Outbound)

exten => _X.,1,Verbose(1,### Incoming Call from ${CALLERID(name)} : ${CALLERID(num)})
exten => 20000,1,Verbose(1,### Dialing trunk line1)
        same => n, SLATrunk(line1)

exten => _X.,1,Verbose(1,### Incoming Call from ${CALLERID(name)} : ${CALLERID(num)}) 


SIP users are defined in sip.conf. SIP users for SLA stations are assigned [SLA_Stations] context.


[SLA-sip-phone](!) ;Template

callerid= "Boss" <20000>

callerid= "Secretary" <20001>

[sip-phone](!) ;Template

callerid= "John Doe" <20002>

Here 20000 and 20001 are using SLA-sip-phone template, thus they land in [SLA_Stations] of dialplan
And 20002 is using sip-phone template and it lands in [External] context

  • Polycom phone configuration
For phone with extension 20001
Make sure that directories, buddies and presence features are enabled.
Then define the directory for the phone.


         Boss Line1

Similar configuration for phone with extension 20000

You can now start testing. Please remember that you have to customize your dialplan according to your environment. Good Luck!

Thursday, February 23, 2012

SIP Load Sharing/Balancing and Failover using DNS SRV records

Note: It is assumed that you know about SIP protocol and you know how to configure SIP clients and SIP servers. [You can also check out my blogs on SIP at  for more info on SIP clients and SIP server configuration]
Brief Introduction on DNS:
DNS(Domain Name System) is a hierarchical distributed naming system for computers, services or any resource connected to the internet or a private network. It translates queries for domain names into IP addresses for the purpose of locating computer services and devices worldwide. (Src:Wikipedia)

In layman term, it maps human-friendly name into IP addresses. For example, it is alot easier to remember instead of remebering IP address of the www host of
DNS server stores the DNS records for a domain name, such as Address(A) records, Name Server(NS) records, Mail Exchanger(MX) records, Service (SRV) records and more. DNS server responds to the DNS queries made by it's clients against its databse.

For more info:

DNS Service(DNS SRV) record - RFC 2782: It is a type of DNS record/entry that specify the location of service available in a domain. It is typically used by clients to locate a service within a domain.

For example:
In Active Directory environment, PCs on domain rely on SRV records to locate domain controllers to authenticate to within their domain.

In SIP environment, SIP clients use SRV records to determine where to send an outgoing call.

Most importantly, DNS SRV records allow you to use domain name rather than full hostname of the server in the SIP address field of the client configuration.

SRV record is written in ZONE file as: TTL class SRV priority weight port target

_sip._udp.rapidtech.phones. 300 IN SRV 0 40 5060 sipserver1.rapidtech.phones.
_sip._udp.rapidtech.phones. 300 IN SRV 0 60 5060 sipserver2.rapidtech.phones.
_sip._udp.rapidtech.phones. 300 IN SRV 1 5 5060 sipserverbackup.rapidtech.phones.

service: name of the service e.g sip

proto: transport protocol of the service e.g tcp or udp

name: domain name that this record belongs to e.g rapidtech.phones

TTL: Time to Live value for this DNS record (Expiry time for the DNS record). Adjust this based on your environment. E.g If you set it to 300 seconds, client will make DNS query to the server every 5 minutes.

class: DNS class. This is always 'IN' here

Priority: Priority for the multiple hosts offering same service. This helps you to define failover serivce hosts. Lower value means more preferred. e.g sipserver1 and sipserver2 have priority 0 thus acts as primary servers and sipserverbackup has priority 1(greater than 0) thus acts as failover server.

Weight: A relative weight for records with the same priority. It is used for load sharing among the servers e.g. sipserver1 and sipserver2  sipserver1 will be used 40% of the time and sipserver2 will be used for 60% of the time.  If all the servers with priority 0 are unavailable, the record with the next highest priority value will be chosen, which is sipserverbackup.rapidtech.phones and it will be used 100% of time as it is not sharing load with another server.

port: TCP or UDP port on which the service is available e.g 5060 for SIP

target: the canonical hostname of the server providing the service e.g sipserver1.rapidtech.phones., sipserver2.rapidtech.phones., sipserverbackup.rapidtech.phones.

Ok great, now how do I implement it? Right!

DNS server:
Here I am going to use BIND/named (Linux based DNS server)
To run your own DNS: Install the bind, bind-devel, bind-utils, and caching-nameserver packages

Master Zone file:  rapidtech.phones

 #vi /var/lib/named/master/rapidtech.phones

$TTL 1800
@               IN SOA          dns1.dnsserver.phones.     root.dns1.dnsserver.phones. (
                                2012022302      ; serial
                                1800                    ; refresh time in seconds
                                600                      ; retry time in seconds
                                1w                        ; expiry time
                                1800 )                  ; minimum TTL

rapidtech.phones.        IN NS           dns1.dnsserver.phones.
sipserver1  IN A  
sipserver2  IN A  
NTP            IN A  
FTP             IN A  

_sip._udp.rapidtech.phones.   IN SRV 0 40 5060 sipserver1.rapidtech.phones.
_sip._udp.rapidtech.phones.   IN SRV 0 60 5060 sipserver2.rapidtech.phones.
 _sip._udp.rapidtech.phones.  IN SRV 1 5 5060 sipserverbackup.rapidtech.phones.

Define a zone in named.conf
#vi /etc/named.conf

logging {
        channel log_file {
                file "/var/log/bind.log" versions 3 size 100M; 
                severity dynamic;
                print-time yes;
                print-severity yes;
                print-category yes;

        category statistics { log_file; };
        category queries { log_file; };
        category xfer-in { log_file; };
        category xfer-out { log_file; };
        category default { log_file; };
#all DNS category activities will be logged in /var/lib/named/var/log/bind.log [ Warning!! it will not log in /var/log/bind.log ]

zone "rapidtech.phones" in {
        allow-transfer { any; };
        file "master/rapidtech.phones";
        type master;

Now restart the DNS service

#service named restart 

SIP clients:
SIP Proxy server setting: rapidtech.phones
This setting will allow SIP clients to make call thru' the available SIP servers.

[ Did you notice that just using domain name, you are directed to the available server according to the rules of SRV record? In this case, simply using rapidtech.phones, SIP client will use sipserver1 or sipserver2 or sipserverbackup according to the SRV records rule ]

Good Luck!

DNS SOA Header:
 DNS SRV Record:

Monday, January 30, 2012

Windows not syncing with NTP server

NTP (Network Time Protocol) is widely used for computer clock synchronization in  internet. There are various versions of NTP. Latest version as of Jun 2010 is NTPv4 and is well described in RFC5905. NTP4 is modified to accommodate IPv6 and other improvement has been done over NTPv4.

Are you getting 'Peer Unreachable' when you try to syc with NTP server?
Usually there are various reasons behind the problem.

1. Firewall or port filter : Make sure that default UDP port 123 is open. You can test this real quick just by turning off Firewall.

2. Windows Time Service (w32time) not running on the appropriate mode
There are various modes of operation for Windows Time Service as NTP supports several different packet types.
Normally NTP client sends 'client' mode request packets to a NTP server
NTP server responds back with 'server' mode packet with timing information

By default some windows (esp. XP and earlier) sends 'symmetric active' mode packet instead of 'client' mode request packets. 'symmetric active' mode packets is for NTP's peering feature where a pool of computers(peers) are configured to sync their clocks among each others to agree upon a common 'network time', which then can be supplied to the client.

Usually NTP server drops 'symmetric active' mode packets, unless it is told to do so.

Q: How can I switch to 'client' mode of Windows Time Service?

Ans: You have to change the Windows registry and it can be done easily via command line

 w32tm  /config  /,0x8  /syncfromflags:MANUAL

Here, is my NTP server

The valid settings for the mode used with the /manualpeerlist switch include the following:
  • 0x01 - use special poll interval SpecialInterval
  • 0x02 - UseAsFallbackOnly
  • 0x04 - send request as SymmetricActive mode
  • 0x08 - send request as Client mode
The mode that Windows Time uses to send requests is set by the following registry subkey:

0x8  enables 'client' mode for Windows Time Service
syncfromflags:MANUAL  forces Windows Time Service to use manualpeerlist for the time query. 

Make changes effective immediately
w32tm  /config  /update

To resync manually
w32tm /resync

Additional Tips: 
If you want to sync with time server everyday, you can create a new 'Scheduled Task' under Control Panel --> Scheduled Task to run  'w32tm  /resync' everyday at your specified time.

Good Luck!

Friday, January 20, 2012

Integrate Asterisk with SIP enabled Wireless phone: Polycom SpectraLink 8030

If you are looking for SIP and 802.11a/b/g compatible wireless phone, SpectraLink 8030 can be one of your choices. It is compatible with Asterisk.  It has also Push-To-Talk (PTT) functionality that allows group communication just like Walky Talky.

Product information of SpectraLink 8030 can be found at

Software and documents for SpectraLink 8030 can be downloaded from following link from Polycom

If you are using Polycom SpectraLink VIEW certified Wireless Access Point, you can call 1-800-Polycom and get the support. If not, there is no luck to get any kind of support from them.

In my case, we have
  • DHCP , DNS, NTP and TFTP server running on Linux
  • Xirrus Array - XN4, XN8   (Make sure your wireless AP supports WMM- Wi-Fi Multimedia; sometime you might have to upgrade to the latest firmware. Contact your  Wireless AP vendor if your AP doesn't have WMM enabled)
  • Asterisk Server (SIP server + PBX) : IP address
  • SpectraLink 8030 ( one has an extension 2000 and other has an extension 3000)
  • Voicemail (Extension 2100)
In this article, I am not going to show you how to configure DHCP, DNS, NTP, TFTP server. If you need any help, contact your Server Administrator or look for online help.

Step1: Publish the required firmwares and configs to  TFTP server
Download SIP software of SpectraLink 8030 from above link  
Unzip it and publish the content to TFTP server

You will see various .bin files and .cfg files.

In my case, I have following files

You don't have to touch .bin files.  You don't even have to touch slnk_cfg.cfg file

All you need to do is edit sip_allusers.cfg and create the config files for individual extensions (in my case I have two SpectraLink. I want to extensions: 2000 and 3000)

#vi sip_allusers.cfg
#--------Configuration for Asterisk based system-------------
PROXY1_TYPE            = Asterisk
PROXY1_ADDR            =  #IP address of Asterisk Server
PROXY1_KEYPRESS_2833   = enable
PROXY1_HOLD_IP0        = disable
PROXY1_PRACK           = enable
PROXY1_REREG_SECS      = 3600

Create a config file for an extension 2000
#vi sip_2000.cfg
LINE1         = 2000
LINE1_CALLID  = Spectralink x2000
LINE1_AUTH    = 2000; myp@ssw0rd

#Note- Password follows extension in LINE1_AUTH line

Similarly create a config file for an extension 3000

#vi sip_3000.cfg
LINE1         = 3000
LINE1_CALLID  = Spectralink x3000
LINE1_AUTH    = 3000; myp@ssw0rd

#Note- Password follows extension in LINE1_AUTH line

Step2: Configure Asterisk Server

Spectralink 8030 wouldn't register to Asterisk server. I have to go thru' rigorous troubleshooting before I could figure out the fact that SpectraLink 8030's latest SIP software is still based on the original SIP RFC 2543. [ Polycom support didn't want to talk about anything as I wasn't using their VIEW certified AP. ]

[Please read about fundamental SIP request header if you haven't done so far]

However Asterisk is designed on the basis of latest SIP RFC 3261. Asterisk server drops the REGISTER request coming from SpectraLink 8030 because as per RFC 2543 standard SpectraLink doesn't send tag id in SIP REQUEST FROM header.

Thus you have to tell Asterisk to ignore the tags in SIP request headers. You can do that by using global option in sip.conf

Asterisk 1.8 has pedantic=yes by default

;pedantic=yes ; Enable checking of tags in headers,
                                ; international character conversions in URIs
                                ; and multiline formatted headers for strict
                                ; SIP compatibility (defaults to "yes")

You have to use   pedantic=no  for SpectraLink 8030 to work with Asterisk

#vi sip.conf

callerid="Dave One" <2000>

callerid="John One" <3000>

Step3: Configure AP 
Different APs have different tools for wireless configuration. Make sure you are using 802.11a/b/g wireless APs. AP must be configured as WMM-PowerSave. Please go thru' the product guide that came along with your AP to enable WMM-PowerSave.

Create a SSID for your voice network. [You many not want to broadcast this SSID to minimize easy access to SSID by intruders]

You can use any kind of encryption you want to. I prefer WPA2 as it uses Pre-Shared Key(PSK) and it allows user to manually enter keys to initiate WPA security.

SSID: spectralinknetwork
WPA2 passphrase: myp@ssword

Make sure various Radio bands are available  for use. I have enabled a/g band and I am going to use '802.11a standard'  for my SpectraLink phones. 

BONUS INFORMATION: Brief introduction on various wireless standards:
  • 802.11a standard operates in 5GHz band with maximum data rate of 54Mbps. It's range is lower than the range of 802.11b but offers higher number of channels and also higher data rate.
  • 802.11b standard operates in 2.4GHz band with maximum data rate of 11Mbps. It's range is higher range than 802.11a but it suffers interference from other devices like Bluetooth, cordless telephonesc etc operating at 2.4 GHz. Data rate offered is less than 802.11a.
  • 802.11g standard operates in 2.4GHz just like 802.11b, but operates at maximum data rate of 54Mbps. 
  • 802.11n standard operates in 5GHz and/or 2.4GHz using MIMO technology. 

Step4: Use SIP HAT(Handset Administration Tool) provided by Polycom to configure the initial configuration for SpectraLink 8030. You can download SIP HAT from above provided link 

Network Configuration of SpectraLink via SIP HAT Tool
  • Enable DHCP
  • Use SSID:spectralinknetwork  and WPA2 passphrase: myp@ssword and click on 'Generate PSK from Passphrase + SSID' button
  • Use QoS Type 'Wi-Fi Standard'
  • Admission Control: Optional
  • 802.11 Config: a
  • Enable the bands you want to use

SIP configuration and others via SIP HAT Tool
  • Change the TimeZone as required
  • Enter the SIP username: 3000 and password: myp@ssword
Follow the procedure as per instructed by SIP HAT Software to write the settings to SpectraLink 8030 handset. It might prompt for the password before you can write the settings to the handset. Default password is '123456'. Ignore any minor errors while writing the settings to handset as handset will download the latest firmware from your TFTP server anyway.

 Step5: Powercycle the handset. If your ducks are in row, it will work without hassle. If come across any issues, follow the SpectraLink 8020/8030 Wireless Telephone Administration Guide for SIP.

SpectraLink 8030 displays Startup Sequence: 1 thru' 9.  Let's say your handset is stuck at '1234567', it means it has successfully gone thru '8' and '9', but it is stuck at '7'. If you look on the administrative guide, '1234567' means DHCP response with bad DNS server configuration. So, you have to fix possible DNS/DHCP server issue.

If you need further help, you can email me at or simply post the comment.