Puntero Nulo – Episodio 5

Escúchalo:: PunteroNulo-Episodio5

La semana pasada me dijeron que el podcast era demasiado técnico. Gracias, aunque siempre intento digerir las noticias de tecnología algunos días después de que estén de moda (para no caer en la agenda) y de una forma que sea comprensible para la mayoría de la audiencia técnica.

Como siempre, sus comentarios y sugerencias son siempre bienvenidos en el correo j en bureado.com y en Twitter, @bureado.

De facto, el podcast ha estado saliendo quincenal así que mejor no engañaos. A continuación las fuentes de este episodio:


Complex multi-PBX setups with Asterisk

The greatest feature of the Asterisk IPBX is the dialplan. Basically, sources (extensions, incoming calls, inteal applications) and destinations (outgoing calls, extensions at other PBXs, inteal applications) are mapped as contexts on this dialplan thingy. The dialplan lives on the extensions.conf file, or those that are included, such as extensions_custom.conf on FreePBX setups.If you already write your own dialplan, consider yourself an Asterisk hacker and you’ll probably want to stop reading. However, if you wonder how to interconnect multiple Asterisk PBXs, especially when using a Web-based administration interface such as the ones found on Elastix, Trixbox and home-brewed FreePBX-based solutions, then keep reading, I hope it’s edifying and entertaining.Assume you have three locations which need PBX service. In my case, those are Quito, Cuenca and Guayaquil. They are interconnected using a telco E1 connection, full-data. They’re on separate private /24 blocks, but they see each other just fine.First of all, ask yourself if you really need to provide PBX service to each location. I mean, do you need to offer point-to-point communications even when the third party is down? But then, isn’t your E1 connection a single point of failure? You need to decide this before deciding to offer local PBX services, since it’s obviously cheaper to maintain just one PBX. And if you only need one PBX, then you might also stop reading.That said, the advantages of providing a local PBX are:

  • Faster response for applications such as voicemail, directory, IVRs et al.
  • Ability to take profit of local PSTN connections, for example, an existing FXO
  • In case of failure of one site, you can communicate the others, provided the communication channel is stil there
  • Administration becomes delegable if your setup is big enough to justify local admins

If you want to take advantage of having a local PBX, then you’ll create the local extensions in the local PBX. Let’s assume that Alice and Bob work on Cuenca, so they have their extensions 100 and 101 created there. Mallory works on Guayaquil, so he’s 200 in the local PBX and Charlie is 300 on Quito. So, go ahead and use FreePBX to create the SIP extensions on each PBX!Next step is to create IAX2 trunks. IAX exists to interconnect Asterisk PBXs. To our eyes, using IAX instead of SIP or whatever means we get full semantics on signalling among the PBXs, no headaches with caller IDs, channel usage et al. So, the process is a bit creepy on FreePBX, we need to go to Basic -> Trunks, Add IAX2 Trunk and define PEER and USER details. So basically we should interchange the information from PEER on one side to USER on the other side, fill the blanks so you get something like:

PEER details:

USER details:

USER details:

PEER details:


Set meaningful names for Trunk name and USER context, since those would be useful later. Right now you have local PBX services, and IAX trunks among the PBXs, but they’re not aware neither of the existence of more extensions on the other side, nor the dial rules to get there. Here we go with Outbound routes.You should create n-1 trunks and n-1 routes for any n-PBX Asterisk setup. Go ahead and create two outbound routes on each of your PBXs, using the prefix for each location, for example 1xx for Cuenca, 2xx for Guayaquil and 3xx for Quito. The ‘xx’ thingy has a special meaning on Asterisk’s dialplan, check FreePBX’s online help for details, but using ‘Nxx’ where N is the prefix for each location should do just fine. For each outbound route select the matching trunk.Great, you can now dial 2xx from Cuenca or Quito and you should get to Guayaquil via the IAX trunks. The only issue is that, when you have a respectable amount of extensions, you need to centralize your extensions directory. If you don’t use an LDAP directory, which you should do, you’ll run into problems when provisioning the personal directory to your users.So, finally, FreePBX has this thingy called “Custom Extensions” which you can create as a regular extension and after you do that you can assign a dial rule for that. So, instead of CUSTOM/XXX as the dial rule, use IAX2/foo-peer/XXX. Be advised that by setting this up this way, your whole work with outbound routes is useless, and you have to create the extension in all PBXes, but this is easily solved using LDAP.Alright, so that’s it. You now have multiple Asterisk PBXes, local service on each site, IAX2 trunks among them, calling routes active for all your extensions and some scenarios for ‘centralized’ extension management. Check my other posts under the Asterisk tag for more Asterisk awesomeness.

Ditching PCI cards in Asterisk for fun and profit

In the past, I’ve used PCI cards providing telephony TDM for my Asterisk-based projects. I’ve only worked with Digium’s FXO/FXS and T1/E1 cards, both in PCI and PCI-x formats, until a client asked for a gateway solution with FXO, FXS and E1, where using the PCI cards in a 1U IPBX was simply out of the question.Using Etheet gateways has always been a problem in those cases, since entry-to-medium level solutions lack the processing power for massive call handling, and signalling is poor, making the architecture unfit for reporting purposes and specialized apps such as call centers. But hey, that’s my experience with gateways.Therefore, I looked into Xorcom’s Astribank. They pack FXO, FXS and PRI/BRI ports inside a convenient 19″ 1U case, which can connect to an Asterisk-based IPBX server via USB and gets recognized as an integral DAHDI device in mode setups.So I ordered a composite 8xFXO, 8xFXS and 1xE1 PRI from Astribank, labelled XR0072. Getting the equipment from Arizona to Florida was easy, and since I worked with DHL, getting it to Guayaquil in Ecuador was a breeze (next-day delivery) but passing customs is, as always in Latin America, a time-consuming operation. After paying 12.5% taxes and then some for DHL operations, and 15 days waiting, I got the equipment in Quito.To my surprise, the Astribank was extremely light and small, slightly near 3 Kg in 1U form factor and under 1/4 depth in the rack. While it had a rack-mounting kit, which I used, it could also rest securely over my IPBX without rack screws.My Astribank uses a single USB cable to connect to the “master” PBX — it could also be connected to a secondary PBX and provide a fault tolerant setup. It also depends on a DC supply, which they included. Since I was using a mode Debian, with a mode Asterisk with already-compiled mode DAHDI (formerly called Zapata/Zaptel) drivers, I just connected the equipment via USB to the IPBX, issued an invoke-rc.d dahdi restart and we were good to go.Note: you do need the fxload package in Debian for firmware loading to the Astribank. And for “good to go” I mean you can check the registered spans with dahdi_registration and, as soon as you connect the E1 cable that comes from the CPE to the CPE port (which in my XR0072 is the first on the lower row for PRI) you get an OK status with dahdi_tool. Also note that I use an E1/CPE port, which is the default for the Astribank, otherwise I’d have to set the XPP_PRI_SETUP variable as indicated on the User Manual.DAHDI insists on configuring a crc4 parameter for the detected spans, which I needed to remove and restart DAHDI so the equipment could ‘sync’ with the CPE (that is, the box that the telco provided, with the balun and the crossover RJ45 cable) and avoid some nasty noise issues on the line, that also occur with Digium’s Wildcard for PRI.

usb:008/005          xpp_usb+     e4e4:1162 Astribank-modular FPGA-firmware LABEL=[usb:...]       CONNECTOR=@usb-0000:00:1d.7-1         XBUS-00/XPD-00: E1       (31)  Span 1  DAHDI-SYNC        XBUS-00/XPD-10: FXS      (8)   Span 2         XBUS-00/XPD-20: FXO      (8)   Span 3

Using DAHDI’s dahdi_genconf command writes an /etc/asterisk/dahdi-channels.conf file with the group and channel configuration as detected by DAHDI. It should be included by the chan_dahdi.conf file, which, in my case, is not necessary since I only wanted to enable one DAHDI group (DAHDI/g0) with my 31 E1 channels (1-15,17-31)

group=0context=from-pstnchannel => 1-15,17-31

That means that when I want to use the FXO/FXS ports, it’d probably be easier to include the dahdi-channels.conf (FXS ports, for example, belong to a different context, from-inteal) so I don’t have to type more than my laziness permits.I also found that, in my setup, some Asterisk parameters were superfluous, such as the switchtype (either national or euroisdn work, and the former is the default) or the echo-cancelling stuff, so I assume Astribank’s doing a great job in negotiating that with the CPE. Do take note, however, that in my case the CPE needed to be cold-restarted so I could get an ‘Up’ status in Asterisk (pri show spans) and that my only non-default, channel related configuration in chan_dahdi.conf is signalling=pri_cpe.So far, so good. I’m really happy with the Astribank and I can fully understand how useful it is in terms of price (quite competitive in comparison with traditional cards, specially when bought from resellers -like me-), size/weight and functionality/ease of setup and administration. Kudos!

Brief notes on Asterisk and Cisco SPA5xx phones

Sipura, then Linksys, then Cisco, makes beautiful SIP phones. Under the new “Cisco Small Business Pro” line, Cisco sells the SPA5xx phones, which have great interaction with an Asterisk IPBX.

There’s an official, supported method for zero-touch configuration of SPA5xx phones with Asterisk. You need, of course, access to the DHCP server, the TFTP server and the IPBX. In my case, there’s no such thing as zero-touch since my client works on a separate VLAN, which I need to manually input on the phone. Of course, I could also send the phones a bogus configuration file stating the new VLAN, they’ll reboot and voila.

Anyway, as with any Cisco phone, this configuration file is an ugly XML one, but it’s a flat-profile on SPA5xx phones, so you can use awk, grep, sed and whatever without XML parsing if you need to build yours.

Better yet, you can get a “sample” XML configuration file by calling a GET method on the embedded web server of the SPA5xx phones, say:


Once you have this file, it’s just a matter of substituting the needed variables. Here’s a brief provision script which finds for #TAGS# inside a demo XML file:


using, say:

<Station_Name group="Phone/General">#STATIONNAME#</Station_Name><Short_Name_1_ group="Phone/Line_Key_1">#SHORTNAME#</Short_Name_1_><Display_Name_1_ group="Ext_1/Subscriber_Information">#DISPLAYNAME#</Display_Name_1_><User_ID_1_ group="Ext_1/Subscriber_Information">#EXTENSION#</User_ID_1_>

Of course, files need to be named spa$MAC.xml, be located on /var/lib/tftpboot/xml, or wherever your TFTP server desires to serve the files under an xml/ directory, or where the spa502G.cfg file says. I could remotely configure a dynamic LDAP directory, feature codes, dial plans, remote syslog and codec information using these XML files. But you can also write an static Directory using GET and POST (it’s called “Personal Directory”) automatically if you use FreePBX, see this code.

Ah, just call /admin/restart on each phone to reboot the phones. If you are now bitten by the beauty of standards-compliant, well documented SPA5xx phones, the resources under MyCiscoCommunity will be of great help. Look for the Asterisk Zero Touch Configuration Guide, the Provisioning Guide and the Admin Guide.