[Serusers] SER parallel forking

Daniel-Constantin Mierla daniel at iptel.org
Thu May 20 12:51:46 CEST 2004


Hello,
you can add a permanent contact (you can use 'serctl ul add ...') for 
each user to asterisk and SER will automatically fork.

.Daniel

On 5/20/2004 10:24 AM, Peter Gradwell wrote:

> Hi,
>
> We're integrating SER and Asterisk and want to use parallel forking
> so that calls for sip users to simultaneously call the sip phone and
> ser<user>@asterisk.gradwell.net, which will then wait a per-user delay
> before answering with the voicemail.
>
> The call does divert, but only after SER's own timer expires.  This
> might work ok as a last resort, but really we want the parallel forking
> as described above to work so that we can have per-user delays, it may
> also make supporting call diverts easier, since Asterisk is good at
> stuff like that.
>
> As far as I can tell the main logic for doing the branching (using
> append_branch) is very similar to SER's example config file onr.cfg in
> the distribution's examples directory.  However I didn't have much luck
> with that either!  Our config file is included below.
>
> Any thoughts on how to make this work would be most welcome!
>
> many thanks
> peter
>
> =====================================================================
> # # $Id: ser.cfg,v 1.21.2.1 2003/07/30 16:46:18 andrei Exp $ #
> # simple quick-start config script
> #
>
> # ----------- global configuration parameters ------------------------
>
> #debug=3         # debug level (cmd line: -dddddddddd)
> #fork=yes
> #log_stderror=no    # (cmd line: -E)
>
> /* Uncomment these lines to enter debugging mode */
> debug=9
> fork=no
> log_stderror=yes
>
> check_via=no    # (cmd. line: -v)
> dns=yes           # (cmd. line: -r)
> rev_dns=no      # (cmd. line: -R)
> listen=193.111.200.106
> #mhomed=1
> port=5060
> children=4
> fifo="/tmp/ser_fifo"
> alias="ser.gradwell.net"
> alias="193.111.200.106"
> #fifo_db_url="mysql://ser:********@hostingdb/ser"
>
> # ------------------ module loading ----------------------------------
>
> # Uncomment this if you want to use SQL database
> #loadmodule "/usr/local/lib/ser/modules/mysql.so"
>
> loadmodule "/usr/local/lib/ser/modules/mysql.so"
> loadmodule "/usr/local/lib/ser/modules/sl.so"
> loadmodule "/usr/local/lib/ser/modules/tm.so"
> loadmodule "/usr/local/lib/ser/modules/rr.so"
> loadmodule "/usr/local/lib/ser/modules/maxfwd.so"
> loadmodule "/usr/local/lib/ser/modules/usrloc.so"
> loadmodule "/usr/local/lib/ser/modules/registrar.so"
> #loadmodule "/usr/local/lib/ser/modules/uri.so"
> loadmodule "/usr/local/lib/ser/modules/group.so"
> loadmodule "/usr/local/lib/ser/modules/acc.so"
> loadmodule "/usr/local/lib/ser/modules/textops.so"
> loadmodule "/usr/local/lib/ser/modules/domain.so"
> #loadmodule "/usr/local/lib/ser/modules/enum.so"
> loadmodule "/usr/local/lib/ser/modules/msilo.so"
> loadmodule "/usr/local/lib/ser/modules/auth.so"
> loadmodule "/usr/local/lib/ser/modules/auth_db.so"
> #loadmodule "/usr/local/lib/ser/modules/nathelper.so"
> loadmodule "/usr/local/lib/ser/modules/xlog.so"
>
>
> # Use a private ENUM space [not yet, we just pretend to be the real thing
> #modparam("enum","domain_suffix","enum.go-sip.org.")
>
> # We force all the lookup and registrar related stuff to take the domain
> # into account.
>
> # Point everything at sip-auth-adm for DB related stuff
> modparam("usrloc", "use_domain",   1)
> modparam("registrar", "use_domain",   1)
> modparam("group", "use_domain",   1)
> modparam("auth_db", "use_rpid",   1)
> modparam("auth_db", "rpid_column",   "username")
>
> # We do not use persistant storage, this reduces DB overhead,
> # however, if we move to a HA pair, then this should be set to 1
> # and the seed for generating nonce values must be synchronised.
> # NOTE: Actually we HAVE to use 1 anyway as our aliases table is
> # in SQL.
> modparam("usrloc", "db_mode",   2)
> modparam("usrloc","db_url", "mysql://ser:********@hostingdb/ser")
> modparam("domain","db_url", "mysql://ser:********@hostingdb/ser")
> modparam("domain","db_mode",1)
> modparam("group","db_url", "mysql://ser:********@hostingdb/ser")
> #modparam("group","db_mode",1)
>
> modparam("auth_db","db_url", "mysql://ser:********@hostingdb/ser")
> modparam("auth_db", "calculate_ha1", yes)
> modparam("auth_db", "password_column", "password")
> #modparam("uri","db_url", "mysql://ser:********@hostingdb/ser")
> #modparam("uri","use_uri_table", yes)
> modparam("acc","db_url", "mysql://ser:********@hostingdb/ser")
> modparam("msilo","db_url","mysql://ser:********@hostingdb/ser")
> #modparam("msilo","registrar","sip:registrar at go-sip.com")
>
> modparam("tm", "fr_inv_timer", 15 )
> modparam("tm", "fr_timer", 10 )
> #modparam("tm", "wt_timer", 2 )
>
>
> # Useful for some badly behaved clients
> modparam("rr", "enable_full_lr", 1)
>
> # Set accounting flags, these are the defaults anyway
> modparam("acc", "db_flag", 1)
> modparam("acc", "db_missed_flag", 2)
>
> # Nathelpher
> #modparam("nathelper", "natping_interval", 10)
>
> # Which flags mean what...
> # 1 - account
> # 2 - missed call
> # 3 - url reqires enum rewrite
> # 4 - user has voicemail accessuser has voicemail access
> # 5 - user is online
> # 6 - inbout call rtp stream should be proxied:
> # 7 - outbound call rtp stream should be proxied:
> # 8 - set up voicemail in route[3]
>
> # -------------------------  request routing logic -------------------
>
> # main routing logic
>
> route{
>
>     xdbg("*****\n");
>     xdbg("***** %rm %ru\n");
>     xdbg("*****\n");
>
>     # initial sanity checks -- messages with
>     # max_forwards==0, or excessively long requests
>     if (!mf_process_maxfwd_header("10")) {
>         sl_send_reply("483","Too Many Hops");
>         break;
>     };
>     if (msg:len > max_len) {
>         sl_send_reply("513", "Message too big");
>         break;
>     };
>
>     # we record-route all messages -- to make sure that
>     # subsequent messages will go through our proxy; that's
>     # particularly good if upstream and downstream entities
>     # use different transport protocol
>     record_route();   
>     # loose-route processing
>     if (loose_route()) {
>         t_relay();
>         break;
>     };
>
>     if(method=="BYE"){
>         setflag(1);
>         t_relay();
>         break;
>     };
>
>     # if the request is for other domain use UsrLoc
>     # (in case, it does not work, use the following command
>     # with proper names and addresses in it)
>     if ( is_uri_host_local() || uri == myself ) {
>
>         # We want to deal primarily with numbers rather
>         # than usernames, this makes life easier in
>         # voicemail.
>         #
>         # Translate any usernames to numbers
>         if (method=="REGISTER") {
>             # Leaving the domain blank means that the
>             # domain from the url will be used.
>             if (!www_authorize("","subscriber")) {
>                 www_challenge("", "1");
>                 break;
>             };
>
>             save("location");
>             break;
>         };
>
>         log("**** lookup(aliases)\n");
>         lookup("aliases");
>
>         # We don't deal with presence at the moment
>         if (method=="SUBSCRIBE" || method == "PUBLISH") {
>                            sl_send_reply("503", "Service Unavailable");
>             break;
>         };
>
>         # Rewriting for other SIP networks...
>         if(uri=~"^sip:\*\*.*"){
>             # We only want our customer relaying through our servers
>             strip(2);
>             if (!proxy_authorize("","subscriber")) {
>                 proxy_challenge("", "1");
>                 break;
>             };
>
>             sl_send_reply("404", "Not Found");
>             break;
>         };
>
>         if(uri=~"^sip:[0-9][0-9][0-9]@.*" ){
>             t_relay_to_udp("asterisk.gradwell.net","5060");
>             break;
>         };
>
>         if (uri=~"^sip:0.*") {
>
>             if (uri=~"^sip:0.*") {
>                 if (uri=~"^sip:00.*") {
>                     strip(2);
>                 }else{
>                     strip(1);
>                     prefix("44");
>                 };
>             };
>
>             route(6);
>             break;
>         };
>
>         # native SIP destinations are handled using our USRLOC DB
>         if (method == "INVITE" || method == "ACK" || method == 
> "MESSAGE") {
>             if (uri=~"^sip:\*") {
>                 t_relay_to_udp("asterisk.gradwell.net","5060");
>                 break;
>             };
>
>             # Request uri is now invalid or in Username  form
>             if (lookup("location")) {
>                 log("*** found in usrloc\n");
>                 if(method=="MESSAGE"){
>                     # Remote agent may not accept messages, we 
> juststore them.
>                     t_on_failure("1");
>                     t_relay();
>                     break;
>                 };
>
>                 # they are  online
>                 setflag(5);
>             } else {
>                 if(method=="MESSAGE"){
>                     # Remote agent may not accept messages, we 
> juststore them.
>                            if (m_store("1")) {
>                                     t_reply("202", "Accepted");
>                            }else{
>                                     t_reply("503", "Service 
> Unavailable");
>                            };
>                     break;
>                 };
>             };
>
>             if (!isflagset(5)) {
>                 log("**** not found in usrloc, diverting to vm\n");
>                 revert_uri();
>                 lookup("aliases");
>                 # User not registered with either username or extension
>                 # Instant Unavailable voicemail
>                 acc_db_request("Unavailable - Offline", "missed_calls");
>                 log("**** lookup(aliases)\n");
>                 lookup("aliases");
>                 prefix("ser");
>                 route(2);   
>                 break;
>             };
>
>             setflag(8);
>             route(3);
>             break;
>         };
>     };
>
>     # forward to current uri now; use stateful forwarding; that
>     # works reliably even if we forward from TCP to UDP
>
>     route(3);
> }
>
> # Our voicemail route.
> route[2]{
>         append_hf("P-hint: in-route-2\r\n");
>         log("IDESK: Route 2, Forwarding to Voicemail\n");
>         xdbg("IDESK: method=%rm, r_uri=%ru, cseq=%cs\n");
>     rewritehost("asterisk.gradwell.net");
>     rewriteport("5060");
>     if (!t_relay()) {
>         log("Forwarding to Voicemail FAILED\n");
>         sl_reply_error();
>         break;
>     };
>     break;
> }
>
>
> # Stateful relaying with NAT if it is needed.
> # NOTE: One possibel enhancement here is to do the rtp-proxying via 
> another box
> # this would move the traffic away from the ser server completely.
>
> # Nat for outbound from idesk
> route[3]{
>            log("IDESK: Route for fixing up outbound\n");
>
>     if (isflagset(8)) {
>         # We know where they are, and they have
>         # voicemail access, so we fork to their
>         # voicemail account.
>
>         append_branch();
>         revert_uri();
>         log("**** setting up vm branch\n");
>         log("**** lookup(aliases)\n");
>         lookup("aliases");
>         prefix("ser");
>
>         append_hf("P-hint: known-vm \r\n");
>         rewritehost("asterisk.gradwell.net");
>         rewriteport("5060");
>     };
>
>     if (method == "INVITE"){
>         if (isflagset(6)) {
>                  log("IDESK: Outbound RTP Proxying \n");
>             log("failure 1, reply 1\n");
>             t_on_failure("1");
>             #t_on_reply("1");
>         } ;
>         if (isflagset(7)){
>                  log("IDESK: Inbound RTP Proxying \n");
>             log("failure 1, reply 2\n");
>             t_on_failure("1");
>             #t_on_reply("2");
>         } ;
>         if (isflagset(5) && !isflagset(6) && !isflagset(7)){
>             log("failure 1, reply 3\n");
>             t_on_failure("1");
>             #t_on_reply("3");
>         };
>     };
>
>     if (!t_relay()) {
>         sl_reply_error();
>         break;
>     };
> }
>
> ####
> ####onreply_route[1]{
> ####    # Our rtp proxying
> ####           log("IDESK: Reply Route for fixing up Outboudn nat\n");
> ####    if(status=~"4[0-9][0-9].*"){
> ####        setflag(2);
> ####    };
> ####    if(status=~"200.*" && search("application/sdp")){
> ####        if(src_ip=="192.168.254.27"){
> ####            route(5);
> ####        };
> ####        # If it comes back through this route then it needs natting
> ####        if (search("application/sdp")){
> ####            force_rtp_proxy_from("192.168.254.26");
> ####        };
> ####    };
> ####}
> ####
> ####onreply_route[2]{
> ####    # Our rtp proxying
> ####           log("IDESK: Reply Route for fixing up Inbound  nat\n");
> ####    if(status=~"4[0-9][0-9].*"){
> ####        setflag(2);
> ####    };
> ####    if(status=~"200.*" && search("application/sdp")){
> ####        if(src_ip=="194.130.117.27"){
> ####            route(5);
> ####        };
> ####        # If it comes back through this route then it needs natting
> ####        if (search("application/sdp")){
> ####            force_rtp_proxy_from("194.130.117.26");
> ####        };
> ####    };
> ####}
>
> onreply_route[3]{
>     # Our rtp proxying
>            log("IDESK: Reply Route for fixing up Inbound  nat\n");
>     if(status=~"4[0-9][0-9].*"){
>         setflag(2);
>     };
>     if(status=~"200.*" && search("application/sdp")){
>         if(isflagset(5) && ( src_ip == "192.168.254.27" || src_ip == 
> "194.130.117.27")){
>             route(5);
>         };
>     };
> }
>
> failure_route[1]{
>     if(method=="MESSAGE"){
>         # Remote agent may not accept messages, we juststore them.
>                if (m_store("1")) {
>                         t_reply("202", "Accepted");
>                }else{
>                         t_reply("503", "Service Unavailable");
>                };
>         break;
>     };
>     append_hf("P-hint: missed \r\n");
>     setflag(2);
>            append_hf("P-hint: in-reply-route-1\r\n");
>            log("IDESK: Failure Route 1\n");
> }
>
> # Account as missed
> route[5] {
>     log("IDESK: Route 3\n");
>     append_hf("P-hint: in-route-3\r\n");
>     append_hf("P-hint: missed \r\n");
> #    setflag(2);
>     acc_db_request("No Answer", "missed_calls");
> }
>
> # This is our route out to the PSTN;
> route[6]{
>     append_hf("P-hint: in-route-4-pstn\r\n");
>     # This really is going to be a PSTN call, so we
>     # Need to check the credentials
>     # Leaving the domain blank means that the
>     # domain from the url will be used.
>
>     if (uri=~"^sip:44.*") {
>         strip(2);
>         prefix("0");
>     };
>
>     if(method=="INVITE"){
>         # sip.calluk.com will authenticate...
>         #if (!proxy_authorize("","subscriber")) {
>         #    proxy_challenge("", "1");
>         #    break;
>         #};
>         append_rpid_hf();
>         log("Forwarding to PSTN\n");
>         setflag(1);
>         rewritehost("sip.calluk.com");
>         if(!t_relay_to_udp("sip.calluk.com","5060")){
>             sl_reply_error();
>         };
>         break;
>     };
>
>     if(method=="CANCEL" || method=="ACK" || method=="BYE"){
>         setflag(1);
>         if(!t_relay_to_udp("sip.calluk.com","5060")){
>             sl_reply_error();
>         };
>         break;
>     }
> }
>
> =====================================================================
>
> thanks
> peter
>




More information about the sr-users mailing list