Asterisk 13 PJSIP sometime sounds works some time not

I recently set up my asterisk 13 with PJSIP and database. All working fine, but sometimes I get no voice, where most of the time I get a voice. So I need RTP software? following is detail log, I am looking but not found any voice or codec issue, as I set up codec to all, and this is local environment all local services, so there should not be any nat related issue but seem I have configured incorrect nat issue. I migrated and also notice the same issue in old sip servers too and I moved it on new due to this voice issue. So it is sure that it is not software issue, but must be configuration issue. Following is my log. note: I am newbie in PJSIP and it is my first PJSIP installation.

-- Executing [1567241111@default:1] AGI("PJSIP/192.168.56.103-00000004", "myagi.pl,0000FFFF0001,1567241111,,PJSIP/192.168.56.103-00000004,,1547882181.8") in new stack
-- Launched AGI Script /var/lib/asterisk/agi-bin/myagi.pl
<--- Transmitting SIP response (913 bytes) to UDP:192.168.56.103:5060 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.56.103:5060;received=192.168.56.103;branch=z9hG4bK08e608fd
Call-ID: 25918c527ec2200b25e99b862ff7ac80@192.168.56.103:5060
From: "vendorTest" <sip:0000FFFF0001@192.168.56.103>;tag=as7756e843
To: <sip:1567241111@192.168.56.102>;tag=1bf6a0d2-1c8b-431f-91c7-a074337a7b88
CSeq: 102 INVITE
Server: Asterisk PBX certified/13.21-cert3
Contact: <sip:192.168.56.102:5060>
Allow: OPTIONS, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, REGISTER, REFER, MESSAGE
Supported: 100rel, timer, replaces, norefersub
Content-Type: application/sdp
Content-Length:   288

v=0
o=- 2131651698 2131651700 IN IP4 192.168.56.102
s=Asterisk
c=IN IP4 192.168.56.102
t=0 0
m=audio 24874 RTP/AVP 0 8 3 101
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:3 GSM/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
a=maxptime:150
a=sendrecv

<--- Received SIP request (460 bytes) from UDP:192.168.56.103:5060 --->
ACK sip:192.168.56.102:5060 SIP/2.0
Via: SIP/2.0/UDP 192.168.56.103:5060;branch=z9hG4bK62ff354e
Max-Forwards: 70
From: "vendorTest" <sip:0000FFFF0001@192.168.56.103>;tag=as7756e843
To: <sip:1567241111@192.168.56.102>;tag=1bf6a0d2-1c8b-431f-91c7-a074337a7b88
Contact: <sip:0000FFFF0001@192.168.56.103:5060>
Call-ID: 25918c527ec2200b25e99b862ff7ac80@192.168.56.103:5060
CSeq: 102 ACK
User-Agent: Asterisk PBX 11.13.1~dfsg-2+deb8u5
Content-Length: 0

My PJSIP configuration calling peer

[192.168.56.103]
type = aor
contact = sip:192.168.56.103
maximum_expiration = 60
minimum_expiration = 60
default_expiration = 180

[192.168.56.103]
type = identify
endpoint = 192.168.56.103
match =  192.168.56.103

[192.168.56.103]
type = endpoint
context = default
dtmf_mode = rfc4733
disallow = all
allow =all
direct_media = yes
language = en
aors = 159.203.27.198
t38_udptl = yes
t38_udptl_ec = none
rtp_symmetric = yes
force_rport = no
rewrite_contact = yes
direct_media = no

My Servers

192.168.56.103 - Asterisk 13 with PJSIP  - call receiver
192.168.56.102 - Asterisk 11 with PJSIP - Caller

To make clear I have put voicemail so other part is actualy asterisk replying, normal it asks for password and it does 10 times but 2 times no voice? any idea where I am doing wrong. Should I install RTPengine or RTPProxy. This server will be on internet to provide voip calls and also register sip client,and my client will be public internet user, so they mostly be behind nat!

You would need to look at “rtp set debug on” and see where audio is going to and coming from. Have you double checked any firewall on the system to make sure it allows the RTP port range?

I disabled firewall, and still getting issue. Following is RTP set debug on log, actually when there is success-full sound, it is getting RTP packet, but when no success it is just sending and not receiving any packets.

Success log

Sent RTP packet to      192.168.56.103:24384 (type 00, seq 016771, ts 014240, len 000160)
    -- AGI Script Executing Application: (VoiceMailMain) Options: (15672489497@VPL)
    -- <PJSIP/192.168.56.103-00000004> Playing 'vm-password.ulaw' (language 'en')
    -- <PJSIP/192.168.56.103-00000004>AGI Script vplsaleem.pl completed, returning 4
  == Spawn extension (default, 15672489497, 1) exited non-zero on 'PJSIP/192.168.56.103-00000004'
  == Setting global variable 'SIPDOMAIN' to '192.168.56.102'
    -- Executing [15672489497@default:1] AGI("PJSIP/192.168.56.103-00000005", "vplsaleem.pl,0000FFFF0001,15672489497,,PJSIP/192.168.56.103-00000005,,1548073297.10") in new stack
    -- Launched AGI Script /var/lib/asterisk/agi-bin/vplsaleem.pl
Got  RTP packet from    192.168.56.103:25370 (type 00, seq 022381, ts 000136, len 000160)
    -- <PJSIP/192.168.56.103-00000005> Playing '/var/lib/asterisk/sounds/ivrfiles/INTRO_mondex123.com.slin' (escape_digits=123456789) (sample_offset 0) (language 'en')
Sent RTP packet to      192.168.56.103:25370 (type 00, seq 010622, ts 000160, len 000160)
Sent RTP packet to      192.168.56.103:25370 (type 00, seq 010623, ts 000320, len 000160)
Got  RTP packet from    192.168.56.103:25370 (type 00, seq 022382, ts 000296, len 000160)
Sent RTP packet to      192.168.56.103:25370 (type 00, seq 010624, ts 000480, len 000160)
Got  RTP packet from    192.168.56.103:25370 (type 00, seq 022383, ts 000456, len 000160)
Got  RTP packet from    192.168.56.103:25370 (type 00, seq 022384, ts 000616, len 000160)
Sent RTP packet to      192.168.56.103:25370 (type 00, seq 010625, ts 000640, len 000160)
Got  RTP packet from    192.168.56.103:25370 (type 00, seq 022385, ts 000776, len 000160)
Sent RTP packet to      192.168.56.103:25370 (type 00, seq 010626, ts 000800, len 000160)
Sent RTP packet to      192.168.56.103:25370 (type 00, seq 010627, ts 000960, len 000160)
Got  RTP packet from    192.168.56.103:25370 (type 00, seq 022386, ts 000936, len 000160)
Sent RTP packet to      192.168.56.103:25370 (type 00, seq 010628, ts 001120, len 000160)
Got  RTP packet from    192.168.56.103:25370 (type 00, seq 022387, ts 001096, len 000160)
Got  RTP packet from    192.168.56.103:25370 (type 00, seq 022388, ts 001256, len 000160)

Failed Log

Sent RTP packet to      192.168.56.103:17902 (type 00, seq 021527, ts 014880, len 000160)
    -- AGI Script Executing Application: (VoiceMailMain) Options: (15672489497@VPL)
    -- <PJSIP/192.168.56.103-00000003> Playing 'vm-password.ulaw' (language 'en')
    -- <PJSIP/192.168.56.103-00000003>AGI Script vplsaleem.pl completed, returning 4
  == Spawn extension (default, 15672489497, 1) exited non-zero on 'PJSIP/192.168.56.103-00000003'
  == Setting global variable 'SIPDOMAIN' to '192.168.56.102'
    -- Executing [15672489497@default:1] AGI("PJSIP/192.168.56.103-00000004", "vplsaleem.pl,0000FFFF0001,15672489497,,PJSIP/192.168.56.103-00000004,,1548073275.8") in new stack
    -- Launched AGI Script /var/lib/asterisk/agi-bin/vplsaleem.pl
    -- <PJSIP/192.168.56.103-00000004> Playing '/var/lib/asterisk/sounds/ivrfiles/INTRO_mondex123.com.slin' (escape_digits=123456789) (sample_offset 0) (language 'en')
Sent RTP packet to      192.168.56.103:24384 (type 00, seq 016683, ts 000160, len 000160)
Sent RTP packet to      192.168.56.103:24384 (type 00, seq 016684, ts 000320, len 000160)
Sent RTP packet to      192.168.56.103:24384 (type 00, seq 016685, ts 000480, len 000160)
Sent RTP packet to      192.168.56.103:24384 (type 00, seq 016686, ts 000640, len 000160)
Sent RTP packet to      192.168.56.103:24384 (type 00, seq 016687, ts 000800, len 000160)
Sent RTP packet to      192.168.56.103:24384 (type 00, seq 016688, ts 000960, len 000160)
Sent RTP packet to      192.168.56.103:24384 (type 00, seq 016689, ts 001120, len 000160)
Sent RTP packet to      192.168.56.103:24384 (type 00, seq 016690, ts 001280, len 000160)
Sent RTP packet to      192.168.56.103:24384 (type 00, seq 016691, ts 001440, len 000160)
Sent RTP packet to      192.168.56.103:24384 (type 00, seq 016692, ts 001600, len 000160)
Sent RTP packet to      192.168.56.103:24384 (type 00, seq 016693, ts 001760, len 000160)
Sent RTP packet to      192.168.56.103:24384 (type 00, seq 016694, ts 001920, len 000160)
Sent RTP packet to      192.168.56.103:24384 (type 00, seq 016695, ts 002080, len 000160)
Sent RTP packet to      192.168.56.103:24384 (type 00, seq 016696, ts 002240, len 000160)
Sent RTP packet to      192.168.56.103:24384 (type 00, seq 016697, ts 002400, len 000160)
Sent RTP packet to      192.168.56.103:24384 (type 00, seq 016698, ts 002560, len 000160)
Sent RTP packet to      192.168.56.103:24384 (type 00, seq 016699, ts 002720, len 000160)
Sent RTP packet to      192.168.56.103:24384 (type 00, seq 016700, ts 002880, len 000160)
Sent RTP packet to      192.168.56.103:24384 (type 00, seq 016701, ts 003040, len 000160)

I’d suggest doing packet captures outside of Asterisk then to see if traffic is still being dropped somewhere, or if the endpoint is the source of the problem in some way. There’s seemingly nothing wrong from an Asterisk perspective.

I used ngrep to capture.

on Failed voice

interface: enp0s3 (192.168.56.0/255.255.255.0)
filter: ( host 192.168.56.103 ) and ((ip || ip6) || (vlan && (ip || ip6)))

U 192.168.56.103:5060 -> 192.168.56.102:5060 #1
INVITE sip:15672489497@192.168.56.102 SIP/2.0.
Via: SIP/2.0/UDP 192.168.56.103:5060;branch=z9hG4bK61d0ec23.
Max-Forwards: 70.
From: "vendorTest" <sip:0000FFFF0001@192.168.56.103>;tag=as1a0bc36c.
To: <sip:15672489497@192.168.56.102>.
Contact: <sip:0000FFFF0001@192.168.56.103:5060>.
Call-ID: 1f8e93a5158699dd38053e68333ebcfd@192.168.56.103:5060.
CSeq: 102 INVITE.
User-Agent: Asterisk PBX 11.13.1~dfsg-2+deb8u5.
Date: Mon, 21 Jan 2019 12:28:29 GMT.
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE.
Supported: replaces, timer.
Content-Type: application/sdp.
Content-Length: 301.
.
v=0.
o=root 1157164229 1157164229 IN IP4 192.168.56.103.
s=Asterisk PBX 11.13.1~dfsg-2+deb8u5.
c=IN IP4 192.168.56.103.
t=0 0.
m=audio 19176 RTP/AVP 0 3 8 101.
a=rtpmap:0 PCMU/8000.
a=rtpmap:3 GSM/8000.
a=rtpmap:8 PCMA/8000.
a=rtpmap:101 telephone-event/8000.
a=fmtp:101 0-16.
a=ptime:20.
a=sendrecv.


U 192.168.56.102:5060 -> 192.168.56.103:5060 #2
SIP/2.0 100 Trying.
Via: SIP/2.0/UDP 192.168.56.103:5060;received=192.168.56.103;branch=z9hG4bK61d0ec23.
Call-ID: 1f8e93a5158699dd38053e68333ebcfd@192.168.56.103:5060.
From: "vendorTest" <sip:0000FFFF0001@192.168.56.103>;tag=as1a0bc36c.
To: <sip:15672489497@192.168.56.102>.
CSeq: 102 INVITE.
Server: Asterisk PBX certified/13.21-cert3.
Content-Length:  0.
.


U 192.168.56.102:5060 -> 192.168.56.103:5060 #3
SIP/2.0 200 OK.
Via: SIP/2.0/UDP 192.168.56.103:5060;received=192.168.56.103;branch=z9hG4bK61d0ec23.
Call-ID: 1f8e93a5158699dd38053e68333ebcfd@192.168.56.103:5060.
From: "vendorTest" <sip:0000FFFF0001@192.168.56.103>;tag=as1a0bc36c.
To: <sip:15672489497@192.168.56.102>;tag=c67c0ed3-38ed-4a16-8b63-b49957c7357b.
CSeq: 102 INVITE.
Server: Asterisk PBX certified/13.21-cert3.
Contact: <sip:192.168.56.102:5060>.
Allow: OPTIONS, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, REGISTER, REFER, MESSAGE.
Supported: 100rel, timer, replaces, norefersub.
Content-Type: application/sdp.
Content-Length:   288.
.
v=0.
o=- 1157164229 1157164231 IN IP4 192.168.56.102.
s=Asterisk.
c=IN IP4 192.168.56.102.
t=0 0.
m=audio 18332 RTP/AVP 0 8 3 101.
a=rtpmap:0 PCMU/8000.
a=rtpmap:8 PCMA/8000.
a=rtpmap:3 GSM/8000.
a=rtpmap:101 telephone-event/8000.
a=fmtp:101 0-16.
a=ptime:20.
a=maxptime:150.
a=sendrecv.


U 192.168.56.103:5060 -> 192.168.56.102:5060 #4
ACK sip:192.168.56.102:5060 SIP/2.0.
Via: SIP/2.0/UDP 192.168.56.103:5060;branch=z9hG4bK19eb1d31.
Max-Forwards: 70.
From: "vendorTest" <sip:0000FFFF0001@192.168.56.103>;tag=as1a0bc36c.
To: <sip:15672489497@192.168.56.102>;tag=c67c0ed3-38ed-4a16-8b63-b49957c7357b.
Contact: <sip:0000FFFF0001@192.168.56.103:5060>.
Call-ID: 1f8e93a5158699dd38053e68333ebcfd@192.168.56.103:5060.
CSeq: 102 ACK.
User-Agent: Asterisk PBX 11.13.1~dfsg-2+deb8u5.
Content-Length: 0.
U 192.168.56.102:18332 -> 192.168.56.103:19176 #5
..<G....:.o0.........................................~~.~..~...................................................~~~..........................................................

U 192.168.56.102:18332 -> 192.168.56.103:19176 #6
..<H...@:.o0...........~~~~~..~..~~~~~~~~~................................................................................~...............~...........~}~..}~..~~~...~......
....
....

and on success

interface: enp0s3 (192.168.56.0/255.255.255.0)
filter: ( host 192.168.56.103 ) and ((ip || ip6) || (vlan && (ip || ip6)))

U 192.168.56.103:5060 -> 192.168.56.102:5060 #1
INVITE sip:15672489497@192.168.56.102 SIP/2.0.
Via: SIP/2.0/UDP 192.168.56.103:5060;branch=z9hG4bK06e2ca75.
Max-Forwards: 70.
From: "vendorTest" <sip:0000FFFF0001@192.168.56.103>;tag=as36f4c2e2.
To: <sip:15672489497@192.168.56.102>.
Contact: <sip:0000FFFF0001@192.168.56.103:5060>.
Call-ID: 6faadd1b4c0f2fa136db0f83038632ba@192.168.56.103:5060.
CSeq: 102 INVITE.
User-Agent: Asterisk PBX 11.13.1~dfsg-2+deb8u5.
Date: Mon, 21 Jan 2019 12:32:23 GMT.
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE.
Supported: replaces, timer.
Content-Type: application/sdp.
Content-Length: 300.
.
v=0.
o=root 1870928973 1870928973 IN IP4 192.168.56.103.
s=Asterisk PBX 11.13.1~dfsg-2+deb8u5.
c=IN IP4 192.168.56.103.
t=0 0.
m=audio 7006 RTP/AVP 0 3 8 101.
a=rtpmap:0 PCMU/8000.
a=rtpmap:3 GSM/8000.
a=rtpmap:8 PCMA/8000.
a=rtpmap:101 telephone-event/8000.
a=fmtp:101 0-16.
a=ptime:20.
a=sendrecv.


U 192.168.56.102:5060 -> 192.168.56.103:5060 #2
SIP/2.0 100 Trying.
Via: SIP/2.0/UDP 192.168.56.103:5060;received=192.168.56.103;branch=z9hG4bK06e2ca75.
Call-ID: 6faadd1b4c0f2fa136db0f83038632ba@192.168.56.103:5060.
From: "vendorTest" <sip:0000FFFF0001@192.168.56.103>;tag=as36f4c2e2.
To: <sip:15672489497@192.168.56.102>.
CSeq: 102 INVITE.
Server: Asterisk PBX certified/13.21-cert3.
Content-Length:  0.
.


U 192.168.56.102:5060 -> 192.168.56.103:5060 #3
SIP/2.0 200 OK.
Via: SIP/2.0/UDP 192.168.56.103:5060;received=192.168.56.103;branch=z9hG4bK06e2ca75.
Call-ID: 6faadd1b4c0f2fa136db0f83038632ba@192.168.56.103:5060.
From: "vendorTest" <sip:0000FFFF0001@192.168.56.103>;tag=as36f4c2e2.
To: <sip:15672489497@192.168.56.102>;tag=3d4adb5f-5ba1-4777-96b5-bb20260d65b5.
CSeq: 102 INVITE.
Server: Asterisk PBX certified/13.21-cert3.
Contact: <sip:192.168.56.102:5060>.
Allow: OPTIONS, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, REGISTER, REFER, MESSAGE.
Supported: 100rel, timer, replaces, norefersub.
Content-Type: application/sdp.
Content-Length:   288.
.
v=0.
o=- 1870928973 1870928975 IN IP4 192.168.56.102.
s=Asterisk.
c=IN IP4 192.168.56.102.
t=0 0.
m=audio 19166 RTP/AVP 0 8 3 101.
a=rtpmap:0 PCMU/8000.
a=rtpmap:8 PCMA/8000.
a=rtpmap:3 GSM/8000.
a=rtpmap:101 telephone-event/8000.
a=fmtp:101 0-16.
a=ptime:20.
a=maxptime:150.
a=sendrecv.


U 192.168.56.103:5060 -> 192.168.56.102:5060 #4
ACK sip:192.168.56.102:5060 SIP/2.0.
Via: SIP/2.0/UDP 192.168.56.103:5060;branch=z9hG4bK6009956e.
Max-Forwards: 70.
From: "vendorTest" <sip:0000FFFF0001@192.168.56.103>;tag=as36f4c2e2.
To: <sip:15672489497@192.168.56.102>;tag=3d4adb5f-5ba1-4777-96b5-bb20260d65b5.
Contact: <sip:0000FFFF0001@192.168.56.103:5060>.
Call-ID: 6faadd1b4c0f2fa136db0f83038632ba@192.168.56.103:5060.
CSeq: 102 ACK.
User-Agent: Asterisk PBX 11.13.1~dfsg-2+deb8u5.
Content-Length: 0.
.


U 192.168.56.103:7006 -> 192.168.56.102:19166 #5
.......`/.s_..................................................~~.~~~~~~.~~.~~~..~~~~~..~.~~.~~.~~~.~....~.~.~.~~...~.~~...~.~~~~~~.~~...~~.~~~....~~.....~~.~.~~~~.~.~~~~.~.

U 192.168.56.102:19166 -> 192.168.56.103:7006 #6
...+....M.$..........................................~~.~..~...................................................~~~..........................................................

Dear Josh,
Wow it work, I have issue in my other server, as it was set from 10000-20000 where Asterisk 13 was sending more than or less than packets. so no response was coming bak.
I really appreciate that you forward me in right direction. Can you recommended what would be configuration of nat if my clients are behind nat and my server is on public ip.
Thank.

Your configuration already covers NAT:

rtp_symmetric = yes
force_rport = no
rewrite_contact = yes
direct_media = no

You may want to remove the “direct_media = yes” that is further up though in the same endpoint.

Dear Josh,
is there any way that I can bound asterisk to send RTP traffic on 10000-20000 ports only? as it is sending from 5000 to 35000 so I have to open all ports to keep communication.
I setup RTP configuration but it is not taking effect, when I do module reload it show that now port 10000-20000 is setup for RTP communication. But still it is sending at 5000+

Are you referring to the port it is sending TO? If so, Asterisk has no control over that - it is the responsibility of the remote endpoint to provide the port it wants media on.

Actually your SDP does show port 7006 in one case, so if rtp.conf has been updated to reflect the correct ports then I’d suggest restarting and if that doesnt’ fix it then I do not know. You are using an old unsupported version, so it may have had a problem.

Yes it is sending from 5000 to 35000 as defaults of RTP.conf I updated and restart but nothing work. Yes you are right I am using caller as old asteirsk 11 and received asterisk 13. But seem it is time to move on 15. Thank you for help.

Asterisk 15 is not supported for bug fixes, only security. The current supported versions along with dates is available on the wiki[1].

[1] https://wiki.asterisk.org/wiki/display/AST/Asterisk+Versions