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
3ae9dafc
Commit
3ae9dafc
authored
Oct 19, 2022
by
Stefan Spettel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refact(smf): optimize code with const references
Signed-off-by:
Stefan Spettel
<
stefan.spettel@eurecom.fr
>
parent
1d69ccac
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
36 deletions
+38
-36
src/smf_app/smf_n7.cpp
src/smf_app/smf_n7.cpp
+20
-20
src/smf_app/smf_n7.hpp
src/smf_app/smf_n7.hpp
+18
-16
No files found.
src/smf_app/smf_n7.cpp
View file @
3ae9dafc
...
@@ -147,7 +147,7 @@ smf_n7::~smf_n7() {
...
@@ -147,7 +147,7 @@ smf_n7::~smf_n7() {
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
std
::
shared_ptr
<
smf_pcf_client
>
smf_pcf_client
::
discover_pcf
(
std
::
shared_ptr
<
smf_pcf_client
>
smf_pcf_client
::
discover_pcf
(
const
Snssai
snssai
,
const
PlmnId
plmn_id
,
const
std
::
string
dnn
)
{
const
Snssai
&
snssai
,
const
PlmnId
&
plmn_id
,
const
std
::
string
&
dnn
)
{
if
(
smf_cfg
.
use_local_pcc_rules
)
{
if
(
smf_cfg
.
use_local_pcc_rules
)
{
Logger
::
smf_n7
().
info
(
"Local PCC rules are enabled, do not discover PCF"
);
Logger
::
smf_n7
().
info
(
"Local PCC rules are enabled, do not discover PCF"
);
return
nullptr
;
return
nullptr
;
...
@@ -173,16 +173,16 @@ std::shared_ptr<smf_pcf_client> smf_pcf_client::discover_pcf(
...
@@ -173,16 +173,16 @@ std::shared_ptr<smf_pcf_client> smf_pcf_client::discover_pcf(
}
}
bool
smf_pcf_client
::
discover_pcf_with_nrf
(
bool
smf_pcf_client
::
discover_pcf_with_nrf
(
std
::
string
&
addr
,
std
::
string
&
api_version
,
const
Snssai
snssai
,
std
::
string
&
addr
,
std
::
string
&
api_version
,
const
Snssai
&
snssai
,
const
PlmnId
plmn_id
,
const
std
::
string
dnn
)
{
const
PlmnId
&
plmn_id
,
const
std
::
string
&
dnn
)
{
Logger
::
smf_n7
().
debug
(
"Discover PCF with NRF"
);
Logger
::
smf_n7
().
debug
(
"Discover PCF with NRF"
);
Logger
::
smf_n7
().
warn
(
"NRF discovery not yet supported!"
);
Logger
::
smf_n7
().
warn
(
"NRF discovery not yet supported!"
);
return
false
;
return
false
;
}
}
bool
smf_pcf_client
::
discover_pcf_from_config_file
(
bool
smf_pcf_client
::
discover_pcf_from_config_file
(
std
::
string
&
addr
,
std
::
string
&
api_version
,
const
Snssai
snssai
,
std
::
string
&
addr
,
std
::
string
&
api_version
,
const
Snssai
&
snssai
,
const
PlmnId
plmn_id
,
const
std
::
string
dnn
)
{
const
PlmnId
&
plmn_id
,
const
std
::
string
&
dnn
)
{
// TODO ignore snssai, plmn_id and dnn, because it is not part of
// TODO ignore snssai, plmn_id and dnn, because it is not part of
// configuration
// configuration
Logger
::
smf_n7
().
debug
(
"Discover PCF from config file"
);
Logger
::
smf_n7
().
debug
(
"Discover PCF from config file"
);
...
@@ -199,7 +199,7 @@ bool smf_pcf_client::discover_pcf_from_config_file(
...
@@ -199,7 +199,7 @@ bool smf_pcf_client::discover_pcf_from_config_file(
// resolve IP address
// resolve IP address
uint8_t
addr_type
=
0
;
uint8_t
addr_type
=
0
;
uint32_t
pcf_port
=
0
;
uint32_t
pcf_port
=
0
;
std
::
string
addr_temp
=
""
;
std
::
string
addr_temp
;
if
(
!
fqdn
::
resolve
(
smf_cfg
.
fqdn
,
addr_temp
,
pcf_port
,
addr_type
))
{
if
(
!
fqdn
::
resolve
(
smf_cfg
.
fqdn
,
addr_temp
,
pcf_port
,
addr_type
))
{
Logger
::
smf_n7
().
warn
(
"Could not resolve FQDN %s"
,
smf_cfg
.
fqdn
.
c_str
());
Logger
::
smf_n7
().
warn
(
"Could not resolve FQDN %s"
,
smf_cfg
.
fqdn
.
c_str
());
return
false
;
return
false
;
...
@@ -222,16 +222,16 @@ bool smf_pcf_client::discover_pcf_from_config_file(
...
@@ -222,16 +222,16 @@ bool smf_pcf_client::discover_pcf_from_config_file(
}
}
http_status_code_e
smf_pcf_client
::
send_request
(
http_status_code_e
smf_pcf_client
::
send_request
(
const
std
::
string
&
uri
,
const
std
::
string
&
body
,
std
::
string
&
response_body
,
const
std
::
string
&
uri
,
const
std
::
string
&
body
,
const
std
::
string
&
method
,
std
::
string
&
response_
headers
,
std
::
string
method
,
std
::
string
&
response_
body
,
std
::
string
&
response_headers
,
bool
use_response_headers
)
{
bool
use_response_headers
)
{
if
(
uri
==
""
)
{
if
(
uri
.
empty
()
)
{
Logger
::
smf_n7
().
warn
(
"PCF URI is not set"
);
Logger
::
smf_n7
().
warn
(
"PCF URI is not set"
);
return
http_status_code_e
::
HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR
;
return
http_status_code_e
::
HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR
;
}
}
// generate a promise for the curl handle
// generate a promise for the curl handle
uint32_t
promise_id
=
smf
_sbi_inst
->
generate_promise_id
();
uint32_t
promise_id
=
smf
::
smf_sbi
::
generate_promise_id
();
Logger
::
smf_sbi
().
debug
(
"Promise ID generated %d"
,
promise_id
);
Logger
::
smf_sbi
().
debug
(
"Promise ID generated %d"
,
promise_id
);
uint32_t
*
pid_ptr
=
&
promise_id
;
uint32_t
*
pid_ptr
=
&
promise_id
;
...
@@ -240,7 +240,7 @@ http_status_code_e smf_pcf_client::send_request(
...
@@ -240,7 +240,7 @@ http_status_code_e smf_pcf_client::send_request(
boost
::
shared_future
<
uint32_t
>
f
;
boost
::
shared_future
<
uint32_t
>
f
;
f
=
p
->
get_future
();
f
=
p
->
get_future
();
smf_sbi_inst
->
add_promise
(
promise_id
,
p
);
smf_sbi_inst
->
add_promise
(
promise_id
,
p
);
bool
res
=
false
;
bool
res
;
// Create a new curl easy handle and add to the multi handle
// Create a new curl easy handle and add to the multi handle
if
(
use_response_headers
)
{
if
(
use_response_headers
)
{
res
=
smf_sbi_inst
->
curl_create_handle
(
res
=
smf_sbi_inst
->
curl_create_handle
(
...
@@ -276,7 +276,7 @@ sm_policy_status_code smf_pcf_client::create_policy_association(
...
@@ -276,7 +276,7 @@ sm_policy_status_code smf_pcf_client::create_policy_association(
std
::
string
response_headers
;
std
::
string
response_headers
;
http_status_code_e
response_code
=
send_request
(
http_status_code_e
response_code
=
send_request
(
root_uri
,
json_data
.
dump
(),
response_data
,
response_headers
,
"POST"
,
root_uri
,
json_data
.
dump
(),
"POST"
,
response_data
,
response_headers
,
true
);
true
);
if
(
response_code
==
http_status_code_e
::
HTTP_STATUS_CODE_201_CREATED
)
{
if
(
response_code
==
http_status_code_e
::
HTTP_STATUS_CODE_201_CREATED
)
{
...
@@ -303,7 +303,7 @@ sm_policy_status_code smf_pcf_client::create_policy_association(
...
@@ -303,7 +303,7 @@ sm_policy_status_code smf_pcf_client::create_policy_association(
ProblemDetails
problem_details
;
ProblemDetails
problem_details
;
from_json
(
response_data
,
problem_details
);
from_json
(
response_data
,
problem_details
);
std
::
string
info
=
""
;
std
::
string
info
;
sm_policy_status_code
response
;
sm_policy_status_code
response
;
switch
(
response_code
)
{
switch
(
response_code
)
{
case
http_status_code_e
:
:
HTTP_STATUS_CODE_403_FORBIDDEN
:
case
http_status_code_e
:
:
HTTP_STATUS_CODE_403_FORBIDDEN
:
...
@@ -328,7 +328,7 @@ sm_policy_status_code smf_pcf_client::create_policy_association(
...
@@ -328,7 +328,7 @@ sm_policy_status_code smf_pcf_client::create_policy_association(
info
=
info
=
"SM Policy Association Creation: Unknown Error Code from "
"SM Policy Association Creation: Unknown Error Code from "
"PCF: "
+
"PCF: "
+
response_code
;
std
::
to_string
(
response_code
)
;
}
}
Logger
::
smf_n7
().
warn
(
Logger
::
smf_n7
().
warn
(
...
@@ -346,7 +346,7 @@ sm_policy_status_code smf_pcf_client::remove_policy_association(
...
@@ -346,7 +346,7 @@ sm_policy_status_code smf_pcf_client::remove_policy_association(
std
::
string
resp
;
std
::
string
resp
;
http_status_code_e
response_code
=
http_status_code_e
response_code
=
send_request
(
uri
,
json_data
.
dump
(),
resp
,
resp
,
"POST"
,
false
);
send_request
(
uri
,
json_data
.
dump
(),
"POST"
,
resp
,
resp
,
false
);
switch
(
response_code
)
{
switch
(
response_code
)
{
case
http_status_code_e
:
:
HTTP_STATUS_CODE_204_NO_CONTENT
:
case
http_status_code_e
:
:
HTTP_STATUS_CODE_204_NO_CONTENT
:
...
@@ -371,7 +371,7 @@ sm_policy_status_code smf_pcf_client::update_policy_association(
...
@@ -371,7 +371,7 @@ sm_policy_status_code smf_pcf_client::update_policy_association(
nlohmann
::
json
json_data
;
nlohmann
::
json
json_data
;
to_json
(
json_data
,
update_data
);
to_json
(
json_data
,
update_data
);
http_status_code_e
response_code
=
http_status_code_e
response_code
=
send_request
(
uri
,
json_data
.
dump
(),
resp
,
resp
,
"POST"
,
false
);
send_request
(
uri
,
json_data
.
dump
(),
"POST"
,
resp
,
resp
,
false
);
nlohmann
::
json
json_resp
;
nlohmann
::
json
json_resp
;
...
@@ -400,9 +400,9 @@ sm_policy_status_code smf_pcf_client::get_policy_association(
...
@@ -400,9 +400,9 @@ sm_policy_status_code smf_pcf_client::get_policy_association(
policy_association
&
association
)
{
policy_association
&
association
)
{
std
::
string
uri
=
association
.
pcf_location
;
std
::
string
uri
=
association
.
pcf_location
;
std
::
string
resp
;
std
::
string
resp
;
std
::
string
empty
=
""
;
std
::
string
empty
;
http_status_code_e
response_code
=
http_status_code_e
response_code
=
send_request
(
uri
,
empty
,
resp
,
resp
,
"GET"
,
false
);
send_request
(
uri
,
empty
,
"GET"
,
resp
,
resp
,
false
);
nlohmann
::
json
j
=
nlohmann
::
json
::
parse
(
resp
);
nlohmann
::
json
j
=
nlohmann
::
json
::
parse
(
resp
);
SmPolicyControl
control
;
SmPolicyControl
control
;
switch
(
response_code
)
{
switch
(
response_code
)
{
...
...
src/smf_app/smf_n7.hpp
View file @
3ae9dafc
...
@@ -72,8 +72,9 @@ struct policy_association {
...
@@ -72,8 +72,9 @@ struct policy_association {
std
::
string
pcf_location
;
std
::
string
pcf_location
;
void
set_context
(
void
set_context
(
std
::
string
supi
,
std
::
string
dnn
,
snssai_t
snssai
,
plmn_t
plmn
,
const
std
::
string
&
supi
,
const
std
::
string
&
dnn
,
const
snssai_t
&
snssai
,
uint8_t
pdu_session_id
,
pdu_session_type_t
pdu_session_type
)
{
const
plmn_t
&
plmn
,
const
uint8_t
pdu_session_id
,
const
pdu_session_type_t
&
pdu_session_type
)
{
oai
::
smf_server
::
model
::
Snssai
snssai_model
;
oai
::
smf_server
::
model
::
Snssai
snssai_model
;
snssai_model
.
setSst
(
snssai
.
sst
);
snssai_model
.
setSst
(
snssai
.
sst
);
snssai_model
.
setSd
(
std
::
to_string
(
snssai
.
sd
));
snssai_model
.
setSd
(
std
::
to_string
(
snssai
.
sd
));
...
@@ -100,17 +101,17 @@ struct policy_association {
...
@@ -100,17 +101,17 @@ struct policy_association {
context
.
setServingNetwork
(
plmn_id_model
);
context
.
setServingNetwork
(
plmn_id_model
);
}
}
std
::
string
toString
()
{
std
::
string
toString
()
const
{
std
::
string
s
=
""
;
std
::
string
s
;
if
(
decision
.
pccRulesIsSet
())
{
if
(
decision
.
pccRulesIsSet
())
{
s
.
append
(
"
\t\t
PCC Rules:
\n
"
);
s
.
append
(
"
\t\t
PCC Rules:
\n
"
);
for
(
auto
it
:
decision
.
getPccRules
())
{
for
(
const
auto
&
it
:
decision
.
getPccRules
())
{
s
.
append
(
"
\t\t\t\t
"
).
append
(
it
.
second
.
getPccRuleId
()).
append
(
"
\n
"
);
s
.
append
(
"
\t\t\t\t
"
).
append
(
it
.
second
.
getPccRuleId
()).
append
(
"
\n
"
);
}
}
}
}
if
(
decision
.
traffContDecsIsSet
())
{
if
(
decision
.
traffContDecsIsSet
())
{
s
.
append
(
"
\t\t
Traffic Control Descriptions:
\n
"
);
s
.
append
(
"
\t\t
Traffic Control Descriptions:
\n
"
);
for
(
auto
it
:
decision
.
getTraffContDecs
())
{
for
(
const
auto
&
it
:
decision
.
getTraffContDecs
())
{
s
.
append
(
"
\t\t\t\t
"
).
append
(
it
.
second
.
getTcId
()).
append
(
"
\n
"
);
s
.
append
(
"
\t\t\t\t
"
).
append
(
it
.
second
.
getTcId
()).
append
(
"
\n
"
);
}
}
}
}
...
@@ -190,7 +191,8 @@ class smf_pcf_client : public policy_storage {
...
@@ -190,7 +191,8 @@ class smf_pcf_client : public policy_storage {
const
std
::
string
delete_suffix
=
"delete"
;
const
std
::
string
delete_suffix
=
"delete"
;
const
std
::
string
update_suffix
=
"update"
;
const
std
::
string
update_suffix
=
"update"
;
explicit
smf_pcf_client
(
std
::
string
pcf_addr
,
std
::
string
pcf_api_version
)
{
explicit
smf_pcf_client
(
const
std
::
string
&
pcf_addr
,
const
std
::
string
&
pcf_api_version
)
{
root_uri
=
"http://"
+
pcf_addr
+
"/"
+
sm_api_name
+
"/"
+
root_uri
=
"http://"
+
pcf_addr
+
"/"
+
sm_api_name
+
"/"
+
pcf_api_version
+
"/"
+
sm_api_policy_resource_part
;
pcf_api_version
+
"/"
+
sm_api_policy_resource_part
;
}
}
...
@@ -207,8 +209,8 @@ class smf_pcf_client : public policy_storage {
...
@@ -207,8 +209,8 @@ class smf_pcf_client : public policy_storage {
* @return & smf_pcf_client nullptr in case of an error
* @return & smf_pcf_client nullptr in case of an error
*/
*/
static
std
::
shared_ptr
<
smf_pcf_client
>
discover_pcf
(
static
std
::
shared_ptr
<
smf_pcf_client
>
discover_pcf
(
const
oai
::
smf_server
::
model
::
Snssai
snssai
,
const
oai
::
smf_server
::
model
::
Snssai
&
snssai
,
const
oai
::
smf_server
::
model
::
PlmnId
plmn_id
,
const
std
::
string
dnn
);
const
oai
::
smf_server
::
model
::
PlmnId
&
plmn_id
,
const
std
::
string
&
dnn
);
sm_policy_status_code
create_policy_association
(
sm_policy_status_code
create_policy_association
(
policy_association
&
association
)
override
;
policy_association
&
association
)
override
;
...
@@ -227,18 +229,18 @@ class smf_pcf_client : public policy_storage {
...
@@ -227,18 +229,18 @@ class smf_pcf_client : public policy_storage {
private:
private:
static
bool
discover_pcf_with_nrf
(
static
bool
discover_pcf_with_nrf
(
std
::
string
&
addr
,
std
::
string
&
api_version
,
std
::
string
&
addr
,
std
::
string
&
api_version
,
const
oai
::
smf_server
::
model
::
Snssai
snssai
,
const
oai
::
smf_server
::
model
::
Snssai
&
snssai
,
const
oai
::
smf_server
::
model
::
PlmnId
plmn_id
,
const
std
::
string
dnn
);
const
oai
::
smf_server
::
model
::
PlmnId
&
plmn_id
,
const
std
::
string
&
dnn
);
static
bool
discover_pcf_from_config_file
(
static
bool
discover_pcf_from_config_file
(
std
::
string
&
addr
,
std
::
string
&
api_version
,
std
::
string
&
addr
,
std
::
string
&
api_version
,
const
oai
::
smf_server
::
model
::
Snssai
snssai
,
const
oai
::
smf_server
::
model
::
Snssai
&
snssai
,
const
oai
::
smf_server
::
model
::
PlmnId
plmn_id
,
const
std
::
string
dnn
);
const
oai
::
smf_server
::
model
::
PlmnId
&
plmn_id
,
const
std
::
string
&
dnn
);
http_status_code_e
send_request
(
http_status_code_e
send_request
(
const
std
::
string
&
uri
,
const
std
::
string
&
body
,
const
std
::
string
&
uri
,
const
std
::
string
&
body
,
std
::
string
&
response_body
,
std
::
string
&
response_headers
,
const
std
::
string
&
method
,
std
::
string
&
response_body
,
std
::
string
method
,
bool
use_response_headers
=
false
);
std
::
string
&
response_headers
,
bool
use_response_headers
=
false
);
std
::
string
root_uri
;
std
::
string
root_uri
;
};
};
...
@@ -333,4 +335,4 @@ class smf_n7 {
...
@@ -333,4 +335,4 @@ class smf_n7 {
mutable
std
::
shared_mutex
policy_storages_mutex
;
mutable
std
::
shared_mutex
policy_storages_mutex
;
};
};
}
// namespace smf::n7
}
// namespace smf::n7
#endif
/* FILE_SMF_N
4
_HPP_SEEN */
#endif
/* FILE_SMF_N
7
_HPP_SEEN */
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