Skip to content

Commit

Permalink
Update openSIPS IMS configuration files
Browse files Browse the repository at this point in the history
Co-authored-by: Razvan Crainea <[email protected]>
  • Loading branch information
herlesupreeth and razvancrainea committed Jan 21, 2025
1 parent 2dc170e commit f12631b
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 4 deletions.
44 changes: 44 additions & 0 deletions opensips_ims_pcscf/opensips.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ mpath="/usr/lib/x86_64-linux-gnu/opensips/modules"

####### Modules Section ########

#### MYSQL module
loadmodule "db_mysql.so"

#### SIGNALING module
loadmodule "signaling.so"

Expand Down Expand Up @@ -135,6 +138,18 @@ modparam("rtpengine", "rtpengine_sock", "udp:RTPENGINE_IP:2223")
loadmodule "event_route.so"
loadmodule "json.so"

#### PRESENCE modules
loadmodule "presence.so"
loadmodule "presence_reginfo.so"
loadmodule "pua.so"
modparam("pua|presence","db_url", "mysql://opensips_pcscf:heslo@MYSQL_IP/opensips_pcscf")

loadmodule "pua_reginfo.so"

modparam("pua_reginfo", "ul_domain", "location")
modparam("pua_reginfo", "ul_identities_key", "identities")
modparam("pua_reginfo", "default_domain", "IMS_DOMAIN")
modparam("pua_reginfo", "server_address", "sip:[email protected]_DOMAIN")


####### Routing Logic ########
Expand Down Expand Up @@ -180,6 +195,11 @@ route{
t_on_reply("rtpengine_answer");
}

if (is_method("SUBSCRIBE|NOTIFY") && is_myself($rd)) {
route(handle_presence);
exit;
}

# route it out to whatever destination was set by loose_route()
# in $du (destination URI).
route(relay);
Expand Down Expand Up @@ -208,6 +228,10 @@ route{
t_on_reply("register_reply");
route(relay);
exit;
} else if (is_method("SUBSCRIBE|PUBLISH")) {
xlog("L_INFO", "[$ci] Received $rm for $tu - handling\n");
route(handle_presence);
exit;
} else if (is_method("INVITE")) {
if (loose_route()) {
xlog("L_INFO", "[$ci] Received INVITE for $tu - relaying to S-CSCF ($ru/$du)\n");
Expand Down Expand Up @@ -275,6 +299,9 @@ onreply_route[register_reply] {
} else if ($T_reply_code == 200) {
if (!save("location", "no-reply, path-off"))
xlog("L_ERR", "[$ci] could not save\n");
else
ul_add_key("location", "$tU@$td", "identities", "$hdr(P-Associated-URI)");
reginfo_update("$tU@$td");
}

}
Expand Down Expand Up @@ -436,3 +463,20 @@ event_route[E_DM_REQUEST] {

}
}

route[handle_presence] {
if (!t_newtran()){
sl_reply_error();
exit;
}
if ($hdr(Event) != "reg") {
xlog("L_ERR", "[$ci] Unhandled event $hdr(Event)\n");
send_reply(489, "Bad Event");
exit;
}

if (is_method("PUBLISH"))
handle_publish();
if (is_method("SUBSCRIBE"))
handle_subscribe();
}
25 changes: 25 additions & 0 deletions opensips_ims_pcscf/pcscf_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,36 @@ cp /mnt/pcscf/pcscf.dictionary /etc/opensips
cp /mnt/pcscf/opensips.cfg /etc/opensips
cp -r /mnt/pcscf/db /etc/opensips

while ! mysqladmin ping -h ${MYSQL_IP} --silent; do
sleep 5;
done

# Sleep until permissions are set
sleep 10;

# Create PCSCF database, populate tables and grant privileges
if [[ -z "`mysql -u root -h ${MYSQL_IP} -qfsBe "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME='opensips_pcscf'" 2>&1`" ]];
then
mysql -u root -h ${MYSQL_IP} -e "create database opensips_pcscf;"
mysql -u root -h ${MYSQL_IP} opensips_pcscf < /usr/share/opensips/mysql/standard-create.sql
mysql -u root -h ${MYSQL_IP} opensips_pcscf < /usr/share/opensips/mysql/presence-create.sql
PCSCF_USER_EXISTS=`mysql -u root -h ${MYSQL_IP} -s -N -e "SELECT EXISTS(SELECT 1 FROM mysql.user WHERE User = 'opensips_pcscf' AND Host = '%')"`
if [[ "$PCSCF_USER_EXISTS" == 0 ]]
then
mysql -u root -h ${MYSQL_IP} -e "CREATE USER 'opensips_pcscf'@'%' IDENTIFIED WITH mysql_native_password BY 'heslo'";
mysql -u root -h ${MYSQL_IP} -e "CREATE USER 'opensips_pcscf'@'$PCSCF_IP' IDENTIFIED WITH mysql_native_password BY 'heslo'";
mysql -u root -h ${MYSQL_IP} -e "GRANT ALL ON opensips_pcscf.* TO 'opensips_pcscf'@'%'";
mysql -u root -h ${MYSQL_IP} -e "GRANT ALL ON opensips_pcscf.* TO 'opensips_pcscf'@'$PCSCF_IP'";
mysql -u root -h ${MYSQL_IP} -e "FLUSH PRIVILEGES;"
fi
fi

sed -i 's|PCSCF_IP|'$PCSCF_IP'|g' /etc/opensips/opensips.cfg
sed -i 's|IMS_DOMAIN|'$IMS_DOMAIN'|g' /etc/opensips/opensips.cfg
sed -i 's|EPC_DOMAIN|'$EPC_DOMAIN'|g' /etc/opensips/opensips.cfg
sed -i 's|SCSCF_IP|'$SCSCF_IP'|g' /etc/opensips/opensips.cfg
sed -i 's|RTPENGINE_IP|'$RTPENGINE_IP'|g' /etc/opensips/opensips.cfg
sed -i 's|MYSQL_IP|'$MYSQL_IP'|g' /etc/opensips/opensips.cfg

sed -i 's|PCRF_BIND_PORT|'$PCRF_BIND_PORT'|g' /etc/opensips/freeDiameter.conf
sed -i 's|PCSCF_BIND_PORT|'$PCSCF_BIND_PORT'|g' /etc/opensips/freeDiameter.conf
Expand Down
28 changes: 24 additions & 4 deletions opensips_ims_scscf/opensips.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ log_level=3
xlog_level=3
log_stderror=yes
log_stdout=yes
xlog_buf_size=16384
log_facility=LOG_LOCAL0

udp_workers=4
Expand Down Expand Up @@ -126,6 +127,12 @@ modparam("dialplan","db_url", "mysql://opensips_scscf:heslo@MYSQL_IP/opensips_sc
#### auth module
loadmodule "auth.so"

#### JSON module
loadmodule "json.so"

#### XML module
loadmodule "xml.so"



####### Routing Logic ########
Expand Down Expand Up @@ -223,9 +230,8 @@ route{
$rU = $(rU{s.select,0,;});
}
if (!dp_translate(1, $rU, $var(dialplan))) {
xlog("L_ERR", "[$ci] dial $rU not in dialplan\n");
t_reply(404, "Unknown user");
exit;
$var(dialplan) = "USER";
xlog("L_DBG", "[$ci] unknown dialplan - considering $var(dialplan)\n");
}
xlog("L_INFO", "[$ci] Dial $rU is a $var(dialplan) dialplan\n");
switch ($var(dialplan)) {
Expand Down Expand Up @@ -273,7 +279,21 @@ route[aka_resume_sar] {
xlog("[$ci] SAA rc: $var(rc), SAA AVPs: $var(rpl_avps)\n");
$avp(attr) = $ct.fields(params);
append_to_reply("Service-Route: <sip:[email protected]_DOMAIN:6060;lr>\r\n");
append_to_reply("P-Associated-URI: <$fu>\r\n");
$json(rpl_avps) := $var(rpl_avps);
for ($var(item) in $(json(rpl_avps)[*])) {
$json(item) := $var(item);
for ($var(key) in $(json(item.keys)[*])) {
if ($var(key) == "Cx-User-Data") {
$xml(data) := $json(item/$var(key));
$xml(profile) := $xml(data/IMSSubscription/ServiceProfile);
$var(idx) = 0;
while ($xml(profile/ServiceProfile/PublicIdentity[$var(idx)]) != NULL) {
append_to_reply("P-Associated-URI: <$xml(profile/ServiceProfile/PublicIdentity[$var(idx)]/Identity.val)>\r\n");
$var(idx) = $var(idx) + 1;
}
}
}
}
if (!save("location", "path-lazy")) {
t_reply(503, "Internal Error");
exit;
Expand Down

0 comments on commit f12631b

Please sign in to comment.