Skip to content
10 changes: 6 additions & 4 deletions lte/gateway/c/core/oai/include/sgw_context_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ sgw_eps_bearer_ctxt_t* sgw_s8_cm_get_eps_bearer_entry(
mme_sgw_tunnel_t* sgw_cm_create_s11_tunnel(teid_t remote_teid,
teid_t local_teid);
magma::lte::oai::S11BearerContext*
sgw_cm_create_bearer_context_information_in_collection(teid_t teid);
sgw_cm_create_bearer_context_information_in_collection(imsi64_t imsi64,
teid_t teid);
magma::proto_map_rc_t sgw_cm_remove_bearer_context_information(teid_t teid,
imsi64_t imsi64);
sgw_eps_bearer_ctxt_t* sgw_cm_create_eps_bearer_ctxt_in_collection(
Expand All @@ -69,10 +70,11 @@ magma::proto_map_rc_t sgw_cm_insert_eps_bearer_ctxt_in_collection(

// Returns SPGW state pointer for given UE indexed by IMSI
magma::lte::oai::S11BearerContext* sgw_cm_get_spgw_context(teid_t teid);
spgw_ue_context_t* spgw_get_ue_context(imsi64_t imsi64);
spgw_ue_context_t* spgw_create_or_get_ue_context(imsi64_t imsi64);
magma::lte::oai::SpgwUeContext* spgw_get_ue_context(imsi64_t imsi64);
magma::lte::oai::SpgwUeContext* spgw_create_or_get_ue_context(imsi64_t imsi64);

status_code_e spgw_update_teid_in_ue_context(imsi64_t imsi64, teid_t teid);
magma::lte::oai::S11BearerContext* spgw_update_teid_in_ue_context(
imsi64_t imsi64, teid_t teid);

magma::proto_map_rc_t sgw_cm_get_eps_bearer_entry(
magma::lte::oai::SgwPdnConnection* const sgw_pdn_connection, ebi_t ebi,
Expand Down
2 changes: 1 addition & 1 deletion lte/gateway/c/core/oai/include/sgw_s8_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ void sgw_free_s11_bearer_context_information(void** ptr);
* state_ue_map
* @param pointer to an object of spgw_ue_context_t
*/
void sgw_free_ue_context(void** ptr);
void sgw_s8_free_ue_context(void** ptr);
4 changes: 2 additions & 2 deletions lte/gateway/c/core/oai/include/spgw_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ typedef struct spgw_ue_context_s {
LIST_HEAD(teid_list_head_s, sgw_s11_teid_s) sgw_s11_teid_list;
} spgw_ue_context_t;

// Map- Key:imsi of uint64_t, Data:spgw_ue_context_s*
typedef magma::proto_map_s<uint64_t, struct spgw_ue_context_s*>
// Map- Key:imsi of uint64_t, Data:magma::lte::oai::SpgwUeContext*
typedef magma::proto_map_s<uint64_t, magma::lte::oai::SpgwUeContext*>
map_uint64_spgw_ue_context_t;

// Map- Key: eps_bearer_id(uint32), Data: SgwEpsBearerContext
Expand Down
4 changes: 2 additions & 2 deletions lte/gateway/c/core/oai/tasks/grpc_service/S8ServiceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ static void convert_proto_msg_to_itti_create_bearer_req(
get_qos_from_proto_msg(request->bearer_context().qos(), &s8_bc->qos);
}
if (request->bearer_context().has_tft()) {
magma::lte::SpgwStateConverter::proto_to_traffic_flow_template(
request->bearer_context().tft(), &s8_bc->tft);
proto_to_traffic_flow_template(request->bearer_context().tft(),
&s8_bc->tft);
}
get_fteid_from_proto_msg(request->bearer_context().user_plane_fteid(),
&s8_bc->pgw_s8_up);
Expand Down
4 changes: 2 additions & 2 deletions lte/gateway/c/core/oai/tasks/sgw/pgw_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ void handle_s5_create_session_request(
new_bearer_ctxt_info_p->sgw_eps_bearer_context();
OAILOG_DEBUG_UE(
LOG_SPGW_APP, sgw_context.imsi64(),
"Handle s5_create_session_request, for context sgw s11 teid, " TEID_FMT
"EPS bearer id %u\n",
"Handle s5_create_session_request, for context sgw s11 teid " TEID_FMT
" EPS bearer id %u\n",
context_teid, eps_bearer_id);

imsi = sgw_context.imsi();
Expand Down
59 changes: 32 additions & 27 deletions lte/gateway/c/core/oai/tasks/sgw/sgw_context_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,18 @@ mme_sgw_tunnel_t* sgw_cm_create_s11_tunnel(teid_t remote_teid,

//-----------------------------------------------------------------------------
magma::lte::oai::S11BearerContext*
sgw_cm_create_bearer_context_information_in_collection(teid_t teid) {
sgw_cm_create_bearer_context_information_in_collection(imsi64_t imsi64,
teid_t teid) {
magma::lte::oai::S11BearerContext* new_bearer_context_information =
new magma::lte::oai::S11BearerContext();
spgw_update_teid_in_ue_context(imsi64, teid);

if (!new_bearer_context_information) {
OAILOG_ERROR_UE(LOG_SPGW_APP, imsi64,
"Failed to create new s_plus_pgw_context in ue context for "
"teid " TEID_FMT,
teid);
OAILOG_FUNC_RETURN(LOG_SPGW_APP, nullptr);
}
/*
* Trying to insert the new tunnel into the map.
* * * * If collision_p is not NULL (0), it means tunnel is already present.
Expand Down Expand Up @@ -199,24 +207,23 @@ magma::proto_map_rc_t sgw_cm_remove_bearer_context_information(
"Failed to free teid from state_teid_map \n");
return magma::PROTO_MAP_REMOVE_KEY_FAILED;
}
spgw_ue_context_t* ue_context_p = nullptr;
magma::lte::oai::SpgwUeContext* ue_context_p = nullptr;
map_uint64_spgw_ue_context_t* spgw_ue_state = get_spgw_ue_state();
if (!spgw_ue_state) {
OAILOG_ERROR_UE(LOG_SPGW_APP, imsi64, "Failed to find spgw_ue_state");
return magma::PROTO_MAP_SEARCH_NO_RESULT;
}
spgw_ue_state->get(imsi64, &ue_context_p);
if (ue_context_p) {
sgw_s11_teid_t* p1 = LIST_FIRST(&(ue_context_p->sgw_s11_teid_list));
while (p1) {
if (p1->sgw_s11_teid == teid) {
LIST_REMOVE(p1, entries);
free_cpp_wrapper(reinterpret_cast<void**>(&p1));
for (auto itr = ue_context_p->s11_bearer_context().begin();
itr != ue_context_p->s11_bearer_context().end(); itr++) {
magma::lte::oai::S11BearerContext spgw_context = *itr;
if (spgw_context.sgw_eps_bearer_context().sgw_teid_s11_s4() == teid) {
ue_context_p->mutable_s11_bearer_context()->erase(itr);
break;
}
p1 = LIST_NEXT(p1, entries);
}
if (LIST_EMPTY(&ue_context_p->sgw_s11_teid_list)) {
if (ue_context_p->s11_bearer_context_size() == 0) {
if (spgw_ue_state->remove(imsi64) != magma::PROTO_MAP_OK) {
OAILOG_ERROR_UE(LOG_SPGW_APP, imsi64,
"Failed to free imsi64 from imsi_ue_context_map \n");
Expand Down Expand Up @@ -332,31 +339,30 @@ magma::proto_map_rc_t sgw_update_eps_bearer_entry(
return (eps_bearer_map.update_val(ebi, bearer_context_p));
}

spgw_ue_context_t* spgw_get_ue_context(imsi64_t imsi64) {
magma::lte::oai::SpgwUeContext* spgw_get_ue_context(imsi64_t imsi64) {
OAILOG_FUNC_IN(LOG_SPGW_APP);
spgw_ue_context_t* ue_context_p = nullptr;
magma::lte::oai::SpgwUeContext* ue_context_p = nullptr;
map_uint64_spgw_ue_context_t* state_ue_map = get_spgw_ue_state();
if (!state_ue_map) {
OAILOG_ERROR(LOG_SPGW_APP, "Failed to find spgw_ue_state");
OAILOG_ERROR(LOG_SPGW_APP, "Failed to find state_ue_map");
OAILOG_FUNC_RETURN(LOG_SPGW_APP, nullptr);
}
state_ue_map->get(imsi64, &ue_context_p);
OAILOG_FUNC_RETURN(LOG_SPGW_APP, ue_context_p);
}

spgw_ue_context_t* spgw_create_or_get_ue_context(imsi64_t imsi64) {
magma::lte::oai::SpgwUeContext* spgw_create_or_get_ue_context(imsi64_t imsi64) {
OAILOG_FUNC_IN(LOG_SPGW_APP);
spgw_ue_context_t* ue_context_p = nullptr;
magma::lte::oai::SpgwUeContext* ue_context_p = nullptr;
map_uint64_spgw_ue_context_t* state_ue_map = get_spgw_ue_state();
if (!state_ue_map) {
OAILOG_ERROR(LOG_SPGW_APP, "Failed to find spgw_ue_state");
OAILOG_ERROR(LOG_SPGW_APP, "Failed to find state_ue_map");
OAILOG_FUNC_RETURN(LOG_SPGW_APP, nullptr);
}
state_ue_map->get(imsi64, &ue_context_p);
if (!ue_context_p) {
ue_context_p = new spgw_ue_context_t();
ue_context_p = new magma::lte::oai::SpgwUeContext();
if (ue_context_p) {
LIST_INIT(&ue_context_p->sgw_s11_teid_list);
state_ue_map->insert(imsi64, ue_context_p);
} else {
OAILOG_ERROR_UE(LOG_SPGW_APP, imsi64,
Expand All @@ -366,22 +372,21 @@ spgw_ue_context_t* spgw_create_or_get_ue_context(imsi64_t imsi64) {
OAILOG_FUNC_RETURN(LOG_SPGW_APP, ue_context_p);
}

status_code_e spgw_update_teid_in_ue_context(imsi64_t imsi64, teid_t teid) {
magma::lte::oai::S11BearerContext* spgw_update_teid_in_ue_context(
imsi64_t imsi64, teid_t teid) {
OAILOG_FUNC_IN(LOG_SPGW_APP);
spgw_ue_context_t* ue_context_p = spgw_create_or_get_ue_context(imsi64);
magma::lte::oai::SpgwUeContext* ue_context_p =
spgw_create_or_get_ue_context(imsi64);
if (!ue_context_p) {
OAILOG_ERROR_UE(LOG_SPGW_APP, imsi64,
"Failed to get UE context for sgw_s11_teid " TEID_FMT "\n",
teid);
OAILOG_FUNC_RETURN(LOG_SPGW_APP, RETURNerror);
OAILOG_FUNC_RETURN(LOG_SPGW_APP, nullptr);
}

sgw_s11_teid_t* sgw_s11_teid_p = new sgw_s11_teid_t();
sgw_s11_teid_p->sgw_s11_teid = teid;
LIST_INSERT_HEAD(&ue_context_p->sgw_s11_teid_list, sgw_s11_teid_p, entries);
OAILOG_DEBUG(LOG_SPGW_APP,
"Inserted sgw_s11_teid to list of teids of UE context" TEID_FMT
"\n",
"Inserted spgw_context to list of S11BearerContext of UE "
"context for sgw_s11_teid " TEID_FMT,
teid);
OAILOG_FUNC_RETURN(LOG_SPGW_APP, RETURNok);
OAILOG_FUNC_RETURN(LOG_SPGW_APP, ue_context_p->add_s11_bearer_context());
}
41 changes: 19 additions & 22 deletions lte/gateway/c/core/oai/tasks/sgw/sgw_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,23 +152,15 @@ status_code_e sgw_handle_s11_create_session_request(
OAILOG_DEBUG_UE(
LOG_SPGW_APP, imsi64,
"Rx CREATE-SESSION-REQUEST MME S11 teid " TEID_FMT
"S-GW S11 teid " TEID_FMT " APN %s EPS bearer Id %d\n",
" S-GW S11 teid " TEID_FMT " APN %s bearer Id %d\n",
new_endpoint_p->remote_teid, new_endpoint_p->local_teid,
session_req_pP->apn,
session_req_pP->bearer_contexts_to_be_created.bearer_contexts[0]
.eps_bearer_id);

if (spgw_update_teid_in_ue_context(imsi64, new_endpoint_p->local_teid) ==
RETURNerror) {
OAILOG_ERROR_UE(LOG_SPGW_APP, imsi64,
"Failed to update sgw_s11_teid" TEID_FMT
" in UE context \n",
new_endpoint_p->local_teid);
OAILOG_FUNC_RETURN(LOG_SPGW_APP, RETURNerror);
}
s_plus_p_gw_eps_bearer_ctxt_info_p =
sgw_cm_create_bearer_context_information_in_collection(
new_endpoint_p->local_teid);
imsi64, new_endpoint_p->local_teid);
if (s_plus_p_gw_eps_bearer_ctxt_info_p) {
/*
* We try to create endpoint for S11 interface. A NULL endpoint means that
Expand Down Expand Up @@ -1297,7 +1289,7 @@ void sgw_handle_release_access_bearers_request(
OAILOG_DEBUG_UE(LOG_SPGW_APP, imsi64,
"Release Access Bearer Request Received in SGW\n");

spgw_ue_context_t* ue_context_p = nullptr;
magma::lte::oai::SpgwUeContext* ue_context_p = nullptr;
gtpv2c_cause_value_t cause = CONTEXT_NOT_FOUND;
magma::lte::oai::S11BearerContext* ctx_p = nullptr;

Expand All @@ -1309,15 +1301,20 @@ void sgw_handle_release_access_bearers_request(
state_ue_map->get(imsi64, &ue_context_p);

if (ue_context_p) {
sgw_s11_teid_t* s11_teid_p = nullptr;
LIST_FOREACH(s11_teid_p, &ue_context_p->sgw_s11_teid_list, entries) {
if (s11_teid_p) {
ctx_p = sgw_cm_get_spgw_context(s11_teid_p->sgw_s11_teid);
if (ctx_p) {
sgw_process_release_access_bearer_request(
LOG_SPGW_APP, imsi64, ctx_p->mutable_sgw_eps_bearer_context());
cause = REQUEST_ACCEPTED;
}
for (auto idx = 0; idx < ue_context_p->s11_bearer_context_size(); idx++) {
ctx_p = ue_context_p->mutable_s11_bearer_context(idx);
magma::lte::oai::S11BearerContext* check_ctx_p = nullptr;
check_ctx_p = sgw_cm_get_spgw_context(
ctx_p->sgw_eps_bearer_context().sgw_teid_s11_s4());
if (ctx_p == check_ctx_p) {
sgw_process_release_access_bearer_request(
LOG_SPGW_APP, imsi64, ctx_p->mutable_sgw_eps_bearer_context());
cause = REQUEST_ACCEPTED;
} else {
OAILOG_DEBUG_UE(
LOG_SPGW_APP, imsi64,
"S11BearerContext doesn't match state teid map for teid" TEID_FMT,
ctx_p->sgw_eps_bearer_context().sgw_teid_s11_s4());
}
}
}
Expand Down Expand Up @@ -1351,8 +1348,8 @@ void handle_s5_create_session_response(

OAILOG_DEBUG_UE(
LOG_SPGW_APP, new_bearer_ctxt_info_p->sgw_eps_bearer_context().imsi64(),
"Handle s5_create_session_response, for Context SGW S11 teid, " TEID_FMT
"EPS bearer id %u\n",
"Handle s5_create_session_response, for Context SGW S11 teid " TEID_FMT
" bearer id %u\n",
session_resp.context_teid, session_resp.eps_bearer_id);

// PCO processing
Expand Down
23 changes: 21 additions & 2 deletions lte/gateway/c/core/oai/tasks/sgw/spgw_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ void put_spgw_state() { SpgwStateManager::getInstance().write_state_to_db(); }

void put_spgw_ue_state(imsi64_t imsi64) {
if (SpgwStateManager::getInstance().is_persist_state_enabled()) {
spgw_ue_context_t* ue_context_p = nullptr;
magma::lte::oai::SpgwUeContext* ue_context_p = nullptr;
map_uint64_spgw_ue_context_t* spgw_ue_state = get_spgw_ue_state();
if (!spgw_ue_state) {
OAILOG_ERROR(LOG_SPGW_APP, "Failed to find spgw_ue_state");
OAILOG_ERROR(LOG_SPGW_APP, "spgw_ue_state is nullptr");
OAILOG_FUNC_OUT(LOG_SPGW_APP);
}
spgw_ue_state->get(imsi64, &ue_context_p);
Expand Down Expand Up @@ -191,6 +191,25 @@ void sgw_free_ue_context(void** ptr) {
return;
}

magma::lte::oai::SpgwUeContext* ue_context_p =
reinterpret_cast<magma::lte::oai::SpgwUeContext*>(*ptr);
if (!ue_context_p) {
OAILOG_ERROR(LOG_SPGW_APP,
"sgw_free_ue_context received invalid pointer for deletion");
return;
}
ue_context_p->Clear();
free_cpp_wrapper(reinterpret_cast<void**>(ptr));
return;
}

void sgw_s8_free_ue_context(void** ptr) {
if (!ptr) {
OAILOG_ERROR(LOG_SPGW_APP,
"sgw_free_ue_context received invalid pointer for deletion");
return;
}

spgw_ue_context_t* ue_context_p = reinterpret_cast<spgw_ue_context_t*>(*ptr);
if (!ue_context_p) {
OAILOG_ERROR(LOG_SPGW_APP,
Expand Down
Loading