mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-25 00:58:45 +05:00
Adding LCR processing to SM-Kamailio
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
# 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
|
||||
}
|
||||
|
||||
# Called when the connection with CGRateS closes
|
||||
event_route[evapi:connection-closed] {
|
||||
$var(connClosed) = $evapi(srcaddr) + ":" + $evapi(srcport);
|
||||
if $sht(cgrconn=>cgr) == $var(connClosed) {
|
||||
@@ -12,44 +13,29 @@ event_route[evapi:connection-closed] {
|
||||
}
|
||||
}
|
||||
|
||||
# Message received from CGRateS, dispatch it to own route
|
||||
event_route[evapi:message-received] {
|
||||
json_get_field("$evapi(msg)", "Event", "$var(Event)");
|
||||
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] {
|
||||
route(CGR_CALL_START);
|
||||
}
|
||||
|
||||
# Called by Kamailio on dialog end
|
||||
event_route[dialog:end] {
|
||||
route(CGR_CALL_END);
|
||||
}
|
||||
|
||||
# Send AUTH_REQUEST to CGRateS
|
||||
route[CGR_AUTH_REQUEST] {
|
||||
route[CGRATES_AUTH_REQUEST] {
|
||||
# Auth INVITEs with CGRateS
|
||||
if $sht(cgrconn=>cgr) == $null {
|
||||
sl_send_reply("503","Charging controller unreachable");
|
||||
exit;
|
||||
}
|
||||
switch ($fU) {
|
||||
case 1001:
|
||||
case 1006:
|
||||
case 1007:
|
||||
$dlg_var(cgrReqType) = "*prepaid";
|
||||
break;
|
||||
case 1002:
|
||||
$dlg_var(cgrReqType) = "*postpaid";
|
||||
break;
|
||||
case 1003:
|
||||
$dlg_var(cgrReqType) = "*pseudoprepaid";
|
||||
break;
|
||||
default:
|
||||
$dlg_var(cgrReqType) = "*rated";
|
||||
}
|
||||
$dlg_var(cgrTenant) = "cgrates.org";
|
||||
$dlg_var(cgrAccount) = $fU;
|
||||
$dlg_var(cgrDestination) = $rU;
|
||||
evapi_async_relay("{\"event\":\"CGR_AUTH_REQUEST\",
|
||||
\"tr_index\":\"$T(id_index)\",
|
||||
\"tr_label\":\"$T(id_label)\",
|
||||
@@ -57,7 +43,8 @@ route[CGR_AUTH_REQUEST] {
|
||||
\"cgr_tenant\":\"$dlg_var(cgrTenant)\",
|
||||
\"cgr_account\":\"$dlg_var(cgrAccount)\",
|
||||
\"cgr_destination\":\"$dlg_var(cgrDestination)\",
|
||||
\"cgr_setuptime\":\"$TS\"}");
|
||||
\"cgr_setuptime\":\"$TS\",
|
||||
\"cgr_computelcr\":\"true\"}");
|
||||
}
|
||||
|
||||
# Process AUTH_REPLY from CGRateS
|
||||
@@ -65,25 +52,12 @@ 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)", "AuthError", "$var(AuthError)");
|
||||
json_get_field("$evapi(msg)", "Suppliers", "$avp(CgrSuppliers)");
|
||||
json_get_field("$evapi(msg)", "Error", "$avp(CgrError)");
|
||||
$var(id_index) = $(var(TransactionIndex){s.int});
|
||||
$var(id_label) = $(var(TransactionLabel){s.int});
|
||||
$var(max_session_time) = $(var(MaxSessionTime){s.int});
|
||||
t_continue("$var(id_index)", "$var(id_label)", "CGR_DIALOG_TIMEOUT");
|
||||
}
|
||||
|
||||
# Check AUTH_REPLY for errors and set dialog timeout if necessary, call route(RELAY) after processing
|
||||
route[CGR_DIALOG_TIMEOUT] {
|
||||
if $var(AuthError) != "null" { # null is converted in string by json_get_field
|
||||
xlog("CGR_AUTH_ERROR: $var(AuthError)");
|
||||
sl_send_reply("503","CGR_AUTH_ERROR");
|
||||
exit;
|
||||
}
|
||||
if $var(max_session_time) != -1 && !dlg_set_timeout("$var(max_session_time)") {
|
||||
sl_send_reply("503","CGR_MAX_SESSION_TIME_ERROR");
|
||||
exit;
|
||||
}
|
||||
route(RELAY);
|
||||
$avp(CgrMaxSessionTime) = $(var(MaxSessionTime){s.int});
|
||||
t_continue("$var(id_index)", "$var(id_label)", "CGRATES_AUTH_REPLY"); # Unpark the transaction
|
||||
}
|
||||
|
||||
# CGRateS request for session disconnect
|
||||
@@ -129,4 +103,5 @@ route[CGR_CALL_END] {
|
||||
\"cgr_destination\":\"$dlg_var(cgrDestination)\",
|
||||
\"cgr_answertime\":\"$dlg(start_ts)\",
|
||||
\"cgr_duration\":\"$var(callDur)\"}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -167,10 +167,45 @@ request_route {
|
||||
route(RELAY);
|
||||
}
|
||||
dlg_manage();
|
||||
route(CGR_AUTH_REQUEST);
|
||||
switch ($fU) {
|
||||
case 1001:
|
||||
case 1006:
|
||||
case 1007:
|
||||
$dlg_var(cgrReqType) = "*prepaid";
|
||||
break;
|
||||
case 1002:
|
||||
$dlg_var(cgrReqType) = "*postpaid";
|
||||
break;
|
||||
case 1003:
|
||||
$dlg_var(cgrReqType) = "*pseudoprepaid";
|
||||
break;
|
||||
default:
|
||||
$dlg_var(cgrReqType) = "*rated";
|
||||
}
|
||||
$dlg_var(cgrTenant) = "cgrates.org";
|
||||
$dlg_var(cgrAccount) = $fU;
|
||||
$dlg_var(cgrDestination) = $rU;
|
||||
route(CGRATES_AUTH_REQUEST); # Will be answered in CGRATES_AUTH_REPLY
|
||||
exit;
|
||||
}
|
||||
|
||||
# Here will land requests after processing them with CGRateS. Call RELAY or other routes following this route
|
||||
route[CGRATES_AUTH_REPLY] {
|
||||
if $avp(CgrError) != "null" { # null is converted in string by json_get_field
|
||||
xlog("CGR_AUTH_ERROR: $avp(CgrError)");
|
||||
sl_send_reply("503","CGR_ERROR");
|
||||
exit;
|
||||
}
|
||||
if $avp(CgrMaxSessionTime) != -1 && !dlg_set_timeout("$avp(CgrMaxSessionTime)") {
|
||||
sl_send_reply("503","CGR_MAX_SESSION_TIME_ERROR");
|
||||
exit;
|
||||
}
|
||||
if $avp(CgrSuppliers) != "" { # Enforce the supplier variable to the first one received from CGRateS, more for testing purposes
|
||||
$dlg_var(supplier) = $(avp(CgrSuppliers){s.select,0,,});
|
||||
}
|
||||
route(RELAY);
|
||||
}
|
||||
|
||||
# Wrapper for relaying requests
|
||||
route[RELAY] {
|
||||
# enable additional event routes for forwarded requests
|
||||
|
||||
Reference in New Issue
Block a user