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
d54a2ecf
Commit
d54a2ecf
authored
Jun 20, 2022
by
Stefan Spettel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refact(smf): Replace folly AtomicHashMap with std unordered_map
Signed-off-by:
Stefan Spettel
<
stefan.spettel@eurecom.fr
>
parent
5b9c8065
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
50 deletions
+54
-50
src/smf_app/smf_n7.cpp
src/smf_app/smf_n7.cpp
+41
-40
src/smf_app/smf_n7.hpp
src/smf_app/smf_n7.hpp
+13
-10
No files found.
src/smf_app/smf_n7.cpp
View file @
d54a2ecf
...
@@ -45,14 +45,16 @@ extern smf_config smf_cfg;
...
@@ -45,14 +45,16 @@ extern smf_config smf_cfg;
extern
smf_sbi
*
smf_sbi_inst
;
extern
smf_sbi
*
smf_sbi_inst
;
uint32_t
smf_n7
::
select_pcf
(
const
SmPolicyContextData
&
context
)
{
uint32_t
smf_n7
::
select_pcf
(
const
SmPolicyContextData
&
context
)
{
// TODO abstraction: Here we should choose between local PCC rules and PCF
// client
// TODO PCF selection
// TODO PCF selection
if
(
policy_storages
.
empty
())
{
if
(
policy_storages
.
empty
())
{
std
::
unique_lock
policies_lock
(
policy_storages_mutex
);
// TODO choose between local PCC rules and PCF client, for now only PCF
// TODO choose between local PCC rules and PCF client, for now only PCF
// client
// client
if
(
smf_cfg
.
use_local_pcc_rules
)
{
Logger
::
smf_n7
().
warn
(
"Local PCC rules are not supported yet"
);
return
0
;
}
else
{
PlmnId
plmn_id
=
{};
PlmnId
plmn_id
=
{};
plmn_id
.
setMcc
(
context
.
getServingNetwork
().
getMcc
());
plmn_id
.
setMcc
(
context
.
getServingNetwork
().
getMcc
());
plmn_id
.
setMnc
(
context
.
getServingNetwork
().
getMnc
());
plmn_id
.
setMnc
(
context
.
getServingNetwork
().
getMnc
());
...
@@ -61,13 +63,14 @@ uint32_t smf_n7::select_pcf(const SmPolicyContextData& context) {
...
@@ -61,13 +63,14 @@ uint32_t smf_n7::select_pcf(const SmPolicyContextData& context) {
if
(
storage
)
{
if
(
storage
)
{
// TODO for now, only use the first PCF
// TODO for now, only use the first PCF
policy_storages
.
insert
(
1
,
storage
);
policy_storages
.
insert
(
std
::
make_pair
(
1
,
storage
)
);
return
1
;
// ID is always 1, only one PF
return
1
;
// ID is always 1, only one PF
}
else
{
}
else
{
Logger
::
smf_n7
().
info
(
"Did not find PCF"
);
Logger
::
smf_n7
().
info
(
"Did not find PCF"
);
return
0
;
return
0
;
}
}
}
}
}
// TODO for now, only use first PCF
// TODO for now, only use first PCF
return
1
;
return
1
;
...
@@ -79,23 +82,15 @@ sm_policy_status_code smf_n7::create_sm_policy_association(
...
@@ -79,23 +82,15 @@ sm_policy_status_code smf_n7::create_sm_policy_association(
if
(
pcf_id
==
0
)
{
if
(
pcf_id
==
0
)
{
return
sm_policy_status_code
::
PCF_NOT_AVAILABLE
;
return
sm_policy_status_code
::
PCF_NOT_AVAILABLE
;
}
}
/*std::shared_ptr<policy_storage> store;
association
.
pcf_id
=
pcf_id
;
std
::
shared_ptr
<
policy_storage
>
storage
=
try {
get_policy_storage
(
association
.
pcf_id
);
store = policy_storages.at(pcf_id);
} catch (std::exception) {
return sm_policy_status_code::PCF_NOT_AVAILABLE;
} */
folly
::
AtomicHashMap
<
uint32_t
,
std
::
shared_ptr
<
policy_storage
>>::
iterator
it
=
policy_storages
.
find
(
pcf_id
);
if
(
it
==
policy_storages
.
end
()
)
{
if
(
!
storage
)
{
return
sm_policy_status_code
::
PCF_NOT_AVAILABLE
;
return
sm_policy_status_code
::
PCF_NOT_AVAILABLE
;
}
}
sm_policy_status_code
res
=
sm_policy_status_code
res
=
storage
->
create_policy_association
(
association
);
it
->
second
->
create_policy_association
(
association
);
if
(
res
==
sm_policy_status_code
::
CREATED
)
{
if
(
res
==
sm_policy_status_code
::
CREATED
)
{
if
(
association
.
id
==
0
)
{
if
(
association
.
id
==
0
)
{
...
@@ -115,26 +110,32 @@ sm_policy_status_code smf_n7::create_sm_policy_association(
...
@@ -115,26 +110,32 @@ sm_policy_status_code smf_n7::create_sm_policy_association(
sm_policy_status_code
smf_n7
::
remove_sm_policy_association
(
sm_policy_status_code
smf_n7
::
remove_sm_policy_association
(
const
policy_association
&
association
,
const
policy_association
&
association
,
const
SmPolicyDeleteData
&
delete_data
)
{
const
SmPolicyDeleteData
&
delete_data
)
{
folly
::
AtomicHashMap
<
uint32_t
,
std
::
shared_ptr
<
policy_storage
>>::
iterator
it
=
std
::
shared_ptr
<
policy_storage
>
storage
=
policy_storages
.
find
(
association
.
pcf_id
);
get_policy_storage
(
association
.
pcf_id
);
if
(
!
storage
)
return
sm_policy_status_code
::
PCF_NOT_AVAILABLE
;
if
(
it
==
policy_storages
.
end
())
{
return
storage
->
remove_policy_association
(
association
,
delete_data
);
return
sm_policy_status_code
::
PCF_NOT_AVAILABLE
;
}
return
it
->
second
->
remove_policy_association
(
association
,
delete_data
);
}
}
sm_policy_status_code
smf_n7
::
update_sm_policy_association
(
sm_policy_status_code
smf_n7
::
update_sm_policy_association
(
policy_association
&
association
,
policy_association
&
association
,
const
SmPolicyUpdateContextData
&
update_data
)
{
const
SmPolicyUpdateContextData
&
update_data
)
{
folly
::
AtomicHashMap
<
uint32_t
,
std
::
shared_ptr
<
policy_storage
>>::
iterator
it
=
std
::
shared_ptr
<
policy_storage
>
storage
=
policy_storages
.
find
(
association
.
pcf_id
);
get_policy_storage
(
association
.
pcf_id
);
if
(
!
storage
)
return
sm_policy_status_code
::
PCF_NOT_AVAILABLE
;
return
storage
->
update_policy_association
(
update_data
,
association
);
}
std
::
shared_ptr
<
policy_storage
>
smf_n7
::
get_policy_storage
(
uint32_t
pcf_id
)
{
std
::
shared_lock
policies_lock
(
policy_storages_mutex
);
auto
it
=
policy_storages
.
find
(
pcf_id
);
if
(
it
==
policy_storages
.
end
())
{
if
(
it
==
policy_storages
.
end
())
{
return
sm_policy_status_code
::
PCF_NOT_AVAILABLE
;
return
nullptr
;
}
}
return
it
->
second
;
return
it
->
second
->
update_policy_association
(
update_data
,
association
);
}
}
smf_n7
::~
smf_n7
()
{
smf_n7
::~
smf_n7
()
{
...
@@ -251,7 +252,7 @@ http_status_code_e smf_pcf_client::send_request(
...
@@ -251,7 +252,7 @@ http_status_code_e smf_pcf_client::send_request(
}
}
if
(
!
res
)
{
if
(
!
res
)
{
Logger
::
smf_
sbi
().
warn
(
Logger
::
smf_
n7
().
warn
(
"Could not create a new handle to send message to PCF"
);
"Could not create a new handle to send message to PCF"
);
smf_sbi_inst
->
remove_promise
(
promise_id
);
smf_sbi_inst
->
remove_promise
(
promise_id
);
return
http_status_code_e
::
HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR
;
return
http_status_code_e
::
HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR
;
...
...
src/smf_app/smf_n7.hpp
View file @
d54a2ecf
...
@@ -31,8 +31,8 @@
...
@@ -31,8 +31,8 @@
#include <string>
#include <string>
#include <memory>
#include <memory>
//#include <folly/concurrency/ConcurrentHashMap.h
>
#include <unordered_map
>
#include <
folly/AtomicHashMap.h
>
#include <
shared_mutex
>
#include "Snssai.h"
#include "Snssai.h"
#include "PlmnId.h"
#include "PlmnId.h"
...
@@ -253,9 +253,7 @@ class smf_pcf_client : public policy_storage {
...
@@ -253,9 +253,7 @@ class smf_pcf_client : public policy_storage {
*/
*/
class
smf_n7
{
class
smf_n7
{
public:
public:
const
uint32_t
PCF_CLIENTS
=
16
;
smf_n7
()
:
policy_storages
(){};
smf_n7
()
:
policy_storages
(
PCF_CLIENTS
){};
smf_n7
(
smf_n7
const
&
)
=
delete
;
smf_n7
(
smf_n7
const
&
)
=
delete
;
void
operator
=
(
smf_n7
const
&
)
=
delete
;
void
operator
=
(
smf_n7
const
&
)
=
delete
;
virtual
~
smf_n7
();
virtual
~
smf_n7
();
...
@@ -321,11 +319,16 @@ class smf_n7 {
...
@@ -321,11 +319,16 @@ class smf_n7 {
uint32_t
select_pcf
(
uint32_t
select_pcf
(
const
oai
::
smf_server
::
model
::
SmPolicyContextData
&
context
);
const
oai
::
smf_server
::
model
::
SmPolicyContextData
&
context
);
// TODO the ConcurrentHashMap of folly would be much better, but I get a
/**
// linker error, we should fix that Reason: AtomicHashMap requires that the
* @brief Helper method to receive the policy storage (thread safe)
// amount of objects is known upfront.
*
folly
::
AtomicHashMap
<
uint32_t
,
std
::
shared_ptr
<
policy_storage
>>
* @param pcf_id ID of the policy storage
policy_storages
;
* @return std::shared_ptr<policy_storage> -> nullptr in case not found
*/
std
::
shared_ptr
<
policy_storage
>
get_policy_storage
(
uint32_t
pcf_id
);
std
::
unordered_map
<
uint32_t
,
std
::
shared_ptr
<
policy_storage
>>
policy_storages
;
mutable
std
::
shared_mutex
policy_storages_mutex
;
};
};
}
// namespace smf::n7
}
// namespace smf::n7
#endif
/* FILE_SMF_N4_HPP_SEEN */
#endif
/* FILE_SMF_N4_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