Asterisk 1.8 to 16

About 10 years ago, our company had a station without sip support and the first Asterisk 1.6 was connected via PRI streams. Subsequently, I wanted redirects with number substitution and category management, and chan_ss7 from netfors was found, which, after filing with a file, could do it all. Time passed and PJSIP came out in version 13 of Aterisk, and chan_ss7 was only compiled under 1.8. And periodically, once every six months, there were problems with interruptions, which manifested themselves in the disappearing voice. They appeared and passed by themselves.



The main station was replaced and learned sip and it was decided to upgrade Asterisk to 16.



The installation was carried out on clean debian 10. The repositories have version 16.2.1, so we will build from sources. Download the latest Asterisk 16, I had it on 16.12.0:



cd /usr/src
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-16-current.tar.gz


Unpack it into a folder and go to it:



tar xzvf asterisk-16-current.tar.gz
cd asterisk-16.*


Now let's install all the required dependencies in debian. There is no need to iterate over them manually. All dependencies are collected in a script that needs to be run.



contrib/scripts/install_prereq install


Next, download the mp3 sources, which are needed to build the mp3 module.



contrib/scripts/get_mp3_source.sh


All dependencies are installed and you can proceed to the assembly.



./configure
make menuselect


To what is installed by default, I add:



  • On the first tab, format_mp3.
  • In Core Sound Packages, I indicate Russian RU-WAV sounds.
  • In Extras Sound Packages I choose English EN-WAV, unfortunately there is no Russian.


Continue after accepting the settings by clicking on Save & Exit. Compile:



./configure
make


Then let's build and install the package using checkinstall:



checkinstall


We fill in the version, package name, etc. I write the package name asterisk-16 so that it does not conflict with the one in the repositories.



checkinstall


Add a user to run Asterisk and grant folder permissions:



adduser --system --group --home /var/lib/asterisk --no-create-home --gecos "Asterisk" asterisk
usermod -a -G dialout,audio asterisk
chown -R asterisk: /var/{lib,log,run,spool}/asterisk /usr/lib/asterisk /etc/asterisk


We configure Asterisk to run under this user. To do this, add parameters to the / etc / default / asterisk config:



AST_USER="asterisk"
AST_GROUP="asterisk"


After editing /etc/asterisk/modules.conf. We remove unnecessary things, for example:



noload => chan_sip.so


We start asterisk in the console and check that there are no errors:



asterisk -cvvv


If everything is fine, then add the service to startup and run:



systemctl enable asterisk
systemctl start asterisk


This completes the installation and proceed to setting up.



In PJSIP, the syntax has radically changed and it will not work just to copy the config. There is a config converter in the source folder contrib / scripts / sip_to_pjsip / sip_to_pjsip.py, but the format with separate aor, identify, etc. not convenient and an output was found with pjsip_wizard. We just need to create a transport in /etc/asterisk/pjsip.conf add:



[transport-udp]
type = transport
protocol = udp
bind = x.x.x.x
external_media_address = x.x.x.x
external_signaling_address = x.x.x.x


Change xxxx to the IP address on which you will listen.



We create a template for the user:



[main-template](!)
type=wizard
transport=transport-udp
accepts_auth = yes
accepts_registrations = yes
aor/qualify_frequency = 100
aor/max_contacts = 1
aor/remove_existing = yes
inbound_auth/auth_type = userpass
endpoint/disallow = all
endpoint/allow = alaw
endpoint/dtmf_mode = rfc4733
endpoint/deny = 0.0.0.0/0
endpoint/context = city_out
endpoint/direct_media = no
endpoint/device_state_busy_at = 1
endpoint/language = ru
endpoint/sdp_session = MySDp


And then an ordinary user will already have a config:



[100](main-template)
endpoint/permit=192.168.100.1
inbound_auth/username=100
inbound_auth/password=P@$$Word123
endpoint/callerid='' <100>


And this is already very similar to the chan_sip format, and we change the names of the parameters in the editor by replacing the words.



For clients behind nat, instead of nat = yes, we will make a hotel template with the addition of lines:



endpoint/rtp_symmetric=yes
endpoint/force_rport=yes
endpoint/rewrite_contact=yes


For pjsip to behave like chan_sip, i.e. add one peer one device. Some Chinese phones sometimes send for some reason a second registration from another port when the first one is valid and this allows you to bypass this bug.



aor/max_contacts = 1
aor/remove_existing = yes


One of the features of PJSIP is multiple registration, which was not supported in chan_sip. Change aor / max_contacts to the required amount and call in the dialplan:



exten => _XXX,1,Dial(${PJSIP_DIAL_CONTACTS(${EXTEN})})


It has become very convenient that you can specify interception groups by name, and not by numbers as before:



endpoint/named_call_group = aveks
endpoint/named_pickup_group = aveks


The old chan_sip had a call-limit parameter that limited the number of peer conversations. The new chan_pjsip does not have this, in all chats it is recommended to limit calls by the GROUP parameter. For some reason, nowhere in the manuals does it use the endpoint / device_state_busy_at parameter and add it to extensions.conf to the incoming and outgoing context:



exten => _X.,1,GoSub(subDeviceBusy,s,1(${EXTEN},${CALLERID(num)}))
[subDeviceBusy]
exten => s,1,NoOp(PJSIP/${ARG1} has state ${DEVICE_STATE(PJSIP/${ARG1})})
exten => s,n,NoOp(CallerId is ${ARG2})
exten => s,n,ExecIf($["${DEVICE_STATE(PJSIP/${ARG1})}" = "BUSY"]?Hangup(17))
exten => s,n,Return


You can view the lines in the Asterisk console:



pjsip show endpoint 100
Endpoint:  100/100                                      Not in use    0 of 1
     InAuth:  100-iauth/100
        Aor:  100                                            3
      Contact:  100/sip:100@192.168.0.10:5062       c34b4c2d4d Avail         7.981
  Transport:  transport-udp             udp      0      0  192.168.0.1:5060


Here 0 of 1 shows how many lines are busy from possible.



In 16 Asterisk macros became obsolete so they had to be rewritten on Gosub.



In order to transmit the caller's number when calling, add the Diversion header to INVITE when calling:



exten => 2222222,n,Dial(PJSIP/8XXXXXXXXXX@trunk,,tTb(add_diversion^${EXTEN}^1)
[add_diversion]
exten => _XXXXXXX,1,Set(PJSIP_HEADER(add,Diversion)=<sip:XXX${EXTEN}@x.x.x.x>\;reason=unconditional\;screen=yes\;privacy=off)
exten => _XXXXXXX,n,Return()


Here, 2222222 is the city number on which the forwarding is, 8XXXXXXXXXX is the number to which the forwarding is and, if necessary, add the area code instead of XXX sip: XXX $ {EXTEN} @xxxx>



There were no particular problems with the queue configuration files, we only change members from SIP to PJSIP.



Don't forget to use the documentation

pjsip_wizard.conf

pjsip.conf



All Articles