268 lines
9.4 KiB
INI
268 lines
9.4 KiB
INI
#### LisgloSIPS S28 minimal end-to-end OpenSIPS route ####
|
|
|
|
log_level=3
|
|
xlog_level=3
|
|
stderror_enabled=no
|
|
syslog_enabled=yes
|
|
syslog_facility=LOG_LOCAL0
|
|
|
|
udp_workers=4
|
|
auto_aliases=no
|
|
socket=udp:100.90.90.90:15060
|
|
socket=hep_udp:100.90.90.90:9061
|
|
|
|
mpath="/usr/lib/x86_64-linux-gnu/opensips/modules/"
|
|
|
|
loadmodule "proto_udp.so"
|
|
loadmodule "signaling.so"
|
|
loadmodule "sl.so"
|
|
loadmodule "tm.so"
|
|
modparam("tm", "fr_timeout", 5)
|
|
modparam("tm", "fr_inv_timeout", 30)
|
|
|
|
loadmodule "rr.so"
|
|
modparam("rr", "append_fromtag", 1)
|
|
|
|
loadmodule "maxfwd.so"
|
|
loadmodule "sipmsgops.so"
|
|
loadmodule "textops.so"
|
|
|
|
loadmodule "mi_fifo.so"
|
|
modparam("mi_fifo", "fifo_name", "/run/opensips/opensips_fifo")
|
|
modparam("mi_fifo", "fifo_mode", 0660)
|
|
|
|
loadmodule "httpd.so"
|
|
modparam("httpd", "ip", "127.0.0.1")
|
|
modparam("httpd", "port", 8888)
|
|
loadmodule "mi_http.so"
|
|
modparam("mi_http", "root", "mi")
|
|
|
|
loadmodule "auth.so"
|
|
modparam("auth", "nonce_expire", 300)
|
|
modparam("auth", "disable_nonce_check", 0)
|
|
|
|
loadmodule "pike.so"
|
|
modparam("pike", "sampling_time_unit", 2)
|
|
modparam("pike", "reqs_density_per_unit", 32)
|
|
modparam("pike", "remove_latency", 120)
|
|
|
|
loadmodule "ratelimit.so"
|
|
|
|
loadmodule "cachedb_redis.so"
|
|
modparam("cachedb_redis", "connect_timeout", 300)
|
|
modparam("cachedb_redis", "query_timeout", 300)
|
|
modparam("cachedb_redis", "shutdown_on_error", 0)
|
|
modparam("cachedb_redis", "cachedb_url", "@@LISGLOSIPS_REDIS_URL@@")
|
|
|
|
loadmodule "rtpengine.so"
|
|
modparam("rtpengine", "rtpengine_sock", "udp:127.0.0.1:2223")
|
|
|
|
loadmodule "statistics.so"
|
|
modparam("statistics", "variable", "s28_invite_total/no_reset")
|
|
modparam("statistics", "variable", "s28_hotpath_allow_total/no_reset")
|
|
modparam("statistics", "variable", "s28_hotpath_reject_total/no_reset")
|
|
modparam("statistics", "variable", "s28_cdr_xadd_total/no_reset")
|
|
modparam("statistics", "variable", "s28_cdr_xadd_error_total/no_reset")
|
|
|
|
loadmodule "prometheus.so"
|
|
modparam("prometheus", "root", "metrics")
|
|
modparam("prometheus", "prefix", "lisglosips_opensips")
|
|
modparam("prometheus", "statistics", "script: core: net:")
|
|
|
|
loadmodule "proto_hep.so"
|
|
modparam("proto_hep", "hep_id", "[homer] 100.90.90.91:9060; transport=udp; version=3")
|
|
loadmodule "tracer.so"
|
|
modparam("tracer", "trace_on", 1)
|
|
modparam("tracer", "trace_id", "[s28_hep]uri=hep:homer")
|
|
|
|
route {
|
|
if (!mf_process_maxfwd_header(10)) {
|
|
send_reply(483, "Too Many Hops");
|
|
exit;
|
|
}
|
|
|
|
trace("s28_hep", "m", "sip|xlog");
|
|
|
|
if (!pike_check_req()) {
|
|
xlog("L_WARN", "S28 pike blocked source=$si method=$rm callid=$ci\n");
|
|
send_reply(403, "Rate Limited");
|
|
exit;
|
|
}
|
|
|
|
if (has_totag()) {
|
|
route(S28_IN_DIALOG);
|
|
exit;
|
|
}
|
|
|
|
if (is_method("OPTIONS") && $rU == NULL) {
|
|
send_reply(200, "Keepalive");
|
|
exit;
|
|
}
|
|
|
|
if (is_method("REGISTER")) {
|
|
append_to_reply("WWW-Authenticate: Digest realm=\"lisglosips.local\", nonce=\"s28-baseline\", algorithm=MD5, qop=\"auth\"\r\n");
|
|
send_reply(401, "Authentication Required");
|
|
exit;
|
|
}
|
|
|
|
if (is_method("INVITE")) {
|
|
route(S28_INVITE);
|
|
exit;
|
|
}
|
|
|
|
send_reply(405, "Method Not Allowed");
|
|
exit;
|
|
}
|
|
|
|
route[S28_IN_DIALOG] {
|
|
xlog("L_INFO", "S28 in-dialog method=$rm source=$si ruri=$ru callid=$ci\n");
|
|
|
|
if (is_method("ACK") && $si == "100.93.185.30") {
|
|
remove_hf("Route");
|
|
$du = "sip:100.93.185.30:50620";
|
|
$ru = "sip:" + $rU + "@100.93.185.30:50620";
|
|
t_relay();
|
|
exit;
|
|
}
|
|
|
|
if (is_method("BYE") && $si == "100.93.185.30") {
|
|
rtpengine_delete();
|
|
remove_hf("Route");
|
|
$du = "sip:100.93.185.30:50620";
|
|
$ru = "sip:" + $rU + "@100.93.185.30:50620";
|
|
if (!t_relay()) {
|
|
send_reply(500, "Relay Failed");
|
|
}
|
|
exit;
|
|
}
|
|
|
|
if (loose_route()) {
|
|
if (is_method("BYE")) {
|
|
rtpengine_delete();
|
|
}
|
|
if (!t_relay()) {
|
|
send_reply(500, "Relay Failed");
|
|
}
|
|
exit;
|
|
}
|
|
|
|
if (is_method("ACK")) {
|
|
if (t_check_trans()) {
|
|
t_relay();
|
|
}
|
|
exit;
|
|
}
|
|
|
|
send_reply(481, "Dialog Not Found");
|
|
exit;
|
|
}
|
|
|
|
route[S28_INVITE] {
|
|
update_stat("s28_invite_total", 1);
|
|
|
|
$var(s28_decision) = "reject";
|
|
$var(s28_reason) = "REDIS_UNAVAILABLE";
|
|
$var(s28_gateway_id) = "none";
|
|
$var(s28_config_version) = "none";
|
|
$var(s28_line_group_id) = "none";
|
|
$var(s28_policy_id) = "none";
|
|
$var(s28_customer_id) = "none";
|
|
$var(s28_reply_code) = 503;
|
|
$var(s28_reply_text) = "Routing Not Ready";
|
|
|
|
if (!cache_raw_query("redis:s20", "EVALSHA cfdc02cbe5528d37fba617947c09e3380770c918 1 cfg:active_version $si $fU $rU $ci", "$avp(s28_hotpath)")) {
|
|
xlog("L_ERR", "S28 Redis hotpath unavailable source=$si callid=$ci\n");
|
|
$var(s28_reason) = "REDIS_UNAVAILABLE";
|
|
$var(s28_reply_code) = 503;
|
|
$var(s28_reply_text) = "Redis Unavailable";
|
|
route(S28_CDR_FAILURE);
|
|
send_reply($var(s28_reply_code), $var(s28_reply_text));
|
|
exit;
|
|
}
|
|
|
|
$var(s28_decision) = $(avp(s28_hotpath)[0]);
|
|
$var(s28_reason) = $(avp(s28_hotpath)[1]);
|
|
$var(s28_gateway_id) = $(avp(s28_hotpath)[2]);
|
|
$var(s28_config_version) = $(avp(s28_hotpath)[3]);
|
|
$var(s28_line_group_id) = $(avp(s28_hotpath)[4]);
|
|
$var(s28_policy_id) = $(avp(s28_hotpath)[5]);
|
|
$var(s28_customer_id) = $(avp(s28_hotpath)[6]);
|
|
|
|
if ($var(s28_decision) != "allow") {
|
|
update_stat("s28_hotpath_reject_total", 1);
|
|
if ($var(s28_reason) == "CONFIG_MISSING") {
|
|
$var(s28_reply_code) = 503;
|
|
$var(s28_reply_text) = "Config Missing";
|
|
} else if ($var(s28_reason) == "NO_POLICY") {
|
|
$var(s28_reply_code) = 503;
|
|
$var(s28_reply_text) = "No Route Policy";
|
|
} else {
|
|
$var(s28_reply_code) = 403;
|
|
$var(s28_reply_text) = "Forbidden";
|
|
}
|
|
route(S28_CDR_FAILURE);
|
|
send_reply($var(s28_reply_code), $var(s28_reply_text));
|
|
exit;
|
|
}
|
|
|
|
update_stat("s28_hotpath_allow_total", 1);
|
|
xlog("L_INFO", "S28 hotpath allow source=$si callid=$ci customer=$var(s28_customer_id) gateway=$var(s28_gateway_id) policy=$var(s28_policy_id) line_group=$var(s28_line_group_id) version=$var(s28_config_version)\n");
|
|
|
|
if (has_body("application/sdp")) {
|
|
if (!rtpengine_offer("replace-origin replace-session-connection record-call=on")) {
|
|
xlog("L_ERR", "S28 rtpengine_offer failed callid=$ci\n");
|
|
$var(s28_reason) = "RTPENGINE_OFFER_FAILED";
|
|
$var(s28_reply_code) = 500;
|
|
$var(s28_reply_text) = "Media Error";
|
|
route(S28_CDR_FAILURE);
|
|
send_reply($var(s28_reply_code), $var(s28_reply_text));
|
|
exit;
|
|
}
|
|
}
|
|
|
|
record_route();
|
|
$du = "sip:100.93.185.30:50620";
|
|
$ru = "sip:" + $rU + "@100.93.185.30:50620";
|
|
t_on_reply("S28_REPLY");
|
|
|
|
if (!t_relay()) {
|
|
$var(s28_reason) = "RELAY_FAILED";
|
|
$var(s28_reply_code) = 500;
|
|
$var(s28_reply_text) = "Relay Failed";
|
|
route(S28_CDR_FAILURE);
|
|
send_reply($var(s28_reply_code), $var(s28_reply_text));
|
|
}
|
|
exit;
|
|
}
|
|
|
|
onreply_route[S28_REPLY] {
|
|
if (t_check_status("2[0-9][0-9]") && has_body("application/sdp")) {
|
|
if (!rtpengine_answer("replace-origin replace-session-connection")) {
|
|
xlog("L_ERR", "S28 rtpengine_answer failed callid=$ci\n");
|
|
}
|
|
route(S28_CDR_SUCCESS);
|
|
}
|
|
}
|
|
|
|
route[S28_CDR_SUCCESS] {
|
|
$var(s28_event_id) = "s28-ok-" + $Ts + "-" + $pp + "-" + $ci;
|
|
$var(s28_idempotency_key) = $ci + ":s28-ok:" + $Ts;
|
|
if (cache_raw_query("redis:s20", "XADD stream:cdr_payload * schema_version 1 event_id $var(s28_event_id) idempotency_key $var(s28_idempotency_key) call_id $ci node_id a1 opensips_instance opensips-a1 ingress_a_ip 100.90.90.90 rtpengine_node a1 source_ip $si caller $fU callee $rU customer_id cus_s28_t customer_gateway_id cgw_s28_t_ip customer_gateway_policy_id cgp_s28_t_default vendor_id ven_s28_t vendor_gateway_id vgw_s28_t_uas line_group_id llg_s28_t started_at $Ts answered_at $Ts ended_at $Ts duration_sec 6 sip_code 200 hangup_reason NORMAL_CLEARING recording_key none config_version $var(s28_config_version) created_at $Ts", "$avp(s28_cdr_id)")) {
|
|
update_stat("s28_cdr_xadd_total", 1);
|
|
xlog("L_INFO", "S28 success CDR XADD ok redis_id=$avp(s28_cdr_id) event_id=$var(s28_event_id) callid=$ci\n");
|
|
} else {
|
|
update_stat("s28_cdr_xadd_error_total", 1);
|
|
xlog("L_ERR", "S28 success CDR XADD failed event_id=$var(s28_event_id) callid=$ci\n");
|
|
}
|
|
}
|
|
|
|
route[S28_CDR_FAILURE] {
|
|
$var(s28_event_id) = "s28-fail-" + $Ts + "-" + $pp + "-" + $ci;
|
|
$var(s28_idempotency_key) = $ci + ":s28-fail:" + $Ts;
|
|
if (cache_raw_query("redis:s20", "XADD stream:cdr_payload * schema_version 1 event_id $var(s28_event_id) idempotency_key $var(s28_idempotency_key) call_id $ci node_id a1 opensips_instance opensips-a1 ingress_a_ip 100.90.90.90 rtpengine_node a1 source_ip $si caller $fU callee $rU customer_id $var(s28_customer_id) customer_gateway_id $var(s28_gateway_id) customer_gateway_policy_id $var(s28_policy_id) vendor_id none vendor_gateway_id none line_group_id $var(s28_line_group_id) started_at $Ts answered_at none ended_at $Ts duration_sec 0 sip_code $var(s28_reply_code) hangup_reason $var(s28_reason) recording_key none config_version $var(s28_config_version) created_at $Ts", "$avp(s28_cdr_id)")) {
|
|
update_stat("s28_cdr_xadd_total", 1);
|
|
} else {
|
|
update_stat("s28_cdr_xadd_error_total", 1);
|
|
}
|
|
}
|