@@ -107,7 +107,7 @@ static int s1ap_send_init_sctp(void) {
107107static 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
526522static 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;
0 commit comments