mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 05:39:54 +05:00
Updating tutorial2 sample .csvs and few of the docs for installing with OpenSIPS
This commit is contained in:
@@ -187,6 +187,7 @@ route[CGR_CALL_END] {
|
||||
\"AnswerTime\":\"$dlg(start_ts)\",
|
||||
\"PaypalAccount\":\"$dlg_var(paypalAccount)\",
|
||||
\"SetupTime\":\"$dlg_var(SetupTime)\",
|
||||
\"Usage\":\"$var(callDur)\"}");
|
||||
\"Usage\":\"$var(callDur)\",
|
||||
\"Supplier\":\"$dlg_var(cgrSupplier)\"}");
|
||||
}
|
||||
|
||||
|
||||
@@ -15,10 +15,6 @@
|
||||
debug=2
|
||||
log_stderror=no
|
||||
|
||||
listen=udp:enp0s3:5060
|
||||
listen=udp:127.0.0.1:5080
|
||||
listen=udp:127.0.0.1:5060
|
||||
listen=udp:enp0s3:5080
|
||||
|
||||
memdbg=5
|
||||
memlog=5
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
# re-generating the scenario with different options.#
|
||||
#
|
||||
# Please refer to the Core CookBook at:
|
||||
# https://opensips.org/Resources/DocsCookbooks
|
||||
# http://www.opensips.org/Resources/DocsCookbooks
|
||||
# for a explanation of possible statements, functions and parameters.
|
||||
#
|
||||
|
||||
@@ -23,11 +23,7 @@ udp_workers=4
|
||||
|
||||
auto_aliases=no
|
||||
|
||||
listen=udp:enp0s3:5060
|
||||
listen=udp:127.0.0.1:5080
|
||||
listen=udp:127.0.0.1:5060
|
||||
listen=udp:enp0s3:5080
|
||||
|
||||
socket=udp:enp0s8:5060
|
||||
|
||||
|
||||
####### Modules Section ########
|
||||
@@ -85,7 +81,15 @@ loadmodule "proto_udp.so"
|
||||
#### CGRateS module
|
||||
loadmodule "dialog.so"
|
||||
loadmodule "cgrates.so"
|
||||
modparam("cgrates", "cgrates_engine", "127.0.0.1:2014")
|
||||
modparam("cgrates", "cgrates_engine", "192.168.56.111:2014")
|
||||
|
||||
#### MySQL module
|
||||
loadmodule "db_mysql.so"
|
||||
|
||||
#### Drouting module
|
||||
loadmodule "drouting.so"
|
||||
modparam("drouting", "db_url",
|
||||
"mysql://opensips:opensipsrw@localhost/opensips")
|
||||
|
||||
|
||||
####### Routing Logic ########
|
||||
@@ -201,7 +205,7 @@ route{
|
||||
# check auth with CGRateS
|
||||
$cgr_opt(GetMaxUsage) = 1; # also retrieve the max usage
|
||||
$cgr_opt(GetAttributes) = 1;
|
||||
$cgr_opt(GetSuppliers) = 1;
|
||||
$cgr_opt(GetRoutes) = 1;
|
||||
$cgr_opt(AuthorizeResources) = 1;
|
||||
$cgr_opt(AllocateResources) = 1;
|
||||
$cgr_opt(ReleaseResources) = 1;
|
||||
@@ -218,29 +222,96 @@ route{
|
||||
}
|
||||
|
||||
route [resume_cgr_auth] {
|
||||
if ($rc != 1) {
|
||||
xlog("Call not authorized: code=$cgrret!\n");
|
||||
$var(rc) = $rc;
|
||||
# with GetMaxUsage == false, cgrates_auth() returns -2 on success
|
||||
if ($var(rc) < 0 && ($cgr_ret(MaxUsage) != 0 || $var(rc) != -2)) {
|
||||
xlog("L_NOTICE", "[$ci] CGRateS auth failed: rc=$var(rc), code=$cgr_ret\n");
|
||||
send_reply(403, "Forbidden");
|
||||
exit;
|
||||
}
|
||||
|
||||
# Set the returned attributes from CGRateS as script pseudovariables
|
||||
$var(idx) = 0;
|
||||
while ($(cgr_ret(AttributesDigest){s.select,$var(idx),,}) != NULL) {
|
||||
$avp($(cgr_ret(AttributesDigest){s.select,$var(idx),,}{s.select,0,:}))
|
||||
= $(cgr_ret(AttributesDigest){s.select,$var(idx),,}{s.select,1,:});
|
||||
$var(idx) = $var(idx) + 1;
|
||||
}
|
||||
cgrates_acc("cdr|missed", "$fU", "$rU");
|
||||
xlog("### Have authorized the call and it should go through");
|
||||
route(relay);
|
||||
|
||||
# Enable CDRs being sent to CGRateS
|
||||
cgrates_acc("cdr|missed", "$fU", "$rU");
|
||||
|
||||
if ( $cgr_ret(RoutesDigest)==NULL ) { # no routing requested
|
||||
route(relay);
|
||||
}
|
||||
|
||||
xlog("L_INFO", "[$ci] CGRateS auth OK, with routes: <$cgr_ret(RoutesDigest)>\n");
|
||||
$avp(carriers) := $cgr_ret(RoutesDigest);
|
||||
$avp(carriers_idx) := 0;
|
||||
|
||||
route( to_carriers );
|
||||
}
|
||||
|
||||
|
||||
route[to_carriers] {
|
||||
|
||||
xlog("L_INFO", "[$ci] routing to carrier IDX $avp(carriers_idx)\n");
|
||||
|
||||
$var(carrier) = $(avp(carriers){s.select,$avp(carriers_idx),,});
|
||||
if ( $var(carrier) == NULL) {
|
||||
send_reply( 404 , "No route available to route");
|
||||
exit;
|
||||
}
|
||||
$cgr(RouteID) = $var(carrier);
|
||||
|
||||
xlog("L_INFO", "[$ci] routing to carrier <$var(carrier)>\n");
|
||||
$avp(carriers_idx) := $avp(carriers_idx) + 1;
|
||||
|
||||
#if ( !route_to_carrier("$var(carrier)") ) {
|
||||
# xlog("L_INFO", "[$ci] failed to route to carrier, skipping>\n");
|
||||
# route( to_carriers );
|
||||
# exit;
|
||||
#}
|
||||
|
||||
t_on_failure("gw_failure");
|
||||
t_relay();
|
||||
|
||||
#end;
|
||||
|
||||
}
|
||||
|
||||
failure_route[gw_failure] {
|
||||
xlog("L_INFO", "[$ci] GW call failed to established with $T_reply_code code\n");
|
||||
|
||||
if (t_was_cancelled()) {
|
||||
exit;
|
||||
}
|
||||
|
||||
# failure indication about GWs?
|
||||
if ( t_check_status("(408)|([56][0-9][0-9])") ) {
|
||||
xlog("L_INFO", "[$ci] GW $rd failed with $T_reply_code -> retry\n");
|
||||
if ( use_next_gw() ) {
|
||||
xlog("L_INFO", "[$ci] using new GW <$rd>\n");
|
||||
t_on_failure("gw_failure");
|
||||
t_relay();
|
||||
#end
|
||||
}
|
||||
|
||||
# no more GWs for the carrier, try the next carrier
|
||||
route( to_carriers );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
route[relay] {
|
||||
# for INVITEs enable some additional helper routes
|
||||
if (is_method("INVITE")) {
|
||||
t_on_branch("per_branch_ops");
|
||||
t_on_reply("handle_nat");
|
||||
t_on_failure("missed_call");
|
||||
t_on_reply("handle_reply");
|
||||
t_on_failure("handle_failure");
|
||||
}
|
||||
|
||||
if (!t_relay()) {
|
||||
@@ -257,13 +328,13 @@ branch_route[per_branch_ops] {
|
||||
}
|
||||
|
||||
|
||||
onreply_route[handle_nat] {
|
||||
onreply_route[handle_reply] {
|
||||
xlog("incoming reply\n");
|
||||
}
|
||||
|
||||
|
||||
failure_route[missed_call] {
|
||||
failure_route[handle_failure] {
|
||||
if (t_was_cancelled()) {
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user