diff --git a/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c b/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c index 2ae914ce53..099ff37954 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c +++ b/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c @@ -288,7 +288,7 @@ int nr_dlsch_encoding(PHY_VARS_gNB *gNB, } G = nr_get_G(nb_rb, nb_symb_sch, nb_re_dmrs, length_dmrs,mod_order,rel15->nrOfLayers); - LOG_D(PHY,"dlsch coding A %d G %d (nb_rb %d, nb_symb_sch %d, nb_re_dmrs %d, length_dmrs %d, mod_order %d mod_order %d)\n", A,G, nb_rb,nb_symb_sch,nb_re_dmrs,length_dmrs,mod_order); + LOG_D(PHY,"dlsch coding A %d G %d (nb_rb %d, nb_symb_sch %d, nb_re_dmrs %d, length_dmrs %d, mod_order %d mod_order %d)\n", A,G, nb_rb,nb_symb_sch,nb_re_dmrs,length_dmrs,(int)mod_order); if (A > 3824) { // Add 24-bit crc (polynomial A) to payload diff --git a/openair1/PHY/NR_TRANSPORT/nr_ulsch.c b/openair1/PHY/NR_TRANSPORT/nr_ulsch.c index f23c4e530f..e6b709b2aa 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_ulsch.c +++ b/openair1/PHY/NR_TRANSPORT/nr_ulsch.c @@ -151,7 +151,8 @@ void dump_pusch_stats(FILE *fd,PHY_VARS_gNB *gNB) { aa,gNB->ulsch_stats[i].power[aa]/10,gNB->ulsch_stats[i].power[aa]%10, aa,gNB->ulsch_stats[i].noise_power[aa]/10,gNB->ulsch_stats[i].noise_power[aa]%10); else stroff+=sprintf(output+stroff," ulsch_power[%d] %d.%d, ulsch_noise_power[%d] %d.%d\n", - aa,gNB->ulsch_stats[i].noise_power[aa]/10,gNB->ulsch_stats[i].noise_power[aa]%10); + aa,gNB->ulsch_stats[i].power[aa]/10,gNB->ulsch_stats[i].power[aa]%10, + gNB->ulsch_stats[i].noise_power[aa]/10,gNB->ulsch_stats[i].noise_power[aa]%10); AssertFatal(stroff<(STATSTRLEN-1000),"Increase STATSTRLEN\n"); diff --git a/openair1/SIMULATION/NR_PHY/dlsim.c b/openair1/SIMULATION/NR_PHY/dlsim.c index d53041aa74..ac49d6d7ed 100644 --- a/openair1/SIMULATION/NR_PHY/dlsim.c +++ b/openair1/SIMULATION/NR_PHY/dlsim.c @@ -227,7 +227,8 @@ void nr_dlsim_preprocessor(module_id_t module_id, /* manually set free CCE to 0 */ const int target_ss = NR_SearchSpace__searchSpaceType_PR_ue_Specific; - sched_ctrl->search_space = get_searchspace(sched_ctrl->active_bwp, target_ss); + NR_ServingCellConfigCommon_t *scc = RC.nrmac[module_id]->common_channels[0].ServingCellConfigCommon; + sched_ctrl->search_space = get_searchspace(scc, sched_ctrl->active_bwp, target_ss); uint8_t nr_of_candidates; find_aggregation_candidates(&sched_ctrl->aggregation_level, &nr_of_candidates, diff --git a/openair2/RRC/NR/L2_nr_interface.c b/openair2/RRC/NR/L2_nr_interface.c index a67eef2a64..6b9ff4bdc4 100644 --- a/openair2/RRC/NR/L2_nr_interface.c +++ b/openair2/RRC/NR/L2_nr_interface.c @@ -43,6 +43,8 @@ #include "NR_MIB.h" #include "NR_BCCH-BCH-Message.h" #include "rrc_gNB_UE_context.h" +#include + extern RAN_CONTEXT_t RC; diff --git a/openair2/RRC/NR/MESSAGES/asn1_msg.c b/openair2/RRC/NR/MESSAGES/asn1_msg.c index 921322fbdf..47dadb9c23 100755 --- a/openair2/RRC/NR/MESSAGES/asn1_msg.c +++ b/openair2/RRC/NR/MESSAGES/asn1_msg.c @@ -1034,7 +1034,7 @@ void fill_initial_SpCellConfig(rnti_t rnti, AssertFatal(scc->downlinkConfigCommon->initialDownlinkBWP->genericParameters.subcarrierSpacing==NR_SubcarrierSpacing_kHz30, "SCS != 30kHz\n"); AssertFatal(scc->tdd_UL_DL_ConfigurationCommon->pattern1.dl_UL_TransmissionPeriodicity==NR_TDD_UL_DL_Pattern__dl_UL_TransmissionPeriodicity_ms5, - "TDD period != 5ms : %ld\n",scc->tdd_UL_DL_ConfigurationCommon->pattern1.dl_UL_TransmissionPeriodicity); + "TDD period != 5ms : %d\n",scc->tdd_UL_DL_ConfigurationCommon->pattern1.dl_UL_TransmissionPeriodicity); schedulingRequestResourceConfig->periodicityAndOffset->choice.sl40 = 10*((rnti>>1)&3) + (rnti&2); schedulingRequestResourceConfig->resource = calloc(1,sizeof(*schedulingRequestResourceConfig->resource)); diff --git a/openair2/RRC/NR/rrc_gNB.c b/openair2/RRC/NR/rrc_gNB.c index 5278cea675..3225009652 100755 --- a/openair2/RRC/NR/rrc_gNB.c +++ b/openair2/RRC/NR/rrc_gNB.c @@ -1015,7 +1015,7 @@ rrc_gNB_generate_dedicatedRRCReconfiguration( break; default: - LOG_E(NR_RRC,"not supported 5qi %d\n", ue_context_pP->ue_context.pdusession[i].param.qos[qos_flow_index].fiveQI); + LOG_E(NR_RRC,"not supported 5qi %lu\n", ue_context_pP->ue_context.pdusession[i].param.qos[qos_flow_index].fiveQI); ue_context_pP->ue_context.pdusession[i].status = PDU_SESSION_STATUS_FAILED; ue_context_pP->ue_context.pdusession[i].xid = xid; pdu_sessions_done++; diff --git a/openair3/ocp-gtpu/gtp_itf.cpp b/openair3/ocp-gtpu/gtp_itf.cpp index e4d3945469..c50d5699cf 100644 --- a/openair3/ocp-gtpu/gtp_itf.cpp +++ b/openair3/ocp-gtpu/gtp_itf.cpp @@ -85,7 +85,7 @@ class gtpEndPoints { gtpEndPoints globGtp; - // note TEid 0 is reserved for specific usage: echo req/resp, error and supported extensions +// note TEid 0 is reserved for specific usage: echo req/resp, error and supported extensions static uint32_t gtpv1uNewTeid(void) { #ifdef GTPV1U_LINEAR_TEID_ALLOCATION g_gtpv1u_teid = g_gtpv1u_teid + 1; @@ -121,8 +121,10 @@ static int gtpv1uCreateAndSendMsg(int h, uint32_t peerIp, uint16_t peerPort, te msgHdr->version=1; msgHdr->msgType=GTP_GPDU; msgHdr->msgLength=htons(msgLen); + if ( seqNumFlag || extHdrFlag || npduNumFlag) msgHdr->msgLength+=4; + msgHdr->teid=htonl(teid); if(seqNumFlag || extHdrFlag || npduNumFlag) { @@ -191,7 +193,48 @@ static void gtpv1uSend(instance_t instance, gtpv1u_enb_tunnel_data_req_t *req, b tmp.teid_outgoing, buffer, length, seqNumFlag, npduNumFlag, false, tmp.seqNum, tmp.npduNum, 0) ; } - + +static void gtpv1uSend2(instance_t instance, gtpv1u_gnb_tunnel_data_req_t *req, bool seqNumFlag, bool npduNumFlag) { + uint8_t *buffer=req->buffer+req->offset; + size_t length=req->length; + uint64_t rnti=req->rnti; + int rab_id=req->pdusession_id; + pthread_mutex_lock(&globGtp.gtp_lock); + auto inst=&globGtp.instances[compatInst(instance)]; + auto ptrRnti=inst->ue2te_mapping.find(rnti); + + if ( ptrRnti==inst->ue2te_mapping.end() ) { + LOG_E(GTPU, "gtpv1uSend failed: while getting ue rnti %lx in hashtable ue_mapping\n", rnti); + pthread_mutex_unlock(&globGtp.gtp_lock); + return; + } + + auto ptr=ptrRnti->second.bearers; + + if ( ptr.find(rab_id) == ptr.end() ) { + LOG_E(GTPU,"sending a packet to a non existant RNTI:RAB: %lx/%x\n", rnti, rab_id); + pthread_mutex_unlock(&globGtp.gtp_lock); + return; + } else + LOG_D(GTPU,"sending a packet to RNTI:RAB:teid %lx/%x/%x, len %lu, oldseq %d, oldnum %d\n", + rnti, rab_id,ptr[rab_id].teid_outgoing,length, ptr[rab_id].seqNum,ptr[rab_id].npduNum ); + + if(seqNumFlag) + ptr[rab_id].seqNum++; + + if(npduNumFlag) + ptr[rab_id].npduNum++; + + // We will release the lock, let's copy data before + ocp_gtpv1u_bearer_t tmp=ptr[rab_id]; + pthread_mutex_unlock(&globGtp.gtp_lock); + gtpv1uCreateAndSendMsg(compatInst(instance), + tmp.outgoing_ip_addr, + tmp.outgoing_port, + tmp.teid_outgoing, + buffer, length, seqNumFlag, npduNumFlag, false, tmp.seqNum, tmp.npduNum, 0) ; +} + static void gtpv1uEndTunnel(instance_t instance, gtpv1u_enb_tunnel_data_req_t *req) { uint64_t rnti=req->rnti; int rab_id=req->rab_id; @@ -214,9 +257,9 @@ static void gtpv1uEndTunnel(instance_t instance, gtpv1u_enb_tunnel_data_req_t *r } else LOG_D(GTPU,"sending a end packet packet to RNTI:RAB:teid %lx/%x/%x\n", rnti, rab_id,ptr[rab_id].teid_outgoing); + ocp_gtpv1u_bearer_t tmp=ptr[rab_id]; pthread_mutex_unlock(&globGtp.gtp_lock); - Gtpv1uMsgHeaderT msgHdr; // N should be 0 for us (it was used only in 2G and 3G) msgHdr.PN=0; @@ -229,7 +272,6 @@ static void gtpv1uEndTunnel(instance_t instance, gtpv1u_enb_tunnel_data_req_t *r msgHdr.msgType=GTP_END_MARKER; msgHdr.msgLength=htons(0); msgHdr.teid=htonl(tmp.teid_outgoing); - // Fix me: add IPv6 support, using flag ipVersion static struct sockaddr_in to= {0}; to.sin_family = AF_INET; @@ -243,7 +285,7 @@ static void gtpv1uEndTunnel(instance_t instance, gtpv1u_enb_tunnel_data_req_t *r compatInst(instance), IPV4_ADDR_FORMAT(tmp.outgoing_ip_addr), tmp.outgoing_port, sizeof(msgHdr)); } } - + static int udpServerSocket(openAddr_s addr) { LOG_I(GTPU, "Initializing UDP for local address %s with port %s\n", addr.originHost, addr.originService); int status; @@ -280,7 +322,7 @@ static int udpServerSocket(openAddr_s addr) { memcpy(globGtp.instances[sockfd].foundAddr, &ipv4->sin_addr.s_addr, sizeof(ipv4->sin_addr.s_addr)); globGtp.instances[sockfd].foundAddrLen=sizeof(ipv4->sin_addr.s_addr); - globGtp.instances[sockfd].ipVersion=4; + globGtp.instances[sockfd].ipVersion=4; break; } else if (p->ai_family == AF_INET6) { LOG_W(GTPU,"Local address is IP v6\n"); @@ -288,7 +330,7 @@ static int udpServerSocket(openAddr_s addr) { memcpy(globGtp.instances[sockfd].foundAddr, &ipv6->sin6_addr.s6_addr, sizeof(ipv6->sin6_addr.s6_addr)); globGtp.instances[sockfd].foundAddrLen=sizeof(ipv6->sin6_addr.s6_addr); - globGtp.instances[sockfd].ipVersion=6; + globGtp.instances[sockfd].ipVersion=6; } else AssertFatal(false,"Local address is not IPv4 or IPv6"); } @@ -344,7 +386,8 @@ instance_t ocp_gtpv1Init(openAddr_t context) { return id; } -teid_t newGtpuCreateTunnel(instance_t instance, rnti_t rnti, int bearer_id, teid_t teid, transport_layer_addr_t remoteAddr, int port, gtpCallback callBack) { +teid_t newGtpuCreateTunnel(instance_t instance, rnti_t rnti, int bearer_id, teid_t teid, + transport_layer_addr_t remoteAddr, int port, gtpCallback callBack) { pthread_mutex_lock(&globGtp.gtp_lock); auto inst=&globGtp.instances[instance]; auto it=inst->ue2te_mapping.find(rnti); @@ -459,20 +502,40 @@ int ocp_gtpv1u_update_s1u_tunnel( return 0; } - int gtpv1u_create_ngu_tunnel( const instance_t instanceP, - const gtpv1u_gnb_create_tunnel_req_t * const create_tunnel_req_pP, - gtpv1u_gnb_create_tunnel_resp_t * const create_tunnel_resp_pP) { - return !GTPNOK; - } - - int gtpv1u_update_ngu_tunnel( - const instance_t instanceP, - const gtpv1u_gnb_create_tunnel_req_t *const create_tunnel_req_pP, - const rnti_t prior_rnti - ) { - return GTPNOK; +int gtpv1u_create_ngu_tunnel( const instance_t instance, + const gtpv1u_gnb_create_tunnel_req_t *const create_tunnel_req, + gtpv1u_gnb_create_tunnel_resp_t *const create_tunnel_resp) { + LOG_D(GTPU, "Start create tunnels for RNTI %x, num_tunnels %d, sgw_S1u_teid %d\n", + create_tunnel_req->rnti, + create_tunnel_req->num_tunnels, + create_tunnel_req->upf_NGu_teid[0]); + + for (int i = 0; i < create_tunnel_req->num_tunnels; i++) { + teid_t teid=newGtpuCreateTunnel(compatInst(instance), create_tunnel_req->rnti, + create_tunnel_req->pdusession_id[i], + create_tunnel_req->upf_NGu_teid[i], + create_tunnel_req->upf_addr[i], 2152, + pdcp_data_req); + create_tunnel_resp->status=0; + create_tunnel_resp->rnti=create_tunnel_req->rnti; + create_tunnel_resp->num_tunnels=create_tunnel_req->num_tunnels; + create_tunnel_resp->gnb_NGu_teid[i]=teid; + memcpy(create_tunnel_resp->gnb_addr.buffer,globGtp.instances[compatInst(instance)].foundAddr, + globGtp.instances[compatInst(instance)].foundAddrLen); + create_tunnel_resp->gnb_addr.length= globGtp.instances[compatInst(instance)].foundAddrLen; } + return !GTPNOK; +} + +int gtpv1u_update_ngu_tunnel( + const instance_t instanceP, + const gtpv1u_gnb_create_tunnel_req_t *const create_tunnel_req_pP, + const rnti_t prior_rnti +) { + return GTPNOK; +} + int ocp_gtpv1u_create_x2u_tunnel( const instance_t instanceP, const gtpv1u_enb_create_x2u_tunnel_req_t *const create_tunnel_req_pP, @@ -510,10 +573,10 @@ int ocp_gtpv1u_delete_s1u_tunnel( const instance_t instance, return newGtpuDeleteTunnel(instance, req_pP->rnti); } - int gtpv1u_delete_x2u_tunnel( const instance_t instanceP, - const gtpv1u_enb_delete_tunnel_req_t * const req_pP, - int enbflag) { - return 0; +int gtpv1u_delete_x2u_tunnel( const instance_t instanceP, + const gtpv1u_enb_delete_tunnel_req_t *const req_pP, + int enbflag) { + return 0; } static int Gtpv1uHandleEchoReq(int h, @@ -546,15 +609,16 @@ static int Gtpv1uHandleSupportedExt(int h, return rc; } - // When end marker arrives, we notify the client with buffer size = 0 - // The client will likely call "delete tunnel" - // nevertheless we don't take the initiative +// When end marker arrives, we notify the client with buffer size = 0 +// The client will likely call "delete tunnel" +// nevertheless we don't take the initiative static int Gtpv1uHandleEndMarker(int h, uint8_t *msgBuf, uint32_t msgBufLen, uint16_t peerPort, uint32_t peerIp) { Gtpv1uMsgHeaderT *msgHdr = (Gtpv1uMsgHeaderT *) msgBuf; + if ( msgHdr->version != 1 || msgHdr->PT != 1 ) { LOG_E(GTPU, "Received a packet that is not GTP header\n"); return GTPNOK; @@ -570,6 +634,7 @@ static int Gtpv1uHandleEndMarker(int h, pthread_mutex_unlock(&globGtp.gtp_lock); return GTPNOK; } + // This context is not good for gtp // frame, ... has no meaning // manyother attributes may come from create tunnel @@ -607,7 +672,7 @@ static int Gtpv1uHandleEndMarker(int h, LOG_D(GTPU,"Received END marker packet for: teid:%x\n", ntohl(msgHdr->teid)); return !GTPNOK; } - + static int Gtpv1uHandleGpdu(int h, uint8_t *msgBuf, uint32_t msgBufLen, @@ -732,8 +797,8 @@ void gtpv1uReceiver(int h) { void *ocp_gtpv1uTask(void *args) { while(1) { /* Trying to fetch a message from the message queue. - If the queue is empty, this function will block till a - message is sent to the task. + If the queue is empty, this function will block till a + message is sent to the task. */ MessageDef *message_p = NULL; itti_receive_msg(OCP_GTPV1_U, &message_p); @@ -750,20 +815,27 @@ void *ocp_gtpv1uTask(void *args) { } break; + case GTPV1U_GNB_TUNNEL_DATA_REQ: { + gtpv1uSend2(compatInst(ITTI_MSG_DESTINATION_INSTANCE(message_p)), + >PV1U_GNB_TUNNEL_DATA_REQ(message_p), false, false); + itti_free(OCP_GTPV1_U, GTPV1U_GNB_TUNNEL_DATA_REQ(message_p).buffer); + } + break; + case TERMINATE_MESSAGE: break; case TIMER_HAS_EXPIRED: LOG_E(GTPU, "Received unexpected timer expired (no need of timers in this version) %s\n", ITTI_MSG_NAME(message_p)); break; - - case GTPV1U_ENB_END_MARKER_REQ: - gtpv1uEndTunnel(compatInst(ITTI_MSG_DESTINATION_INSTANCE(message_p)), - >PV1U_ENB_TUNNEL_DATA_REQ(message_p)); - itti_free(OCP_GTPV1_U, GTPV1U_ENB_TUNNEL_DATA_REQ(message_p).buffer); - break; - - case GTPV1U_ENB_DATA_FORWARDING_REQ: + + case GTPV1U_ENB_END_MARKER_REQ: + gtpv1uEndTunnel(compatInst(ITTI_MSG_DESTINATION_INSTANCE(message_p)), + >PV1U_ENB_TUNNEL_DATA_REQ(message_p)); + itti_free(OCP_GTPV1_U, GTPV1U_ENB_TUNNEL_DATA_REQ(message_p).buffer); + break; + + case GTPV1U_ENB_DATA_FORWARDING_REQ: case GTPV1U_ENB_DATA_FORWARDING_IND: case GTPV1U_ENB_END_MARKER_IND: LOG_E(GTPU, "to be developped %s\n", ITTI_MSG_NAME(message_p)); @@ -777,7 +849,7 @@ void *ocp_gtpv1uTask(void *args) { AssertFatal((legacyInstanceMapping=ocp_gtpv1Init(addr))!=0,"Instance 0 reserved for legacy\n"); break; - case GTPV1U_GNB_NG_REQ: + case GTPV1U_GNB_NG_REQ: // to be dev: should be removed, to use API strcpy(addr.originHost, GTPV1U_ENB_S1_REQ(message_p).addrStr); strcpy(addr.originService, GTPV1U_ENB_S1_REQ(message_p).portStr);