diff --git a/pcscf/route/mo.cfg b/pcscf/route/mo.cfg index cfa1ed7..68b626e 100644 --- a/pcscf/route/mo.cfg +++ b/pcscf/route/mo.cfg @@ -21,6 +21,78 @@ route[MO] remove_hf("P-Asserted-Identity"); remove_hf("P-Preferred-Identity"); +####################################################################################################################### +## now lets try a N5 PolicyAuthorizationrequest to user Session in the PCF ### NOTE: THIS IS EXREAMLLY EXPEREMENTAL!!## +####################################################################################################################### +############## Route added by Abdul karim Barbour ##################################################################### +####################################################################################################################### + +## Storing IDs and IPs from UE into variables to use them later in the N5 Request: + + + $var(orig_ue_ip) = $si; + $var(orig_ue_port) = $sp; + $var(pcscf_ip) = $Ri; + $var(pcscf_port) = $Rp; + +# now checking it on console if I got what I wanted : + xlog("L_INFO", "connection Info for UE $var(orig_ue_ip) $var(orig_ue_port)\n"); + xlog("L_INFO", "connection Info for P-CSCF is: $var(pcscf_ip) $var(pcscf_port)\n"); + +# now trying some way to store IP of Orig UE + $var(user_id_req_ip) = $fU; # should get the user part of the Orig UE from request + + # Store the IP in the hash table associated with the UE + $sht(user_data=>$var(user_id_req_ip)) = $var(orig_ue_ip); + xlog("L_INFO", "IP Info for UE MSISDN $var(user_id_req_ip): $var(orig_ue_ip)\n"); + +# nnow trying some way to store Port of Orig UE + $var(user_id_req_port) = $fU; # should get the user part of the Orig UE from request + + # Store the Port in the hash table associated with the UE + $sht(user_ids=>$var(user_id_req_port)) = $var(orig_ue_port); + xlog("L_INFO", "Port Info for UE MSISDN $var(user_id_req_port): $var(orig_ue_port)\n"); + +## now saving SDP Info from UE to variables to use them later in the N5 Flow Fdecs : + +$var(sdp_src_ip) = $sdp(c:ip); +$var(sdp_src_port) = $sdp(m0:rtp:port); +$var(sdp_src_rtcp_port) = $sdp(m0:rtcp:port); +$var(sdp_mline_raw) = $sdp(m0:raw); + +xlog("L_INFO", "SDP Info : Connection IP is $var(sdp_src_ip) Port is $var(sdp_src_port) Mline dump $var(sdp_mline_raw) \n"); + + +# now trying some way to store SDP SRC_IP of Orig UE + $var(user_id_sdp_ip) = $fU; # should get the user part of the Orig UE from request + + # Store the AppSession in the hash table associated with the UE + $sht(user_sdps_ip=>$var(user_id_sdp_ip)) = $var(sdp_src_ip); + xlog("L_INFO", "SDP SRC_IP of Orig UE $var(user_id_sdp_ip): $var(sdp_src_ip)\n"); + +# now trying some way to store SDP Media_Port of Orig UE + $var(user_id_sdp_port) = $fU; # should get the user part of the Orig UE from request + + # store SDP Media_Port in the hash table associated with the UE + $sht(user_sdps_port=>$var(user_id_sdp_port)) = $var(sdp_src_port); + xlog("L_INFO", "SDP Media_Port of Orig UE $var(user_id_sdp_port): $var(sdp_src_port)\n"); + +# now trying some way to store SDP RTCP_Media_Port of Orig UE + $var(user_id_sdp_rtcp_port) = $fU; # should get the user part of the Orig UE from request + + # Store the RTCP_Media_Port in the hash table associated with the UE + $sht(user_sdps_rtcp_port=>$var(user_id_sdp_rtcp_port)) = $var(sdp_src_rtcp_port); + xlog("L_INFO", "SDP RTCP_Media_Port of Orig UE $var(user_id_sdp_rtcp_port): $var(sdp_src_rtcp_port)\n"); + + + +##################################################################### +##### END OF N5 VoNR Experement !!!! the variables should be saved ## +##################################################################### +##################################################################### +##################################################################### + + # Add P-Charging-Vector sip_p_charging_vector("g"); @@ -115,7 +187,196 @@ onreply_route[MO_reply] { #!endif # In case of 1xx and 2xx do NAT if(status=~"[12][0-9][0-9]") - route(NATMANAGE); +route(NATMANAGE); + +#################################################### +## N5 PolicyAuthorizationrequest QoS ############### +#################################################### +## Route added by Abdul karim Barbour ############## +#################################################### + +#### 5G VoNR N5 NPCF Authorization reuqest + + if (t_check_status("183|200|180") && has_body("application/sdp")){ + xlog("L_DBG", "IMS: Received 183/200 inside orig_initial_reply\n"); + + if (t_is_retr_async_reply()) { + xlog("L_DBG", "Dropping retransmitted reply which is still currently suspended\n"); + drop(); + } +### Getting the IP/Port of UE + $var(orig_ue_ip) = $fU; # User Part of the from Header to get the USER + $var(ue_ip_addr) = $sht(user_data=>$var(orig_ue_ip)); + xlog("L_INFO", "IP for UE $var(orig_ue_ip) is: $var(ue_ip_addr)\n"); + + $var(orig_ue_port) = $fU; # User Part of the from Header to get the USER + $var(ue_port_sip) = $sht(user_ids=>$var(orig_ue_port)); + xlog("L_INFO", "IP for UE $var(orig_ue_port) is: $var(ue_port_sip)\n"); + +## retrieving IMSI from Registration + $var(imsi_reg) = $var(ue_ip_addr); # User Part of the from Header to get the USER + $var(ue_imsi_inv) = $sht(user_ids=>$var(imsi_reg)); + xlog("L_INFO", "IMSI for UE with IP $var(ue_ip_addr) is: $var(ue_imsi_inv)\n"); + +## retrieving SDP Connection Info and Media Port for UE + $var(sdp_id_ue) = $fU; # User Part of the from Header to get the USER + $var(ue_sdp_ip) = $sht(user_sdps_ip=>$var(sdp_id_ue)); + xlog("L_INFO", "SDP IP for UE with MSISDN $var(sdp_id_ue) is: $var(ue_sdp_ip)\n"); + + $var(sdp_id_ue_port) = $fU; # User Port of the from Header to get the USER + $var(ue_sdp_port) = $sht(user_sdps_port=>$var(sdp_id_ue_port)); + xlog("L_INFO", "SDP Port for UE with MSISDN $var(sdp_id_ue_port) is: $var(ue_sdp_port)\n"); + + + $var(sdp_id_ue_rtcp_port) = $fU; # User Port of the from Header to get the USER + $var(ue_sdp_rtcp_port) = $sht(user_sdps_rtcp_port=>$var(sdp_id_ue_rtcp_port)); + xlog("L_INFO", "SDP Port for UE with MSISDN $var(sdp_id_ue_rtcp_port) is: $var(ue_sdp_rtcp_port)\n"); + +## retrieving 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"); + + +#### now start to build the N5 Request + + xlog("L_ALERT","DEBUG: Preparing N5 Message to PCF for $fu\n"); + + xlog("L_ALERT","DEBUG: Initialize empty arrays and objects\n"); + +### Initialize empty arrays and objects + $var(events) = '[]'; + $var(medComponents) = '{}'; + $var(medSubComps) = '{}'; + $var(evSubsc) = '{}'; + $var(payload) = '{}'; + +### Set afAppId and dnn in payload + jansson_set("string", "afAppId", "urn:urn-7:3gpp-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_answ_ip) $var(sdp_answ_port) to $var(ue_sdp_ip) $var(ue_sdp_port)\", \"permit in 17 from $var(ue_sdp_ip) $var(ue_sdp_port) to $var(sdp_answ_ip) $var(sdp_answ_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_answ_ip) $var(sdp_answ_rtcp_port) to $var(ue_sdp_ip) $var(ue_sdp_rtcp_port)\", \"permit in 17 from $var(ue_sdp_ip) $var(ue_sdp_rtcp_port) to $var(sdp_answ_ip) $var(sdp_answ_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_ALERT","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:8284", "$var(payload)"); + jansson_set("string", "sponStatus", "SPONSOR_DISABLED", "$var(payload)"); + jansson_set("string", "supi", "imsi-$var(ue_imsi_inv)", "$var(payload)"); + jansson_set("string", "gpsi", "msisdn-$fU", "$var(payload)"); + jansson_set("string", "suppFeat", "4", "$var(payload)"); + jansson_set("string", "ueIpv4", "$var(ue_ip_addr)", "$var(payload)"); + + ### Assemble the final JSON request + jansson_set("obj", "ascReqData", "$var(payload)", "$var(json_request)"); + + xlog("L_ALERT","DEBUG: Set headers for the HTTP2 Request\n"); +### Set headers + $var(time_now)=$_s($timef(%a, %d %b %Y %H:%M:%S %Z)); + xlog("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_ALERT","DEBUG: 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)" ); + xlog("HTTP response: $var(result)\n"); + xlog("L_ALERT", "response header: $curlerror(error)\n"); + xlog("L_ALERT", "response header: $var(response_code)\n"); + xlog("L_ALERT", "response header: $httprhdr(location)\n"); + +# Now I will retrieve the AppSessionID out of the location Header it should be always at the end +# Example URL: "http://172.22.0.27:7777/npcf-policyauthorization/v1/app-sessions/(someSessionID)" + +# Firt 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 +# now doing some magic + $var(start_pos) = $var(pos) + 1; + $var(end_pos) = $var(len) - $var(start_pos); + $var(app_session) = $(var(url){s.substr,$var(start_pos),$var(end_pos)}); + +# now checking it on console if I got what I wanted : + xlog("L_INFO", "AppSession for user $au is: $var(app_session)\n"); + +# now trying some way to store AppSession with the registred UE + $var(user_id) = $fU; # should get the user part of the registred UE + + # Store the AppSession in the hash table associated with the UE + $sht(user_data=>$var(user_id)) = $var(app_session); + xlog("L_INFO", "Stored AppSession for user $var(user_id): $var(app_session)\n"); +} + +################################################## +######### END of 5G VoNR N5 Request have Fun! #### +################################################## + + #!ifdef WITH_RX if (t_check_status("183|200") && has_body("application/sdp")){ xlog("L_DBG", "IMS: Received 183/200 inside orig_initial_reply\n"); @@ -162,6 +423,40 @@ route[MO_aar_reply] # In-Dialog-Mo-Requests ###################################################################### route[MO_indialog] { + +################################### +## Terminating N5 QoS AppSession ## +################################### + + if(is_method("BYE")) + { + xlog("L_ALERT","Terminating AppSession For Call fom User $fu\n"); + # Retrieveing + $var(user_id_call_rel) = $fU; # User Part of the from Header to get the USER + $var(user_appsess_call_rel) = $sht(user_data=>$var(user_id_call_rel)); + xlog("L_INFO", "Terminating Stored AppSession for user $var(user_id_dereg): $var(user_id_call_rel)\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_call_rel)/delete", "$var(json_request)", "$var(headers)", "$var(result)" ); + xlog("Termination resuls: $var(result)\n"); + xlog("L_ALERT", "response header: $curlerror(error)\n"); + xlog("L_ALERT", "response header: $var(response_code)\n"); + xlog("L_ALERT", "response header: $httprhdr(location)\n"); + + } + +########################################## +## End of Terminating N5 QoS AppSession ## +########################################## + + xnotice("PCSCF MO_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");