move N5 logic to its own route block and call to it from other logics
moved both N5 creation and deletion requests to own route block. add calls to the N5 route logic in the main route where needed. change SuppFeat to 2 instead of 4
This commit is contained in:
committed by
Supreeth Herle
parent
8991a2e3b2
commit
c361c21a03
@@ -21,6 +21,21 @@ route[REGISTER] {
|
||||
exit;
|
||||
}
|
||||
|
||||
### N5 Request create and terminate
|
||||
xlog("L_ALERT","Checking if its a Registration and not a De-Reg for $fu\n");
|
||||
$var(reg_exp) = $expires(min);
|
||||
xlog("L_ALERT","Checking Expire $fu and it is : $var(reg_exp)\n");
|
||||
|
||||
# tying a dirty workaround to make it only excute after IPSec tunnel to prevent double excution
|
||||
if ($expires(min) != 0 && is_present_hf("Security-Verify")) {
|
||||
route(REGISTER_N5_Req);
|
||||
}
|
||||
|
||||
if ($expires(min) == 0 ) {
|
||||
xlog("L_ALERT","delete N5 Session for $fu due to de-register\n");
|
||||
route(REG_N5_TERMINATE);
|
||||
}
|
||||
|
||||
#!ifdef WITH_IPSEC
|
||||
$sht(ipsec_clients=>$(ct{nameaddr.uri})) = $null;
|
||||
if ($hdr(Security-Client) =~ ".*ipsec-3gpp.*") {
|
||||
@@ -34,192 +49,6 @@ route[REGISTER] {
|
||||
else
|
||||
$ru = "sip:"+$rU+"@"+$rd;
|
||||
|
||||
################################################################################
|
||||
################################################################################
|
||||
##### 5G Experemntal PCF N5 Interface Reg #Route Added by Abdul Karim Barbour##
|
||||
################################################################################
|
||||
################################################################################
|
||||
|
||||
xlog("L_ALERT","DEBUG: Preparing N5 Message to PCF for $fu\n");
|
||||
|
||||
xlog("L_ALERT","Checking if its a Registration and not a De-Reg for $fu\n");
|
||||
$var(reg_exp) = $expires(min);
|
||||
xlog("L_ALERT","Checking Expire $fu and it is : $var(reg_exp)\n");
|
||||
|
||||
# tying a dirty workaround to make it only excute after IPSec tunnel to prevent double excution
|
||||
if ($expires(min) != 0 && is_present_hf("Security-Verify")) {
|
||||
xlog("L_ALERT","its a Registration, starting N5 Auth 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", "IMS Services Register", "$var(payload)");
|
||||
jansson_set("string", "dnn", "ims", "$var(payload)");
|
||||
|
||||
### Set medComponents
|
||||
jansson_set("integer", "medCompN", 0, "$var(medComp)");
|
||||
jansson_set("string", "qosReference", "qosVoNR", "$var(medComp)");
|
||||
jansson_set("string", "medType", "CONTROL", "$var(medComp)");
|
||||
# jansson_set("array", "codecs", "[\"downlink\\noffer\\n\", \"uplink\\nanswer\\n\"]", "$var(medComp)");
|
||||
# jansson_set("string", "fStatus", "ENABLED", "$var(medComp)");
|
||||
|
||||
jansson_set("integer", "fNum", 0, "$var(medSubComp)");
|
||||
jansson_set("array", "fDescs", "[\"permit out ip from $Ri $Rp to $si $sp\", \"permit in ip from $si $sp to $Ri $RAp\"]", "$var(medSubComp)");
|
||||
jansson_set("string", "fStatus", "ENABLED", "$var(medSubComp)");
|
||||
jansson_set("string", "flowUsage", "AF_SIGNALLING", "$var(medSubComp)");
|
||||
# jansson_set("string", "marBwDl", "5000 Kbps", "$var(medSubComp)");
|
||||
# jansson_set("string", "marBwUl", "3000 Kbps", "$var(medSubComp)");
|
||||
jansson_set("obj", "0", "$var(medSubComp)", "$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-$au", "$var(payload)");
|
||||
jansson_set("string", "suppFeat", "4", "$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_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");
|
||||
|
||||
|
||||
xlog("L_ALERT","Saving AppSessionID to HTABLE\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) = $au; # 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");
|
||||
|
||||
#######
|
||||
## Storing IMSI for later use :
|
||||
######
|
||||
|
||||
xlog("L_ALERT","Storing User IMSI to HTABLE for later use\n");
|
||||
$var(ue_imsi) = $au;
|
||||
|
||||
# now checking it on console if I got what I wanted :
|
||||
xlog("L_INFO", "IP for UE is: $var(ue_imsi)\n");
|
||||
|
||||
# now trying some way to store AppSession with the registred UE
|
||||
$var(ue_imsi_reg_ip) = $si; # should get the user part of the registred UE
|
||||
|
||||
# Store the AppSession in the hash table associated with the UE
|
||||
$sht(user_ids=>$var(ue_imsi_reg_ip)) = $var(ue_imsi);
|
||||
xlog("L_INFO", "Stored IMSI for IP $var(ue_imsi_reg_ip) is: $var(ue_imsi)\n");
|
||||
|
||||
# now contiue with Reg Proccess
|
||||
|
||||
}
|
||||
|
||||
###########################
|
||||
## Terminating AppSession #
|
||||
###########################
|
||||
|
||||
|
||||
if ($expires(min) == 0 || t_check_status("401")) {
|
||||
xlog("L_ALERT","its a De-Registration for $fu, terminating N5 AppSession\n");
|
||||
# Retrieveing
|
||||
$var(user_id_dereg) = $fU; # User Part of the from Header to get the USER
|
||||
$var(user_appsess_dereg) = $sht(user_data=>$var(user_id_dereg));
|
||||
xlog("L_INFO", "Terminating Stored AppSession for user $var(user_id_dereg): $var(user_appsess_dereg)\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_dereg)/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 5G Experemntal PCF N5 Interface Reg #Route Added by Abdul Karim Barbour#####
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
|
||||
|
||||
#!ifdef WITH_RX
|
||||
if ($expires(min) != 0) {
|
||||
xlog("L_DBG","Subscribing to signalling bearer status\n");
|
||||
@@ -480,6 +309,13 @@ onreply_route[REGISTER_reply]
|
||||
######################################################################
|
||||
failure_route[REGISTER_failure]
|
||||
{
|
||||
|
||||
# Terminate N5 Session on Reg Failure
|
||||
|
||||
if (t_check_status("403|408|[5-6][0-9][0-9]")) {
|
||||
route(REG_N5_TERMINATE);
|
||||
}
|
||||
|
||||
#!ifdef WITH_IPBLOCK
|
||||
if (t_check_status("403|[5-6][0-9][0-9]")) {
|
||||
if ($sht(failedauth=>$si) != $null)
|
||||
@@ -499,4 +335,180 @@ failure_route[REGISTER_failure]
|
||||
update_stat("register_failed", "+1");
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#############################################
|
||||
##### 5G Experemntal PCF N5 Interface Reg ##
|
||||
#############################################
|
||||
|
||||
route[REGISTER_N5_Req]
|
||||
{
|
||||
|
||||
|
||||
xlog("L_ALERT","its a Registration, starting N5 Auth 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", "+g.3gpp.icsi-ref=\"urn%3Aurn-7%3A3gpp-service.ims.icsi.mmtel\"", "$var(payload)"); # adding a note that this could be improved in future to get the value SIP Header
|
||||
jansson_set("string", "dnn", "ims", "$var(payload)");
|
||||
|
||||
### Set medComponents
|
||||
jansson_set("integer", "medCompN", 0, "$var(medComp)");
|
||||
jansson_set("string", "qosReference", "qosVoNR", "$var(medComp)");
|
||||
jansson_set("string", "medType", "CONTROL", "$var(medComp)");
|
||||
|
||||
jansson_set("integer", "fNum", 0, "$var(medSubComp)");
|
||||
jansson_set("array", "fDescs", "[\"permit out ip from $RAi $RAp to $si $sp\", \"permit in ip from $si $sp to $RAi $RAp\"]", "$var(medSubComp)");
|
||||
jansson_set("string", "fStatus", "ENABLED", "$var(medSubComp)");
|
||||
jansson_set("string", "flowUsage", "AF_SIGNALLING", "$var(medSubComp)");
|
||||
# jansson_set("string", "marBwDl", "5000 Kbps", "$var(medSubComp)");
|
||||
# jansson_set("string", "marBwUl", "3000 Kbps", "$var(medSubComp)");
|
||||
jansson_set("obj", "0", "$var(medSubComp)", "$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-$au", "$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_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("L_ALERT", "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("L_ALERT", "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");
|
||||
|
||||
|
||||
xlog("L_ALERT","Saving AppSessionID to HTABLE\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) = $au; # 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");
|
||||
|
||||
#######
|
||||
## Storing IMSI for later use :
|
||||
######
|
||||
|
||||
xlog("L_ALERT","Storing User IMSI to HTABLE for later use\n");
|
||||
$var(ue_imsi) = $au;
|
||||
|
||||
# now checking it on console if I got what I wanted :
|
||||
xlog("L_INFO", "IP for UE is: $var(ue_imsi)\n");
|
||||
|
||||
# now trying some way to store AppSession with the registred UE
|
||||
$var(ue_imsi_reg_ip) = $si; # should get the user part of the registred UE
|
||||
|
||||
# Store the AppSession in the hash table associated with the UE
|
||||
$sht(user_ids=>$var(ue_imsi_reg_ip)) = $var(ue_imsi);
|
||||
xlog("L_INFO", "Stored IMSI for IP $var(ue_imsi_reg_ip) is: $var(ue_imsi)\n");
|
||||
|
||||
# now contiue with Reg Proccess
|
||||
|
||||
### N5 REQ Route END
|
||||
}
|
||||
|
||||
###########################
|
||||
## Terminating AppSession #
|
||||
###########################
|
||||
route[REG_N5_TERMINATE]
|
||||
{
|
||||
xlog("L_ALERT","its a De-Registration for $fu, terminating N5 AppSession\n");
|
||||
# Retrieveing
|
||||
$var(user_id_dereg) = $fU; # User Part of the from Header to get the USER
|
||||
$var(user_appsess_dereg) = $sht(user_data=>$var(user_id_dereg));
|
||||
xlog("L_INFO", "Terminating Stored AppSession for user $var(user_id_dereg): $var(user_appsess_dereg)\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_dereg)/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");
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user