Using Asterisk as a PSTN Gateway for OpenSER

by Flavio E. Goncalves | June 2008 | Linux Servers Networking & Telephony Open Source

PSTN or Public Switched Telephone Network is the collection of all the telephone networks, which are interconnected in the world. If we want to be able to route calls from and to the PSTN using OpenSER, we need to be connected to a PSTN. To send calls to the PSTN, we need a device called PSTN gateway. There are several manufacturers such as Cisco, Nortel, and others who manufacture this kind of equipment. You can also use an Asterisk PBX box for this task. Asterisk makes an affordable PSTN gateway that is very competitive with the big players mentioned above. In this article by Flavio E. Goncalves, we will see how to use asterisk as a PSTN gateway for OpenSER.

Using Asterisk as a PSTN Gateway

Step 1: Add the gateway address in the trusted table using SerMyAdmin:

Using Asterisk as a PSTN Gateway for OpenSER

If desired or convenient, you can instead use the MySQL command line interface to achieve the same result.

#mysql –u openser –p
-- enter your mysql password --
mysql> use openser;
mysql> INSERT INTO trusted ( src_ip, proto, from_pattern )
VALUES ( '10.1.30.22', 'any', '^sip:.*$');

The records above tell the OpenSER script to allow requests coming from the IP address 10.1.30.22 with any transport protocol, matching the regular expression ^sip:.*$. You can use the following command if you don't want to reload OpenSER.

#openserctl fifo trusted_reload

Step 2: Include your served domains in the domain table (if you have not done before).

openserctl domain add sermyadmin.org

You can also use SerMyAdmin to do this.

Using Asterisk as a PSTN Gateway for OpenSER

Step 3: Include the user into the groups (local, ld, and int):

#openserctl acl grant 1000@sermyadmin.org local
#openserctl acl grant 1000@sermyadmin.org ld
#openserctl acl grant 1000@sermyadmin.org int
#openserctl acl grant 1001@sermyadmin.org local

To use SerMyAdmin, just go to the screen below:

Using Asterisk as a PSTN Gateway for OpenSER

Step 4: Configuring Asterisk as a gateway.

Two very popular gateways for OpenSER are Asterisk and Cisco AS5300. Gateways from other manufacturers can be used too; check their documentation for instructions. Let's see how to configure a Cisco 2601 with two FXO interfaces and an Asterisk with an E1 PSTN card.

Warning
It is important to prevent the direct sending of SIP packets to gateways. The SIP proxy should be in front of the gateway and a firewall should prevent users from sending SIP requests directly to the gateway.

Step 5: Setting up the Asterisk Server or the Cisco Gateway.

We will assume that the PSTN side of the Asterisk gateway is already configured. Now let's change the SIP configuration (sip.conf) of our gateway and its dial plan (extensions.conf). We will configure Asterisk to send to the proxy each call coming from the PSTN and vice versa. We are using the guest feature of the SIP channel on the Asterisk Server. Prior knowledge of Asterisk is required here. Below is the simplest configuration allowing Asterisk to communicate with OpenSER. Please, adapt this script to your topology.

Warning
Allow SIP packets to your asterisk server, coming only from your SIP server. Do not allow SIP packets coming from other destinations. You can use IP Tables to do this, consult a Linux security specialist, if you are
in doubt.

Asterisk Gateway (sip.conf)

[general]
context=sipincoming
#calls incoming from the SIP proxy to be terminated in the PSTN lines
[sipproxy]
#calls incoming from the PSTN to be forwarded to clients behind the SIP
#proxy
type=peer
host=10.1.30.22
Asterisk (extensions.conf)
[general]
[globals]
[sipincoming]
exten=>_[0-9].,1,Dial(Zap/g1/${EXTEN:1})
exten=>_[0-9].,2,hangup()
[sipoutgoing]
# If you have a digital interface use the lines below
exten=_[0-9].,1,Answer()
exten=_[0-9].,2,dial(SIP/${EXTEN}@sipproxy)
exten=_[0-9].,3,Hangup()
#If you have analog FXO interfaces use the lines below.
exten=s,1,Answer()
exten=s,2,dial(SIP/${EXTEN}@sipproxy)
exten=s,3,Hangup()

Cisco 2601 Gateway

The following explanation could help, but prior knowledge of Cisco gateways is required to complete this configuration. The call routing on Cisco gateways is done by the instruction dial peer. Any call with the number called starting with 9 followed by any number (9T) is forwarded to the PSTN on the ports 1/0 or 1/1 as instructed by the dial peer voice 1 and 2 POTS lines (plain old telephone system). Called numbers starting from 1 to 9 with any number of digits following will be directed to the SIP proxy in the IP address 10.1.3.22 as instructed in the 'dial-peer voice 123 voip' line.

voice class codec 1
codec preference 2 g711ulaw
!
interface Ethernet0/0
ip address 10.1.30.38 255.255.0.0
half-duplex
!
ip classless
ip route 0.0.0.0 0.0.0.0 10.1.0.1
no ip http server
ip pim bidir-enable
!
voice-port 1/0
!
voice-port 1/1
!
mgcp profile default
!
! The dial-peer pots commands will handle the calls coming from SIP
!dial-peers. Any call matching 9 followed by any number of digits will
be !forwarded to the PSTN with the 9 striped.
dial-peer voice 1 pots
destination-pattern 9T
port 1/0
!
dial-peer voice 2 pots
destination-pattern 9T
port1/1
!
!The dial-peer voip commands will handle the calls coming from the
pots !dial peers (PSTN). You can prefix a number (80 in this example)
and send the DID number ahead.
!
dial-peer voice 123 voip
destination-pattern ....T
prefix80
forward all
session protocol sipv2
session target ipv4:10.1.30.22
dtmf-relay sip-notify

Step 6: Test the configuration making and receiving calls.

Summary

In this article, we have seen how to configure and use the Cisco 2601 gateway and the Asterisk gateway for OpenSER to send calls to the PSTN.

If you have read this article you may be interested to view :

Building Telephony Systems with OpenSER A step-by-step guide to building a high performance Telephony System
Published: April 2008
eBook Price: $26.99
Book Price: $44.99
See more
Select your format and quantity:

About the Author :


Flavio E. Goncalves was born in 1966 in Minas Gerais, Brazil. Having always had a strong interest in computers, he got his first personal computer in 1983 and since then it has been almost an addiction. He received his degree in Engineering in 1989 with focus in computer aided design and computer aided manufacturing. He is also CEO of V.Office Networks in Brazil, a consulting company dedicated to the areas of Networks, Security, Telecom, and Operating Systems and a training center since its foundation in 1996. Since 1993, he has participated in a series of certification programs having being certificated as Novell MCNE/MCNI, Microsoft MCSE/MCT, Cisco CCSP/CCNP/CCDP, Asterisk dCAP, and some other.

He started writing about open-source software because he thinks the way certification programs were organized in the past was very good to help learners. Some books today are written by strictly technical people, who, sometimes, do not have a clear idea on how people learn. He tried to use his 15-year experience as instructor to help people learn open-source telephony software. His experience with networks, protocol analyzers, and IP telephony, combined with his teaching skills, gave him an edge to write this book. This is the second book he has written; the first one was The Configuration Guide for Asterisk PBX. As the CEO of V.Office, Flavio E. Goncalves balances his time between family, work, and fun. He is the father of two children and lives in Florianopolis, Brazil, in his opinion one of the most beautiful places in the world. He dedicates his free time to water sports such as surfing and sailing.

You can contact him at flavio@asteriskguide.com, or visit his website www.asteriskguide.com.

Books From Packt

trixbox CE 2.6
trixbox CE 2.6

Lighttpd
Lighttpd

Learning jQuery 1.3
Learning jQuery 1.3

Learning Nagios 3.0
Learning Nagios 3.0

Learning FreeNAS
Learning FreeNAS

Spring 2.5 Aspect Oriented Programming
Spring 2.5 Aspect Oriented Programming

Linux Thin Client Networks Design and Deployment
Linux Thin Client Networks Design and Deployment

Asterisk Gateway Interface 1.4 and 1.6 Programming
Asterisk Gateway Interface 1.4 and 1.6 Programming


 

 

Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software