Routing script tutorial:route remap Tutorial

From TBwiki
Jump to: navigation, search

Contents

route_remap tutorial

'route_remap' is a method implemented in the base_routing and is use to modify call parameters per route (allowing to change call attributes in a different manner per route). This tutorial will explain how to use the parameter for the 'route_remap' method.

route_remap examples


Things to know about these examples:

  • A new field called 'priority' needs to be add to the routes.
  • A new field called 'asr_threshold' needs to be add to the routes.
  • A new field called 'usage_threshold' needs to be add to the routes.

route_remap setup

Time to take a look how to match route to a call. List of routes use for the example:

 Calling      Called      NAP      Remapped NAP       Priority
 5550000     1110000     isdn       sip                4     
 5550000     2220000     sip        isdn               3     
 5550000     3330000     sip_p2     isdn_1             2     


List of naps:

 Name       Asr threshold       Usage threshold   
 isdn         40                 90     
 sip          52                 92     


Input used in the test script window:

 @call_params = {:calling => '5550000', :called => '5550002', :nap => 'isdn'}
 @nap_list = [
   {:name => 'sip', },
   {:name => 'isdn' },
   {:name => 'sip_p3' }
 ]


route_remap parameter


The following example is a isdn to sip gateway. This time we will remap the called and the calling number.

 require 'base_routing'
 
 class RemapTutorial < BaseRouting
   route_match :call_field_name => :nap
   route_remap :call_field_name => :called, :route_field_name => :called
   route_remap :method => :remapped_tutorial
   route_remap :proc => Proc.new { |route, caf_call, nap_list, call_params|
 
     puts "Proc is called"  
     #remapping calling
     remap_calling = call_params[:calling]
     puts "remapped : #{remap_calling}"
     
     if( remap_calling == "5550000" )
       remap_calling = "9871111"
     elsif ( remap_calling == "7772222")
       remap_calling = "6541111"
     end
 
     puts "remap_calling : #{remap_calling}"
     call_params[:calling] = remap_calling
     
     call_params
   }
 
   def remapped_tutorial(route, caf_call, nap_list, call_params)
 
     puts "Method is called"  
     remap_calling = call_params[:calling]
     puts "remapped : #{remap_calling}"
     
     if( remap_calling == "5550000" )
       remap_calling = "7772222"
     elsif( remap_calling == "9871111" )
       remap_calling = "9992222"
     end
     
     puts "remap_calling : #{remap_calling}"
     call_params[:calling] = remap_calling
     
     call_params
   
   end
 
 end
 
 @@routing = RemapTutorial.new
 
 
 def init_routes( routes )
   @@routing.init routes
 end
 
 def route( call, nap_list )
   @@routing.route call, nap_list
 end


route_remap script output

The called number is remapped by the the :call_field_name / :route_field_name. Like 'route_match', if :call_field_name is used alone the parameter (in this case :called), will be remapped by the same parameter of :route_field_name. The following 2 lines will have the exact same behavior (they both remapped the called number of the call with the called number of the route):

 route_remap :call_field_name => :called
 route_remap :call_field_name => :called, :route_field_name => :called

As for the :method and :proc parameters, they both remap the calling number but to different values.

The remapping result needs to be inserted in call_params hash and return in your method or proc. All remap function return remapped parameter in the call_params. They are executed in the order they are declared.

Here is the output of the example:

 Call Params:
   Reason:        ok
   Called:        2220000
   Calling:       6541111
   Nap:           sip
 Matched route:
   Remapped calling:    
   Called:        2220000
   Calling:       5550000
   Remapped called:    
   Priority:      3
   Remapped nap:  isdn
   Nap:           sip
 Output: OUT: Method is called
  OUT:
  OUT: call : 5550000
  OUT:
  OUT: remap_calling : 7772222
  OUT:
  OUT: Proc is called
  OUT:
  OUT: remapped : 7772222
  OUT:
  OUT: remap_calling : 6541111
  OUT:
  OUT: Nap attribute must be remapped
  OUT:



Back to Routing Script Tutorial.

Personal tools