/weblog/inter-asterisk-exchange-voip-primer

Inter-Asterisk Exchange :: IAX2 VoIP Primer

Friday, June 20, 2008

The Asterisk Open Source PBX uses a standard set of protocols to communicate with remote systems be it another Asterisk server or other types of Voice over IP systems and hardware. Knowing how these VoIP protocols function will not only give you a clear picture of how Asterisk deals with VoIP, but show you how other systems work as well. One VoIP protocol that is unique to the Asterisk project is Intra-Asterisk eXchange (IAX2).

Inter-Asterisk Exchange is a voice over internet protocol developed by Digium's Mark Spencer; Asterisk's lead developer. Today, when people refer to IAX (pronounced eeks), they most likely mean IAX2, which is the second version of the IAX protocol. The original IAX protocol has since been depreciated. As the name implies, IAX2 is another method to transfer voice and other data from Asterisk to Asterisk. The protocol has gained some popularity, and now devices outside of Asterisk's software support the IAX2 protocol.

The idea behind IAX2 was simple: build from the ground up a protocol that is simple and full featured. IAX2 uses one UDP port for both signalling and media transfer. The default UDP port is 4569 and is also used for both the destination and the source port. This means signalling for call set-up, tear down, and modification, along with the UDP datagrams, are all sent over the same port using a single protocol. It is sort of like two protocols combined into one! This also means that IAX2 has its own built-in means of transferring voice data, so unlike a call placed with Session Initiation Protocol (SIP), a second transport protocol (RTP) is not used.

When IAX2 was being designed, there where many problems with SIP in Network Address Translation (NAT) environments. With SIP, you had signalling happening on one port (typically TCP port 5060) and RTP being sent over a range of UDP ports. This was incompatible with NAT firewalls, and SIP proxies and other hacks had to be developed. Since all IAX2 communications to and from an Asterisk server or IAX device happen over a single port, using a single protocol, IAX2 works in just about any network environment without issue with NAT firewalls or routers.

This alone is pretty groovy stuff, but it doesn't stop there!

IAX2 supports built-in encryption. It uses an Advanced Encryption Standard (AES) 128-bit block cipher. The protocol is built upon a "shared secret" type of set-up. That is, before any calls can be encrypted, the "shared secret" must be stored on each Asterisk server. IAX2's AES 128-bit encryption works on a call-by-call basis and to reduce processing overhead, only the data portion of the message is encrypted.

IAX2 also employs various ways to reduce the amount of bandwidth needed in order to operate. Unlike SIP's easy-to-understand almost HTTP-like commands (methods) and responses, IAX2 uses a "binary" approach. Binary codes reduce the size of signalling. To further reduce bandwidth usage, "Trunking" was introduced into the protocol. When trunking is enabled, multiple calls can be combined into single packets.

What does this mean?

Let's assume an office has four calls going on at one time. For each call, VoIP packets are sent across the network with the "header" information. Within this header is information about the source, destination, timing, and so on. With trunking, one packet can be used to transfer header information about all the concurrent calls. Since you don't need to send four packets with header information about the four calls, you're knocking down the transmission of header data from 4 to 1. This might not sound like much, but in VoIP networks that tend to have a large amount of concurrent calls, trunking can add up to big bandwidth savings.

How IAX2 Works

In order to accomplish both signalling and streaming audio data of a call, IAX2 uses two different UDP "frame" types: "Mini Frames" and "Full Frames".

Full Frames are used for "reliable" information transfer. This means that when a full frame is sent, it expects an ACK (acknowledgment) back from the target. This is useful for things like call set-up, tear down, and registration. For example, when a call is made with IAX2, a full frame requesting a "NEW" call is sent to the remote Asterisk server. The remote Asterisk server then sends an ACK, which tells the sending system the command was received.

Full frames are also used for sending other information such as caller ID, billing information, codec preferences, and other data. Basically, anything that requires an ACK after a command is sent will use full frames.

Unlike the Full Frame, a Mini Frame requires no acknowledgment. This is an unreliable means of data transport, and like RTP, either it gets there or it does not. Mini Frames are not used for control or signalling data, but are actually the UDP datagram that contains the audio portion of the call. Overall, it works similar to RTP, in that it is a low overhead UDP stream.

An IAX2 Frame only contains an F bit to specify whether it's a Full or Mini Frame (F bit set to 0 == Mini Frame), the source call number, time stamp, and the actual data. The time stamps are used to reorder the packets in the correct order since they might be received out of order.

To learn more about leveraging Asterisk and the features of the IAX2 protocol, contact me using this form.

UPDATE: VoIP Supply has announced the availabilty of a new IAX2 deskset phone; Citel C4110. In an effort to promote this phone, they have drafted a contest, giving away one of three of C4110 phones.