Skip to content

Instantly share code, notes, and snippets.

@hamidrhashmi
Last active May 28, 2021 04:13
Show Gist options
  • Save hamidrhashmi/2cbbd57bd12c9505646c6e4d4389080f to your computer and use it in GitHub Desktop.
Save hamidrhashmi/2cbbd57bd12c9505646c6e4d4389080f to your computer and use it in GitHub Desktop.
OpenSIPs B2BUA Server
####### Global Parameters #########
#debug_mode=yes
log_level=3
log_stderror=no
log_facility=LOG_LOCAL0
children=8
#tcp_children=32
check_via=no
rev_dns=off
/* uncomment the following lines to enable debugging */
#debug_mode=yes
/* uncomment the next line to enable the auto temporary blacklisting of
not available destinations (default disabled) */
#disable_dns_blacklist=no
/* uncomment the next line to enable IPv6 lookup after IPv4 dns
lookup failures (default disabled) */
#dns_try_ipv6=yes
/* comment the next line to enable the auto discovery of local aliases
based on reverse DNS on IPs */
auto_aliases=no
listen=udp:127.0.0.1:5060 AS 8.8.8.8:5060 ### Customize Me
#listen=tcp:127.0.0.1:5060 AS 8.8.8.8:5060 ### Customize Me
#listen=tls:127.0.0.1:5060 AS 8.8.8.8:5060 ### Customize Me
#tcp_max_msg_time=10
#tcp_connect_timeout=350
#sip_warning=0
#tcp_connection_lifetime = 3600
#tcp_keepalive=0
####### Modules Section ########
#set module path
mpath="/usr/local/lib64/opensips/modules/"
#### SIGNALING module
loadmodule "signaling.so"
#### StateLess module
loadmodule "sl.so"
#### Transaction Module
loadmodule "tm.so"
modparam("tm", "fr_timeout", 15)
modparam("tm", "fr_inv_timeout", 48)
modparam("tm", "restart_fr_on_each_reply", 0)
modparam("tm", "onreply_avp_mode", 1)
#### Record Route Module
loadmodule "rr.so"
/* do not append from tag to the RR (no need for this script) */
modparam("rr", "append_fromtag", 0)
#### MAX ForWarD module
loadmodule "maxfwd.so"
#### SIP MSG OPerationS module
loadmodule "sipmsgops.so"
#### FIFO Management Interface
loadmodule "mi_fifo.so"
modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")
modparam("mi_fifo", "fifo_mode", 0666)
#### URI module
loadmodule "uri.so"
modparam("uri", "use_uri_table", 0)
#### MYSQL module
loadmodule "db_mysql.so"
#### AVPOPS module
loadmodule "avpops.so"
#### ACCounting module
#loadmodule "acc.so"
/* what special events should be accounted ? */
#modparam("acc", "early_media", 0)
#modparam("acc", "report_cancels", 0)
/*
by default we do not adjust the direct of the sequential requests.
if you enable this parameter, be sure the enable "append_fromtag"
in "rr" module
*/
#modparam("acc", "detect_direction", 0)
#modparam("acc", "db_url",
# "mysql://opensips:opensipsrw@localhost/opensips") # CUSTOMIZE ME
#### DISPATCHER module
#loadmodule "dispatcher.so"
#modparam("dispatcher", "db_url","mysql://user:password@127.0.0.1/database") ### Customize Me
#modparam("dispatcher", "ds_ping_method", "OPTIONS")
#modparam("dispatcher", "ds_probing_mode", 0)
#modparam("dispatcher", "ds_ping_interval", 30)
#### MI_HTTP module
#loadmodule "mi_http.so"
loadmodule "proto_udp.so"
#loadmodule "proto_tcp.so"
#modparam("proto_tcp", "tcp_send_timeout", 2000)
#modparam("proto_tcp", "tcp_max_msg_chunks", 8)
#loadmodule "proto_tls.so"
#loadmodule "tls_mgm.so"
#modparam("tls_mgm","verify_cert", "1")
#modparam("tls_mgm","require_cert", "0")
#modparam("tls_mgm","tls_method", "TLSv1")
#modparam("tls_mgm","certificate", "/usr/local/etc/opensips/server.pem")
#modparam("tls_mgm","private_key", "/usr/local/etc/opensips/server.key")
#modparam("tls_mgm","ca_list", "/usr/local/etc/opensips/server.pem")
#### B2B_Entity ####
loadmodule "b2b_entities.so"
modparam("b2b_entities", "script_req_route", "b2b_request")
modparam("b2b_entities", "script_reply_route", "b2b_reply")
modparam("b2b_entities", "b2b_key_prefix", "B2B1")
modparam("b2b_entities", "db_mode", 0)
#modparam("b2b_entities", "replication_mode", 0)
#### B2B_Entity ####
loadmodule "b2b_logic.so"
modparam("b2b_logic", "init_callid_hdr", "Init-CallID")
loadmodule "uac_auth.so"
####### Routing Logic ########
# main request routing logic
route{
xlog("L_INFO","[$fU $tU $ci $rm] Request Received from $pr:$si:$sp User-Agent:$ua");
if (!mf_process_maxfwd_header("10")) {
send_reply("483","Too Many Hops");
exit;
}
if (has_totag()) {
# handle hop-by-hop ACK (no routing required)
if ( is_method("ACK") && t_check_trans() ) {
xlog("L_INFO","[$fU $tU $ci $rm] Relaying Request to $ru");
t_relay();
exit;
}
# sequential request withing a dialog should
# take the path determined by record-routing
if ( !loose_route() ) {
# we do record-routing for all our traffic, so we should not
# receive any sequential requests without Route hdr.
send_reply("404","Not here");
exit;
}
/*
if (is_method("BYE")) {
xlog("L_INFO","[$fU $tU $ci $rm] BYE ");
# do accounting even if the transaction fails
#o_accounting("db","failed");
}
*/
# route it out to whatever destination was set by loose_route()
# in $du (destination URI).
route(RELAY);
exit;
}
#### INITIAL REQUESTS
# CANCEL processing
if (is_method("CANCEL")) {
if (t_check_trans())
t_relay();
exit;
}
/*
if ($rU==NULL) {
# request with no Username in RURI
send_reply("484","Address Incomplete");
exit;
}
*/
t_check_trans();
# preloaded route checking
if (loose_route()) {
xlog("L_ERR","[$fU $tU $ci $rm] Attempt to route with preloaded Route's");
remove_hf("Route");
}
if(is_method("REGISTER")) {
$ru=$du;
} else if (is_method("INVITE")) {
$du="sip:{Remote Carrier IP}:5060";
$ru= "sip:" + $tU + "@{Remote Carrier IP}:5060" ;
xlog("L_INFO","[$fU $tU $ci $rm] Relaying Request to $ru");
xlog("L_INFO","[$fU $tU $ci $rm] Calling function b2b_init");
b2b_init_request("top hiding");
exit;
}
t_on_failure("GW_FAILOVER");
route(RELAY);
}
route[RELAY] {
if (!t_relay()) {
sl_reply_error();
}
exit;
}
failure_route[GW_FAILOVER] {
if (t_was_cancelled()) {
exit;
}
# failure detection with redirect to next available trunk
if (t_check_status("(408)|([56][0-9][0-9])")) {
xlog("Failed trunk $rd/$du detected \n");
send_reply("500","All GW are down");
}
}
route[b2b_request]
{
xlog("L_INFO","[$fU $tU $ci $rm] B2B_Request Received from $pr:$si:$sp User-Agent:$ua");
xlog("L_INFO","[$fU $tU $ci $rm] B2B_Request message $rs:$rr received \n");
}
route[b2b_reply]
{
xlog("L_INFO","[$fU $tU $ci $rm] B2B_Reply Received from $pr:$si:$sp User-Agent:$ua");
xlog("L_INFO","[$fU $tU $ci $rm] B2B_Reply message $rs:$rr received \n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment