There is a dialplan module,  maybe it Could help you in some topics 

Best regards 

El martes, 28 de julio de 2015, Nelson Migliaro <eng.migliaro@gmail.com> escribió:
Hello everybody,

I am currently using Kamailio in order to separate traffic based on dialed number.

Some traffic goes to several Asterisk in a load balance strategy and other traffic goes to other SIP devices.

I use carrierroute module in order to route traffic based on destination. I use scan_prefix to classify traffic and rewrite_host to route the traffic.

A destination number usually go to one of 4 asterisk server. I do this in order to load balance the traffic. In order to distribute traffic I use prob (0.25 for each destination).

Using this configuration, I have to include on carrieroute table a row for each destination node. Since the amount of destination is huge, I have to repeat configuration in tables. It also complicates maintenance.

I was thinking of using a combination of carrierroute and dispatcher module. Carrierroute for classify traffic, strip numbers, and rewrite destination host and dispatcher to distribute the traffic over asterisk. Using this configuration I have to indicate asterisk nodes once in dispatcher table once. Also in carrierroute table I have to indicate each prefix once.

I was thinking in something like this.

if(!cr_route("carrier", "domain", "$rU", "$rU", "call_id")){
     sl_send_reply("403", "Not allowed");
     drop;
}

if(!ds_select_dst("1", "4")) {
     sl_send_reply("403", "Not allowed");
     drop;
}

t_relay;

Does it make sense, or am I complicating everything and there is a magic way to achieve this.

Thank you.