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
5507552f
Commit
5507552f
authored
Dec 14, 2020
by
Tien-Thinh Nguyen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add NFDeregister operation
parent
117d3988
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
154 additions
and
6 deletions
+154
-6
src/api-server/impl/NFInstanceIDDocumentApiImpl.cpp
src/api-server/impl/NFInstanceIDDocumentApiImpl.cpp
+59
-2
src/nrf_app/nrf_app.cpp
src/nrf_app/nrf_app.cpp
+60
-2
src/nrf_app/nrf_app.hpp
src/nrf_app/nrf_app.hpp
+32
-2
src/nrf_app/nrf_profile.hpp
src/nrf_app/nrf_profile.hpp
+3
-0
No files found.
src/api-server/impl/NFInstanceIDDocumentApiImpl.cpp
View file @
5507552f
...
...
@@ -14,6 +14,7 @@
#include "logger.hpp"
#include "nrf_app.hpp"
#include "nrf_config.hpp"
#include "nrf_profile.hpp"
#include "ProblemDetails.h"
#include "3gpp_29.500.h"
...
...
@@ -36,14 +37,68 @@ NFInstanceIDDocumentApiImpl::NFInstanceIDDocumentApiImpl(
m_address
(
address
)
{
}
//------------------------------------------------------------------------------
void
NFInstanceIDDocumentApiImpl
::
deregister_nf_instance
(
const
std
::
string
&
nfInstanceID
,
Pistache
::
Http
::
ResponseWriter
&
response
)
{
response
.
send
(
Pistache
::
Http
::
Code
::
Ok
,
"Do some magic
\n
"
);
Logger
::
nrf_sbi
().
info
(
"Got a request to de-register a given NF Instance, Instance ID: %s"
,
nfInstanceID
.
c_str
());
int
http_code
=
0
;
ProblemDetails
problem_details
=
{
};
m_nrf_app
->
handle_deregister_nf_instance
(
nfInstanceID
,
http_code
,
1
,
problem_details
);
nlohmann
::
json
json_data
=
{
};
std
::
string
content_type
=
"application/json"
;
if
(
http_code
!=
HTTP_STATUS_CODE_204_NO_CONTENT
)
{
to_json
(
json_data
,
problem_details
);
content_type
=
"application/problem+json"
;
//content type
response
.
headers
().
add
<
Pistache
::
Http
::
Header
::
ContentType
>
(
Pistache
::
Http
::
Mime
::
MediaType
(
content_type
));
response
.
send
(
Pistache
::
Http
::
Code
(
http_code
),
json_data
.
dump
().
c_str
());
return
;
}
else
{
response
.
headers
().
add
<
Pistache
::
Http
::
Header
::
ContentType
>
(
Pistache
::
Http
::
Mime
::
MediaType
(
content_type
));
response
.
send
(
Pistache
::
Http
::
Code
(
http_code
));
}
}
//------------------------------------------------------------------------------
void
NFInstanceIDDocumentApiImpl
::
get_nf_instance
(
const
std
::
string
&
nfInstanceID
,
Pistache
::
Http
::
ResponseWriter
&
response
)
{
response
.
send
(
Pistache
::
Http
::
Code
::
Ok
,
"Do some magic
\n
"
);
Logger
::
nrf_sbi
().
info
(
"Got a request to retrieve the profile of a given NF Instance, Instance ID: %s"
,
nfInstanceID
.
c_str
());
int
http_code
=
0
;
std
::
shared_ptr
<
nrf_profile
>
profile
=
{
};
ProblemDetails
problem_details
=
{
};
m_nrf_app
->
handle_get_nf_instance
(
nfInstanceID
,
profile
,
http_code
,
1
,
problem_details
);
nlohmann
::
json
json_data
=
{
};
std
::
string
content_type
=
"application/json"
;
if
(
http_code
!=
HTTP_STATUS_CODE_200_OK
)
{
to_json
(
json_data
,
problem_details
);
content_type
=
"application/problem+json"
;
}
else
{
profile
.
get
()
->
to_json
(
json_data
);
}
//content type
response
.
headers
().
add
<
Pistache
::
Http
::
Header
::
ContentType
>
(
Pistache
::
Http
::
Mime
::
MediaType
(
content_type
));
response
.
send
(
Pistache
::
Http
::
Code
(
http_code
),
json_data
.
dump
().
c_str
());
}
//------------------------------------------------------------------------------
void
NFInstanceIDDocumentApiImpl
::
register_nf_instance
(
const
std
::
string
&
nfInstanceID
,
const
NFProfile
&
nFProfile
,
const
Pistache
::
Optional
<
Pistache
::
Http
::
Header
::
Raw
>
&
contentEncoding
,
...
...
@@ -79,6 +134,8 @@ void NFInstanceIDDocumentApiImpl::register_nf_instance(
+
nfInstanceID
);
response
.
send
(
Pistache
::
Http
::
Code
(
http_code
),
json_data
.
dump
().
c_str
());
}
//------------------------------------------------------------------------------
void
NFInstanceIDDocumentApiImpl
::
update_nf_instance
(
const
std
::
string
&
nfInstanceID
,
const
std
::
vector
<
PatchItem
>
&
patchItem
,
Pistache
::
Http
::
ResponseWriter
&
response
)
{
...
...
src/nrf_app/nrf_app.cpp
View file @
5507552f
...
...
@@ -230,6 +230,64 @@ void nrf_app::handle_get_nf_instances(const std::string &nf_type,
}
}
void
nrf_app
::
handle_get_nf_instance
(
const
std
::
string
&
nf_instance_id
,
std
::
shared_ptr
<
nrf_profile
>
&
profile
,
int
&
http_code
,
const
uint8_t
http_version
,
ProblemDetails
&
problem_details
)
{
Logger
::
nrf_app
().
info
(
"Handle Retrieve an NF Instance (HTTP version %d)"
,
http_version
);
//TODO: If the NF Service Consumer is not allowed to retrieve the NF profile of this specific registered NF instance, the
//NRF shall return "403 Forbidden" status code.
profile
=
find_nf_profile
(
nf_instance_id
);
if
(
profile
.
get
()
==
nullptr
)
{
Logger
::
nrf_app
().
debug
(
"Profile with profile ID %s not found"
,
nf_instance_id
.
c_str
());
http_code
=
HTTP_STATUS_CODE_404_NOT_FOUND
;
problem_details
.
setCause
(
protocol_application_error_e2str
[
RESOURCE_URI_STRUCTURE_NOT_FOUND
]);
return
;
}
else
{
Logger
::
nrf_app
().
debug
(
"Profile with profile ID %s"
,
nf_instance_id
.
c_str
());
profile
.
get
()
->
display
();
http_code
=
HTTP_STATUS_CODE_200_OK
;
return
;
}
}
//------------------------------------------------------------------------------
void
nrf_app
::
handle_deregister_nf_instance
(
const
std
::
string
&
nf_instance_id
,
int
&
http_code
,
const
uint8_t
http_version
,
ProblemDetails
&
problem_details
)
{
Logger
::
nrf_app
().
info
(
"Handle Deregister an NF Instance (HTTP version %d)"
,
http_version
);
if
(
is_profile_exist
(
nf_instance_id
))
{
if
(
remove_nf_profile
(
nf_instance_id
))
{
Logger
::
nrf_app
().
debug
(
"Removed NF profile with profile ID %s"
,
nf_instance_id
.
c_str
());
http_code
=
HTTP_STATUS_CODE_204_NO_CONTENT
;
return
;
}
else
{
http_code
=
HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR
;
problem_details
.
setCause
(
protocol_application_error_e2str
[
SYSTEM_FAILURE
]);
return
;
}
}
else
{
Logger
::
nrf_app
().
debug
(
"Profile with profile ID %s not found"
,
nf_instance_id
.
c_str
());
http_code
=
HTTP_STATUS_CODE_404_NOT_FOUND
;
problem_details
.
setCause
(
protocol_application_error_e2str
[
RESOURCE_URI_STRUCTURE_NOT_FOUND
]);
return
;
}
}
//------------------------------------------------------------------------------
bool
nrf_app
::
add_nf_profile
(
const
std
::
string
&
profile_id
,
const
std
::
shared_ptr
<
nrf_profile
>
&
p
)
{
...
...
@@ -335,7 +393,7 @@ bool nrf_app::is_profile_exist(const std::string &profile_id) const {
}
//------------------------------------------------------------------------------
bool
nrf_app
::
remove_nf_profile
(
std
::
shared_ptr
<
nrf_profile
>
&
snp
)
{
bool
nrf_app
::
remove_nf_profile
(
const
std
::
shared_ptr
<
nrf_profile
>
&
snp
)
{
std
::
string
key
;
snp
.
get
()
->
get_nf_instance_id
(
key
);
std
::
unique_lock
lock
(
m_instance_id2nrf_profile
);
...
...
@@ -351,7 +409,7 @@ bool nrf_app::remove_nf_profile(std::shared_ptr<nrf_profile> &snp) {
}
//------------------------------------------------------------------------------
bool
nrf_app
::
remove_nf_profile
(
std
::
string
&
profile_id
)
{
bool
nrf_app
::
remove_nf_profile
(
const
std
::
string
&
profile_id
)
{
std
::
unique_lock
lock
(
m_instance_id2nrf_profile
);
if
(
instance_id2nrf_profile
.
erase
(
profile_id
))
{
Logger
::
nrf_app
().
info
(
"Removed NF profile (ID %d) from the list"
,
...
...
src/nrf_app/nrf_app.hpp
View file @
5507552f
...
...
@@ -92,6 +92,36 @@ class nrf_app {
const
std
::
vector
<
PatchItem
>
&
patchItem
,
int
&
http_code
,
const
uint8_t
http_version
,
ProblemDetails
&
problem_details
);
/*
* Handle a Get NF Instance request
* @param [const std::string &] nf_instance_id: Instance ID
* @param [nrf_profile &] profile: NF profile
* @param [int &] http_code: HTTP code used to return to the consumer
* @param [const uint8_t] http_version: HTTP version
* @param [ProblemDetails &] problem_details: Store details of the error
* @return void
*/
void
handle_get_nf_instance
(
const
std
::
string
&
nf_instance_id
,
std
::
shared_ptr
<
nrf_profile
>
&
profile
,
int
&
http_code
,
const
uint8_t
http_version
,
ProblemDetails
&
problem_details
);
/*
* Handle De-register a given NF Instance
* @param [const std::string &] nf_instance_id: Instance ID
* @param [int &] http_code: HTTP code used to return to the consumer
* @param [const uint8_t] http_version: HTTP version
* @param [ProblemDetails &] problem_details: Store details of the error
* @return void
*/
void
handle_deregister_nf_instance
(
const
std
::
string
&
nf_instance_id
,
int
&
http_code
,
const
uint8_t
http_version
,
ProblemDetails
&
problem_details
);
/*
* Insert a nrf profile
* @param [const std::string &] profile_id: Profile ID
...
...
@@ -148,14 +178,14 @@ class nrf_app {
* @param [std::shared_ptr<nrf_profile> &] snp: profile to be removed
* @return true if successful, otherwise, return false
*/
bool
remove_nf_profile
(
std
::
shared_ptr
<
nrf_profile
>
&
snp
);
bool
remove_nf_profile
(
const
std
::
shared_ptr
<
nrf_profile
>
&
snp
);
/*
* Remove a nf profile from the list
* @param [std::string &] profile_id: ID of the profile to be removed
* @return true if successful, otherwise, return false
*/
bool
remove_nf_profile
(
std
::
string
&
profile_id
);
bool
remove_nf_profile
(
const
std
::
string
&
profile_id
);
void
subscribe_task_tick
(
uint64_t
ms
);
void
handle_heartbeart_timeout
(
uint64_t
ms
);
...
...
src/nrf_app/nrf_profile.hpp
View file @
5507552f
...
...
@@ -41,6 +41,7 @@
#include "nrf.h"
#include "nrf_event.hpp"
#include "logger.hpp"
namespace
oai
{
namespace
nrf
{
...
...
@@ -94,7 +95,9 @@ class nrf_profile : public std::enable_shared_from_this<nrf_profile> {
}
nrf_profile
(
nrf_profile
&
b
)
=
delete
;
virtual
~
nrf_profile
()
{
Logger
::
nrf_app
().
debug
(
"Delete instance..."
);
task_connection
.
disconnect
();
}
...
...
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