#!KAMAILIO
#
# This config file implements an Online-Charging-Server
#     - web: https://www.kamailio.org
#     - git: http://github.com/kamailio/kamailio
#
# Refer to the Core CookBook at https://www.kamailio.org/w/documentation/
# for an explanation of possible statements, functions and parameters.
#
# Direct your questions about this file to: <sr-users@lists.kamailio.org>.
#
# For more information about the various parameters, functions and statements
# try http://sip-router.org/wiki/ .
#

import_file "ocs.cfg"

####### Defined Values #########
# *** Value defines - IDs used later in config

# - flags
#	FLT_ - per transaction (message) flags
#	FLB_ - per branch flags


####### Global Parameters #########

#!ifdef WITH_DEBUG
debug=4
log_stderror=yes
#!else
debug=0
log_stderror=no
#!endif

memdbg=5
memlog=5

log_stderror=no
sip_warning=no

rundir="/run/kamailio_ocs"

user_agent_header="User-Agent: TelcoSuite OCS"
server_header="Server: TelcoSuite OCS"

/* comment the next line to enable the auto discovery of local aliases
   based on reverse DNS on IPs (default on) */
auto_aliases=no

check_via=no    # (cmd. line: -v)
dns=no          # (cmd. line: -r)
rev_dns=no      # (cmd. line: -R)

# Do SRV-Loadbalancing:
dns_srv_lb=no
# Always: Also try IPv6:
dns_try_ipv6=no
# Always prefer IPv6:
dns_cache_flags=6
# DNS-Based failover
use_dns_failover = on
# Query NAPTR-Records as well:
dns_try_naptr=no

children=3
log_name="[Charging]"

system.shutdownmode = 0 desc "System shutdown mode"
system.service = "Online-Charging-Server" desc "Function of this server"

# ------------------ module loading ----------------------------------
mpath="/usr/lib64/kamailio/modules_k/:/usr/lib64/kamailio/modules/:/usr/local/lib/kamailio/modules/"
# (we try both the lib64 and the lib directory)

loadmodule "cdp"
loadmodule "cdp_avp"
loadmodule "ims_ocs"
loadmodule "xlog"
loadmodule "pv"
loadmodule "cfgutils"
loadmodule "textops"
loadmodule "ctl"
loadmodule "sl"
loadmodule "tm"
loadmodule "kex"
loadmodule "corex"

# ----- ctl params -----
modparam("ctl", "binrpc", "unix:/run/kamailio_ocs/kamailio_ctl")

# ----- cdp params -----
modparam("cdp","config_file","/etc/kamailio_ocs/ocs.xml")

route {
	# Do nothing, we only do Diameter requests
	drop();
	exit;
}

event_route[ocs:ccr-orig] {
	xlog("Session-Case: Originating\n");
	xlog("----------------------------------------\n");
	if (is_method("INVITE")) {
		xlog("START - Request\n");
	} else if (is_method("UPDATE")) {
		xlog("INTERIM - Request\n");
	} else if (is_method("BYE")) {
		xlog("STOP - Request\n");
	}
	xlog("----------------------------------------\n");
	xlog("From:               $fu\n");
	xlog("To:                 $ru\n");
	xlog("Call-ID:            $ci\n");
	xlog("Requested Units:    $hdr(P-Requested-Units)\n");
	xlog("Used Units:         $hdr(P-Used-Units)\n");
	xlog("Access Network:     $hdr(P-Access-Network-Info)\n");
	xlog("Service Identifier: $hdr(P-Service-Identifier)\n");

	ccr_result("2001", "600", "0");
}

event_route[ocs:ccr-term] {
	xlog("Session-Case: Terminating\n");
	xlog("----------------------------------------\n");
	if (is_method("INVITE")) {
		xlog("START - Request\n");
	} else if (is_method("UPDATE")) {
		xlog("INTERIM - Request\n");
	} else if (is_method("BYE")) {
		xlog("STOP - Request\n");
	}
	xlog("----------------------------------------\n");
	xlog("From:               $fu\n");
	xlog("To:                 $ru\n");
	xlog("Call-ID:            $ci\n");
	xlog("Requested Units:    $hdr(P-Requested-Units)\n");
	xlog("Used Units:         $hdr(P-Used-Units)\n");
	xlog("Access Network:     $hdr(P-Access-Network-Info)\n");
	xlog("Service Identifier: $hdr(P-Service-Identifier)\n");

	ccr_result("2001", "600", "0");
}
