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
f9c48674
Unverified
Commit
f9c48674
authored
Sep 29, 2021
by
kharade
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
NF instances (store) validated
parent
cdab6bea
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
31 deletions
+62
-31
src/api-server/nrf-http2-server.cpp
src/api-server/nrf-http2-server.cpp
+60
-29
src/api-server/nrf-http2-server.h
src/api-server/nrf-http2-server.h
+1
-1
src/common/nrf.h
src/common/nrf.h
+1
-1
No files found.
src/api-server/nrf-http2-server.cpp
View file @
f9c48674
...
@@ -56,46 +56,64 @@ void nrf_http2_server::start() {
...
@@ -56,46 +56,64 @@ void nrf_http2_server::start() {
std
::
string
subscriptionID
=
{};
std
::
string
subscriptionID
=
{};
SubscriptionData
subscriptionData
=
{};
SubscriptionData
subscriptionData
=
{};
// NF Instances
// NF Instances
(Store)
server
.
handle
(
server
.
handle
(
NNRF_NFM_BASE
+
nrf_cfg
.
sbi_api_version
+
NNRF_NFM_NF_INSTANCE
,
NNRF_NFM_BASE
+
nrf_cfg
.
sbi_api_version
+
"/nf-instances"
,
[
&
](
const
request
&
request
,
const
response
&
response
)
{
request
.
on_data
([
&
](
const
uint8_t
*
data
,
std
::
size_t
len
)
{
std
::
string
msg
((
char
*
)
data
,
len
);
try
{
// Retrieves a collection of NF Instances
if
(
request
.
method
().
compare
(
"GET"
)
==
0
)
{
std
::
string
split_query
=
request
.
uri
().
raw_query
;
// Parse query paramaters
std
::
string
nfType
=
util
::
get_query_param
(
split_query
,
"nf-type"
);
std
::
string
limit_nfs
=
util
::
get_query_param
(
split_query
.
c_str
(),
"limit"
);
Logger
::
nrf_sbi
().
debug
(
"/nnrf-nfm/ query params - nfType: %s, limit_nfs: %s, "
,
nfType
.
c_str
(),
limit_nfs
.
c_str
());
this
->
get_nf_instances_handler
(
nfType
,
limit_nfs
,
response
);
}
}
catch
(
nlohmann
::
detail
::
exception
&
e
)
{
Logger
::
nrf_sbi
().
warn
(
"Can not parse the json data (error: %s)!"
,
e
.
what
());
response
.
write_head
(
http_status_code_e
::
HTTP_STATUS_CODE_400_BAD_REQUEST
);
response
.
end
();
return
;
}
});
});
// NF Instances ID (Document)
server
.
handle
(
NNRF_NFM_BASE
+
nrf_cfg
.
sbi_api_version
+
NNRF_NFM_NF_INSTANCES
,
[
&
](
const
request
&
request
,
const
response
&
response
)
{
[
&
](
const
request
&
request
,
const
response
&
response
)
{
request
.
on_data
([
&
](
const
uint8_t
*
data
,
std
::
size_t
len
)
{
request
.
on_data
([
&
](
const
uint8_t
*
data
,
std
::
size_t
len
)
{
std
::
string
msg
((
char
*
)
data
,
len
);
std
::
string
msg
((
char
*
)
data
,
len
);
NFProfile
nFProfile
;
NFProfile
nFProfile
;
try
{
try
{
// Register a new NF Instance
if
(
request
.
method
().
compare
(
"PUT"
)
==
0
&&
len
>
0
)
{
if
(
request
.
method
().
compare
(
"PUT"
)
==
0
&&
len
>
0
)
{
nlohmann
::
json
::
parse
(
msg
.
c_str
()).
get_to
(
nFProfile
);
nlohmann
::
json
::
parse
(
msg
.
c_str
()).
get_to
(
nFProfile
);
this
->
register_nf_instance_handler
(
nFProfile
,
response
);
this
->
register_nf_instance_handler
(
nFProfile
,
response
);
}
}
// Read the profile of a given NF Instance
if
(
request
.
method
().
compare
(
"GET"
)
==
0
)
{
if
(
request
.
method
().
compare
(
"GET"
)
==
0
)
{
nlohmann
::
json
::
parse
(
msg
.
c_str
()).
get_to
(
nFProfile
);
std
::
vector
<
std
::
string
>
split_result
;
std
::
vector
<
std
::
string
>
split_result
;
std
::
vector
<
std
::
string
>
split_query
;
boost
::
split
(
boost
::
split
(
split_result
,
request
.
uri
().
path
,
boost
::
is_any_of
(
"/"
));
split_result
,
request
.
uri
().
path
,
boost
::
is_any_of
(
"/"
));
boost
::
split
(
split_query
,
request
.
uri
().
path
,
boost
::
is_any_of
(
"?"
));
if
(
split_result
.
size
()
==
5
)
{
if
(
split_result
.
size
()
==
5
)
{
// Read the profile of given NF Instance
nfInstanceID
=
split_result
[
split_result
.
size
()
-
1
].
c_str
();
nfInstanceID
=
split_result
[
split_result
.
size
()
-
1
].
c_str
();
this
->
get_nf_instance_handler
(
nfInstanceID
,
response
);
this
->
get_nf_instance_handler
(
nfInstanceID
,
response
);
}
}
if
(
split_result
.
size
()
==
4
)
{
// Retrieves a collection of NF Instances
std
::
string
querystring
=
split_query
[
split_query
.
size
()
-
1
].
c_str
();
std
::
string
nfType
=
util
::
get_query_param
(
querystring
,
"nf-type"
);
uint32_t
limit
=
stoi
(
util
::
get_query_param
(
querystring
,
"limit"
).
c_str
());
this
->
get_nf_instances_handler
(
nfType
,
limit
,
response
);
}
}
}
// Update NF Instance profile
if
(
request
.
method
().
compare
(
"PATCH"
)
==
0
&&
len
>
0
)
{
if
(
request
.
method
().
compare
(
"PATCH"
)
==
0
&&
len
>
0
)
{
std
::
vector
<
PatchItem
>
patchItem
;
std
::
vector
<
PatchItem
>
patchItem
;
nlohmann
::
json
::
parse
(
msg
.
c_str
()).
get_to
(
patchItem
);
nlohmann
::
json
::
parse
(
msg
.
c_str
()).
get_to
(
patchItem
);
...
@@ -105,7 +123,7 @@ void nrf_http2_server::start() {
...
@@ -105,7 +123,7 @@ void nrf_http2_server::start() {
nfInstanceID
=
split_result
[
split_result
.
size
()
-
1
].
c_str
();
nfInstanceID
=
split_result
[
split_result
.
size
()
-
1
].
c_str
();
this
->
update_instance_handler
(
nfInstanceID
,
patchItem
,
response
);
this
->
update_instance_handler
(
nfInstanceID
,
patchItem
,
response
);
}
}
// Deregisters a given NF Instance
if
(
request
.
method
().
compare
(
"DELETE"
)
==
0
)
{
if
(
request
.
method
().
compare
(
"DELETE"
)
==
0
)
{
std
::
vector
<
std
::
string
>
split_result
;
std
::
vector
<
std
::
string
>
split_result
;
boost
::
split
(
boost
::
split
(
...
@@ -124,17 +142,19 @@ void nrf_http2_server::start() {
...
@@ -124,17 +142,19 @@ void nrf_http2_server::start() {
});
});
});
});
// Subscriptions
// Subscriptions
(Collection & ID Document)
server
.
handle
(
server
.
handle
(
NNRF_NFM_BASE
+
nrf_cfg
.
sbi_api_version
+
NNRF_NFM_STATUS_SUBSCRIBE_URL
,
NNRF_NFM_BASE
+
nrf_cfg
.
sbi_api_version
+
NNRF_NFM_STATUS_SUBSCRIBE_URL
,
[
&
](
const
request
&
request
,
const
response
&
response
)
{
[
&
](
const
request
&
request
,
const
response
&
response
)
{
request
.
on_data
([
&
](
const
uint8_t
*
data
,
std
::
size_t
len
)
{
request
.
on_data
([
&
](
const
uint8_t
*
data
,
std
::
size_t
len
)
{
std
::
string
msg
((
char
*
)
data
,
len
);
std
::
string
msg
((
char
*
)
data
,
len
);
try
{
try
{
// Create a new subscription
if
(
request
.
method
().
compare
(
"POST"
)
==
0
&&
len
>
0
)
{
if
(
request
.
method
().
compare
(
"POST"
)
==
0
&&
len
>
0
)
{
nlohmann
::
json
::
parse
(
msg
.
c_str
()).
get_to
(
subscriptionData
);
nlohmann
::
json
::
parse
(
msg
.
c_str
()).
get_to
(
subscriptionData
);
this
->
create_subscription_handler
(
subscriptionData
,
response
);
this
->
create_subscription_handler
(
subscriptionData
,
response
);
}
}
// Updates a subscription
if
(
request
.
method
().
compare
(
"PATCH"
)
==
0
&&
len
>
0
)
{
if
(
request
.
method
().
compare
(
"PATCH"
)
==
0
&&
len
>
0
)
{
std
::
vector
<
PatchItem
>
patchItem
;
std
::
vector
<
PatchItem
>
patchItem
;
nlohmann
::
json
::
parse
(
msg
.
c_str
()).
get_to
(
patchItem
);
nlohmann
::
json
::
parse
(
msg
.
c_str
()).
get_to
(
patchItem
);
...
@@ -145,6 +165,7 @@ void nrf_http2_server::start() {
...
@@ -145,6 +165,7 @@ void nrf_http2_server::start() {
this
->
update_subscription_handler
(
this
->
update_subscription_handler
(
subscriptionID
,
patchItem
,
response
);
subscriptionID
,
patchItem
,
response
);
}
}
// Delete a subscription
if
(
request
.
method
().
compare
(
"DELETE"
)
==
0
)
{
if
(
request
.
method
().
compare
(
"DELETE"
)
==
0
)
{
std
::
vector
<
std
::
string
>
split_result
;
std
::
vector
<
std
::
string
>
split_result
;
boost
::
split
(
boost
::
split
(
...
@@ -163,13 +184,14 @@ void nrf_http2_server::start() {
...
@@ -163,13 +184,14 @@ void nrf_http2_server::start() {
});
});
});
});
// NF Discovery
// NF Discovery
(Store)
server
.
handle
(
server
.
handle
(
NNRF_DISC_BASE
+
nrf_cfg
.
sbi_api_version
+
"/nf-instances"
,
NNRF_DISC_BASE
+
nrf_cfg
.
sbi_api_version
+
"/nf-instances"
,
[
&
](
const
request
&
request
,
const
response
&
response
)
{
[
&
](
const
request
&
request
,
const
response
&
response
)
{
request
.
on_data
([
&
](
const
uint8_t
*
data
,
std
::
size_t
len
)
{
request
.
on_data
([
&
](
const
uint8_t
*
data
,
std
::
size_t
len
)
{
std
::
string
msg
((
char
*
)
data
,
len
);
std
::
string
msg
((
char
*
)
data
,
len
);
try
{
try
{
// Search a collection of NF Instances
if
(
request
.
method
().
compare
(
"GET"
)
==
0
)
{
if
(
request
.
method
().
compare
(
"GET"
)
==
0
)
{
std
::
string
split_query
=
request
.
uri
().
raw_query
;
std
::
string
split_query
=
request
.
uri
().
raw_query
;
...
@@ -282,15 +304,24 @@ void nrf_http2_server::get_nf_instance_handler(
...
@@ -282,15 +304,24 @@ void nrf_http2_server::get_nf_instance_handler(
}
}
void
nrf_http2_server
::
get_nf_instances_handler
(
void
nrf_http2_server
::
get_nf_instances_handler
(
const
std
::
string
&
nf
Type
,
const
uint32_t
&
limit
,
const
std
::
string
&
nf
_type
,
const
std
::
string
&
limit_nfs
,
const
response
&
response
)
{
const
response
&
response
)
{
Logger
::
nrf_sbi
().
info
(
Logger
::
nrf_sbi
().
info
(
"Got a request to retrieve a collection of NF Instances"
);
"Got a request to retrieve a collection of NF Instances"
);
if
(
!
nfType
.
empty
())
std
::
string
nfType
=
{};
if
(
!
nf_type
.
empty
())
{
nfType
=
nf_type
;
Logger
::
nrf_sbi
().
debug
(
"
\t
NF type: %s"
,
nfType
.
c_str
());
Logger
::
nrf_sbi
().
debug
(
"
\t
NF type: %s"
,
nfType
.
c_str
());
}
if
(
limit
>
0
)
Logger
::
nrf_sbi
().
debug
(
"
\t
Limit number of items: %d"
,
limit
);
uint32_t
limit_Nfs
=
0
;
if
(
!
limit_nfs
.
empty
())
{
limit_Nfs
=
stoi
(
limit_nfs
);
Logger
::
nrf_sbi
().
debug
(
"
\t
Maximum number of NFProfiles to be returned in the response: %d"
,
limit_Nfs
);
}
int
http_code
=
0
;
int
http_code
=
0
;
ProblemDetails
problem_details
=
{};
ProblemDetails
problem_details
=
{};
...
@@ -300,7 +331,7 @@ void nrf_http2_server::get_nf_instances_handler(
...
@@ -300,7 +331,7 @@ void nrf_http2_server::get_nf_instances_handler(
std
::
vector
<
std
::
string
>
uris
=
{};
std
::
vector
<
std
::
string
>
uris
=
{};
m_nrf_app
->
handle_get_nf_instances
(
m_nrf_app
->
handle_get_nf_instances
(
nfType
,
uris
,
limit
,
http_code
,
2
,
problem_details
);
nfType
,
uris
,
limit
_Nfs
,
http_code
,
2
,
problem_details
);
if
(
http_code
!=
HTTP_STATUS_CODE_200_OK
)
{
if
(
http_code
!=
HTTP_STATUS_CODE_200_OK
)
{
to_json
(
json_data
,
problem_details
);
to_json
(
json_data
,
problem_details
);
...
@@ -482,7 +513,7 @@ void nrf_http2_server::search_nf_instances_handler(
...
@@ -482,7 +513,7 @@ void nrf_http2_server::search_nf_instances_handler(
Logger
::
nrf_sbi
().
info
(
Logger
::
nrf_sbi
().
info
(
"Got a request to discover the set of NF instances that satisfies a "
"Got a request to discover the set of NF instances that satisfies a "
"number of input query parameters"
);
"number of input query parameters"
);
// ToDo
std
::
string
target_nfType
=
{};
std
::
string
target_nfType
=
{};
if
(
!
target_nf_type
.
empty
())
{
if
(
!
target_nf_type
.
empty
())
{
target_nfType
=
target_nf_type
;
target_nfType
=
target_nf_type
;
...
...
src/api-server/nrf-http2-server.h
View file @
f9c48674
...
@@ -55,7 +55,7 @@ class nrf_http2_server {
...
@@ -55,7 +55,7 @@ class nrf_http2_server {
void
get_nf_instance_handler
(
void
get_nf_instance_handler
(
const
std
::
string
&
nfInstanceID
,
const
response
&
response
);
const
std
::
string
&
nfInstanceID
,
const
response
&
response
);
void
get_nf_instances_handler
(
void
get_nf_instances_handler
(
const
std
::
string
&
nf
Type
,
const
uint32_t
&
limit
,
const
std
::
string
&
nf
_type
,
const
std
::
string
&
limit_nfs
,
const
response
&
response
);
const
response
&
response
);
void
update_instance_handler
(
void
update_instance_handler
(
const
std
::
string
&
nfInstanceID
,
const
std
::
vector
<
PatchItem
>&
patchItem
,
const
std
::
string
&
nfInstanceID
,
const
std
::
vector
<
PatchItem
>&
patchItem
,
...
...
src/common/nrf.h
View file @
f9c48674
...
@@ -78,7 +78,7 @@ typedef uint32_t evsub_id_t;
...
@@ -78,7 +78,7 @@ typedef uint32_t evsub_id_t;
#define NNRF_NFM_BASE "/nnrf-nfm/"
#define NNRF_NFM_BASE "/nnrf-nfm/"
#define NNRF_DISC_BASE "/nnrf-disc/"
#define NNRF_DISC_BASE "/nnrf-disc/"
#define NNRF_NFM_NF_INSTANCE "/nf-instances/"
#define NNRF_NFM_NF_INSTANCE
S
"/nf-instances/"
#define NNRF_NFM_STATUS_SUBSCRIBE_URL "/subscriptions"
#define NNRF_NFM_STATUS_SUBSCRIBE_URL "/subscriptions"
#define NF_CURL_TIMEOUT_MS 1000L
#define NF_CURL_TIMEOUT_MS 1000L
...
...
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