ENUM/E164 Call Routing (LCR)

Introduction

ENUM is a telephony technology that may single-handedly create the greatest changes in both Internet telephony as well as regular telephone service. In a nutshell, ENUM is a technology which allows users of disparate networks and technologies to call each other through the use of a common routing database. This database is stored in DNS records on a centralized server.


				5.4.3.2.1.enum.fierymoon.com.     NAPTR   100 10 "u" "E2U+IAX2" "!^\\+(.*)$!iax2:guest@127.0.0.1/\\1@local!" .
			

Figure 1. A sample ENUM entry in a DNS record

In the above figure, the record would be parsed by an ENUM compatible system to read "Phone number 12345 is to be redirected to iax2:guest@127.0.0.1/12345@local" All of the weird mumbo jumbo in the lines is important - they're called Regular Expressions and it's a topic too big to be covered in this documentation.

Making ENUM Work for You

Imagine you're the phone company, and you want to offer a new service that allows a single phone number (say, your home number) to ring multiple phones at once. With ENUM, this is painfully simple. You would simply create multiple ENUM entries for the same number, and increment the priority in the NAPTR line (For hints on how NATPRs work, check the BIND/DNS documentation.)

For most users, though, ENUM has an even more useful implication: Free long distance calling over the Internet. Take http://enum.fierymoon.com , a production ENUM registry and database. By simply adding what exchanges your system can call locally, suddenly people from all over the world can utilize your Asterisk system to make calls that would otherwise cost an arm and a leg.

As an example, let's take John Q. Public, who's recently moved to India to follow a tech job. He has family back in Seattle that he wishes he could talk to on a daily basis. Before, he would have to have either an expensive calling card, or some other home brew solution for point-to-point Internet dialing. Now, with the beauty of ENUM, John can use enum.fierymoon.com with his hobby asterisk box to see if there is an ENUM entry in Seattle. Let's say that John Smith has a T1 in Seattle and seldom uses it after hours - he can set up his ENUM records to let everyone who uses the ENUM database utilize his local calling area. Suddenly John Q. is making his calls to family and friends for only the cost of his Internet connection.

Setting up ENUM Routing on your Asterisk System

ENUM is a relatively easy item to setup on your asterisk system. If you're looking to dial out, it's as simple as using the EnumLookup application with a properly configured enum.conf (examples below.) If you're looking to be an endpoint of ENUM (i.e., if you'd like to donate some of your phone service to someone in need) then there is just a bit more work to be done.

enum.conf

This configuration file is blindingly simple. It has but one directive type, "search". Let's say you've got five separate ENUM sources you'd like to look up from, you'd simply list them in individual search lines:


					
					; ENUM Configuration for resolving phone numbers over DNS
					;
					
					[general]
					
					;
					; The search list for domains may be customized.  Domains are searched
					; in the order they are listed here.
					;
					
					search => enum.fierymoon.com
					search => e164.org
					search => e164.arpa
				

Figure 2. enum.conf

Remember to restart when you change this file, or else the changes will not be immediately accepted.

A little clarification here: enum.fierymoon.com and e164.org are ENUM/E.164 services, that allow anybody to add their records to the database and maintain them. They more or less were created out of the situation, that the official ENUM registry based on the e164.arpa domain is getting implemented painfully slow and will in many countries not be accessible for updates by individuals.

e164.org for an example took the step of calling you up on any telephone number that you add to their registry, giving you a pinkode, that you need to enter on the website to enable your personal enum records for your regular landline or cellphone. That way nobody can hijack phonenumbers, that he hasn't access to.

enum.fierymoon.com is quite interesting because this ENUM service maintains records of gateways that allow free access to toll free numbers.

extensions.conf

Once you've changed your enum.conf file, it is just a matter of adding some extensions to allow you to dial on ENUM:


					[enumcheck]
					exten => _41NXXNXXXXXX,1,EnumLookup(${EXTEN:1})
					exten => _41NXXNXXXXXX,2,Dial(${ENUM})
					exten => _41NXXNXXXXXX,3,Hangup
					exten => _41NXXNXXXXXX,102,Hangup
				

Figure 3. extensions.conf (snippet)

In this example, the user would dial 4 followed by the number they were attempting to call (This extension example utilizes NANPA numbers, i.e., North America, only.) The EnumLookup application stores the correct URL to dial in the ${ENUM} variable if the lookup succeeds.

Configuring your System to Allow ENUM Calls through your PSTN Interface

Allowing users to dial out of your PSTN interface is quite a noble thing to do! However, you'll want to protect yourself to make sure your nobility is not exploited for someone else's gains! Hopefully in this section you will understand the necessity of protecting your phone bill.

There are a few steps involved in setting up your dial-out ENUM configuration:

  1. Decide which technology you will use for allowing phone calls, be it IAX2, SIP, H323, or any other technology that can be formed into a URI.

  2. Find a list of local exchanges that you can call and keep it handy - you will need it later.

  3. Configure your iax.conf, sip.conf, h323.conf, or any other configuration files that will require modifications for the particular protocol you are intending to interface.

  4. Configure your extensions.conf to have a context specifically for allowing ENUM dial-out.

  5. Add the local exchanges that you found into your astdb so that you can look them up with your extension.

(As a note, I believe that Asterisk only supports IAX2 and SIP as well as PSTN for the URIs ENUM will return - I cannot be 100% sure of this so anyone in-the-know is free to correct me) In our examples, we will be using an IAX2 user for receiving our calls.

iax.conf


					[enumuser]
					type=user
					context=enumloc
					callerid="Enum Lookup" <000>
					disallow=all
					allow=ilbc
					accountcode=enumuser
				

Figure 4. Sample iax.conf configuration for an enum user

Our IAX user setup is pretty simple. All this user needs to do is allow calls into our ENUM outbound context. In this example, I have limited the only available codec to iLBC, so I can cut down on bandwidth consumed in the process. I've also assigned an account code of enumuser, so that when I pull my CDR records I can see who's using the ENUM.

extensions.conf


					[enumloc]
					exten => _1NXXNXXXXXX,1,SetVar(enumok=0)
					exten => _1NXXNXXXXXX,2,ODBCget(enumok=${EXTEN:1:3}/${EXTEN:4:3})
					exten => _1NXXNXXXXXX,3,GotoIf(${enumok}?4:900)
					exten => _1NXXNXXXXXX,4,ChanIsAvail(Zap/1)
					exten => _1NXXNXXXXXX,5,Dial(Zap/1/${EXTEN})
					exten => _1NXXNXXXXXX,6,Hangup
					exten => _1NXXNXXXXXX,105,Playback(enum-inuse)
					exten => _1NXXNXXXXXX,106,Hangup
					exten => _1NXXNXXXXXX,900,Congestion
				

Figure 5. Sample extensions.conf logic for inbound calls

This extension takes a little bit of explanation (There's a lot going on here, so pay attention!) First of all, we initialize a local variable, ${enumok} to 0. This allows us to have a default variable in case our astdb lookup returns nothing. Priority two does the actual astdb lookup. It's pretty simple, it asks whether the area code and prefix are in the astdb database - if they are, great, priority three makes processing continue at step four. If they are not, then they are played a congestion tone at priority 900. At step 4, we ask whether our only FXO device, Zap/1, is in use. If it isn't, we do the dialing required to complete the call. If our Zapata device is in use, we playback the file "enum-inuse" and then hangup.

Now, some of you must be wondering - "How do I get my extensions into the astdb?" Well, that's a hard question to answer, unless you are using ODBCget as opposed to DBGet. I'll give you a bit of a hint here:


					<?
					        $fp=fopen("./lpref","r");
					        while (!feof($fp))
					        {
					                $line=fgets($fp);
					                list($npa,$nxx,$desc,$zone) = split(";", $line, 4);
					                echo "INSERT INTO \"astdb\"
				                        (\"astfamily\",\"astkey\",\"astvalue\")
				                        VALUES('".$npa."','".$nxx."','1');\n";
					        }
					        fclose($fp);
					?>
				

Figure 6. How to create SQL insert queries from a standard NANPA CO/CLEC list

After a reload of asterisk, your box should be ready to receive calls via IAX2 with user name "enumuser", with calls bound to context "enumloc" - your lookups should make sure the call is local to you, and then pass it along.