Asterisk Kamailio integration

Hello All,

I am working to get Kamilio server as Proxy server with using 2 Asterisk as Voip servers.

The situation is that I connected a SIP phone to the Kamilio server and dispatching calls to Asterisk are going well in the direction to Asterisk but as soon I want to call the SIP phone back it does not work.

I have configured a Kamilio server as dispatcher:

route(DISPATCHER);

route[DISPATCHER] {

round robin dispatching on gateways group ‘1’

if(!ds_select_dst(“1”, “4”))
{
send_reply(“404”, “No destination”);
exit;
}
xlog(“ —— DISPATCH: going to <$ru> via <$du>n");
route(RELAY);
exit;
}

Created 2 dispatcher gateway:

kamctl dispatcher addgw 1 sip:10.2.11.120:5060
kamctl dispatcher addgw 1 sip:10.2.11.121:5060

Registered a SIP phone:

kamctl add 1001 1001

On the Asterisk in SIP.config
[1001]
type=friend
host=dynamic
secret=1001
context=000003
port=5060
insecure=invite
qualify=yes
disallow=all
allow=alaw
allow=ulaw
canreinvite=no

extensions.conf

[000003]
exten => _X!,1,Dial(SIP/outgoingworld/${EXTEN},180)
exten => _X!,2,Hangup

Till so far it works fine, the SIP phone is dispatched to Asterisk via Kamilio and I can call the rest off the world.

For calls to the SIP phone I have configured a channel to Kamilio:
SIP.config

[kamilio]
type=friend
host=172.16.1.94
port=5060
insecure=invite
qualify=yes

in extensions.config
exten => _X!,1,Dial(SIP/Kamailio/1001,180)

I get an ans ware back: congestion

I think that the reasson of this is that Kamailio want to dispatch back because I needed to change the kamailio.cfg

replace #route(PSTN);
new code:

route(DISPATCHER);

Any idea how to fix this

I have a small update:

As soon I disable: #route(DISPATCHER); and enable route(PSTN);
I am able to make calls Kamilio and the SIP phone is reachable nut the SIP phone will not be dispatched any more to the Asterisk servers…

Probaply I need to change somewhere in the Kamilio.cfg that the route(DISPATCHER); is active when ??? and enable route(PSTN); for when Asterisk is attempting the Kamailio

I have add the following code to Kamailio, it’s dispatching to asterisk but still not accept calls from Asterisk to the ATA/SIP phone, I think I need need to change something in th code like, IF THE CALLS COMMING FROM AN ASTERISK SERVER, DONT RUN THIS CODE.

please any idea?

if (is_method(“INVITE”)) {
ds_select_dst(“1”,“4”);
sl_send_reply(“100”,“Trying”);
forward();
exit();
}

I have found the solution: .

Put this in front of the Dialplan code:
meaning is, when a host dispatchers calls handle the call normal.

if(ds_is_from_list()) {

route(LOCATION);
}