Knowledge Center next icon How to integrate CM SIP trunk with Asterisk PBX
Apr 10, 2024
5 minutes read

How to integrate CM SIP trunk with Asterisk PBX

Integrations (PBX) toggle

Goal

A step by step guide to configure a Asterisk PBX for use with the CM SIP trunk.

Product

  • Voice

Steps

Main configuration

Along other configuration files (most likely located in /etc/asterisk/ on Debian systems), the most important files for configuring your system to work with the CM.com in- and outbound platforms are pjsip.conf and extensions.conf. Pjsip.conf contains all the details for connecting to and from our platforms, while extensions.conf describes your dialplan; what should Asterisk do when an inbound call arrives, and what to do for an outbound calls. First we will set up some default settings in pjsip.conf. Below you can find complete examples of both config files that should set you up 90% of the way for making and receiving your first call. If you want more information on the structure and elements of the pjsip.conf config file please visit the Asterisk documentation.

First we set some global parameters. Most of this is boilerplate, but can be adjust as per your wishes. Please refer to the official documentation for more information. The most important parameters to configure here are external_media_address and external_signalling_address. These parameters should be set to the public IP address of your Asterisk box. If you do not have one you will need one. This situation does not deal with NAT scenarios, though it might just work.

[global]
type=global
user_agent=Asterisk PBX
max_initial_qualify_time=5

[transport-udp]
type=transport
protocol=udp
bind=0.0.0.0
local_net=192.168.0.0/16
local_net=127.0.0.1/32
external_media_address=<EXTERNIP>
external_signaling_address=<EXTERNIP>

Now we will move on to some defaults. These endpoint, auth and aor can be used further down the config file. These will just set some defaults such that those won’t need repeating multiple times. You probably won’t need to change these, but feel free to consult the official documentation.

;DEFAULTS
[default-endpoint](!)
type=endpoint
transport=transport-udp
disallow=all
allow=g729
allow=alaw
allow=gsm
direct_media=no
force_rport=yes

[default-auth](!)
type=auth
auth_type=userpass

[default-aor](!)
type=aor
max_contacts=1
remove_existing=yes
qualify_frequency=120

Now that you have the basics, continue setting up our outbound trunks as your outbound endpoints.


Configuring outbound

First we will extend the default endpoint:

[cm](default-endpoint)
outbound_auth=cm
aors=cm

Next we need to ensure Asterisk knows how to authenticate with the CM.com platform. In the config below you will enter your SIP Account username and password. You can find these in the Voice Management App under the SIP Accounts menu option.

[cm](default-auth)
password=<PASSWORD>
username=<USERNAME>

Lastly, we need to tell pjsip.conf where to reach the CM.com platform:

[cm]
type=aor
contact=sip:nl.voip.cm.com:5060
qualify_frequency=60

Now the pjsip.conf configuration should be complete to make your first outbound call. We only need to create a dialplan extension. This is done in extensions.conf. Here we tell Asterisk what to do: send the call to CM.com.

[to-cm]
exten => _X.,1,NoOp(Oubound call from: ${CALLERID(all)} to: ${EXTEN})
same => n,Dial(PJSIP/${EXTEN}@cm)
same => n,Hangup()

A couple of important things are happening here. First of all the name of the context: [to-cm]. We need to remember this later on. Next we call the Dial-application. We supply that we want to use the PJSIP channel, along with the number we want to call (${EXTEN}) and that we want to use the endpoint cm. This will send an INVITE to the CM.com outbound platform when a call is dialed out via this context.

After reloading as described under “Reload asterisk”, we are ready to test. This can be done via the Asterisk CLI (asterisk -r) using the command:

dial <NUMBER YOU WANT TO DIAL>@to-cm

Do not forget to replace “<NUMBER YOU WANT TO DIAL>” with your number!

Configuring inbound

When using CM.com for inbound calling Asterisk needs to be configured to allow calls from the inbound endpoints. Additionally, an inbound endpoint needs to be configured. We first configure the endpoint, which we inherit from the default-endpoint we configured under the section “Main configuration”. For this endpoint we define the context parameter. This context is important, it is the part of the dialplan that is executed when an inbound call arrives from the CM.com platform to your Asterisk machine.

;CM Trunk inbound
[cminbound](default-endpoint)
context=from-cm

Next we will create an identify section in the context. This tells Asterisk to match all incoming requests from the CM.com inbound IP range to the cminbound endpoint.

[cminbound]type=identifyendpoint=cminboundmatch=188.94.184.0/23

Now your pjsip.conf configuration should be set up completely to receive inbound calls. Keep on reading below on how to set up extensions.conf in order to be able to receive inbound calls on your Asterisk machine; we still need to tell it what to do with those!

Responding to OPTIONS

For inbound traffic (CM.com → Customer) we do not support REGISTER. Instead we will just deliver calls without authentication to your Asterisk PBX. You can define your endpoints in the Voice Management App under “Distribution groups”. We send OPTIONS to your endpoints defined in the distribution group and we expect a 200 OK reply. If we do not get this reply we assume the endpoint to be down and unable to receive calls. As such, we won’t send it any calls. If all endpoints in a distribution group are down, we will reject the call and the number will be unreachable until we receive a successful response again.

By default Asterisk will not send a 200 OK in response to OPTIONS when not correctly configured. In order to make Asterisk send this reply we need to add a so-called “NoOp()” command in your extensions.conf. This command needs to be added to the default context for your CM.com inbound […]

For example, add the following line at the end of your inbound context if not already present:

exten =>  s,1,NoOp()

As an example we add the NoOp() command af the very top of our inbound context (as defined above in pjsip.conf) which is located in our extensions.conf:

;Inbound context[from-cm]exten => s,1,NoOp(Inbound call from: ${CALLERID(all)} to: ${EXTEN})same => n,Answer()same => n,Hangup()

This example will log a line, answer the call and hang up immediately. In case an OPTIONS request arrives, it will reply with a 200 OK. Note the [from-cm], the context name, which must match the context name defined in pjsip.conf for the [cminbound] endpoint. Do not forget to reload Asterisk as described under “Reload asterisk”.

Reload asterisk

After applying changes to the Asterisk config, Asterisk needs to be reloaded for the changes to take effect. If you have only changed something in extensions.conf the following command is sufficient:

dialplan reload

Either execute this command in the Asterisk CLI (opened by typing asterisk -r) or from your shell:

asterisk -rx ‘dialplan reload’

When you have changed something in other configuration files such as pjsip.conf you will need to execute either/or:

pjsip reloadcore reload

Restarting Asterisk completely is also an option to make sure the new config is used.

Example configurations

pjsip.conf

[global]
type=global
user_agent=Asterisk PBX
max_initial_qualify_time=5

[transport-udp]
type=transport
protocol=udp
bind=0.0.0.0
local_net=192.168.0.0/16
local_net=127.0.0.1/32
external_media_address=<EXTERNIP>
external_signaling_address=<EXTERNIP>

;DEFAULTS
[default-endpoint](!)
type=endpoint
transport=transport-udp
disallow=all
allow=g729
allow=alaw
allow=gsm
direct_media=no
force_rport=yes

[default-auth](!)
type=auth
auth_type=userpass

[default-aor](!)
type=aor
max_contacts=1
remove_existing=yes
qualify_frequency=120

[cm](default-endpoint)
outbound_auth=cm
aors=cm

[cm](default-auth)
password=<PASSWORD>
username=<USERNAME>

[cm]
type=aor
contact=sip:nl.voip.cm.com:5060
qualify_frequency=60

;CM Trunk inbound
[cminbound](default-endpoint)
context=from-cm

[cminbound]
type=identify
endpoint=cminbound
match=188.94.184.0/23

extensions.conf

;Outbound context
[to-cm]
exten => _X.,1,NoOp(Oubound call from: ${CALLERID(all)} to: ${EXTEN})
same => n,Dial(PJSIP/${EXTEN}@cm)
same => n,Hangup()

;Inbound context
[from-cm]
exten => s,1,NoOp(Inbound call from: ${CALLERID(all)} to: ${EXTEN})
same => n,Answer()
same => n,Hangup()

group icon
Get support

Can’t find the answer you are looking for?
Ask for the help of our chatbot, or get in touch with our support team.

Contact Support
Is this region a better fit for you?
Go
close icon