Files
docker_open5gs/pcscf/route/mt.cfg
2024-12-31 13:53:16 +01:00

551 lines
22 KiB
INI

######################################################################
# Terminating, Initial requests
######################################################################
route[MT] {
xnotice("PCSCF MT: \n Destination URI: $du\n Request URI: $ru\n");
xnotice("Source IP and Port: ($si:$sp)\n Route-URI: $route_uri\n");
xnotice("Received IP and Port: ($Ri:$Rp)\n");
xnotice("Contact header: $ct\n");
xnotice("Term UE connection information : IP is $dd and Port is $rp \n");
xnotice("Term P-CSCF connection information : IP is $RAi and Port is $RAp \n");
set_dlg_profile("term");
#!ifdef WITH_N5
if(is_method("INVITE")) {
route(N5_INIT_MT_REQ);
}
#!endif
#!ifdef WITH_IPSEC
ipsec_forward("location", IPSEC_FORWARD_FLAGS);
#!endif
t_on_reply("MT_reply");
}
######################################################################
# Replies to Originating Initial Requests
######################################################################
onreply_route[MT_reply] {
xnotice("PCSCF MT_reply: \n Destination URI: $du\n Request URI: $ru\n");
xnotice("Source IP and Port: ($si:$sp)\n Route-URI: $route_uri\n");
xnotice("Received IP and Port: ($Ri:$Rp)\n");
xnotice("Contact header: $ct\n");
if (!strempty($(ct{tobody.params}))) {
append_hf("C-Params: $(ct{tobody.params})\r\n");
}
# In case of 1xx and 2xx do NAT
if(status=~"[12][0-9][0-9]")
route(NATMANAGE);
#!ifdef WITH_N5
# N5 PATCH Request for updating AppSession context
if (t_check_status("180|183|200") && has_body("application/sdp")) {
xlog("L_INFO", "Received early answer in 18x. Patching N5 session in PCF\n");
if (t_is_retr_async_reply()) {
xlog("L_INFO", "Dropping retransmitted reply which is still currently suspended\n");
drop();
}
route(N5_PATCH_MT_REQ);
}
# Terminating N5 AppSession after error response
if (status=~"[45][0-9][0-9]") {
xnotice("Received Error response for the Call. Going to terminate N5 Session\n");
route(N5_MTC_TERM);
}
#!endif
#!ifdef WITH_RX
if (t_check_status("183|200") && has_body("application/sdp")){
xnotice("PCSCF MT_reply: \n Destination URI: $du\n Request URI: $ru\n");
xnotice("Source IP and Port: ($si:$sp)\n Route-URI: $route_uri\n");
xnotice("Received IP and Port: ($Ri:$Rp)\n");
xnotice("Contact header: $ct\n");
xlog("L_DBG", "IMS: Received 183 inside term_initial_reply\n");
if (t_is_retr_async_reply()) {
xlog("L_DBG", "Dropping retransmitted reply which is still currently suspended\n");
drop();
}
xlog("L_DBG","Diameter: Term authorizing media via Rx\n");
$avp(FTAG_CUSTOM_AVP)=$ft;
$avp(TTAG_CUSTOM_AVP)=$tt;
$avp(CALLID_CUSTOM_AVP)=$ci;
if (Rx_AAR("MT_aar_reply","term","",-1) == 0) {
exit;
}
}
}
route[MT_aar_reply]
{
xlog("L_DBG", "IMS: TERM_SESSION_AAR_REPLY\n");
# Check reply AVP since the operation is async
switch ($avp(s:aar_return_code)) {
case 1:
xlog("L_DBG", "Diameter: Orig AAR success on media authorization\n");
break;
default:
xlog("L_ERR", "IMS: AAR failed Orig\n");
xlog("L_ERR", "IMS: ttag: "+ "$avp(TTAG_CUSTOM_AVP)");
xlog("L_ERR", "IMS: ftag: "+ "$avp(FTAG_CUSTOM_AVP)");
xlog("L_ERR", "IMS: callid: "+ "$avp(CALLID_CUSTOM_AVP)");
# Comment this if you want to allow even if Rx fails
if(dlg_get("$avp(CALLID_CUSTOM_AVP)","$avp(FTAG_CUSTOM_AVP)","$avp(TTAG_CUSTOM_AVP)")){
dlg_terminate("all", "Sorry no QoS available");
exit;
}
}
#!endif
}
######################################################################
# In-Dialog-MT-Requests
######################################################################
route[MT_indialog] {
#!ifdef WITH_N5
# N5 PATCH Request for updating AppSession context
if (is_method("INVITE")) {
xlog("L_INFO"," InDialog SDP Change. Sending N5 Request to update appSession context\n");
route(N5_PATCH_REQ);
}
# Terminating N5 AppSession after BYE
if (is_method("BYE|CANCEL")) {
xlog("L_INFO"," InDialog Call End/Cancel/Error. Terminating N5 QoS Session\n");
route(N5_MTC_TERM);
}
#!endif
xnotice("PCSCF MT_indialog: \n Destination URI: $du\n Request URI: $ru\n");
xnotice("Source IP and Port: ($si:$sp)\n Route-URI: $route_uri\n");
xnotice("Received IP and Port: ($Ri:$Rp)\n");
xnotice("Contact header: $ct\n");
#resetflag(FLT_MOBILE_ORIG);
t_on_reply("MT_indialog_reply");
# Append rport only if its a request coming from UE
if (is_request() && ($hdrc(Via) == 1)) {
force_rport();
}
#!ifdef WITH_IPSEC
if ($dd != "" && $rd != "" && $fs != "") {
if ($rd =~ ".*" + $dd + ".*") {
ipsec_forward("location", IPSEC_FORWARD_FLAGS);
}
}
#!endif
}
onreply_route[MT_indialog_reply] {
xnotice("PCSCF MT_indialog_reply: \n Destination URI: $du\n Request URI: $ru\n");
xnotice("Source IP and Port: ($si:$sp)\n Route-URI: $route_uri\n");
xnotice("Received IP and Port: ($Ri:$Rp)\n");
xnotice("Contact header: $ct\n");
#!ifdef WITH_N5
# N5 PATCH Request for updating AppSession context for Indialog reply
if (t_check_status("180|183|200") && has_body("application/sdp")){
xlog("L_INFO", "Received MT_indialog_reply. Patching N5 session in PCF\n");
if (t_is_retr_async_reply()) {
xlog("L_INFO", "Dropping retransmitted reply which is still currently suspended\n");
drop();
}
route(N5_PATCH_MT_REQ);
}
#!endif
# In case of 1xx and 2xx do NAT
if(status=~"[12][0-9][0-9]")
route(NATMANAGE);
#!ifdef WITH_RX
if (t_check_status("183|200") && has_body("application/sdp") && !is_method("PRACK")) {
if (t_is_retr_async_reply()) {
xlog("L_DBG", "Dropping retransmitted reply which is still currently suspended\n");
drop();
}
xlog("L_DBG", "IMS: TERM_SUBSEQUENT reply. This is a 200 OK to a re-INVITE\n");
xlog("L_DBG","Diameter: Term authorizing media via Rx\n");
$avp(FTAG_CUSTOM_AVP)=$ft;
$avp(TTAG_CUSTOM_AVP)=$tt;
$avp(CALLID_CUSTOM_AVP)=$ci;
if (Rx_AAR("MT_indialog_aar_reply","term","",-1) == 0) {
exit;
}
}
}
route[MT_indialog_aar_reply]
{
# Check reply AVP since the operation is async
switch ($avp(s:aar_return_code)) {
case 1:
xlog("L_DBG", "Diameter: Orig AAR success on media authorization\n");
break;
default:
xlog("L_ERR", "IMS: AAR failed Orig\n");
xlog("L_ERR", "IMS: ttag: "+ "$avp(TTAG_CUSTOM_AVP)");
xlog("L_ERR", "IMS: ftag: "+ "$avp(FTAG_CUSTOM_AVP)");
xlog("L_ERR", "IMS: callid: "+ "$avp(CALLID_CUSTOM_AVP)");
# Comment this if you want to allow even if Rx fails
if(dlg_get("$avp(CALLID_CUSTOM_AVP)","$avp(FTAG_CUSTOM_AVP)","$avp(TTAG_CUSTOM_AVP)")){
dlg_terminate("all", "Sorry no QoS available");
exit;
}
}
#!endif
}
#!ifdef WITH_N5
# Route Logic for N5 Requests
route[N5_INIT_MT_REQ] {
# Storing IDs and IPs from UE into variables to use them later in the N5 Request
$var(term_ue_ip) = $dd;
$var(term_sip_ue_port) = $rp;
$var(pcscf_sip_ip) = $Ri;
$var(pcscf_sip_port) = $Rp;
xlog("L_INFO", "SIP Connection Info for Term UE $var(term_ue_ip) $var(term_sip_ue_port)\n");
xlog("L_INFO", "SIP Connection Info for P-CSCF is: $var(pcscf_sip_ip) $var(pcscf_sip_port)\n");
$var(term_user_id_req_ip) = $tU;
# Store the IP in the hash table associated with the UE
$sht(user_sip_ips=>$var(term_user_id_req_ip)) = $var(term_ue_ip);
xlog("L_INFO", "SIP/SDP IP Info for Term UE MSISDN $var(term_user_id_req_ip): $var(term_ue_ip)\n");
$var(term_user_id_req_port) = $tU;
# Store the Port in the hash table associated with the UE
$sht(user_sip_ports=>$var(term_user_id_req_port)) = $var(term_sip_ue_port);
xlog("L_INFO", "SIP Port Info for UE MSISDN $var(term_user_id_req_port): $var(term_sip_ue_port)\n");
xlog("L_INFO", "IMS: MTC INVITE TO $tU\n");
# Retrieving SDP Connection Info and Media Port for UE
$var(sdp_src_ip) = $sdp(c:ip);
$var(sdp_src_port) = $sdp(m0:rtp:port);
$var(orig_ue_sdp_rtcp_port) = $sdp(m0:rtcp:port);
$var(sdp_mline_raw) = $sdp(m0:raw);
xlog("L_INFO", "SDP Info From INVITE: $sdp(c:ip) -- $sdp(m0:rtp:port) -- $sdp(m0:rtcp:port)\n");
$var(call_id_sdp_ip) = $ci;
# Store the SDP IP in the hash table associated with the Call-Id
$sht(user_sdps_ip=>$var(call_id_sdp_ip)) = $var(sdp_src_ip);
$var(ret_call_id_sdp_ip) = $ci;
$var(sdp_src_ip) = $sht(user_sdps_ip=>$var(ret_call_id_sdp_ip));
xlog("L_INFO", "SDP IP of orig UE $fU Call-ID $var(call_id_sdp_ip): $var(sdp_src_ip)\n");
$var(sdp_call_id_port) = $ci;
# Store SDP Media Port in the hash table associated with the Call-Id
$sht(user_sdps_port=>$var(sdp_call_id_port)) = $var(sdp_src_port);
xlog("L_INFO", "SDP Port for MTC Call-ID $var(sdp_call_id_port) is: $var(sdp_src_port)\n");
$var(sdp_call_id_rtcp_port) = $ci;
#Store SDP RTCP Port in the hash table associated with the Call-Id
$sht(user_sdps_rtcp_port=>$var(sdp_call_id_rtcp_port)) = $var(orig_ue_sdp_rtcp_port);
$var(sdp_call_id_rtcp_port) = $ci;
$var(orig_ue_sdp_rtcp_port) = $sht(user_sdps_rtcp_port=>$var(sdp_call_id_rtcp_port));
xlog("L_INFO", "SDP RTCP Port for UE with MSISDN $fU is: $var(orig_ue_sdp_rtcp_port)\n");
xlog("L_INFO", "Preparing QoS N5 Message to PCF for INVITE To term UE\n");
$var(events) = '[]';
$var(medComponents) = '{}';
$var(medSubComps) = '{}';
$var(evSubsc) = '{}';
$var(payload) = '{}';
# Set afAppId and dnn in payload
# TODO: Get the value from SIP Header
jansson_set("string", "afAppId", "+g.3gpp.icsi-ref=\"urn%3Aurn-7%3A3gpp-service.ims.icsi.mmtel\"", "$var(payload)");
jansson_set("string", "dnn", "ims", "$var(payload)");
# Set medComponents
jansson_set("integer", "medCompN", 1, "$var(medComp)");
jansson_set("string", "qosReference", "qosVoNR", "$var(medComp)");
jansson_set("string", "medType", "AUDIO", "$var(medComp)");
jansson_set("array", "codecs", "[\"downlink\\noffer\\n\", \"uplink\\nanswer\\n\"]", "$var(medComp)");
# RTP
jansson_set("integer", "fNum", 1, "$var(medSubComp1)");
jansson_set("array", "fDescs", "[\"permit out 17 from $var(sdp_src_ip) $var(sdp_src_port) to $dd 49000-51000\", \"permit in 17 from $dd 49000-51000 to $var(sdp_src_ip) $var(sdp_src_port)\"]", "$var(medSubComp1)");
jansson_set("string", "fStatus", "ENABLED", "$var(medSubComp1)");
jansson_set("string", "marBwDl", "5000 Kbps", "$var(medSubComp1)");
jansson_set("string", "marBwUl", "3000 Kbps", "$var(medSubComp1)");
jansson_set("string", "flowUsage", "NO_INFO", "$var(medSubComp1)");
# RTCP
jansson_set("integer", "fNum", 2, "$var(medSubComp2)");
jansson_set("array", "fDescs", "[\"permit out 17 from $var(sdp_src_ip) $var(orig_ue_sdp_rtcp_port) to $dd 49000-51000\", \"permit in 17 from $dd 49000-51000 to $var(sdp_src_ip) $var(orig_ue_sdp_rtcp_port)\"]", "$var(medSubComp2)");
jansson_set("string", "fStatus", "ENABLED", "$var(medSubComp2)");
jansson_set("string", "marBwDl", "5000 Kbps", "$var(medSubComp2)");
jansson_set("string", "marBwUl", "3000 Kbps", "$var(medSubComp2)");
jansson_set("string", "flowUsage", "RTCP", "$var(medSubComp2)");
# Merging the flows under MediaSubComponent
jansson_set("obj", "0", "$var(medSubComp1)", "$var(medSubComps)");
jansson_set("obj", "1", "$var(medSubComp2)", "$var(medSubComps)");
jansson_set("obj", "medSubComps", "$var(medSubComps)", "$var(medComp)");
jansson_set("obj", "0", "$var(medComp)", "$var(medComponents)");
jansson_set("obj", "medComponents", "$var(medComponents)", "$var(payload)");
xlog("L_INFO","DEBUG: Set evSubsc\n");
# Set evSubsc
jansson_set("string", "event", "QOS_NOTIF", "$var(event1)");
jansson_set("string", "notifMethod", "PERIODIC", "$var(event1)");
jansson_append("obj", "", "$var(event1)", "$var(events)");
jansson_set("string", "event", "ANI_REPORT", "$var(event2)");
jansson_set("string", "notifMethod", "ONE_TIME", "$var(event2)");
jansson_append("obj", "", "$var(event2)", "$var(events)");
jansson_set("array", "events", "$var(events)", "$var(evSubsc)");
jansson_set("obj", "evSubsc", "$var(evSubsc)", "$var(payload)");
# Set other parameters in payload
jansson_set("string", "notifUri", "http://172.22.0.21:7777", "$var(payload)");
jansson_set("string", "sponStatus", "SPONSOR_DISABLED", "$var(payload)");
jansson_set("string", "gpsi", "msisdn-$tU", "$var(payload)");
jansson_set("string", "suppFeat", "2", "$var(payload)");
jansson_set("string", "ueIpv4", "$dd", "$var(payload)");
# Assemble the final JSON request
jansson_set("obj", "ascReqData", "$var(payload)", "$var(json_request)");
xlog("L_INFO","DEBUG: Set headers for the HTTP2 Request\n");
# Set headers
$var(time_now)=$_s($timef(%a, %d %b %Y %H:%M:%S %Z));
xlog("L_INFO", "Today is $var(time_now)\n");
$var(headers) = "Content-Type: application/json\r\n";
$var(headers) = $var(headers) + "3gpp-sbi-discovery-target-nf-type: NRF\r\n";
$var(headers) = $var(headers) + "accept: application/json\r\n";
$var(headers) = $var(headers) + "accept: application/problem+json\r\n";
$var(headers) = $var(headers) + "3gpp-sbi-max-rsp-time: 10000\r\n";
$var(headers) = $var(headers) + "3gpp-sbi-discovery-service-names: npcf-policyauthorization\r\n";
$var(headers) = $var(headers) + "3gpp-sbi-sender-timestamp: " + $var(time_now);
xlog("L_INFO","Sending the request to PCF\n");
# Send the request to PCF
http_client_request_v2pk("POST", "http://172.22.0.27:7777/npcf-policyauthorization/v1/app-sessions", "$var(json_request)", "$var(headers)", "$var(result)" );
switch ($rc) {
# Success case
case 201:
xlog("L_INFO", "N5 QoS Session successfully Created $rc\n");
xlog("L_INFO", "HTTP results: $var(result)\n");
xlog("L_INFO", "HTTP response: $rc\n");
xlog("L_INFO", "Location Header: $httprhdr(location)\n");
# Retrieve the AppSession Id out of the location header in response
# Example URL: "http://172.22.0.27:7777/npcf-policyauthorization/v1/app-sessions/(someSessionID)"
# Store the url of the lcoation Header in var
$var(url) = $httprhdr(location);
# Get the length of the URL
$var(len) = $(var(url){s.len});
# Initialize the position variable to the length of the URL
$var(pos) = $var(len);
# Find the position of the last slash by iterating backwards
while ($var(pos) > 0) {
$var(pos) = $var(pos) - 1;
if ($(var(url){s.substr,$var(pos),1}) == "/") {
# We've found the last slash
break;
}
}
# Extract the substring after the last slash
# Set the starting position after the last slash
$var(start_pos) = $var(pos) + 1;
# Calculate the length of the substring after the last slash
$var(substring_length) = $var(len) - $var(start_pos);
# Extract the substring after the last slash
$var(mtc_app_session) = $(var(url){s.substr,$var(start_pos),$var(substring_length)});
xlog("L_INFO", "AppSession Id for user $tU is: $var(mtc_app_session)\n");
$var(term_user_id) = $tU;
# Store the AppSession Id in the hash table associated with the UE
$sht(user_data=>$var(term_user_id)) = $var(mtc_app_session);
xlog("L_INFO", "Stored AppSession for user $var(term_user_id): $var(mtc_app_session)\n");
break;
default:
xlog("L_ERR", "N5 QoS Session faild - Reason code: $rc\n");
send_reply("412", "MTC N5 QoS Session Creation faild");
exit;
}
}
# 5G VoNR N5 Policy Authorization PATCH request
route[N5_PATCH_MT_REQ] {
xlog("L_INFO", "N5_PATCH_MT_REQ, building N5 PATCH Request\n");
# Retrieve SDP Connection Info and Media Port for UE
$var(sdp_call_id) = $ci;
$var(orig_ue_sdp_ip) = $sht(user_sdps_ip=>$var(sdp_call_id));
xlog("L_INFO", "SDP IP for UE with MSISDN $fU Call-ID $var(sdp_call_id) is: $var(orig_ue_sdp_ip)\n");
$var(sdp_call_id_port) = $ci;
$var(orig_ue_sdp_port) = $sht(user_sdps_port=>$var(sdp_call_id_port));
xlog("L_INFO", "SDP RTP Port for UE with MSISDN $fU Call-ID $var(sdp_call_id_port) is: $var(orig_ue_sdp_port)\n");
$var(sdp_call_id_rtcp_port) = $ci;
$var(orig_ue_sdp_rtcp_port) = $sht(user_sdps_rtcp_port=>$var(sdp_call_id_rtcp_port));
xlog("L_INFO", "SDP RTCP Port for UE with MSISDN $fU Call-ID $var(sdp_call_id_rtcp_port) is: $var(orig_ue_sdp_rtcp_port)\n");
# Retrieve SDP Connection Info from SDP Answer
$var(sdp_answ_ip) = $sdp(c:ip);
$var(sdp_answ_port) = $sdp(m0:rtp:port);
$var(sdp_answ_rtcp_port) = $sdp(m0:rtcp:port);
$var(sdp_answ_codec) = $(rb{line.sw,a=rtpmap}{s.select,1, });
xlog("L_INFO", "SDP Answer connection Info is: $var(sdp_answ_ip), RTP port $var(sdp_answ_port), RTCP Port $var(sdp_answ_rtcp_port) and codec is $var(sdp_answ_codec)\n");
# Retrieve AppSession
$var(mtc_resp_app_id) = $tU;
$var(user_appsess_mtc_rep) = $sht(user_data=>$var(mtc_resp_app_id));
xlog("L_INFO", "Stored MTC AppSession for user $var(mtc_resp_app_id): $var(user_appsess_mtc_rep)\n");
xlog("L_INFO","Preparing PATCH N5 Message for SDP Answer\n");
$var(events) = '[]';
$var(medComponents) = '{}';
$var(medSubComps) = '{}';
$var(evSubsc) = '{}';
$var(payload) = '{}';
# Set afAppId and dnn in payload
jansson_set("string", "afAppId", "+g.3gpp.icsi-ref=\"urn%3Aurn-7%3A3gpp-service.ims.icsi.mmtel\"", "$var(payload)");
jansson_set("string", "dnn", "ims", "$var(payload)");
# Set medComponents
jansson_set("integer", "medCompN", 1, "$var(medComp)");
jansson_set("string", "qosReference", "qosVoNR", "$var(medComp)");
jansson_set("string", "medType", "AUDIO", "$var(medComp)");
jansson_set("array", "codecs", "[\"downlink\\n$var(sdp_answ_codec)\\n\", \"uplink\\n$var(sdp_answ_codec)\\n\"]", "$var(medComp)");
# RTP
jansson_set("integer", "fNum", 1, "$var(medSubComp1)");
jansson_set("array", "fDescs", "[\"permit out 17 from $var(orig_ue_sdp_ip) $var(orig_ue_sdp_port) to $var(sdp_answ_ip) $var(sdp_answ_port)\", \"permit in 17 from $var(sdp_answ_ip) $var(sdp_answ_port) to $var(orig_ue_sdp_ip) $var(orig_ue_sdp_port)\"]", "$var(medSubComp1)");
jansson_set("string", "fStatus", "ENABLED", "$var(medSubComp1)");
jansson_set("string", "marBwDl", "5000 Kbps", "$var(medSubComp1)");
jansson_set("string", "marBwUl", "3000 Kbps", "$var(medSubComp1)");
jansson_set("string", "flowUsage", "NO_INFO", "$var(medSubComp1)");
# RTCP
jansson_set("integer", "fNum", 2, "$var(medSubComp2)");
jansson_set("array", "fDescs", "[\"permit out 17 from $var(orig_ue_sdp_ip) $var(orig_ue_sdp_rtcp_port) to $var(sdp_answ_ip) $var(sdp_answ_rtcp_port)\", \"permit in 17 from $var(sdp_answ_ip) $var(sdp_answ_rtcp_port) to $var(orig_ue_sdp_ip) $var(orig_ue_sdp_rtcp_port)\"]", "$var(medSubComp2)");
jansson_set("string", "fStatus", "ENABLED", "$var(medSubComp2)");
jansson_set("string", "marBwDl", "6000 Kbps", "$var(medSubComp2)");
jansson_set("string", "marBwUl", "5000 Kbps", "$var(medSubComp2)");
jansson_set("string", "flowUsage", "RTCP", "$var(medSubComp2)");
# Merging the flows under MediaSubComponent
jansson_set("obj", "0", "$var(medSubComp1)", "$var(medSubComps)");
jansson_set("obj", "1", "$var(medSubComp2)", "$var(medSubComps)");
jansson_set("obj", "medSubComps", "$var(medSubComps)", "$var(medComp)");
jansson_set("obj", "0", "$var(medComp)", "$var(medComponents)");
jansson_set("obj", "medComponents", "$var(medComponents)", "$var(payload)");
xlog("L_INFO","DEBUG: Set evSubsc\n");
# Set evSubsc
jansson_set("string", "event", "QOS_NOTIF", "$var(event1)");
jansson_set("string", "notifMethod", "PERIODIC", "$var(event1)");
jansson_append("obj", "", "$var(event1)", "$var(events)");
jansson_set("string", "event", "ANI_REPORT", "$var(event2)");
jansson_set("string", "notifMethod", "ONE_TIME", "$var(event2)");
jansson_append("obj", "", "$var(event2)", "$var(events)");
jansson_set("array", "events", "$var(events)", "$var(evSubsc)");
jansson_set("obj", "evSubsc", "$var(evSubsc)", "$var(payload)");
# Set other parameters in payload
jansson_set("string", "notifUri", "http://172.22.0.21:7777", "$var(payload)");
jansson_set("string", "sponStatus", "SPONSOR_DISABLED", "$var(payload)");
jansson_set("string", "gpsi", "msisdn-$tU", "$var(payload)");
jansson_set("string", "suppFeat", "2", "$var(payload)");
jansson_set("string", "ueIpv4", "$si", "$var(payload)");
# Assemble the final JSON request
jansson_set("obj", "ascReqData", "$var(payload)", "$var(json_request)");
xlog("L_INFO","DEBUG: Set headers for the HTTP2 Request\n");
# Set headers
$var(time_now)=$_s($timef(%a, %d %b %Y %H:%M:%S %Z));
xlog("L_INFO", "Today is $var(time_now)\n");
# Set Content-type to application/merge-patch+json for compatibility with RFC7386 for JSON PATCH/Merge
$var(headers) = "Content-Type: application/merge-patch+json\r\n";
$var(headers) = $var(headers) + "3gpp-sbi-discovery-target-nf-type: NRF\r\n";
$var(headers) = $var(headers) + "accept: application/json\r\n";
$var(headers) = $var(headers) + "accept: application/problem+json\r\n";
$var(headers) = $var(headers) + "3gpp-sbi-max-rsp-time: 10000\r\n";
$var(headers) = $var(headers) + "3gpp-sbi-discovery-service-names: npcf-policyauthorization\r\n";
$var(headers) = $var(headers) + "3gpp-sbi-sender-timestamp: " + $var(time_now);
xlog("L_INFO","Sending the request to PCF\n");
# Send the request to PCF
http_client_request_v2pk("PATCH", "http://172.22.0.27:7777/npcf-policyauthorization/v1/app-sessions/$var(user_appsess_mtc_rep)", "$var(json_request)", "$var(headers)", "$var(result)" );
switch ($rc) {
case 200:
xlog("L_INFO", "N5 QoS Session modification success - reason code: $rc\n");
xlog("L_INFO", "HTTP results: $var(result)\n");
xlog("L_INFO", "HTTP response: $rc\n");
xlog("L_INFO", "cURL Response: $curlerror(error)\n");
xlog("L_INFO", "Location Header header: $httprhdr(location)\n");
break;
default:
xlog("L_ERR", "N5 QoS Session modification faild - reason code: $rc\n");
send_reply("412", "MTC N5 QoS Session modify faild");
exit;
}
}
route[N5_MTC_TERM] {
xlog("L_ALERT","Terminating AppSession For Call for User $tU due to call END\n");
# Retrieve appSession based on To URI
$var(mtc_resp_app_id) = $tU;
$var(user_appsess_mtc_rep) = $sht(user_data=>$var(mtc_resp_app_id));
if $var(user_appsess_mtc_rep) == 0 {
xlog("L_INFO", "No AppSession Id found to terminate. Trying using From URI\n");
# Retrieve appSession based on From URI
$var(mtc_resp_app_id) = $fU;
$var(user_appsess_mtc_rep) = $sht(user_data=>$var(mtc_resp_app_id));
xlog("L_INFO", "Alt-Method : Terminating Stored AppSession for user $var(mtc_resp_app_id): $var(user_appsess_mtc_rep)\n");
} else {
xlog("L_INFO", "Normal Method : MTC AppSession for user $var(mtc_resp_app_id): $var(user_appsess_mtc_rep)\n");
}
$var(headers) = "X-SIP-Status: De-Registration\r\n";
$var(headers) = $var(headers) + "3gpp-sbi-discovery-target-nf-type: NRF\r\n";
$var(headers) = $var(headers) + "accept: application/json\r\n";
$var(headers) = $var(headers) + "accept: application/problem+json\r\n";
$var(headers) = $var(headers) + "3gpp-sbi-max-rsp-time: 10000\r\n";
$var(headers) = $var(headers) + "3gpp-sbi-discovery-service-names: npcf-policyauthorization\r\n";
$var(headers) = $var(headers) + "3gpp-sbi-sender-timestamp: " + $var(time_now);
http_client_request_v2pk("POST", "http://172.22.0.27:7777/npcf-policyauthorization/v1/app-sessions/$var(user_appsess_mtc_rep)/delete", "$var(json_request)", "$var(headers)", "$var(result)" );
xlog("L_INFO", "cURL header: $curlerror(error)\n");
xlog("L_INFO", "HTTP response: $rc\n");
}
#!endif