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
cdab6bea
Unverified
Commit
cdab6bea
authored
Sep 28, 2021
by
kharade
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nf discovery service validated
parent
aae8130e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
95 additions
and
41 deletions
+95
-41
src/api-server/nrf-http2-server.cpp
src/api-server/nrf-http2-server.cpp
+79
-32
src/api-server/nrf-http2-server.h
src/api-server/nrf-http2-server.h
+3
-2
src/common/nrf.h
src/common/nrf.h
+1
-0
src/common/utils/string.cpp
src/common/utils/string.cpp
+11
-6
src/common/utils/string.hpp
src/common/utils/string.hpp
+1
-1
No files found.
src/api-server/nrf-http2-server.cpp
View file @
cdab6bea
...
...
@@ -34,6 +34,7 @@
#include <regex>
#include <nlohmann/json.hpp>
#include <string>
#include "string.hpp"
#include "logger.hpp"
#include "nrf_config.hpp"
...
...
@@ -67,6 +68,7 @@ void nrf_http2_server::start() {
nlohmann
::
json
::
parse
(
msg
.
c_str
()).
get_to
(
nFProfile
);
this
->
register_nf_instance_handler
(
nFProfile
,
response
);
}
if
(
request
.
method
().
compare
(
"GET"
)
==
0
)
{
nlohmann
::
json
::
parse
(
msg
.
c_str
()).
get_to
(
nFProfile
);
std
::
vector
<
std
::
string
>
split_result
;
...
...
@@ -88,11 +90,12 @@ void nrf_http2_server::start() {
std
::
string
nfType
=
util
::
get_query_param
(
querystring
,
"nf-type"
);
uint32_t
limit
=
a
toi
(
util
::
get_query_param
(
querystring
,
"limit"
).
c_str
());
s
toi
(
util
::
get_query_param
(
querystring
,
"limit"
).
c_str
());
this
->
get_nf_instances_handler
(
nfType
,
limit
,
response
);
}
}
if
(
request
.
method
().
compare
(
"PATCH"
)
==
0
&&
len
>
0
)
{
std
::
vector
<
PatchItem
>
patchItem
;
nlohmann
::
json
::
parse
(
msg
.
c_str
()).
get_to
(
patchItem
);
...
...
@@ -102,6 +105,7 @@ void nrf_http2_server::start() {
nfInstanceID
=
split_result
[
split_result
.
size
()
-
1
].
c_str
();
this
->
update_instance_handler
(
nfInstanceID
,
patchItem
,
response
);
}
if
(
request
.
method
().
compare
(
"DELETE"
)
==
0
)
{
std
::
vector
<
std
::
string
>
split_result
;
boost
::
split
(
...
...
@@ -148,7 +152,48 @@ void nrf_http2_server::start() {
subscriptionID
=
split_result
[
split_result
.
size
()
-
1
].
c_str
();
this
->
remove_subscription_handler
(
subscriptionID
,
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 Discovery
server
.
handle
(
NNRF_DISC_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
{
if
(
request
.
method
().
compare
(
"GET"
)
==
0
)
{
std
::
string
split_query
=
request
.
uri
().
raw_query
;
// Parse query paramaters
std
::
string
nfTypeTarget
=
util
::
get_query_param
(
split_query
,
"target-nf-type"
);
std
::
string
nfTypeReq
=
util
::
get_query_param
(
split_query
.
c_str
(),
"requester-nf-type"
);
std
::
string
requester_nf_instance_id
=
util
::
get_query_param
(
split_query
.
c_str
(),
"requester-nf-instance-id"
);
std
::
string
limit_nfs
=
util
::
get_query_param
(
split_query
.
c_str
(),
"limit"
);
// TODO: other query parameters
Logger
::
nrf_sbi
().
debug
(
"/nnrf-disc/ query params - nfTypeTarget: %s, nfTypeReq: %s, "
"requester-nf-instance-id: %s, limit_nfs %s"
,
nfTypeTarget
.
c_str
(),
nfTypeReq
.
c_str
(),
requester_nf_instance_id
.
c_str
(),
limit_nfs
.
c_str
());
this
->
search_nf_instances_handler
(
nfTypeTarget
,
nfTypeReq
,
requester_nf_instance_id
,
limit_nfs
,
response
);
}
}
catch
(
nlohmann
::
detail
::
exception
&
e
)
{
Logger
::
nrf_sbi
().
warn
(
"Can not parse the json data (error: %s)!"
,
e
.
what
());
...
...
@@ -431,38 +476,40 @@ void nrf_http2_server::remove_subscription_handler(
}
void
nrf_http2_server
::
search_nf_instances_handler
(
const
SubscriptionData
&
subscriptionData
,
const
response
&
response
)
{
const
std
::
string
&
target_nf_type
,
const
std
::
string
&
requester_nf_type
,
const
std
::
string
&
requester_nf_instance_id
,
const
std
::
string
&
limit_nfs
,
const
response
&
response
)
{
Logger
::
nrf_sbi
().
info
(
"Got a request to discover the set of NF instances that satisfies a "
"number of input query parameters"
);
// ToDo
std
::
string
target_nf
_t
ype
=
{};
// if (!targetNfType.isE
mpty()) {
// target_nf_type = targetNfType.get()
;
// Logger::nrf_sbi().debug("\tTarget NF type: %s", target_nf_t
ype.c_str());
//
}
std
::
string
requester_nf
_t
ype
=
{};
// if (!requesterNfType.isE
mpty()) {
// requester_nf_type = requesterNfType.get()
;
//
Logger::nrf_sbi().debug(
// "\tRequested NF type: %s", requester_nf_t
ype.c_str());
//
}
std
::
string
requester_nf
_i
nstance_id
=
{};
// if (!requesterNfInstanceId.isE
mpty()) {
// requester_nf_instance_id = requesterNfInstanceId.get()
;
//
Logger::nrf_sbi().debug(
//
"\tRequested NF instance id: %s", requester_nf_instance_id.c_str());
//
}
uint32_t
limit_
n
fs
=
0
;
// if (!limit.isE
mpty()) {
// limit_nfs = limit.get(
);
//
Logger::nrf_sbi().debug(
//
"\tMaximum number of NFProfiles to be returned in the response: %d",
// limit_n
fs);
//
}
std
::
string
target_nf
T
ype
=
{};
if
(
!
target_nf_type
.
e
mpty
())
{
target_nfType
=
target_nf_type
;
Logger
::
nrf_sbi
().
debug
(
"
\t
Target NF type: %s"
,
target_nfT
ype
.
c_str
());
}
std
::
string
requester_nf
T
ype
=
{};
if
(
!
requester_nf_type
.
e
mpty
())
{
requester_nfType
=
requester_nf_type
;
Logger
::
nrf_sbi
().
debug
(
"
\t
Requested NF type: %s"
,
requester_nfT
ype
.
c_str
());
}
std
::
string
requester_nf
I
nstance_id
=
{};
if
(
!
requester_nf_instance_id
.
e
mpty
())
{
requester_nfInstance_id
=
requester_nf_instance_id
;
Logger
::
nrf_sbi
().
debug
(
"
\t
Requested NF instance id: %s"
,
requester_nf_instance_id
.
c_str
());
}
uint32_t
limit_
N
fs
=
0
;
if
(
!
limit_nfs
.
e
mpty
())
{
limit_Nfs
=
stoi
(
limit_nfs
);
Logger
::
nrf_sbi
().
debug
(
"
\t
Maximum number of NFProfiles to be returned in the response: %d"
,
limit_N
fs
);
}
// TODO: other query parameters
...
...
@@ -470,8 +517,8 @@ void nrf_http2_server::search_nf_instances_handler(
ProblemDetails
problem_details
=
{};
std
::
string
search_id
=
{};
m_nrf_app
->
handle_search_nf_instances
(
target_nf
_type
,
requester_nf_type
,
requester_nf_instance_id
,
limit_n
fs
,
search_id
,
http_code
,
1
,
problem_details
);
target_nf
Type
,
requester_nfType
,
requester_nfInstance_id
,
limit_N
fs
,
search_id
,
http_code
,
2
,
problem_details
);
nlohmann
::
json
json_data
=
{};
std
::
string
content_type
=
"application/json"
;
...
...
@@ -485,7 +532,7 @@ void nrf_http2_server::search_nf_instances_handler(
}
else
{
// convert the profile to Json
if
(
search_result
!=
nullptr
)
search_result
.
get
()
->
to_json
(
json_data
,
limit_
n
fs
);
search_result
.
get
()
->
to_json
(
json_data
,
limit_
N
fs
);
}
// TODO: applying client restrictions in terms of the number of
...
...
src/api-server/nrf-http2-server.h
View file @
cdab6bea
...
...
@@ -31,7 +31,6 @@
#define FILE_NRF_HTTP2_SERVER_SEEN
#include "conversions.hpp"
#include "string.hpp"
//#include "nrf.h"
#include "nrf_app.hpp"
...
...
@@ -69,7 +68,9 @@ class nrf_http2_server {
void
remove_subscription_handler
(
const
std
::
string
&
subscriptionID
,
const
response
&
response
);
void
search_nf_instances_handler
(
const
SubscriptionData
&
subscriptionData
,
const
response
&
response
);
const
std
::
string
&
target_nf_type
,
const
std
::
string
&
requester_nf_type
,
const
std
::
string
&
requester_nf_instance_id
,
const
std
::
string
&
limit_nfs
,
const
response
&
response
);
void
access_token_request_handler
(
const
SubscriptionData
&
subscriptionData
,
const
response
&
response
);
...
...
src/common/nrf.h
View file @
cdab6bea
...
...
@@ -77,6 +77,7 @@ typedef uint32_t evsub_id_t;
#define UNASSIGNED_EVSUB_ID ((evsub_id_t) 0x00000000)
#define NNRF_NFM_BASE "/nnrf-nfm/"
#define NNRF_DISC_BASE "/nnrf-disc/"
#define NNRF_NFM_NF_INSTANCE "/nf-instances/"
#define NNRF_NFM_STATUS_SUBSCRIBE_URL "/subscriptions"
...
...
src/common/utils/string.cpp
View file @
cdab6bea
...
...
@@ -19,6 +19,7 @@
* contact@openairinterface.org
*/
#include "string.hpp"
#include <iostream>
#include <algorithm>
#include <functional>
...
...
@@ -89,14 +90,18 @@ std::string& util::trim(std::string& s) {
}
// extract query param from given querystring
std
::
string
&
util
::
get_query_param
(
std
::
string
&
querystring
,
std
::
string
param
)
{
std
::
string
query_param_tmp
;
//
std
::
string
util
::
get_query_param
(
std
::
string
querystring
,
std
::
string
param
)
{
std
::
regex
reList
(
"([^=]*)=([^&]*)&?"
);
std
::
string
tmp
=
param
;
query_param_tmp
.
clear
()
;
std
::
for_each
(
std
::
sregex_iterator
(
querystring
.
begin
(),
querystring
.
end
(),
reList
),
std
::
sregex_iterator
(),
[
param
](
std
::
smatch
const
&
match
)
{
std
::
string
qs_match_1
=
match
[
1
].
str
();
if
(
qs_match_1
==
param
)
return
match
[
2
].
str
();
std
::
sregex_iterator
(),
[
param
](
std
::
smatch
match
)
{
if
(
match
[
1
]
==
param
)
{
query_param_tmp
=
match
[
2
].
str
().
c_str
();
return
;
}
});
return
query_param_tmp
;
}
\ No newline at end of file
src/common/utils/string.hpp
View file @
cdab6bea
...
...
@@ -40,6 +40,6 @@ std::string& rtrim(std::string& s);
// trim from both ends
std
::
string
&
trim
(
std
::
string
&
s
);
// extract query param from given querystring
std
::
string
&
get_query_param
(
std
::
string
&
querystring
,
std
::
string
param
);
std
::
string
get_query_param
(
std
::
string
querystring
,
std
::
string
param
);
}
// namespace util
#endif
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