Files
lisglosips/infra/server-a/s20/opensips/opensips.cfg

187 lines
6.4 KiB
INI

#### LisgloSIPS S20 OpenSIPS Redis hot path, HEP and metrics baseline ####
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 "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", 16)
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", "s20_invite_total/no_reset")
modparam("statistics", "variable", "s20_hotpath_allow_total/no_reset")
modparam("statistics", "variable", "s20_hotpath_reject_total/no_reset")
modparam("statistics", "variable", "s20_redis_error_total/no_reset")
modparam("statistics", "variable", "s20_cdr_xadd_total/no_reset")
modparam("statistics", "variable", "s20_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", "[s20_hep]uri=hep:homer")
route {
if (!mf_process_maxfwd_header(10)) {
send_reply(483, "Too Many Hops");
exit;
}
trace("s20_hep", "m", "sip|xlog");
if (!pike_check_req()) {
xlog("L_WARN", "S20 pike blocked source=$si method=$rm callid=$ci\n");
send_reply(403, "Rate Limited");
exit;
}
if (has_totag()) {
send_reply(481, "Dialog Not Found");
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=\"s20-baseline\", algorithm=MD5, qop=\"auth\"\r\n");
send_reply(401, "Authentication Required");
exit;
}
if (is_method("INVITE")) {
route(S20_INVITE);
exit;
}
send_reply(405, "Method Not Allowed");
exit;
}
route[S20_INVITE] {
update_stat("s20_invite_total", 1);
$var(s20_decision) = "reject";
$var(s20_reason) = "REDIS_UNAVAILABLE";
$var(s20_gateway_id) = "none";
$var(s20_config_version) = "none";
$var(s20_line_group_id) = "none";
$var(s20_policy_id) = "none";
$var(s20_customer_id) = "none";
$var(s20_reply_code) = 503;
$var(s20_reply_text) = "Routing Not Ready";
if (!cache_raw_query("redis:s20", "EVALSHA cfdc02cbe5528d37fba617947c09e3380770c918 1 cfg:active_version $si $fU $rU $ci", "$avp(s20_hotpath)")) {
update_stat("s20_redis_error_total", 1);
xlog("L_ERR", "S20 Redis hotpath unavailable source=$si callid=$ci\n");
$var(s20_reason) = "REDIS_UNAVAILABLE";
$var(s20_reply_code) = 503;
$var(s20_reply_text) = "Redis Unavailable";
route(S20_CDR_XADD);
send_reply($var(s20_reply_code), $var(s20_reply_text));
exit;
}
$var(s20_decision) = $(avp(s20_hotpath)[0]);
$var(s20_reason) = $(avp(s20_hotpath)[1]);
$var(s20_gateway_id) = $(avp(s20_hotpath)[2]);
$var(s20_config_version) = $(avp(s20_hotpath)[3]);
$var(s20_line_group_id) = $(avp(s20_hotpath)[4]);
$var(s20_policy_id) = $(avp(s20_hotpath)[5]);
$var(s20_customer_id) = $(avp(s20_hotpath)[6]);
if ($var(s20_decision) == "allow") {
update_stat("s20_hotpath_allow_total", 1);
xlog("L_INFO", "S20 hotpath allow source=$si callid=$ci customer=$var(s20_customer_id) gateway=$var(s20_gateway_id) policy=$var(s20_policy_id) line_group=$var(s20_line_group_id) version=$var(s20_config_version)\n");
$var(s20_reason) = "ROUTING_NOT_READY";
$var(s20_reply_code) = 503;
$var(s20_reply_text) = "Routing Not Ready";
route(S20_CDR_XADD);
send_reply($var(s20_reply_code), $var(s20_reply_text));
exit;
}
update_stat("s20_hotpath_reject_total", 1);
if ($var(s20_reason) == "CONFIG_MISSING") {
$var(s20_reply_code) = 503;
$var(s20_reply_text) = "Config Missing";
} else if ($var(s20_reason) == "NO_POLICY") {
$var(s20_reply_code) = 503;
$var(s20_reply_text) = "No Route Policy";
} else {
$var(s20_reply_code) = 403;
$var(s20_reply_text) = "Forbidden";
}
xlog("L_WARN", "S20 hotpath reject reason=$var(s20_reason) source=$si callid=$ci version=$var(s20_config_version)\n");
route(S20_CDR_XADD);
send_reply($var(s20_reply_code), $var(s20_reply_text));
exit;
}
route[S20_CDR_XADD] {
$var(s20_event_id) = "s20-" + $Ts + "-" + $pp + "-" + $ci;
if (cache_raw_query("redis:s20", "XADD stream:cdr_payload * event_id $var(s20_event_id) call_id $ci source_ip $si caller $fU callee $rU customer_id $var(s20_customer_id) customer_gateway_id $var(s20_gateway_id) customer_gateway_policy_id $var(s20_policy_id) line_group_id $var(s20_line_group_id) sip_code $var(s20_reply_code) hangup_reason $var(s20_reason) config_version $var(s20_config_version) created_at_unix $Ts", "$avp(s20_cdr_id)")) {
update_stat("s20_cdr_xadd_total", 1);
xlog("L_INFO", "S20 CDR XADD ok redis_id=$avp(s20_cdr_id) event_id=$var(s20_event_id) callid=$ci reason=$var(s20_reason)\n");
} else {
update_stat("s20_cdr_xadd_error_total", 1);
xlog("L_ERR", "S20 CDR XADD failed event_id=$var(s20_event_id) callid=$ci reason=$var(s20_reason)\n");
}
}