Routing script tutorial:Routing Class Tutorial

From TBwiki
Revision as of 09:24, 20 May 2009 by 10.0.0.157 (Talk)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Routing Class Tutorial

This is a basic tutorial about script routing. This page will explain the different methods required in a script routing.

Here is a list of routes of a sip/isdn gateway:

 Calling  Called  NAP  Remapped NAP
 2220000 1110000 sip   isdn    
 4440000 3330000 isdn   sip    


These routes are pretty restrictive, since the calling and called number are set to a single number. We could simply remove the number in the calling and called number to allow any number to go from sip to isdn. But for the sake of this example we won't.

Let's create a class that will only match the call by nap and remap it (sip to isdn / isdn to sip).

 require 'base_routing'
 
 class IsdnSipGw < BaseRouting
   route_match :call_field_name => :nap
   route_remap :call_field_name => :nap, :route_field_name => :remapped_nap
 end
 
 @@routing = IsdnSipGw.new
 
 def init_routes( routes )
   @@routing.init routes
 end
 
 def route( call, nap_list )
   @@routing.route call, nap_list
 end


Let's analyze the script in more detail:

 class IsdnSipGw < BaseRouting
   route_match :call_field_name => :nap
   route_remap :call_field_name => :nap, :route_field_name => :remapped_nap
 end


This is the definition of the routing class which is called IsdnSipGw and has BaseRouting as base class. It will match call to the route according to its incoming nap. It will also remap the nap field value with the value of the remapped_nap field located in the route.

 @@routing = IsdnSipGw.new


Creates a routing object of IsdnSipGw type. This line is executed when the script is loaded into the gateway application.

 def init_routes( routes )
   @@routing.init routes
 end


Send the routes list to the routing objects. If you want to pre-order your routes because the priority will not change through time or because of the incoming call parameter, now it is a good time. The init_routes is called only once when the script is loaded in the gateway (think applying the configuration).

 def route( call, nap_list )
   @@routing.route call, nap_list
 end


This method order the routes, then match the call to a route, then remap the fields if there was a match.


Back to Routing Script Tutorial.

Personal tools