Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-NRF
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-NRF
Commits
31b184ee
Commit
31b184ee
authored
Sep 23, 2022
by
Tien Thinh NGUYEN
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validate the Heartbeat message and act accordingly
parent
fec2ddcd
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
67 additions
and
30 deletions
+67
-30
src/common/utils/api_conversions.cpp
src/common/utils/api_conversions.cpp
+1
-1
src/nrf_app/nrf_app.cpp
src/nrf_app/nrf_app.cpp
+20
-12
src/nrf_app/nrf_app.hpp
src/nrf_app/nrf_app.hpp
+1
-1
src/nrf_app/nrf_profile.cpp
src/nrf_app/nrf_profile.cpp
+27
-9
src/nrf_app/nrf_profile.hpp
src/nrf_app/nrf_profile.hpp
+18
-7
No files found.
src/common/utils/api_conversions.cpp
View file @
31b184ee
...
...
@@ -72,7 +72,7 @@ bool api_conv::profile_api_to_nrf_profile(
"
\t
Status: %s"
,
profile
.
get
()
->
get_nf_status
().
c_str
());
profile
.
get
()
->
set_nf_heartBeat_timer
(
api_profile
.
getHeartBeatTimer
());
Logger
::
nrf_app
().
debug
(
"
\t
Heart
Bear
t timer: %d"
,
profile
.
get
()
->
get_nf_heartBeat_timer
());
"
\t
Heart
bea
t timer: %d"
,
profile
.
get
()
->
get_nf_heartBeat_timer
());
profile
.
get
()
->
set_nf_priority
(
api_profile
.
getPriority
());
Logger
::
nrf_app
().
debug
(
"
\t
Priority: %d"
,
profile
.
get
()
->
get_nf_priority
());
profile
.
get
()
->
set_nf_capacity
(
api_profile
.
getCapacity
());
...
...
src/nrf_app/nrf_app.cpp
View file @
31b184ee
...
...
@@ -171,7 +171,7 @@ void nrf_app::handle_register_nf_instance(
Logger
::
nrf_app
().
info
(
"Added/Updated NF Profile (ID %s) to the DB"
,
nf_instance_id
.
c_str
());
// Heartbea
r
t management for this NF profile
// Heartbeat management for this NF profile
// get current time
uint64_t
ms
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
std
::
chrono
::
system_clock
::
now
().
time_since_epoch
())
...
...
@@ -216,7 +216,8 @@ void nrf_app::handle_update_nf_instance(
std
::
shared_ptr
<
nrf_profile
>
sn
=
{};
sn
=
find_nf_profile
(
nf_instance_id
);
bool
op_success
=
true
;
bool
is_heartbeart_procedure
=
false
;
bool
is_heartbeat_procedure
=
false
;
std
::
string
heartbeat_value
=
{};
if
(
sn
.
get
()
!=
nullptr
)
{
for
(
auto
p
:
patchItem
)
{
...
...
@@ -237,7 +238,8 @@ void nrf_app::handle_update_nf_instance(
switch
(
op
)
{
case
PATCH_OP_REPLACE
:
{
if
(
path
.
compare
(
"nfStatus"
)
==
0
)
{
is_heartbeart_procedure
=
true
;
is_heartbeat_procedure
=
true
;
heartbeat_value
=
p
.
getValue
();
Logger
::
nrf_app
().
info
(
"NF Heart-Beat procedure!"
);
}
if
(
sn
.
get
()
->
replace_profile_info
(
path
,
p
.
getValue
()))
{
...
...
@@ -277,7 +279,7 @@ void nrf_app::handle_update_nf_instance(
problem_details
.
setCause
(
protocol_application_error_e2str
[
MANDATORY_IE_INCORRECT
]);
}
else
{
if
(
!
is_heartbea
r
t_procedure
)
if
(
!
is_heartbeat_procedure
)
// update successful,
// Notify NF status change event
m_event_sub
.
nf_status_profile_changed
(
...
...
@@ -286,7 +288,7 @@ void nrf_app::handle_update_nf_instance(
}
// for NF Heartbeat procedure
if
(
is_heartbea
r
t_procedure
and
(
http_code
==
HTTP_STATUS_CODE_200_OK
))
{
if
(
is_heartbeat_procedure
and
(
http_code
==
HTTP_STATUS_CODE_200_OK
))
{
http_code
=
HTTP_STATUS_CODE_204_NO_CONTENT
;
uint64_t
ms
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
std
::
chrono
::
system_clock
::
now
().
time_since_epoch
())
...
...
@@ -307,11 +309,17 @@ void nrf_app::handle_update_nf_instance(
sn
.
get
()
->
subscribe_heartbeat_timeout_nfupdate
(
ms
);
}
// sn.get()->subscribe_heartbeat_timeout_nfupdate(ms);
// Subscribe again to heartbeat timeout if not done (e.g., change status
// from SUSPENDED to REGISTERED)
if
(
!
sn
.
get
()
->
is_heartbeat_timeout_nfupdate_active
())
{
sn
.
get
()
->
subscribe_heartbeat_timeout_nfupdate
(
ms
);
}
// update NF status
if
(
sn
.
get
()
->
set_nf_status
(
heartbeat_value
))
{
// update NF updated flag
sn
.
get
()
->
set_status_updated
(
true
);
// update NF status
sn
.
get
()
->
set_nf_status
(
"REGISTERED"
);
}
return
;
}
...
...
@@ -991,13 +999,13 @@ void nrf_app::subscribe_task_tick(uint64_t ms) {
Logger
::
nrf_app
().
debug
(
"subscribe task_tick: %d"
,
ms
);
m_event_sub
.
subscribe_task_tick
(
boost
::
bind
(
&
nrf_app
::
handle_heartbea
r
t_timeout
,
this
,
_1
),
interval
,
boost
::
bind
(
&
nrf_app
::
handle_heartbeat_timeout
,
this
,
_1
),
interval
,
ms
%
20000
);
}
//------------------------------------------------------------------------------
void
nrf_app
::
handle_heartbea
r
t_timeout
(
uint64_t
ms
)
{
Logger
::
nrf_app
().
info
(
"handle_heartbea
r
t_timeout %d"
,
ms
);
void
nrf_app
::
handle_heartbeat_timeout
(
uint64_t
ms
)
{
Logger
::
nrf_app
().
info
(
"handle_heartbeat_timeout %d"
,
ms
);
}
//------------------------------------------------------------------------------
...
...
src/nrf_app/nrf_app.hpp
View file @
31b184ee
...
...
@@ -325,7 +325,7 @@ class nrf_app {
* @param [uint64_t] ms: current time in milliseconds
* @return void
*/
void
handle_heartbea
r
t_timeout
(
uint64_t
ms
);
void
handle_heartbeat_timeout
(
uint64_t
ms
);
/*
* Verify whether a subscription is authorized
...
...
src/nrf_app/nrf_profile.cpp
View file @
31b184ee
...
...
@@ -83,10 +83,16 @@ nf_type_t nrf_profile::get_nf_type() const {
}
//------------------------------------------------------------------------------
void
nrf_profile
::
set_nf_status
(
const
std
::
string
&
status
)
{
bool
nrf_profile
::
set_nf_status
(
const
std
::
string
&
status
)
{
Logger
::
nrf_app
().
debug
(
"Set NF status to %s"
,
status
.
c_str
());
if
(
!
(
boost
::
iequals
(
nf_status
,
"REGISTERED"
)
or
boost
::
iequals
(
nf_status
,
"UNDISCOVERABLE"
)
or
boost
::
iequals
(
nf_status
,
"DEREGISTERED"
)))
{
return
false
;
}
std
::
unique_lock
lock
(
nf_profile_mutex
);
nf_status
=
status
;
return
true
;
}
//------------------------------------------------------------------------------
...
...
@@ -662,12 +668,12 @@ void nrf_profile::subscribe_heartbeat_timeout_nfregistration(uint64_t ms) {
its
.
it_value
.
tv_nsec
/
1000000
;
// convert sec, nsec to msec
Logger
::
nrf_app
().
debug
(
"Subscribe to the Heart
Bear
tTimer expire event (after NF "
"Subscribe to the Heart
bea
tTimer expire event (after NF "
"registration): interval %d, current time %ld"
,
2
*
HEART_BEAT_TIMER
,
ms
);
first_hb_connection
=
m_event_sub
.
subscribe_task_tick
(
boost
::
bind
(
&
nrf_profile
::
handle_heartbea
r
t_timeout_nfregistration
,
this
,
_1
),
&
nrf_profile
::
handle_heartbeat_timeout_nfregistration
,
this
,
_1
),
interval
,
ms
+
interval
);
}
...
...
@@ -689,7 +695,7 @@ void nrf_profile::subscribe_heartbeat_timeout_nfupdate(uint64_t ms) {
ms
=
ms
+
2000
;
// Not a realtime NF: adding 2000ms interval between the
// expected NF update message and HBT
hb_update_connection
=
m_event_sub
.
subscribe_task_tick
(
boost
::
bind
(
&
nrf_profile
::
handle_heartbea
r
t_timeout_nfupdate
,
this
,
_1
),
boost
::
bind
(
&
nrf_profile
::
handle_heartbeat_timeout_nfupdate
,
this
,
_1
),
interval
,
ms
+
interval
);
first_update
=
false
;
}
...
...
@@ -697,6 +703,7 @@ void nrf_profile::subscribe_heartbeat_timeout_nfupdate(uint64_t ms) {
//------------------------------------------------------------------------------
bool
nrf_profile
::
unsubscribe_heartbeat_timeout_nfupdate
()
{
std
::
unique_lock
lock
(
hb_mutex
);
if
(
hb_update_connection
.
connected
())
{
hb_update_connection
.
disconnect
();
Logger
::
nrf_app
().
debug
(
...
...
@@ -707,8 +714,19 @@ bool nrf_profile::unsubscribe_heartbeat_timeout_nfupdate() {
}
}
//------------------------------------------------------------------------------
bool
nrf_profile
::
is_heartbeat_timeout_nfupdate_active
()
{
std
::
shared_lock
lock
(
hb_mutex
);
if
(
hb_update_connection
.
connected
())
{
return
true
;
}
else
{
return
false
;
}
}
//------------------------------------------------------------------------------
bool
nrf_profile
::
unsubscribe_heartbeat_timeout_nfregistration
()
{
std
::
unique_lock
lock
(
hb_mutex
);
if
(
first_hb_connection
.
connected
())
{
first_hb_connection
.
disconnect
();
Logger
::
nrf_app
().
debug
(
...
...
@@ -721,15 +739,15 @@ bool nrf_profile::unsubscribe_heartbeat_timeout_nfregistration() {
}
//------------------------------------------------------------------------------
void
nrf_profile
::
handle_heartbea
r
t_timeout
(
uint64_t
ms
)
{
void
nrf_profile
::
handle_heartbeat_timeout
(
uint64_t
ms
)
{
Logger
::
nrf_app
().
info
(
"
\n
Handle heartbea
r
t timeout, NF instance ID %s, time %d"
,
"
\n
Handle heartbeat timeout, NF instance ID %s, time %d"
,
nf_instance_id
.
c_str
(),
ms
);
set_nf_status
(
"SUSPENDED"
);
}
//------------------------------------------------------------------------------
void
nrf_profile
::
handle_heartbea
r
t_timeout_nfregistration
(
uint64_t
ms
)
{
void
nrf_profile
::
handle_heartbeat_timeout_nfregistration
(
uint64_t
ms
)
{
Logger
::
nrf_app
().
info
(
"
\n
Handle the first Heartbeat timeout, NF instance ID %s, current time "
"%d"
,
...
...
@@ -744,12 +762,12 @@ void nrf_profile::handle_heartbeart_timeout_nfregistration(uint64_t ms) {
}
//------------------------------------------------------------------------------
void
nrf_profile
::
handle_heartbea
r
t_timeout_nfupdate
(
uint64_t
ms
)
{
void
nrf_profile
::
handle_heartbeat_timeout_nfupdate
(
uint64_t
ms
)
{
uint64_t
current_ms
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
std
::
chrono
::
system_clock
::
now
().
time_since_epoch
())
.
count
();
Logger
::
nrf_app
().
info
(
"
\n
Handle heartbea
r
t timeout (NF update), NF instance ID %s, time %ld, "
"
\n
Handle heartbeat timeout (NF update), NF instance ID %s, time %ld, "
"current "
"ms %ld"
,
nf_instance_id
.
c_str
(),
ms
,
current_ms
);
...
...
src/nrf_app/nrf_profile.hpp
View file @
31b184ee
...
...
@@ -64,6 +64,7 @@ class nrf_profile : public std::enable_shared_from_this<nrf_profile> {
priority
(
0
),
capacity
(
0
),
nf_services
(),
hb_mutex
(),
nf_profile_mutex
()
{
nf_instance_name
=
""
;
nf_status
=
""
;
...
...
@@ -84,6 +85,7 @@ class nrf_profile : public std::enable_shared_from_this<nrf_profile> {
priority
(
0
),
capacity
(
0
),
nf_services
(),
hb_mutex
(),
nf_profile_mutex
()
{
nf_instance_name
=
""
;
nf_status
=
""
;
...
...
@@ -105,6 +107,7 @@ class nrf_profile : public std::enable_shared_from_this<nrf_profile> {
capacity
(
0
),
nf_services
(),
nf_type
(
NF_TYPE_UNKNOWN
),
hb_mutex
(),
nf_profile_mutex
()
{
nf_instance_name
=
""
;
nf_status
=
""
;
...
...
@@ -168,7 +171,7 @@ class nrf_profile : public std::enable_shared_from_this<nrf_profile> {
* @param [const std::string &] status: instance status
* @return void
*/
void
set_nf_status
(
const
std
::
string
&
status
);
bool
set_nf_status
(
const
std
::
string
&
status
);
/*
* Get NF instance status
...
...
@@ -463,25 +466,25 @@ class nrf_profile : public std::enable_shared_from_this<nrf_profile> {
void
subscribe_heartbeat_timeout_nfregistration
(
uint64_t
ms
);
/*
* Handle heartbea
r
t timeout event
* Handle heartbeat timeout event
* @param [uint64_t] ms: current time
* @return void
*/
void
handle_heartbea
r
t_timeout
(
uint64_t
ms
);
void
handle_heartbeat_timeout
(
uint64_t
ms
);
/*
* Handle heartbea
r
t timeout event after NF Registration
* Handle heartbeat timeout event after NF Registration
* @param [uint64_t] ms: current time
* @return void
*/
void
handle_heartbea
r
t_timeout_nfregistration
(
uint64_t
ms
);
void
handle_heartbeat_timeout_nfregistration
(
uint64_t
ms
);
/*
* Handle heartbea
r
t timeout event after NF Update
* Handle heartbeat timeout event after NF Update
* @param [uint64_t] ms: current time
* @return void
*/
void
handle_heartbea
r
t_timeout_nfupdate
(
uint64_t
ms
);
void
handle_heartbeat_timeout_nfupdate
(
uint64_t
ms
);
/*
* Unubscribe to HBT event (after NF Registration)
...
...
@@ -497,6 +500,13 @@ class nrf_profile : public std::enable_shared_from_this<nrf_profile> {
*/
bool
unsubscribe_heartbeat_timeout_nfupdate
();
/*
* Verify whether HBT is currently active
* @param void
* @return true if active, otherwise return false
*/
bool
is_heartbeat_timeout_nfupdate_active
();
/*
* Set status updated to true
* @param void
...
...
@@ -524,6 +534,7 @@ class nrf_profile : public std::enable_shared_from_this<nrf_profile> {
hb_update_connection
;
// connection for the HBT timeout (after NF Update)
bs2
::
connection
first_hb_connection
;
// connection for first HBT timeout
// (after NF Registration)
mutable
std
::
shared_mutex
hb_mutex
;
bool
first_update
;
bool
is_updated
;
mutable
std
::
shared_mutex
nf_profile_mutex
;
...
...
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