-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathpstn_dest.cfg
154 lines (130 loc) · 4.82 KB
/
pstn_dest.cfg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
route[pstn_forward]{
$avp(position)=1;
$avp(dstlist_id)=0;
route(get_carriers);
if($avp(failovers)==$null){
$avp(sip_code)="500";
$avp(sip_reason)="No More Carriers";
route(SET_CDR);
acc_db_request("No More Carriers", "failed_calls");
xlog("L_INFO","No More Carriers");
sl_send_reply("500","No More Carriers");
exit;
}
$avp(max_attempts)=$var(max_attempts);
xlog("L_INFO","The max call attempts are $avp(max_attempts)");
$avp(call_attempts)=0;
route(carrier_routing);
exit;
}
route[get_carriers]{
redis_cmd("redis","evalsha ed298d3856ca8aeadde716def3ac0d9a72059740 0 $avp(routeId) $avp(dstlist_id) $avp(position) $avp(called_number)","r");
if($redis(r=>value[0])!=0){
$avp(failovers)=$redis(r=>size);
$avp(carrier)=$redis(r=>value[0]);
$var(c)=$avp(failovers)-1;
while($var(c)!=-1){
$(avp(carrier)[$var(c)]) = $redis(r=>value[$var(c)]);
#--xlog("L_INFO","Carrier $var(c) $redis(r=>value[$var(c)])");
$var(c)=$var(c)-1;
}
}
}
route[carrier_routing]{
xlog("L_INFO","call variables $avp(call_attempts) : $avp(max_attempts) ");
if($avp(call_attempts)<$avp(max_attempts)){
if($avp(call_attempts)<$avp(failovers)){
$avp(carrier_id)=$(avp(carrier)[$avp(call_attempts)]{s.select,0,:});
$avp(dst_carrier_rate)=$(avp(carrier)[$avp(call_attempts)]{s.select,1,:});
$avp(carrier_prefix)=$(avp(carrier)[$avp(call_attempts)]{s.select,2,:});
xlog("L_INFO", "carrier_routing: carrier Id is $avp(carrier_id) ; dst_carrier_rate : $avp(dst_carrier_rate) ; carrier_prefix: $avp(carrier_prefix) Attempt no : $avp(call_attempts)");
route(carrier_fetch_ip);
route(carrier_relay);
}
}else{
xlog("L_INFO","MAX Attempts reached");
}
exit;
}
route[carrier_fetch_ip]{
redis_cmd("redis","SRANDMEMBER carrierOutIps:$avp(carrier_id)","r");
$avp(domain_port)=$redis(r=>value);
if(is_avp_set("$avp(domain_port)")){
$avp(domain)=$(avp(domain_port){s.select,0,:});
$avp(port)=$(avp(domain_port){s.select,1,:});
}else{
$avp(call_attempts)=$avp(call_attempts)+1;
//xlog("L_INFO","INC call_attempts $avp(call_attempts)");
route(carrier_routing);
}
}
route[carrier_relay]{
route(rtp_engine);
$rd=$avp(domain);
$rp=$avp(port);
t_on_failure("carrier_failover");
t_on_reply("carrier_reply");
$var(duri) = "sip:"+$rU+"@"+$rd+":"+$rp;
$du = $var(duri);
xlog("L_INFO","relayed $avp(domain):$avp(port) $avp(called_number) $var(duri) $du");
if (!t_relay()) {
sl_reply_error();
}
exit;
}
failure_route[carrier_failover]{
if(t_is_canceled() || t_check_status("487") || t_check_status("404") ) {
//Incase of a cancelled / Invalid call Attempt
xlog("L_INFO","Incase of a cancelled / Invalid call Attempt $rm");
setflag(CANCELLED);
$avp(sip_code)=$T_reply_code;
$avp(sip_reason)=$T_reply_reason;
route(SET_CDR);
route(rtp_engine);
acc_db_request("Some comment", "failed_calls");
exit;
}
if(isflagset(RINGING)){
//Incase a call fails after a 18X provisional response || t_check_status("486")
xlog("L_INFO","The call had already received a 180 0r 183 and then failed");
$avp(sip_code)=$T_reply_code;
$avp(sip_reason)=$T_reply_reason;
route(SET_CDR);
acc_db_request("FAILED AFTER SESSION PROGRESS", "failed_calls");
setflag(CANCELLED);
route(rtp_engine);
resetflag(RINGING);
exit;
}
//Incase a call fails otherwise
$avp(sip_code)=$T_reply_code;
$avp(sip_reason)=$T_reply_reason;
route(SET_CDR);
acc_db_request("Some comment", "failed_sessions");
xlog("L_INFO","InRoute carrier_failover route $avp(call_attempts) ; $T_reply_code");
$avp(call_attempts)=$avp(call_attempts)+1;
route(carrier_routing);
exit;
}
onreply_route[carrier_reply]{
if(status == "100") {
$avp(inv_timer) = 17;
//xlog("L_INFO","100 trying");
}
if(status == "180" || status == "183") {
//xlog("L_INFO","ringing");
$avp(inv_timer) = 45;
//do not fail-over call now as we have a provisional response
setflag(RINGING);
}
if(status == "200") {
if(!isflagset(ANSWERED)){
xlog("L_INFO","received 200ok in dst_carrier route $ci answer_timestamp : $TS");
setflag(ANSWERED);
$avp(sip_code)=$T_reply_code;
$avp(sip_reason)=$T_reply_reason;
route(SET_CDR);
route(rtp_engine);
}
}
}