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
b561323c
Commit
b561323c
authored
Sep 08, 2021
by
wangyongshou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add curl http send
parent
b3b67fbe
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
82 deletions
+86
-82
src/smf_app/smf_config.cpp
src/smf_app/smf_config.cpp
+6
-6
src/smf_app/smf_procedure.cpp
src/smf_app/smf_procedure.cpp
+80
-76
No files found.
src/smf_app/smf_config.cpp
View file @
b561323c
...
...
@@ -632,21 +632,21 @@ int smf_config::load(const string& config_file) {
}
udm_addr
.
api_version
=
udm_api_version
;
//AGENT
const
Setting
&
agent_cfg
=
smf_cfg
[
SMF_CONFIG_STRING_AGENT
];
//AGENT
const
Setting
&
agent_cfg
=
smf_cfg
[
SMF_CONFIG_STRING_AGENT
];
unsigned
int
agent_enable
=
0
;
unsigned
int
agent_enable
=
0
;
std
::
string
agent_url
;
//enable
if
(
!
(
agent_cfg
.
lookupValue
(
SMF_CONFIG_STRING_AGENT_ENABLE
,
agent_enable
)))
{
//enable
if
(
!
(
agent_cfg
.
lookupValue
(
SMF_CONFIG_STRING_AGENT_ENABLE
,
agent_enable
)))
{
Logger
::
smf_app
().
error
(
SMF_CONFIG_STRING_AGENT_ENABLE
"failed"
);
throw
(
SMF_CONFIG_STRING_AGENT_ENABLE
"failed"
);
}
agent
.
enable
=
agent_enable
;
//URL
if
(
!
(
agent_cfg
.
lookupValue
(
if
(
!
(
agent_cfg
.
lookupValue
(
SMF_CONFIG_STRING_AGENT_URL
,
agent_url
)))
{
Logger
::
smf_app
().
error
(
SMF_CONFIG_STRING_AGENT_URL
"failed"
);
throw
(
SMF_CONFIG_STRING_AGENT_URL
"failed"
);
...
...
src/smf_app/smf_procedure.cpp
View file @
b561323c
...
...
@@ -513,84 +513,88 @@ void session_create_sm_context_procedure::handle_itti_msg(
n11_triggered_pending
->
get_msg_name
());
}
if
(
smf_cfg
.
agent
.
enable
)
{
//add it to nwdaf->agent in 20210906
nlohmann
::
json
smf_agent_json_data
=
{};
smf_agent_json_data
[
"supi"
]
=
supi_str
.
c_str
();
struct
in_addr
ue_addr
=
n11_triggered_pending
->
res
.
get_paa
().
ipv4_address
;
smf_agent_json_data
[
"adIpv4Addr"
]
=
(
char
*
)
inet_ntoa
(
ue_addr
);
smf_agent_json_data
[
"pduSeId"
]
=
n11_triggered_pending
->
res
.
get_pdu_session_id
();
if
(
n11_triggered_pending
->
res
.
get_pdu_session_type
()
==
PDU_SESSION_TYPE_E_IPV4
||
n11_triggered_pending
->
res
.
get_pdu_session_type
()
==
PDU_SESSION_TYPE_E_IPV4V6
)
smf_agent_json_data
[
"pduSessType"
]
=
"Ipv4"
;
//If no DNN information from UE, set to default value
std
::
string
dnn
=
n11_trigger
.
get
()
->
req
.
get_dnn
();
if
(
dnn
.
length
()
==
0
)
{
dnn
=
smf_cfg
.
get_default_dnn
();
}
smf_agent_json_data
[
"dnn"
]
=
dnn
.
c_str
();
std
::
string
agent_req_data
=
smf_agent_json_data
.
dump
();
std
::
string
agent_http_url
=
"http://192.168.2.170:9999"
;
unsigned
char
*
data
=
(
unsigned
char
*
)
malloc
(
agent_req_data
.
length
()
+
1
);
memset
(
data
,
0
,
agent_req_data
.
length
()
+
1
);
memcpy
((
void
*
)
data
,
(
void
*
)
agent_req_data
.
c_str
(),
agent_req_data
.
length
());
curl_global_init
(
CURL_GLOBAL_ALL
);
CURL
*
curl
=
curl
=
curl_easy_init
();
if
(
curl
)
{
CURLcode
res
=
{};
struct
curl_slist
*
headers
=
nullptr
;
// headers = curl_slist_append(headers, "charsets: utf-8");
headers
=
curl_slist_append
(
headers
,
"content-type: multipart/related; boundary=----Boundary"
);
curl_easy_setopt
(
curl
,
CURLOPT_HTTPHEADER
,
headers
);
curl_easy_setopt
(
curl
,
CURLOPT_URL
,
agent_http_url
.
c_str
());
curl_easy_setopt
(
curl
,
CURLOPT_HTTPGET
,
1
);
curl_easy_setopt
(
curl
,
CURLOPT_TIMEOUT_MS
,
100L
);
// curl_easy_setopt(curl, CURLOPT_INTERFACE, "eno1:amf"); //hardcoded
// Response information.
long
httpCode
=
{
0
};
std
::
unique_ptr
<
std
::
string
>
httpData
(
new
std
::
string
());
curl_easy_setopt
(
curl
,
CURLOPT_WRITEFUNCTION
,
&
agent_http_callback
);
curl_easy_setopt
(
curl
,
CURLOPT_WRITEDATA
,
httpData
.
get
());
curl_easy_setopt
(
curl
,
CURLOPT_POSTFIELDSIZE
,
agent_req_data
.
length
());
curl_easy_setopt
(
curl
,
CURLOPT_POSTFIELDS
,
data
);
res
=
curl_easy_perform
(
curl
);
curl_easy_getinfo
(
curl
,
CURLINFO_RESPONSE_CODE
,
&
httpCode
);
// get cause from the response
nlohmann
::
json
response_data
;
try
{
response_data
=
nlohmann
::
json
::
parse
(
*
httpData
.
get
());
}
catch
(
nlohmann
::
json
::
exception
&
e
)
{
std
::
cout
<<
"Could not get json data from the response"
<<
std
::
endl
;
}
std
::
cout
<<
"[AGENT ] , response from "
"AGENT, Http Code "
<<
httpCode
<<
std
::
endl
;
curl_easy_cleanup
(
curl
);
}
curl_global_cleanup
();
free
(
data
);
//add it to nwdaf->agent in 20210906
nlohmann
::
json
smf_agent_json_data
=
{};
smf_agent_json_data
[
"supi"
]
=
supi_str
.
c_str
();
struct
in_addr
ue_addr
=
n11_triggered_pending
->
res
.
get_paa
().
ipv4_address
;
smf_agent_json_data
[
"adIpv4Addr"
]
=
(
char
*
)
inet_ntoa
(
ue_addr
);
smf_agent_json_data
[
"pduSeId"
]
=
n11_triggered_pending
->
res
.
get_pdu_session_id
();
if
(
n11_triggered_pending
->
res
.
get_pdu_session_type
()
==
PDU_SESSION_TYPE_E_IPV4
||
n11_triggered_pending
->
res
.
get_pdu_session_type
()
==
PDU_SESSION_TYPE_E_IPV4V6
)
smf_agent_json_data
[
"pduSessType"
]
=
"Ipv4"
;
//If no DNN information from UE, set to default value
std
::
string
dnn
=
n11_trigger
.
get
()
->
req
.
get_dnn
();
if
(
dnn
.
length
()
==
0
)
{
dnn
=
smf_cfg
.
get_default_dnn
();
}
smf_agent_json_data
[
"dnn"
]
=
dnn
.
c_str
();
std
::
string
agent_req_data
=
smf_agent_json_data
.
dump
();
unsigned
char
*
data
=
(
unsigned
char
*
)
malloc
(
agent_req_data
.
length
()
+
1
);
if
(
!
data
)
return
;
memset
(
data
,
0
,
agent_req_data
.
length
()
+
1
);
memcpy
((
void
*
)
data
,
(
void
*
)
agent_req_data
.
c_str
(),
agent_req_data
.
length
());
curl_global_init
(
CURL_GLOBAL_ALL
);
CURL
*
curl
=
curl
=
curl_easy_init
();
if
(
curl
)
{
CURLcode
res
=
{};
struct
curl_slist
*
headers
=
nullptr
;
// headers = curl_slist_append(headers, "charsets: utf-8");
headers
=
curl_slist_append
(
headers
,
"Content-Type: application/json"
);
curl_easy_setopt
(
curl
,
CURLOPT_HTTPHEADER
,
headers
);
curl_easy_setopt
(
curl
,
CURLOPT_URL
,
smf_cfg
.
agent
.
url
.
c_str
());
curl_easy_setopt
(
curl
,
CURLOPT_HTTPGET
,
1
);
curl_easy_setopt
(
curl
,
CURLOPT_TIMEOUT_MS
,
100L
);
// Response information.
long
httpCode
=
{
0
};
std
::
unique_ptr
<
std
::
string
>
httpData
(
new
std
::
string
());
curl_easy_setopt
(
curl
,
CURLOPT_WRITEFUNCTION
,
&
agent_http_callback
);
curl_easy_setopt
(
curl
,
CURLOPT_WRITEDATA
,
httpData
.
get
());
curl_easy_setopt
(
curl
,
CURLOPT_POSTFIELDSIZE
,
agent_req_data
.
length
());
curl_easy_setopt
(
curl
,
CURLOPT_POSTFIELDS
,
data
);
res
=
curl_easy_perform
(
curl
);
Logger
::
smf_app
().
info
(
"SMF->AGENT data:%s"
,
data
);
curl_easy_getinfo
(
curl
,
CURLINFO_RESPONSE_CODE
,
&
httpCode
);
// get cause from the response
nlohmann
::
json
response_data
;
try
{
response_data
=
nlohmann
::
json
::
parse
(
*
httpData
.
get
());
}
catch
(
nlohmann
::
json
::
exception
&
e
)
{
std
::
cout
<<
"Could not get json data from the response"
<<
std
::
endl
;
}
std
::
cout
<<
"[AGENT ] , response from "
"AGENT, Http Code "
<<
httpCode
<<
std
::
endl
;
curl_easy_cleanup
(
curl
);
}
curl_global_cleanup
();
free
(
data
);
}
}
...
...
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