-
-
Save alexsosic/5a33d314d2db1832fd04166fe6615227 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
request_route { | |
$var(authpassed) = 0; | |
route(INITIATE); | |
if (route(IS_IN_DIALOG) && is_known_dlg()) { | |
route(WITHINDLG); | |
} else { | |
# check if is a dialog and it's an mine Dialog | |
t_check_trans(); | |
# do authentication | |
if($var(authpassed) == 0) route(AUTHCACHE); | |
if ($shv(log_routein) == 1) xlog("L_NOTICE", "[f:$fU-t:$tU id:$ci | $rm] Auth Passed !!\n"); | |
# Save register location | |
if (is_method("REGISTER")) { | |
route(REGISTRAR); | |
} #end if is_method(REGISTER) | |
route(RECORD_ROUTE); | |
if (is_method("INVITE")) { | |
dlg_manage(); | |
} | |
route(CGRATES); ###### Call to CGRATES | |
route(GENERAL_RELAY); | |
} #end else IS_IN_DIALOG | |
} #end request_route | |
... | |
route[CGRATES] { | |
$var(breadcrumbs) = "CGRATES"; | |
if ($shv(log_routein) == 1) xlog("L_NOTICE", "[f:$fU-t:$tU id:$ci | $rm] RouteIN $var(breadcrumbs) \n"); | |
$dlg_var(cgrReqType) = "*prepaid"; | |
$dlg_var(cgrTenant) = "evox.it"; | |
$dlg_var(cgrAccount) = $fU; | |
$dlg_var(cgrDestination) = $rU; | |
route(CGRATES_AUTH_REQUEST); # Will be answered in CGRATES_AUTH_REPLY | |
exit; | |
} | |
... | |
#KAMAILIO | |
# Kamailio-CGRateS related route blocks | |
# Called on new connection over evapi, should normally be the case of CGRateS engine | |
event_route[evapi:connection-new] { | |
$sht(cgrconn=>cgr) = $evapi(srcaddr) + ":" + $evapi(srcport); # Detect presence of at least one connection | |
xlog("L_NOTICE", "CGRateS - new connection $sht(cgrconn=>cgr)\n"); | |
} | |
# Called when the connection with CGRateS closes | |
event_route[evapi:connection-closed] { | |
$var(connClosed) = $evapi(srcaddr) + ":" + $evapi(srcport); | |
if $sht(cgrconn=>cgr) == $var(connClosed) { | |
$sht(cgrconn=>cgr) = $null; | |
} | |
} | |
# Message received from CGRateS, dispatch it to own route | |
event_route[evapi:message-received] { | |
json_get_field("$evapi(msg)", "Event", "$var(Event)"); | |
if ($shv(log_routein) == 1) xlog("L_NOTICE", "[f:$fU-t:$tU id:$ci | $rm] CGRATES Message received: $var(Event) \n"); | |
route($(var(Event){s.rm,"})); #" String characters are kept by json_get_field, remove them here | |
} | |
# Called by Kamailio on new dialog | |
event_route[dialog:start] { | |
xlog("*****************Call start!\n"); | |
route(CGR_CALL_START); | |
} | |
# Called by Kamailio on dialog end | |
event_route[dialog:end] { | |
route(CGR_CALL_END); | |
} | |
# Called by Kamailio on local disconnect | |
event_route[tm:local-request] { | |
route(CGR_CALL_END); | |
} | |
# Send AUTH_REQUEST to CGRateS | |
route[CGRATES_AUTH_REQUEST] { | |
# Auth INVITEs with CGRateS | |
if ($shv(log_routein) == 1) xlog("L_NOTICE", "[f:$fU-t:$tU id:$ci | $rm] RouteIN CGRATES_AUTH_REQUEST\n"); | |
if $sht(cgrconn=>cgr) == $null { | |
sl_send_reply("503","Charging controller unreachable"); | |
if ($shv(log_routein) == 1) xlog("L_NOTICE", "[f:$fU-t:$tU id:$ci | $rm] CGRATES_AUTH_REQUEST connection NOT ONLINE !!!! \n"); | |
exit; | |
} | |
if ($shv(log_routein) == 1) xlog("L_NOTICE", "[f:$fU-t:$tU id:$ci | $rm] CGRATES_AUTH_REQUEST connection OK \n"); | |
evapi_async_relay("{\"event\":\"CGR_AUTH_REQUEST\", | |
\"tr_index\":\"$T(id_index)\", | |
\"tr_label\":\"$T(id_label)\", | |
\"cgr_reqtype\":\"$dlg_var(cgrReqType)\", | |
\"cgr_tenant\":\"$dlg_var(cgrTenant)\", | |
\"cgr_account\":\"$dlg_var(cgrAccount)\", | |
\"cgr_destination\":\"$dlg_var(cgrDestination)\", | |
\"cgr_setuptime\":\"$TS\", | |
\"cgr_computelcr\":\"true\"}"); | |
if ($shv(log_routein) == 1) xlog("L_NOTICE", "[f:$fU-t:$tU id:$ci | $rm] CGRATES_AUTH_REQUEST evapi request sent, waiting response ... \n"); | |
} | |
# Process AUTH_REPLY from CGRateS | |
route[CGR_AUTH_REPLY] { | |
json_get_field("$evapi(msg)", "TransactionIndex", "$var(TransactionIndex)"); | |
json_get_field("$evapi(msg)", "TransactionLabel", "$var(TransactionLabel)"); | |
json_get_field("$evapi(msg)", "MaxSessionTime", "$var(MaxSessionTime)"); | |
json_get_field("$evapi(msg)", "Suppliers", "$var(Suppliers)"); | |
json_get_field("$evapi(msg)", "Error", "$var(Error)"); | |
$var(id_index) = $(var(TransactionIndex){s.int}); | |
$var(id_label) = $(var(TransactionLabel){s.int}); | |
$var(CgrMaxSessionTime) = $(var(MaxSessionTime){s.int}); | |
$var(CgrSuppliers) = $(var(Suppliers){s.rm,"}); # " | |
$var(CgrError) = $(var(Error){s.rm,"}); # " | |
xlog("L_NOTICE", "[f:$fU-t:$tU id:$ci | $rm] continuing in CGRATES_AUTH_REPLY with : $var(id_index) , $var(id_label)\n"); | |
t_continue("$var(id_index)", "$var(id_label)", "CGRATES_AUTH_REPLY"); # Unpark the transaction | |
} | |
# Send AUTH_REQUEST to CGRateS | |
route[CGRATES_LCR_REQUEST] { | |
if ($shv(log_routein) == 1) xlog("L_NOTICE", "[f:$fU-t:$tU id:$ci | $rm] RouteIN CGR_LCR_REQUEST\n"); | |
# Auth INVITEs with CGRateS | |
if $sht(cgrconn=>cgr) == $null { | |
sl_send_reply("503","Charging controller unreachable"); | |
exit; | |
} | |
evapi_async_relay("{\"event\":\"CGR_LCR_REQUEST\", | |
\"tr_index\":\"$T(id_index)\", | |
\"tr_label\":\"$T(id_label)\", | |
\"cgr_tenant\":\"$dlg_var(cgrTenant)\", | |
\"cgr_account\":\"$dlg_var(cgrAccount)\", | |
\"cgr_destination\":\"$dlg_var(cgrDestination)\", | |
\"cgr_setuptime\":\"$TS\"}"); | |
} | |
# Process LCR_REPLY from CGRateS | |
route[CGR_LCR_REPLY] { | |
if ($shv(log_routein) == 1) xlog("L_NOTICE", "[f:$fU-t:$tU id:$ci | $rm] RouteIN CGR_LCR_REPLY\n"); | |
json_get_field("$evapi(msg)", "TransactionIndex", "$var(TransactionIndex)"); | |
json_get_field("$evapi(msg)", "TransactionLabel", "$var(TransactionLabel)"); | |
json_get_field("$evapi(msg)", "MaxSessionTime", "$var(MaxSessionTime)"); | |
json_get_field("$evapi(msg)", "Suppliers", "$var(Suppliers)"); | |
json_get_field("$evapi(msg)", "Error", "$var(Error)"); | |
$var(id_index) = $(var(TransactionIndex){s.int}); | |
$var(id_label) = $(var(TransactionLabel){s.int}); | |
$var(CgrMaxSessionTime) = $(var(MaxSessionTime){s.int}); | |
$var(CgrSuppliers) = $(var(Suppliers){s.rm,"}); | |
$var(CgrError) = $(var(Error){s.rm,"}); | |
t_continue("$var(id_index)", "$var(id_label)", "CGRATES_AUTH_REPLY"); # Unpark the transaction | |
} | |
route[CGRATES_RL_REQUEST] { | |
if ($shv(log_routein) == 1) xlog("L_NOTICE", "[f:$fU-t:$tU id:$ci | $rm] RouteIN CGRATES_RL_REQUEST\n"); | |
if $sht(cgrconn=>cgr) == $null { | |
sl_send_reply("503","Charging controller unreachable"); | |
exit; | |
} | |
evapi_async_relay("{\"event\":\"CGR_RL_REQUEST\", | |
\"tr_index\":\"$T(id_index)\", | |
\"tr_label\":\"$T(id_label)\", | |
\"cgr_tenant\":\"$dlg_var(cgrTenant)\", | |
\"cgr_account\":\"$dlg_var(cgrAccount)\", | |
\"cgr_destination\":\"$dlg_var(cgrDestination)\", | |
\"cgr_setuptime\":\"$TS\"}"); | |
} | |
# Process RL_REPLY from CGRateS | |
route[CGR_RL_REPLY] { | |
if ($shv(log_routein) == 1) xlog("L_NOTICE", "[f:$fU-t:$tU id:$ci | $rm] RouteIN CGR_RL_REPLY\n"); | |
json_get_field("$evapi(msg)", "TransactionIndex", "$var(TransactionIndex)"); | |
json_get_field("$evapi(msg)", "TransactionLabel", "$var(TransactionLabel)"); | |
json_get_field("$evapi(msg)", "ResourceAllocated", "$var(ResourceAllocated)"); | |
json_get_field("$evapi(msg)", "Error", "$var(Error)"); | |
$var(id_index) = $(var(TransactionIndex){s.int}); | |
$var(id_label) = $(var(TransactionLabel){s.int}); | |
$var(CGRResourceAllocated) = $(var(ResourceAllocated){s.rm,"}); # " | |
$var(CgrError) = $(var(Error){s.rm,"}); # " | |
xlog("L_NOTICE", "[f:$fU-t:$tU id:$ci | $rm] continuing in CGRATES_RL_REPLY with : $var(id_index) , $var(id_label) allocated: $var(CGRResourceAllocated) pre: $var(ResourceAllocated)\n"); | |
t_continue("$var(id_index)", "$var(id_label)", "CGRATES_RL_REPLY"); # Unpark the transaction | |
} | |
# CGRateS request for session disconnect | |
route[CGR_SESSION_DISCONNECT] { | |
json_get_field("$evapi(msg)", "HashEntry", "$var(HashEntry)"); | |
json_get_field("$evapi(msg)", "HashId", "$var(HashId)"); | |
json_get_field("$evapi(msg)", "Reason", "$var(Reason)"); | |
jsonrpc_exec('{"jsonrpc":"2.0","id":1, "method":"dlg.end_dlg","params":[$(var(HashEntry){s.rm,"}),$(var(HashId){s.rm,"})]}'); | |
#$jsonrpl($var(reply)); | |
} | |
# Inform CGRateS about CALL_START (start prepaid sessions loops) | |
route[CGR_CALL_START] { | |
if $sht(cgrconn=>cgr) == $null { | |
xlog("Charging controller unreachable"); | |
exit; | |
} | |
evapi_relay("{\"event\":\"CGR_CALL_START\", | |
\"callid\":\"$dlg(callid)\", | |
\"from_tag\":\"$dlg(from_tag)\", | |
\"h_entry\":\"$dlg(h_entry)\", | |
\"h_id\":\"$dlg(h_id)\", | |
\"cgr_reqtype\":\"$dlg_var(cgrReqType)\", | |
\"cgr_tenant\":\"$dlg_var(cgrTenant)\", | |
\"cgr_account\":\"$dlg_var(cgrAccount)\", | |
\"cgr_destination\":\"$dlg_var(cgrDestination)\", | |
\"cgr_answertime\":\"$TS\", | |
\"cgr_supplier\":\"$dlg_var(cgrSupplier)\"}"); | |
} | |
# Inform CGRateS about CALL_END (stop debit loops, perform accounting if desired in this way) | |
route[CGR_CALL_END] { | |
if $sht(cgrconn=>cgr) == $null { | |
xlog("Charging controller unreachable"); | |
exit; | |
} | |
$var(callDur) = $TS - $dlg(start_ts); | |
evapi_relay("{\"event\":\"CGR_CALL_END\", | |
\"callid\":\"$dlg(callid)\", | |
\"from_tag\":\"$dlg(from_tag)\", | |
\"cgr_reqtype\":\"$dlg_var(cgrReqType)\", | |
\"cgr_tenant\":\"$dlg_var(cgrTenant)\", | |
\"cgr_account\":\"$dlg_var(cgrAccount)\", | |
\"cgr_destination\":\"$dlg_var(cgrDestination)\", | |
\"cgr_answertime\":\"$dlg(start_ts)\", | |
\"cgr_duration\":\"$var(callDur)\", | |
\"cgr_supplier\":\"$dlg_var(cgrSupplier)\", | |
\"cgr_disconnectcause\":\"$T_reply_code\"}"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment