Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-AUSF
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-AUSF
Commits
d9138e8f
Commit
d9138e8f
authored
May 25, 2021
by
Tien-Thinh Nguyen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish the code
parent
faaf20f5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
75 deletions
+39
-75
src/ausf_app/ausf_app.cpp
src/ausf_app/ausf_app.cpp
+9
-10
src/ausf_app/ausf_app.hpp
src/ausf_app/ausf_app.hpp
+0
-8
src/ausf_app/ausf_client.cpp
src/ausf_app/ausf_client.cpp
+28
-55
src/ausf_app/ausf_client.hpp
src/ausf_app/ausf_client.hpp
+2
-2
No files found.
src/ausf_app/ausf_app.cpp
View file @
d9138e8f
...
...
@@ -136,14 +136,14 @@ void ausf_app::handle_ue_authentications(
// 5g he av from udm
// get authentication related info
std
::
string
udmUri
,
Method
,
R
esponse
;
std
::
string
udmUri
,
method
,
r
esponse
;
udmUri
=
"http://"
+
std
::
string
(
inet_ntoa
(
*
((
struct
in_addr
*
)
&
ausf_cfg
.
udm_addr
.
ipv4_addr
)))
+
":"
+
std
::
to_string
(
ausf_cfg
.
udm_addr
.
port
)
+
"/nudm-ueau/v1/"
+
supi
+
"/security-information/generate-auth-data"
;
Logger
::
ausf_server
().
debug
(
"UDM's URI %s"
,
udmUri
.
c_str
());
M
ethod
=
"POST"
;
m
ethod
=
"POST"
;
// form udm request body AuthInfo
nlohmann
::
json
AuthInfo
=
...
...
@@ -169,16 +169,16 @@ void ausf_app::handle_ue_authentications(
}
// Send request to UDM
ausf_client_inst
->
curl_http_client
(
udmUri
,
Method
,
AuthInfo
.
dump
(),
R
esponse
);
ausf_client_inst
->
curl_http_client
(
udmUri
,
method
,
AuthInfo
.
dump
(),
r
esponse
);
Logger
::
ausf_server
().
error
(
"Response from UDM: %s"
,
R
esponse
.
c_str
());
Logger
::
ausf_server
().
error
(
"Response from UDM: %s"
,
r
esponse
.
c_str
());
ProblemDetails
problemDetails
;
nlohmann
::
json
problemDetails_json
=
{};
nlohmann
::
json
response_data
=
{};
try
{
response_data
=
nlohmann
::
json
::
parse
(
R
esponse
.
c_str
());
response_data
=
nlohmann
::
json
::
parse
(
r
esponse
.
c_str
());
}
catch
(
nlohmann
::
json
::
exception
&
e
)
{
Logger
::
ausf_server
().
info
(
"Could not Parse Json content from UDM response"
);
...
...
@@ -429,9 +429,8 @@ void ausf_app::handle_ue_authentications_confirmation(
confirmResponse
.
setSupi
(
sc
->
supi_ausf
);
}
// Send authResult to UDM
// send authentication result info
std
::
string
udmUri
,
Method
,
Response
;
// Send authResult to UDM (authentication result info)
std
::
string
udmUri
,
method
,
response
;
udmUri
=
"http://"
+
std
::
string
(
inet_ntoa
(
*
((
struct
in_addr
*
)
&
ausf_cfg
.
udm_addr
.
ipv4_addr
)))
+
...
...
@@ -439,7 +438,7 @@ void ausf_app::handle_ue_authentications_confirmation(
sc
->
supi_ausf
+
"/auth-events"
;
cout
<<
udmUri
.
c_str
()
<<
endl
;
Logger
::
ausf_server
().
debug
(
"UDM's URI: %s"
,
udmUri
.
c_str
());
M
ethod
=
"POST"
;
m
ethod
=
"POST"
;
// form request body
nlohmann
::
json
confirmResultInfo
=
{};
...
...
@@ -461,7 +460,7 @@ void ausf_app::handle_ue_authentications_confirmation(
Logger
::
ausf_server
().
debug
(
"confirmResultInfo: %s"
,
confirmResultInfo
.
dump
().
c_str
());
ausf_client_inst
->
curl_http_client
(
udmUri
,
Method
,
confirmResultInfo
.
dump
(),
R
esponse
);
udmUri
,
method
,
confirmResultInfo
.
dump
(),
r
esponse
);
}
}
...
...
src/ausf_app/ausf_app.hpp
View file @
d9138e8f
...
...
@@ -95,14 +95,6 @@ class ausf_app {
const
std
::
string
&
contextId
,
std
::
shared_ptr
<
security_context
>
sc
);
private:
/* AUSF_AV_s ausf_av_s;
// stored temporarily
uint8_t XRES_STAR[16]; // store xres*
std::string SUPI_AUSF; // store supi
std::string AUTH_TYPE; // store authType
std::string SERVING_NN; // store serving network name
std::string KAUSF_TMP; // store Kausf(string)
*/
std
::
map
<
supi64_t
,
std
::
shared_ptr
<
security_context
>>
imsi2security_context
;
mutable
std
::
shared_mutex
m_imsi2security_context
;
...
...
src/ausf_app/ausf_client.cpp
View file @
d9138e8f
...
...
@@ -66,9 +66,9 @@ ausf_client::~ausf_client() {
//------------------------------------------------------------------------------
void
ausf_client
::
curl_http_client
(
std
::
string
remoteUri
,
std
::
string
M
ethod
,
std
::
string
msgBody
,
std
::
string
&
R
esponse
)
{
Logger
::
ausf_
server
().
info
(
"Send HTTP message with body %s"
,
msgBody
.
c_str
());
std
::
string
remoteUri
,
std
::
string
m
ethod
,
std
::
string
msgBody
,
std
::
string
&
r
esponse
)
{
Logger
::
ausf_
app
().
info
(
"Send HTTP message with body %s"
,
msgBody
.
c_str
());
uint32_t
str_len
=
msgBody
.
length
();
char
*
body_data
=
(
char
*
)
malloc
(
str_len
+
1
);
...
...
@@ -81,30 +81,32 @@ void ausf_client::curl_http_client(
if
(
curl
)
{
CURLcode
res
=
{};
struct
curl_slist
*
headers
=
nullptr
;
if
(
!
Method
.
compare
(
"POST"
)
||
!
Method
.
compare
(
"PUT"
)
||
!
Method
.
compare
(
"PATCH"
))
{
if
(
(
method
.
compare
(
"POST"
)
==
0
)
or
(
method
.
compare
(
"PUT"
)
==
0
)
or
(
method
.
compare
(
"PATCH"
)
==
0
))
{
std
::
string
content_type
=
"Content-Type: application/json"
;
headers
=
curl_slist_append
(
headers
,
content_type
.
c_str
());
curl_easy_setopt
(
curl
,
CURLOPT_HTTPHEADER
,
headers
);
}
curl_easy_setopt
(
curl
,
CURLOPT_URL
,
remoteUri
.
c_str
());
if
(
!
Method
.
compare
(
"POST"
)
)
if
(
method
.
compare
(
"POST"
)
==
0
)
curl_easy_setopt
(
curl
,
CURLOPT_HTTPPOST
,
1
);
else
if
(
!
Method
.
compare
(
"PUT"
)
)
else
if
(
method
.
compare
(
"PUT"
)
==
0
)
curl_easy_setopt
(
curl
,
CURLOPT_CUSTOMREQUEST
,
"PUT"
);
else
if
(
!
Method
.
compare
(
"DELETE"
)
)
else
if
(
method
.
compare
(
"DELETE"
)
==
0
)
curl_easy_setopt
(
curl
,
CURLOPT_CUSTOMREQUEST
,
"DELETE"
);
else
if
(
!
Method
.
compare
(
"PATCH"
)
)
else
if
(
method
.
compare
(
"PATCH"
)
==
0
)
curl_easy_setopt
(
curl
,
CURLOPT_CUSTOMREQUEST
,
"PATCH"
);
else
curl_easy_setopt
(
curl
,
CURLOPT_HTTPGET
,
1
);
curl_easy_setopt
(
curl
,
CURLOPT_TIMEOUT_MS
,
CURL_TIMEOUT_MS
);
curl_easy_setopt
(
curl
,
CURLOPT_TCP_KEEPALIVE
,
1
);
curl_easy_setopt
(
curl
,
CURLOPT_INTERFACE
,
ausf_cfg
.
sbi
.
if_name
.
c_str
());
Logger
::
ausf_
server
().
info
(
"
[CURL] r
equest sent by interface "
+
ausf_cfg
.
sbi
.
if_name
);
Logger
::
ausf_
app
().
info
(
"
R
equest sent by interface "
+
ausf_cfg
.
sbi
.
if_name
);
//
R
esponse information.
//
r
esponse information.
long
httpCode
=
{
0
};
std
::
unique_ptr
<
std
::
string
>
httpData
(
new
std
::
string
());
std
::
unique_ptr
<
std
::
string
>
httpHeaderData
(
new
std
::
string
());
...
...
@@ -113,8 +115,9 @@ void ausf_client::curl_http_client(
curl_easy_setopt
(
curl
,
CURLOPT_WRITEFUNCTION
,
&
callback
);
curl_easy_setopt
(
curl
,
CURLOPT_WRITEDATA
,
httpData
.
get
());
curl_easy_setopt
(
curl
,
CURLOPT_HEADERDATA
,
httpHeaderData
.
get
());
if
(
!
Method
.
compare
(
"POST"
)
||
!
Method
.
compare
(
"PUT"
)
||
!
Method
.
compare
(
"PATCH"
))
{
if
((
method
.
compare
(
"POST"
)
==
0
)
or
(
method
.
compare
(
"PUT"
)
==
0
)
or
(
method
.
compare
(
"PATCH"
)
==
0
))
{
curl_easy_setopt
(
curl
,
CURLOPT_POSTFIELDSIZE
,
msgBody
.
length
());
curl_easy_setopt
(
curl
,
CURLOPT_POSTFIELDS
,
body_data
);
}
...
...
@@ -126,10 +129,10 @@ void ausf_client::curl_http_client(
std
::
string
json_data_response
=
""
;
std
::
string
resMsg
=
""
;
bool
is_response_ok
=
true
;
Logger
::
ausf_
server
().
info
(
"Get response with httpcode (%d)"
,
httpCode
);
Logger
::
ausf_
app
().
info
(
"Get response with httpcode (%d)"
,
httpCode
);
if
(
httpCode
==
0
)
{
Logger
::
ausf_
server
().
info
(
Logger
::
ausf_
app
().
info
(
"Cannot get response when calling %s"
,
remoteUri
.
c_str
());
// free curl before returning
curl_slist_free_all
(
headers
);
...
...
@@ -139,67 +142,37 @@ void ausf_client::curl_http_client(
nlohmann
::
json
response_data
=
{};
if
(
httpCode
!=
200
&&
httpCode
!=
201
&&
httpCode
!=
204
)
{
if
(
httpCode
!=
200
&&
httpCode
!=
201
&&
httpCode
!=
204
)
{
// TODO: remove hardcoded values
is_response_ok
=
false
;
if
(
response
.
size
()
<
1
)
{
Logger
::
ausf_
server
().
info
(
"There's no content in the response"
);
Logger
::
ausf_
app
().
info
(
"There's no content in the response"
);
// TODO: send context response error
return
;
}
Logger
::
ausf_server
().
info
(
"Wrong response code"
);
Logger
::
ausf_app
().
warn
(
"Receive response with Http Code %d"
,
httpCode
);
return
;
}
else
{
// httpCode = 200 || httpCode = 201 || httpCode = 204
/*
//store location of the created context
std::string header_response = *httpHeaderData.get();
std::string CRLF = "\r\n";
std::size_t location_pos = header_response.find("Location");
if (location_pos != std::string::npos)
{
std::size_t crlf_pos = header_response.find(CRLF, location_pos);
if (crlf_pos != std::string::npos)
{
std::string location = header_response.substr(location_pos + 10,
crlf_pos - (location_pos + 10)); printf("Location of the created SMF
context: %s", location.c_str());
}
}
try
{
response_data = nlohmann::json::parse(response);
}
catch (nlohmann::json::exception &e)
{
printf("Could not get Json content from the response");
//Set the default Cause
response_data["error"]["cause"] = "504 Gateway Timeout";
}*/
Response
=
*
httpData
.
get
();
response
=
*
httpData
.
get
();
}
if
(
!
is_response_ok
)
{
try
{
response_data
=
nlohmann
::
json
::
parse
(
json_data_response
);
}
catch
(
nlohmann
::
json
::
exception
&
e
)
{
Logger
::
ausf_server
().
info
(
"Could not get Json content from the response"
);
Logger
::
ausf_app
().
info
(
"Could not get Json content from the response"
);
// Set the default Cause
response_data
[
"error"
][
"cause"
]
=
"504 Gateway Timeout"
;
}
Logger
::
ausf_
server
().
info
(
Logger
::
ausf_
app
().
info
(
"Get response with jsonData: %s"
,
json_data_response
.
c_str
());
std
::
string
cause
=
response_data
[
"error"
][
"cause"
];
Logger
::
ausf_
server
().
info
(
"Call Network Function services failure"
);
Logger
::
ausf_
server
().
info
(
"Cause value: %s"
,
cause
.
c_str
());
Logger
::
ausf_
app
().
info
(
"Call Network Function services failure"
);
Logger
::
ausf_
app
().
info
(
"Cause value: %s"
,
cause
.
c_str
());
}
curl_slist_free_all
(
headers
);
curl_easy_cleanup
(
curl
);
...
...
src/ausf_app/ausf_client.hpp
View file @
d9138e8f
...
...
@@ -50,8 +50,8 @@ class ausf_client {
ausf_client
(
ausf_client
const
&
)
=
delete
;
void
curl_http_client
(
std
::
string
remoteUri
,
std
::
string
M
ethod
,
std
::
string
msgBody
,
std
::
string
&
R
esponse
);
std
::
string
remoteUri
,
std
::
string
m
ethod
,
std
::
string
msgBody
,
std
::
string
&
r
esponse
);
};
}
// namespace app
}
// namespace ausf
...
...
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