You are on page 1of 10

Asterisk Primer

History

You're probably reading this because you're confused. That's OK. It's (unfortunately) perfectly normal. You've no doubt noticed that there is a lot of information about Asterisk everywhere and that trying to get a handle on it is frustrating and may seem near impossible right now. Relax. Take a deep breath. It's really not that complicated to understand. A particular Asterisk (or OpenPBX) install can get pretty complex, but we don't care about that right now. This document will not tell you how to set up a call center with branches in different countries. This document will not tell you how to forward your ex-girlfriends number to a mental health hotline. All I want to do here is show you the very, very basics. This is something that I think has been missing from the Asterisk community, and I don't really know why. You may want to know who I am. I'm just this guy, you know? I've been a Linux user since Linus sent his message to usenet in '91 (I was a TA for a COBOL class at Purdue (CS 130) with a guy named Ian Murdock and we "discovered" Linux together.) I've been dabbling with Asterisk on and off for a few years. I've recently built my first "real" system and wanted to write some of this stuff down in the hopes that it'll help somebody. This whole paragraph was just for the name drop. Also, as you advance past this document (think of this as a bootstrap) you'll learn that I've lied to you repeatedly. It's for your own good and you'll thank me later. Advanced users who spot the lies now: why are you reading this? Go away. :p Preamble out of the way and delusions of grandeur properly squashed: let's get started. I suppose the first thing you need to know is what Asterisk is. No history lesson here, folks, you know where it came from, that's the first thing in every tutorial. Mark Spencer, spirit of Linux, blah, blah, blah. Not to diminish the contribution, but we don't really care right now. We just want to get moving, right? Here's the secret that seems to get lost in the noise: Asterisk connects telephones together. That's pretty much it. It can connect a telephone to an IVR (interactive voice response think "press 1 to hear a monkey screech, press 2 to insult the President...) or it can connect a telephone to another telephone. It can connect a traditional copper line to a SIP phone over your LAN, or over the Internet. But the thing to keep in mind is that it connects telephones to telephones. Another thing you need to know is that to connect to the "traditional" telco you're going

to need hardware. You can use an Asterisk box to connect to a VoIP provider with no additional hardware at all, but if you want to interface with an analog phone line or digital lines on a T1, E1 or PRI you're going to need some hardware. I think this is the subject that most people are confused about, so I'm going to spend quite a bit of effort trying to explain this stuff. It's really not that hard, but most people are completely unfamiliar with it, which makes it pretty difficult since you have to start from scratch. First, however, let's back up just a little bit. I'm going to simplify this as much as possible. In a basic Asterisk install you have: 1) lines (such as analog phone lines) 2) an Asterisk box 3) extensions (such as a soft phone running on your laptop)

As you can see, very basic. Asterisk will listen for calls from the outside world and then connect them to an extension, or listen for calls from an extension and connect them to the outside world. Or connect from extension to extension and not involve the outside world at all. No two situations are the same, but this is the very, very basic model for all setups. You may have to connect analog phone lines, or a T1 or PRI or VoIP or whatever, but this model takes all of that into account. Because no two situations are the same, at this point we have to start splitting things up into bite sized manageable chunks. We'll work outside in, starting with "lines."

As mentioned briefly, "lines" are what connect your Asterisk machine to the outside world. To review, a line can be a VoIP trunk, one or more analog lines (also called "trunks") or digital multiplexed lines such as a T1 or PRI. A VoIP line requires no hardware other than the Asterisk machine itself, a network card and an Internet connection. You'll set up the trunk in the Asterisk config files with the username and password assigned to you by your provider. Your extensions will then be able to use that line to call out. That's all I'm going to say about that, because there are already a million tutorials about how to hook Asterisk up to your Vonage account or whatever. An analog line from the outside world is where things start to get confusing. You will need a card that will take the analog line and make it usable with Asterisk. Cards such as the Sangoma A200 (Remora) and the Digium TDM400P and TDM2400P series. You can also use devices called analog adapters which are usually SIP based and are probably a good solution for home users and hobbyists. There are two "types" of lines when it comes to these analog cards. You will see "FXS" and "FXO" and, yes, I do believe that the telco engineers who came up with those terms were trying to be intentionally obtuse. Get used to that, 'cause it happens all over the telco industry. I digress.

FXS is "foreign exchange station." FXS lines are what you would use to connect an analog phone or other analog device to your Asterisk box. If you wanted to hook up a fax machine you'd need an FXS port. If you wanted to hook your existing house phones up you'd need at least one FXS port. (You can hook them all up to one FXS port and have them all ring at the same time like they do now, or you can have one extension per FSX port and ring the extensions separately.) FXO is foreign exchange office. This is the part that provides "dial tone" to your Asterisk

box. This is the part that will let you call the outside world. If you have one phone line you will need one FXO port. If you have two lines, two FXO ports. Anything over 8 analog lines and you should probably start looking at a PRI or fractional PRI. More on that later. Let's talk for a bit about the commonly available cards you can use for analog connections.

You will be tempted to use an X100p. Don't. Let's get this out of the way. Do not use an X100P for anything but testing. Buy one off ebay, don't spend more than $20. You'll soon learn that it's a piece of shit, but it's good enough to test with. The problems you'll have: 1) it will not hang up the line when the remote end hangs up. This means your line will be busy forever or until you hang it up yourself. 2) the quality is horrible. Pops, buzzes, echo, all kinds of garbage. 3) the reliability is bad. You will lose calls. All that being said, some people will read this and think "I bet it won't do that to me." It will. Don't. Use. It.

Digium TDM2400P Schematic Example

Amphenol Connectors The Digium TDM2400P is a "high density" card, taking only one slot for up to 24 lines. It's also pretty expensive and out of the reach of most hobbyists. It has what's called an "Amphenol" connector on the back of it, you use that to break out into individual twisted pair lines. The 2400P, like the other Digium analog cards, is modular. Meaning you can mix and match FXO and FXS modules on the card to meet your needs. The 2400P uses 4 port modules, in contrast to the 400P that uses single line modules. As the name may suggest, you can have up to 24 lines total on the card, in any configuration of FXS and FXO you desire, as long as the numbers are multiples of four. Use this card if you have a lot of analog devices such as fax machines, or if you want to hook up traditional analog phones in a lot of places. As mentioned previously, if you're stocking this with a bunch of FXO modules, please look into getting a PRI circuit. It may save you money and will be much more flexible. The 2400P has an echo cancellation option. Again, more on this later.

Digium TDM400P Schematic Example The Digium TDM400P is a four port card that accepts individual modules. This is a good choice for a home user or very small business that only has a few lines. You can do any combination of FXO and FXS on this card you desire. I've never had more than one of these at a time, but I've heard some people say that multiples are fine and others say that multiples are horrible. Sorry, that's the nature of these things. As far as I know the 400P does not have an echo cancellation option.

Sangoma A200 Remora Schematic Example The Sangoma A200 is another analog card. It can do up to 24 ports as well, but you need to have six slots available to do it because each four ports takes a slot. Note that only one actual PCI slot is used, but the extra ports still take up a slot on the back of the PC case. The A200 is modular too, but the modularity is kind of weird. The physical set up is you have four ports per card, each card has two two port modules and you can have up to six cards per "unit," giving you a total of 24 ports possible. I'm using this card in my production unit in an all FXS configuration with 8 total ports. This card is a good choice for a small business as well, but the amount of space it takes up is a drawback. The 2400P might be a better choice if you need to make more slots available. Hey Sangoma: make a breakout box.

Example setup: ATA with FXS and FXO Ports

Example setup: One ATA with an FXS port and another with an FXO port. In addition to cards you physically install in a PC, you can also get what is known as an "ATA." ATA stands for "Analog Telephony Adapter." These are simply one or more FXO and/or FXS ports on a stand alone piece of network hardware that then presents that port as a SIP device that you can then hook up to your Asterisk box. A combo box such as (I just Googled this, it's not an endorsement) the Zoom 5801 ATA would probably work well for a simple home Asterisk install. It has both ports so you can plug your home line into the FXO port, your house wiring into the FXS port and you now have an Asterisk system. To that you can add one or two VoIP lines and some SIP extensions, but I'm getting ahead of myself. The ATAs are available in many configurations, with single ports to multiple ports, combos and everything in between. They've come down in price quite a bit and second hand ones are available on ebay. If you Google some combination of "fxs fxo ata" you'll find quite a few things to take a look at. Digital cards. This is where the fun stuff is. Digital cards connect your Asterisk box to a T1, E1, PRI or other digital line. Digium makes many models. The main differences being: echo cancellation, number of ports and slot voltage. You can get anywhere from 1 to 4 port cards. I can't help you with the slot voltage, I don't get why they'd make different cards when it's perfectly possible to auto-detect. I bought a Sangoma card because I wasn't sure what machine I was going to install the card into for the finished project, so I didn't want to back myself into a corner. That being said, I'm sure their cards work just fine. Sangoma makes several cards too, but their echo cancellation offerings don't kick in until you get up to the A104D. So no EC if you want a one or two port Sangoma card. The digital cards all work in pretty much the same way. You have so many "channels" per port that you can use however you want. Quick primer on digital telephony:

Every time I say T1 you can read "T1 and E1" they're very similar, the main difference being that the E1 carries more channels (32 instead of 24.) Seeing as I am a fat and lazy American I'll concentrate on the T1 bit. A T1 is a carrier that can carry multiplexed data and voice. It can be configured in two ways, as what most people call a T1, 24 channels or as an ISDN PRI circuit, which is 23 b (or bearer) channels and a d (or data) channel. There is always overhead with a channel. Things need to happen, like set up, tear down and the like. With a "T1" all this happens inside the channel, which is why it's known as "robbed bit signaling." The 64K channels will carry only 56K after the overhead is accounted for. It's also much less flexible than a PRI circuit. A PRI reserves a channel to handle all the signaling, freeing the bearer channels to just do the work. That lets you do stuff like DID (also known as DDI) signaling and the like much easier than on a T1. (An E1 PRI is very similar, but has the d channel in the "middle" and, again, carries more channels.) What does this mean to you as a potential *-hole? Well, each channel will carry a conversation (we'll ignore the data for the purposes of this document.) They become the "lines" we talked about before. You can have a whole 23 channel PRI (don't use a robbed bit T1, it's silly) or a fractionalized PRI with less. My company currently has 16 PRI channels. You can bundle PRIs together, so you can have one data channel take care of much more than 23 b channels.

PRI Example Configuration

TODO: expand section on digital telephony? Finally, I wanted to write just a bit about extensions. Extensions can be hardware SIP phones, software SIP phones, software IAX phones (I think there may even be hardware IAX phones now), and analog phones. I'm probably missing something, but I think you get the idea. My suggestion would be to start out with one of the free IAX or SIP software phones while you're testing, then you can add hardware phones later if you want. IDEFisk which uses IAX is one I've used, as is X-Lite which uses SIP. That should be enough to get you started. There are many other tutorials you can read for more detail and that discuss more complex subjects. That's not what this was for. If you're still confused, or if you think there's something that could be addressed, feel free to drop me a line or edit this page. Try to keep the style consistent, and don't expand it too much, that would defeat the purpose. Clarity is key and dumb humor doesn't hurt. Here are a couple Asterisk design examples, built using the knowledge we've gained above. If you don't understand these, that's OK, they're just here as examples. You'll eventually understand them.

A more complex example with a PRI circuit.

A more complex example with inbound analog lines.

You might also like