-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcarrier.cfg
135 lines (116 loc) · 4.11 KB
/
carrier.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
route[is_carrier]{
xlog("L_INFO","Inroute source is carrier");
//HMSET customer:7045 routeId 23456 balance 700
redis_cmd("redis","HGET customer:$avp(custId) routeId","r");
$avp(routeId)=$redis(r=>value);
//check abuse caller
redis_cmd("redis","SISMEMBER abuse:$avp(called_number) $avp(caller_id)","r");
if($redis(r=>value[0])==1){
sl_send_reply("486","Busy Here");
exit;
}
route(did_channels_check);
if($avp(routingType)==1){
//direct routing could be IP address or Phone number or Username
redis_cmd("redis","HMGET direct:$avp(called_number) dstUri dnis","r");
if($redis(r=>value[0])!=0){
$avp(dstUri)=$redis(r=>value[0]);
$avp(dnis)=$redis(r=>value[1]);
}
}else{
sl_send_reply("500","Internal Server Error");
exit;
}
route(rtp_engine);
route(relay_out);
}
route[relay_out]{
xlog("L_INFO","Call routing identity is $avp(dstUri) rtpProxy = $sht(rtpProxy=>mip_$ci)");
$avp(identity)=$(avp(dstUri){s.select,0,:});
$avp(port)=$(avp(dstUri){s.select,1,:});
$avp(dstUrilen)=$(avp(identity){s.len});
if(is_ip($avp(identity))){
//TODO dnis for the called number
//call is routed to IP address and the DNIS should be same as called number
xlog("L_INFO","identity is IP Address identity : $avp(identity) and port : $avp(port)");
$rU=$avp(dnis);
$rd=$avp(identity);
$rp=$avp(port);
$var(duri) = "sip:"+$rU+"@"+$avp(identity)+":"+$avp(port);
$du = $var(duri);
t_on_failure("dst_failure");
t_on_reply("dst_reply");
if(!t_relay()) {
sl_reply_error();
exit;
}
exit;
}
if($avp(dstUrilen)>7){
xlog("L_INFO","PSTN number ROUTING");
$rU=$avp(dnis);
$avp(called_number)=$avp(dnis);
route(pstn_forward);
}
}
onreply_route[dst_reply]{
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","the call was answered and ANSWERED flag was will be set now");
setflag(ANSWERED);
$avp(sip_code)=$T_reply_code;
$avp(sip_reason)=$T_reply_reason;
route(SET_CDR);
route(rtp_engine);
}
}
}
failure_route[dst_failure]{
xlog("L_INFO","failure route ; $T_reply_code");
if(t_is_canceled() || t_check_status("487") || t_check_status("404") || t_check_status("486")) {
xlog("L_INFO","Incase of a cancelled / Invalid call Attempt $rm ; Inbound call");
setflag(CANCELLED);
$avp(sip_code)=$T_reply_code;
$avp(sip_reason)=$T_reply_reason;
xlog("L_INFO","cancelled call ; sip_code :$avp(sip_code) ; sip_reason: $avp(sip_reason)");
route(SET_CDR);
route(rtp_engine);
acc_db_request("Canceled call", "failed_sessions");
exit;
}
if(t_check_status("408|403")){
xlog("L_INFO","failure route 408");
$avp(inv_timer) = 17;
$avp(sip_code)=$T_reply_code;
$avp(sip_reason)=$T_reply_reason;
route(SET_CDR);
acc_db_request("Canceled call", "failed_sessions");
exit;
}
if(t_check_status("480")){
xlog("L_INFO","failure route 480");
setflag(CANCELLED);
$avp(sip_code)=$T_reply_code;
$avp(sip_reason)=$T_reply_reason;
route(SET_CDR);
route(rtp_engine);
acc_db_request("Temp Unavailable", "failed_sessions");
exit;
}
if(isflagset(RINGING)){
//Incase a call fails after a 18X provisional response
xlog("L_INFO","The call had already received a 180 0r 183 and then failed $T_reply_code $rm");
$avp(sip_code)=$T_reply_code;
$avp(sip_reason)=$T_reply_reason;
route(SET_CDR);
acc_db_request("RINGING", "failed_sessions");
resetflag(RINGING);
exit;
}
}