Commit de9c8634 authored by Remi Hardy's avatar Remi Hardy
Browse files

Merge remote-tracking branch 'origin/s1_subnormal' into integration_2021_wk10

parents 17e10eb2 535efa0f
......@@ -398,6 +398,11 @@ typedef struct s1ap_register_enb_req_s {
/* Number of SCTP streams used for a mme association */
uint16_t sctp_in_streams;
uint16_t sctp_out_streams;
uint16_t s1_setuprsp_wait_timer;
uint16_t s1_setupreq_wait_timer;
uint16_t s1_setupreq_count;
uint16_t sctp_req_timer;
uint16_t sctp_req_count;
} s1ap_register_enb_req_t;
//-------------------------------------------------------------------------------------------//
......
......@@ -2429,6 +2429,65 @@ int RCconfig_S1(
"to\n"
" tracking_area_code = 1; // no string!!\n"
" plmn_list = ( { mcc = 208; mnc = 93; mnc_length = 2; } )\n");
if(*ENBParamList.paramarray[k][ENB_S1SETUP_RSP_TIMER_IDX].uptr <= 0xffff)
{
S1AP_REGISTER_ENB_REQ(msg_p).s1_setuprsp_wait_timer = *ENBParamList.paramarray[k][ENB_S1SETUP_RSP_TIMER_IDX].uptr;
}
else
{
LOG_E(S1AP,
"s1setup_rsp_timer value in conf file is invalid (%d). Default value is set.\n",
*ENBParamList.paramarray[k][ENB_S1SETUP_RSP_TIMER_IDX].uptr);
S1AP_REGISTER_ENB_REQ(msg_p).s1_setuprsp_wait_timer = 5;
}
if(*ENBParamList.paramarray[k][ENB_S1SETUP_REQ_TIMER_IDX].uptr <= 0xffff)
{
S1AP_REGISTER_ENB_REQ(msg_p).s1_setupreq_wait_timer = *ENBParamList.paramarray[k][ENB_S1SETUP_REQ_TIMER_IDX].uptr;
}
else
{
LOG_E(S1AP,
"s1setup_req_timer value in conf file is invalid (%d). Default value is set.\n",
*ENBParamList.paramarray[k][ENB_S1SETUP_REQ_TIMER_IDX].uptr);
S1AP_REGISTER_ENB_REQ(msg_p).s1_setupreq_wait_timer = 5;
}
if(*ENBParamList.paramarray[k][ENB_S1SETUP_REQ_COUNT_IDX].uptr <= 0xffff)
{
S1AP_REGISTER_ENB_REQ(msg_p).s1_setupreq_count = *ENBParamList.paramarray[k][ENB_S1SETUP_REQ_COUNT_IDX].uptr;
}
else
{
LOG_E(S1AP,
"s1setup_req_count value in conf file is invalid (%d). Default value is set.\n",
*ENBParamList.paramarray[k][ENB_S1SETUP_REQ_COUNT_IDX].uptr);
S1AP_REGISTER_ENB_REQ(msg_p).s1_setupreq_count = 0xffff;
}
if(*ENBParamList.paramarray[k][ENB_SCTP_REQ_TIMER_IDX].uptr <= 0xffff)
{
S1AP_REGISTER_ENB_REQ(msg_p).sctp_req_timer = *ENBParamList.paramarray[k][ENB_SCTP_REQ_TIMER_IDX].uptr;
}
else
{
LOG_E(S1AP,
"sctp_req_timer value in conf file is invalid (%d). Default value is set.\n",
*ENBParamList.paramarray[k][ENB_SCTP_REQ_TIMER_IDX].uptr);
S1AP_REGISTER_ENB_REQ(msg_p).sctp_req_timer = 180;
}
if(*ENBParamList.paramarray[k][ENB_SCTP_REQ_COUNT_IDX].uptr <= 0xffff)
{
S1AP_REGISTER_ENB_REQ(msg_p).sctp_req_count = *ENBParamList.paramarray[k][ENB_SCTP_REQ_COUNT_IDX].uptr;
}
else
{
LOG_E(S1AP,
"sctp_req_count value in conf file is invalid (%d). Default value is set.\n",
*ENBParamList.paramarray[k][ENB_SCTP_REQ_COUNT_IDX].uptr);
S1AP_REGISTER_ENB_REQ(msg_p).sctp_req_count = 0xffff;
}
config_getlist(&PLMNParamList, PLMNParams, sizeof(PLMNParams)/sizeof(paramdef_t), aprefix);
if (PLMNParamList.numelt < 1 || PLMNParamList.numelt > 6) {
......
......@@ -214,6 +214,11 @@ typedef enum {
#define ENB_CONFIG_STRING_X2 "enable_x2"
#define ENB_CONFIG_STRING_ENB_M2 "enable_enb_m2"
#define ENB_CONFIG_STRING_MCE_M2 "enable_mce_m2"
#define ENB_CONFIG_STRING_S1SETUP_RSP_TIMER "s1setup_rsp_timer"
#define ENB_CONFIG_STRING_S1SETUP_REQ_TIMER "s1setup_req_timer"
#define ENB_CONFIG_STRING_S1SETUP_REQ_COUNT "s1setup_req_count"
#define ENB_CONFIG_STRING_SCTP_REQ_TIMER "sctp_req_timer"
#define ENB_CONFIG_STRING_SCTP_REQ_COUNT "sctp_req_count"
/*-----------------------------------------------------------------------------------------------------------------------------------------*/
/* cell configuration parameters */
/* optname helpstr paramflags XXXptr defXXXval type numelt */
......@@ -239,6 +244,11 @@ typedef enum {
{ENB_CONFIG_STRING_X2, NULL, 0, strptr:NULL, defstrval:NULL, TYPE_STRING, 0}, \
{ENB_CONFIG_STRING_ENB_M2, NULL, 0, strptr:NULL, defstrval:"no", TYPE_STRING, 0}, \
{ENB_CONFIG_STRING_MCE_M2, NULL, 0, strptr:NULL, defstrval:"no", TYPE_STRING, 0}, \
{ENB_CONFIG_STRING_S1SETUP_RSP_TIMER, NULL, 0, uptr:NULL, defuintval:5, TYPE_UINT, 0}, \
{ENB_CONFIG_STRING_S1SETUP_REQ_TIMER, NULL, 0, uptr:NULL, defuintval:5, TYPE_UINT, 0}, \
{ENB_CONFIG_STRING_S1SETUP_REQ_COUNT, NULL, 0, uptr:NULL, defuintval:65535, TYPE_UINT, 0}, \
{ENB_CONFIG_STRING_SCTP_REQ_TIMER, NULL, 0, uptr:NULL, defuintval:180, TYPE_UINT, 0}, \
{ENB_CONFIG_STRING_SCTP_REQ_COUNT, NULL, 0, uptr:NULL, defuintval:65535, TYPE_UINT, 0}, \
}
#define ENB_ENB_ID_IDX 0
......@@ -261,6 +271,11 @@ typedef enum {
#define ENB_ENABLE_X2 17
#define ENB_ENABLE_ENB_M2 18
#define ENB_ENABLE_MCE_M2 19
#define ENB_S1SETUP_RSP_TIMER_IDX 20
#define ENB_S1SETUP_REQ_TIMER_IDX 21
#define ENB_S1SETUP_REQ_COUNT_IDX 22
#define ENB_SCTP_REQ_TIMER_IDX 23
#define ENB_SCTP_REQ_COUNT_IDX 24
#define TRACKING_AREA_CODE_OKRANGE {0x0001,0xFFFD}
#define ENBPARAMS_CHECK { \
......
......@@ -782,21 +782,37 @@ rrc_eNB_send_S1AP_NAS_FIRST_REQ(
S1AP_NAS_FIRST_REQ (message_p).ue_identity.presenceMask |= UE_IDENTITIES_gummei;
if (r_mme->plmn_Identity != NULL) {
if ((r_mme->plmn_Identity->mcc != NULL) && (r_mme->plmn_Identity->mcc->list.count > 0)) {
/* Use first indicated PLMN MCC if it is defined */
S1AP_NAS_FIRST_REQ (message_p).ue_identity.gummei.mcc = *r_mme->plmn_Identity->mcc->list.array[selected_plmn_identity];
if ((r_mme->plmn_Identity->mcc != NULL) && (r_mme->plmn_Identity->mcc->list.count == 3))
{
S1AP_NAS_FIRST_REQ (message_p).ue_identity.gummei.mcc = (*r_mme->plmn_Identity->mcc->list.array[0] & 0xf) * 100 +
(*r_mme->plmn_Identity->mcc->list.array[1] & 0xf) * 10 +
(*r_mme->plmn_Identity->mcc->list.array[2] & 0xf);
LOG_I(S1AP, "[eNB %d] Build S1AP_NAS_FIRST_REQ adding in s_TMSI: GUMMEI MCC %u ue %x\n",
ctxt_pP->module_id,
S1AP_NAS_FIRST_REQ (message_p).ue_identity.gummei.mcc,
ue_context_pP->ue_context.rnti);
}
if (r_mme->plmn_Identity->mnc.list.count > 0) {
/* Use first indicated PLMN MNC if it is defined */
S1AP_NAS_FIRST_REQ (message_p).ue_identity.gummei.mnc = *r_mme->plmn_Identity->mnc.list.array[selected_plmn_identity];
LOG_I(S1AP, "[eNB %d] Build S1AP_NAS_FIRST_REQ adding in s_TMSI: GUMMEI MNC %u ue %x\n",
if(r_mme->plmn_Identity->mnc.list.count == 3)
{
S1AP_NAS_FIRST_REQ (message_p).ue_identity.gummei.mnc = (*r_mme->plmn_Identity->mnc.list.array[0] & 0xf) * 100 +
(*r_mme->plmn_Identity->mnc.list.array[1] & 0xf) * 10 +
(*r_mme->plmn_Identity->mnc.list.array[2] & 0xf);
S1AP_NAS_FIRST_REQ (message_p).ue_identity.gummei.mnc_len = 3;
LOG_I(S1AP, "[eNB %d] Build S1AP_NAS_FIRST_REQ adding in s_TMSI: GUMMEI MNC %u %udigit ue %x\n",
ctxt_pP->module_id,
S1AP_NAS_FIRST_REQ (message_p).ue_identity.gummei.mnc,
S1AP_NAS_FIRST_REQ (message_p).ue_identity.gummei.mnc_len,
ue_context_pP->ue_context.rnti);
}
else if(r_mme->plmn_Identity->mnc.list.count == 2)
{
S1AP_NAS_FIRST_REQ (message_p).ue_identity.gummei.mnc = (*r_mme->plmn_Identity->mnc.list.array[0] & 0xf) * 10 +
(*r_mme->plmn_Identity->mnc.list.array[1] & 0xf);
S1AP_NAS_FIRST_REQ (message_p).ue_identity.gummei.mnc_len = 2;
LOG_I(S1AP, "[eNB %d] Build S1AP_NAS_FIRST_REQ adding in s_TMSI: GUMMEI MNC %u %udigit ue %x\n",
ctxt_pP->module_id,
S1AP_NAS_FIRST_REQ (message_p).ue_identity.gummei.mnc,
S1AP_NAS_FIRST_REQ (message_p).ue_identity.gummei.mnc_len,
ue_context_pP->ue_context.rnti);
}
} else { // end if plmn_Identity != NULL
......
......@@ -536,6 +536,14 @@ int x2ap_eNB_handle_x2_setup_response(instance_t instance,
return -1;
}
if((x2ap_eNB_data->state == X2AP_ENB_STATE_CONNECTED) ||
(x2ap_eNB_data->state == X2AP_ENB_STATE_READY))
{
X2AP_ERROR("Received Unexpexted X2 Setup Response Message\n");
return -1;
}
X2AP_DEBUG("Received a new X2 setup response\n");
X2AP_FIND_PROTOCOLIE_BY_ID(X2AP_X2SetupResponse_IEs_t, ie, x2SetupResponse,
......@@ -662,6 +670,14 @@ int x2ap_eNB_handle_x2_setup_failure(instance_t instance,
return -1;
}
if((x2ap_eNB_data->state == X2AP_ENB_STATE_CONNECTED) ||
(x2ap_eNB_data->state == X2AP_ENB_STATE_READY))
{
X2AP_ERROR("Received Unexpexted X2 Setup Failure Message\n");
return -1;
}
X2AP_DEBUG("Received a new X2 setup failure\n");
X2AP_FIND_PROTOCOLIE_BY_ID(X2AP_X2SetupFailure_IEs_t, ie, x2SetupFailure,
......@@ -730,6 +746,7 @@ int x2ap_eNB_handle_handover_preparation (instance_t instance,
X2AP_ProtocolIE_ID_id_Old_eNB_UE_X2AP_ID, true);
if (ie == NULL ) {
X2AP_ERROR("%s %d: ie is a NULL pointer \n",__FILE__,__LINE__);
itti_free(ITTI_MSG_ORIGIN_ID(msg), msg);
return -1;
}
......@@ -750,7 +767,11 @@ int x2ap_eNB_handle_handover_preparation (instance_t instance,
//measResultListEUTRA.list.array[ncell_index]->physCellId;
X2AP_FIND_PROTOCOLIE_BY_ID(X2AP_HandoverRequest_IEs_t, ie, x2HandoverRequest,
X2AP_ProtocolIE_ID_id_GUMMEI_ID, true);
if (ie == NULL ) {
X2AP_ERROR("%s %d: ie is a NULL pointer \n",__FILE__,__LINE__);
itti_free(ITTI_MSG_ORIGIN_ID(msg), msg);
return -1;
}
TBCD_TO_MCC_MNC(&ie->value.choice.ECGI.pLMN_Identity, X2AP_HANDOVER_REQ(msg).ue_gummei.mcc,
X2AP_HANDOVER_REQ(msg).ue_gummei.mnc, X2AP_HANDOVER_REQ(msg).ue_gummei.mnc_len);
OCTET_STRING_TO_INT8(&ie->value.choice.GUMMEI.mME_Code, X2AP_HANDOVER_REQ(msg).ue_gummei.mme_code);
......@@ -761,6 +782,7 @@ int x2ap_eNB_handle_handover_preparation (instance_t instance,
if (ie == NULL ) {
X2AP_ERROR("%s %d: ie is a NULL pointer \n",__FILE__,__LINE__);
itti_free(ITTI_MSG_ORIGIN_ID(msg), msg);
return -1;
}
......@@ -872,6 +894,7 @@ int x2ap_eNB_handle_handover_response (instance_t instance,
if (ie == NULL ) {
X2AP_ERROR("%s %d: ie is a NULL pointer \n",__FILE__,__LINE__);
itti_free(ITTI_MSG_ORIGIN_ID(msg), msg);
return -1;
}
......@@ -882,6 +905,7 @@ int x2ap_eNB_handle_handover_response (instance_t instance,
if (ie == NULL ) {
X2AP_ERROR("%s %d: ie is a NULL pointer \n",__FILE__,__LINE__);
itti_free(ITTI_MSG_ORIGIN_ID(msg), msg);
return -1;
}
......@@ -912,6 +936,7 @@ int x2ap_eNB_handle_handover_response (instance_t instance,
if (ie == NULL ) {
X2AP_ERROR("%s %d: ie is a NULL pointer \n", __FILE__, __LINE__);
itti_free(ITTI_MSG_ORIGIN_ID(msg), msg);
return -1;
}else{
if (ie->value.choice.E_RABs_Admitted_List.list.count > 0) {
......@@ -959,6 +984,12 @@ int x2ap_eNB_handle_handover_response (instance_t instance,
X2AP_FIND_PROTOCOLIE_BY_ID(X2AP_HandoverRequestAcknowledge_IEs_t, ie, x2HandoverRequestAck,
X2AP_ProtocolIE_ID_id_TargeteNBtoSource_eNBTransparentContainer, true);
if (ie == NULL ) {
X2AP_ERROR("%s %d: ie is a NULL pointer \n",__FILE__,__LINE__);
itti_free(ITTI_MSG_ORIGIN_ID(msg), msg);
return -1;
}
X2AP_TargeteNBtoSource_eNBTransparentContainer_t *c = &ie->value.choice.TargeteNBtoSource_eNBTransparentContainer;
if (c->size > 1024 /* TODO: this is the size of rrc_buffer in struct x2ap_handover_req_ack_s */)
......@@ -1012,6 +1043,7 @@ int x2ap_eNB_handle_ue_context_release (instance_t instance,
if (ie == NULL ) {
X2AP_ERROR("%s %d: ie is a NULL pointer \n",__FILE__,__LINE__);
itti_free(ITTI_MSG_ORIGIN_ID(msg), msg);
return -1;
}
......@@ -1022,6 +1054,7 @@ int x2ap_eNB_handle_ue_context_release (instance_t instance,
if (ie == NULL ) {
X2AP_ERROR("%s %d: ie is a NULL pointer \n",__FILE__,__LINE__);
itti_free(ITTI_MSG_ORIGIN_ID(msg), msg);
return -1;
}
......
......@@ -1211,7 +1211,7 @@ int gtpv1u_eNB_init(void) {
//gtpv1u_data_g.udp_data;
RC.gtpv1u_data_g->seq_num = 0;
RC.gtpv1u_data_g->restart_counter = 0;
RC.gtpv1u_data_g->enb_ip_address_for_S1u_S12_S4_up = 0;
/* Initializing GTPv1-U stack */
if ((rc = nwGtpv1uInitialize(&RC.gtpv1u_data_g->gtpv1u_stack, GTPU_STACK_ENB)) != NW_GTPV1U_OK) {
LOG_E(GTPU, "Failed to setup nwGtpv1u stack %x\n", rc);
......
......@@ -190,7 +190,6 @@ int decode_attach_accept(attach_accept_msg *attach_accept, uint8_t *buffer, uint
default:
errorCodeDecoder = TLV_DECODE_UNEXPECTED_IEI;
LOG_TRACE(WARNING, "DECODE_UNEXPECTED_IEI %x (4 bits)", ieiDecoded);
AssertFatal(0, " ");
return TLV_DECODE_UNEXPECTED_IEI;
}
}
......
......@@ -43,13 +43,17 @@ int decode_supported_codec_list(SupportedCodecList *supportedcodeclist, uint8_t
CHECK_LENGTH_DECODER(len - decoded, ielen);
supportedcodeclist->systemidentification = *(buffer + decoded);
decoded++;
ielen--;
supportedcodeclist->lengthofbitmap = *(buffer + decoded);
decoded++;
ielen--;
//IES_DECODE_U16(supportedcodeclist->codecbitmap, *(buffer + decoded));
IES_DECODE_U16(buffer, decoded, supportedcodeclist->codecbitmap);
ielen=ielen -2;
#if defined (NAS_DEBUG)
dump_supported_codec_list_xml(supportedcodeclist, iei);
#endif
decoded = decoded + ielen;
return decoded;
}
int encode_supported_codec_list(SupportedCodecList *supportedcodeclist, uint8_t iei, uint8_t *buffer, uint32_t len)
......
......@@ -443,14 +443,14 @@ static int _emm_as_data_ind(nas_user_t *user, const emm_as_data_t *msg, int *emm
EPS_MOBILITY_MANAGEMENT_MESSAGE) {
/* Process EMM data */
rc = _emm_as_recv(user, plain_msg, bytes, emm_cause);
free(plain_msg);
} else if (header.protocol_discriminator ==
EPS_SESSION_MANAGEMENT_MESSAGE) {
const OctetString data = {bytes, (uint8_t *)plain_msg};
/* Foward ESM data to EPS session management */
rc = lowerlayer_data_ind(user, &data);
free(plain_msg);
}
free(plain_msg);
}
} else {
/* Process successfull lower layer transfer indication */
......
......@@ -296,16 +296,16 @@ int emm_proc_security_mode_command(nas_user_t *user, int native_ksi, int ksi,
else {
/* Setup EMM cause code */
emm_cause = EMM_CAUSE_SECURITY_MODE_REJECTED;
/* Release security mode control internal data */
if (security_data->kenb.value) {
free(security_data->kenb.value);
security_data->kenb.value = NULL;
security_data->kenb.length = 0;
}
}
}
/* Release security mode control internal data */
if (security_data->kenb.value) {
free(security_data->kenb.value);
security_data->kenb.value = NULL;
security_data->kenb.length = 0;
}
/* Setup EMM procedure handler to be executed upon receiving
* lower layer notification */
rc = emm_proc_lowerlayer_initialize(user->lowerlayer_data, NULL, NULL, NULL, NULL);
......
......@@ -106,7 +106,12 @@ extern int asn1_xer_print;
if (ie == NULL ) { \
S1AP_ERROR("S1AP_FIND_PROTOCOLIE_BY_ID: %s %d: ie is NULL\n",__FILE__,__LINE__);\
} \
if (mandatory) DevAssert(ie != NULL); \
if (mandatory) { \
if (ie == NULL) { \
S1AP_ERROR("S1AP_FIND_PROTOCOLIE_BY_ID: %s %d: ie is NULL\n",__FILE__,__LINE__);\
return -1; \
} \
} \
} while(0)
/** \brief Function callback prototype.
**/
......
This diff is collapsed.
......@@ -30,6 +30,22 @@
#ifndef S1AP_ENB_H_
#define S1AP_ENB_H_
#define S1AP_MMEIND 0x80000000
#define S1AP_UEIND 0x00000000
#define S1_SETRSP_WAIT 0x00010000
#define S1_SETREQ_WAIT 0x00020000
#define SCTP_REQ_WAIT 0x00030000
#define S1AP_LINEIND 0x0000ffff
#define S1AP_TIMERIND 0x00ff0000
#define S1AP_TIMERID_INIT 0xffffffffffffffff
typedef enum s1ap_timer_type_s {
S1AP_TIMER_PERIODIC,
S1AP_TIMER_ONE_SHOT,
S1AP_TIMER_TYPE_MAX,
} s1ap_timer_type_t;
typedef struct s1ap_eNB_config_s {
// MME related params
unsigned char mme_enabled; ///< MME enabled ?
......@@ -43,6 +59,7 @@ void *s1ap_eNB_process_itti_msg(void*);
void s1ap_eNB_init(void);
void *s1ap_eNB_task(void *arg);
int s1ap_timer_remove(long timer_id);
uint32_t s1ap_generate_eNB_id(void);
#endif /* S1AP_ENB_H_ */
......
......@@ -89,8 +89,6 @@ static int s1ap_eNB_decode_initiating_message(S1AP_S1AP_PDU_t *pdu) {
default:
S1AP_ERROR("Unknown procedure ID (%d) for initiating message\n",
(int)pdu->choice.initiatingMessage.procedureCode);
AssertFatal( 0, "Unknown procedure ID (%d) for initiating message\n",
(int)pdu->choice.initiatingMessage.procedureCode);
return -1;
}
......
......@@ -165,6 +165,12 @@ typedef struct s1ap_eNB_mme_data_s {
/* Only meaningfull in virtual mode */
struct s1ap_eNB_instance_s *s1ap_eNB_instance;
uint32_t nb_calls;
net_ip_address_t mme_ip_address;
long timer_id;
uint16_t s1_setupreq_cnt;
uint16_t sctp_req_cnt;
} s1ap_eNB_mme_data_t;
typedef struct s1ap_eNB_instance_s {
......@@ -217,6 +223,14 @@ typedef struct s1ap_eNB_instance_s {
/* Default Paging DRX of the eNB as defined in TS 36.304 */
paging_drx_t default_drx;
net_ip_address_t enb_ip_address;
uint16_t s1_setuprsp_wait_timer;
uint16_t s1_setupreq_wait_timer;
uint16_t s1_setupreq_count;
uint16_t sctp_req_timer;
uint16_t sctp_req_count;
uint16_t sctp_in_streams;
uint16_t sctp_out_streams;
} s1ap_eNB_instance_t;
typedef struct {
......
This diff is collapsed.
......@@ -95,23 +95,43 @@ struct s1ap_eNB_mme_data_s *s1ap_eNB_get_MME(
{
struct s1ap_eNB_mme_data_s temp;
struct s1ap_eNB_mme_data_s *found;
struct s1ap_eNB_mme_data_s *mme_p;
memset(&temp, 0, sizeof(struct s1ap_eNB_mme_data_s));
temp.assoc_id = assoc_id;
temp.cnx_id = cnx_id;
if (instance_p == NULL) {
STAILQ_FOREACH(instance_p, &s1ap_eNB_internal_data.s1ap_eNB_instances_head,
s1ap_eNB_entries) {
found = RB_FIND(s1ap_mme_map, &instance_p->s1ap_mme_head, &temp);
if( cnx_id != 0 ) {
if (instance_p == NULL) {
STAILQ_FOREACH(instance_p, &s1ap_eNB_internal_data.s1ap_eNB_instances_head,
s1ap_eNB_entries) {
found = RB_FIND(s1ap_mme_map, &instance_p->s1ap_mme_head, &temp);
if (found != NULL) {
return found;
if (found != NULL) {
return found;
}
}
} else {
return RB_FIND(s1ap_mme_map, &instance_p->s1ap_mme_head, &temp);
}
} else {
return RB_FIND(s1ap_mme_map, &instance_p->s1ap_mme_head, &temp);
if (instance_p == NULL) {
STAILQ_FOREACH(instance_p, &s1ap_eNB_internal_data.s1ap_eNB_instances_head,
s1ap_eNB_entries) {
RB_FOREACH(mme_p, s1ap_mme_map, &instance_p->s1ap_mme_head) {
if( mme_p->assoc_id == assoc_id ) {
return mme_p;
}
}
}
} else {
RB_FOREACH(mme_p, s1ap_mme_map, &instance_p->s1ap_mme_head) {
if( mme_p->assoc_id == assoc_id ) {
return mme_p;
}
}
}
}
return NULL;
......
......@@ -138,8 +138,8 @@ int s1ap_eNB_handle_nas_first_req(
* identity, selects the MME with the highest capacity.
*/
mme_desc_p = s1ap_eNB_nnsf_select_mme(
instance_p,
s1ap_nas_first_req_p->establishment_cause);
instance_p,
s1ap_nas_first_req_p->establishment_cause);
if (mme_desc_p) {
S1AP_INFO("[eNB %ld] Chose MME '%s' (assoc_id %d) through highest relative capacity\n",
......@@ -358,10 +358,18 @@ int s1ap_eNB_handle_nas_downlink(uint32_t assoc_id,
container = &pdu->choice.initiatingMessage.value.choice.DownlinkNASTransport;
S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_DownlinkNASTransport_IEs_t, ie, container,
S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID, true);
if(ie == NULL)
{
return -1;
}
mme_ue_s1ap_id = ie->value.choice.MME_UE_S1AP_ID;
S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_DownlinkNASTransport_IEs_t, ie, container,
S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID, true);
if(ie == NULL)
{
return -1;
}
enb_ue_s1ap_id = ie->value.choice.ENB_UE_S1AP_ID;
if ((ue_desc_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance,
......@@ -416,6 +424,10 @@ int s1ap_eNB_handle_nas_downlink(uint32_t assoc_id,
S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_DownlinkNASTransport_IEs_t, ie, container,
S1AP_ProtocolIE_ID_id_NAS_PDU, true);
if(ie == NULL)
{
return -1;
}
/* Forward the NAS PDU to RRC */
s1ap_eNB_itti_send_nas_downlink_ind(s1ap_eNB_instance->instance,
ue_desc_p->ue_initial_id,
......@@ -494,9 +506,9 @@ int s1ap_eNB_nas_uplink(instance_t instance, s1ap_uplink_nas_t *s1ap_uplink_nas_
ie->criticality = S1AP_Criticality_ignore;
ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_EUTRAN_CGI;
MCC_MNC_TO_PLMNID(
s1ap_eNB_instance_p->mcc[ue_context_p->selected_plmn_identity],
s1ap_eNB_instance_p->mnc[ue_context_p->selected_plmn_identity],
s1ap_eNB_instance_p->mnc_digit_length[ue_context_p->selected_plmn_identity],
s1ap_eNB_instance_p->mcc[ue_context_p->mme_ref->broadcast_plmn_index[0]],
s1ap_eNB_instance_p->mnc[ue_context_p->mme_ref->broadcast_plmn_index[0]],
s1ap_eNB_instance_p->mnc_digit_length[ue_context_p->mme_ref->broadcast_plmn_index[0]],
&ie->value.choice.EUTRAN_CGI.pLMNidentity);
//#warning "TODO get cell id from RRC"
MACRO_ENB_ID_TO_CELL_IDENTITY(s1ap_eNB_instance_p->eNB_id,
......
......@@ -36,15 +36,29 @@
#include "s1ap_eNB_defs.h"
#include "s1ap_eNB_nnsf.h"
typedef struct MME_nnsf_inf {
struct s1ap_eNB_mme_data_s *mme_p;
uint64_t weight;
} MME_nnsf_inf_t;
struct s1ap_eNB_mme_data_s *
s1ap_eNB_nnsf_select_mme(s1ap_eNB_instance_t *instance_p,
rrc_establishment_cause_t cause)
{
struct s1ap_eNB_mme_data_s *mme_data_p = NULL;
struct s1ap_eNB_mme_data_s *mme_highest_capacity_p = NULL;
uint8_t current_capacity = 0;
uint16_t capacity_sum = 0;
MME_nnsf_inf_t mme_inf[10];
int cnt;
int nb_mme = 0;
uint64_t weight = 0;
memset(mme_inf, 0, sizeof(mme_inf));
RB_FOREACH(mme_data_p, s1ap_mme_map, &instance_p->s1ap_mme_head) {
capacity_sum = capacity_sum + mme_data_p->relative_mme_capacity;
if (mme_data_p->state != S1AP_ENB_STATE_CONNECTED) {
/* The association between MME and eNB is not ready for the moment,
* go to the next known MME.
......@@ -69,7 +83,8 @@ s1ap_eNB_nnsf_select_mme(s1ap_eNB_instance_t *instance_p,
|| (cause == RRC_CAUSE_HIGH_PRIO_ACCESS))) {
continue;
}
mme_inf[nb_mme].mme_p = mme_data_p;
nb_mme++;
/* At this point, the RRC establishment can be handled by the MME
* even if it is in overload state.
*/
......@@ -78,14 +93,27 @@ s1ap_eNB_nnsf_select_mme(s1ap_eNB_instance_t *instance_p,
continue;
}
}
if (current_capacity < mme_data_p->relative_mme_capacity) {
/* We find a better MME, keep a reference to it */
current_capacity = mme_data_p->relative_mme_capacity;
mme_highest_capacity_p = mme_data_p;
}
if( nb_mme != 0 ) {
for( cnt = 0 ; cnt < nb_mme ; cnt++ ) {
mme_inf[cnt].weight = (capacity_sum*10)/mme_inf[cnt].mme_p->relative_mme_capacity;
mme_inf[cnt].weight = (mme_inf[cnt].weight)*(mme_inf[cnt].mme_p->nb_calls + 1);
}
mme_highest_capacity_p = mme_inf[0].mme_p;
weight = mme_inf[0].weight;
for( cnt = 1 ; cnt < nb_mme ; cnt++ ) {
if( weight > mme_inf[cnt].weight ) {