[Home]

Summary:ASTERISK-08160: IAX2 trunking not enabled in one direction for 'user' rather than 'friend'
Reporter:Brian Candler (candlerb)Labels:
Date Opened:2006-11-21 03:47:35.000-0600Date Closed:2011-06-07 14:07:53
Priority:MinorRegression?No
Status:Closed/CompleteComponents:Channels/chan_iax2
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) asterisk1-conf.tgz
( 1) asterisk2-conf.tgz
Description:Consider the following setup for combining SIP calls into an IAX2 trunk and then breaking them back out again as SIP.

SIP ATA ----->               IAX2                 ------> SIP provider
SIP ATA -----> Asterisk1 =============> Asterisk2 ------> SIP provider
SIP ATA ----->                                    ------> SIP provider

192.168.   192.168.  10.69.         10.69.
1.x        1.1       255.245        255.251

The configuration (defined below) only needs to permit outbound calls. So the SIP ATAs do not register with Asterisk1, Asterisk1 does not register with Asterisk2, and Asterisk2 does not register with the SIP provider.

In this scenario, audio is trunked in one direction only. Running tcpdump on the IAX2 link when two G729 calls are in progress shows:

15:53:33.364129 IP 10.69.255.245.4569 > 10.69.255.251.4569: UDP, length 60
15:53:33.368300 IP 10.69.255.251.4569 > 10.69.255.245.4569: UDP, length 24
15:53:33.372985 IP 10.69.255.251.4569 > 10.69.255.245.4569: UDP, length 24
15:53:33.384124 IP 10.69.255.245.4569 > 10.69.255.251.4569: UDP, length 60
15:53:33.388250 IP 10.69.255.251.4569 > 10.69.255.245.4569: UDP, length 24
15:53:33.392928 IP 10.69.255.251.4569 > 10.69.255.245.4569: UDP, length 24
15:53:33.404125 IP 10.69.255.245.4569 > 10.69.255.251.4569: UDP, length 60
15:53:33.408715 IP 10.69.255.251.4569 > 10.69.255.245.4569: UDP, length 24
15:53:33.412851 IP 10.69.255.251.4569 > 10.69.255.245.4569: UDP, length 24

However, if I modify the setup so that Asterisk1 registers with Asterisk2, then it works, and audio is trunked both ways (all packets UDP payload length 60). So I believe there is some wrong logic when checking for the IAX_TRUNK flag.

How to replicate
================

My test rig is as follows.

Asterisk1 is 1.2.13. My device is actually rather esoteric: it's an Asus WL500g Deluxe running OpenWrt WhiteRussian RC6 (kernel 2.4.30), Asterisk binaries from http://zandbelt.dyndns.org/asterisk.html and using ztdummy + usb-uhci as the timing source. However, this side works. As you can see from the tcpdump it's combining the RTP streams into a single trunked packet. You should be able to substitute any Asterisk server with a zaptel timing source.

Asterisk2 is SVN trunk r47654, running under CentOS 4.4. The machine has a real Digium TDM400P as its timing source. I know this works because trunking can be made to work under some circumstances, as described later.

Configuration files - Asterisk1
===============================

-------------------- sip.conf ------------------
; This is purposely an "insecure" configuration which allows any SIP user
; to place outbound calls through us without authentication!
[general]
context=outbound
allowexternaldomains=yes
bindport=5060
bindaddr=192.168.1.1
disallow=all
allow=g729
allow=gsm

-------------------- iax.conf ------------------
[general]
bandwidth=low
allow=g729
allow=gsm
tos=lowdelay
autokill=yes
jitterbuffer=no
forcejitterbuffer=no
trunktimestamps=yes

[upstream]
type=peer
username=venue
secret=PPPPPPPP
auth=md5
host=10.69.255.251
qualify=yes
trunk=yes

-------------------- extensions.conf -----------
[general]
autofallthrough=no

[outbound]
exten => _X.,1,Dial(iax2/upstream/${EXTEN},45)

Configuration files - Asterisk2
===============================

-------------------- sip.conf ------------------
[general]
context=default
canreinvite=no
srvlookup=yes
disallow=all
allow=g729
allow=gsm

[authentication]

[sipgate-out]
type=peer
host=sipgate.co.uk
username=NNNNNNN
secret=XXXXXXXX
fromuser=NNNNNNN
fromdomain=sipgate.co.uk
insecure=invite

-------------------- iax.conf ------------------
[general]
bandwidth=low
disallow=lpc10
allow=g729
allow=gsm
tos=ef
autokill=yes
jitterbuffer=no
forcejitterbuffer=no
trunktimestamps=yes
trunk=yes

[venue]
type=user
secret=PPPPPPPP
auth=md5
context=outbound
qualify=yes
trunk=yes

-------------------- extensions.conf -----------
[general]
autofallthrough=no

[outbound]
exten => _X.,1,Dial(SIP/${EXTEN}@sipgate-out,45)

Replicating the problem
=======================

You need two or more SIP devices to place an outbound call via Asterisk1. The only configuration needed is to set the SIP proxy to Asterisk1's IP; you don't even need to set a username and password.

When this happens, and you run tcpdump on the IAX2 link, you see that packets from Asterisk1->Asterisk2 are trunked, but packets from Asterisk2->Asterisk1 are not trunked.

Workaround
==========

The problem goes away if you modify the configuration so that Asterisk1 registers with Asterisk2.

PATCH TO ASTERISK1:

--- iax.conf.orig       2006-11-21 09:31:52.000000000 +0000
+++ iax.conf    2006-11-21 09:31:52.000000000 +0000
@@ -1,4 +1,5 @@
[general]
+register=>venue:PPPPPPPP@10.69.255.251
bandwidth=low
allow=g729
allow=gsm

PATCH TO ASTERISK2:

--- iax.conf.orig       2006-11-21 09:29:25.000000000 +0000
+++ iax.conf    2006-11-21 09:29:13.000000000 +0000
@@ -11,7 +11,9 @@
trunk=yes

[venue]
-type=user
+;type=user
+type=friend
+host=dynamic
secret=xyzzy
auth=md5
context=outbound

tcpdump now shows 50pps and UDP payload size 60 bytes in both directions.

However, I don't think this should be required. If I understand correctly, registration is a function of locating a device for placing inbound calls, and should not affect the processing of outbound calls.

[In my particular scenario, I want to have multiple 'Asterisk1' machines in a hub-and-spoke arrangement, and to keep things simple I want them all to use the same IAX2 'user' entry on Asterisk2. If they all have to register then they will need separate entries.]


****** ADDITIONAL INFORMATION ******

I have not tested this with Asterisk2 running 1.2.13
Comments:By: Brian Candler (candlerb) 2006-11-21 06:52:42.000-0600

The ASCII diagram didn't come out very well. Let me try again on a single line:

SIP ATA(xN) ---> Asterisk1 ====(IAX2)===> Asterisk2 -----> SIP provider (N calls)

That is:
* A number of separate SIP ATAs all send INVITEs to Asterisk1
* Asterisk1 connects these calls via IAX2 to Asterisk2
* Asterisk2 connects each call as a separate SIP call to an upstream provider

By: Brian Candler (candlerb) 2006-11-22 03:54:43.000-0600

I have now retested this with asterisk2 running 1.2.13. I get the same results, namely:

* If asterisk1 doesn't register with asterisk2, but places calls as a "user", then the audio from asterisk2 to asterisk1 is not trunked.

* If asterisk1 registers to asterisk2 as a "friend", trunking works fine.

So:

[iaxuser]
type=user
...
trunk=yes    << this setting is not being honoured.

Regards, Brian.

By: Joshua C. Colp (jcolp) 2006-11-22 12:00:06.000-0600

Can we see the total iax.conf involved plus the dial line? Thanks.

By: Joshua C. Colp (jcolp) 2006-11-22 12:00:44.000-0600

Sorry, didn't see it before.

By: Brian Candler (candlerb) 2006-11-22 12:11:06.000-0600

The files pasted in the 'Description' section are the complete files.

The only other files in /etc/asterisk/ are asterisk.conf, modules.conf and logger.conf, which are the default files. All other files have been moved to /etc/asterisk/samples/

By: Joshua C. Colp (jcolp) 2006-11-22 12:17:25.000-0600

I've tried to lab this up using as many different versions as I can and every time it works... so let's turn up debugging!

Go into logger.conf and add debug to the list that will be outputted to the console. Then once Asterisk is started up do core set debug 9 on trunk, or set debug 9 on 1.4/1.2 and see if it says it created a trunk peer. Thanks.

By: Brian Candler (candlerb) 2006-11-22 13:41:46.000-0600

I presume you mean to do this on asterisk2 in the diagram above - the one which takes IAX2 calls and turns them into SIP. OK, I've done this on the box which is running SVN Trunk. (For historical reasons, this machine identifies itself as 'asterisk1' so please don't be confused by this!)

asterisk1*CLI> core set debug 9
Core debug was 0 and is now 9
asterisk1*CLI> iax2 reload
 == Parsing '/etc/asterisk/iax.conf': [Nov 22 19:34:34] DEBUG[17906]: config.c:841 config_text_file_load: Parsing /etc/asterisk/iax.conf
Found
 == Loaded firmware 'iaxy.bin'
[Nov 22 19:34:34] NOTICE[17906]: iax2-provision.c:518 iax_provision_reload: No IAX provisioning configuration found, IAX provisioning disabled.
asterisk1*CLI>

That's all I see. Remember that (a) the other machine is a user, not a peer, and (b) the other machine does not register to this one.

I'm doing this remotely at the moment, so unfortunately I don't have a way to pick up a phone and place a call. All I can show is:

asterisk1*CLI> iax2 show peers
Name/Username    Host                 Mask             Port          Status
0 iax2 peers [0 online, 0 offline, 0 unmonitored]
asterisk1*CLI> iax2 show users
Username         Secret                Authen           Def.Context      A/C Codec Pref
venue            PPPPPPPP              000000000000002  outbound         No Host

Just to confirm: on your 'asterisk2' box you have defined asterisk1 as a user, not a peer or friend?

Regards,

Brian.

By: Joshua C. Colp (jcolp) 2006-11-22 13:44:12.000-0600

It is a user yes, and you'll have to place a call to see this information and don't forget to modify logger.conf and do logger reload to see the debug output. It creates a trunk peer on the first call if trunking is enabled and correctly detected. All subsequent calls find the same trunk peer that was created on the first call and use it. Once the last call ends, the trunk peer goes away. All this shows up under core debug.

By: Brian Candler (candlerb) 2006-11-22 14:34:21.000-0600

OK - will do tomorrow morning. Thanks.

By: Brian Candler (candlerb) 2006-11-23 03:08:27.000-0600

OK. To make life simpler I added the following to extensions.conf on the 'asterisk2' machine:

exten => 160,1,Answer()
exten => 160,2,Playback(/var/lib/asterisk/moh/fpm-world-mix)
exten => 160,3,Playback(/var/lib/asterisk/moh/fpm-sunshine)
exten => 160,4,Playback(/var/lib/asterisk/moh/rpm-calm-river)
exten => 160,5,Wait(3)
exten => 160,6,Goto(2)

Now here's what I see when I dial 160 from one of the SIP phones, i.e. SIP phone -(SIP)-> Asterisk1 -(IAX2)-> Asterisk2

asterisk1*CLI> core set debug 9
Core debug is at least 9
asterisk1*CLI> iax2 reload
 == Parsing '/etc/asterisk/iax.conf': [Nov 23 09:01:34] DEBUG[19562]: config.c:841 config_text_file_load: Parsing /etc/asterisk/iax.conf
Found
 == Loaded firmware 'iaxy.bin'
[Nov 23 09:01:34] NOTICE[19562]: iax2-provision.c:518 iax_provision_reload: No IAX provisioning configuration found, IAX provisioning disabled.
   -- Accepting AUTHENTICATED call from 10.69.255.245:
      > requested format = g729,
      > requested prefs = (g729|gsm),
      > actual format = g729,
      > host prefs = (g729|gsm),
      > priority = mine
[Nov 23 09:01:47] DEBUG[19563]: pbx.c:1685 pbx_extension_helper: Launching 'Answer'
   -- Executing [160@outbound:1] Answer("IAX2/10.69.255.245:4569-1", "") in new stack
[Nov 23 09:01:47] DEBUG[19563]: chan_iax2.c:3190 iax2_answer: Answering IAX2 call
[Nov 23 09:01:47] DEBUG[19563]: devicestate.c:303 __ast_device_state_changed_literal: Notification of state change to be queued on device/channel IAX2/10.69.255.245:4569-1
[Nov 23 09:01:47] DEBUG[14234]: devicestate.c:161 ast_device_state: No provider found, checking channel drivers for IAX2 - 10.69.255.245:4569
[Nov 23 09:01:47] DEBUG[14234]: chan_iax2.c:9592 iax2_devicestate: Checking device state for device 10.69.255.245
[Nov 23 09:01:47] DEBUG[14234]: devicestate.c:287 do_state_change: Changing state for IAX2/10.69.255.245:4569 - state 4 (Invalid)
[Nov 23 09:01:47] DEBUG[19563]: pbx.c:1685 pbx_extension_helper: Launching 'Playback'
   -- Executing [160@outbound:2] Playback("IAX2/10.69.255.245:4569-1", "/var/lib/asterisk/moh/fpm-world-mix") in new stack
[Nov 23 09:01:47] DEBUG[19563]: channel.c:2735 set_format: Set channel IAX2/10.69.255.245:4569-1 to write format slin
[Nov 23 09:01:47] DEBUG[19563]: channel.c:1907 ast_settimeout: Scheduling timer at 160 sample intervals
   -- Playing '/var/lib/asterisk/moh/fpm-world-mix' (language 'en')
[Nov 23 09:01:47] DEBUG[14244]: chan_iax2.c:6642 socket_process: Ooh, voice format changed to 256
[Nov 23 09:01:47] DEBUG[14244]: channel.c:2735 set_format: Set channel IAX2/10.69.255.245:4569-1 to read format g729
[Nov 23 09:01:47] DEBUG[14246]: chan_iax2.c:3549 find_tpeer: Created trunk peer for '10.69.255.245:4569'
asterisk1*CLI>

'tcpdump -i eth0 -n udp' now shows:
09:05:04.904828 IP 10.69.255.251.4569 > 10.69.255.245.4569: UDP, length 24
09:05:04.910675 IP 10.69.255.245.4569 > 10.69.255.251.4569: UDP, length 34
09:05:04.924821 IP 10.69.255.251.4569 > 10.69.255.245.4569: UDP, length 24
09:05:04.930675 IP 10.69.255.245.4569 > 10.69.255.251.4569: UDP, length 34
09:05:04.944864 IP 10.69.255.251.4569 > 10.69.255.245.4569: UDP, length 24
09:05:04.950675 IP 10.69.255.245.4569 > 10.69.255.251.4569: UDP, length 34

And then when I place a second call from a second SIP phone:

   -- Accepting AUTHENTICATED call from 10.69.255.245:
      > requested format = g729,
      > requested prefs = (g729|gsm),
      > actual format = g729,
      > host prefs = (g729|gsm),
      > priority = mine
[Nov 23 09:05:24] DEBUG[19574]: pbx.c:1685 pbx_extension_helper: Launching 'Answer'
   -- Executing [160@outbound:1] Answer("IAX2/10.69.255.245:4569-3", "") in new stack
[Nov 23 09:05:24] DEBUG[19574]: chan_iax2.c:3190 iax2_answer: Answering IAX2 call
[Nov 23 09:05:24] DEBUG[19574]: devicestate.c:303 __ast_device_state_changed_literal: Notification of state change to be queued on device/channel IAX2/10.69.255.245:4569-3
[Nov 23 09:05:24] DEBUG[19574]: pbx.c:1685 pbx_extension_helper: Launching 'Playback'
   -- Executing [160@outbound:2] Playback("IAX2/10.69.255.245:4569-3", "/var/lib/asterisk/moh/fpm-world-mix") in new stack
[Nov 23 09:05:24] DEBUG[19574]: channel.c:2735 set_format: Set channel IAX2/10.69.255.245:4569-3 to write format slin
[Nov 23 09:05:24] DEBUG[19574]: channel.c:1907 ast_settimeout: Scheduling timer at 160 sample intervals
   -- Playing '/var/lib/asterisk/moh/fpm-world-mix' (language 'en')
[Nov 23 09:05:24] DEBUG[14234]: devicestate.c:161 ast_device_state: No provider found, checking channel drivers for IAX2 - 10.69.255.245:4569
[Nov 23 09:05:24] DEBUG[14234]: chan_iax2.c:9592 iax2_devicestate: Checking device state for device 10.69.255.245
[Nov 23 09:05:24] DEBUG[14234]: devicestate.c:287 do_state_change: Changing state for IAX2/10.69.255.245:4569 - state 4 (Invalid)
[Nov 23 09:05:24] DEBUG[14245]: chan_iax2.c:6642 socket_process: Ooh, voice format changed to 256
[Nov 23 09:05:24] DEBUG[14245]: channel.c:2735 set_format: Set channel IAX2/10.69.255.245:4569-3 to read format g729

and the same tcpdump command now shows:

09:06:38.781418 IP 10.69.255.245.4569 > 10.69.255.251.4569: UDP, length 60
09:06:38.785627 IP 10.69.255.251.4569 > 10.69.255.245.4569: UDP, length 24
09:06:38.798594 IP 10.69.255.251.4569 > 10.69.255.245.4569: UDP, length 24
09:06:38.800911 IP 10.69.255.245.4569 > 10.69.255.251.4569: UDP, length 60
09:06:38.805629 IP 10.69.255.251.4569 > 10.69.255.245.4569: UDP, length 24
09:06:38.818631 IP 10.69.255.251.4569 > 10.69.255.245.4569: UDP, length 24
09:06:38.821004 IP 10.69.255.245.4569 > 10.69.255.251.4569: UDP, length 60
09:06:38.825601 IP 10.69.255.251.4569 > 10.69.255.245.4569: UDP, length 24
09:06:38.838631 IP 10.69.255.251.4569 > 10.69.255.245.4569: UDP, length 24

HTH, Brian.

By: Brian Candler (candlerb) 2006-11-23 03:41:51.000-0600

Hmm. Just to be sure, I actually stopped and restarted asterisk2, and then did the same test again. As before, I got a log message about a trunk peer being created:

...
[Nov 23 09:37:39] DEBUG[19887]: channel.c:2735 set_format: Set channel IAX2/10.69.255.245:4569-5 to read format g729
[Nov 23 09:37:39] DEBUG[19888]: chan_iax2.c:3549 find_tpeer: Created trunk peer for '10.69.255.245:4569'
asterisk1*CLI>

However, tcpdump still disagrees. With one call:

09:38:30.322876 IP 10.69.255.245.4569 > 10.69.255.251.4569: UDP, length 34
09:38:30.323249 IP 10.69.255.251.4569 > 10.69.255.245.4569: UDP, length 24
09:38:30.342880 IP 10.69.255.245.4569 > 10.69.255.251.4569: UDP, length 34
09:38:30.343251 IP 10.69.255.251.4569 > 10.69.255.245.4569: UDP, length 24
09:38:30.362878 IP 10.69.255.245.4569 > 10.69.255.251.4569: UDP, length 34
09:38:30.363242 IP 10.69.255.251.4569 > 10.69.255.245.4569: UDP, length 24

and two calls:

09:39:57.168923 IP 10.69.255.245.4569 > 10.69.255.251.4569: UDP, length 60
09:39:57.176996 IP 10.69.255.251.4569 > 10.69.255.245.4569: UDP, length 24
09:39:57.183946 IP 10.69.255.251.4569 > 10.69.255.245.4569: UDP, length 24
09:39:57.188917 IP 10.69.255.245.4569 > 10.69.255.251.4569: UDP, length 60
09:39:57.196949 IP 10.69.255.251.4569 > 10.69.255.245.4569: UDP, length 24
09:39:57.203946 IP 10.69.255.251.4569 > 10.69.255.245.4569: UDP, length 24



By: Brian Candler (candlerb) 2006-11-23 06:47:03.000-0600

I have tarred up *.conf from /etc/asterisk on both machines and uploaded. The only modification I did first was to blank out my sipgate account details in asterisk2's sip.conf

By: Serge Vecher (serge-v) 2007-02-22 15:59:08.000-0600

any changes with latest 1.4 / trunk?

By: Joshua C. Colp (jcolp) 2007-08-06 10:52:03

This is actually a configuration issue. You must have both a peer and a user when doing trunking, you can't just have a user.