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
ec8c6d21
Commit
ec8c6d21
authored
Mar 11, 2020
by
Tien-Thinh Nguyen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix issue for API server to deal with multipart/related message
parent
bd99e507
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
263 additions
and
84 deletions
+263
-84
src/api-server/api/IndividualSMContextApi.cpp
src/api-server/api/IndividualSMContextApi.cpp
+57
-14
src/api-server/api/IndividualSMContextApi.h
src/api-server/api/IndividualSMContextApi.h
+29
-2
src/api-server/api/SMContextsCollectionApi.cpp
src/api-server/api/SMContextsCollectionApi.cpp
+70
-60
src/api-server/api/SMContextsCollectionApi.h
src/api-server/api/SMContextsCollectionApi.h
+22
-0
src/api-server/impl/IndividualSMContextApiImpl.cpp
src/api-server/impl/IndividualSMContextApiImpl.cpp
+4
-7
src/api-server/impl/IndividualSMContextApiImpl.h
src/api-server/impl/IndividualSMContextApiImpl.h
+20
-0
src/api-server/impl/SMContextsCollectionApiImpl.h
src/api-server/impl/SMContextsCollectionApiImpl.h
+20
-0
src/api-server/smf-api-server.cpp
src/api-server/smf-api-server.cpp
+20
-1
src/api-server/smf-api-server.h
src/api-server/smf-api-server.h
+21
-0
No files found.
src/api-server/api/IndividualSMContextApi.cpp
View file @
ec8c6d21
...
...
@@ -10,8 +10,29 @@
* Do not edit the class manually.
*/
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#include "IndividualSMContextApi.h"
#include "SmContextReleaseMessage.h"
#include "logger.hpp"
#include "Helpers.h"
extern
"C"
{
...
...
@@ -55,6 +76,7 @@ void IndividualSMContextApi::setupRoutes() {
void
IndividualSMContextApi
::
release_sm_context_handler
(
const
Pistache
::
Rest
::
Request
&
request
,
Pistache
::
Http
::
ResponseWriter
response
)
{
//TODO: to be updated as update_sm_context_handler
Logger
::
smf_api_server
().
info
(
"Received a Nsmf_PDUSession_UpdateSMContext: PDU Session Release request from AMF"
);
Logger
::
smf_api_server
().
debug
(
"Request body: %s
\n
"
,
request
.
body
().
c_str
());
SmContextReleaseMessage
smContextReleaseMessage
;
...
...
@@ -139,10 +161,12 @@ void IndividualSMContextApi::update_sm_context_handler(const Pistache::Rest::Req
Logger
::
smf_api_server
().
info
(
"Received a SM context update request from AMF"
);
Logger
::
smf_api_server
().
debug
(
"Request body: %s
\n
"
,
request
.
body
().
c_str
());
SmContextUpdateMessage
smContextUpdateMessage
;
// Getting the path params
auto
smContextRef
=
request
.
param
(
":smContextRef"
).
as
<
std
::
string
>
();
std
::
size_t
found
=
request
.
body
().
find
(
"Content-Type"
);
std
::
string
boundary_str
=
request
.
body
().
substr
(
2
,
found
-
4
);
Logger
::
smf_api_server
().
debug
(
"Boundary: %s"
,
boundary_str
.
c_str
());
SmContextUpdateMessage
smContextUpdateMessage
;
//step 1. use multipartparser to decode the request
multipartparser_callbacks_init
(
&
g_callbacks
);
...
...
@@ -157,19 +181,33 @@ void IndividualSMContextApi::update_sm_context_handler(const Pistache::Rest::Req
multipartparser
parser
;
init_globals
();
multipartparser_init
(
&
parser
,
BOUNDARY
);
if
((
multipartparser_execute
(
&
parser
,
&
g_callbacks
,
request
.
body
().
c_str
(),
strlen
(
request
.
body
().
c_str
()))
!=
strlen
(
request
.
body
().
c_str
()))
or
(
!
g_body_begin_called
)){
response
.
send
(
Pistache
::
Http
::
Code
::
Bad_Request
,
""
);
return
;
multipartparser_init
(
&
parser
,
reinterpret_cast
<
const
char
*>
(
boundary_str
.
c_str
()));
unsigned
int
str_len
=
request
.
body
().
length
();
unsigned
char
*
data
=
(
unsigned
char
*
)
malloc
(
str_len
+
1
);
memset
(
data
,
0
,
str_len
+
1
);
memcpy
((
void
*
)
data
,
(
void
*
)
request
.
body
().
c_str
(),
str_len
);
//if ((multipartparser_execute(&parser, &g_callbacks, request.body().c_str(), strlen(request.body().c_str())) != strlen(request.body().c_str())) or (!g_body_begin_called)){
if
((
multipartparser_execute
(
&
parser
,
&
g_callbacks
,
reinterpret_cast
<
const
char
*>
(
data
),
str_len
)
!=
strlen
(
request
.
body
().
c_str
()))
or
(
!
g_body_begin_called
)){
Logger
::
smf_api_server
().
warn
(
"The received message can not be parsed properly!"
);
//TODO: fix this issue
//response.send(Pistache::Http::Code::Bad_Request, "");
//return;
}
free
(
data
);
data
=
nullptr
;
uint8_t
size
=
g_parts
.
size
();
Logger
::
smf_api_server
().
debug
(
"Number of g_parts %d"
,
g_parts
.
size
());
part
p0
=
g_parts
.
front
();
g_parts
.
pop_front
();
Logger
::
smf_api_server
().
debug
(
"Request body, part 1:
\n
%s"
,
p0
.
body
.
c_str
());
Logger
::
smf_api_server
().
debug
(
"Request body, part 1: %s"
,
p0
.
body
.
c_str
());
part
p1
=
{};
if
(
g_parts
.
size
()
>=
2
){
if
(
size
>
1
){
p1
=
g_parts
.
front
();
g_parts
.
pop_front
();
Logger
::
smf_api_server
().
debug
(
"Request body, part 2:
\n
%s"
,
p1
.
body
.
c_str
());
Logger
::
smf_api_server
().
debug
(
"Request body, part 2:
%s (%d bytes)"
,
p1
.
body
.
c_str
(),
p1
.
body
.
length
());
//part p2 = g_parts.front(); g_parts.pop_front();
//Logger::smf_api_server().debug("Request body, part 3: \n %s",p2.body.c_str());
}
...
...
@@ -180,28 +218,33 @@ void IndividualSMContextApi::update_sm_context_handler(const Pistache::Rest::Req
nlohmann
::
json
::
parse
(
p0
.
body
.
c_str
()).
get_to
(
smContextUpdateData
);
smContextUpdateMessage
.
setJsonData
(
smContextUpdateData
);
if
(
g_parts
.
size
()
>=
2
){
if
(
size
>
1
){
if
(
smContextUpdateData
.
n2SmInfoIsSet
()){
//N2 SM (for Session establishment, or for session modification)
smContextUpdateMessage
.
setBinaryDataN2SmInformation
(
p1
.
body
.
c_str
());
Logger
::
smf_api_server
().
debug
(
"N2 SM information is set"
);
smContextUpdateMessage
.
setBinaryDataN2SmInformation
(
p1
.
body
);
}
if
(
smContextUpdateData
.
n1SmMsgIsSet
()){
//N1 SM (for session modification, UE-initiated)
Logger
::
smf_api_server
().
debug
(
"N1 SM message is set"
);
smContextUpdateMessage
.
setBinaryDataN1SmMessage
(
p1
.
body
.
c_str
());
}
}
// Getting the path params
auto
smContextRef
=
request
.
param
(
":smContextRef"
).
as
<
std
::
string
>
();
this
->
update_sm_context
(
smContextRef
,
smContextUpdateMessage
,
response
);
}
catch
(
nlohmann
::
detail
::
exception
&
e
)
{
//send a 400 error
Logger
::
smf_api_server
().
warn
(
"Error in parsing json, send a msg with a 400 error code to AMF"
);
response
.
send
(
Pistache
::
Http
::
Code
::
Bad_Request
,
e
.
what
());
return
;
}
catch
(
std
::
exception
&
e
)
{
//send a 500 error
Logger
::
smf_api_server
().
warn
(
"Send a msg with a 500 error code to AMF"
);
response
.
send
(
Pistache
::
Http
::
Code
::
Internal_Server_Error
,
e
.
what
());
return
;
}
}
void
IndividualSMContextApi
::
individual_sm_context_api_default_handler
(
const
Pistache
::
Rest
::
Request
&
,
Pistache
::
Http
::
ResponseWriter
response
)
{
...
...
src/api-server/api/IndividualSMContextApi.h
View file @
ec8c6d21
...
...
@@ -15,6 +15,29 @@
*
*/
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#ifndef IndividualSMContextApi_H_
#define IndividualSMContextApi_H_
...
...
@@ -34,7 +57,11 @@
#include "SmContextUpdatedData.h"
#include "SmContextUpdateMessage.h"
#include "SmContextReleaseMessage.h"
#include <string>
#include "SmContextMessage.h"
#include "SmContextCreateError.h"
#include "SmContextCreatedData.h"
namespace
oai
{
namespace
smf_server
{
...
...
@@ -48,7 +75,7 @@ public:
virtual
~
IndividualSMContextApi
()
{}
void
init
();
const
std
::
string
base
=
"/nsmf-pdusession/v
1
"
;
const
std
::
string
base
=
"/nsmf-pdusession/v
2
"
;
private:
void
setupRoutes
();
...
...
src/api-server/api/SMContextsCollectionApi.cpp
View file @
ec8c6d21
...
...
@@ -74,6 +74,11 @@ void SMContextsCollectionApi::post_sm_contexts_handler(const Pistache::Rest::Req
Logger
::
smf_api_server
().
info
(
"Received a SM context create request from AMF"
);
Logger
::
smf_api_server
().
debug
(
"Request body: %s
\n
"
,
request
.
body
().
c_str
());
std
::
size_t
found
=
request
.
body
().
find
(
"Content-Type"
);
std
::
string
boundary_str
=
request
.
body
().
substr
(
2
,
found
-
4
);
Logger
::
smf_api_server
().
debug
(
"Boundary: %s"
,
boundary_str
.
c_str
());
SmContextMessage
smContextMessage
;
SmContextCreateData
smContextCreateData
;
...
...
@@ -90,22 +95,26 @@ void SMContextsCollectionApi::post_sm_contexts_handler(const Pistache::Rest::Req
multipartparser
parser
;
init_globals
();
multipartparser_init
(
&
parser
,
BOUNDARY
);
multipartparser_init
(
&
parser
,
reinterpret_cast
<
const
char
*>
(
boundary_str
.
c_str
())
);
if
((
multipartparser_execute
(
&
parser
,
&
g_callbacks
,
request
.
body
().
c_str
(),
strlen
(
request
.
body
().
c_str
()))
!=
strlen
(
request
.
body
().
c_str
()))
or
(
!
g_body_begin_called
)){
response
.
send
(
Pistache
::
Http
::
Code
::
Bad_Request
,
""
);
return
;
Logger
::
smf_api_server
().
warn
(
"The received message can not be parsed properly!"
);
//TODO: fix this issue
//response.send(Pistache::Http::Code::Bad_Request, "");
//return;
}
Logger
::
smf_api_server
().
debug
(
"Number of g_parts %d"
,
g_parts
.
size
());
//at least 2 parts for Json data and N1 (+ N2)
if
(
g_parts
.
size
()
<
2
){
response
.
send
(
Pistache
::
Http
::
Code
::
Bad_Request
,
""
);
return
;
}
part
p0
=
g_parts
.
front
();
g_parts
.
pop_front
();
Logger
::
smf_api_server
().
debug
(
"Request body, part 1:
\n
%s"
,
p0
.
body
.
c_str
());
part
p1
=
g_parts
.
front
();
g_parts
.
pop_front
();
Logger
::
smf_api_server
().
debug
(
"Request body, part 2:
\n
%s"
,
p1
.
body
.
c_str
());
if
(
g_parts
.
size
()
==
3
)
{
if
(
g_parts
.
size
()
>
0
)
{
part
p2
=
g_parts
.
front
();
g_parts
.
pop_front
();
Logger
::
smf_api_server
().
debug
(
"Request body, part 3:
\n
%s"
,
p2
.
body
.
c_str
());
}
...
...
@@ -118,6 +127,7 @@ void SMContextsCollectionApi::post_sm_contexts_handler(const Pistache::Rest::Req
this
->
post_sm_contexts
(
smContextMessage
,
response
);
}
catch
(
nlohmann
::
detail
::
exception
&
e
)
{
//send a 400 error
Logger
::
smf_api_server
().
warn
(
"Can not parse the json data!"
);
response
.
send
(
Pistache
::
Http
::
Code
::
Bad_Request
,
e
.
what
());
return
;
}
catch
(
std
::
exception
&
e
)
{
...
...
src/api-server/api/SMContextsCollectionApi.h
View file @
ec8c6d21
...
...
@@ -15,6 +15,28 @@
*
*/
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#ifndef SMContextsCollectionApi_H_
#define SMContextsCollectionApi_H_
...
...
src/api-server/impl/IndividualSMContextApiImpl.cpp
View file @
ec8c6d21
...
...
@@ -45,6 +45,8 @@ IndividualSMContextApiImpl::IndividualSMContextApiImpl(std::shared_ptr<Pistache:
{
}
void
IndividualSMContextApiImpl
::
release_sm_context
(
const
std
::
string
&
smContextRef
,
const
SmContextReleaseMessage
&
smContextReleaseMessage
,
Pistache
::
Http
::
ResponseWriter
&
response
)
{
//TODO: to be updated as update_sm_context_handler
Logger
::
smf_api_server
().
info
(
"release_sm_context..."
);
//handle Nsmf_PDUSession_UpdateSMContext Request
...
...
@@ -92,21 +94,16 @@ void IndividualSMContextApiImpl::update_sm_context(const std::string &smContextR
if
(
smContextUpdateData
.
n2SmInfoIsSet
()){
//N2 SM (for Session establishment)
std
::
string
n2_sm_information
=
smContextUpdateMessage
.
getBinaryDataN2SmInformation
();
//std::string n2_sm_information = (smContextUpdateData.getN2SmInfo()).getContentId();
std
::
string
n2_sm_msg_hex
;
m_smf_app
->
convert_string_2_hex
(
n2_sm_information
,
n2_sm_msg_hex
);
Logger
::
smf_api_server
().
debug
(
"smContextMessage, n2 sm information %s"
,
n2_sm_information
.
c_str
());
std
::
string
n2_sm_info_type
=
smContextUpdateData
.
getN2SmInfoType
();
sm_context_req_msg
.
set_n2_sm_information
(
n2_sm_
msg_hex
);
sm_context_req_msg
.
set_n2_sm_information
(
n2_sm_
information
);
sm_context_req_msg
.
set_n2_sm_info_type
(
n2_sm_info_type
);
}
else
if
(
smContextUpdateData
.
n1SmMsgIsSet
()){
//N1 SM (for session modification)
std
::
string
n1_sm_message
=
smContextUpdateMessage
.
getBinaryDataN1SmMessage
();
std
::
string
n1_sm_msg_hex
;
m_smf_app
->
convert_string_2_hex
(
n1_sm_message
,
n1_sm_msg_hex
);
Logger
::
smf_api_server
().
debug
(
"smContextMessage, n1 sm message %s"
,
n1_sm_message
.
c_str
());
sm_context_req_msg
.
set_n1_sm_message
(
n1_sm_m
sg_hex
);
sm_context_req_msg
.
set_n1_sm_message
(
n1_sm_m
essage
);
}
//Step 2. TODO: initialize necessary values for sm context req from smContextUpdateData
...
...
src/api-server/impl/IndividualSMContextApiImpl.h
View file @
ec8c6d21
...
...
@@ -15,6 +15,26 @@
*
*
*/
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#ifndef INDIVIDUAL_SM_CONTEXT_API_IMPL_H_
#define INDIVIDUAL_SM_CONTEXT_API_IMPL_H_
...
...
src/api-server/impl/SMContextsCollectionApiImpl.h
View file @
ec8c6d21
...
...
@@ -15,6 +15,26 @@
*
*
*/
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#ifndef SM_CONTEXTS_COLLECTION_API_IMPL_H_
#define SM_CONTEXTS_COLLECTION_API_IMPL_H_
...
...
src/api-server/smf-api-server.cpp
View file @
ec8c6d21
...
...
@@ -9,7 +9,26 @@
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#include "pistache/endpoint.h"
#include "pistache/http.h"
...
...
src/api-server/smf-api-server.h
View file @
ec8c6d21
...
...
@@ -10,6 +10,27 @@
* Do not edit the class manually.
*/
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#include "pistache/endpoint.h"
#include "pistache/http.h"
...
...
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