Asterisk & Call Manager Express Integration.

Posted: Sunday, November 17, 2013 by Mahmoud Ramadan Ali in Labels:

-In this article I’ll go over how to build a SIP Trunk between Asterisk and CISCO Call Manager Express(CME) to allow Full-Duplex communication between both of them.

-To achieve this kind of setup (Toll-bypass) you need to configure CME to register with Asterisk as a SIP-User Agent (SIP-UA) also you must configure Asterisk to register with CME for Full-Duplex connectivity.

Configure a trunk from CME to Asterisk:
Enable SIP and allow SIP to SIP connections:
-Very simple, we just enable the SIP protocol and configure CME bridge SIP connections.
CME(config)#voice service voip
CME(conf-voi-serv)#allow-connections sip to sip
Configure G711alaw/G711ulaw Codec voice class:
-Usually you will use the G729 Codec over the WAN but unfortunately it's NOT enabled by default on Asterisk so to avoid Codec mismatch it's recommend to use at least one common Codec.
-Asterisk has a native support for G711alaw/G711ulaw Codec so you need to configure a voice class for these Codec to be negotiated with Asterisk.
CME(config)#voice class codec 1
CME(config-class)#codec preference 1 g711ulaw
CME(config-class)#codec preference 2 g711alaw
Configure a SIP Dial-Peer pointing to Asterisk:
-Configure a Dial-Peer pointing to Asterisk using SIP also configure the Codecs that will be negotiated over the trunk using the Codec voice class created at the previous step.
-The "dtmf-relay" command allows you to define how to relay the Dtmf-Tones.

CME(config)#dial-peer voice 1 voip
CME(config-dial-peer)#destination-pattern .T
CME(config-dial-peer)#session protocol sipv2
CME(config-dial-peer)#session target ipv4:
CME(config-dial-peer)#voice-class codec 1
CME(config-dial-peer)#dtmf-relay sip-notify rtp-nte
CME(config-dial-peer)#no shut

Configure a SIP-User Agent (SIP-UA) Account to register with Asterisk:
-Configure CME to act as a SIP-UA and set the account username/password that will be used to register with the Asterisk Server.
-Both of the "credentials" and the "authentication" commands are using different authentication standard to authenticate the same account.
-The "register" command gives you the ability to specify " Registration Timeout Retry Timer ".
-The "sip-server" command allows you to define the SIP port number used on the SIP server.This is useful only if you are using custom SIP port number on your Asterisk server which is NOT recommended.
-The "keepalive" command Sets the time interval between sending Options message requests when the SIP server is active or down.
CME(config-sip-ua)#credentials username CMEUSER password CMEPASS realm
CME(config-sip-ua)#authentication username CMEUSER password CMEPASS
CME(config-sip-ua)#registrar ipv4: expires 3600
CME(config-sip-ua)#sip-server ipv4:
CME(config-sip-ua)#keepalive target ipv4:
On Asterisk configure a SIP account to be used by CME to register it's SIP-UA account.
-Now CME will try to register with Asterisk using the SIP-UA account but it will fail since there is NO SIP account configured on Asterisk for successful registration.
-In the FreePBX GUI:Go to "Connectivity">"Trunk">"Add SIP Trunk" and configure the "Outgoing Settings" as follows.

Verify the SIP-UA registration on CME and Asterisk. 
-Use the " Show sip-ua registration status " command on CME to verify the registration process.
CME#sh sip-ua register status
Line          peer           expires(sec)  registered
============  =============  ============  ===========
CMEUSER       -1               2745          yes
-Use the " sip show users " command on Asterisk to verify the registration process.
Asterisk*CLI> sip show users
Username                   Secret           Accountcode      Def.Context      ACL  ForcerPort
CMEUSER                    CMEPASS                           from-trunk-sip-  No   Yes

Tip:The order of the configuration is critical.The SIP DP should be configured before the SIP-UA to trigger the CME registration.

Configure a trunk from Asterisk to CME:
-This step covers the configuration required to register Asterisk with CME.
-The configuration includes configuring CME as a registrar server to accept incoming SIP registration requests and creating the account that will be used by Asterisk to register with CME.
Configure CME as a registrar server and define the VOIP interface.
-Use the "sip" command to enable the SIP protocol.This should be done before to enable the SIP-UA client on CME.
-Use the "bind" command to define the VOIP interface used for both of SIP signaling and media processing.
-Use the "registrar server" command to enable CME to act as a registrar server and process incoming registration requests on it's VOIP interface.
CME(config)#voice service voip
CME(conf-voi-serv)# sip
CME(conf-serv-sip)#bind all source-interface fastEthernet 0/0
CME(conf-serv-sip)#registrar server
Configure the "max-dn" and the "max-pool".
-Configure the maximum DN and the maximum pool number that CME can provision.
CME(config)#voice register global
CME(config-register-global)#max-dn 2
CME(config-register-global)#max-pool 2
Configure the pool ID.
-The "id" will be the Asterisk IP Address.
Notice: For the SIP registrar server to identify the SIP endpoints by IP Address it should NOT be configured in CME mode.
CME(config)#voice register pool 1
CME(config-register-pool)# id ip
Configure the account that will be used by Asterisk to register with CME.
-Next configure the credentials that will be used by Asterisk to login and register with asterisk.
Tip:The "Username" MUST be a number just not to receive an "Invalid destination-pattern" error message when Asterisk tries to register.
CME(config)#username 12345 password 0 ASTERISKPASS
In the FreePBX GUI edit the trunk configuration by adding the register string in form of "Username:Password@IP Address".
verify Asterisk registration on Asterisk and CME.
-Use the “sip show registry" on Asterisk to verify the registration process.
Asterisk*CLI> sip show registry
Host                                    dnsmgr Username       Refresh State                Reg.Time                      N      12345              105 Registered           Sun, 17 Nov 2013 07:47:21
1 SIP registrations.
-Use the “sh voice register pool 1" on CME to verify the registration process.
CME#sh voice register pool 1
Pool Tag 1
  Ip address is, Mask is
  Proxy Ip address is
  DTMF Relay is disabled
  kpml signal is enabled
  Active registrations  : 1
  Total Registration Statistics
    Registration requests  : 3
    Registration success   : 3
    Registration failed    : 0
    unRegister requests    : 2
    unRegister success     : 2
    unRegister failed      : 0
Verify the entire configuration in the FreePBX GUI.
-The "IP Trunk Online" represents the incoming trunk from CME to Asterisk.
-The "IP Trunk Registrations" represents the outgoing trunk from Asterisk to CME .
Summary:As you see the configuration process can be summarized in two stages. First,configure CME as a SIP-UA to register with Asterisk. Second,Configure Asterisk to register with CME and authenticate using the account that you configure in the global configuration mode.This account will be used as a service account to authorize Asterisk to register with CME.