Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-SMF
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenXG
OpenXG-SMF
Commits
30165886
Commit
30165886
authored
Jan 06, 2021
by
Tien-Thinh Nguyen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First version for Register/Update NF Instance to NRF
parent
d2640197
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
485 additions
and
9 deletions
+485
-9
src/common/smf.h
src/common/smf.h
+6
-1
src/smf_app/smf_app.cpp
src/smf_app/smf_app.cpp
+110
-0
src/smf_app/smf_app.hpp
src/smf_app/smf_app.hpp
+44
-0
src/smf_app/smf_n11.cpp
src/smf_app/smf_n11.cpp
+170
-0
src/smf_app/smf_n11.hpp
src/smf_app/smf_n11.hpp
+7
-0
src/smf_app/smf_profile.cpp
src/smf_app/smf_profile.cpp
+93
-0
src/smf_app/smf_profile.hpp
src/smf_app/smf_profile.hpp
+55
-8
No files found.
src/common/smf.h
View file @
30165886
...
@@ -91,7 +91,9 @@ typedef uint8_t pdu_session_id;
...
@@ -91,7 +91,9 @@ typedef uint8_t pdu_session_id;
//SMF + AMF + 3GPP TS 29.571 (Common data)
//SMF + AMF + 3GPP TS 29.571 (Common data)
enum
class
http_response_codes_e
{
enum
class
http_response_codes_e
{
HTTP_RESPONSE_CODE_OK
=
200
,
HTTP_RESPONSE_CODE_OK
=
200
,
HTTP_RESPONSE_CODE_CREATED
=
201
,
HTTP_RESPONSE_CODE_ACCEPTED
=
202
,
HTTP_RESPONSE_CODE_ACCEPTED
=
202
,
HTTP_RESPONSE_CODE_NO_CONTENT
=
204
,
HTTP_RESPONSE_CODE_BAD_REQUEST
=
400
,
HTTP_RESPONSE_CODE_BAD_REQUEST
=
400
,
HTTP_RESPONSE_CODE_UNAUTHORIZED
=
401
,
HTTP_RESPONSE_CODE_UNAUTHORIZED
=
401
,
HTTP_RESPONSE_CODE_FORBIDDEN
=
403
,
HTTP_RESPONSE_CODE_FORBIDDEN
=
403
,
...
@@ -201,6 +203,10 @@ typedef struct qos_profile_s {
...
@@ -201,6 +203,10 @@ typedef struct qos_profile_s {
#define NSMF_PDU_SESSION_SM_CONTEXT_CREATE_URL "/sm-contexts"
#define NSMF_PDU_SESSION_SM_CONTEXT_CREATE_URL "/sm-contexts"
#define NSMF_PDU_SESSION_SM_CONTEXT_UPDATE_URL "/sm-contexts/"
#define NSMF_PDU_SESSION_SM_CONTEXT_UPDATE_URL "/sm-contexts/"
//NRF
#define NNRF_NFM_BASE "/nnrf-nfm/"
#define NNRF_NF_REGISTER_URL "/nf-instances/"
//for CURL
//for CURL
#define AMF_CURL_TIMEOUT_MS 100L
#define AMF_CURL_TIMEOUT_MS 100L
#define AMF_NUMBER_RETRIES 3
#define AMF_NUMBER_RETRIES 3
...
@@ -225,7 +231,6 @@ typedef struct dnn_smf_info_item_s {
...
@@ -225,7 +231,6 @@ typedef struct dnn_smf_info_item_s {
typedef
struct
snssai_smf_info_item_s
{
typedef
struct
snssai_smf_info_item_s
{
snssai_t
snssai
;
snssai_t
snssai
;
std
::
vector
<
dnn_smf_info_item_t
>
dnn_smf_info_list
;
std
::
vector
<
dnn_smf_info_item_t
>
dnn_smf_info_list
;
}
snssai_smf_info_item_t
;
}
snssai_smf_info_item_t
;
typedef
struct
smf_info_s
{
typedef
struct
smf_info_s
{
...
...
src/smf_app/smf_app.cpp
View file @
30165886
...
@@ -32,6 +32,8 @@
...
@@ -32,6 +32,8 @@
#include <cstdlib>
#include <cstdlib>
#include <iostream>
#include <iostream>
#include <stdexcept>
#include <stdexcept>
#include <boost/uuid/random_generator.hpp>
#include <boost/uuid/uuid_io.hpp>
#include "3gpp_24.007.h"
#include "3gpp_24.007.h"
#include "3gpp_24.501.h"
#include "3gpp_24.501.h"
...
@@ -252,6 +254,13 @@ void smf_app_task(void *) {
...
@@ -252,6 +254,13 @@ void smf_app_task(void *) {
}
}
break
;
break
;
case
N11_REGISTER_NF_INSTANCE_RESPONSE
:
if
(
itti_n11_register_nf_instance_response
*
m
=
dynamic_cast
<
itti_n11_register_nf_instance_response
*>
(
msg
))
{
smf_app_inst
->
handle_itti_msg
(
std
::
ref
(
*
m
));
}
break
;
case
TIME_OUT
:
case
TIME_OUT
:
if
(
itti_msg_timeout
*
to
=
dynamic_cast
<
itti_msg_timeout
*>
(
msg
))
{
if
(
itti_msg_timeout
*
to
=
dynamic_cast
<
itti_msg_timeout
*>
(
msg
))
{
Logger
::
smf_app
().
info
(
"TIME-OUT event timer id %d"
,
to
->
timer_id
);
Logger
::
smf_app
().
info
(
"TIME-OUT event timer id %d"
,
to
->
timer_id
);
...
@@ -259,6 +268,9 @@ void smf_app_task(void *) {
...
@@ -259,6 +268,9 @@ void smf_app_task(void *) {
case
TASK_SMF_APP_TRIGGER_T3591
:
case
TASK_SMF_APP_TRIGGER_T3591
:
smf_app_inst
->
timer_t3591_timeout
(
to
->
timer_id
,
to
->
arg2_user
);
smf_app_inst
->
timer_t3591_timeout
(
to
->
timer_id
,
to
->
arg2_user
);
break
;
break
;
case
TASK_SMF_APP_TIMEOUT_NRF_HEARTBEAT
:
smf_app_inst
->
timer_nrf_heartbeat_timeout
(
to
->
timer_id
,
to
->
arg2_user
);
break
;
default:
;
default:
;
}
}
}
}
...
@@ -318,6 +330,9 @@ smf_app::smf_app(const std::string &config_file)
...
@@ -318,6 +330,9 @@ smf_app::smf_app(const std::string &config_file)
start_upf_association
(
*
it
);
start_upf_association
(
*
it
);
}
}
//Register to NRF
register_to_nrf
();
Logger
::
smf_app
().
startup
(
"Started"
);
Logger
::
smf_app
().
startup
(
"Started"
);
}
}
...
@@ -547,6 +562,15 @@ void smf_app::handle_itti_msg(itti_n11_release_sm_context_response &m) {
...
@@ -547,6 +562,15 @@ void smf_app::handle_itti_msg(itti_n11_release_sm_context_response &m) {
}
}
}
}
void
smf_app
::
handle_itti_msg
(
itti_n11_register_nf_instance_response
&
r
)
{
Logger
::
smf_app
().
debug
(
"NF Instance Registration response"
);
//Set heartbeat timer
timer_nrf_heartbeat
=
itti_inst
->
timer_setup
(
r
.
profile
.
get_nf_heartBeat_timer
(),
0
,
TASK_SMF_APP
,
TASK_SMF_APP_TIMEOUT_NRF_HEARTBEAT
,
0
);
//TODO arg2_user
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void
smf_app
::
handle_pdu_session_create_sm_context_request
(
void
smf_app
::
handle_pdu_session_create_sm_context_request
(
std
::
shared_ptr
<
itti_n11_create_sm_context_request
>
smreq
)
{
std
::
shared_ptr
<
itti_n11_create_sm_context_request
>
smreq
)
{
...
@@ -1367,6 +1391,32 @@ void smf_app::timer_t3591_timeout(timer_id_t timer_id, uint64_t arg2_user) {
...
@@ -1367,6 +1391,32 @@ void smf_app::timer_t3591_timeout(timer_id_t timer_id, uint64_t arg2_user) {
// TODO: send session modification request again...
// TODO: send session modification request again...
}
}
//---------------------------------------------------------------------------------------------
void
smf_app
::
timer_nrf_heartbeat_timeout
(
timer_id_t
timer_id
,
uint64_t
arg2_user
)
{
// TODO: send Heatbeat to NRF
Logger
::
smf_app
().
debug
(
"Send ITTI msg to N11 task to trigger NRF Heartbeat"
);
std
::
shared_ptr
<
itti_n11_update_nf_instance_request
>
itti_msg
=
std
::
make_shared
<
itti_n11_update_nf_instance_request
>
(
TASK_SMF_APP
,
TASK_SMF_N11
);
oai
::
smf_server
::
model
::
PatchItem
patch_item
=
{};
//{"op":"replace","path":"/nfInstanceName", "value": "OAI-SMF"}
patch_item
.
setOp
(
"replace"
);
patch_item
.
setPath
(
"/nfInstanceName"
);
patch_item
.
setValue
(
"OAI-SMF"
);
itti_msg
->
patch_items
.
push_back
(
patch_item
);
itti_msg
->
smf_instance_id
=
smf_instance_id
;
int
ret
=
itti_inst
->
send_msg
(
itti_msg
);
if
(
RETURNok
!=
ret
)
{
Logger
::
smf_app
().
error
(
"Could not send ITTI message %s to task TASK_SMF_N11"
,
itti_msg
->
get_msg_name
());
}
}
//---------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
n2_sm_info_type_e
smf_app
::
n2_sm_info_type_str2e
(
n2_sm_info_type_e
smf_app
::
n2_sm_info_type_str2e
(
const
std
::
string
&
n2_info_type
)
const
{
const
std
::
string
&
n2_info_type
)
const
{
...
@@ -1672,3 +1722,63 @@ void smf_app::get_ee_subscriptions(
...
@@ -1672,3 +1722,63 @@ void smf_app::get_ee_subscriptions(
}
}
}
}
}
}
//---------------------------------------------------------------------------------------------
void
smf_app
::
generate_smf_profile
()
{
// generate UUID
generate_uuid
();
nf_profile
.
set_nf_instance_id
(
smf_instance_id
);
nf_profile
.
set_nf_instance_name
(
"OAI-SMF"
);
nf_profile
.
set_nf_type
(
"SMF"
);
nf_profile
.
set_nf_status
(
"REGISTERED"
);
nf_profile
.
set_nf_heartBeat_timer
(
50
);
nf_profile
.
set_nf_priority
(
1
);
nf_profile
.
set_nf_capacity
(
100
);
nf_profile
.
add_nf_ipv4_addresses
(
smf_cfg
.
sbi
.
addr4
);
// custom info
for
(
auto
s
:
smf_cfg
.
session_management_subscription
)
{
// SNSSAIS
snssai_t
snssai
=
{};
snssai
.
sD
=
s
.
single_nssai
.
sD
;
snssai
.
sST
=
s
.
single_nssai
.
sST
;
nf_profile
.
add_snssai
(
snssai
);
// SMF info
dnn_smf_info_item_t
dnn_item
=
{.
dnn
=
s
.
dnn
};
snssai_smf_info_item_t
smf_info_item
=
{};
smf_info_item
.
dnn_smf_info_list
.
push_back
(
dnn_item
);
smf_info_item
.
snssai
.
sD
=
s
.
single_nssai
.
sD
;
smf_info_item
.
snssai
.
sST
=
s
.
single_nssai
.
sST
;
nf_profile
.
add_smf_info_item
(
smf_info_item
);
}
}
//---------------------------------------------------------------------------------------------
void
smf_app
::
register_to_nrf
()
{
// create a NF profile to this instance
generate_smf_profile
();
// send request to N11 to send NF registration to NRF
trigger_nf_registration_request
();
}
//------------------------------------------------------------------------------
void
smf_app
::
generate_uuid
()
{
smf_instance_id
=
to_string
(
boost
::
uuids
::
random_generator
()());
}
//------------------------------------------------------------------------------
void
smf_app
::
trigger_nf_registration_request
()
{
Logger
::
smf_app
().
debug
(
"Send ITTI msg to N11 task to trigger the registration request to NRF"
);
std
::
shared_ptr
<
itti_n11_register_nf_instance_request
>
itti_msg
=
std
::
make_shared
<
itti_n11_register_nf_instance_request
>
(
TASK_SMF_APP
,
TASK_SMF_N11
);
itti_msg
->
profile
=
nf_profile
;
int
ret
=
itti_inst
->
send_msg
(
itti_msg
);
if
(
RETURNok
!=
ret
)
{
Logger
::
smf_app
().
error
(
"Could not send ITTI message %s to task TASK_SMF_N11"
,
itti_msg
->
get_msg_name
());
}
}
src/smf_app/smf_app.hpp
View file @
30165886
...
@@ -52,6 +52,7 @@
...
@@ -52,6 +52,7 @@
#include "smf_msg.hpp"
#include "smf_msg.hpp"
#include "smf_pco.hpp"
#include "smf_pco.hpp"
#include "smf_subscription.hpp"
#include "smf_subscription.hpp"
#include "smf_profile.hpp"
namespace
smf
{
namespace
smf
{
...
@@ -59,6 +60,7 @@ namespace smf {
...
@@ -59,6 +60,7 @@ namespace smf {
#define TASK_SMF_APP_TIMEOUT_T3591 (1)
#define TASK_SMF_APP_TIMEOUT_T3591 (1)
#define TASK_SMF_APP_TRIGGER_T3592 (2)
#define TASK_SMF_APP_TRIGGER_T3592 (2)
#define TASK_SMF_APP_TIMEOUT_T3592 (3)
#define TASK_SMF_APP_TIMEOUT_T3592 (3)
#define TASK_SMF_APP_TIMEOUT_NRF_HEARTBEAT (4)
// Table 10.3.2 @3GPP TS 24.501 V16.1.0 (2019-06)
// Table 10.3.2 @3GPP TS 24.501 V16.1.0 (2019-06)
#define T3591_TIMER_VALUE_SEC 16
#define T3591_TIMER_VALUE_SEC 16
...
@@ -136,6 +138,10 @@ class smf_app {
...
@@ -136,6 +138,10 @@ class smf_app {
pdu_session_release_sm_context_response
>>>
pdu_session_release_sm_context_response
>>>
sm_context_release_promises
;
sm_context_release_promises
;
smf_profile
nf_profile
;
//SMF profile
std
::
string
smf_instance_id
;
// SMF instance id
timer_id_t
timer_nrf_heartbeat
;
/*
/*
* Apply the config from the configuration file for DNN pools
* Apply the config from the configuration file for DNN pools
* @param [const smf_config &cfg] cfg
* @param [const smf_config &cfg] cfg
...
@@ -340,6 +346,13 @@ class smf_app {
...
@@ -340,6 +346,13 @@ class smf_app {
*/
*/
void
handle_itti_msg
(
itti_n11_n1n2_message_transfer_response_status
&
snm
);
void
handle_itti_msg
(
itti_n11_n1n2_message_transfer_response_status
&
snm
);
/*
* Handle ITTI message from N11 (NFRegiser Response)
* @param [itti_n11_register_nf_instance_response&] r
* @return void
*/
void
handle_itti_msg
(
itti_n11_register_nf_instance_response
&
r
);
/*
/*
* Restore a N4 Session
* Restore a N4 Session
* @param [const seid_t &] seid: Session ID to be restored
* @param [const seid_t &] seid: Session ID to be restored
...
@@ -603,6 +616,8 @@ class smf_app {
...
@@ -603,6 +616,8 @@ class smf_app {
*/
*/
void
timer_t3591_timeout
(
timer_id_t
timer_id
,
uint64_t
arg2_user
);
void
timer_t3591_timeout
(
timer_id_t
timer_id
,
uint64_t
arg2_user
);
void
timer_nrf_heartbeat_timeout
(
timer_id_t
timer_id
,
uint64_t
arg2_user
);
/*
/*
* To start an association with a UPF (SMF-initiated association)
* To start an association with a UPF (SMF-initiated association)
* @param [const pfcp::node_id_t] node_id: UPF Node ID
* @param [const pfcp::node_id_t] node_id: UPF Node ID
...
@@ -750,6 +765,35 @@ class smf_app {
...
@@ -750,6 +765,35 @@ class smf_app {
void
get_ee_subscriptions
(
void
get_ee_subscriptions
(
smf_event_t
ev
,
supi64_t
supi
,
pdu_session_id_t
pdu_session_id
,
smf_event_t
ev
,
supi64_t
supi
,
pdu_session_id_t
pdu_session_id
,
std
::
vector
<
std
::
shared_ptr
<
smf_subscription
>>
&
subscriptions
);
std
::
vector
<
std
::
shared_ptr
<
smf_subscription
>>
&
subscriptions
);
/*
* Trigger NF instance registration to NRF
* @param [void]
* @return void
*/
void
register_to_nrf
();
/*
* Generate a random UUID for SMF instance
* @param [void]
* @return void
*/
void
generate_uuid
();
/*
* Generate a SMF profile for this instance
* @param [void]
* @return void
*/
void
generate_smf_profile
();
/*
* Send request to N11 task to trigger NF instance registration to NRF
* @param [void]
* @return void
*/
void
trigger_nf_registration_request
();
};
};
}
}
#include "smf_config.hpp"
#include "smf_config.hpp"
...
...
src/smf_app/smf_n11.cpp
View file @
30165886
...
@@ -106,6 +106,18 @@ void smf_n11_task(void *args_p) {
...
@@ -106,6 +106,18 @@ void smf_n11_task(void *args_p) {
shared_msg
));
shared_msg
));
break
;
break
;
case
N11_REGISTER_NF_INSTANCE_REQUEST
:
smf_n11_inst
->
register_nf_instance
(
std
::
static_pointer_cast
<
itti_n11_register_nf_instance_request
>
(
shared_msg
));
break
;
case
N11_UPDATE_NF_INSTANCE_REQUEST
:
smf_n11_inst
->
update_nf_instance
(
std
::
static_pointer_cast
<
itti_n11_update_nf_instance_request
>
(
shared_msg
));
break
;
case
TERMINATE
:
case
TERMINATE
:
if
(
itti_msg_terminate
*
terminate
=
if
(
itti_msg_terminate
*
terminate
=
dynamic_cast
<
itti_msg_terminate
*>
(
msg
))
{
dynamic_cast
<
itti_msg_terminate
*>
(
msg
))
{
...
@@ -640,4 +652,162 @@ CURL *smf_n11::curl_create_handle(event_notification &ev_notif,
...
@@ -640,4 +652,162 @@ CURL *smf_n11::curl_create_handle(event_notification &ev_notif,
return
curl
;
return
curl
;
}
}
//-----------------------------------------------------------------------------------------------------
void
smf_n11
::
register_nf_instance
(
std
::
shared_ptr
<
itti_n11_register_nf_instance_request
>
msg
)
{
Logger
::
smf_n11
().
debug
(
"Send NF Instance Registration to NRF (HTTP version %d)"
,
msg
->
http_version
);
nlohmann
::
json
json_data
=
{};
msg
->
profile
.
to_json
(
json_data
);
std
::
string
url
=
std
::
string
(
inet_ntoa
(
*
((
struct
in_addr
*
)
&
smf_cfg
.
nrf_addr
.
ipv4_addr
)))
+
":"
+
std
::
to_string
(
smf_cfg
.
nrf_addr
.
port
)
+
NNRF_NFM_BASE
+
smf_cfg
.
nrf_addr
.
api_version
+
NNRF_NF_REGISTER_URL
+
msg
->
profile
.
get_nf_instance_id
();
Logger
::
smf_n11
().
debug
(
"Send NF Instance Registration to NRF (NRF URL %s)"
,
url
.
c_str
());
std
::
string
body
=
json_data
.
dump
();
Logger
::
smf_n11
().
debug
(
"Send NF Instance Registration to NRF (Msg body %s)"
,
body
.
c_str
());
curl_global_init
(
CURL_GLOBAL_ALL
);
CURL
*
curl
=
curl
=
curl_easy_init
();
if
(
curl
)
{
CURLcode
res
=
{};
struct
curl_slist
*
headers
=
nullptr
;
// headers = curl_slist_append(headers, "charsets: utf-8");
headers
=
curl_slist_append
(
headers
,
"content-type: application/json"
);
curl_easy_setopt
(
curl
,
CURLOPT_HTTPHEADER
,
headers
);
curl_easy_setopt
(
curl
,
CURLOPT_URL
,
url
.
c_str
());
curl_easy_setopt
(
curl
,
CURLOPT_HTTPGET
,
1
);
curl_easy_setopt
(
curl
,
CURLOPT_CUSTOMREQUEST
,
"PUT"
);
curl_easy_setopt
(
curl
,
CURLOPT_TIMEOUT_MS
,
AMF_CURL_TIMEOUT_MS
);
if
(
msg
->
http_version
==
2
)
{
curl_easy_setopt
(
curl
,
CURLOPT_VERBOSE
,
1L
);
// we use a self-signed test server, skip verification during debugging
curl_easy_setopt
(
curl
,
CURLOPT_SSL_VERIFYPEER
,
0L
);
curl_easy_setopt
(
curl
,
CURLOPT_SSL_VERIFYHOST
,
0L
);
curl_easy_setopt
(
curl
,
CURLOPT_HTTP_VERSION
,
CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE
);
}
// Response information.
long
httpCode
=
{
0
};
std
::
unique_ptr
<
std
::
string
>
httpData
(
new
std
::
string
());
curl_easy_setopt
(
curl
,
CURLOPT_WRITEFUNCTION
,
&
callback
);
curl_easy_setopt
(
curl
,
CURLOPT_WRITEDATA
,
httpData
.
get
());
curl_easy_setopt
(
curl
,
CURLOPT_POSTFIELDSIZE
,
body
.
length
());
curl_easy_setopt
(
curl
,
CURLOPT_POSTFIELDS
,
body
.
c_str
());
res
=
curl_easy_perform
(
curl
);
curl_easy_getinfo
(
curl
,
CURLINFO_RESPONSE_CODE
,
&
httpCode
);
Logger
::
smf_n11
().
debug
(
"Response from AMF, Http Code: %d"
,
httpCode
);
if
(
static_cast
<
http_response_codes_e
>
(
httpCode
)
==
http_response_codes_e
::
HTTP_RESPONSE_CODE_CREATED
)
{
Logger
::
smf_n11
().
debug
(
"Got successful response from NRF"
);
json
response_data
=
{};
try
{
response_data
=
json
::
parse
(
*
httpData
.
get
());
}
catch
(
json
::
exception
&
e
)
{
Logger
::
smf_n11
().
warn
(
"Could not parse json from the NRF response"
);
}
Logger
::
smf_n11
().
debug
(
"Response from NRF, Http Code: %d"
,
httpCode
);
// send response to APP to process
std
::
shared_ptr
<
itti_n11_register_nf_instance_response
>
itti_msg
=
std
::
make_shared
<
itti_n11_register_nf_instance_response
>
(
TASK_SMF_N11
,
TASK_SMF_APP
);
itti_msg
->
http_response_code
=
httpCode
;
itti_msg
->
http_version
=
msg
->
http_version
;
itti_msg
->
profile
.
from_json
(
response_data
);
int
ret
=
itti_inst
->
send_msg
(
itti_msg
);
if
(
RETURNok
!=
ret
)
{
Logger
::
smf_n11
().
error
(
"Could not send ITTI message %s to task TASK_SMF_APP"
,
itti_msg
->
get_msg_name
());
}
}
else
{
Logger
::
smf_n11
().
warn
(
"Could not get response from NRF"
);
}
curl_slist_free_all
(
headers
);
curl_easy_cleanup
(
curl
);
}
curl_global_cleanup
();
}
//-----------------------------------------------------------------------------------------------------
void
smf_n11
::
update_nf_instance
(
std
::
shared_ptr
<
itti_n11_update_nf_instance_request
>
msg
)
{
Logger
::
smf_n11
().
debug
(
"Send NF Instance Registration to NRF (HTTP version %d)"
,
msg
->
http_version
);
nlohmann
::
json
json_data
=
nlohmann
::
json
::
array
();
for
(
auto
i
:
msg
->
patch_items
)
{
nlohmann
::
json
item
=
{};
to_json
(
item
,
i
);
json_data
.
push_back
(
item
);
}
std
::
string
body
=
json_data
.
dump
();
Logger
::
smf_n11
().
debug
(
"Send NF Instance Registration to NRF (Msg body %s)"
,
body
.
c_str
());
std
::
string
url
=
std
::
string
(
inet_ntoa
(
*
((
struct
in_addr
*
)
&
smf_cfg
.
nrf_addr
.
ipv4_addr
)))
+
":"
+
std
::
to_string
(
smf_cfg
.
nrf_addr
.
port
)
+
NNRF_NFM_BASE
+
smf_cfg
.
nrf_addr
.
api_version
+
NNRF_NF_REGISTER_URL
+
msg
->
smf_instance_id
;
Logger
::
smf_n11
().
debug
(
"Send NF Update to NRF (NRF URL %s)"
,
url
.
c_str
());
curl_global_init
(
CURL_GLOBAL_ALL
);
CURL
*
curl
=
curl
=
curl_easy_init
();
if
(
curl
)
{
CURLcode
res
=
{};
struct
curl_slist
*
headers
=
nullptr
;
// headers = curl_slist_append(headers, "charsets: utf-8");
headers
=
curl_slist_append
(
headers
,
"content-type: application/json"
);
curl_easy_setopt
(
curl
,
CURLOPT_HTTPHEADER
,
headers
);
curl_easy_setopt
(
curl
,
CURLOPT_URL
,
url
.
c_str
());
curl_easy_setopt
(
curl
,
CURLOPT_HTTPGET
,
1
);
curl_easy_setopt
(
curl
,
CURLOPT_CUSTOMREQUEST
,
"PATCH"
);
curl_easy_setopt
(
curl
,
CURLOPT_TIMEOUT_MS
,
AMF_CURL_TIMEOUT_MS
);
if
(
msg
->
http_version
==
2
)
{
curl_easy_setopt
(
curl
,
CURLOPT_VERBOSE
,
1L
);
// we use a self-signed test server, skip verification during debugging
curl_easy_setopt
(
curl
,
CURLOPT_SSL_VERIFYPEER
,
0L
);
curl_easy_setopt
(
curl
,
CURLOPT_SSL_VERIFYHOST
,
0L
);
curl_easy_setopt
(
curl
,
CURLOPT_HTTP_VERSION
,
CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE
);
}
// Response information.
long
httpCode
=
{
0
};
std
::
unique_ptr
<
std
::
string
>
httpData
(
new
std
::
string
());
curl_easy_setopt
(
curl
,
CURLOPT_WRITEFUNCTION
,
&
callback
);
curl_easy_setopt
(
curl
,
CURLOPT_WRITEDATA
,
httpData
.
get
());
curl_easy_setopt
(
curl
,
CURLOPT_POSTFIELDSIZE
,
body
.
length
());
curl_easy_setopt
(
curl
,
CURLOPT_POSTFIELDS
,
body
.
c_str
());
res
=
curl_easy_perform
(
curl
);
curl_easy_getinfo
(
curl
,
CURLINFO_RESPONSE_CODE
,
&
httpCode
);
Logger
::
smf_n11
().
debug
(
"Response from NRF, Http Code: %d"
,
httpCode
);
curl_slist_free_all
(
headers
);
curl_easy_cleanup
(
curl
);
}
curl_global_cleanup
();
}
src/smf_app/smf_n11.hpp
View file @
30165886
...
@@ -39,6 +39,8 @@
...
@@ -39,6 +39,8 @@
namespace
smf
{
namespace
smf
{
#define TASK_SMF_N11_TIMEOUT_NRF_HEARTBEAT_REQUEST 1
class
smf_n11
{
class
smf_n11
{
private:
private:
std
::
thread
::
id
thread_id
;
std
::
thread
::
id
thread_id
;
...
@@ -95,6 +97,11 @@ class smf_n11 {
...
@@ -95,6 +97,11 @@ class smf_n11 {
void
notify_subscribed_event
(
void
notify_subscribed_event
(
std
::
shared_ptr
<
itti_n11_notify_subscribed_event
>
msg
);
std
::
shared_ptr
<
itti_n11_notify_subscribed_event
>
msg
);
void
register_nf_instance
(
std
::
shared_ptr
<
itti_n11_register_nf_instance_request
>
msg
);
void
update_nf_instance
(
std
::
shared_ptr
<
itti_n11_update_nf_instance_request
>
msg
);
/*
/*
* Create Curl handle for multi curl
* Create Curl handle for multi curl
* @param [event_notification&] ev_notif: content of the event notification
* @param [event_notification&] ev_notif: content of the event notification
...
...
src/smf_app/smf_profile.cpp
View file @
30165886
...
@@ -146,6 +146,21 @@ void smf_profile::set_custom_info(const nlohmann::json &c) { custom_info = c; }
...
@@ -146,6 +146,21 @@ void smf_profile::set_custom_info(const nlohmann::json &c) { custom_info = c; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void
smf_profile
::
get_custom_info
(
nlohmann
::
json
&
c
)
const
{
c
=
custom_info
;
}
void
smf_profile
::
get_custom_info
(
nlohmann
::
json
&
c
)
const
{
c
=
custom_info
;
}
//------------------------------------------------------------------------------
void
smf_profile
::
set_smf_info
(
const
smf_info_t
&
s
)
{
smf_info
=
s
;
}
//------------------------------------------------------------------------------
void
smf_profile
::
add_smf_info_item
(
const
snssai_smf_info_item_t
&
s
)
{
smf_info
.
snssai_smf_info_list
.
push_back
(
s
);
}
//------------------------------------------------------------------------------
void
smf_profile
::
get_smf_info
(
smf_info_t
&
s
)
const
{
s
=
smf_info
;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void
smf_profile
::
display
()
{
void
smf_profile
::
display
()
{
Logger
::
smf_app
().
debug
(
"NF instance info"
);
Logger
::
smf_app
().
debug
(
"NF instance info"
);
...
@@ -201,6 +216,84 @@ void smf_profile::to_json(nlohmann::json &data) const {
...
@@ -201,6 +216,84 @@ void smf_profile::to_json(nlohmann::json &data) const {
data
[
"custom_info"
]
=
custom_info
;
data
[
"custom_info"
]
=
custom_info
;
}
}
//------------------------------------------------------------------------------
void
smf_profile
::
from_json
(
const
nlohmann
::
json
&
data
)
{
if
(
data
.
find
(
"nfInstanceId"
)
!=
data
.
end
())
{
nf_instance_id
=
data
[
"nfInstanceId"
].
get
<
std
::
string
>
();
}
if
(
data
.
find
(
"nfInstanceName"
)
!=
data
.
end
())
{
nf_instance_name
=
data
[
"nfInstanceName"
].
get
<
std
::
string
>
();
}
if
(
data
.
find
(
"nfType"
)
!=
data
.
end
())
{
nf_type
=
data
[
"nfType"
].
get
<
std
::
string
>
();
}
if
(
data
.
find
(
"nfStatus"
)
!=
data
.
end
())
{
nf_status
=
data
[
"nfStatus"
].
get
<
std
::
string
>
();
}
if
(
data
.
find
(
"smfInfo"
)
!=
data
.
end
())
{
nlohmann
::
json
info
=
data
[
"smfInfo"
];
dnn_smf_info_item_t
dnn_item
=
{};
snssai_smf_info_item_t
smf_info_item
=
{};
if
(
info
.
find
(
"sNssaiSmfInfoList"
)
!=
info
.
end
())
{
nlohmann
::
json
snssai_smf_info_list
=
data
[
"smfInfo"
][
"sNssaiSmfInfoList"
];
for
(
auto
it
:
snssai_smf_info_list
)
{
if
(
it
.
find
(
"sNssai"
)
!=
it
.
end
())
{
if
(
it
[
"sNssai"
].
find
(
"sst"
)
!=
it
[
"sNssai"
].
end
())
smf_info_item
.
snssai
.
sST
=
it
[
"sNssai"
][
"sst"
].
get
<
int
>
();
if
(
it
[
"sNssai"
].
find
(
"sd"
)
!=
it
[
"sNssai"
].
end
())
smf_info_item
.
snssai
.
sD
=
it
[
"sNssai"
][
"sd"
].
get
<
std
::
string
>
();
}
if
(
it
.
find
(
"dnnSmfInfoList"
)
!=
it
.
end
())
{
for
(
auto
d
:
it
[
"dnnSmfInfoList"
])
{
if
(
it
.
find
(
"dnn"
)
!=
it
.
end
())
{
dnn_item
.
dnn
=
d
[
"dnn"
].
get
<
std
::
string
>
();
smf_info_item
.
dnn_smf_info_list
.
push_back
(
dnn_item
);
}
}
}
}
}
}
if
(
data
.
find
(
"ipv4Addresses"
)
!=
data
.
end
())
{
nlohmann
::
json
ipv4_addresses
=
data
[
"ipv4Addresses"
];
for
(
auto
it
:
ipv4_addresses
)
{
struct
in_addr
addr4
=
{};
std
::
string
address
=
it
.
get
<
std
::
string
>
();
unsigned
char
buf_in_addr
[
sizeof
(
struct
in_addr
)];
if
(
inet_pton
(
AF_INET
,
util
::
trim
(
address
).
c_str
(),
buf_in_addr
)
==
1
)
{
memcpy
(
&
addr4
,
buf_in_addr
,
sizeof
(
struct
in_addr
));
}
else
{
Logger
::
smf_app
().
warn
(
"Address conversion: Bad value %s"
,
util
::
trim
(
address
).
c_str
());
}
Logger
::
smf_app
().
debug
(
"
\t
IPv4 Addr: %s"
,
address
.
c_str
());
add_nf_ipv4_addresses
(
addr4
);
}
}
if
(
data
.
find
(
"priority"
)
!=
data
.
end
())
{
priority
=
data
[
"priority"
].
get
<
int
>
();
}
if
(
data
.
find
(
"capacity"
)
!=
data
.
end
())
{
capacity
=
data
[
"capacity"
].
get
<
int
>
();
}
//TODO: custom_info;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void
smf_profile
::
handle_heartbeart_timeout
(
uint64_t
ms
)
{
void
smf_profile
::
handle_heartbeart_timeout
(
uint64_t
ms
)
{
Logger
::
smf_app
().
info
(
"Handle heartbeart timeout profile %s, time %d"
,
Logger
::
smf_app
().
info
(
"Handle heartbeart timeout profile %s, time %d"
,
...
...
src/smf_app/smf_profile.hpp
View file @
30165886
...
@@ -55,8 +55,9 @@ class smf_profile : public std::enable_shared_from_this<smf_profile> {
...
@@ -55,8 +55,9 @@ class smf_profile : public std::enable_shared_from_this<smf_profile> {
snssais
(),
snssais
(),
ipv4_addresses
(),
ipv4_addresses
(),
priority
(
0
),
priority
(
0
),
capacity
(
0
),
capacity
(
0
)
event_sub
(
smf_event
::
get_instance
())
{
// event_sub(smf_event::get_instance())
{
nf_instance_name
=
""
;
nf_instance_name
=
""
;
nf_status
=
""
;
nf_status
=
""
;
custom_info
=
{};
custom_info
=
{};
...
@@ -69,14 +70,30 @@ class smf_profile : public std::enable_shared_from_this<smf_profile> {
...
@@ -69,14 +70,30 @@ class smf_profile : public std::enable_shared_from_this<smf_profile> {
ipv4_addresses
(),
ipv4_addresses
(),
priority
(
0
),
priority
(
0
),
capacity
(
0
),
capacity
(
0
),
nf_type
(
"NF_TYPE_UNKNOWN"
),
nf_type
(
"NF_TYPE_UNKNOWN"
)
event_sub
(
smf_event
::
get_instance
())
{
// event_sub(smf_event::get_instance())
{
nf_instance_name
=
""
;
nf_instance_name
=
""
;
nf_status
=
""
;
nf_status
=
""
;
custom_info
=
{};
custom_info
=
{};
}
}
smf_profile
(
smf_profile
&
b
)
=
delete
;
smf_profile
&
operator
=
(
const
smf_profile
&
s
)
{
nf_instance_id
=
s
.
nf_instance_id
;
heartBeat_timer
=
s
.
heartBeat_timer
;
snssais
=
s
.
snssais
;
ipv4_addresses
=
s
.
ipv4_addresses
;
priority
=
s
.
priority
;
capacity
=
s
.
capacity
;
nf_type
=
s
.
nf_type
;
// event_sub = s.event_sub;
nf_instance_name
=
s
.
nf_instance_name
;
nf_status
=
s
.
nf_status
;
custom_info
=
s
.
custom_info
;
}
//smf_profile(smf_profile &b) = delete;
virtual
~
smf_profile
()
{
virtual
~
smf_profile
()
{
Logger
::
smf_app
().
debug
(
"Delete SMF Profile instance..."
);
Logger
::
smf_app
().
debug
(
"Delete SMF Profile instance..."
);
...
@@ -277,19 +294,49 @@ class smf_profile : public std::enable_shared_from_this<smf_profile> {
...
@@ -277,19 +294,49 @@ class smf_profile : public std::enable_shared_from_this<smf_profile> {
*/
*/
void
get_custom_info
(
nlohmann
::
json
&
c
)
const
;
void
get_custom_info
(
nlohmann
::
json
&
c
)
const
;
/*
* Set smf info
* @param [smf_info_t &] s: smf info
* @return void
*/
void
set_smf_info
(
const
smf_info_t
&
s
);
/*
* Add an snssai_smf_info_item to the smf info
* @param [const snssai_smf_info_item_t &] s: snssai_smf_info_item
* @return void
*/
void
add_smf_info_item
(
const
snssai_smf_info_item_t
&
s
);
/*
* Get NF instance smf info
* @param [smf_info_t &] s: store instance's smf info
* @return void:
*/
void
get_smf_info
(
smf_info_t
&
s
)
const
;
/*
/*
* Print related-information for NF profile
* Print related-information for NF profile
* @param void
* @param void
* @return void:
* @return void:
*/
*/
v
irtual
v
oid
display
();
void
display
();
/*
/*
* Represent NF profile as json object
* Represent NF profile as json object
* @param [nlohmann::json &] data: Json data
* @param [nlohmann::json &] data: Json data
* @return void
* @return void
*/
*/
virtual
void
to_json
(
nlohmann
::
json
&
data
)
const
;
void
to_json
(
nlohmann
::
json
&
data
)
const
;
/*
* Covert from a json represetation to SMF profile
* @param [nlohmann::json &] data: Json data
* @return void
*/
void
from_json
(
const
nlohmann
::
json
&
data
);
/*
/*
* Handle heartbeart timeout event
* Handle heartbeart timeout event
...
@@ -300,7 +347,7 @@ class smf_profile : public std::enable_shared_from_this<smf_profile> {
...
@@ -300,7 +347,7 @@ class smf_profile : public std::enable_shared_from_this<smf_profile> {
protected:
protected:
// for Event Handling
// for Event Handling
smf_event
&
event_sub
;
//
smf_event &event_sub;
// From NFProfile (Section 6.1.6.2.2@3GPP TS 29.510 V16.0.0 (2019-06))
// From NFProfile (Section 6.1.6.2.2@3GPP TS 29.510 V16.0.0 (2019-06))
std
::
string
nf_instance_id
;
std
::
string
nf_instance_id
;
std
::
string
nf_instance_name
;
std
::
string
nf_instance_name
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment