Encompass N5 HTTP2 code with ifdef

This commit is contained in:
herlesupreeth
2024-08-12 10:32:41 +02:00
parent 726dc91b7a
commit b4c9492b39

View File

@@ -229,7 +229,6 @@ loadmodule "ims_qos"
#!endif
#!ifdef WITH_N5
loadmodule "http_async_client"
loadmodule "http_client"
loadmodule "jansson"
loadmodule "nghttp2"
@@ -273,15 +272,6 @@ modparam("jsonrpcs", "fifo_name", "/var/run/kamailio/kamailio_rpc.fifo")
/* set the path to RPC unix socket control file */
modparam("jsonrpcs", "dgram_socket", "/var/run/kamailio/kamailio_rpc.sock")
# Experemental HTTP2 for 5G
loadmodule "nghttp2"
loadmodule "http_client"
loadmodule "jansson"
loadmodule "uuid"
### removed HTTP_CLIENT_ASYC as it only support HTTP1.1 so no use for it untill it get improved
# ----------------- setting module-specific parameters ---------------
#!ifdef DB_URL2
# ----- db_cluster params -----
@@ -451,14 +441,30 @@ modparam("ims_qos", "dialog_direction", RX_IMS_REG_DIALOG_DIRECTION)
#!endif
#!ifdef WITH_N5
# Tables to store users and their session details
modparam("htable", "htable", "user_data=>size=8;autoexpire=3600;")
modparam("htable", "htable", "user_ids=>size=8;autoexpire=3600;")
modparam("htable", "htable", "user_sdps_ip=>size=8;autoexpire=3600;")
modparam("htable", "htable", "user_sdps_port=>size=8;autoexpire=3600;")
modparam("htable", "htable", "user_sdps_rtcp_port=>size=8;autoexpire=3600;")
modparam("htable", "htable", "user_sip_ips=>size=8;autoexpire=3600;")
modparam("htable", "htable", "user_sip_ports=>size=8;autoexpire=3600;")
# HTTP2 for 5G -- Modules Parameters
modparam("http_client", "httpredirect", 1)
modparam("http_client", "useragent", "PCSCF")
modparam("http_client", "maxdatasize", 64535)
modparam("http_client", "connection_timeout", 2)
modparam("http_client", "keep_connections", 1)
modparam("http_client", "response_headers", 1)
modparam("http_client", "query_result", 1)
# modparam("http_client", "httpcon", "pcfapi=>http://N5_BIND_IP:N5_BIND_PORT")
modparam("nghttp2", "listen_addr", "N5_BIND_IP")
modparam("nghttp2", "listen_port", "N5_BIND_PORT")
# Replace the following with your own Key and Cert
# modparam("nghttp2", "tls_private_key", "/mnt/pcscf/http2_key.pem")
# modparam("nghttp2", "tls_public_key", "/mnt/pcscf/http2_tr.pem")
modparam("rtimer", "timer", "name=NRF_NFM;interval=5;mode=1;")
modparam("rtimer", "exec", "timer=NRF_NFM;route=NRF_NFM")
@@ -505,179 +511,6 @@ modparam("statistics", "variable", "register_success")
modparam("statistics", "variable", "register_failed")
modparam("statistics", "variable", "register_time")
# --- Experemental HTTP2 for 5G -- Modules Parameters
# Creating table to store users with there AppSessions
modparam("htable", "htable", "user_data=>size=8;autoexpire=3600;")
modparam("htable", "htable", "user_ids=>size=8;autoexpire=3600;")
modparam("htable", "htable", "user_sdps_ip=>size=8;autoexpire=3600;")
modparam("htable", "htable", "user_sdps_port=>size=8;autoexpire=3600;")
modparam("htable", "htable", "user_sdps_rtcp_port=>size=8;autoexpire=3600;")
modparam("htable", "htable", "user_sip_ips=>size=8;autoexpire=3600;")
modparam("htable", "htable", "user_sip_ports=>size=8;autoexpire=3600;")
modparam("http_client", "httpredirect", 1)
modparam("http_client", "useragent", "PCSCF")
modparam("http_client", "maxdatasize", 64535)
modparam("http_client", "connection_timeout", 2)
modparam("http_client", "keep_connections", 1)
modparam("http_client", "response_headers", 1)
modparam("http_client", "query_result", 1)
modparam("http_client", "httpcon", "pcfapi=>http://172.22.0.27:7777")
modparam("nghttp2", "listen_addr", "172.22.0.21")
# modparam("nghttp2", "listen_port", "8005") # if using SSL Termination like HAProxy
modparam("nghttp2", "listen_port", "7777"
modparam("nghttp2", "tls_private_key", "/mnt/pcscf/http2_key.pem") # you can generate your own Key NGHTTP2 will not run without TLS
modparam("nghttp2", "tls_public_key", "/mnt/pcscf/http2_tr.pem") # you can generate your own Key NGHTTP2 will not run without TLS
modparam("rtimer", "timer", "name=NRF_NFM;interval=5;mode=1;")
modparam("rtimer", "exec", "timer=NRF_NFM;route=NRF_NFM")
####### Routing Logic ########
###################################################
## 5G N5 HTTP2 Server routing script basic code ##
###################################################
event_route[nghttp2:request] {
xinfo("request: $nghttp2(method) - url: $nghttp2(path) - data: [$nghttp2(data)]\n");
// Check if the requested URL is /terminate
if ($nghttp2(path) == "/terminate") {
nghttp2_reply_header("accept", "application/json");
nghttp2_reply_header("accept", "application/problem+json");
nghttp2_reply_header("Content-Type", "application/json");
nghttp2_reply_header("Server", "P-CSCF");
nghttp2_reply("204", "No Content");
} else {
// Optionally handle other URLs or do nothing
nghttp2_reply_header("accept", "application/json");
nghttp2_reply_header("accept", "application/problem+json");
nghttp2_reply_header("Content-Type", "application/json");
nghttp2_reply_header("Server", "PCSCF");
nghttp2_reply("404", "Not Found");
}
}
###################################
## 5G N5 Registring PCSCF to SCP ##
###################################
route[NRF_NFM] {
if ($shv(n5_hb_fail_count) > 5) {
xlog("L_ERR", "PCSCF NF no longer registered at SCP. Re-attempting registration!!\n");
$shv(n5_initalized) = 0;
}
$var(time_now) = $_s($timef(%a, %d %b %Y %H:%M:%S %Z));
# TODO: Send at heartbeat intervals received in reponse to NF registration
if ($shv(n5_initalized) == 1) {
# Send Heartbeat
$var(nf_hb_headers) = "content-type: application/json-patch+json\r\n";
$var(nf_hb_headers) = $var(nf_hb_headers) + "accept: application/json,application/problem+json\r\n";
$var(nf_hb_headers) = $var(nf_hb_headers) + "3gpp-sbi-discovery-target-nf-type: NRF\r\n";
$var(nf_hb_headers) = $var(nf_hb_headers) + "3gpp-sbi-max-rsp-time: 10000\r\n";
$var(nf_hb_headers) = $var(nf_hb_headers) + "3gpp-sbi-discovery-service-names: nnrf-nfm\r\n";
$var(nf_hb_headers) = $var(nf_hb_headers) + "3gpp-sbi-sender-timestamp: " + $var(time_now);
$var(nf_hb_json_body) ='[]';
$var(nf_hb_body) = '{
"op": "replace",
"path": "/nfStatus",
"value": "REGISTERED"
}';
jansson_append("obj", "", $var(nf_hb_body), "$var(nf_hb_json_body)");
$var(nf_hb_body) = '{
"op": "replace",
"path": "/load",
"value": 0
}';
jansson_append("obj", "", $var(nf_hb_body), "$var(nf_hb_json_body)");
http_client_request_v2pk("PATCH", "http://172.22.0.35:7777/nnrf-nfm/v1/nf-instances/$shv(pcscf_uuid)", "$var(nf_hb_json_body)", "$var(nf_hb_headers)", "$var(nf_hb_result)");
switch ($rc) {
case 204:
$shv(n5_hb_fail_count) = 0;
break;
default:
$shv(n5_hb_fail_count) = $shv(n5_hb_fail_count) + 1;
return;
}
return;
}
# Generate UUID for PCSCF
$shv(pcscf_uuid) = $uuid(g);
# Register NF
$var(nf_reg_headers) = "content-type: application/json\r\n";
$var(nf_reg_headers) = $var(nf_reg_headers) + "accept: application/json,application/problem+json\r\n";
$var(nf_reg_headers) = $var(nf_reg_headers) + "3gpp-sbi-discovery-target-nf-type: NRF\r\n";
$var(nf_reg_headers) = $var(nf_reg_headers) + "3gpp-sbi-max-rsp-time: 10000\r\n";
$var(nf_reg_headers) = $var(nf_reg_headers) + "3gpp-sbi-discovery-service-names: nnrf-nfm\r\n";
$var(nf_reg_headers) = $var(nf_reg_headers) + "3gpp-sbi-sender-timestamp: " + $var(time_now);
$var(nf_reg_body) = '{
"nfInstanceId": "$shv(pcscf_uuid)",
"nfType": "PCSCF",
"nfStatus": "REGISTERED",
"ipv4Addresses": ["172.22.0.21"],
"allowedNfTypes": ["SCP", "PCF"],
"priority": 0,
"capacity": 100,
"load": 0,
"nfServiceList": {
"$shv(pcscf_uuid)": {
"serviceInstanceId": "$shv(pcscf_uuid)",
"serviceName": "npcf-policyauthorization",
"versions": [
{
"apiVersionInUri": "v2",
"apiFullVersion": "2.0.0"
}
],
"scheme": "http",
"nfServiceStatus": "REGISTERED",
"ipEndPoints": [
{
"ipv4Address": "172.22.0.21",
"port": 8284
}
],
"allowedNfTypes": [
"PCF"
],
"priority": 0,
"capacity": 100,
"load": 0
}
},
"nfProfileChangesSupportInd": true
}';
jansson_append("obj", "", "$var(nf_reg_body)", "$var(nf_reg_json_body)");
http_client_request_v2pk("PUT", "http://172.22.0.35:7777/nnrf-nfm/v1/nf-instances/$shv(pcscf_uuid)", "$var(nf_reg_json_body)", "$var(nf_reg_headers)", "$var(nf_reg_result)");
switch ($rc) {
case 201:
xlog("L_INFO", "P-CSCF NF registered successfully at SCP\n");
$shv(n5_initalized) = 1;
$shv(n5_hb_fail_count) = 0;
break;
default:
xlog("L_ERR", "P-CSCF NF failed to register at SCP with code=$rc\n");
return;
}
}
###############################
## End of 5G Experement #######
###############################
# Main SIP request routing logic
# - processing of any incoming SIP request starts with this route
route {
@@ -1185,6 +1018,8 @@ route[preload_pcscf] {
#!endif
#!ifdef WITH_N5
# 5G N5 HTTP2 Server routing script basic code
event_route[nghttp2:request] {
xinfo("request: $nghttp2(method) - url: $nghttp2(path) - data: [$nghttp2(data)]\n");
@@ -1193,10 +1028,20 @@ event_route[nghttp2:request] {
nghttp2_reply_header("Content-Type", "text/html");
nghttp2_reply_header("Server:", "PCSCF");
nghttp2_reply("200", "<html><body>PCF registered at PCSCF</body></html>");
} else {
// Optionally handle other URLs or do nothing
nghttp2_reply("404", "<html><body>Not Found</body></html>");
}
} else if ($nghttp2(path) == "/terminate") {
nghttp2_reply_header("accept", "application/json");
nghttp2_reply_header("accept", "application/problem+json");
nghttp2_reply_header("Content-Type", "application/json");
nghttp2_reply_header("Server", "PCSCF");
nghttp2_reply("204", "No Content");
} else {
// Optionally handle other URLs or do nothing
nghttp2_reply_header("accept", "application/json");
nghttp2_reply_header("accept", "application/problem+json");
nghttp2_reply_header("Content-Type", "application/json");
nghttp2_reply_header("Server", "PCSCF");
nghttp2_reply("404", "Not Found");
}
}
route[NRF_NFM] {