Skip to content

Commit 5db2c25

Browse files
committed
fix(agw): Modified code to port s1ap_state_t structure to protobuf structure,S1apState
Signed-off-by: Rashmi <[email protected]>
1 parent 19d5564 commit 5db2c25

22 files changed

+764
-697
lines changed

lte/gateway/c/core/oai/include/proto_map.hpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,35 @@ struct proto_map_s {
293293
}
294294
return PROTO_MAP_DUMP_FAIL;
295295
}
296+
297+
/***************************************************************************
298+
** **
299+
** Name: update_val() **
300+
** **
301+
** Description: Takes key and valueP as parameters.If the key exists, **
302+
** updates the value corresponding to key **
303+
** else returns error. **
304+
** **
305+
***************************************************************************/
306+
307+
proto_map_rc_t update_val(const keyT key, valueT* valueP) {
308+
if (!map) {
309+
return PROTO_MAP_NOT_CREATED;
310+
}
311+
if (map->empty()) {
312+
return PROTO_MAP_EMPTY;
313+
}
314+
if (valueP == nullptr) {
315+
return PROTO_MAP_BAD_PARAMETER_VALUE;
316+
}
317+
auto search_result = map->find(key);
318+
if (search_result != map->end()) {
319+
(*map)[key] = *valueP;
320+
return PROTO_MAP_OK;
321+
} else {
322+
return PROTO_MAP_KEY_NOT_EXISTS;
323+
}
324+
}
296325
};
297326

298327
// Map- Key: uint64_t, Data: uint64_t

lte/gateway/c/core/oai/include/s1ap_state.hpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ oai::S1apState* get_s1ap_state(bool read_from_db);
3838

3939
void put_s1ap_state(void);
4040

41-
magma::lte::oai::EnbDescription* s1ap_state_get_enb(oai::S1apState* state,
42-
sctp_assoc_id_t assoc_id);
41+
proto_map_rc_t s1ap_state_get_enb(oai::S1apState* state,
42+
sctp_assoc_id_t assoc_id,
43+
oai::EnbDescription* enb);
4344

44-
oai::UeDescription* s1ap_state_get_ue_enbid(
45-
sctp_assoc_id_t sctp_assoc_id, enb_ue_s1ap_id_t enb_ue_s1ap_id);
45+
oai::UeDescription* s1ap_state_get_ue_enbid(sctp_assoc_id_t sctp_assoc_id,
46+
enb_ue_s1ap_id_t enb_ue_s1ap_id);
4647

47-
oai::UeDescription* s1ap_state_get_ue_mmeid(
48-
mme_ue_s1ap_id_t mme_ue_s1ap_id);
48+
oai::UeDescription* s1ap_state_get_ue_mmeid(mme_ue_s1ap_id_t mme_ue_s1ap_id);
4949

5050
oai::UeDescription* s1ap_state_get_ue_imsi(imsi64_t imsi64);
5151

@@ -83,13 +83,17 @@ bool s1ap_ue_compare_by_mme_ue_id_cb(__attribute__((unused)) uint64_t keyP,
8383
void* parameterP, void** resultP);
8484

8585
bool s1ap_ue_compare_by_imsi(__attribute__((unused)) uint64_t keyP,
86-
oai::UeDescription* elementP,
87-
void* parameterP, void** resultP);
86+
oai::UeDescription* elementP, void* parameterP,
87+
void** resultP);
8888

8989
void remove_ues_without_imsi_from_ue_id_coll(void);
9090

91-
void clean_stale_enb_state(
92-
oai::S1apState* state, oai::EnbDescription* new_enb_association);
91+
void clean_stale_enb_state(oai::S1apState* state,
92+
oai::EnbDescription* new_enb_association);
93+
94+
proto_map_rc_t s1ap_state_update_enb_map(oai::S1apState* state,
95+
sctp_assoc_id_t assoc_id,
96+
oai::EnbDescription* enb);
9397

9498
} // namespace lte
9599
} // namespace magma

lte/gateway/c/core/oai/include/s1ap_types.hpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,9 @@ extern "C" {
3636
#define S1AP_TIMER_INACTIVE_ID (-1)
3737
#define S1AP_UE_CONTEXT_REL_COMP_TIMER 1 // in seconds
3838

39-
// Map- Key: uint32_t , Data: enb_description_t*
40-
typedef magma::proto_map_s<uint32_t, magma::lte::oai::EnbDescription*>
41-
map_uint32_enb_description_t;
42-
43-
typedef struct s1ap_state_s {
44-
// key:sctp_assoc_id, value: pointer to eNB_description_s
45-
map_uint32_enb_description_t enbs;
46-
// contains sctp association id, key is mme_ue_s1ap_id
47-
magma::proto_map_uint32_uint32_t mmeid2associd;
48-
49-
uint32_t num_enbs;
50-
} s1ap_state_t;
39+
// Map- Key: uint32_t , Data: EnbDescription
40+
typedef magma::proto_map_s<uint32_t, magma::lte::oai::EnbDescription>
41+
proto_map_uint32_enb_description_t;
5142

5243
typedef struct s1ap_imsi_map_s {
5344
magma::proto_map_uint32_uint64_t mme_ueid2imsi_map;

lte/gateway/c/core/oai/tasks/grpc_service/S1apServiceImpl.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@ Status S1apServiceImpl::GetENBState(ServerContext* context, const Void* request,
4646
// it will not affect ownership
4747
oai::S1apState* s1ap_state = get_s1ap_state(false);
4848
if (s1ap_state != nullptr) {
49-
if (!(s1ap_state->enbs.size())) {
49+
if (!(s1ap_state->enbs_size())) {
5050
return Status::OK;
5151
}
52-
53-
for (auto itr = s1ap_state->enbs.map->begin();
54-
itr != s1ap_state->enbs.map->end(); itr++) {
55-
EnbDescription* enb_ref = itr->second;
56-
if (enb_ref) {
57-
(*response->mutable_enb_state_map())[enb_ref->enb_id()] =
58-
enb_ref->nb_ue_associated();
52+
proto_map_uint32_enb_description_t enb_map;
53+
enb_map.map = s1ap_state->mutable_enbs();
54+
for (auto itr = enb_map.map->begin(); itr != enb_map.map->end(); itr++) {
55+
EnbDescription enb_ref = itr->second;
56+
if (enb_ref.sctp_assoc_id()) {
57+
(*response->mutable_enb_state_map())[enb_ref.enb_id()] =
58+
enb_ref.nb_ue_associated();
5959
}
6060
}
6161
}

lte/gateway/c/core/oai/tasks/ha/ha_service_handler.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ bool sync_up_with_orc8r(void) {
7373
}
7474

7575
typedef struct callback_data_s {
76-
S1apState* s1ap_state;
76+
magma::lte::oai::S1apState* s1ap_state;
7777
ha_agw_offload_req_t* request;
7878
} callback_data_t;
7979

@@ -94,24 +94,26 @@ bool trigger_agw_offload_for_ue(const hash_key_t keyP, void* const elementP,
9494
callback_data_t* callback_data = (callback_data_t*)parameterP;
9595
ha_agw_offload_req_t* offload_request =
9696
(ha_agw_offload_req_t*)callback_data->request;
97-
S1apState* s1ap_state = (S1apState*)callback_data->s1ap_state;
97+
magma::lte::oai::S1apState* s1ap_state =
98+
(magma::lte::oai::S1apState*)callback_data->s1ap_state;
9899
struct ue_mm_context_s* ue_context_p = (struct ue_mm_context_s*)elementP;
99100
bool any_flag = false; // true if we tried offloading any UE
100101

101102
IMSI_STRING_TO_IMSI64(offload_request->imsi, &imsi64);
102103

103-
EnbDescription* enb_ref_p = magma::lte::s1ap_state_get_enb(
104-
s1ap_state, ue_context_p->sctp_assoc_id_key);
104+
magma::lte::oai::EnbDescription enb_ref_p;
105+
magma::proto_map_rc_t rc = magma::lte::s1ap_state_get_enb(
106+
s1ap_state, ue_context_p->sctp_assoc_id_key, &enb_ref_p);
105107

106-
if (!enb_ref_p) {
108+
if (rc != magma::PROTO_MAP_OK) {
107109
OAILOG_ERROR_UE(LOG_UTIL, imsi64,
108110
"Failed to find enb_ref_p for assoc_id :%u",
109111
ue_context_p->sctp_assoc_id_key);
110112
return false;
111113
}
112114
// Return if this UE does not satisfy any of the filtering criteria
113115
if ((imsi64 != ue_context_p->emm_context._imsi64) &&
114-
(offload_request->eNB_id != enb_ref_p->enb_id())) {
116+
(offload_request->eNB_id != enb_ref_p.enb_id())) {
115117
return false;
116118
}
117119

@@ -128,7 +130,7 @@ bool trigger_agw_offload_for_ue(const hash_key_t keyP, void* const elementP,
128130
ue_context_p->mme_ue_s1ap_id;
129131
S1AP_UE_CONTEXT_RELEASE_REQ(message_p).enb_ue_s1ap_id =
130132
ue_context_p->enb_ue_s1ap_id;
131-
S1AP_UE_CONTEXT_RELEASE_REQ(message_p).enb_id = enb_ref_p->enb_id();
133+
S1AP_UE_CONTEXT_RELEASE_REQ(message_p).enb_id = enb_ref_p.enb_id();
132134
S1AP_UE_CONTEXT_RELEASE_REQ(message_p).relCause = S1AP_NAS_MME_OFFLOADING;
133135

134136
OAILOG_INFO(
@@ -141,7 +143,7 @@ bool trigger_agw_offload_for_ue(const hash_key_t keyP, void* const elementP,
141143
ue_context_p->emm_context._imsi64, offload_request->imsi,
142144
ue_context_p->mme_ue_s1ap_id, ue_context_p->enb_ue_s1ap_id,
143145
ue_context_p->e_utran_cgi.cell_identity.enb_id,
144-
ue_context_p->e_utran_cgi.cell_identity.cell_id, enb_ref_p->enb_id());
146+
ue_context_p->e_utran_cgi.cell_identity.cell_id, enb_ref_p.enb_id());
145147
OAILOG_INFO(LOG_UTIL, "UE Context Release procedure initiated for IMSI%s",
146148
offload_request->imsi);
147149
IMSI_STRING_TO_IMSI64(offload_request->imsi,

lte/gateway/c/core/oai/tasks/s1ap/s1ap_common.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,10 +429,9 @@ extern int asn1_xer_print;
429429

430430
/** \brief Function callback prototype.
431431
**/
432-
typedef status_code_e (*s1ap_message_handler_t)(S1apState* state,
433-
const sctp_assoc_id_t assoc_id,
434-
const sctp_stream_id_t stream,
435-
S1ap_S1AP_PDU_t* pdu);
432+
typedef status_code_e (*s1ap_message_handler_t)(
433+
magma::lte::oai::S1apState* state, const sctp_assoc_id_t assoc_id,
434+
const sctp_stream_id_t stream, S1ap_S1AP_PDU_t* pdu);
436435

437436
/** \brief Handle criticality
438437
\param criticality Criticality of the IE

lte/gateway/c/core/oai/tasks/s1ap/s1ap_mme.cpp

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ static int s1ap_send_init_sctp(void) {
107107
static int handle_message(zloop_t* loop, zsock_t* reader, void* arg) {
108108
MessageDef* received_message_p = receive_msg(reader);
109109
imsi64_t imsi64 = itti_get_associated_imsi(received_message_p);
110-
S1apState* state = get_s1ap_state(false);
110+
oai::S1apState* state = get_s1ap_state(false);
111111
AssertFatal(state != NULL, "failed to retrieve s1ap state (was null)");
112112

113113
bool is_task_state_same = false;
@@ -376,37 +376,27 @@ static void s1ap_mme_exit(void) {
376376
}
377377

378378
//------------------------------------------------------------------------------
379-
oai::EnbDescription* s1ap_new_enb(void) {
380-
oai::EnbDescription* enb_ref = NULL;
379+
void s1ap_new_enb(oai::EnbDescription* enb_ref) {
381380
magma::proto_map_uint32_uint64_t ue_id_coll;
382381

383-
enb_ref = new oai::EnbDescription();
384-
/*
385-
* Something bad happened during new
386-
* * * * May be we are running out of memory.
387-
* * * * TODO: Notify eNB with a cause like Hardware Failure.
388-
*/
389-
if (enb_ref == NULL) {
390-
OAILOG_CRITICAL(
382+
if (enb_ref == nullptr) {
383+
OAILOG_ERROR(
391384
LOG_S1AP,
392-
"Failed to allocate memory for structure, oai::EnbDescription \n");
393-
return enb_ref;
385+
"Received invalid pointer for structure, oai::EnbDescription ");
386+
return;
394387
}
395388
ue_id_coll.map = enb_ref->mutable_ue_id_map();
396389
ue_id_coll.set_name("s1ap_ue_coll");
397390
enb_ref->set_nb_ue_associated(0);
398-
return enb_ref;
391+
return;
399392
}
400393

401394
//------------------------------------------------------------------------------
402-
oai::UeDescription* s1ap_new_ue(S1apState* state,
395+
oai::UeDescription* s1ap_new_ue(oai::EnbDescription* enb_ref,
403396
const sctp_assoc_id_t sctp_assoc_id,
404397
enb_ue_s1ap_id_t enb_ue_s1ap_id) {
405-
oai::EnbDescription* enb_ref = NULL;
406398
oai::UeDescription* ue_ref = nullptr;
407399

408-
enb_ref = s1ap_state_get_enb(state, sctp_assoc_id);
409-
DevAssert(enb_ref != NULL);
410400
ue_ref = new oai::UeDescription();
411401
/*
412402
* Something bad happened during memory allocation...
@@ -445,23 +435,28 @@ oai::UeDescription* s1ap_new_ue(S1apState* state,
445435
}
446436

447437
//------------------------------------------------------------------------------
448-
void s1ap_remove_ue(S1apState* state, oai::UeDescription* ue_ref) {
449-
oai::EnbDescription* enb_ref = NULL;
438+
void s1ap_remove_ue(oai::S1apState* state, oai::UeDescription* ue_ref) {
439+
oai::EnbDescription enb_ref;
450440

451441
// NULL reference...
452442
if (ue_ref == nullptr) return;
453443

454444
mme_ue_s1ap_id_t mme_ue_s1ap_id = ue_ref->mme_ue_s1ap_id();
455-
enb_ref = s1ap_state_get_enb(state, ue_ref->sctp_assoc_id());
456-
DevAssert(enb_ref->nb_ue_associated() > 0);
445+
if ((s1ap_state_get_enb(state, ue_ref->sctp_assoc_id(), &enb_ref)) !=
446+
PROTO_MAP_OK) {
447+
OAILOG_ERROR(LOG_S1AP, "Failed to get enb association for assoc_id: %u",
448+
ue_ref->sctp_assoc_id());
449+
return;
450+
}
451+
DevAssert(enb_ref.nb_ue_associated() > 0);
457452
// Updating number of UE
458-
enb_ref->set_nb_ue_associated((enb_ref->nb_ue_associated() - 1));
453+
enb_ref.set_nb_ue_associated((enb_ref.nb_ue_associated() - 1));
459454

460455
OAILOG_TRACE(LOG_S1AP,
461456
"Removing UE enb_ue_s1ap_id: " ENB_UE_S1AP_ID_FMT
462457
" mme_ue_s1ap_id:" MME_UE_S1AP_ID_FMT " in eNB id : %d\n",
463458
ue_ref->enb_ue_s1ap_id(), ue_ref->mme_ue_s1ap_id(),
464-
enb_ref->enb_id);
459+
enb_ref.enb_id);
465460

466461
ue_ref->set_s1ap_ue_state(oai::S1AP_UE_INVALID_STATE);
467462
if (ue_ref->s1ap_ue_context_rel_timer().id() != S1AP_TIMER_INACTIVE_ID) {
@@ -475,12 +470,12 @@ void s1ap_remove_ue(S1apState* state, oai::UeDescription* ue_ref) {
475470
return;
476471
}
477472
s1ap_ue_state->remove(ue_ref->comp_s1ap_id());
478-
proto_map_uint32_uint32_t mmeid2associd_map.map =
479-
state->mutable_mmeid2associd();
473+
proto_map_uint32_uint32_t mmeid2associd_map;
474+
mmeid2associd_map.map = state->mutable_mmeid2associd();
480475
mmeid2associd_map.remove(mme_ue_s1ap_id);
481476

482477
magma::proto_map_uint32_uint64_t ue_id_coll;
483-
ue_id_coll.map = enb_ref->mutable_ue_id_map();
478+
ue_id_coll.map = enb_ref.mutable_ue_id_map();
484479
ue_id_coll.remove(mme_ue_s1ap_id);
485480

486481
imsi64_t imsi64 = INVALID_IMSI64;
@@ -490,28 +485,29 @@ void s1ap_remove_ue(S1apState* state, oai::UeDescription* ue_ref) {
490485
s1ap_imsi_map->mme_ueid2imsi_map.remove(mme_ue_s1ap_id);
491486

492487
OAILOG_DEBUG(LOG_S1AP, "Num UEs associated %u num elements in ue_id_coll %lu",
493-
enb_ref->nb_ue_associated(), ue_id_coll.size());
494-
if (!enb_ref->nb_ue_associated()) {
495-
if (enb_ref->s1_enb_state() == magma::lte::oai::S1AP_RESETING) {
488+
enb_ref.nb_ue_associated(), ue_id_coll.size());
489+
if (!enb_ref.nb_ue_associated()) {
490+
if (enb_ref.s1_enb_state() == magma::lte::oai::S1AP_RESETING) {
496491
OAILOG_INFO(LOG_S1AP, "Moving eNB state to S1AP_INIT \n");
497-
enb_ref->set_s1_state(magma::lte::oai::S1AP_INIT);
498-
set_gauge("s1_connection", 0, 1, "enb_name", enb_ref->enb_name());
492+
enb_ref.set_s1_state(magma::lte::oai::S1AP_INIT);
493+
set_gauge("s1_connection", 0, 1, "enb_name", enb_ref.enb_name());
499494
state->set_num_enbs(state->num_enbs() - 1);
500-
} else if (enb_ref->s1_enb_state() == magma::lte::oai::S1AP_SHUTDOWN) {
495+
} else if (enb_ref.s1_enb_state() == magma::lte::oai::S1AP_SHUTDOWN) {
501496
OAILOG_INFO(LOG_S1AP, "Deleting eNB \n");
502-
set_gauge("s1_connection", 0, 1, "enb_name", enb_ref->enb_name());
503-
s1ap_remove_enb(state, enb_ref);
497+
set_gauge("s1_connection", 0, 1, "enb_name", enb_ref.enb_name());
498+
s1ap_remove_enb(state, &enb_ref);
504499
}
505500
}
501+
s1ap_state_update_enb_map(state, enb_ref.sctp_assoc_id(), &enb_ref);
506502
}
507503

508504
//------------------------------------------------------------------------------
509-
void s1ap_remove_enb(S1apState* state, oai::EnbDescription* enb_ref) {
505+
void s1ap_remove_enb(oai::S1apState* state, oai::EnbDescription* enb_ref) {
510506
if (enb_ref == NULL) {
511507
return;
512508
}
513509
magma::proto_map_uint32_uint64_t ue_id_coll;
514-
map_uint32_enb_description_t enb_map;
510+
proto_map_uint32_enb_description_t enb_map;
515511
enb_ref->set_s1_state(magma::lte::oai::S1AP_INIT);
516512

517513
ue_id_coll.map = enb_ref->mutable_ue_id_map();
@@ -524,7 +520,7 @@ void s1ap_remove_enb(S1apState* state, oai::EnbDescription* enb_ref) {
524520
}
525521

526522
static int handle_stats_timer(zloop_t* loop, int id, void* arg) {
527-
S1apState* s1ap_state_p = get_s1ap_state(false);
523+
oai::S1apState* s1ap_state_p = get_s1ap_state(false);
528524
application_s1ap_stats_msg_t stats_msg;
529525
stats_msg.nb_enb_connected = s1ap_state_p->num_enbs();
530526
stats_msg.nb_s1ap_last_msg_latency = s1ap_last_msg_latency;

lte/gateway/c/core/oai/tasks/s1ap/s1ap_mme.hpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,28 +53,26 @@ namespace lte {
5353
/** \brief Allocate and add to the list a new eNB descriptor
5454
* @returns Reference to the new eNB element in list
5555
**/
56-
magma::lte::oai::EnbDescription* s1ap_new_enb(void);
56+
void s1ap_new_enb(oai::EnbDescription*);
5757

5858
/** \brief Allocate and add to the right eNB list a new UE descriptor
5959
* \param sctp_assoc_id association ID over SCTP
6060
* \param enb_ue_s1ap_id ue ID over S1AP
6161
* @returns Reference to the new UE element in list
6262
**/
63-
oai::UeDescription* s1ap_new_ue(S1apState* state,
64-
sctp_assoc_id_t sctp_assoc_id,
65-
enb_ue_s1ap_id_t enb_ue_s1ap_id);
63+
oai::UeDescription* s1ap_new_ue(oai::EnbDescription* enb_ref,
64+
sctp_assoc_id_t sctp_assoc_id,
65+
enb_ue_s1ap_id_t enb_ue_s1ap_id);
6666

6767
/** \brief Remove target UE from the list
6868
* \param ue_ref UE structure reference to remove
6969
**/
70-
void s1ap_remove_ue(S1apState* state,
71-
oai::UeDescription* ue_ref);
70+
void s1ap_remove_ue(oai::S1apState* state, oai::UeDescription* ue_ref);
7271

7372
/** \brief Remove target eNB from the list and remove any UE associated
7473
* \param enb_ref eNB structure reference to remove
7574
**/
76-
void s1ap_remove_enb(S1apState* state,
77-
oai::EnbDescription* enb_ref);
75+
void s1ap_remove_enb(oai::S1apState* state, oai::EnbDescription* enb_ref);
7876

7977
void free_enb_description(void** ptr);
8078

0 commit comments

Comments
 (0)