한국어

소프트스위치

온누리070 플레이스토어 다운로드
    acrobits softphone
     온누리 070 카카오 프러스 친구추가온누리 070 카카오 프러스 친구추가친추
     카카오톡 채팅 상담 카카오톡 채팅 상담카톡
    
     라인상담
     라인으로 공유

     페북공유

   ◎위챗 : speedseoul


  
     PAYPAL
     
     PRICE
     

pixel.gif

    before pay call 0088 from app


http://saevolgo.blogspot.kr/2013/08/rtpproxy-revisited-kamailio-40.html



Wednesday, August 21, 2013

RTPproxy Revisited [Kamailio 4.0]

Time and again I see people getting stuck on RTPproxy integration with Kamailio. I recently got another opportunity to put RTPproxy in between the User Phones and Kamailio setup as depicted in the following diagram.



That is similar to what I've posted earlier on this topic. In this post I will try be more verbose and write each and every step I did to have RTPs flowing.

I assume you've a Kamailio installed and working and configurations file from Asipto Knowledge Base by Daniel and that there are TWO NICs configured with Public IP and Private IP as shown in the diagram above.

The important thing which I'm looking for from the configuration is the WITH_NAT tag. follow the code and see how the NAT is handled. route[NATMANAGE] is called at almost all important routes.

The overall idea is;

1- Install RTPproxy
2- Start RTPproxy in Bridged mode
3- Make Kamailio aware of multiple NICs
4- Add Private IP asterisks in dispatcher
5- Create a new route RTPPROXY to engage RTP-proxy whenever needed
6- Call in the RTPPROXY route in the NATMANAGE route.
7- Important Things to take care of.

So lets start following the steps.

1- Installing RTPproxy

root@Kamailio:~# cd /usr/src/
root@Kamailio:~# wget http://b2bua.org/chrome/site/rtpproxy-1.2.1.tar.gz
root@Kamailio:~# tar zxvf rtpproxy-1.2.1.tar.gz
root@Kamailio:~# cd rtpproxy-1.2.1/
root@Kamailio:~# ./configure
root@Kamailio:~# make
root@Kamailio:~# make install

Setup LSB script for RTP-proxy
root@Kamailio:~# cp debian/rtpproxy-default.ex /etc/default/rtpproxy
edit the default file and put in the parameters.
root@Kamailio:~# vim /etc/default/rtpproxy

2- Start RTPproxy in Bridged mode


DAEMON_OPTS="-F -s udp:127.0.0.1:7722 -l 77.66.55.44/192.168.1.244 -d DBUG:LOG_LOCAL0 -u root"

Save and Exit

root@Kamailio:~# cp debian/rtpproxy.init /etc/init.d/rtpproxy
root@Kamailio:~# chmod a+x /etc/init.d/rtpproxy

Open up the file

root@Kamailio:~# vim /etc/init.d/rtpproxy

see that the DAEMON field points to the file in /usr/bin/rtpproxy

DAEMON=/usr/bin/rtpproxy

Lets copy the RTPproxy binary to that location.

root@Kamailio:~# cp rtpproxy /usr/bin/rtpproxy

Start up RTPproxy

root@Kamailio:~# /etc/init.d/rtpproxy start

verify that rtpproxy is running and listening on the specified 7722 

root@Kamailio:~# netstat -pln | grep rtpp
udp        0      0 127.0.0.1:7722          0.0.0.0:*                           6554/rtpproxy
Thats all.

3- Making Kamailio aware of multiple NICs


Lets move on to step 3 involving Kamailio configurations.

root@Kamailio:~# vim /usr/local/etc/kamailio/kamailio.cfg

Insert the following line in global parameters section, just under where we define "listen=" or "port=" 

mhomed=1

That will ensure that Kamailio uses its Private IP to communicate with Asterisks on Private subnet. Don't forget this.

We also need to put this line on the top definitions of kamailio.cfg file so kamailio use the NAT functions.

#!define WITH_NAT

4- Adding Asterisks to dispatcher


Now Add Private IP asterisks in dispatcher: Follow my post on adding dispatcher to the plain configurations from here: http://saevolgo.blogspot.com/2011/11/how-to-increasing-voip-services.html

5- Writing some Kamailio routing logic for RTPPROXY

That was easy, now the real thing the addition of RTPPROXY route which I modified a little bit from the last link mentioned.

To have the code working I have used the SQLOPS module configured to query kamailio.dispatcher table as the AVPOPS module was already busy.

NOTE: Using the DB query is a costly operation BUT it allows me to detect if Kamailio is sending call to Dispatcher listed IPs or not. I have a mix of Asterisks on Private Subnet and on Public Subnet and if the Asterisk dispatcher has chosen or the call is coming from is a Private IP then engage RTPproxy. This detection is handled by IPOPS module and its function is_ip_rfc1918()

loadmodule "ipops.so"
loadmodule "sqlops.so"
modparam("sqlops","sqlcon","ca=>mysql://openser:openserrw@localhost/kamailio")

Then declare the route:

# RTPProxy control
route[RTPPROXY] {
        if (is_method("INVITE")){
                sql_query("ca", "select destination from dispatcher where destination like '%$dd%'","ra");
                if($dbr(ra=>rows)>0){
                        $avp(duip)=$(du{s.select,-2,:});
                        if (is_ip_rfc1918("$avp(duip)")) {
                                xlog("L_INFO", "Call is going to private IPv4 Media Server Engage RTPProxy Now\n");
                                #rtpproxy_manage("crwie","192.168.1.244");
                                rtpproxy_manage("rwie");
                        }

                }
                else if(ds_is_from_list()){
                        if (is_ip_rfc1918("$si")) {
                                xlog("L_INFO", " Call is coming from a private IPv4 Media Server Engage RTPProxy Now\n");
                                #rtpproxy_manage("crwei","77.66.55.44");
                                rtpproxy_manage("rwei");

                        }
                }else if(!ds_is_from_list()){
                          rtpproxy_manage("rwie");

                }
      }
}

6- Using RTPPROXY route

Add the RTPPROXY route just where the FLT_NATS and FLB_NATB flags are tested.

        if (!(isflagset(FLT_NATS) || isbflagset(FLB_NATB))){
                return;
        }
                route(RTPPROXY);

Now Save and Exit the kamailio.cfg file.

Restart Kamailio.

root@Kamailio:~# /etc/init.d/kamailio stop
root@Kamailio:~# /etc/init.d/kamailio start

7- Helpful Things to know

Asterisk needs to have the peer declared for kamailio using its Private IP.

[Kamailio]
type=friend
host=192.168.1.244
port=5060
disallow=all
allow=gsm
allow=g729
allow=alaw
allow=ulaw
context=SBC-Incoming
canreinvite=no
insecure=port,invite
nat=force_rport,comedia
qualify=yes
directrtpsetup=no

See that I've used "directrtpsetup=no" so that Asterisk don't decide to go direct with the End caller.

Use xlog lines in kamailio.cfg file to follow the call.

The way I always setup my whole environment is that Kamailio handles the REGISTRATIONs and only INVITES are load-balanced to Asterisks or FreeSWITCHes where they receive the call from Kamailio peer and execute dialplan applications and IF call needs to dial out they dial the destination back to kamailio.
Kamailio needs to detect the call coming FROM the Media-Servers (ds_is_from_list() function)

So I know when a user calls in and when the call comes in from the media-servers.

Always try to first have an echo test working for calls. I use Asterisk application Echo() and when I dial in from user I get my own audio echoed back and I know that atleast my audio path is complete. This never tells you that your setup is 100% perfect but it is a good way to know if you're headed right direction.


Wireshark is a great Friend. Use it to examine everything in depth. No matter what I do I always need Wireshark to visually see what is going on with the SIP packets, that gives me everything I need to know to make things right.

root@Kamailio200:~# tcpdump -i any -s 0 -w rtp-calls.pcap -vvv
tcpdump: listening on any, link-type LINUX_SLL (Linux cooked), capture size 65535 bytes
1666 packets captured
Download this "rtp-calls.pcap" file and open it up in Wireshark. Click "Telephony"  from the menu bar and select "VoIP Calls"


Hit the Flow button and you'll see beautiful arrows showing the direction of SIP and RTP packets.


On the very Left Hand side is my Soft Phone's Public IP address, then 77.66.55.44 is kamailio's WAN side, and suddenly we see 192.168.1.244 which is Private IP of Kamailio communicating with an Asterisk on 192.168.1.36
The Bold arrows labeled RTP are flowing in both direction means all Perfect.

Thats all for one day. Hope to have some comments and questions on this soon.

14 comments:

  1. Thank you very much!

    How to configure kamailio+rtp to work on multiply interfaces ?
    eth0 - LAN
    eth1 - VLAN1
    eth1 - VLAN2
    eth2 - WAN

    Reply
    Replies
    1. An excellent question, although it requires an extra blog post but I'll try explain the concept.

      1- Identify your NICs to be bridged. Just need to know a logical view which interface for rtpproxy to be used in what case?

      2- Start multiple daemons of RTpproxy with different listeners ports and differnt VLANs used.

      3- In kamailio.cfg connect with multiple RTPproxy instances like this: 
      # multiple sets of multiple rtproxies
      modparam("rtpproxy", "rtpproxy_sock",
      "1 == udp:localhost:12221")
      modparam("rtpproxy", "rtpproxy_sock",
      "2 == udp:localhost:12225")

      and then from the SIP traffic identifiy which set of RTPproxy to engage by this function: set_rtp_proxy_set("2"); 

      That is a very very brief summary.

  2. Hello!

    i have error in route[TOASTERISK] section
    in line 
    > ds_mark_dst("P");

    > ERROR: [usr_avp.c:437]: search_avp(): ERROR:avp:search_first_avp: 0 ID or NULL NAME AVP!

    and sip debug in asterisk
    <--- SIP read from UDP:192.168.30.250:6000 --->
    INVITE sip:110@PU.BL.IC.IP:6000;transport=UDP SIP/2.0
    Record-Route: 
    Record-Route: 
    Via: SIP/2.0/UDP 192.168.30.250:6000;branch=z9hG4bK49cf.52e49675.0
    Via: SIP/2.0/UDP CL.IE.NT.IP:37176;branch=z9hG4bK-d8754z-3c51331a1cd05eae-1---d8754z-;rport=37176
    Max-Forwards: 16
    Contact: 
    To: 
    From: ;tag=832a5f3f
    Call-ID: ZGFhZDFmZGY5ZDU0ODkzYzQ2NzY0ZjliMzYzZThiNWE.
    CSeq: 2 INVITE
    Allow: INVITE, ACK, CANCEL, BYE, NOTIFY, REFER, MESSAGE, OPTIONS, INFO, SUBSCRIBE
    Content-Type: application/sdp
    Supported: replaces, norefersub, extended-refer, timer, X-cisco-serviceuri
    User-Agent: Zoiper r19016
    Allow-Events: presence, kpml
    Content-Length: 309

    v=0
    o=Z 0 0 IN IP4 PU.BL.IC.IPPU.BL.IC.IP
    s=Z
    c=IN IP4 PU.BL.IC.IPPU.BL.IC.IP
    t=0 0
    m=audio 1227412274 RTP/AVP 3 110 98 8 0 101
    a=rtpmap:110 speex/8000
    a=rtpmap:98 iLBC/8000
    a=fmtp:98 mode=20
    a=rtpmap:101 telephone-event/8000
    a=fmtp:101 0-15
    a=sendrecv
    a=nortpproxy:yes
    a=nortpproxy:yes

    with error
    [Aug 31 02:17:56] ERROR[17594]: netsock2.c:269 ast_sockaddr_resolve: getaddrinfo("PU.BL.IC.IPPU.BL.IC.IP", "(null)", ...): No address associated with hostname
    [Aug 31 02:17:56] WARNING[17594]: chan_sip.c:9973 process_sdp_c: Unable to lookup RTP Audio host in c= line, 'IN IP4 PU.BL.IC.IPPU.BL.IC.IP'

    Reply
    Replies
    1. As for the AVP error check ur avp configuation as follows....
      modparam("dispatcher", "dst_avp", "$avp(i:271)")
      modparam("dispatcher", "grp_avp", "$avp(i:272)")
      modparam("dispatcher", "cnt_avp", "$avp(i:273)")

  3. in route[NATMANAGE]
    when i register and call from 10.10.101.50 (private ISP.LAN)
    nat_uac_test("19") return true 
    and i have correct INVITE (192.168.30.250 is my kamailio&rtpproxy lan side)
    v=0
    o=Z 0 0 IN IP4 192.168.30.250
    s=Z
    c=IN IP4 192.168.30.250
    t=0 0
    m=audio 17530 RTP/AVP 3 110 98 8 0 101
    a=rtpmap:110 speex/8000
    a=rtpmap:98 iLBC/8000
    a=fmtp:98 mode=20
    a=rtpmap:101 telephone-event/8000
    a=fmtp:101 0-15
    a=sendrecv
    a=nortpproxy:yes

    but when i switch to GSM connection
    nat_uac_test("19") return FALSE 
    and i have invalid INVITE (10.133.19.49 is IP behind GSM NAT)
    v=0
    o=Z 0 0 IN IP4 10.133.19.49
    s=Z
    c=IN IP4 10.133.19.49
    t=0 0
    m=audio 57756 RTP/AVP 3 110 98 8 0 101
    a=rtpmap:110 speex/8000
    a=rtpmap:98 iLBC/8000
    a=fmtp:98 mode=20
    a=rtpmap:101 telephone-event/8000
    a=fmtp:101 0-15
    a=sendrecv

    Reply
    Replies
    1. Read this: 
      http://www.kamailio.org/docs/modules/4.0.x/modules/nathelper.html#idp15376536
      This is really tough then...hmmm...Your "Public IP" is again a Private IP. !!?

    2. no. 10.133.19.49 is GSM private IP ! 192.168.30.250 is kamailio lan ip

    3. Like I said read the link and put the right value in the nat_test function, could be like (31) or so. I suggest take a full packet trace to know from which IP this GSM SIP traffic is coming, is it Public? or Private ?
      Also post the situation on User mailing list to get a more accurate solution.

  4. Hi Ahmed,
    first- thank you for this excellent blog. I am starting to learn about kamailio (I am asterisk admin) and I have one question. Is it "correct" to use kamailio with sip peers and asterisk which are all in private lan (no UA coming from wan side). Kamailio would have one interface point to provider, also with private IP address from provider, and one interface in subnet together with couple of asterisk servers and sip peers. In that way peers (phones) would register to kamailio, which would load balancing calls between asterisk servers and pass calls from asterisks to provider? Thx again!

    Reply
  5. Hello,

    I'm trying to setup Kamailio and Asterisk on the samebox with Kamailio listening on a public + private IP and asterisk only on private IP. 

    Unfortunately I'm unable to get working as expected. We need somebody get us an hand !
    Please contact me at scramattegmailcom 

    Best regards

    Reply
  6. Hello Gohar...i tested this more than one time and i'm receiving the same error message in asterisk 
    ...................................................................................
    [2013-10-16 05:20:04] ERROR[3216][C-0000002c]: netsock2.c:269 ast_sockaddr_resolve: getaddrinfo("192.168.1.80192.168.1.80", "(null)", ...): Name or service not known
    [2013-10-16 05:20:04] WARNING[3216][C-0000002c]: chan_sip.c:10873 process_sdp_c: Unable to lookup RTP Audio host in c= line, 'IN IP4 192.168.1.80192.168.1.80'
    [2013-10-16 05:20:04] WARNING[3216][C-0000002c]: chan_sip.c:10464 process_sdp: Insufficient information in SDP (c=)...
    ..............................................................................
    So help me plz to solve this issue...

    Reply
  7. Hi Gohar,

    Thanks for a detailed and informative descriptions of the setup. I'm also trying to setup similar network, without the LB for this time.

    I'm running into an issue, I'm not sure whether you've seen this yourselves. Please share some pointers. My network is:

    clients <--> Public IP(Kamailio/RTPProxy)10.1.128.11 <--> 10.1.128.34 (Freeswitch)

    The 200 OK response from Freeswitch (on the way back from called party to caller) to Kamailio is shown below. Notice the Contact header URI host part contains Freeswitch Private IP (10.1.128.34). Kamailio suppose to change that to Public IP before forwarding the 200 OK (copied below) to Caller in public domain. But. it's not. As a result, ACK from Caller is not reaching back to Kamailio.

    How did you or anybody out there using Kamailio resolve this problem? If needed, I can copy/paste my kamailio.cfg.

    SIP 200 OK ->

    Via: SIP/2.0/UDP 10.1.128.11;branch=z9hG4bKa7ea.4013d9881c1b7fe7b4c6c0f0e8f9d6b6.0
    Via: SIP/2.0/UDP :5060;rport=5060;branch=z9hG4bK-383736-9b4621118533d3ccea17992738433249
    Record-Route: 
    Record-Route: ;r2=on;lr=on;ftag=791b5ae3;nat=yes>
    From: \"Dipak Biswas\" >;tag=791b5ae3
    To: >;tag=atXF5443gQj9p
    Call-ID: 20d5d6d366fcb06c259a0895b3e44b52@0:0:0:0:0:0:0:0
    CSeq: 2 INVITE
    Contact: 
    User-Agent: FreeSWITCH mod_sofia/1.4.2+git~20140108T200418Z~d8fc8469b4~64bit
    Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY
    Supported: timer, precondition, path, replaces
    Allow-Events: talk, hold, conference, refer
    Content-Type: application/sdp
    Content-Disposition: session
    Content-Length: 269


    Thanks,
    Dipak

    Reply
  8. Hello Ahmed,

    In your setup, how do I manage users login/password? by kamailio or Asterisk?
    I see only one peer in your Asterisk configuration.
    I'm a little lost. :-)

    How to set up this configuration with a Ast2Billing system or users are managed by 1 SIP user (A, B, etc) = 1 SIP peer/friend in asterisk.

    Thank you,
    Mickael

    Reply
    Replies
    1. Dear Mickael, In my example users are to be managed in Kamailio DB,they'll get registered at Kamailio and Asterisk give services only for Media level stuff. 

      For setting up with A2billing you'll need to change this approach and see the Kamailio Asipto blog and integrate the A2billing SIP user table with kamailio directly and let the rest of the DB be used by asterisk(s). That way from A2billing Web-Panel you'll be able to manage SIP users/routes/LCR etc and Kamailio will be the only visible component of your project for each SIP endpoint.


조회 수 :
100764
등록일 :
2014.03.07
00:21:53 (*.251.139.148)
엮인글 :
http://webs.co.kr/index.php?document_srl=38973&act=trackback&key=d91
게시글 주소 :
http://webs.co.kr/index.php?document_srl=38973
List of Articles
번호 제목 글쓴이 날짜 조회 수
48 SIP PBX - OpenSIPS and Asterisk configuration admin 2014-03-12 159632
47 Conference Support in Kamailio (OpenSER) admin 2014-03-12 83753
46 OpenSIPS configuration for 2 or more FreeSWITCH installs admin 2014-03-12 74030
45 The Impact of TLS on SIP Server Performance file admin 2014-03-12 41133
44 book-opensips-101 / content / 3.2. SIP TLS Secure Calling.mediawiki admin 2014-03-12 41597
43 Where to check OpenSIPS does not start? admin 2014-03-09 42109
42 opensips-1.10.0_src.tar.gz experimental source code documentation admin 2014-03-09 37038
41 Kamailo OpenSIPs installation on Debian admin 2014-03-09 80679
40 Using the openSIPS Registrant Module admin 2014-03-09 51601
39 RTPproxy Frequentry Asked Questions (FAQ) ¶ admin 2014-03-07 174144
38 Building Telephony Systems with OpenSIPS 1.6 RTPProxy + OpenSIPS 1.7 admin 2014-03-07 39621
» Installing RTPproxy Start RTPproxy in Bridged mode very good admin 2014-03-07 100764
36 OpenSIPS Control Panel (OCP) Installation Guide admin 2014-03-06 277732
35 OpenSIPS Control Panel install guide admin 2014-03-06 95046
34 rtpproxy Module admin 2014-03-06 37738
33 MediaProxy Installation Guide admin 2014-03-06 178916
32 How to install OpenSIPS on CentOS debian module add xcap admin 2014-03-06 45105
31 Problem with presence_xml module Opensips 1.9 admin 2014-03-06 47014
30 Building Telephony Systems with OpenSIPS 1.6 books file admin 2014-03-06 41580
29 Multimedia Service Platform admin 2014-03-06 36297
28 How to install OpenSIPS on CentOS Debian etc admin 2014-03-05 44041
27 Opensips Installation, How to. admin 2014-03-05 74671
26 100% CPU usage opensips admin 2014-03-05 53557
25 A2Billing and OpenSIPS admin 2014-03-04 41011
24 Opensips_1.9 install guide this is great I like this admin 2014-03-04 106425
23 Opensips install debian admin 2014-03-03 37263
22 Open Source VOIP applications, both clients and servers. admin 2013-11-20 43370
21 OfficeSIP Server is freeware VoIP, SIP server for Windows admin 2013-09-11 53933
20 My new toy: Bluebox-ng admin 2013-04-06 90661
19 Flooding Asterisk, Freeswitch and Kamailio with Metasploit admin 2013-04-06 98440