Routing script tutorial:route remap Tutorial

From TBwiki
Revision as of 11:21, 20 May 2009 by 10.0.0.157 (Talk)
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. 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, call, nap_list, remapped_fields|
 
     puts "Proc is called"  
     #remapping calling
     if remapped_fields[:calling].nil?
       remap_calling = call.get(:calling)
       puts "call : #{remap_calling}"
     else
       remap_calling = remapped_fields[:calling]
       puts "remapped : #{remap_calling}"
     end
     
     if( remap_calling == "5550000" )
       remap_calling = "9871111"
     elsif ( remap_calling == "7772222")
       remap_calling = "6541111"
     end
 
     puts "remap_calling : #{remap_calling}"
     remapped_fields[:calling] = remap_calling
     
     remapped_fields
   }
 
   def remapped_tutorial(route, call, nap_list, remapped_fields)
 
     puts "Method is called"  
     if remapped_fields[:calling].nil?
       remap_calling = call.get(:calling)
       puts "call : #{remap_calling}"
     else
       remap_calling = remapped_fields[:calling]
       puts "remapped : #{remap_calling}"
     end
     
     if( remap_calling == "5550000" )
       remap_calling = "7772222"
     elsif( remap_calling == "9871111" )
       remap_calling = "9992222"
     end
     
     puts "remap_calling : #{remap_calling}"
     remapped_fields[:calling] = remap_calling
     
     remapped_fields
   
   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.

It is important when remapping to always verify the remapped_fields parameter. If some parameters were remapped previously, the changes will be supply in the remapped_fields (4th parameter of your method or proc). The remapping result needs to put in that hash and return in your method or proc. It is possible though that you may want to overwrite the change done previously, in that case use directly the call parameter but of course you will need to order your 'route_remap' accordingly. They are executed in the order they are declared.

The actual changes on the call will only be "merged" after all the remapping are done.

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