From aabb9dc4104d85ba6ed4ebae552c2720fa27a862 Mon Sep 17 00:00:00 2001 From: Navid Nikaein <navid.nikaein@eurecom.fr> Date: Tue, 22 Jul 2014 11:27:13 +0000 Subject: [PATCH] * breakdown MAC into multiple files based on the transport channel * update oaisim event handler to manage configuration event on runtime git-svn-id: http://svn.eurecom.fr/openair4G/trunk@5577 818b1a75-f10b-46b9-bf7c-635c3b92a50f --- openair1/PHY/LTE_TRANSPORT/print_stats.c | 4 +- openair1/PHY/TOOLS/time_meas.h | 4 +- openair2/LAYER2/MAC/config.c | 5 +- openair2/LAYER2/MAC/defs.h | 579 +-- openair2/LAYER2/MAC/eNB_scheduler.c | 4363 +---------------- openair2/LAYER2/MAC/eNB_scheduler_bch.c | 188 + openair2/LAYER2/MAC/eNB_scheduler_dlsch.c | 1914 ++++++++ openair2/LAYER2/MAC/eNB_scheduler_mch.c | 580 +++ .../LAYER2/MAC/eNB_scheduler_primitives.c | 503 ++ openair2/LAYER2/MAC/eNB_scheduler_ulsch.c | 861 ++++ openair2/LAYER2/MAC/extern.h | 4 +- openair2/LAYER2/MAC/l1_helpers.c | 6 +- openair2/LAYER2/MAC/main.c | 21 +- openair2/LAYER2/MAC/openair2_proc.c | 2 +- openair2/LAYER2/MAC/pre_processor.c | 28 +- openair2/LAYER2/MAC/proto.h | 607 +++ openair2/LAYER2/MAC/ra_procedures.c | 651 ++- openair2/LAYER2/MAC/rar_tools.c | 5 +- openair2/LAYER2/MAC/ue_procedures.c | 7 +- openair2/LAYER2/MAC/vars.h | 4 +- openair2/LAYER2/Makefile.inc | 5 + openair2/RRC/LITE/rrc_eNB.c | 1 + .../GENERIC-LTE-EPC/CONF/epc.pft.memphis.conf | 124 + .../SIMU/EXAMPLES/OSD/WEBXML/template_2.xml | 4 +- .../SIMU/EXAMPLES/OSD/WEBXML/template_4.xml | 5 +- .../SIMU/EXAMPLES/OSD/WEBXML/template_40.xml | 4 +- targets/SIMU/USER/event_handler.c | 3280 +++++++++++-- targets/SIMU/USER/event_handler.h | 17 +- targets/SIMU/USER/oaisim.c | 26 +- targets/SIMU/USER/oaisim.h | 6 +- targets/SIMU/USER/oaisim_config.c | 249 +- targets/SIMU/USER/oaisim_functions.c | 26 +- targets/SIMU/USER/sinr_sim.c | 8 +- 33 files changed, 8761 insertions(+), 5330 deletions(-) create mode 100644 openair2/LAYER2/MAC/eNB_scheduler_bch.c create mode 100644 openair2/LAYER2/MAC/eNB_scheduler_dlsch.c create mode 100644 openair2/LAYER2/MAC/eNB_scheduler_mch.c create mode 100644 openair2/LAYER2/MAC/eNB_scheduler_primitives.c create mode 100644 openair2/LAYER2/MAC/eNB_scheduler_ulsch.c create mode 100644 openair2/LAYER2/MAC/proto.h create mode 100755 targets/PROJECTS/GENERIC-LTE-EPC/CONF/epc.pft.memphis.conf diff --git a/openair1/PHY/LTE_TRANSPORT/print_stats.c b/openair1/PHY/LTE_TRANSPORT/print_stats.c index 18dc679f2c..0bdc2e9344 100644 --- a/openair1/PHY/LTE_TRANSPORT/print_stats.c +++ b/openair1/PHY/LTE_TRANSPORT/print_stats.c @@ -44,7 +44,9 @@ #include "PHY/extern.h" #include "SCHED/extern.h" - +#ifdef OPENAIR2 +#include "../openair2/LAYER2/MAC/proto.h" +#endif extern int mac_get_rrc_status(uint8_t Mod_id,uint8_t eNB_flag,uint8_t index); diff --git a/openair1/PHY/TOOLS/time_meas.h b/openair1/PHY/TOOLS/time_meas.h index 42a5f44d4b..92e30fde4f 100644 --- a/openair1/PHY/TOOLS/time_meas.h +++ b/openair1/PHY/TOOLS/time_meas.h @@ -27,8 +27,8 @@ static inline unsigned long long rdtsc_oai(void) { return x; } #elif defined(__x86_64__) -static inline unsigned long long rdtsc_oai() __attribute__((always_inline)); -static inline unsigned long long rdtsc_oai() { +static inline unsigned long long rdtsc_oai(void) __attribute__((always_inline)); +static inline unsigned long long rdtsc_oai(void) { unsigned long long a, d; __asm__ volatile ("rdtsc" : "=a" (a), "=d" (d)); return (d<<32) | a; diff --git a/openair2/LAYER2/MAC/config.c b/openair2/LAYER2/MAC/config.c index 204c59d3c3..490a26798f 100644 --- a/openair2/LAYER2/MAC/config.c +++ b/openair2/LAYER2/MAC/config.c @@ -28,8 +28,8 @@ *******************************************************************************/ /*! \file config.c * \brief UE and eNB configuration - * \author Raymond Knopp, Navid Nikaein - * \date 2013 + * \author Navid Nikaein and Raymond Knopp + * \date 2010 - 2014 * \version 0.1 * \email: navid.nikaein@eurecom.fr * @ingroup _mac @@ -45,6 +45,7 @@ #include "MeasObjectToAddModList.h" #include "TDD-Config.h" #include "defs.h" +#include "proto.h" #include "extern.h" #include "UTIL/LOG/log.h" #include "UTIL/LOG/vcd_signal_dumper.h" diff --git a/openair2/LAYER2/MAC/defs.h b/openair2/LAYER2/MAC/defs.h index a3b07dae45..f1cdf72594 100644 --- a/openair2/LAYER2/MAC/defs.h +++ b/openair2/LAYER2/MAC/defs.h @@ -28,7 +28,7 @@ *******************************************************************************/ /*! \file def.h * \brief MAC data structures, constant, and function prototype -* \author Raymond Knopp, Navid Nikaein +* \author Navid Nikaein and Raymond Knopp * \date 2011 * \version 0.5 * \email navid.nikaein@eurecom.fr @@ -534,6 +534,34 @@ typedef struct{ } UE_TEMPLATE; +typedef struct{ + //UL transmission bandwidth in RBs + uint8_t ul_bandwidth[MAX_NUM_LCID]; + //DL transmission bandwidth in RBs + uint8_t dl_bandwidth[MAX_NUM_LCID]; + + //To do GBR bearer + uint8_t min_ul_bandwidth[MAX_NUM_LCID]; + + uint8_t min_dl_bandwidth[MAX_NUM_LCID]; + + //aggregated bit rate of non-gbr bearer per UE + uint64_t ue_AggregatedMaximumBitrateDL; + //aggregated bit rate of non-gbr bearer per UE + uint64_t ue_AggregatedMaximumBitrateUL; + //CQI scheduling interval in subframes. + uint16_t cqiSchedInterval; + //Contention resolution timer used during random access + uint8_t mac_ContentionResolutionTimer; + + uint16_t max_allowed_rbs[MAX_NUM_LCID]; + + uint8_t max_mcs[MAX_NUM_LCID]; + + uint16_t priority[MAX_NUM_LCID]; + +} UE_sched_ctrl; + typedef struct { /// Flag to indicate this process is active boolean_t RA_active; @@ -655,7 +683,7 @@ typedef struct{ eNB_STATS eNB_stats; /// eNB to UE statistics eNB_UE_STATS eNB_UE_stats[NUMBER_OF_UE_MAX]; - + UE_sched_ctrl UE_sched_ctrl[NUMBER_OF_UE_MAX]; // MAC function execution peformance profiler time_stats_t eNB_scheduler; time_stats_t schedule_si; @@ -912,553 +940,6 @@ int rrc_mac_config_req(module_id_t module_idP, ); -/** \brief First stage of Random-Access Scheduling. Loops over the RA_templates and checks if RAR, Msg3 or its retransmission are to be scheduled in the subframe. It returns the total number of PRB used for RA SDUs. For Msg3 it retrieves the L3msg from RRC and fills the appropriate buffers. For the others it just computes the number of PRBs. Each DCI uses 3 PRBs (format 1A) -for the message. -@param Mod_id Instance ID of eNB -@param frame Frame index -@param subframe Subframe number on which to act -@param nprb Pointer to current PRB count -@param nCCE Pointer to current nCCE count -*/ -void schedule_RA(module_id_t module_idP,frame_t frameP,sub_frame_t subframe,uint8_t Msg3_subframe,uint8_t *nprb,unsigned int *nCCE); - -/** \brief First stage of SI Scheduling. Gets a SI SDU from RRC if available and computes the MCS required to transport it as a function of the SDU length. It assumes a length less than or equal to 64 bytes (MCS 6, 3 PRBs). -@param Mod_id Instance ID of eNB -@param frame Frame index -@param subframe Subframe number on which to act -@param Msg3_subframe Subframe where Msg3 will be transmitted -@param nprb Pointer to current PRB count -@param nCCE Pointer to current nCCE count -*/ -void schedule_SI(module_id_t module_idP,frame_t frameP,uint8_t *nprb,unsigned int *nCCE); - -/** \brief MBMS scheduling: Checking the position for MBSFN subframes. Create MSI, transfer MCCH from RRC to MAC, transfer MTCHs from RLC to MAC. Multiplexing MSI,MCCH&MTCHs. Return 1 if there are MBSFN data being allocated, otherwise return 0; -@param Mod_id Instance ID of eNB -@param frame Frame index -@param subframe Subframe number on which to act -*/ -int schedule_MBMS(module_id_t module_idP,frame_t frameP, sub_frame_t subframe); - -/** \brief check the mapping between sf allocation and sync area, Currently only supports 1:1 mapping -@param Mod_id Instance ID of eNB -@param mbsfn_sync_area index of mbsfn sync area -@param[out] index of sf pattern -*/ -int8_t get_mbsfn_sf_alloction (module_id_t module_idP, uint8_t mbsfn_sync_area); - -/** \brief check the mapping between sf allocation and sync area, Currently only supports 1:1 mapping -@param Mod_id Instance ID of eNB -@param mbsfn_sync_area index of mbsfn sync area -@param eNB_index index of eNB -@param[out] index of sf pattern -*/ -int8_t ue_get_mbsfn_sf_alloction (module_id_t module_idP, uint8_t mbsfn_sync_area, unsigned char eNB_index); - -/** \brief top ULSCH Scheduling for TDD (config 1-6). -@param Mod_id Instance ID of eNB -@param frame Frame index -@param subframe Subframe number on which to act -@param sched_subframe Subframe number where PUSCH is transmitted (for DAI lookup) -@param nCCE Pointer to current nCCE count -*/ -void schedule_ulsch(module_id_t module_idP,frame_t frameP,unsigned char cooperation_flag,sub_frame_t subframe,unsigned char sched_subframe,unsigned int *nCCE); - -/** \brief ULSCH Scheduling per RNTI TDD config (config 1-6). -@param Mod_id Instance ID of eNB -@param frame Frame index -@param subframe Subframe number on which to act -@param sched_subframe Subframe number where PUSCH is transmitted (for DAI lookup) -@param nCCE Pointer to current nCCE count -*/ -void schedule_ulsch_rnti(module_id_t module_idP, unsigned char cooperation_flag, frame_t frameP, sub_frame_t subframe, unsigned char sched_subframe, uint8_t granted_UEs, unsigned int *nCCE, unsigned int *nCCE_available, uint16_t *first_rb); - -/** \brief ULSCH Scheduling for CBA RNTI TDD config (config 1-6). -@param Mod_id Instance ID of eNB -@param frame Frame index -@param subframe Subframe number on which to act -@param sched_subframe Subframe number where PUSCH is transmitted (for DAI lookup) -@param nCCE Pointer to current nCCE count -*/ -void schedule_ulsch_cba_rnti(module_id_t module_idP, unsigned char cooperation_flag, frame_t frameP, sub_frame_t subframe, unsigned char sched_subframe, uint8_t granted_UEs, unsigned int *nCCE, unsigned int *nCCE_available, uint16_t *first_rb); - -/** \brief Second stage of DLSCH scheduling, after schedule_SI, schedule_RA and schedule_dlsch have been called. This routine first allocates random frequency assignments for SI and RA SDUs using distributed VRB allocations and adds the corresponding DCI SDU to the DCI buffer for PHY. It then loops over the UE specific DCIs previously allocated and fills in the remaining DCI fields related to frequency allocation. It assumes localized allocation of type 0 (DCI.rah=0). The allocation is done for tranmission modes 1,2,4. -@param Mod_id Instance of eNB -@param frame Frame index -@param subframe Index of subframe -@param rballoc Bitmask for allowable subband allocations -@param RA_scheduled RA was scheduled in this subframe -@param mbsfn_flag Indicates that this subframe is for MCH/MCCH -*/ -void fill_DLSCH_dci(module_id_t module_idP,frame_t frameP,sub_frame_t subframe,uint32_t rballoc,uint8_t RA_scheduled,int mbsfn_flag); - -/** \brief UE specific DLSCH scheduling. Retrieves next ue to be schduled from round-robin scheduler and gets the appropriate harq_pid for the subframe from PHY. If the process is active and requires a retransmission, it schedules the retransmission with the same PRB count and MCS as the first transmission. Otherwise it consults RLC for DCCH/DTCH SDUs (status with maximum number of available PRBS), builds the MAC header (timing advance sent by default) and copies -@param Mod_id Instance ID of eNB -@param frame Frame index -@param subframe Subframe on which to act -@param nb_rb_used0 Number of PRB used by SI/RA -@param nCCE_used Number of CCE used by SI/RA -@param mbsfn_flag Indicates that MCH/MCCH is in this subframe -*/ -void schedule_ue_spec(module_id_t module_idP,frame_t frameP,sub_frame_t subframe,uint16_t nb_rb_used0,unsigned int *nCCE_used,int mbsfn_flag); - -/** \brief Function for UE/PHY to compute PUSCH transmit power in power-control procedure. - @param Mod_id Module id of UE - @returns Po_NOMINAL_PUSCH (PREAMBLE_RECEIVED_TARGET_POWER+DELTA_PREAMBLE -*/ -int8_t get_Po_NOMINAL_PUSCH(module_id_t module_idP); - -/** \brief Function to compute DELTA_PREAMBLE from 36.321 (for RA power ramping procedure and Msg3 PUSCH power control policy) - @param Mod_id Module id of UE - @returns DELTA_PREAMBLE -*/ -int8_t get_DELTA_PREAMBLE(module_id_t module_idP); - -/** \brief Function for compute deltaP_rampup from 36.321 (for RA power ramping procedure and Msg3 PUSCH power control policy) - @param Mod_id Module id of UE - @returns deltaP_rampup -*/ -int8_t get_deltaP_rampup(module_id_t module_idP); - -//main.c - -void chbch_phy_sync_success(module_id_t module_idP,frame_t frameP,uint8_t eNB_index); - -void mrbch_phy_sync_failure(module_id_t module_idP, frame_t frameP,uint8_t free_eNB_index); - -int mac_top_init(int eMBMS_active, uint8_t cba_group_active, uint8_t HO_active); - -char layer2_init_UE(module_id_t module_idP); - -char layer2_init_eNB(module_id_t module_idP, uint8_t Free_ch_index); - -void mac_switch_node_function(module_id_t module_idP); - -int mac_init_global_param(void); - -void mac_top_cleanup(void); - -void mac_UE_out_of_sync_ind(module_id_t module_idP,frame_t frameP, uint16_t eNB_index); - - -// eNB functions -/* \brief This function assigns pre-available RBS to each UE in specified sub-bands before scheduling is done -@param Mod_id Instance ID of eNB -@param frame Index of frame -@param subframe Index of current subframe -@param dl_pow_off Pointer to store resulting power offset for DCI -@param pre_nb_available_rbs Pointer to store number of remaining rbs after scheduling -@param N_RBS Number of resource block groups -@param rb_alloc_sub Table of resource block groups allocated to each UE - */ - - -void dlsch_scheduler_pre_processor (module_id_t module_idP, - frame_t frameP, - sub_frame_t subframe, - uint8_t *dl_pow_off, - uint16_t *pre_nb_available_rbs, - int N_RBGS, - unsigned char rballoc_sub_UE[NUMBER_OF_UE_MAX][N_RBGS_MAX]); - -/* \brief Function to trigger the eNB scheduling procedure. It is called by PHY at the beginning of each subframe, \f$n$\f - and generates all DLSCH allocations for subframe \f$n\f$ and ULSCH allocations for subframe \f$n+k$\f. The resultant DCI_PDU is - ready after returning from this call. -@param Mod_id Instance ID of eNB -@param cooperation_flag Flag to indicated that this cell has cooperating nodes (i.e. that there are collaborative transport channels that -can be scheduled. -@param subframe Index of current subframe -@param calibration_flag Flag to indicate that eNB scheduler should schedule TDD auto-calibration PUSCH. -*/ -void eNB_dlsch_ulsch_scheduler(module_id_t module_idP, uint8_t cooperation_flag, frame_t frameP, sub_frame_t subframeP);//, int calibration_flag); - -/* \brief Function to retrieve result of scheduling (DCI) in current subframe. Can be called an arbitrary numeber of times after eNB_dlsch_ulsch_scheduler -in a given subframe. -@param Mod_id Instance ID of eNB -@param subframe Index of current subframe -@returns Pointer to generated DCI for subframe -*/ -DCI_PDU *get_dci_sdu(module_id_t module_idP,frame_t frameP,sub_frame_t subframe); - -/* \brief Function to indicate a received preamble on PRACH. It initiates the RA procedure. -@param Mod_id Instance ID of eNB -@param preamble_index index of the received RA request -@param timing_offset Offset in samples of the received PRACH w.r.t. eNB timing. This is used to -*/ -void initiate_ra_proc(module_id_t module_idP,frame_t frameP, uint16_t preamble_index,int16_t timing_offset,uint8_t sect_id,sub_frame_t subframe,uint8_t f_id); - -/* \brief Function in eNB to fill RAR pdu when requested by PHY. This provides a single RAR SDU for the moment and returns the t-CRNTI. -@param Mod_id Instance ID of eNB -@param dlsch_buffer Pointer to DLSCH input buffer -@param N_RB_UL Number of UL resource blocks -@returns t_CRNTI -*/ -uint16_t fill_rar(module_id_t module_idP, - frame_t frameP, - uint8_t *dlsch_buffer, - uint16_t N_RB_UL, - uint8_t input_buffer_length); - -/* \brief This function indicates the end of RA procedure and provides the l3msg received on ULSCH. -@param Mod_id Instance ID of eNB -@param rnti RNTI of UE transmitting l3msg -@param l3msg Pointer to received l3msg -*/ -void terminate_ra_proc(module_id_t module_idP,frame_t frameP, rnti_t rnti, uint8_t *l3msg, uint16_t l3msg_len); - -/* \brief Function to indicate a failed RA response. It removes all temporary variables related to the initial connection of a UE -@param Mod_id Instance ID of eNB -@param preamble_index index of the received RA request. -*/ -void cancel_ra_proc(module_id_t module_idP,frame_t frameP, uint16_t preamble_index); - -/* \brief Function to indicate a received SDU on ULSCH. -@param Mod_id Instance ID of eNB -@param rnti RNTI of UE transmitting the SR -@param sdu Pointer to received SDU -*/ -void rx_sdu(module_id_t module_idP, frame_t frameP, rnti_t rnti, uint8_t *sdu, uint16_t sdu_len); - -/* \brief Function to indicate a scheduled schduling request (SR) was received by eNB. -@param Mod_id Instance ID of eNB -@param rnti RNTI of UE transmitting the SR -@param subframe Index of subframe where SR was received -*/ -void SR_indication(module_id_t module_idP,frame_t frameP,rnti_t rnti, sub_frame_t subframe); - -uint8_t *get_dlsch_sdu(module_id_t module_idP,frame_t frameP,rnti_t rnti,uint8_t TBindex); - -/* \brief Function to retrieve MCH transport block and MCS used for MCH in this MBSFN subframe. Returns null if no MCH is to be transmitted -@param Mod_id Instance ID of eNB -@param frame Index of frame -@param subframe Index of current subframe -@param mcs Pointer to mcs used by PHY (to be filled by MAC) -@returns Pointer to MCH transport block and mcs for subframe -*/ -MCH_PDU *get_mch_sdu(uint8_t Mod_id,uint32_t frame,uint32_t subframe); - - -//added for ALU icic purpose -uint32_t Get_Cell_SBMap(module_id_t module_idP); -void UpdateSBnumber(module_id_t module_idP); -//end ALU's algo - - -void ue_mac_reset (module_id_t module_idP,uint8_t eNB_index); -void ue_init_mac (module_id_t module_idP); -void init_ue_sched_info(void); -void add_ue_ulsch_info (module_id_t module_idP, module_id_t ue_mod_idP, sub_frame_t subframe,UE_ULSCH_STATUS status); -void add_ue_dlsch_info (module_id_t module_idP, module_id_t ue_mod_idP, sub_frame_t subframe,UE_DLSCH_STATUS status); -module_id_t find_UE_id (module_id_t module_idP, rnti_t rnti) ; -rnti_t find_UE_RNTI (module_id_t module_idP, module_id_t ue_mod_idP); -uint8_t find_active_UEs (module_id_t module_idP); -boolean_t is_UE_active (module_id_t module_idP, module_id_t ue_mod_idP ); -uint8_t find_ulgranted_UEs(module_id_t module_idP); -uint8_t find_dlgranted_UEs(module_id_t module_idP); -uint8_t process_ue_cqi (module_id_t module_idP, module_id_t ue_mod_idP); - -int8_t find_active_UEs_with_traffic(module_id_t module_idP); - -uint8_t find_num_active_UEs_in_cbagroup(module_id_t module_idP, unsigned char group_id); -uint8_t UE_is_to_be_scheduled(module_id_t module_idP,uint8_t UE_id); -/** \brief Round-robin scheduler for ULSCH traffic. -@param Mod_id Instance ID for eNB -@param subframe Subframe number on which to act -@returns UE index that is to be scheduled if needed/room -*/ -module_id_t schedule_next_ulue(module_id_t module_idP, module_id_t ue_mod_idP,sub_frame_t subframe); - -/** \brief Round-robin scheduler for DLSCH traffic. -@param Mod_id Instance ID for eNB -@param subframe Subframe number on which to act -@returns UE index that is to be scheduled if needed/room -*/ -module_id_t schedule_next_dlue(module_id_t module_idP, sub_frame_t subframe); - -/* \brief Allocates a set of PRBS for a particular UE. This is a simple function for the moment, later it should process frequency-domain CQI information and/or PMI information. Currently it just returns the first PRBS that are available in the subframe based on the number requested. -@param UE_id Index of UE on which to act -@param nb_rb Number of PRBs allocated to UE by scheduler -@param rballoc Pointer to bit-map of current PRB allocation given to previous users/control channels. This is updated for subsequent calls to the routine. -@returns an rballoc bitmap for resource type 0 allocation (DCI). -*/ -uint32_t allocate_prbs(module_id_t ue_mod_idP,uint8_t nb_rb, uint32_t *rballoc); - -/* \fn uint32_t req_new_ulsch(module_id_t module_idP) -\brief check for a new transmission in any drb -@param Mod_id Instance id of UE in machine -@returns 1 for new transmission, 0 for none -*/ -uint32_t req_new_ulsch(module_id_t module_idP); - -/* \brief Get SR payload (0,1) from UE MAC -@param Mod_id Instance id of UE in machine -@param eNB_id Index of eNB that UE is attached to -@param rnti C_RNTI of UE -@param subframe subframe number -@returns 0 for no SR, 1 for SR -*/ -uint32_t ue_get_SR(module_id_t module_idP, frame_t frameP, uint8_t eNB_id,rnti_t rnti,sub_frame_t subframe); - -uint8_t get_ue_weight(module_id_t module_idP, module_id_t ue_mod_idP); - -// UE functions -void mac_out_of_sync_ind(module_id_t module_idP, frame_t frameP, uint16_t CH_index); - -void ue_decode_si(module_id_t module_idP, frame_t frame, uint8_t CH_index, void *pdu, uint16_t len); - - -void ue_send_sdu(module_id_t module_idP, frame_t frame, uint8_t *sdu,uint16_t sdu_len,uint8_t CH_index); - - -#ifdef Rel10 -/* \brief Called by PHY to transfer MCH transport block to ue MAC. -@param Mod_id Index of module instance -@param frame Frame index -@param sdu Pointer to transport block -@param sdu_len Length of transport block -@param eNB_index Index of attached eNB -@param sync_area the index of MBSFN sync area -*/ -void ue_send_mch_sdu(module_id_t module_idP,frame_t frameP,uint8_t *sdu,uint16_t sdu_len,uint8_t eNB_index,uint8_t sync_area) ; - -/*\brief Function to check if UE PHY needs to decode MCH for MAC. -@param Mod_id Index of protocol instance -@param frame Index of frame -@param subframe Index of subframe -@param eNB_index index of eNB for this MCH -@param[out] sync_area return the sync area -@param[out] mcch_active flag indicating whether this MCCH is active in this SF -*/ -int ue_query_mch(uint8_t Mod_id,uint32_t frame,sub_frame_t subframe, uint8_t eNB_index, uint8_t *sync_area, uint8_t *mcch_active); - -#endif - -/* \brief Called by PHY to get sdu for PUSCH transmission. It performs the following operations: Checks BSR for DCCH, DCCH1 and DTCH corresponding to previous values computed either in SR or BSR procedures. It gets rlc status indications on DCCH,DCCH1 and DTCH and forms BSR elements and PHR in MAC header. CRNTI element is not supported yet. It computes transport block for up to 3 SDUs and generates header and forms the complete MAC SDU. -@param Mod_id Instance id of UE in machine -@param eNB_id Index of eNB that UE is attached to -@param rnti C_RNTI of UE -@param subframe subframe number -@returns 0 for no SR, 1 for SR -*/ -void ue_get_sdu(module_id_t module_idP, frame_t frameP, sub_frame_t subframe, uint8_t eNB_index,uint8_t *ulsch_buffer,uint16_t buflen,uint8_t *access_mode); - -/* \brief Function called by PHY to retrieve information to be transmitted using the RA procedure. If the UE is not in PUSCH mode for a particular eNB index, this is assumed to be an Msg3 and MAC attempts to retrieves the CCCH message from RRC. If the UE is in PUSCH mode for a particular eNB index and PUCCH format 0 (Scheduling Request) is not activated, the MAC may use this resource for random-access to transmit a BSR along with the C-RNTI control element (see 5.1.4 from 36.321) -@param Mod_id Index of UE instance -@param New_Msg3 Flag to indicate this call is for a new Msg3 -@param subframe Index of subframe for PRACH transmission (0 ... 9) -@returns A pointer to a PRACH_RESOURCES_t */ -PRACH_RESOURCES_t *ue_get_rach(module_id_t module_idP,frame_t frameP,uint8_t new_Msg3,sub_frame_t subframe); - -/* \brief Function called by PHY to process the received RAR. It checks that the preamble matches what was sent by the eNB and provides the timing advance and t-CRNTI. -@param Mod_id Index of UE instance -@param dlsch_buffer Pointer to dlsch_buffer containing RAR PDU -@param t_crnti Pointer to PHY variable containing the T_CRNTI -@param preamble_index Preamble Index used by PHY to transmit the PRACH. This should match the received RAR to trigger the rest of -random-access procedure -@returns timing advance or 0xffff if preamble doesn't match -*/ -uint16_t ue_process_rar(module_id_t module_idP, frame_t frameP,uint8_t *dlsch_buffer,uint16_t *t_crnti,uint8_t preamble_index); - - -/* \brief Generate header for UL-SCH. This function parses the desired control elements and sdus and generates the header as described -in 36-321 MAC layer specifications. It returns the number of bytes used for the header to be used as an offset for the payload -in the ULSCH buffer. -@param mac_header Pointer to the first byte of the MAC header (UL-SCH buffer) -@param num_sdus Number of SDUs in the payload -@param short_padding Number of bytes for short padding (0,1,2) -@param sdu_lengths Pointer to array of SDU lengths -@param sdu_lcids Pointer to array of LCIDs (the order must be the same as the SDU length array) -@param power_headroom Pointer to power headroom command (NULL means not present in payload) -@param crnti Pointer to CRNTI command (NULL means not present in payload) -@param truncated_bsr Pointer to Truncated BSR command (NULL means not present in payload) -@param short_bsr Pointer to Short BSR command (NULL means not present in payload) -@param long_bsr Pointer to Long BSR command (NULL means not present in payload) -@param post_padding Number of bytes for padding at the end of MAC PDU -@returns Number of bytes used for header -*/ -unsigned char generate_ulsch_header(uint8_t *mac_header, - uint8_t num_sdus, - uint8_t short_padding, - uint16_t *sdu_lengths, - uint8_t *sdu_lcids, - POWER_HEADROOM_CMD *power_headroom, - uint16_t *crnti, - BSR_SHORT *truncated_bsr, - BSR_SHORT *short_bsr, - BSR_LONG *long_bsr, - unsigned short post_padding); - -/* \brief Parse header for UL-SCH. This function parses the received UL-SCH header as described -in 36-321 MAC layer specifications. It returns the number of bytes used for the header to be used as an offset for the payload -in the ULSCH buffer. -@param mac_header Pointer to the first byte of the MAC header (UL-SCH buffer) -@param num_ces Number of SDUs in the payload -@param num_sdu Number of SDUs in the payload -@param rx_ces Pointer to received CEs in the header -@param rx_lcids Pointer to array of LCIDs (the order must be the same as the SDU length array) -@param rx_lengths Pointer to array of SDU lengths -@returns Pointer to payload following header -*/ -uint8_t *parse_ulsch_header(uint8_t *mac_header, - uint8_t *num_ce, - uint8_t *num_sdu, - uint8_t *rx_ces, - uint8_t *rx_lcids, - uint16_t *rx_lengths, - uint16_t tx_lenght); - - -int l2_init(LTE_DL_FRAME_PARMS *frame_parms,int eMBMS_active, uint8_t cba_group_active, uint8_t HO_active); -int mac_init(void); -int8_t add_new_ue(module_id_t module_idP, rnti_t rnti); -int8_t mac_remove_ue(module_id_t enb_mod_idP, module_id_t ue_mod_idP); - -/*! \fn UE_L2_state_t ue_scheduler(module_id_t module_idP,frame_t frameP, sub_frame_t subframe, lte_subframe_t direction,uint8_t eNB_index) - \brief UE scheduler where all the ue background tasks are done. This function performs the following: 1) Trigger PDCP every 5ms 2) Call RRC for link status return to PHY3) Perform SR/BSR procedures for scheduling feedback 4) Perform PHR procedures. -\param[in] module_idP instance of the UE -\param[in] subframe t the subframe number -\param[in] direction subframe direction -\param[in] eNB_index instance of eNB -@returns L2 state (CONNETION_OK or CONNECTION_LOST or PHY_RESYNCH) -*/ -UE_L2_STATE_t ue_scheduler(module_id_t module_idP,frame_t frameP, sub_frame_t subframe, lte_subframe_t direction,uint8_t eNB_index); - -/*! \fn int use_cba_access(module_id_t module_idP,frame_t frameP,sub_frame_t subframe, uint8_t eNB_index); -\brief determine whether to use cba resource to transmit or not -\param[in] Mod_id instance of the UE -\param[in] frame the frame number -\param[in] subframe the subframe number -\param[in] eNB_index instance of eNB -\param[out] access(1) or postpone (0) -*/ -int use_cba_access(module_id_t module_idP,frame_t frameP,sub_frame_t subframe, uint8_t eNB_index); - -/*! \fn int get_bsr_lcgid (module_id_t module_idP); -\brief determine the lcgid for the bsr -\param[in] Mod_id instance of the UE -\param[out] lcgid -*/ -int get_bsr_lcgid (module_id_t module_idP); - -/*! \fn uint8_t get_bsr_len (module_id_t module_idP, uint16_t bufflen); -\brief determine whether the bsr is short or long assuming that the MAC pdu is built -\param[in] Mod_id instance of the UE -\param[in] bufflen size of phy transport block -\param[out] bsr_len size of bsr control element -*/ -uint8_t get_bsr_len (module_id_t module_idP, uint16_t buflen); - -/*! \fn BSR_SHORT * get_bsr_short(module_id_t module_idP, uint8_t bsr_len) -\brief get short bsr level -\param[in] Mod_id instance of the UE -\param[in] bsr_len indicator for no, short, or long bsr -\param[out] bsr_s pointer to short bsr -*/ -BSR_SHORT *get_bsr_short(module_id_t module_idP, uint8_t bsr_len); - -/*! \fn BSR_LONG * get_bsr_long(module_id_t module_idP, uint8_t bsr_len) -\brief get long bsr level -\param[in] Mod_id instance of the UE -\param[in] bsr_len indicator for no, short, or long bsr -\param[out] bsr_l pointer to long bsr -*/ -BSR_LONG * get_bsr_long(module_id_t module_idP, uint8_t bsr_len); - -/*! \fn boolean_t update_bsr(module_id_t module_idP, frame_t frameP, uint8_t lcid) - \brief get the rlc stats and update the bsr level for each lcid -\param[in] Mod_id instance of the UE -\param[in] frame Frame index -\param[in] lcid logical channel identifier -*/ -boolean_t update_bsr(module_id_t module_idP, frame_t frameP, uint8_t lcid, uint8_t lcgid); - -/*! \fn locate (int *table, int size, int value) - \brief locate the BSR level in the table as defined in 36.321. This function requires that he values in table to be monotonic, either increasing or decreasing. The returned value is not less than 0, nor greater than n-1, where n is the size of table. -\param[in] *table Pointer to BSR table -\param[in] size Size of the table -\param[in] value Value of the buffer -\return the index in the BSR_LEVEL table -*/ -uint8_t locate (const uint32_t *table, int size, int value); - - -/*! \fn int get_sf_periodicBSRTimer(uint8_t periodicBSR_Timer) - \brief get the number of subframe from the periodic BSR timer configured by the higher layers -\param[in] periodicBSR_Timer timer for periodic BSR -\return the number of subframe -*/ -int get_sf_periodicBSRTimer(uint8_t bucketSize); - -/*! \fn int get_ms_bucketsizeduration(uint8_t bucketSize) - \brief get the time in ms form the bucket size duration configured by the higher layer -\param[in] bucketSize the bucket size duration -\return the time in ms -*/ -int get_ms_bucketsizeduration(uint8_t bucketsizeduration); - -/*! \fn int get_sf_retxBSRTimer(uint8_t retxBSR_Timer) - \brief get the number of subframe form the bucket size duration configured by the higher layer -\param[in] retxBSR_Timer timer for regular BSR -\return the time in sf -*/ -int get_sf_retxBSRTimer(uint8_t retxBSR_Timer); - -/*! \fn int get_sf_perioidicPHR_Timer(uint8_t perioidicPHR_Timer){ - \brief get the number of subframe form the periodic PHR timer configured by the higher layer -\param[in] perioidicPHR_Timer timer for reguluar PHR -\return the time in sf -*/ -int get_sf_perioidicPHR_Timer(uint8_t perioidicPHR_Timer); - -/*! \fn int get_sf_prohibitPHR_Timer(uint8_t prohibitPHR_Timer) - \brief get the number of subframe form the prohibit PHR duration configured by the higher layer -\param[in] prohibitPHR_Timer timer for PHR -\return the time in sf -*/ -int get_sf_prohibitPHR_Timer(uint8_t prohibitPHR_Timer); - -/*! \fn int get_db_dl_PathlossChange(uint8_t dl_PathlossChange) - \brief get the db form the path loss change configured by the higher layer -\param[in] dl_PathlossChange path loss for PHR -\return the pathloss in db -*/ -int get_db_dl_PathlossChange(uint8_t dl_PathlossChange); - -/*! \fn uint8_t get_phr_mapping (module_id_t module_idP, uint8_t eNB_index) - \brief get phr mapping as described in 36.313 -\param[in] Mod_id index of eNB -\return phr mapping -*/ -uint8_t get_phr_mapping (module_id_t module_idP, uint8_t eNB_index); - -/*! \fn void update_phr (module_id_t module_idP) - \brief update/reset the phr timers -\param[in] Mod_id index of eNB -\return void -*/ -void update_phr (module_id_t module_idP); - -/*! \brief Function to indicate Msg3 transmission/retransmission which initiates/reset Contention Resolution Timer -\param[in] Mod_id Instance index of UE -\param[in] eNB_id Index of eNB -*/ -void Msg3_tx(module_id_t module_idP,frame_t frameP,uint8_t eNB_id); - - -/*! \brief Function to indicate the transmission of msg1/rach -\param[in] Mod_id Instance index of UE -\param[in] eNB_id Index of eNB -*/ - -void Msg1_tx(module_id_t module_idP,frame_t frameP, uint8_t eNB_id); - -void dl_phy_sync_success(module_id_t module_idP, - frame_t frameP, - unsigned char eNB_index, - uint8_t first_sync); - -int dump_eNB_l2_stats(char *buffer, int length); - -double uniform_rngen(int min, int max); /*@}*/ #endif /*__LAYER2_MAC_DEFS_H__ */ diff --git a/openair2/LAYER2/MAC/eNB_scheduler.c b/openair2/LAYER2/MAC/eNB_scheduler.c index dd163c4649..31c94bc9ff 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler.c +++ b/openair2/LAYER2/MAC/eNB_scheduler.c @@ -28,8 +28,8 @@ *******************************************************************************/ /*! \file eNB_scheduler.c * \brief procedures related to UE - * \author Raymond Knopp, Navid Nikaein - * \date 2011 + * \author Navid Nikaein and Raymond Knopp + * \date 2010 - 2014 * \email: navid.nikaein@eurecom.fr * \version 0.5 * @ingroup _mac @@ -45,4348 +45,40 @@ #include "LAYER2/MAC/defs.h" #include "LAYER2/MAC/extern.h" -#include "UTIL/LOG/log.h" -#include "UTIL/LOG/vcd_signal_dumper.h" -#include "UTIL/OPT/opt.h" -#include "OCG.h" -#include "OCG_extern.h" -#include "ARCH/CBMIMO1/DEVICE_DRIVER/extern.h" -#include "ARCH/CBMIMO1/DEVICE_DRIVER/defs.h" -#include "ARCH/CBMIMO1/DEVICE_DRIVER/from_grlib_softregs.h" - -#include "RRC/LITE/extern.h" -#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h" - -//#include "LAYER2/MAC/pre_processor.c" -#include "pdcp.h" - -#if defined(ENABLE_ITTI) -# include "intertask_interface.h" -#endif - -#define ENABLE_MAC_PAYLOAD_DEBUG -#define DEBUG_eNB_SCHEDULER 1 -//#define DEBUG_HEADER_PARSING 1 -//#define DEBUG_PACKET_TRACE 1 - -/* - #ifndef USER_MODE - #define msg debug_msg - #endif - */ - -extern inline unsigned int taus(void); - - -void init_ue_sched_info(void){ - module_id_t i,j; - for (i=0;i<NUMBER_OF_eNB_MAX;i++){ - for (j=0;j<NUMBER_OF_UE_MAX;j++){ - // init DL - eNB_dlsch_info[i][j].weight = 0; - eNB_dlsch_info[i][j].subframe = 0; - eNB_dlsch_info[i][j].serving_num = 0; - eNB_dlsch_info[i][j].status = S_DL_NONE; - // init UL - eNB_ulsch_info[i][j].subframe = 0; - eNB_ulsch_info[i][j].serving_num = 0; - eNB_ulsch_info[i][j].status = S_UL_NONE; - } - } -} - -void add_ue_ulsch_info(module_id_t module_idP, module_id_t ue_mod_idP, sub_frame_t subframeP, UE_ULSCH_STATUS status){ - - eNB_ulsch_info[module_idP][ue_mod_idP].rnti = find_UE_RNTI(module_idP,ue_mod_idP); - eNB_ulsch_info[module_idP][ue_mod_idP].subframe = subframeP; - eNB_ulsch_info[module_idP][ue_mod_idP].status = status; - - eNB_ulsch_info[module_idP][ue_mod_idP].serving_num++; - -} -void add_ue_dlsch_info(module_id_t module_idP, module_id_t ue_mod_idP, sub_frame_t subframeP, UE_DLSCH_STATUS status){ - - eNB_dlsch_info[module_idP][ue_mod_idP].rnti = find_UE_RNTI(module_idP,ue_mod_idP); - // eNB_dlsch_info[module_idP][ue_mod_idP].weight = weight; - eNB_dlsch_info[module_idP][ue_mod_idP].subframe = subframeP; - eNB_dlsch_info[module_idP][ue_mod_idP].status = status; - - eNB_dlsch_info[module_idP][ue_mod_idP].serving_num++; - -} - -unsigned char get_ue_weight(module_id_t module_idP, module_id_t ue_mod_idP){ - - return(eNB_dlsch_info[module_idP][ue_mod_idP].weight); - -} - -// return is rnti ??? -module_id_t schedule_next_ulue(module_id_t module_idP, module_id_t ue_mod_idP, sub_frame_t subframeP){ - - module_id_t next_ue; - - // first phase: scheduling for ACK - switch (subframeP) { - // scheduling for subframeP 2: for scheduled user during subframeP 5 and 6 - case 8: - if ((eNB_dlsch_info[module_idP][ue_mod_idP].status == S_DL_SCHEDULED) && - (eNB_dlsch_info[module_idP][ue_mod_idP].subframe == 5 || eNB_dlsch_info[module_idP][ue_mod_idP].subframe == 6)){ - // set the downlink status - eNB_dlsch_info[module_idP][ue_mod_idP].status = S_DL_BUFFERED; - return ue_mod_idP; - } - break; - // scheduling for subframeP 3: for scheduled user during subframeP 7 and 8 - case 9: - if ((eNB_dlsch_info[module_idP][ue_mod_idP].status == S_DL_SCHEDULED) && - (eNB_dlsch_info[module_idP][ue_mod_idP].subframe == 7 || eNB_dlsch_info[module_idP][ue_mod_idP].subframe == 8)){ - eNB_dlsch_info[module_idP][ue_mod_idP].status = S_DL_BUFFERED; - return ue_mod_idP; - } - break; - // scheduling UL subframeP 4: for scheduled user during subframeP 9 and 0 - case 0 : - if ((eNB_dlsch_info[module_idP][ue_mod_idP].status == S_DL_SCHEDULED) && - (eNB_dlsch_info[module_idP][ue_mod_idP].subframe == 9 || eNB_dlsch_info[module_idP][ue_mod_idP].subframe == 0)){ - eNB_dlsch_info[module_idP][ue_mod_idP].status = S_DL_BUFFERED; - return ue_mod_idP; - } - break; - default: - break; - } - - // second phase - for (next_ue=0; next_ue <NUMBER_OF_UE_MAX; next_ue++ ){ - - if (eNB_ulsch_info[module_idP][next_ue].status == S_UL_WAITING ) - return next_ue; - else if (eNB_ulsch_info[module_idP][next_ue].status == S_UL_SCHEDULED){ - eNB_ulsch_info[module_idP][next_ue].status = S_UL_BUFFERED; - } - } - for (next_ue=0; next_ue <NUMBER_OF_UE_MAX; next_ue++ ){ - if (eNB_ulsch_info[module_idP][next_ue].status != S_UL_NONE )// do this just for active UEs - eNB_ulsch_info[module_idP][next_ue].status = S_UL_WAITING; - } - next_ue = 0; - return next_ue; - -} - -module_id_t schedule_next_dlue(module_id_t module_idP, sub_frame_t subframeP){ - - module_id_t next_ue; - - for (next_ue=0; next_ue < NUMBER_OF_UE_MAX; next_ue++ ){ - if (eNB_dlsch_info[module_idP][next_ue].status == S_DL_WAITING) - return next_ue; - } - for (next_ue=0; next_ue <NUMBER_OF_UE_MAX; next_ue++ ) - if (eNB_dlsch_info[module_idP][next_ue].status == S_DL_BUFFERED) { - eNB_dlsch_info[module_idP][next_ue].status = S_DL_WAITING; - } - // next_ue = -1; - return (module_id_t)(-1);//next_ue; - -} - -void initiate_ra_proc(module_id_t module_idP, frame_t frameP, uint16_t preamble_index,int16_t timing_offset,uint8_t sect_id,sub_frame_t subframeP,uint8_t f_id) { - - uint8_t i; - - LOG_I(MAC,"[eNB %d][RAPROC] Frame %d Initiating RA procedure for preamble index %d\n",module_idP,frameP,preamble_index); - - for (i=0;i<NB_RA_PROC_MAX;i++) { - if (eNB_mac_inst[module_idP].RA_template[i].RA_active==FALSE) { - eNB_mac_inst[module_idP].RA_template[i].RA_active=TRUE; - eNB_mac_inst[module_idP].RA_template[i].generate_rar=1; - eNB_mac_inst[module_idP].RA_template[i].generate_Msg4=0; - eNB_mac_inst[module_idP].RA_template[i].wait_ack_Msg4=0; - eNB_mac_inst[module_idP].RA_template[i].timing_offset=timing_offset; - // Put in random rnti (to be replaced with proper procedure!!) - eNB_mac_inst[module_idP].RA_template[i].rnti = taus(); - eNB_mac_inst[module_idP].RA_template[i].RA_rnti = 1+subframeP+(10*f_id); - eNB_mac_inst[module_idP].RA_template[i].preamble_index = preamble_index; - LOG_D(MAC,"[eNB %d][RAPROC] Frame %d Activating RAR generation for process %d, rnti %x, RA_active %d\n", - module_idP,frameP,i,eNB_mac_inst[module_idP].RA_template[i].rnti, - eNB_mac_inst[module_idP].RA_template[i].RA_active); - - return; - } - } -} - -void cancel_ra_proc(module_id_t module_idP, frame_t frameP, rnti_t rnti) { - unsigned char i; - LOG_I(MAC,"[eNB %d][RAPROC] Frame %d Cancelling RA procedure for UE rnti %x\n",module_idP,frameP,rnti); - - for (i=0;i<NB_RA_PROC_MAX;i++) { - if (rnti == eNB_mac_inst[module_idP].RA_template[i].rnti) { - eNB_mac_inst[module_idP].RA_template[i].RA_active=FALSE; - eNB_mac_inst[module_idP].RA_template[i].generate_rar=0; - eNB_mac_inst[module_idP].RA_template[i].generate_Msg4=0; - eNB_mac_inst[module_idP].RA_template[i].wait_ack_Msg4=0; - eNB_mac_inst[module_idP].RA_template[i].timing_offset=0; - eNB_mac_inst[module_idP].RA_template[i].RRC_timer=20; - eNB_mac_inst[module_idP].RA_template[i].rnti = 0; - } - } -} - -void terminate_ra_proc(module_id_t module_idP,frame_t frameP,rnti_t rnti,unsigned char *msg3, uint16_t msg3_len) { - - unsigned char rx_ces[MAX_NUM_CE],num_ce,num_sdu,i,*payload_ptr; - unsigned char rx_lcids[NB_RB_MAX]; - uint16_t rx_lengths[NB_RB_MAX]; - int8_t UE_id; - - LOG_I(MAC,"[eNB %d][RAPROC] Frame %d, Received msg3 %x.%x.%x.%x.%x.%x, Terminating RA procedure for UE rnti %x\n", - module_idP,frameP, - msg3[3],msg3[4],msg3[5],msg3[6],msg3[7], msg3[8], rnti); - - for (i=0;i<NB_RA_PROC_MAX;i++) { - LOG_D(MAC,"[RAPROC] Checking proc %d : rnti (%x, %x), active %d\n",i, - eNB_mac_inst[module_idP].RA_template[i].rnti, rnti, - eNB_mac_inst[module_idP].RA_template[i].RA_active); - if ((eNB_mac_inst[module_idP].RA_template[i].rnti==rnti) && - (eNB_mac_inst[module_idP].RA_template[i].RA_active==TRUE)) { - - payload_ptr = parse_ulsch_header(msg3,&num_ce,&num_sdu,rx_ces,rx_lcids,rx_lengths,msg3_len); - LOG_D(MAC,"[eNB %d][RAPROC] Frame %d Received CCCH: length %d, offset %d\n", - module_idP,frameP,rx_lengths[0],payload_ptr-msg3); - if (/*(num_ce == 0) &&*/ (num_sdu==1) && (rx_lcids[0] == CCCH)) { // This is an RRCConnectionRequest/Restablishment - memcpy(&eNB_mac_inst[module_idP].RA_template[i].cont_res_id[0],payload_ptr,6); - LOG_D(MAC,"[eNB %d][RAPROC] Frame %d Received CCCH: length %d, offset %d\n", - module_idP,frameP,rx_lengths[0],payload_ptr-msg3); - UE_id=add_new_ue(module_idP,eNB_mac_inst[module_idP].RA_template[i].rnti); - if (UE_id==-1) { - mac_xface->macphy_exit("[MAC][eNB] Max user count reached\n"); - } - else { - LOG_I(MAC,"[eNB %d][RAPROC] Frame %d Added user with rnti %x => UE %d\n", - module_idP,frameP,eNB_mac_inst[module_idP].RA_template[i].rnti,UE_id); - } - - if (Is_rrc_registered == 1) - mac_rrc_data_ind(module_idP,frameP,CCCH,(uint8_t *)payload_ptr,rx_lengths[0],1,module_idP,0); - // add_user. This is needed to have the rnti for configuring UE (PHY). The UE is removed if RRC - // doesn't provide a CCCH SDU - - } - else if (num_ce >0) { // handle msg3 which is not RRCConnectionRequest - // process_ra_message(msg3,num_ce,rx_lcids,rx_ces); - } - - eNB_mac_inst[module_idP].RA_template[i].generate_Msg4 = 1; - eNB_mac_inst[module_idP].RA_template[i].wait_ack_Msg4 = 0; - - return; - } // if process is active - - } // loop on RA processes -} - -DCI_PDU *get_dci_sdu(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP) { - - return(&eNB_mac_inst[module_idP].DCI_pdu); - -} - -module_id_t find_UE_id(module_id_t module_idP, rnti_t rnti) { - - module_id_t ue_mod_id; - - for (ue_mod_id=0;ue_mod_id<NUMBER_OF_UE_MAX;ue_mod_id++) { - // if (mac_get_rrc_status(module_idP,1,ue_mod_id) >= RRC_CONNECTED) { - if (eNB_mac_inst[module_idP].UE_template[ue_mod_id].rnti==rnti) { - return(ue_mod_id); - } - } - return(module_id_t)(-1); - -} - -rnti_t find_UE_RNTI(module_id_t module_idP, module_id_t ue_mod_idP) { - - return (eNB_mac_inst[module_idP].UE_template[ue_mod_idP].rnti); - -} -boolean_t is_UE_active(module_id_t module_idP, module_id_t ue_mod_idP ){ - if (eNB_mac_inst[module_idP].UE_template[ue_mod_idP].rnti !=0 ) - return TRUE; - else - return FALSE ; -} -uint8_t find_active_UEs(module_id_t module_idP){ - - module_id_t ue_mod_id = 0; - rnti_t rnti = 0; - uint8_t nb_active_ue = 0; - - for (ue_mod_id=0;ue_mod_id<NUMBER_OF_UE_MAX;ue_mod_id++) { - - if (((rnti=eNB_mac_inst[module_idP].UE_template[ue_mod_id].rnti) !=0)&&(eNB_mac_inst[module_idP].UE_template[ue_mod_id].ul_active==TRUE)){ - - if (mac_xface->get_eNB_UE_stats(module_idP,rnti) != NULL){ // check at the phy enb_ue state for this rnti - nb_active_ue++; - } - else { // this ue is removed at the phy => remove it at the mac as well - mac_remove_ue(module_idP, ue_mod_id); - } - } - } - return(nb_active_ue); -} - -// function for determining which active ue should be granted resources in uplink based on BSR+QoS -uint8_t find_ulgranted_UEs(module_id_t module_idP){ - - // all active users should be granted - return(find_active_UEs(module_idP)); -} - -// function for determining which active ue should be granted resources in downlink based on CQI, SI, and BSR -uint8_t find_dlgranted_UEs(module_id_t module_idP){ - - // all active users should be granted - return(find_active_UEs(module_idP)); -} -// get aggregatiob form phy for a give UE -unsigned char process_ue_cqi (module_id_t module_idP, module_id_t ue_mod_idP) { - unsigned char aggregation=2; - // check the MCS and SNR and set the aggregation accordingly - return aggregation; -} -#ifdef CBA -uint8_t find_num_active_UEs_in_cbagroup(module_id_t module_idP, unsigned char group_id){ - - module_id_t UE_id; - rnti_t rnti; - unsigned char nb_ue_in_pusch=0; - LTE_eNB_UE_stats* eNB_UE_stats; - - for (UE_id=group_id;UE_id<NUMBER_OF_UE_MAX;UE_id+=eNB_mac_inst[module_idP].num_active_cba_groups) { - - if (((rnti=eNB_mac_inst[module_idP].UE_template[UE_id].rnti) !=0) && - (eNB_mac_inst[module_idP].UE_template[UE_id].ul_active==TRUE) && - (mac_get_rrc_status(module_idP,1,UE_id) > RRC_CONNECTED)){ - // && (UE_is_to_be_scheduled(module_idP,UE_id))) - // check at the phy enb_ue state for this rnti - if ((eNB_UE_stats= mac_xface->get_eNB_UE_stats(module_idP,rnti)) != NULL){ - if ((eNB_UE_stats->mode == PUSCH) && (UE_is_to_be_scheduled(module_idP,UE_id) == 0)){ - nb_ue_in_pusch++; - } - } - } - } - return(nb_ue_in_pusch); -} -#endif -int8_t add_new_ue(module_id_t enb_mod_idP, rnti_t rntiP) { - module_id_t ue_mod_id; - int j; - - for (ue_mod_id=0;ue_mod_id<NUMBER_OF_UE_MAX;ue_mod_id++) { - if (eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].rnti == 0) { - eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].rnti = rntiP; - for (j=0;j<8;j++) { - eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].oldNDI[j] = 0; - eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].oldNDI_UL[j] = 0; - } - eNB_ulsch_info[enb_mod_idP][ue_mod_id].status = S_UL_WAITING; - eNB_dlsch_info[enb_mod_idP][ue_mod_id].status = S_UL_WAITING; - LOG_D(MAC,"[eNB] Add UE_id %d : rnti %x\n",ue_mod_id,eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].rnti); - return((int8_t)ue_mod_id); - } - } - return(-1); -} - -int8_t mac_remove_ue(module_id_t enb_mod_idP, module_id_t ue_mod_idP) { - - LOG_I(MAC,"Removing UE %d (rnti %x)\n",ue_mod_idP,eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_idP].rnti); - - // clear all remaining pending transmissions - eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_idP].bsr_info[LCGID0] = 0; - eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_idP].bsr_info[LCGID1] = 0; - eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_idP].bsr_info[LCGID2] = 0; - eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_idP].bsr_info[LCGID3] = 0; - - eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_idP].ul_SR = 0; - eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_idP].rnti = 0; - eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_idP].ul_active = FALSE; - eNB_ulsch_info[enb_mod_idP][ue_mod_idP].rnti = 0; - eNB_ulsch_info[enb_mod_idP][ue_mod_idP].status = S_UL_NONE; - eNB_dlsch_info[enb_mod_idP][ue_mod_idP].rnti = 0; - eNB_dlsch_info[enb_mod_idP][ue_mod_idP].status = S_DL_NONE; - - rrc_eNB_free_UE_index(enb_mod_idP,ue_mod_idP); - - return(1); -} - -unsigned char *get_dlsch_sdu(module_id_t module_idP, frame_t frameP, rnti_t rntiP, uint8_t TBindex) { - - module_id_t ue_mod_id; - - if (rntiP==SI_RNTI) { - LOG_D(MAC,"[eNB %d] Frame %d Get DLSCH sdu for BCCH \n",module_idP,frameP); - - return((unsigned char *)&eNB_mac_inst[module_idP].BCCH_pdu.payload[0]); - } - else if ((ue_mod_id = find_UE_id(module_idP,rntiP)) != UE_INDEX_INVALID ){ - LOG_D(MAC,"[eNB %d] Frame %d: Get DLSCH sdu for rnti %x => UE_id %d\n",module_idP,frameP,rntiP,ue_mod_id); - return((unsigned char *)&eNB_mac_inst[module_idP].DLSCH_pdu[ue_mod_id][TBindex].payload[0]); - } else { - LOG_E(MAC,"[eNB %d] Frame %d: UE with RNTI %x does not exist\n", module_idP,frameP,rntiP); - return NULL; - } - -} - -unsigned char *parse_ulsch_header(unsigned char *mac_header, - unsigned char *num_ce, - unsigned char *num_sdu, - unsigned char *rx_ces, - unsigned char *rx_lcids, - unsigned short *rx_lengths, - unsigned short tb_length) { - - unsigned char not_done=1,num_ces=0,num_sdus=0,lcid,num_sdu_cnt; - unsigned char *mac_header_ptr = mac_header; - unsigned short length, ce_len=0; - - while (not_done==1) { - - if (((SCH_SUBHEADER_FIXED *)mac_header_ptr)->E == 0) - not_done = 0; - - lcid = ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->LCID; - if (lcid < EXTENDED_POWER_HEADROOM) { - if (not_done==0) { // last MAC SDU, length is implicit - mac_header_ptr++; - length = tb_length-(mac_header_ptr-mac_header)-ce_len; - for (num_sdu_cnt=0; num_sdu_cnt < num_sdus ; num_sdu_cnt++) - length -= rx_lengths[num_sdu_cnt]; - } - else { - if (((SCH_SUBHEADER_SHORT *)mac_header_ptr)->F == 0) { - length = ((SCH_SUBHEADER_SHORT *)mac_header_ptr)->L; - mac_header_ptr += 2;//sizeof(SCH_SUBHEADER_SHORT); - } - else { // F = 1 - length = ((((SCH_SUBHEADER_LONG *)mac_header_ptr)->L_MSB & 0x7f ) << 8 ) | (((SCH_SUBHEADER_LONG *)mac_header_ptr)->L_LSB & 0xff); - mac_header_ptr += 3;//sizeof(SCH_SUBHEADER_LONG); - } - } - LOG_D(MAC,"[eNB] sdu %d lcid %d tb_length %d length %d (offset now %d)\n", - num_sdus,lcid,tb_length, length,mac_header_ptr-mac_header); - rx_lcids[num_sdus] = lcid; - rx_lengths[num_sdus] = length; - num_sdus++; - } - else { // This is a control element subheader POWER_HEADROOM, BSR and CRNTI - if (lcid == SHORT_PADDING) { - mac_header_ptr++; - } - else { - rx_ces[num_ces] = lcid; - num_ces++; - mac_header_ptr++; - if (lcid==LONG_BSR) - ce_len+=3; - else if (lcid==CRNTI) - ce_len+=2; - else if ((lcid==POWER_HEADROOM) || (lcid==TRUNCATED_BSR)|| (lcid== SHORT_BSR)) - ce_len++; - else { - LOG_E(MAC,"unknown CE %d \n", lcid); - exit(-1); - } - } - } - } - *num_ce = num_ces; - *num_sdu = num_sdus; - - return(mac_header_ptr); -} - -void SR_indication(module_id_t enb_mod_idP, frame_t frameP, rnti_t rntiP, sub_frame_t subframeP) { - - module_id_t ue_mod_id = find_UE_id(enb_mod_idP, rntiP); - - if (ue_mod_id != UE_INDEX_INVALID ) { - LOG_D(MAC,"[eNB %d][SR %x] Frame %d subframeP %d Signaling SR for UE %d \n",enb_mod_idP,rntiP,frameP,subframeP, ue_mod_id); - eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].ul_SR = 1; - eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].ul_active = TRUE; - } else { - // AssertFatal(0, "find_UE_id(%u,rnti %d) not found", enb_mod_idP, rntiP); - AssertError(0, 0, "Frame %d: find_UE_id(%u,rnti %d) not found\n", frameP, enb_mod_idP, rntiP); - } -} - -void rx_sdu(module_id_t enb_mod_idP,frame_t frameP,rnti_t rntiP,uint8_t *sdu, uint16_t sdu_len) { - - unsigned char rx_ces[MAX_NUM_CE],num_ce,num_sdu,i,*payload_ptr; - unsigned char rx_lcids[NB_RB_MAX]; - unsigned short rx_lengths[NB_RB_MAX]; - module_id_t ue_mod_id = find_UE_id(enb_mod_idP,rntiP); - int ii,j; - start_meas(&eNB_mac_inst[enb_mod_idP].rx_ulsch_sdu); - - if ((ue_mod_id > NUMBER_OF_UE_MAX) || (ue_mod_id == -1) || (ue_mod_id == 255) ) - - for(ii=0; ii<NB_RB_MAX; ii++) rx_lengths[ii] = 0; - - vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_RX_SDU,1); - - LOG_D(MAC,"[eNB %d] Received ULSCH sdu from PHY (rnti %x, UE_id %d), parsing header\n",enb_mod_idP,rntiP,ue_mod_id); - payload_ptr = parse_ulsch_header(sdu,&num_ce,&num_sdu,rx_ces,rx_lcids,rx_lengths,sdu_len); - - // control element - for (i=0;i<num_ce;i++) { - - switch (rx_ces[i]) { // implement and process BSR + CRNTI + - case POWER_HEADROOM: - if (ue_mod_id != UE_INDEX_INVALID ){ - eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].phr_info = (payload_ptr[0] & 0x3f);// - PHR_MAPPING_OFFSET; - LOG_D(MAC, "[eNB] MAC CE_LCID %d : Received PHR PH = %d (db)\n", rx_ces[i], eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].phr_info); - } - payload_ptr+=sizeof(POWER_HEADROOM_CMD); - break; - case CRNTI: - LOG_D(MAC, "[eNB] MAC CE_LCID %d : Received CRNTI %d \n", rx_ces[i], payload_ptr[0]); - payload_ptr+=1; - break; - case TRUNCATED_BSR: - case SHORT_BSR: { - if (ue_mod_id != UE_INDEX_INVALID ){ - uint8_t lcgid; - lcgid = (payload_ptr[0] >> 6); - LOG_D(MAC, "[eNB] MAC CE_LCID %d : Received short BSR LCGID = %u bsr = %d\n", - rx_ces[i], lcgid, payload_ptr[0] & 0x3f); - eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].bsr_info[lcgid] = (payload_ptr[0] & 0x3f); - } - payload_ptr += 1;//sizeof(SHORT_BSR); // fixme - } break; - case LONG_BSR: - if (ue_mod_id != UE_INDEX_INVALID ){ - eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].bsr_info[LCGID0] = ((payload_ptr[0] & 0xFC) >> 2); - eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].bsr_info[LCGID1] = - ((payload_ptr[0] & 0x03) << 4) | ((payload_ptr[1] & 0xF0) >> 4); - eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].bsr_info[LCGID2] = - ((payload_ptr[1] & 0x0F) << 2) | ((payload_ptr[2] & 0xC0) >> 6); - eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].bsr_info[LCGID3] = (payload_ptr[2] & 0x3F); - LOG_D(MAC, "[eNB] MAC CE_LCID %d: Received long BSR LCGID0 = %u LCGID1 = " - "%u LCGID2 = %u LCGID3 = %u\n", - rx_ces[i], - eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].bsr_info[LCGID0], - eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].bsr_info[LCGID1], - eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].bsr_info[LCGID2], - eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].bsr_info[LCGID3]); - } - payload_ptr += 3;////sizeof(LONG_BSR); - break; - default: - LOG_E(MAC, "[eNB] Received unknown MAC header (0x%02x)\n", rx_ces[i]); - break; - } - } - - for (i=0;i<num_sdu;i++) { - LOG_D(MAC,"SDU Number %d MAC Subheader SDU_LCID %d, length %d\n",i,rx_lcids[i],rx_lengths[i]); - - switch (rx_lcids[i]) { - case CCCH : - LOG_I(MAC,"[eNB %d][RAPROC] Frame %d, Received CCCH: %x.%x.%x.%x.%x.%x, Terminating RA procedure for UE rnti %x\n", - enb_mod_idP,frameP, - payload_ptr[0],payload_ptr[1],payload_ptr[2],payload_ptr[3],payload_ptr[4], payload_ptr[5], rntiP); - - for (ii=0;ii<NB_RA_PROC_MAX;ii++) { - LOG_D(MAC,"[RAPROC] Checking proc %d : rnti (%x, %x), active %d\n",ii, - eNB_mac_inst[enb_mod_idP].RA_template[ii].rnti, rntiP, - eNB_mac_inst[enb_mod_idP].RA_template[ii].RA_active); - - if ((eNB_mac_inst[enb_mod_idP].RA_template[ii].rnti==rntiP) && - (eNB_mac_inst[enb_mod_idP].RA_template[ii].RA_active==TRUE)) { - - //payload_ptr = parse_ulsch_header(msg3,&num_ce,&num_sdu,rx_ces,rx_lcids,rx_lengths,msg3_len); - - if (ue_mod_id == UE_INDEX_INVALID) { - memcpy(&eNB_mac_inst[enb_mod_idP].RA_template[ii].cont_res_id[0],payload_ptr,6); - LOG_I(MAC,"[eNB %d][RAPROC] Frame %d CCCH: Received RRCConnectionRequest: length %d, offset %d\n", - enb_mod_idP,frameP,rx_lengths[ii],payload_ptr-sdu); - if ((ue_mod_id=add_new_ue(enb_mod_idP,eNB_mac_inst[enb_mod_idP].RA_template[ii].rnti)) == -1 ) - mac_xface->macphy_exit("[MAC][eNB] Max user count reached\n"); - else - LOG_I(MAC,"[eNB %d][RAPROC] Frame %d Added user with rnti %x => UE %d\n", - enb_mod_idP,frameP,eNB_mac_inst[enb_mod_idP].RA_template[ii].rnti,ue_mod_id); - } else { - LOG_I(MAC,"[eNB %d][RAPROC] Frame %d CCCH: Received RRCConnectionReestablishment from UE %d: length %d, offset %d\n", - enb_mod_idP,frameP,ue_mod_id,rx_lengths[ii],payload_ptr-sdu); - } - - if (Is_rrc_registered == 1) - mac_rrc_data_ind(enb_mod_idP,frameP,CCCH,(uint8_t *)payload_ptr,rx_lengths[ii],1,enb_mod_idP,0); - - - if (num_ce >0) { // handle msg3 which is not RRCConnectionRequest - // process_ra_message(msg3,num_ce,rx_lcids,rx_ces); - } - - eNB_mac_inst[enb_mod_idP].RA_template[ii].generate_Msg4 = 1; - eNB_mac_inst[enb_mod_idP].RA_template[ii].wait_ack_Msg4 = 0; - - - } // if process is active - - } // loop on RA processes - - break; - case DCCH : - case DCCH1 : - // if(eNB_mac_inst[module_idP].Dcch_lchan[UE_id].Active==1){ - -#if defined(ENABLE_MAC_PAYLOAD_DEBUG) - LOG_T(MAC,"offset: %d\n",(unsigned char)((unsigned char*)payload_ptr-sdu)); - for (j=0;j<32;j++) - LOG_T(MAC,"%x ",payload_ptr[j]); - LOG_T(MAC,"\n"); -#endif - - // This check is just to make sure we didn't get a bogus SDU length, to be removed ... - if (rx_lengths[i]<CCCH_PAYLOAD_SIZE_MAX) { - LOG_D(MAC,"[eNB %d] Frame %d : ULSCH -> UL-DCCH, received %d bytes form UE %d on LCID %d(%d) \n", - enb_mod_idP,frameP, rx_lengths[i], ue_mod_id, rx_lcids[i], rx_lcids[i]); - - mac_rlc_data_ind(enb_mod_idP,ue_mod_id, frameP,ENB_FLAG_YES,MBMS_FLAG_NO, - rx_lcids[i], - (char *)payload_ptr, - rx_lengths[i], - 1, - NULL);//(unsigned int*)crc_status); - eNB_mac_inst[enb_mod_idP].eNB_UE_stats[ue_mod_id].num_pdu_rx[rx_lcids[i]]+=1; - eNB_mac_inst[enb_mod_idP].eNB_UE_stats[ue_mod_id].num_bytes_rx[rx_lcids[i]]+=rx_lengths[i]; - - } - // } - break; - case DTCH: // default DRB - // if(eNB_mac_inst[module_idP].Dcch_lchan[UE_id].Active==1){ - -#if defined(ENABLE_MAC_PAYLOAD_DEBUG) - LOG_T(MAC,"offset: %d\n",(unsigned char)((unsigned char*)payload_ptr-sdu)); - for (j=0;j<32;j++) - LOG_T(MAC,"%x ",payload_ptr[j]); - LOG_T(MAC,"\n"); -#endif - - LOG_D(MAC,"[eNB %d] Frame %d : ULSCH -> UL-DTCH, received %d bytes from UE %d for lcid %d (%d)\n", - enb_mod_idP,frameP, rx_lengths[i], ue_mod_id,rx_lcids[i],rx_lcids[i]); - - if ((rx_lengths[i] <SCH_PAYLOAD_SIZE_MAX) && (rx_lengths[i] > 0) ) { // MAX SIZE OF transport block - mac_rlc_data_ind(enb_mod_idP,ue_mod_id, frameP,ENB_FLAG_YES,MBMS_FLAG_NO, - DTCH, - (char *)payload_ptr, - rx_lengths[i], - 1, - NULL);//(unsigned int*)crc_status); - eNB_mac_inst[enb_mod_idP].eNB_UE_stats[ue_mod_id].num_pdu_rx[rx_lcids[i]]+=1; - eNB_mac_inst[enb_mod_idP].eNB_UE_stats[ue_mod_id].num_bytes_rx[rx_lcids[i]]+=rx_lengths[i]; - - } - // } - break; - default : //if (rx_lcids[i] >= DTCH) { - eNB_mac_inst[enb_mod_idP].eNB_UE_stats[ue_mod_id].num_errors_rx+=1; - LOG_E(MAC,"[eNB %d] received unsupported or unknown LCID %d from UE %d ", rx_lcids[i], ue_mod_id); - break; - } - payload_ptr+=rx_lengths[i]; - - } - - eNB_mac_inst[enb_mod_idP].eNB_UE_stats[ue_mod_id].total_pdu_bytes_rx+=sdu_len; - eNB_mac_inst[enb_mod_idP].eNB_UE_stats[ue_mod_id].total_num_pdus_rx+=1; - - vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_RX_SDU,0); - stop_meas(&eNB_mac_inst[enb_mod_idP].rx_ulsch_sdu); -} - -unsigned char generate_dlsch_header(unsigned char *mac_header, - unsigned char num_sdus, - unsigned short *sdu_lengths, - unsigned char *sdu_lcids, - unsigned char drx_cmd, - short timing_advance_cmd, - unsigned char *ue_cont_res_id, - unsigned char short_padding, - unsigned short post_padding) { - - SCH_SUBHEADER_FIXED *mac_header_ptr = (SCH_SUBHEADER_FIXED *)mac_header; - uint8_t first_element=0,last_size=0,i; - uint8_t mac_header_control_elements[16],*ce_ptr; - - ce_ptr = &mac_header_control_elements[0]; - - // compute header components - - if ((short_padding == 1) || (short_padding == 2)) { - mac_header_ptr->R = 0; - mac_header_ptr->E = 0; - mac_header_ptr->LCID = SHORT_PADDING; - first_element=1; - last_size=1; - } - if (short_padding == 2) { - mac_header_ptr->E = 1; - mac_header_ptr++; - mac_header_ptr->R = 0; - mac_header_ptr->E = 0; - mac_header_ptr->LCID = SHORT_PADDING; - last_size=1; - } - - if (drx_cmd != 255) { - if (first_element>0) { - mac_header_ptr->E = 1; - mac_header_ptr++; - } - else { - first_element=1; - } - mac_header_ptr->R = 0; - mac_header_ptr->E = 0; - mac_header_ptr->LCID = DRX_CMD; - last_size=1; - } - - if (timing_advance_cmd != 0) { - if (first_element>0) { - mac_header_ptr->E = 1; - mac_header_ptr++; - } - else { - first_element=1; - } - mac_header_ptr->R = 0; - mac_header_ptr->E = 0; - mac_header_ptr->LCID = TIMING_ADV_CMD; - last_size=1; - // msg("last_size %d,mac_header_ptr %p\n",last_size,mac_header_ptr); - ((TIMING_ADVANCE_CMD *)ce_ptr)->R=0; - ((TIMING_ADVANCE_CMD *)ce_ptr)->TA=timing_advance_cmd&0x3f; - LOG_I(MAC,"timing advance =%d (%d)\n",timing_advance_cmd,((TIMING_ADVANCE_CMD *)ce_ptr)->TA); - ce_ptr+=sizeof(TIMING_ADVANCE_CMD); - //msg("offset %d\n",ce_ptr-mac_header_control_elements); - } - - if (ue_cont_res_id) { - if (first_element>0) { - mac_header_ptr->E = 1; - /* - printf("[eNB][MAC] last subheader : %x (R%d,E%d,LCID%d)\n",*(unsigned char*)mac_header_ptr, - ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->R, - ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->E, - ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->LCID); - */ - mac_header_ptr++; - } - else { - first_element=1; - } - - mac_header_ptr->R = 0; - mac_header_ptr->E = 0; - mac_header_ptr->LCID = UE_CONT_RES; - last_size=1; - - LOG_T(MAC,"[eNB ][RAPROC] Generate contention resolution msg: %x.%x.%x.%x.%x.%x\n", - ue_cont_res_id[0], - ue_cont_res_id[1], - ue_cont_res_id[2], - ue_cont_res_id[3], - ue_cont_res_id[4], - ue_cont_res_id[5]); - - memcpy(ce_ptr,ue_cont_res_id,6); - ce_ptr+=6; - // msg("(cont_res) : offset %d\n",ce_ptr-mac_header_control_elements); - } - - //msg("last_size %d,mac_header_ptr %p\n",last_size,mac_header_ptr); - - for (i=0;i<num_sdus;i++) { - LOG_T(MAC,"[eNB] Generate DLSCH header num sdu %d len sdu %d\n",num_sdus, sdu_lengths[i]); - - if (first_element>0) { - mac_header_ptr->E = 1; - /*msg("last subheader : %x (R%d,E%d,LCID%d)\n",*(unsigned char*)mac_header_ptr, - ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->R, - ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->E, - ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->LCID); - */ - mac_header_ptr+=last_size; - //msg("last_size %d,mac_header_ptr %p\n",last_size,mac_header_ptr); - } - else { - first_element=1; - } - if (sdu_lengths[i] < 128) { - ((SCH_SUBHEADER_SHORT *)mac_header_ptr)->R = 0; - ((SCH_SUBHEADER_SHORT *)mac_header_ptr)->E = 0; - ((SCH_SUBHEADER_SHORT *)mac_header_ptr)->F = 0; - ((SCH_SUBHEADER_SHORT *)mac_header_ptr)->LCID = sdu_lcids[i]; - ((SCH_SUBHEADER_SHORT *)mac_header_ptr)->L = (unsigned char)sdu_lengths[i]; - last_size=2; - } - else { - ((SCH_SUBHEADER_LONG *)mac_header_ptr)->R = 0; - ((SCH_SUBHEADER_LONG *)mac_header_ptr)->E = 0; - ((SCH_SUBHEADER_LONG *)mac_header_ptr)->F = 1; - ((SCH_SUBHEADER_LONG *)mac_header_ptr)->LCID = sdu_lcids[i]; - ((SCH_SUBHEADER_LONG *)mac_header_ptr)->L_MSB = ((unsigned short) sdu_lengths[i]>>8)&0x7f; - ((SCH_SUBHEADER_LONG *)mac_header_ptr)->L_LSB = (unsigned short) sdu_lengths[i]&0xff; - ((SCH_SUBHEADER_LONG *)mac_header_ptr)->padding = 0x00; - last_size=3; -#ifdef DEBUG_HEADER_PARSING - LOG_D(MAC,"[eNB] generate long sdu, size %x (MSB %x, LSB %x)\n", - sdu_lengths[i], - ((SCH_SUBHEADER_LONG *)mac_header_ptr)->L_MSB, - ((SCH_SUBHEADER_LONG *)mac_header_ptr)->L_LSB); -#endif - } - } - /* - - printf("last_size %d,mac_header_ptr %p\n",last_size,mac_header_ptr); - - printf("last subheader : %x (R%d,E%d,LCID%d)\n",*(unsigned char*)mac_header_ptr, - ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->R, - ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->E, - ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->LCID); - - - if (((SCH_SUBHEADER_FIXED*)mac_header_ptr)->LCID < UE_CONT_RES) { - if (((SCH_SUBHEADER_SHORT*)mac_header_ptr)->F == 0) - printf("F = 0, sdu len (L field) %d\n",(((SCH_SUBHEADER_SHORT*)mac_header_ptr)->L)); - else - printf("F = 1, sdu len (L field) %d\n",(((SCH_SUBHEADER_LONG*)mac_header_ptr)->L)); - } - */ - if (post_padding>0) {// we have lots of padding at the end of the packet - mac_header_ptr->E = 1; - mac_header_ptr+=last_size; - // add a padding element - mac_header_ptr->R = 0; - mac_header_ptr->E = 0; - mac_header_ptr->LCID = SHORT_PADDING; - mac_header_ptr++; - } - else { // no end of packet padding - // last SDU subhead is of fixed type (sdu length implicitly to be computed at UE) - mac_header_ptr++; - } - - //msg("After subheaders %d\n",(uint8_t*)mac_header_ptr - mac_header); - - if ((ce_ptr-mac_header_control_elements) > 0) { - // printf("Copying %d bytes for control elements\n",ce_ptr-mac_header_control_elements); - memcpy((void*)mac_header_ptr,mac_header_control_elements,ce_ptr-mac_header_control_elements); - mac_header_ptr+=(unsigned char)(ce_ptr-mac_header_control_elements); - } - //msg("After CEs %d\n",(uint8_t*)mac_header_ptr - mac_header); - - return((unsigned char*)mac_header_ptr - mac_header); - -} - -/* - #ifdef Rel10 - unsigned char generate_mch_header( unsigned char *mac_header, - unsigned char num_sdus, - unsigned short *sdu_lengths, - unsigned char *sdu_lcids, - unsigned char msi, - unsigned char short_padding, - unsigned short post_padding) { - - SCH_SUBHEADER_FIXED *mac_header_ptr = (SCH_SUBHEADER_FIXED *)mac_header; - uint8_t first_element=0,last_size=0,i; - uint8_t mac_header_control_elements[2*num_sdus],*ce_ptr; - - ce_ptr = &mac_header_control_elements[0]; - - if ((short_padding == 1) || (short_padding == 2)) { - mac_header_ptr->R = 0; - mac_header_ptr->E = 0; - mac_header_ptr->LCID = SHORT_PADDING; - first_element=1; - last_size=1; - } - if (short_padding == 2) { - mac_header_ptr->E = 1; - mac_header_ptr++; - mac_header_ptr->R = 0; - mac_header_ptr->E = 0; - mac_header_ptr->LCID = SHORT_PADDING; - last_size=1; - } - - // SUBHEADER for MSI CE - if (msi != 0) {// there is MSI MAC Control Element - if (first_element>0) { - mac_header_ptr->E = 1; - mac_header_ptr+=last_size; - } - else { - first_element = 1; - } - if (num_sdus*2 < 128) { - ((SCH_SUBHEADER_SHORT *)mac_header_ptr)->R = 0; - ((SCH_SUBHEADER_SHORT *)mac_header_ptr)->E = 0; - ((SCH_SUBHEADER_SHORT *)mac_header_ptr)->F = 0; - ((SCH_SUBHEADER_SHORT *)mac_header_ptr)->LCID = MCH_SCHDL_INFO; - ((SCH_SUBHEADER_SHORT *)mac_header_ptr)->L = num_sdus*2; - last_size=2; - } - else { - ((SCH_SUBHEADER_LONG *)mac_header_ptr)->R = 0; - ((SCH_SUBHEADER_LONG *)mac_header_ptr)->E = 0; - ((SCH_SUBHEADER_LONG *)mac_header_ptr)->F = 1; - ((SCH_SUBHEADER_LONG *)mac_header_ptr)->LCID = MCH_SCHDL_INFO; - ((SCH_SUBHEADER_LONG *)mac_header_ptr)->L = (num_sdus*2)&0x7fff; - last_size=3; - } - // Create the MSI MAC Control Element here - } - - // SUBHEADER for MAC SDU (MCCH+MTCHs) - for (i=0;i<num_sdus;i++) { - if (first_element>0) { - mac_header_ptr->E = 1; - mac_header_ptr+=last_size; - } - else { - first_element = 1; - } - if (sdu_lengths[i] < 128) { - ((SCH_SUBHEADER_SHORT *)mac_header_ptr)->R = 0; - ((SCH_SUBHEADER_SHORT *)mac_header_ptr)->E = 0; - ((SCH_SUBHEADER_SHORT *)mac_header_ptr)->F = 0; - ((SCH_SUBHEADER_SHORT *)mac_header_ptr)->LCID = sdu_lcids[i]; - ((SCH_SUBHEADER_SHORT *)mac_header_ptr)->L = (unsigned char)sdu_lengths[i]; - last_size=2; - } - else { - ((SCH_SUBHEADER_LONG *)mac_header_ptr)->R = 0; - ((SCH_SUBHEADER_LONG *)mac_header_ptr)->E = 0; - ((SCH_SUBHEADER_LONG *)mac_header_ptr)->F = 1; - ((SCH_SUBHEADER_LONG *)mac_header_ptr)->LCID = sdu_lcids[i]; - ((SCH_SUBHEADER_LONG *)mac_header_ptr)->L = (unsigned short) sdu_lengths[i]&0x7fff; - last_size=3; - } - } - - if (post_padding>0) {// we have lots of padding at the end of the packet - mac_header_ptr->E = 1; - mac_header_ptr+=last_size; - // add a padding element - mac_header_ptr->R = 0; - mac_header_ptr->E = 0; - mac_header_ptr->LCID = SHORT_PADDING; - mac_header_ptr++; - } - else { // no end of packet padding - // last SDU subhead is of fixed type (sdu length implicitly to be computed at UE) - mac_header_ptr++; - } - - // Copy MSI Control Element to the end of the MAC Header if it presents - if ((ce_ptr-mac_header_control_elements) > 0) { - // printf("Copying %d bytes for control elements\n",ce_ptr-mac_header_control_elements); - memcpy((void*)mac_header_ptr,mac_header_control_elements,ce_ptr-mac_header_control_elements); - mac_header_ptr+=(unsigned char)(ce_ptr-mac_header_control_elements); - } - - return((unsigned char*)mac_header_ptr - mac_header); - } - #endif - */ -void add_common_dci(DCI_PDU *DCI_pdu, - void *pdu, - rnti_t rnti, - unsigned char dci_size_bytes, - unsigned char aggregation, - unsigned char dci_size_bits, - unsigned char dci_fmt, - uint8_t ra_flag) { - - memcpy(&DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci].dci_pdu[0],pdu,dci_size_bytes); - DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci].dci_length = dci_size_bits; - DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci].L = aggregation; - DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci].rnti = rnti; - DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci].format = dci_fmt; - DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci].ra_flag = ra_flag; - - - DCI_pdu->Num_common_dci++; - LOG_D(MAC,"add common dci format %d for rnti %d \n",dci_fmt,rnti); -} - -void add_ue_spec_dci(DCI_PDU *DCI_pdu,void *pdu,rnti_t rnti,unsigned char dci_size_bytes,unsigned char aggregation,unsigned char dci_size_bits,unsigned char dci_fmt,uint8_t ra_flag) { - - memcpy(&DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci+DCI_pdu->Num_ue_spec_dci].dci_pdu[0],pdu,dci_size_bytes); - DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci+DCI_pdu->Num_ue_spec_dci].dci_length = dci_size_bits; - DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci+DCI_pdu->Num_ue_spec_dci].L = aggregation; - DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci+DCI_pdu->Num_ue_spec_dci].rnti = rnti; - DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci+DCI_pdu->Num_ue_spec_dci].format = dci_fmt; - DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci+DCI_pdu->Num_ue_spec_dci].ra_flag = ra_flag; - - DCI_pdu->Num_ue_spec_dci++; -} - -void schedule_SI(module_id_t module_idP,frame_t frameP, unsigned char *nprb,unsigned int *nCCE) { - - start_meas(&eNB_mac_inst[module_idP].schedule_si); - - unsigned char bcch_sdu_length; - int mcs = -1; - void *BCCH_alloc_pdu=(void*)&eNB_mac_inst[module_idP].BCCH_alloc_pdu; - - bcch_sdu_length = mac_rrc_data_req(module_idP, - frameP, - BCCH,1, - &eNB_mac_inst[module_idP].BCCH_pdu.payload[0], - 1, - module_idP, - 0); // not used in this case - if (bcch_sdu_length > 0) { - LOG_D(MAC,"[eNB %d] Frame %d : BCCH->DLSCH, Received %d bytes \n",module_idP,frameP,bcch_sdu_length); - - - if (bcch_sdu_length <= (mac_xface->get_TBS_DL(0,3))) - mcs=0; - else if (bcch_sdu_length <= (mac_xface->get_TBS_DL(1,3))) - mcs=1; - else if (bcch_sdu_length <= (mac_xface->get_TBS_DL(2,3))) - mcs=2; - else if (bcch_sdu_length <= (mac_xface->get_TBS_DL(3,3))) - mcs=3; - else if (bcch_sdu_length <= (mac_xface->get_TBS_DL(4,3))) - mcs=4; - else if (bcch_sdu_length <= (mac_xface->get_TBS_DL(5,3))) - mcs=5; - else if (bcch_sdu_length <= (mac_xface->get_TBS_DL(6,3))) - mcs=6; - else if (bcch_sdu_length <= (mac_xface->get_TBS_DL(7,3))) - mcs=7; - else if (bcch_sdu_length <= (mac_xface->get_TBS_DL(8,3))) - mcs=8; - - if (mac_xface->lte_frame_parms->frame_type == TDD) { - switch (mac_xface->lte_frame_parms->N_RB_DL) { - case 6: - ((DCI1A_1_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->mcs = mcs; - break; - case 25: - ((DCI1A_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->mcs = mcs; - break; - case 50: - ((DCI1A_10MHz_TDD_1_6_t*)BCCH_alloc_pdu)->mcs = mcs; - break; - case 100: - ((DCI1A_20MHz_TDD_1_6_t*)BCCH_alloc_pdu)->mcs = mcs; - break; - - } - } - else { - switch (mac_xface->lte_frame_parms->N_RB_DL) { - case 6: - ((DCI1A_1_5MHz_FDD_t*)BCCH_alloc_pdu)->mcs = mcs; - break; - case 25: - ((DCI1A_5MHz_FDD_t*)BCCH_alloc_pdu)->mcs = mcs; - break; - case 50: - ((DCI1A_10MHz_FDD_t*)BCCH_alloc_pdu)->mcs = mcs; - break; - case 100: - ((DCI1A_20MHz_FDD_t*)BCCH_alloc_pdu)->mcs = mcs; - break; - - } - } - -#if defined(USER_MODE) && defined(OAI_EMU) - if (oai_emulation.info.opt_enabled) { - trace_pdu(1, - &eNB_mac_inst[module_idP].BCCH_pdu.payload[0], - bcch_sdu_length, - 0xffff, - 4, - 0xffff, - eNB_mac_inst[module_idP].subframe, - 0, - 0); - } - LOG_D(OPT,"[eNB %d][BCH] Frame %d trace pdu for rnti %x with size %d\n", - module_idP, frameP, 0xffff, bcch_sdu_length); -#endif - - if (mac_xface->lte_frame_parms->frame_type == TDD) { - LOG_D(MAC,"[eNB] Frame %d : Scheduling BCCH->DLSCH (TDD) for SI %d bytes (mcs %d, rb 3, TBS %d)\n", - frameP, - bcch_sdu_length, - mcs, - mac_xface->get_TBS_DL(mcs,3)); - } - else { - LOG_D(MAC,"[eNB] Frame %d : Scheduling BCCH->DLSCH (FDD) for SI %d bytes (mcs %d, rb 3, TBS %d)\n", - frameP, - bcch_sdu_length, - mcs, - mac_xface->get_TBS_DL(mcs,3)); - } - eNB_mac_inst[module_idP].bcch_active=1; - *nprb=3; - *nCCE=4; - } - else { - eNB_mac_inst[module_idP].bcch_active=0; - *nprb=0; - *nCCE=0; - //LOG_D(MAC,"[eNB %d] Frame %d : BCCH not active \n",Mod_id,frame); - } - // this might be misleading when bcch is inactive - stop_meas(&eNB_mac_inst[module_idP].schedule_si); - return; -} - -#ifdef Rel10 -int8_t get_mbsfn_sf_alloction (module_id_t module_idP, uint8_t mbsfn_sync_area){ - // currently there is one-to-one mapping between sf allocation pattern and sync area - if (mbsfn_sync_area > MAX_MBSFN_AREA){ - LOG_W(MAC,"[eNB %d] MBSFN synchronization area %d out of range\n ", module_idP, mbsfn_sync_area); - return -1; - } - else if (eNB_mac_inst[module_idP].mbsfn_SubframeConfig[mbsfn_sync_area] != NULL) - return mbsfn_sync_area; - else { - LOG_W(MAC,"[eNB %d] MBSFN Subframe Config pattern %d not found \n ", module_idP, mbsfn_sync_area); - return -1; - } -} - -int schedule_MBMS(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP) { - - int mcch_flag=0,mtch_flag=0, msi_flag=0; - int mbsfn_period =0;// 1<<(eNB_mac_inst[module_idP].mbsfn_SubframeConfig[0]->radioframeAllocationPeriod); - int mcch_period = 0;//32<<(eNB_mac_inst[module_idP].mbsfn_AreaInfo[0]->mcch_Config_r9.mcch_RepetitionPeriod_r9); - int mch_scheduling_period = 8<<(eNB_mac_inst[module_idP].pmch_Config[0]->mch_SchedulingPeriod_r9); - unsigned char mcch_sdu_length; - unsigned char header_len_mcch=0,header_len_msi=0,header_len_mtch=0, header_len_mtch_temp=0, header_len_mcch_temp=0, header_len_msi_temp=0; - int ii=0, msi_pos=0; - int mcch_mcs = -1; - uint16_t TBS,j,padding=0,post_padding=0; - mac_rlc_status_resp_t rlc_status; - int num_mtch; - int msi_length,i,k; - unsigned char sdu_lcids[11], num_sdus=0, offset=0; - uint16_t sdu_lengths[11], sdu_length_total=0; - unsigned char mch_buffer[MAX_DLSCH_PAYLOAD_BYTES]; // check the max value, this is for dlsch only - - eNB_mac_inst[module_idP].MCH_pdu.Pdu_size=0; - - for (i=0; - i< eNB_mac_inst[module_idP].num_active_mbsfn_area; - i++ ){ - // assume, that there is always a mapping - if ((j=get_mbsfn_sf_alloction(module_idP,i)) == -1) - return 0; - - mbsfn_period = 1<<(eNB_mac_inst[module_idP].mbsfn_SubframeConfig[j]->radioframeAllocationPeriod); - mcch_period = 32<<(eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.mcch_RepetitionPeriod_r9); - msi_pos=0; ii=0; - LOG_D(MAC,"[eNB %d] Frame %d subframeP %d : Checking MBSFN Sync Area %d/%d with SF allocation %d/%d for MCCH and MTCH (mbsfn period %d, mcch period %d)\n", - module_idP,frameP, subframeP,i,eNB_mac_inst[module_idP].num_active_mbsfn_area, - j,eNB_mac_inst[module_idP].num_sf_allocation_pattern,mbsfn_period,mcch_period); - - - switch (eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.signallingMCS_r9) { - case 0: - mcch_mcs = 2; - break; - case 1: - mcch_mcs = 7; - break; - case 2: - mcch_mcs = 13; - break; - case 3: - mcch_mcs = 19; - break; - } - - // 1st: Check the MBSFN subframes from SIB2 info (SF allocation pattern i, max 8 non-overlapping patterns exist) - if (frameP % mbsfn_period == eNB_mac_inst[module_idP].mbsfn_SubframeConfig[j]->radioframeAllocationOffset){ // MBSFN frameP - if (eNB_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.present == MBSFN_SubframeConfig__subframeAllocation_PR_oneFrame){// one-frameP format - - // Find the first subframeP in this MCH to transmit MSI - if (frameP % mch_scheduling_period == eNB_mac_inst[module_idP].mbsfn_SubframeConfig[j]->radioframeAllocationOffset ) { - while (ii == 0) { - ii = eNB_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.choice.oneFrame.buf[0] & (0x80>>msi_pos); - msi_pos++; - } - LOG_D(MAC,"[eNB %d] Frame %d subframeP %d : sync area %d sf allocation pattern %d sf alloc %x msi pos is %d \n", module_idP,frameP, subframeP,i,j,eNB_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.choice.oneFrame.buf[0], msi_pos); - } - - // Check if the subframeP is for MSI, MCCH or MTCHs and Set the correspoding flag to 1 - switch (subframeP) { - case 1: - if (mac_xface->lte_frame_parms->frame_type == FDD) { - if ((eNB_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.choice.oneFrame.buf[0] & MBSFN_FDD_SF1) == MBSFN_FDD_SF1) { - if (msi_pos == 1) - msi_flag = 1; - if ( (frameP % mcch_period == eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.mcch_Offset_r9) && - ((eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.sf_AllocInfo_r9.buf[0] & MBSFN_FDD_SF1) == MBSFN_FDD_SF1) ) - mcch_flag = 1; - mtch_flag = 1; - } - } - break; - - case 2: - if (mac_xface->lte_frame_parms->frame_type == FDD){ - if ((eNB_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.choice.oneFrame.buf[0] & MBSFN_FDD_SF2) == MBSFN_FDD_SF2) { - if (msi_pos == 2) - msi_flag = 1; - if ( (frameP % mcch_period == eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.mcch_Offset_r9) && - ((eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.sf_AllocInfo_r9.buf[0] & MBSFN_FDD_SF2) == MBSFN_FDD_SF2) ) - mcch_flag = 1; - mtch_flag = 1; - } - } - break; - - case 3: - if (mac_xface->lte_frame_parms->frame_type == TDD){// TDD - if ((eNB_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.choice.oneFrame.buf[0] & MBSFN_TDD_SF3) == MBSFN_TDD_SF3) { - if (msi_pos == 1) - msi_flag = 1; - if ( (frameP % mcch_period == eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.mcch_Offset_r9) && - ((eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.sf_AllocInfo_r9.buf[0] & MBSFN_TDD_SF3) == MBSFN_TDD_SF3) ) - mcch_flag = 1; - mtch_flag = 1; - } - } - else {// FDD - if ((eNB_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.choice.oneFrame.buf[0] & MBSFN_FDD_SF3) == MBSFN_FDD_SF3) { - if (msi_pos == 3) - msi_flag = 1; - if ( (frameP % mcch_period == eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.mcch_Offset_r9) && - ((eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.sf_AllocInfo_r9.buf[0] & MBSFN_FDD_SF3) == MBSFN_FDD_SF3) ) - mcch_flag = 1; - mtch_flag = 1; - } - } - break; - - case 4: - if (mac_xface->lte_frame_parms->frame_type == TDD){ - if ((eNB_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.choice.oneFrame.buf[0] & MBSFN_TDD_SF4) == MBSFN_TDD_SF4) { - if (msi_pos == 2) - msi_flag = 1; - if ( (frameP % mcch_period == eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.mcch_Offset_r9) && - ((eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.sf_AllocInfo_r9.buf[0] & MBSFN_TDD_SF4) == MBSFN_TDD_SF4) ) - mcch_flag = 1; - mtch_flag = 1; - } - } - break; - - case 6: - if (mac_xface->lte_frame_parms->frame_type == FDD){ - if ((eNB_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.choice.oneFrame.buf[0] & MBSFN_FDD_SF6) == MBSFN_FDD_SF6) { - if (msi_pos == 4) - msi_flag = 1; - if ( (frameP % mcch_period == eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.mcch_Offset_r9) && - ((eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.sf_AllocInfo_r9.buf[0] & MBSFN_FDD_SF6) == MBSFN_FDD_SF6) ) - mcch_flag = 1; - mtch_flag = 1; - } - } - break; - - case 7: - if (mac_xface->lte_frame_parms->frame_type == TDD){ // TDD - if ((eNB_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.choice.oneFrame.buf[0] & MBSFN_TDD_SF7) == MBSFN_TDD_SF7) { - if (msi_pos == 3) - msi_flag = 1; - if ( (frameP % mcch_period == eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.mcch_Offset_r9) && - ((eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.sf_AllocInfo_r9.buf[0] & MBSFN_TDD_SF7) == MBSFN_TDD_SF7) ) - mcch_flag = 1; - mtch_flag = 1; - } - } - else {// FDD - if ((eNB_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.choice.oneFrame.buf[0] & MBSFN_FDD_SF7) == MBSFN_FDD_SF7) { - if (msi_pos == 5) - msi_flag = 1; - if ( (frameP % mcch_period == eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.mcch_Offset_r9) && - ((eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.sf_AllocInfo_r9.buf[0] & MBSFN_FDD_SF7) == MBSFN_FDD_SF7) ) - mcch_flag = 1; - mtch_flag = 1; - } - } - break; - - case 8: - if (mac_xface->lte_frame_parms->frame_type == TDD){ //TDD - if ((eNB_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.choice.oneFrame.buf[0] & MBSFN_TDD_SF8) == MBSFN_TDD_SF8) { - if (msi_pos == 4) - msi_flag = 1; - if ( (frameP % mcch_period == eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.mcch_Offset_r9) && - ((eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.sf_AllocInfo_r9.buf[0] & MBSFN_TDD_SF8) == MBSFN_TDD_SF8) ) - mcch_flag = 1; - mtch_flag = 1; - } - } - else{ // FDD - if ((eNB_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.choice.oneFrame.buf[0] & MBSFN_FDD_SF8) == MBSFN_FDD_SF8) { - if (msi_pos == 6) - msi_flag = 1; - if ( (frameP % mcch_period == eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.mcch_Offset_r9) && - ((eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.sf_AllocInfo_r9.buf[0] & MBSFN_FDD_SF8) == MBSFN_FDD_SF8) ) - mcch_flag = 1; - mtch_flag = 1; - } - } - break; - - case 9: - if (mac_xface->lte_frame_parms->frame_type == TDD){ - if ((eNB_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.choice.oneFrame.buf[0] & MBSFN_TDD_SF9) == MBSFN_TDD_SF9) { - if (msi_pos == 5) - msi_flag = 1; - if ( (frameP % mcch_period == eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.mcch_Offset_r9) && - ((eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.sf_AllocInfo_r9.buf[0] & MBSFN_TDD_SF9) == MBSFN_TDD_SF9) ) - mcch_flag = 1; - mtch_flag = 1; - } - } - break; - }// end switch - // sf allocation is non-overlapping - if ((msi_flag==1) || (mcch_flag==1) || (mtch_flag==1)){ - LOG_D(MAC,"[eNB %d] Frame %d Subframe %d: sync area %d SF alloc %d: msi flag %d, mcch flag %d, mtch flag %d\n", - module_idP, frameP, subframeP,i,j,msi_flag,mcch_flag,mtch_flag); - break; - } - } - else {// four-frameP format - } - } - } // end of for loop - eNB_mac_inst[module_idP].msi_active=0; - eNB_mac_inst[module_idP].mcch_active=0; - eNB_mac_inst[module_idP].mtch_active=0; - // Calculate the mcs - if ((msi_flag==1) || (mcch_flag==1)) { - eNB_mac_inst[module_idP].MCH_pdu.mcs = mcch_mcs; - } - else if (mtch_flag == 1) { // only MTCH in this subframeP - eNB_mac_inst[module_idP].MCH_pdu.mcs = eNB_mac_inst[module_idP].pmch_Config[0]->dataMCS_r9; - } - - - // 2nd: Create MSI, get MCCH from RRC and MTCHs from RLC - - // there is MSI (MCH Scheduling Info) - if (msi_flag == 1) { - // Create MSI here - uint16_t msi_control_element[29], *msi_ptr; - - msi_ptr = &msi_control_element[0]; - ((MSI_ELEMENT *) msi_ptr)->lcid = MCCH_LCHANID; //MCCH - if (mcch_flag==1) { - ((MSI_ELEMENT *) msi_ptr)->stop_sf_MSB = 0; - ((MSI_ELEMENT *) msi_ptr)->stop_sf_LSB = 0; - } - else { // no mcch for this MSP - ((MSI_ELEMENT *) msi_ptr)->stop_sf_MSB = 0x7;// stop value is 2047 - ((MSI_ELEMENT *) msi_ptr)->stop_sf_LSB = 0xff; - } - msi_ptr+= sizeof(MSI_ELEMENT); - - //Header for MTCHs - num_mtch = eNB_mac_inst[module_idP].mbms_SessionList[0]->list.count; - for (k=0;k<num_mtch;k++) { // loop for all session in this MCH (MCH[0]) at this moment - ((MSI_ELEMENT *) msi_ptr)->lcid = eNB_mac_inst[module_idP].mbms_SessionList[0]->list.array[k]->logicalChannelIdentity_r9;//mtch_lcid; - ((MSI_ELEMENT *) msi_ptr)->stop_sf_MSB = 0; // last subframeP of this mtch (only one mtch now) - ((MSI_ELEMENT *) msi_ptr)->stop_sf_LSB = 0xB; - msi_ptr+=sizeof(MSI_ELEMENT); - } - msi_length = msi_ptr-msi_control_element; - if (msi_length<128) - header_len_msi = 2; - else - header_len_msi = 3; - - LOG_D(MAC,"[eNB %d] Frame %d : MSI->MCH, length of MSI is %d bytes \n",module_idP,frameP,msi_length); - //LOG_D(MAC,"Scheduler: MSI is transmitted in this subframeP \n" ); - - // LOG_D(MAC,"Scheduler: MSI length is %d bytes\n",msi_length); - // Store MSI data to mch_buffer[0] - memcpy((char *)&mch_buffer[sdu_length_total], - msi_control_element, - msi_length); - - sdu_lcids[num_sdus] = MCH_SCHDL_INFO; - sdu_lengths[num_sdus] = msi_length; - sdu_length_total += sdu_lengths[num_sdus]; - LOG_I(MAC,"[eNB %d] Create %d bytes for MSI\n",module_idP,sdu_lengths[num_sdus]); - num_sdus++; - eNB_mac_inst[module_idP].msi_active=1; - } - - // there is MCCH - if (mcch_flag == 1) { - LOG_D(MAC,"[eNB %d] Frame %d Subframe %d: Schedule MCCH MESSAGE (area %d, sfAlloc %d)\n", - module_idP,frameP, subframeP, i, j); - - mcch_sdu_length = mac_rrc_data_req(module_idP, - frameP, - MCCH,1, - &eNB_mac_inst[module_idP].MCCH_pdu.payload[0], - 1,// this is eNB - module_idP, // index - i); // this is the mbsfn sync area index - - if (mcch_sdu_length > 0) { - LOG_D(MAC,"[eNB %d] Frame %d subframeP %d : MCCH->MCH, Received %d bytes from RRC \n",module_idP,frameP,subframeP,mcch_sdu_length); - - header_len_mcch = 2; - if (mac_xface->lte_frame_parms->frame_type == TDD) { - LOG_D(MAC,"[eNB %d] Frame %d subframeP %d: Scheduling MCCH->MCH (TDD) for MCCH message %d bytes (mcs %d )\n", - module_idP, - frameP,subframeP, - mcch_sdu_length, - mcch_mcs); - } - else { - LOG_I(MAC,"[eNB %d] Frame %d subframeP %d: Scheduling MCCH->MCH (FDD) for MCCH message %d bytes (mcs %d)\n", - module_idP, - frameP, subframeP, - mcch_sdu_length, - mcch_mcs); - } - eNB_mac_inst[module_idP].mcch_active=1; - - memcpy((char *)&mch_buffer[sdu_length_total], - &eNB_mac_inst[module_idP].MCCH_pdu.payload[0], - mcch_sdu_length); - sdu_lcids[num_sdus] = MCCH_LCHANID; - sdu_lengths[num_sdus] = mcch_sdu_length; - if (sdu_lengths[num_sdus]>128) - header_len_mcch = 3; - sdu_length_total += sdu_lengths[num_sdus]; - LOG_D(MAC,"[eNB %d] Got %d bytes for MCCH from RRC \n",module_idP,sdu_lengths[num_sdus]); - num_sdus++; - } - } - TBS = mac_xface->get_TBS_DL(eNB_mac_inst[module_idP].MCH_pdu.mcs, mac_xface->lte_frame_parms->N_RB_DL); -#ifdef Rel10 - // do not let mcch and mtch multiplexing when relaying is active - // for sync area 1, so not transmit data - //if ((i == 0) && ((eNB_mac_inst[module_idP].MBMS_flag != multicast_relay) || (eNB_mac_inst[module_idP].mcch_active==0))) { -#endif - // there is MTCHs, loop if there are more than 1 - if (mtch_flag == 1) { - // Calculate TBS - /* if ((msi_flag==1) || (mcch_flag==1)) { - TBS = mac_xface->get_TBS(mcch_mcs, mac_xface->lte_frame_parms->N_RB_DL); - } - else { // only MTCH in this subframeP - TBS = mac_xface->get_TBS(eNB_mac_inst[module_idP].pmch_Config[0]->dataMCS_r9, mac_xface->lte_frame_parms->N_RB_DL); - } - - // get MTCH data from RLC (like for DTCH) - LOG_D(MAC,"[eNB %d] Frame %d subframe %d: Schedule MTCH (area %d, sfAlloc %d)\n",Mod_id,frame,subframe,i,j); - - header_len_mtch = 3; - LOG_D(MAC,"[eNB %d], Frame %d, MTCH->MCH, Checking RLC status (rab %d, tbs %d, len %d)\n", - Mod_id,frame,MTCH,TBS, - TBS-header_len_mcch-header_len_msi-sdu_length_total-header_len_mtch); - - rlc_status = mac_rlc_status_ind(Mod_id,frame,1,RLC_MBMS_YES,MTCH+ (maxDRB + 3) * MAX_MOBILES_PER_RG, - TBS-header_len_mcch-header_len_msi-sdu_length_total-header_len_mtch); - printf("frame %d, subframe %d, rlc_status.bytes_in_buffer is %d\n",frame,subframe, rlc_status.bytes_in_buffer); - - */ - - // get MTCH data from RLC (like for DTCH) - LOG_D(MAC,"[eNB %d] Frame %d subframeP %d: Schedule MTCH (area %d, sfAlloc %d)\n",module_idP,frameP,subframeP,i,j); - - header_len_mtch = 3; - LOG_D(MAC,"[eNB %d], Frame %d, MTCH->MCH, Checking RLC status (rab %d, tbs %d, len %d)\n", - module_idP,frameP,MTCH,TBS, - TBS-header_len_mcch-header_len_msi-sdu_length_total-header_len_mtch); - - rlc_status = mac_rlc_status_ind(module_idP,0,frameP,ENB_FLAG_YES,MBMS_FLAG_YES,MTCH, - TBS-header_len_mcch-header_len_msi-sdu_length_total-header_len_mtch); - LOG_D(MAC,"e-MBMS log channel %u frameP %d, subframeP %d, rlc_status.bytes_in_buffer is %d\n", - MTCH,frameP,subframeP, rlc_status.bytes_in_buffer); - - if (rlc_status.bytes_in_buffer >0) { - LOG_I(MAC,"[eNB %d][MBMS USER-PLANE], Frame %d, MTCH->MCH, Requesting %d bytes from RLC (header len mtch %d)\n", - module_idP,frameP,TBS-header_len_mcch-header_len_msi-sdu_length_total-header_len_mtch,header_len_mtch); - - sdu_lengths[num_sdus] = mac_rlc_data_req( - module_idP, - 0, - frameP, - ENB_FLAG_YES, - MBMS_FLAG_YES, - MTCH, - (char*)&mch_buffer[sdu_length_total]); - //sdu_lengths[num_sdus] = mac_rlc_data_req(module_idP,frameP, MBMS_FLAG_NO, MTCH+(MAX_NUM_RB*(NUMBER_OF_UE_MAX+1)), (char*)&mch_buffer[sdu_length_total]); - LOG_I(MAC,"[eNB %d][MBMS USER-PLANE] Got %d bytes for MTCH %d\n",module_idP,sdu_lengths[num_sdus],MTCH); - eNB_mac_inst[module_idP].mtch_active=1; - sdu_lcids[num_sdus] = MTCH; - sdu_length_total += sdu_lengths[num_sdus]; - if (sdu_lengths[num_sdus] < 128) - header_len_mtch = 2; - num_sdus++; - } - else { - header_len_mtch = 0; - } - } -#ifdef Rel10 - // } -#endif - // FINAL STEP: Prepare and multiplexe MSI, MCCH and MTCHs - if ((sdu_length_total + header_len_msi + header_len_mcch + header_len_mtch) >0) { - // Adjust the last subheader - /* if ((msi_flag==1) || (mcch_flag==1)) { - eNB_mac_inst[module_idP].MCH_pdu.mcs = mcch_mcs; - } - else if (mtch_flag == 1) { // only MTCH in this subframeP - eNB_mac_inst[module_idP].MCH_pdu.mcs = eNB_mac_inst[module_idP].pmch_Config[0]->dataMCS_r9; - } - */ - header_len_mtch_temp = header_len_mtch; - header_len_mcch_temp = header_len_mcch; - header_len_msi_temp = header_len_msi; - if (header_len_mtch>0) - header_len_mtch=1; // remove Length field in the subheader for the last PDU - else if (header_len_mcch>0) - header_len_mcch=1; - else header_len_msi=1; - // Calculate the padding - if ((TBS - header_len_mtch - header_len_mcch - header_len_msi - sdu_length_total) < 0) { - LOG_E(MAC,"Error in building MAC PDU, TBS %d < PDU %d \n", - TBS, header_len_mtch + header_len_mcch + header_len_msi + sdu_length_total); - return; - }else if ((TBS - header_len_mtch - header_len_mcch - header_len_msi - sdu_length_total) <= 2) { - padding = (TBS - header_len_mtch - header_len_mcch - header_len_msi - sdu_length_total); - post_padding = 0; - } - else {// using post_padding, give back the Length field of subheader for the last PDU - padding = 0; - if (header_len_mtch>0) - header_len_mtch = header_len_mtch_temp; - else if (header_len_mcch>0) - header_len_mcch = header_len_mcch_temp; - else header_len_msi = header_len_msi_temp; - post_padding = TBS - sdu_length_total - header_len_msi - header_len_mcch - header_len_mtch; - } - // Generate the MAC Header for MCH - // here we use the function for DLSCH because DLSCH & MCH have the same Header structure - offset = generate_dlsch_header((unsigned char*)eNB_mac_inst[module_idP].MCH_pdu.payload, - num_sdus, - sdu_lengths, - sdu_lcids, - 255, // no drx - 0, // no timing advance - NULL, // no contention res id - padding, - post_padding); - - eNB_mac_inst[module_idP].MCH_pdu.Pdu_size=TBS; - eNB_mac_inst[module_idP].MCH_pdu.sync_area=i; - eNB_mac_inst[module_idP].MCH_pdu.msi_active= eNB_mac_inst[module_idP].msi_active; - eNB_mac_inst[module_idP].MCH_pdu.mcch_active= eNB_mac_inst[module_idP].mcch_active; - eNB_mac_inst[module_idP].MCH_pdu.mtch_active= eNB_mac_inst[module_idP].mtch_active; - LOG_D(MAC," MCS for this sf is %d (mcch active %d, mtch active %d)\n", eNB_mac_inst[module_idP].MCH_pdu.mcs, - eNB_mac_inst[module_idP].MCH_pdu.mcch_active,eNB_mac_inst[module_idP].MCH_pdu.mtch_active ); - LOG_I(MAC,"[eNB %d][MBMS USER-PLANE ] Generate header : sdu_length_total %d, num_sdus %d, sdu_lengths[0] %d, sdu_lcids[0] %d => payload offset %d,padding %d,post_padding %d (mcs %d, TBS %d), header MTCH %d, header MCCH %d, header MSI %d\n", - module_idP,sdu_length_total,num_sdus,sdu_lengths[0],sdu_lcids[0],offset,padding,post_padding,eNB_mac_inst[module_idP].MCH_pdu.mcs,TBS,header_len_mtch, header_len_mcch, header_len_msi); - // copy SDU to mch_pdu after the MAC Header - memcpy(&eNB_mac_inst[module_idP].MCH_pdu.payload[offset],mch_buffer,sdu_length_total); - // filling remainder of MCH with random data if necessery - for (j=0;j<(TBS-sdu_length_total-offset);j++) - eNB_mac_inst[module_idP].MCH_pdu.payload[offset+sdu_length_total+j] = (char)(taus()&0xff); - -#if defined(USER_MODE) && defined(OAI_EMU) - /* Tracing of PDU is done on UE side */ - if (oai_emulation.info.opt_enabled) - trace_pdu(1, (uint8_t *)eNB_mac_inst[module_idP].MCH_pdu.payload, - TBS, module_idP, 6, 0xffff, // M_RNTI = 6 in wirehsark - eNB_mac_inst[module_idP].subframe,0,0); - LOG_D(OPT,"[eNB %d][MCH] Frame %d : MAC PDU with size %d\n", - module_idP, frameP, TBS); -#endif - /* - for (j=0;j<sdu_length_total;j++) - printf("%2x.",eNB_mac_inst[module_idP].MCH_pdu.payload[j+offset]); - printf(" \n");*/ - return 1; - } - else { - eNB_mac_inst[module_idP].MCH_pdu.Pdu_size=0; - eNB_mac_inst[module_idP].MCH_pdu.sync_area=0; - eNB_mac_inst[module_idP].MCH_pdu.msi_active=0; - eNB_mac_inst[module_idP].MCH_pdu.mcch_active=0; - eNB_mac_inst[module_idP].MCH_pdu.mtch_active=0; - // for testing purpose, fill with random data - //for (j=0;j<(TBS-sdu_length_total-offset);j++) - // eNB_mac_inst[module_idP].MCH_pdu.payload[offset+sdu_length_total+j] = (char)(taus()&0xff); - return 0; - } - //this is for testing - /* - if (mtch_flag == 1) { - // LOG_D(MAC,"DUY: mch_buffer length so far is : %ld\n", &mch_buffer[sdu_length_total]-&mch_buffer[0]); - return 1; - } - else - return 0; - */ -} - -MCH_PDU *get_mch_sdu(uint8_t module_idP,uint32_t frameP, sub_frame_t subframeP) { - // eNB_mac_inst[module_idP].MCH_pdu.mcs=0; - //LOG_D(MAC," MCH_pdu.mcs is %d\n", eNB_mac_inst[module_idP].MCH_pdu.mcs); - return(&eNB_mac_inst[module_idP].MCH_pdu); -} - -#endif - -// First stage of Random-Access Scheduling -void schedule_RA(module_id_t module_idP,frame_t frameP, sub_frame_t subframeP,unsigned char Msg3_subframe,unsigned char *nprb,unsigned int *nCCE) { - - start_meas(&eNB_mac_inst[module_idP].schedule_ra); - RA_TEMPLATE *RA_template = (RA_TEMPLATE *)&eNB_mac_inst[module_idP].RA_template[0]; - unsigned char i;//,harq_pid,round; - uint16_t rrc_sdu_length; - unsigned char lcid,offset; - module_id_t UE_id= UE_INDEX_INVALID; - unsigned short TBsize = -1; - unsigned short msg4_padding,msg4_post_padding,msg4_header; - - for (i=0;i<NB_RA_PROC_MAX;i++) { - - if (RA_template[i].RA_active == TRUE) { - - LOG_I(MAC,"[eNB %d][RAPROC] RA %d is active (generate RAR %d, generate_Msg4 %d, wait_ack_Msg4 %d, rnti %x)\n", - module_idP,i,RA_template[i].generate_rar,RA_template[i].generate_Msg4,RA_template[i].wait_ack_Msg4, RA_template[i].rnti); - - if (RA_template[i].generate_rar == 1) { - *nprb= (*nprb) + 3; - *nCCE = (*nCCE) + 4; - RA_template[i].Msg3_subframe=Msg3_subframe; - } - else if (RA_template[i].generate_Msg4 == 1) { - - // check for Msg4 Message - UE_id = find_UE_id(module_idP,RA_template[i].rnti); - if (Is_rrc_registered == 1) { - - // Get RRCConnectionSetup for Piggyback - rrc_sdu_length = mac_rrc_data_req(module_idP, - frameP, - CCCH,1, - &eNB_mac_inst[module_idP].CCCH_pdu.payload[0], - 1, - module_idP, - 0); // not used in this case - if (rrc_sdu_length == -1) - mac_xface->macphy_exit("[MAC][eNB Scheduler] CCCH not allocated\n"); - else { - //msg("[MAC][eNB %d] Frame %d, subframeP %d: got %d bytes from RRC\n",module_idP,frameP, subframeP,rrc_sdu_length); - } - } - - LOG_I(MAC,"[eNB %d][RAPROC] Frame %d, subframeP %d: UE_id %d, Is_rrc_registered %d, rrc_sdu_length %d\n", - module_idP,frameP, subframeP,UE_id, Is_rrc_registered,rrc_sdu_length); - - if (rrc_sdu_length>0) { - LOG_I(MAC,"[eNB %d][RAPROC] Frame %d, subframeP %d: Generating Msg4 with RRC Piggyback (RA proc %d, RNTI %x)\n", - module_idP,frameP, subframeP,i,RA_template[i].rnti); - - //msg("[MAC][eNB %d][RAPROC] Frame %d, subframeP %d: Received %d bytes for Msg4: \n",module_idP,frameP,subframeP,rrc_sdu_length); - // for (j=0;j<rrc_sdu_length;j++) - // msg("%x ",(unsigned char)eNB_mac_inst[module_idP].CCCH_pdu.payload[j]); - // msg("\n"); - // msg("[MAC][eNB] Frame %d, subframeP %d: Generated DLSCH (Msg4) DCI, format 1A, for UE %d\n",frameP, subframeP,UE_id); - // Schedule Reflection of Connection request - - - - // Compute MCS for 3 PRB - msg4_header = 1+6+1; // CR header, CR CE, SDU header - - if (mac_xface->lte_frame_parms->frame_type == TDD) { - - switch (mac_xface->lte_frame_parms->N_RB_DL) { - case 6: - ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->ndi=1; - - if ((rrc_sdu_length+msg4_header) <= 22) { - ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=4; - TBsize = 22; - } - else if ((rrc_sdu_length+msg4_header) <= 28) { - ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=5; - TBsize = 28; - } - else if ((rrc_sdu_length+msg4_header) <= 32) { - ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=6; - TBsize = 32; - } - else if ((rrc_sdu_length+msg4_header) <= 41) { - ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=7; - TBsize = 41; - } - else if ((rrc_sdu_length+msg4_header) <= 49) { - ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=8; - TBsize = 49; - } - else if ((rrc_sdu_length+msg4_header) <= 57) { - ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=9; - TBsize = 57; - } - break; - case 25: - - ((DCI1A_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->ndi=1; - - if ((rrc_sdu_length+msg4_header) <= 22) { - ((DCI1A_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=4; - TBsize = 22; - } - else if ((rrc_sdu_length+msg4_header) <= 28) { - ((DCI1A_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=5; - TBsize = 28; - } - else if ((rrc_sdu_length+msg4_header) <= 32) { - ((DCI1A_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=6; - TBsize = 32; - } - else if ((rrc_sdu_length+msg4_header) <= 41) { - ((DCI1A_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=7; - TBsize = 41; - } - else if ((rrc_sdu_length+msg4_header) <= 49) { - ((DCI1A_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=8; - TBsize = 49; - } - else if ((rrc_sdu_length+msg4_header) <= 57) { - ((DCI1A_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=9; - TBsize = 57; - } - break; - case 50: - - ((DCI1A_10MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->ndi=1; - - if ((rrc_sdu_length+msg4_header) <= 22) { - ((DCI1A_10MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=4; - TBsize = 22; - } - else if ((rrc_sdu_length+msg4_header) <= 28) { - ((DCI1A_10MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=5; - TBsize = 28; - } - else if ((rrc_sdu_length+msg4_header) <= 32) { - ((DCI1A_10MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=6; - TBsize = 32; - } - else if ((rrc_sdu_length+msg4_header) <= 41) { - ((DCI1A_10MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=7; - TBsize = 41; - } - else if ((rrc_sdu_length+msg4_header) <= 49) { - ((DCI1A_10MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=8; - TBsize = 49; - } - else if ((rrc_sdu_length+msg4_header) <= 57) { - ((DCI1A_10MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=9; - TBsize = 57; - } - break; - case 100: - - ((DCI1A_20MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->ndi=1; - - if ((rrc_sdu_length+msg4_header) <= 22) { - ((DCI1A_20MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=4; - TBsize = 22; - } - else if ((rrc_sdu_length+msg4_header) <= 28) { - ((DCI1A_20MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=5; - TBsize = 28; - } - else if ((rrc_sdu_length+msg4_header) <= 32) { - ((DCI1A_20MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=6; - TBsize = 32; - } - else if ((rrc_sdu_length+msg4_header) <= 41) { - ((DCI1A_20MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=7; - TBsize = 41; - } - else if ((rrc_sdu_length+msg4_header) <= 49) { - ((DCI1A_20MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=8; - TBsize = 49; - } - else if ((rrc_sdu_length+msg4_header) <= 57) { - ((DCI1A_20MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=9; - TBsize = 57; - } - break; - } - } - else { // FDD DCI - switch (mac_xface->lte_frame_parms->N_RB_DL) { - case 6: - ((DCI1A_1_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->ndi=1; - - if ((rrc_sdu_length+msg4_header) <= 22) { - ((DCI1A_1_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=4; - TBsize = 22; - } - else if ((rrc_sdu_length+msg4_header) <= 28) { - ((DCI1A_1_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=5; - TBsize = 28; - } - else if ((rrc_sdu_length+msg4_header) <= 32) { - ((DCI1A_1_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=6; - TBsize = 32; - } - else if ((rrc_sdu_length+msg4_header) <= 41) { - ((DCI1A_1_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=7; - TBsize = 41; - } - else if ((rrc_sdu_length+msg4_header) <= 49) { - ((DCI1A_1_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=8; - TBsize = 49; - } - else if ((rrc_sdu_length+msg4_header) <= 57) { - ((DCI1A_1_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=9; - TBsize = 57; - } - break; - case 25: - ((DCI1A_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->ndi=1; - - if ((rrc_sdu_length+msg4_header) <= 22) { - ((DCI1A_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=4; - TBsize = 22; - } - else if ((rrc_sdu_length+msg4_header) <= 28) { - ((DCI1A_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=5; - TBsize = 28; - } - else if ((rrc_sdu_length+msg4_header) <= 32) { - ((DCI1A_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=6; - TBsize = 32; - } - else if ((rrc_sdu_length+msg4_header) <= 41) { - ((DCI1A_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=7; - TBsize = 41; - } - else if ((rrc_sdu_length+msg4_header) <= 49) { - ((DCI1A_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=8; - TBsize = 49; - } - else if ((rrc_sdu_length+msg4_header) <= 57) { - ((DCI1A_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=9; - TBsize = 57; - } - break; - case 50: - ((DCI1A_10MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->ndi=1; - - if ((rrc_sdu_length+msg4_header) <= 22) { - ((DCI1A_10MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=4; - TBsize = 22; - } - else if ((rrc_sdu_length+msg4_header) <= 28) { - ((DCI1A_10MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=5; - TBsize = 28; - } - else if ((rrc_sdu_length+msg4_header) <= 32) { - ((DCI1A_10MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=6; - TBsize = 32; - } - else if ((rrc_sdu_length+msg4_header) <= 41) { - ((DCI1A_10MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=7; - TBsize = 41; - } - else if ((rrc_sdu_length+msg4_header) <= 49) { - ((DCI1A_10MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=8; - TBsize = 49; - } - else if ((rrc_sdu_length+msg4_header) <= 57) { - ((DCI1A_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=9; - TBsize = 57; - } - break; - case 100: - ((DCI1A_20MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->ndi=1; - - if ((rrc_sdu_length+msg4_header) <= 22) { - ((DCI1A_20MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=4; - TBsize = 22; - } - else if ((rrc_sdu_length+msg4_header) <= 28) { - ((DCI1A_20MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=5; - TBsize = 28; - } - else if ((rrc_sdu_length+msg4_header) <= 32) { - ((DCI1A_20MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=6; - TBsize = 32; - } - else if ((rrc_sdu_length+msg4_header) <= 41) { - ((DCI1A_20MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=7; - TBsize = 41; - } - else if ((rrc_sdu_length+msg4_header) <= 49) { - ((DCI1A_20MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=8; - TBsize = 49; - } - else if ((rrc_sdu_length+msg4_header) <= 57) { - ((DCI1A_20MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=9; - TBsize = 57; - } - break; - } - } - RA_template[i].generate_Msg4=0; - RA_template[i].generate_Msg4_dci=1; - RA_template[i].wait_ack_Msg4=1; - RA_template[i].RA_active = FALSE; - lcid=0; - - if ((TBsize - rrc_sdu_length - msg4_header) <= 2) { - msg4_padding = TBsize - rrc_sdu_length - msg4_header; - msg4_post_padding = 0; - } - else { - msg4_padding = 0; - msg4_post_padding = TBsize - rrc_sdu_length - msg4_header -1; - } - LOG_I(MAC,"[eNB %d][RAPROC] Frame %d subframeP %d Msg4 : TBS %d, sdu_len %d, msg4_header %d, msg4_padding %d, msg4_post_padding %d\n", - module_idP,frameP,subframeP,TBsize,rrc_sdu_length,msg4_header,msg4_padding,msg4_post_padding); - offset = generate_dlsch_header((unsigned char*)eNB_mac_inst[module_idP].DLSCH_pdu[(unsigned char)UE_id][0].payload[0], - 1, //num_sdus - &rrc_sdu_length, // - &lcid, // sdu_lcid - 255, // no drx - 0, // no timing advance - RA_template[i].cont_res_id, // contention res id - msg4_padding, // no padding - msg4_post_padding); - - memcpy((void*)&eNB_mac_inst[module_idP].DLSCH_pdu[(unsigned char)UE_id][0].payload[0][(unsigned char)offset], - &eNB_mac_inst[module_idP].CCCH_pdu.payload[0], - rrc_sdu_length); - -#if defined(USER_MODE) && defined(OAI_EMU) - if (oai_emulation.info.opt_enabled){ - trace_pdu(1, (uint8_t *)eNB_mac_inst[module_idP].DLSCH_pdu[(unsigned char)UE_id][0].payload[0], - rrc_sdu_length, UE_id, 3, find_UE_RNTI(module_idP, UE_id), - eNB_mac_inst[module_idP].subframe,0,0); - LOG_D(OPT,"[eNB %d][DLSCH] Frame %d trace pdu for rnti %x with size %d\n", - module_idP, frameP, find_UE_RNTI(module_idP,UE_id), rrc_sdu_length); - } -#endif - *nprb= (*nprb) + 3; - *nCCE = (*nCCE) + 4; - } - //try here - } - /* - else if (eNB_mac_inst[module_idP].RA_template[i].wait_ack_Msg4==1) { - // check HARQ status and retransmit if necessary - LOG_I(MAC,"[eNB %d][RAPROC] Frame %d, subframeP %d: Checking if Msg4 was acknowledged :\n",module_idP,frameP,subframeP); - // Get candidate harq_pid from PHY - mac_xface->get_ue_active_harq_pid(module_idP,eNB_mac_inst[module_idP].RA_template[i].rnti,subframeP,&harq_pid,&round,0); - if (round>0) { - *nprb= (*nprb) + 3; - *nCCE = (*nCCE) + 4; - } - } - */ - } - } - stop_meas(&eNB_mac_inst[module_idP].schedule_ra); -} - -// This has to be updated to include BSR information -uint8_t UE_is_to_be_scheduled(module_id_t module_idP,uint8_t UE_id) { - - - // LOG_D(MAC,"[eNB %d][PUSCH] Frame %d subframeP %d Scheduling UE %d\n",module_idP,rnti,frameP,subframeP, - // UE_id); - - if ((eNB_mac_inst[module_idP].UE_template[UE_id].bsr_info[LCGID0]>0) || - (eNB_mac_inst[module_idP].UE_template[UE_id].bsr_info[LCGID1]>0) || - (eNB_mac_inst[module_idP].UE_template[UE_id].bsr_info[LCGID2]>0) || - (eNB_mac_inst[module_idP].UE_template[UE_id].bsr_info[LCGID3]>0) || - (eNB_mac_inst[module_idP].UE_template[UE_id].ul_SR>0)) // uplink scheduling request - return(1); - else - return(0); -} - -uint32_t bytes_to_bsr_index(int32_t nbytes) { - - uint32_t i=0; - - if (nbytes<0) - return(0); - - while ((i<BSR_TABLE_SIZE)&& - (BSR_TABLE[i]<=nbytes)){ - i++; - } - return(i-1); -} - -// This table holds the allowable PRB sizes for ULSCH transmissions -uint8_t rb_table[33] = {1,2,3,4,5,6,8,9,10,12,15,16,18,20,24,25,27,30,32,36,40,45,48,50,54,60,72,75,80,81,90,96,100}; - -void schedule_ulsch(module_id_t module_idP, frame_t frameP,unsigned char cooperation_flag,sub_frame_t subframeP, unsigned char sched_subframe,unsigned int *nCCE) {//,int calibration_flag) { - - start_meas(&eNB_mac_inst[module_idP].schedule_ulsch); - uint8_t granted_UEs; - unsigned int nCCE_available; - uint16_t first_rb=1,i; - - granted_UEs = find_ulgranted_UEs(module_idP); - nCCE_available = mac_xface->get_nCCE_max(module_idP) - *nCCE; - - // UE data info; - // check which UE has data to transmit - // function to decide the scheduling - // e.g. scheduling_rslt = Greedy(granted_UEs, nb_RB) - - // default function for default scheduling - // - - // output of scheduling, the UE numbers in RBs, where it is in the code??? - // check if RA (Msg3) is active in this subframeP, if so skip the PRBs used for Msg3 - // Msg3 is using 1 PRB so we need to increase first_rb accordingly - // not sure about the break (can there be more than 1 active RA procedure?) - - for (i=0;i<NB_RA_PROC_MAX;i++) { - if ((eNB_mac_inst[module_idP].RA_template[i].RA_active == TRUE) && - (eNB_mac_inst[module_idP].RA_template[i].generate_rar == 0) && - (eNB_mac_inst[module_idP].RA_template[i].Msg3_subframe == sched_subframe)) { - first_rb++; - break; - } - } - - schedule_ulsch_rnti(module_idP, cooperation_flag, frameP, subframeP, sched_subframe, granted_UEs, nCCE, &nCCE_available, &first_rb); - -#ifdef CBA - if ((eNB_mac_inst[module_idP].num_active_cba_groups > 0) && (*nCCE == 0)) - schedule_ulsch_cba_rnti(module_idP, cooperation_flag, frameP, subframeP, sched_subframe, granted_UEs, nCCE, &nCCE_available, &first_rb); -#endif - stop_meas(&eNB_mac_inst[module_idP].schedule_ulsch); - -} -#ifdef CBA -void schedule_ulsch_cba_rnti(module_id_t module_idP, unsigned char cooperation_flag, frame_t frameP, sub_frame_t subframeP, unsigned char sched_subframe, uint8_t granted_UEs, unsigned int *nCCE, unsigned int *nCCE_available, uint16_t *first_rb){ - - DCI0_5MHz_TDD_1_6_t *ULSCH_dci_tdd16; - DCI0_5MHz_FDD_t *ULSCH_dci_fdd; - DCI_PDU *DCI_pdu= &eNB_mac_inst[module_idP].DCI_pdu; - - uint8_t rb_table_index=0, aggregation=2; - uint32_t rballoc; - uint8_t cba_group, cba_resources; - uint8_t required_rbs[NUM_MAX_CBA_GROUP], weight[NUM_MAX_CBA_GROUP], num_cba_resources[NUM_MAX_CBA_GROUP]; - uint8_t available_rbs= ceil(mac_xface->lte_frame_parms->N_RB_UL-1-*first_rb); - uint8_t remaining_rbs= available_rbs; - uint8_t allocated_rbs; - // We compute the weight of each group and initialize some variables - for (cba_group=0;cba_group<eNB_mac_inst[module_idP].num_active_cba_groups;cba_group++) { - // UEs in PUSCH with traffic - weight[cba_group] = find_num_active_UEs_in_cbagroup(module_idP, cba_group); - required_rbs[cba_group] = 0; - num_cba_resources[cba_group]=0; - } - //LOG_D(MAC, "[eNB ] CBA granted ues are %d\n",granted_UEs ); - for (cba_group=0;cba_group<eNB_mac_inst[module_idP].num_active_cba_groups && (*nCCE_available > (1<<aggregation));cba_group++) { - if (remaining_rbs <= 0 ) - break; - // If the group needs some resource - if ((weight[cba_group] > 0) && eNB_mac_inst[module_idP].cba_rnti[cba_group] != 0){ - // to be refined in case of : granted_UEs >> weight[cba_group]*available_rbs - required_rbs[cba_group] = (uint8_t)ceil((weight[cba_group]*available_rbs)/granted_UEs); - - while (remaining_rbs < required_rbs[cba_group] ) - required_rbs[cba_group]--; - - /* - while (rb_table[rb_table_index] < required_rbs[cba_group]) - rb_table_index++; - - while (rb_table[rb_table_index] > remaining_rbs ) - rb_table_index--; - - remaining_rbs-=rb_table[rb_table_index]; - required_rbs[cba_group]=rb_table[rb_table_index]; - */ - // to be refined - if (weight[cba_group] < required_rbs[cba_group]) - num_cba_resources[cba_group]=(uint8_t)ceil(weight[cba_group]/2.0); - else - num_cba_resources[cba_group]=(uint8_t)ceil(required_rbs[cba_group]/2.0); - - while ((*nCCE) + (1<<aggregation) * num_cba_resources[cba_group] > *nCCE_available) - num_cba_resources[cba_group]--; - - LOG_N(MAC,"[eNB %d] Frame %d, subframeP %d: cba group %d weight/granted_ues %d/%d available/required rb (%d/%d), num resources %d->1 (*scaled down*) \n", - module_idP, frameP, subframeP, cba_group, - weight[cba_group], granted_UEs, available_rbs,required_rbs[cba_group], - num_cba_resources[cba_group]); - - num_cba_resources[cba_group]=1; - - } - } - // phase 2 - for (cba_group=0;cba_group<eNB_mac_inst[module_idP].num_active_cba_groups;cba_group++) { - for (cba_resources=0; cba_resources < num_cba_resources[cba_group]; cba_resources++){ - rb_table_index =0; - // check if there was an allocation for this group in the 1st phase - if (required_rbs[cba_group] == 0 ) - continue; - - while (rb_table[rb_table_index] < (uint8_t) ceil(required_rbs[cba_group] / num_cba_resources[cba_group]) ) - rb_table_index++; - - while (rb_table[rb_table_index] > remaining_rbs ) - rb_table_index--; - - remaining_rbs-=rb_table[rb_table_index]; - allocated_rbs=rb_table[rb_table_index]; - - rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_UL, - *first_rb, - rb_table[rb_table_index]); - - *first_rb+=rb_table[rb_table_index]; - LOG_D(MAC,"[eNB %d] Frame %d, subframeP %d: CBA %d rnti %x, total/required/allocated/remaining rbs (%d/%d/%d/%d), rballoc %d, nCCE (%d/%d)\n", - module_idP, frameP, subframeP, cba_group,eNB_mac_inst[module_idP].cba_rnti[cba_group], - available_rbs, required_rbs[cba_group], allocated_rbs, remaining_rbs,rballoc, - *nCCE_available,*nCCE); - - - if (mac_xface->lte_frame_parms->frame_type == TDD) { - ULSCH_dci_tdd16 = (DCI0_5MHz_TDD_1_6_t *)eNB_mac_inst[module_idP].UE_template[cba_group].ULSCH_DCI[0]; - - ULSCH_dci_tdd16->type = 0; - ULSCH_dci_tdd16->hopping = 0; - ULSCH_dci_tdd16->rballoc = rballoc; - ULSCH_dci_tdd16->mcs = 2; - ULSCH_dci_tdd16->ndi = 1; - ULSCH_dci_tdd16->TPC = 1; - ULSCH_dci_tdd16->cshift = cba_group; - ULSCH_dci_tdd16->dai = eNB_mac_inst[module_idP].UE_template[cba_group].DAI_ul[sched_subframe]; - ULSCH_dci_tdd16->cqi_req = 1; - - //add_ue_spec_dci - add_common_dci(DCI_pdu, - ULSCH_dci_tdd16, - eNB_mac_inst[module_idP].cba_rnti[cba_group], - sizeof(DCI0_5MHz_TDD_1_6_t), - aggregation, - sizeof_DCI0_5MHz_TDD_1_6_t, - format0, - 0); - } - else { - ULSCH_dci_fdd = (DCI0_5MHz_FDD_t *)eNB_mac_inst[module_idP].UE_template[cba_group].ULSCH_DCI[0]; - - ULSCH_dci_fdd->type = 0; - ULSCH_dci_fdd->hopping = 0; - ULSCH_dci_fdd->rballoc = rballoc; - ULSCH_dci_fdd->mcs = 2; - ULSCH_dci_fdd->ndi = 1; - ULSCH_dci_fdd->TPC = 1; - ULSCH_dci_fdd->cshift = 0; - ULSCH_dci_fdd->cqi_req = 1; - - //add_ue_spec_dci - add_common_dci(DCI_pdu, - ULSCH_dci_fdd, - eNB_mac_inst[module_idP].cba_rnti[cba_group], - sizeof(DCI0_5MHz_FDD_t), - aggregation, - sizeof_DCI0_5MHz_FDD_t, - format0, - 0); - } - *nCCE = (*nCCE) + (1<<aggregation) * num_cba_resources[cba_group]; - *nCCE_available = mac_xface->get_nCCE_max(module_idP) - *nCCE; - // break;// for the moment only schedule one - } - } -} -#endif -void schedule_ulsch_rnti(module_id_t module_idP, - unsigned char cooperation_flag, - frame_t frameP, - sub_frame_t subframeP, - unsigned char sched_subframe, - uint8_t granted_UEs, - unsigned int *nCCE, - unsigned int *nCCE_available, - uint16_t *first_rb){ - module_id_t ue_mod_id = -1; - module_id_t next_ue = -1; - unsigned char aggregation = 2; - rnti_t rnti = -1; - uint8_t round = 0; - uint8_t harq_pid = 0; - void *ULSCH_dci = NULL; - LTE_eNB_UE_stats *eNB_UE_stats = NULL; - DCI_PDU *DCI_pdu = &eNB_mac_inst[module_idP].DCI_pdu; - uint8_t status = 0; - uint8_t rb_table_index = -1; - uint16_t TBS,i; - uint32_t buffer_occupancy; - uint32_t tmp_bsr; - uint32_t cqi_req,cshift,ndi,mcs,rballoc; - - for (ue_mod_id=0;ue_mod_id<granted_UEs && (*nCCE_available > (1<<aggregation));ue_mod_id++) { - - // msg("[MAC][eNB] subframeP %d: checking UE_id %d\n",subframeP,UE_id); - next_ue = ue_mod_id; // find next ue to schedule - // msg("[MAC][eNB] subframeP %d: next ue %d\n",subframeP,next_ue); - rnti = find_UE_RNTI(module_idP,next_ue); // radio network temp id is obtained - // msg("[MAC][eNB] subframeP %d: rnti %x\n",subframeP,rnti); - - if (rnti==0) // if so, go to next UE - continue; - - eNB_UE_stats = mac_xface->get_eNB_UE_stats(module_idP,rnti); - if (eNB_UE_stats==NULL) - mac_xface->macphy_exit("[MAC][eNB] Cannot find eNB_UE_stats\n"); - - LOG_I(MAC,"[eNB %d] Scheduler Frame %d, subframeP %d, nCCE %d: Checking ULSCH next UE_id %d mode id %d (rnti %x,mode %s), format 0\n", - module_idP,frameP,subframeP,*nCCE,next_ue,module_idP, rnti,mode_string[eNB_UE_stats->mode]); - - if (eNB_UE_stats->mode == PUSCH) { // ue has a ulsch channel - int8_t ret; - // Get candidate harq_pid from PHY - ret = mac_xface->get_ue_active_harq_pid(module_idP,rnti,subframeP,&harq_pid,&round,1); - LOG_I(MAC,"Got harq_pid %d, round %d, next_ue %d\n",harq_pid,round,next_ue); - - /* [SR] 01/07/13: Don't schedule UE if we cannot get harq pid */ -#ifndef EXMIMO_IOT - if ((((UE_is_to_be_scheduled(module_idP,ue_mod_id)>0)) || (round>0) || ((frameP%10)==0)) && (ret == 0)) - // if there is information on bsr of DCCH, DTCH or if there is UL_SR, or if there is a packet to retransmit, or we want to schedule a periodic feedback every 10 frames -#else - if (round==0) -#endif - { - LOG_D(MAC,"[eNB %d][PUSCH %x] Frame %d subframeP %d Scheduling UE %d (SR %d)\n", - module_idP,rnti,frameP,subframeP,ue_mod_id, - eNB_mac_inst[module_idP].UE_template[ue_mod_id].ul_SR); - - // reset the scheduling request - eNB_mac_inst[module_idP].UE_template[ue_mod_id].ul_SR = 0; - - aggregation = process_ue_cqi(module_idP,next_ue); // =2 by default!! - // msg("[MAC][eNB] subframeP %d: aggregation %d\n",subframeP,aggregation); - - status = mac_get_rrc_status(module_idP,1,next_ue); - - if (status < RRC_CONNECTED) - cqi_req = 0; - else - cqi_req = 1; - - - if (round > 0) { - ndi = eNB_mac_inst[module_idP].UE_template[ue_mod_id].oldNDI_UL[harq_pid]; - mcs = (round&3) + 28; //not correct for round==4! - } - else { - ndi = 1-eNB_mac_inst[module_idP].UE_template[ue_mod_id].oldNDI_UL[harq_pid]; - eNB_mac_inst[module_idP].UE_template[ue_mod_id].oldNDI_UL[harq_pid]=ndi; - mcs = openair_daq_vars.target_ue_ul_mcs; - } - - LOG_D(MAC,"[eNB %d] ULSCH scheduler: Ndi %d, mcs %d\n",module_idP,ndi,mcs); - - if((cooperation_flag > 0) && (next_ue == 1)) { // Allocation on same set of RBs - // RIV:resource indication value // function in openair1/PHY/LTE_TRANSPORT/dci_tools.c - rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_UL, - ((next_ue-1)*4),//openair_daq_vars.ue_ul_nb_rb), - 4);//openair_daq_vars.ue_ul_nb_rb); - } - else if ((round==0) && (mcs < 29)) { - rb_table_index = 1; - TBS = mac_xface->get_TBS_UL(mcs,rb_table[rb_table_index]); - buffer_occupancy = ((eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID0] == 0) && - (eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID1] == 0) && - (eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID2] == 0) && - (eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID3] == 0))? - BSR_TABLE[10] : // This is when we've received SR and buffers are fully served - BSR_TABLE[eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID0]]+ - BSR_TABLE[eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID1]]+ - BSR_TABLE[eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID2]]+ - BSR_TABLE[eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID3]]; // This is when remaining data in UE buffers (even if SR is triggered) - - LOG_D(MAC,"[eNB %d][PUSCH %d/%x] Frame %d subframeP %d Scheduled UE, BSR for LCGID0 %d, LCGID1 %d, LCGID2 %d LCGID3 %d, BO %d\n", - module_idP, - ue_mod_id, - rnti, - frameP, - subframeP, - eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID0], - eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID1], - eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID2], - eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID3], - buffer_occupancy); - - while ((TBS < buffer_occupancy) && - rb_table[rb_table_index]<(mac_xface->lte_frame_parms->N_RB_UL-1-*first_rb)){ - // continue until we've exhauster the UEs request or the total number of available PRBs - /* LOG_I(MAC,"[eNB %d][PUSCH %x] Frame %d subframeP %d Scheduled UE (rb_table_index %d => TBS %d)\n", - module_idP,rnti,frameP,subframeP, - rb_table_index,TBS); - */ - rb_table_index++; - TBS = mac_xface->get_TBS_UL(mcs,rb_table[rb_table_index]); - } - - if (rb_table[rb_table_index]>(mac_xface->lte_frame_parms->N_RB_UL-1-*first_rb)) { - rb_table_index--; - TBS = mac_xface->get_TBS_UL(mcs,rb_table[rb_table_index]); - } - //rb_table_index = 8; - - LOG_I(MAC,"[eNB %d][PUSCH %d/%x] Frame %d subframeP %d Scheduled UE (mcs %d, first rb %d, nb_rb %d, rb_table_index %d, TBS %d, harq_pid %d)\n", - module_idP,ue_mod_id,rnti,frameP,subframeP,mcs, - *first_rb,rb_table[rb_table_index], - rb_table_index,mac_xface->get_TBS_UL(mcs,rb_table[rb_table_index]), - harq_pid); - - rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_UL, - *first_rb, - rb_table[rb_table_index]);//openair_daq_vars.ue_ul_nb_rb); - - *first_rb+=rb_table[rb_table_index]; // increment for next UE allocation - eNB_mac_inst[module_idP].UE_template[ue_mod_id].nb_rb_ul[harq_pid] = rb_table[rb_table_index]; //store for possible retransmission - - buffer_occupancy -= mac_xface->get_TBS_UL(mcs,rb_table[rb_table_index]); - i = bytes_to_bsr_index((int32_t)buffer_occupancy); - - // Adjust BSR entries for LCGIDs - if (i>0) { - if (eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID0] <= i) { - tmp_bsr = BSR_TABLE[eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID0]]; - eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID0] = 0; - if (BSR_TABLE[eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID1]] <= (buffer_occupancy-tmp_bsr)) { - tmp_bsr += BSR_TABLE[eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID1]]; - eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID1] = 0; - if (BSR_TABLE[eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID2]] <= (buffer_occupancy-tmp_bsr)) { - tmp_bsr += BSR_TABLE[eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID2]]; - eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID2] = 0; - if (BSR_TABLE[eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID3]] <= (buffer_occupancy-tmp_bsr)) { - tmp_bsr += BSR_TABLE[eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID3]]; - eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID3] = 0; - } else { - eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID3] = bytes_to_bsr_index((int32_t)BSR_TABLE[eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID3]] - ((int32_t)buffer_occupancy - (int32_t)tmp_bsr)); - } - } - else { - eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID2] = bytes_to_bsr_index((int32_t)BSR_TABLE[eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID2]] - ((int32_t)buffer_occupancy -(int32_t)tmp_bsr)); - } - } - else { - eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID1] = bytes_to_bsr_index((int32_t)BSR_TABLE[eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID1]] - (int32_t)buffer_occupancy); - } - } - else { - eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID0] = bytes_to_bsr_index((int32_t)BSR_TABLE[eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID0]] - (int32_t)buffer_occupancy); - } - } - else { // we have flushed all buffers so clear bsr - eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID0] = 0; - eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID1] = 0; - eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID2] = 0; - eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID3] = 0; - } - - - } // ndi==1 - else { //we schedule a retransmission - LOG_I(MAC,"[eNB %d][PUSCH %d/%x] Frame %d subframeP %d Scheduled UE retransmission (mcs %d, first rb %d, nb_rb %d, TBS %d, harq_pid %d)\n", - module_idP,ue_mod_id,rnti,frameP,subframeP,mcs, - *first_rb,eNB_mac_inst[module_idP].UE_template[ue_mod_id].nb_rb_ul[harq_pid], - mac_xface->get_TBS_UL(mcs,eNB_mac_inst[module_idP].UE_template[ue_mod_id].nb_rb_ul[harq_pid]), - harq_pid); - - rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_UL, - *first_rb, - eNB_mac_inst[module_idP].UE_template[ue_mod_id].nb_rb_ul[harq_pid]); - - *first_rb+=eNB_mac_inst[module_idP].UE_template[ue_mod_id].nb_rb_ul[harq_pid]; // increment for next UE allocation - } - - // Cyclic shift for DM RS - if(cooperation_flag == 2) { - if(next_ue == 1)// For Distriibuted Alamouti, cyclic shift applied to 2nd UE - cshift = 1; - else - cshift = 0; - } - else - cshift = 0;// values from 0 to 7 can be used for mapping the cyclic shift (36.211 , Table 5.5.2.1.1-1) - - if (mac_xface->lte_frame_parms->frame_type == TDD) { - switch (mac_xface->lte_frame_parms->N_RB_UL) { - case 6: - ULSCH_dci = eNB_mac_inst[module_idP].UE_template[next_ue].ULSCH_DCI[harq_pid]; - - ((DCI0_1_5MHz_TDD_1_6_t *)ULSCH_dci)->type = 0; - ((DCI0_1_5MHz_TDD_1_6_t *)ULSCH_dci)->hopping = 0; - ((DCI0_1_5MHz_TDD_1_6_t *)ULSCH_dci)->rballoc = rballoc; - ((DCI0_1_5MHz_TDD_1_6_t *)ULSCH_dci)->mcs = mcs; - ((DCI0_1_5MHz_TDD_1_6_t *)ULSCH_dci)->ndi = ndi; - ((DCI0_1_5MHz_TDD_1_6_t *)ULSCH_dci)->TPC = 1; - ((DCI0_1_5MHz_TDD_1_6_t *)ULSCH_dci)->cshift = cshift; - ((DCI0_1_5MHz_TDD_1_6_t *)ULSCH_dci)->padding = 0; - ((DCI0_1_5MHz_TDD_1_6_t *)ULSCH_dci)->dai = eNB_mac_inst[module_idP].UE_template[next_ue].DAI_ul[sched_subframe]; - ((DCI0_1_5MHz_TDD_1_6_t *)ULSCH_dci)->cqi_req = cqi_req; - - add_ue_spec_dci(DCI_pdu, - ULSCH_dci, - rnti, - sizeof(DCI0_1_5MHz_TDD_1_6_t), - aggregation, - sizeof_DCI0_1_5MHz_TDD_1_6_t, - format0, - 0); - break; - default: - case 25: - ULSCH_dci = eNB_mac_inst[module_idP].UE_template[next_ue].ULSCH_DCI[harq_pid]; - - ((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->type = 0; - ((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->hopping = 0; - ((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->rballoc = rballoc; - ((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->mcs = mcs; - ((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->ndi = ndi; - ((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->TPC = 1; - ((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->cshift = cshift; - ((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->padding = 0; - ((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->dai = eNB_mac_inst[module_idP].UE_template[next_ue].DAI_ul[sched_subframe]; - ((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->cqi_req = cqi_req; - - add_ue_spec_dci(DCI_pdu, - ULSCH_dci, - rnti, - sizeof(DCI0_5MHz_TDD_1_6_t), - aggregation, - sizeof_DCI0_5MHz_TDD_1_6_t, - format0, - 0); - break; - case 50: - ULSCH_dci = eNB_mac_inst[module_idP].UE_template[next_ue].ULSCH_DCI[harq_pid]; - - ((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->type = 0; - ((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->hopping = 0; - ((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->rballoc = rballoc; - ((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->mcs = mcs; - ((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->ndi = ndi; - ((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->TPC = 1; - ((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->cshift = cshift; - ((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->padding = 0; - ((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->dai = eNB_mac_inst[module_idP].UE_template[next_ue].DAI_ul[sched_subframe]; - ((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->cqi_req = cqi_req; - - add_ue_spec_dci(DCI_pdu, - ULSCH_dci, - rnti, - sizeof(DCI0_10MHz_TDD_1_6_t), - aggregation, - sizeof_DCI0_10MHz_TDD_1_6_t, - format0, - 0); - break; - case 100: - ULSCH_dci = eNB_mac_inst[module_idP].UE_template[next_ue].ULSCH_DCI[harq_pid]; - - ((DCI0_20MHz_TDD_1_6_t *)ULSCH_dci)->type = 0; - ((DCI0_20MHz_TDD_1_6_t *)ULSCH_dci)->hopping = 0; - ((DCI0_20MHz_TDD_1_6_t *)ULSCH_dci)->rballoc = rballoc; - ((DCI0_20MHz_TDD_1_6_t *)ULSCH_dci)->mcs = mcs; - ((DCI0_20MHz_TDD_1_6_t *)ULSCH_dci)->ndi = ndi; - ((DCI0_20MHz_TDD_1_6_t *)ULSCH_dci)->TPC = 1; - ((DCI0_20MHz_TDD_1_6_t *)ULSCH_dci)->cshift = cshift; - ((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->padding = 0; - ((DCI0_20MHz_TDD_1_6_t *)ULSCH_dci)->dai = eNB_mac_inst[module_idP].UE_template[next_ue].DAI_ul[sched_subframe]; - ((DCI0_20MHz_TDD_1_6_t *)ULSCH_dci)->cqi_req = cqi_req; - - add_ue_spec_dci(DCI_pdu, - ULSCH_dci, - rnti, - sizeof(DCI0_20MHz_TDD_1_6_t), - aggregation, - sizeof_DCI0_20MHz_TDD_1_6_t, - format0, - 0); - break; - } - } - else { //FDD - switch (mac_xface->lte_frame_parms->N_RB_UL) { - case 25: - default: - - ULSCH_dci = eNB_mac_inst[module_idP].UE_template[next_ue].ULSCH_DCI[harq_pid]; - - ((DCI0_5MHz_FDD_t *)ULSCH_dci)->type = 0; - ((DCI0_5MHz_FDD_t *)ULSCH_dci)->hopping = 0; - ((DCI0_5MHz_FDD_t *)ULSCH_dci)->rballoc = rballoc; - ((DCI0_5MHz_FDD_t *)ULSCH_dci)->mcs = mcs; - ((DCI0_5MHz_FDD_t *)ULSCH_dci)->ndi = ndi; - ((DCI0_5MHz_FDD_t *)ULSCH_dci)->TPC = 1; - ((DCI0_5MHz_FDD_t *)ULSCH_dci)->cshift = cshift; - ((DCI0_5MHz_FDD_t *)ULSCH_dci)->padding = 0; - ((DCI0_5MHz_FDD_t *)ULSCH_dci)->cqi_req = cqi_req; - - add_ue_spec_dci(DCI_pdu, - ULSCH_dci, - rnti, - sizeof(DCI0_5MHz_FDD_t), - aggregation, - sizeof_DCI0_5MHz_FDD_t, - format0, - 0); - break; - case 6: - ULSCH_dci = eNB_mac_inst[module_idP].UE_template[next_ue].ULSCH_DCI[harq_pid]; - - ((DCI0_1_5MHz_FDD_t *)ULSCH_dci)->type = 0; - ((DCI0_1_5MHz_FDD_t *)ULSCH_dci)->hopping = 0; - ((DCI0_1_5MHz_FDD_t *)ULSCH_dci)->rballoc = rballoc; - ((DCI0_1_5MHz_FDD_t *)ULSCH_dci)->mcs = mcs; - ((DCI0_1_5MHz_FDD_t *)ULSCH_dci)->ndi = ndi; - ((DCI0_1_5MHz_FDD_t *)ULSCH_dci)->TPC = 1; - ((DCI0_1_5MHz_FDD_t *)ULSCH_dci)->cshift = cshift; - ((DCI0_1_5MHz_FDD_t *)ULSCH_dci)->padding = 0; - ((DCI0_1_5MHz_FDD_t *)ULSCH_dci)->cqi_req = cqi_req; - - add_ue_spec_dci(DCI_pdu, - ULSCH_dci, - rnti, - sizeof(DCI0_1_5MHz_FDD_t), - aggregation, - sizeof_DCI0_1_5MHz_FDD_t, - format0, - 0); - break; - case 50: - ULSCH_dci = eNB_mac_inst[module_idP].UE_template[next_ue].ULSCH_DCI[harq_pid]; - - ((DCI0_10MHz_FDD_t *)ULSCH_dci)->type = 0; - ((DCI0_10MHz_FDD_t *)ULSCH_dci)->hopping = 0; - ((DCI0_10MHz_FDD_t *)ULSCH_dci)->rballoc = rballoc; - ((DCI0_10MHz_FDD_t *)ULSCH_dci)->mcs = mcs; - ((DCI0_10MHz_FDD_t *)ULSCH_dci)->ndi = ndi; - ((DCI0_10MHz_FDD_t *)ULSCH_dci)->TPC = 1; - ((DCI0_10MHz_FDD_t *)ULSCH_dci)->padding = 0; - ((DCI0_10MHz_FDD_t *)ULSCH_dci)->cshift = cshift; - ((DCI0_10MHz_FDD_t *)ULSCH_dci)->cqi_req = cqi_req; - - add_ue_spec_dci(DCI_pdu, - ULSCH_dci, - rnti, - sizeof(DCI0_10MHz_FDD_t), - aggregation, - sizeof_DCI0_10MHz_FDD_t, - format0, - 0); - break; - case 100: - ULSCH_dci = eNB_mac_inst[module_idP].UE_template[next_ue].ULSCH_DCI[harq_pid]; - - ((DCI0_20MHz_FDD_t *)ULSCH_dci)->type = 0; - ((DCI0_20MHz_FDD_t *)ULSCH_dci)->hopping = 0; - ((DCI0_20MHz_FDD_t *)ULSCH_dci)->rballoc = rballoc; - ((DCI0_20MHz_FDD_t *)ULSCH_dci)->mcs = mcs; - ((DCI0_20MHz_FDD_t *)ULSCH_dci)->ndi = ndi; - ((DCI0_20MHz_FDD_t *)ULSCH_dci)->TPC = 1; - ((DCI0_20MHz_FDD_t *)ULSCH_dci)->padding = 0; - ((DCI0_20MHz_FDD_t *)ULSCH_dci)->cshift = cshift; - ((DCI0_20MHz_FDD_t *)ULSCH_dci)->cqi_req = cqi_req; - - add_ue_spec_dci(DCI_pdu, - ULSCH_dci, - rnti, - sizeof(DCI0_20MHz_FDD_t), - aggregation, - sizeof_DCI0_20MHz_FDD_t, - format0, - 0); - break; - - } - } - //#ifdef DEBUG_eNB_SCHEDULER - // dump_dci(mac_xface->lte_frame_parms, - // &DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci+DCI_pdu->Num_ue_spec_dci-1]); - //#endif - add_ue_ulsch_info(module_idP, - next_ue, - subframeP, - S_UL_SCHEDULED); - - *nCCE = (*nCCE) + (1<<aggregation); - *nCCE_available = mac_xface->get_nCCE_max(module_idP) - *nCCE; - //msg("[MAC][eNB %d][ULSCH Scheduler] Frame %d, subframeP %d: Generated ULSCH DCI for next UE_id %d, format 0\n", module_idP,frameP,subframeP,next_ue); - - //break; // leave loop after first UE is schedule (avoids m - } // UE_is_to_be_scheduled - } // UE is in PUSCH - } // loop over UE_id -} - - - -uint32_t allocate_prbs(module_id_t ue_mod_idP,unsigned char nb_rb, uint32_t *rballoc) { - - int i; - uint32_t rballoc_dci=0; - unsigned char nb_rb_alloc=0; - - for (i=0;i<(mac_xface->lte_frame_parms->N_RB_DL-2);i+=2) { - if (((*rballoc>>i)&3)==0) { - *rballoc |= (3<<i); - rballoc_dci |= (1<<((12-i)>>1)); - nb_rb_alloc+=2; - } - if (nb_rb_alloc==nb_rb) - return(rballoc_dci); - } - - if ((mac_xface->lte_frame_parms->N_RB_DL&1)==1) { - if ((*rballoc>>(mac_xface->lte_frame_parms->N_RB_DL-1)&1)==0) { - *rballoc |= (1<<(mac_xface->lte_frame_parms->N_RB_DL-1)); - rballoc_dci |= 1;//(1<<(mac_xface->lte_frame_parms->N_RB_DL>>1)); - } - } - return(rballoc_dci); -} - - -uint32_t allocate_prbs_sub(int nb_rb, uint8_t *rballoc) { - - int check=0;//check1=0,check2=0; - uint32_t rballoc_dci=0; - //uint8_t number_of_subbands=13; - - LOG_T(MAC,"*****Check1RBALLOC****: %d%d%d%d (nb_rb %d,N_RBGS %d)\n", - rballoc[3],rballoc[2],rballoc[1],rballoc[0],nb_rb,mac_xface->lte_frame_parms->N_RBGS); - while((nb_rb >0) && (check < mac_xface->lte_frame_parms->N_RBGS)){ - //printf("rballoc[%d] %d\n",check,rballoc[check]); - if(rballoc[check] == 1){ - rballoc_dci |= (1<<((mac_xface->lte_frame_parms->N_RBGS-1)-check)); - switch (mac_xface->lte_frame_parms->N_RB_DL) { - case 6: - nb_rb--; - case 25: - if ((check == mac_xface->lte_frame_parms->N_RBGS-1)) - nb_rb--; - else - nb_rb-=2; - break; - case 50: - if ((check == mac_xface->lte_frame_parms->N_RBGS-1)) - nb_rb-=2; - else - nb_rb-=3; - break; - case 100: - nb_rb-=4; - break; - } - } - //printf("rb_alloc %x\n",rballoc_dci); - check = check+1; - // check1 = check1+2; - } - // rballoc_dci = (rballoc_dci)&(0x1fff); - LOG_T(MAC,"*********RBALLOC : %x\n",rballoc_dci); - // exit(-1); - return (rballoc_dci); -} - - -void fill_DLSCH_dci(module_id_t module_idP,frame_t frameP, sub_frame_t subframeP,uint32_t RBalloc,uint8_t RA_scheduled,int mbsfn_flag) { - - // loop over all allocated UEs and compute frequency allocations for PDSCH - module_id_t ue_mod_id = -1; - uint8_t first_rb,nb_rb=3; - rnti_t rnti; - unsigned char vrb_map[100]; - uint8_t rballoc_sub[mac_xface->lte_frame_parms->N_RBGS]; - //uint8_t number_of_subbands=13; - uint32_t rballoc = RBalloc; - - unsigned char round; - unsigned char harq_pid; - void *DLSCH_dci=NULL; - DCI_PDU *DCI_pdu= &eNB_mac_inst[module_idP].DCI_pdu; - int i; - void *BCCH_alloc_pdu=(void*)&eNB_mac_inst[module_idP].BCCH_alloc_pdu; - int size_bits,size_bytes; - - if (mbsfn_flag>0) - return; - - start_meas(&eNB_mac_inst[module_idP].fill_DLSCH_dci); - - // clear vrb_map - memset(vrb_map,0,100); - - // SI DLSCH - // printf("BCCH check\n"); - if (eNB_mac_inst[module_idP].bcch_active == 1) { - eNB_mac_inst[module_idP].bcch_active = 0; - LOG_D(MAC,"[eNB %d] Frame %d subframeP %d: BCCH active\n", module_idP, frameP, subframeP); - // randomize frequency allocation for SI - first_rb = (unsigned char)(taus()%(mac_xface->lte_frame_parms->N_RB_DL-4)); - if (mac_xface->lte_frame_parms->frame_type == TDD) { - - } - else { - BCCH_alloc_pdu_fdd.rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); - rballoc |= mac_xface->get_rballoc(BCCH_alloc_pdu_fdd.vrb_type,BCCH_alloc_pdu_fdd.rballoc); - } - - vrb_map[first_rb] = 1; - vrb_map[first_rb+1] = 1; - vrb_map[first_rb+2] = 1; - vrb_map[first_rb+3] = 1; - - if (mac_xface->lte_frame_parms->frame_type == TDD) { - switch (mac_xface->lte_frame_parms->N_RB_DL) { - case 6: - ((DCI1A_1_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); - ((DCI1A_1_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->type = 1; - ((DCI1A_1_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->vrb_type = 0; - ((DCI1A_1_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->ndi = 1; - ((DCI1A_1_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rv = 1; - ((DCI1A_1_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->harq_pid = 0; - ((DCI1A_1_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->TPC = 1; - ((DCI1A_1_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->padding = 0; - rballoc |= mac_xface->get_rballoc(0,((DCI1A_1_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rballoc); - add_common_dci(DCI_pdu, - BCCH_alloc_pdu, - SI_RNTI, - sizeof(DCI1A_1_5MHz_TDD_1_6_t), - 2, - sizeof_DCI1A_1_5MHz_TDD_1_6_t, - format1A,0); - break; - case 25: - ((DCI1A_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); - ((DCI1A_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->type = 1; - ((DCI1A_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->vrb_type = 0; - ((DCI1A_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->ndi = 1; - ((DCI1A_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rv = 1; - ((DCI1A_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->harq_pid = 0; - ((DCI1A_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->TPC = 1; - ((DCI1A_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->padding = 0; - rballoc |= mac_xface->get_rballoc(0,((DCI1A_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rballoc); - add_common_dci(DCI_pdu, - BCCH_alloc_pdu, - SI_RNTI, - sizeof(DCI1A_5MHz_TDD_1_6_t), - 2, - sizeof_DCI1A_5MHz_TDD_1_6_t, - format1A,0); - break; - case 50: - ((DCI1A_10MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); - ((DCI1A_10MHz_TDD_1_6_t*)BCCH_alloc_pdu)->type = 1; - ((DCI1A_10MHz_TDD_1_6_t*)BCCH_alloc_pdu)->vrb_type = 0; - ((DCI1A_10MHz_TDD_1_6_t*)BCCH_alloc_pdu)->ndi = 1; - ((DCI1A_10MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rv = 1; - ((DCI1A_10MHz_TDD_1_6_t*)BCCH_alloc_pdu)->harq_pid = 0; - ((DCI1A_10MHz_TDD_1_6_t*)BCCH_alloc_pdu)->TPC = 1; - ((DCI1A_10MHz_TDD_1_6_t*)BCCH_alloc_pdu)->padding = 0; - rballoc |= mac_xface->get_rballoc(0,((DCI1A_10MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rballoc); - add_common_dci(DCI_pdu, - BCCH_alloc_pdu, - SI_RNTI, - sizeof(DCI1A_10MHz_TDD_1_6_t), - 2, - sizeof_DCI1A_10MHz_TDD_1_6_t, - format1A,0); - break; - case 100: - ((DCI1A_20MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); - ((DCI1A_20MHz_TDD_1_6_t*)BCCH_alloc_pdu)->type = 1; - ((DCI1A_20MHz_TDD_1_6_t*)BCCH_alloc_pdu)->vrb_type = 0; - ((DCI1A_20MHz_TDD_1_6_t*)BCCH_alloc_pdu)->ndi = 1; - ((DCI1A_20MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rv = 1; - ((DCI1A_20MHz_TDD_1_6_t*)BCCH_alloc_pdu)->harq_pid = 0; - ((DCI1A_20MHz_TDD_1_6_t*)BCCH_alloc_pdu)->TPC = 1; - ((DCI1A_20MHz_TDD_1_6_t*)BCCH_alloc_pdu)->padding = 0; - rballoc |= mac_xface->get_rballoc(0,((DCI1A_20MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rballoc); - add_common_dci(DCI_pdu, - BCCH_alloc_pdu, - SI_RNTI, - sizeof(DCI1A_20MHz_TDD_1_6_t), - 2, - sizeof_DCI1A_20MHz_TDD_1_6_t, - format1A,0); - break; - } - } - else { - switch (mac_xface->lte_frame_parms->N_RB_DL) { - case 6: - ((DCI1A_1_5MHz_FDD_t*)BCCH_alloc_pdu)->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); - ((DCI1A_1_5MHz_FDD_t*)BCCH_alloc_pdu)->type = 1; - ((DCI1A_1_5MHz_FDD_t*)BCCH_alloc_pdu)->vrb_type = 0; - ((DCI1A_1_5MHz_FDD_t*)BCCH_alloc_pdu)->ndi = 1; - ((DCI1A_1_5MHz_FDD_t*)BCCH_alloc_pdu)->rv = 1; - ((DCI1A_1_5MHz_FDD_t*)BCCH_alloc_pdu)->harq_pid = 0; - ((DCI1A_1_5MHz_FDD_t*)BCCH_alloc_pdu)->TPC = 1; - ((DCI1A_1_5MHz_FDD_t*)BCCH_alloc_pdu)->padding = 0; - - rballoc |= mac_xface->get_rballoc(0,((DCI1A_1_5MHz_FDD_t*)BCCH_alloc_pdu)->rballoc); - add_common_dci(DCI_pdu, - BCCH_alloc_pdu, - SI_RNTI, - sizeof(DCI1A_1_5MHz_FDD_t), - 2, - sizeof_DCI1A_1_5MHz_FDD_t, - format1A,0); - break; - case 25: - ((DCI1A_5MHz_FDD_t*)BCCH_alloc_pdu)->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); - ((DCI1A_5MHz_FDD_t*)BCCH_alloc_pdu)->type = 1; - ((DCI1A_5MHz_FDD_t*)BCCH_alloc_pdu)->vrb_type = 0; - ((DCI1A_5MHz_FDD_t*)BCCH_alloc_pdu)->ndi = 1; - ((DCI1A_5MHz_FDD_t*)BCCH_alloc_pdu)->rv = 1; - ((DCI1A_5MHz_FDD_t*)BCCH_alloc_pdu)->harq_pid = 0; - ((DCI1A_5MHz_FDD_t*)BCCH_alloc_pdu)->TPC = 1; - ((DCI1A_5MHz_FDD_t*)BCCH_alloc_pdu)->padding = 0; - - rballoc |= mac_xface->get_rballoc(0,((DCI1A_5MHz_FDD_t*)BCCH_alloc_pdu)->rballoc); - add_common_dci(DCI_pdu, - BCCH_alloc_pdu, - SI_RNTI, - sizeof(DCI1A_5MHz_FDD_t), - 2, - sizeof_DCI1A_5MHz_FDD_t, - format1A,0); - break; - case 50: - ((DCI1A_10MHz_FDD_t*)BCCH_alloc_pdu)->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); - ((DCI1A_10MHz_FDD_t*)BCCH_alloc_pdu)->type = 1; - ((DCI1A_10MHz_FDD_t*)BCCH_alloc_pdu)->vrb_type = 0; - ((DCI1A_10MHz_FDD_t*)BCCH_alloc_pdu)->ndi = 1; - ((DCI1A_10MHz_FDD_t*)BCCH_alloc_pdu)->rv = 1; - ((DCI1A_10MHz_FDD_t*)BCCH_alloc_pdu)->harq_pid = 0; - ((DCI1A_10MHz_FDD_t*)BCCH_alloc_pdu)->TPC = 1; - ((DCI1A_10MHz_FDD_t*)BCCH_alloc_pdu)->padding = 0; - - rballoc |= mac_xface->get_rballoc(0,((DCI1A_10MHz_FDD_t*)BCCH_alloc_pdu)->rballoc); - add_common_dci(DCI_pdu, - BCCH_alloc_pdu, - SI_RNTI, - sizeof(DCI1A_10MHz_FDD_t), - 2, - sizeof_DCI1A_10MHz_FDD_t, - format1A,0); - break; - case 100: - ((DCI1A_20MHz_FDD_t*)BCCH_alloc_pdu)->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); - ((DCI1A_20MHz_FDD_t*)BCCH_alloc_pdu)->type = 1; - ((DCI1A_20MHz_FDD_t*)BCCH_alloc_pdu)->vrb_type = 0; - ((DCI1A_20MHz_FDD_t*)BCCH_alloc_pdu)->ndi = 1; - ((DCI1A_20MHz_FDD_t*)BCCH_alloc_pdu)->rv = 1; - ((DCI1A_20MHz_FDD_t*)BCCH_alloc_pdu)->harq_pid = 0; - ((DCI1A_20MHz_FDD_t*)BCCH_alloc_pdu)->TPC = 1; - ((DCI1A_20MHz_FDD_t*)BCCH_alloc_pdu)->padding = 0; - - rballoc |= mac_xface->get_rballoc(0,((DCI1A_20MHz_FDD_t*)BCCH_alloc_pdu)->rballoc); - add_common_dci(DCI_pdu, - BCCH_alloc_pdu, - SI_RNTI, - sizeof(DCI1A_20MHz_FDD_t), - 2, - sizeof_DCI1A_20MHz_FDD_t, - format1A,0); - break; - } - } - } - if (RA_scheduled == 1) { - for (i=0;i<NB_RA_PROC_MAX;i++) { - - if (eNB_mac_inst[module_idP].RA_template[i].generate_rar == 1) { - - //FK: postponed to fill_rar - //eNB_mac_inst[module_idP].RA_template[i].generate_rar = 0; - - LOG_D(MAC,"[eNB %d] Frame %d, subframeP %d: Generating RAR DCI (proc %d), RA_active %d format 1A (%d,%d))\n", - module_idP,frameP, subframeP,i, - eNB_mac_inst[module_idP].RA_template[i].RA_active, - eNB_mac_inst[module_idP].RA_template[i].RA_dci_fmt1, - eNB_mac_inst[module_idP].RA_template[i].RA_dci_size_bits1); - // randomize frequency allocation for RA - while (1) { - first_rb = (unsigned char)(taus()%(mac_xface->lte_frame_parms->N_RB_DL-4)); - if ((vrb_map[first_rb] != 1) && (vrb_map[first_rb+3] != 1)) - break; - } - vrb_map[first_rb] = 1; - vrb_map[first_rb+1] = 1; - vrb_map[first_rb+2] = 1; - vrb_map[first_rb+3] = 1; - - if (mac_xface->lte_frame_parms->frame_type == TDD) { - switch(mac_xface->lte_frame_parms->N_RB_DL) { - case 6: - ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->type=1; - ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type=0; - ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->ndi=1; - ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rv=0; - ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->mcs=0; - ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->harq_pid=0; - ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->TPC=1; - ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->padding=0; - ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); - rballoc |= mac_xface->get_rballoc(((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type, - ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc); - break; - case 25: - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->type=1; - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type=0; - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->ndi=1; - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rv=0; - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->mcs=0; - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->harq_pid=0; - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->TPC=1; - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->padding=0; - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); - rballoc |= mac_xface->get_rballoc(((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type, - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc); - break; - case 50: - ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->type=1; - ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type=0; - ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->ndi=1; - ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rv=0; - ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->mcs=0; - ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->harq_pid=0; - ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->TPC=1; - ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->padding=0; - ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); - rballoc |= mac_xface->get_rballoc(((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type, - ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc); - break; - case 100: - ((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->type=1; - ((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type=0; - ((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->ndi=1; - ((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rv=0; - ((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->mcs=0; - ((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->harq_pid=0; - ((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->TPC=1; - ((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->padding=0; - ((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); - rballoc |= mac_xface->get_rballoc(((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type, - ((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc); - break; - default: - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->type=1; - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type=0; - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->ndi=1; - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rv=0; - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->mcs=0; - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->harq_pid=0; - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->TPC=1; - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->padding=0; - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); - rballoc |= mac_xface->get_rballoc(((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type, - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc); - break; - } - } - else { - switch(mac_xface->lte_frame_parms->N_RB_DL) { - case 6: - ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->type=1; - ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type=0; - ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->ndi=1; - ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rv=0; - ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->mcs=0; - ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->harq_pid=0; - ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->TPC=1; - ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->padding=0; - ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); - rballoc |= mac_xface->get_rballoc(((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type, - ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc); - break; - case 25: - ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->type=1; - ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type=0; - ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->ndi=1; - ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rv=0; - ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->mcs=0; - ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->harq_pid=0; - ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->TPC=1; - ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->padding=0; - ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_UL,first_rb,4); - rballoc |= mac_xface->get_rballoc(((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type, - ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc); - break; - case 50: - ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->type=1; - ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type=0; - ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->ndi=1; - ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rv=0; - ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->mcs=0; - ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->harq_pid=0; - ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->TPC=1; - ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->padding=0; - ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); - rballoc |= mac_xface->get_rballoc(((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type, - ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc); - break; - case 100: - ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->type=1; - ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type=0; - ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->ndi=1; - ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rv=0; - ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->mcs=0; - ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->harq_pid=0; - ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->TPC=1; - ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->padding=0; - ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); - rballoc |= mac_xface->get_rballoc(((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type, - ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc); - break; - default: - break; - } - } - add_common_dci(DCI_pdu, - (void*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0], - eNB_mac_inst[module_idP].RA_template[i].RA_rnti, - eNB_mac_inst[module_idP].RA_template[i].RA_dci_size_bytes1, - 2, - eNB_mac_inst[module_idP].RA_template[i].RA_dci_size_bits1, - eNB_mac_inst[module_idP].RA_template[i].RA_dci_fmt1, - 1); - - - - LOG_D(MAC,"[eNB %d] Frame %d: Adding common dci for RA%d (RAR) RA_active %d\n",module_idP,frameP,i, - eNB_mac_inst[module_idP].RA_template[i].RA_active); - } - if (eNB_mac_inst[module_idP].RA_template[i].generate_Msg4_dci == 1) { - - // randomize frequency allocation for RA - while (1) { - first_rb = (unsigned char)(taus()%(mac_xface->lte_frame_parms->N_RB_DL-4)); - if ((vrb_map[first_rb] != 1) && (vrb_map[first_rb+3] != 1)) - break; - } - vrb_map[first_rb] = 1; - vrb_map[first_rb+1] = 1; - vrb_map[first_rb+2] = 1; - vrb_map[first_rb+3] = 1; - - if (mac_xface->lte_frame_parms->frame_type == TDD) { - switch (mac_xface->lte_frame_parms->N_RB_DL) { - case 6: - ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->type=1; - ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type=0; - ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rv=0; - ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->harq_pid=0; - ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->TPC=1; - ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->padding=0; - ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc= mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); - rballoc |= mac_xface->get_rballoc(((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type, - ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc); - break; - case 25: - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->type=1; - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type=0; - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rv=0; - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->harq_pid=0; - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->TPC=1; - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->padding=0; - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc= mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); - rballoc |= mac_xface->get_rballoc(((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type, - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc); - break; - case 50: - ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->type=1; - ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type=0; - ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rv=0; - ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->harq_pid=0; - ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->TPC=1; - ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->padding=0; - ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc= mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); - rballoc |= mac_xface->get_rballoc(((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type, - ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc); - break; - case 100: - ((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->type=1; - ((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type=0; - ((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rv=0; - ((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->harq_pid=0; - ((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->TPC=1; - ((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc= mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); - rballoc |= mac_xface->get_rballoc(((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type, - ((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc); - break; - default: - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->type=1; - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type=0; - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rv=0; - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->harq_pid=0; - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->TPC=1; - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->padding=0; - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc= mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); - rballoc |= mac_xface->get_rballoc(((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type, - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc); - break; - } - } - else { - switch (mac_xface->lte_frame_parms->N_RB_DL) { - - case 6: - ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->type=1; - ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type=0; - ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rv=0; - ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->harq_pid=0; - ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->TPC=1; - ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->padding=0; - ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc= mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); - rballoc |= mac_xface->get_rballoc(((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type, - ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc); - break; - case 25: - ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->type=1; - ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type=0; - ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rv=0; - ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->harq_pid=0; - ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->TPC=1; - ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->padding=0; - ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc= mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); - rballoc |= mac_xface->get_rballoc(((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type, - ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc); - break; - case 50: - ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->type=1; - ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type=0; - ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rv=0; - ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->harq_pid=0; - ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->TPC=1; - ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->padding=0; - ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc= mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); - rballoc |= mac_xface->get_rballoc(((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type, - ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc); - break; - case 100: - ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->type=1; - ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type=0; - ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rv=0; - ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->harq_pid=0; - ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->TPC=1; - ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->padding=0; - ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc= mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); - rballoc |= mac_xface->get_rballoc(((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type, - ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc); - break; - default: - ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->type=1; - ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type=0; - ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rv=0; - ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->harq_pid=0; - ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->TPC=1; - ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc= mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); - rballoc |= mac_xface->get_rballoc(((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type, - ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc); - break; - } - } - - add_ue_spec_dci(DCI_pdu, - (void*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0], - eNB_mac_inst[module_idP].RA_template[i].rnti, - eNB_mac_inst[module_idP].RA_template[i].RA_dci_size_bytes2, - 1, - eNB_mac_inst[module_idP].RA_template[i].RA_dci_size_bits2, - eNB_mac_inst[module_idP].RA_template[i].RA_dci_fmt2, - 0); - LOG_D(MAC,"[eNB %d][RAPROC] Frame %d, subframeP %d: Adding ue specific dci (rnti %x) for Msg4\n", - module_idP,frameP,subframeP,eNB_mac_inst[module_idP].RA_template[i].rnti); - eNB_mac_inst[module_idP].RA_template[i].generate_Msg4_dci=0; - - } - else if (eNB_mac_inst[module_idP].RA_template[i].wait_ack_Msg4==1) { - // check HARQ status and retransmit if necessary - LOG_I(MAC,"[eNB %d][RAPROC] Frame %d, subframeP %d: Checking if Msg4 was acknowledged: \n", - module_idP,frameP,subframeP); - // Get candidate harq_pid from PHY - mac_xface->get_ue_active_harq_pid(module_idP,eNB_mac_inst[module_idP].RA_template[i].rnti,subframeP,&harq_pid,&round,0); - if (round>0) { - // we have to schedule a retransmission - if (mac_xface->lte_frame_parms->frame_type == TDD) - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->ndi=1; - else - ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->ndi=1; - // randomize frequency allocation for RA - while (1) { - first_rb = (unsigned char)(taus()%(mac_xface->lte_frame_parms->N_RB_DL-4)); - if ((vrb_map[first_rb] != 1) && (vrb_map[first_rb+3] != 1)) - break; - } - vrb_map[first_rb] = 1; - vrb_map[first_rb+1] = 1; - vrb_map[first_rb+2] = 1; - vrb_map[first_rb+3] = 1; - if (mac_xface->lte_frame_parms->frame_type == TDD) { - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_UL,first_rb,4); - rballoc |= mac_xface->get_rballoc(((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type, - ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc); - } - else { - ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_UL,first_rb,4); - rballoc |= mac_xface->get_rballoc(((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type, - ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc); - } - - add_ue_spec_dci(DCI_pdu, - (void*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0], - eNB_mac_inst[module_idP].RA_template[i].rnti, - eNB_mac_inst[module_idP].RA_template[i].RA_dci_size_bytes2, - 2, - eNB_mac_inst[module_idP].RA_template[i].RA_dci_size_bits2, - eNB_mac_inst[module_idP].RA_template[i].RA_dci_fmt2, - 0); - LOG_W(MAC,"[eNB %d][RAPROC] Frame %d, subframeP %d: Msg4 not acknowledged, adding ue specific dci (rnti %x) for RA (Msg4 Retransmission)\n", - module_idP,frameP,subframeP,eNB_mac_inst[module_idP].RA_template[i].rnti); - } - else { - LOG_I(MAC,"[eNB %d][RAPROC] Frame %d, subframeP %d : Msg4 acknowledged\n",module_idP,frameP,subframeP); - eNB_mac_inst[module_idP].RA_template[i].wait_ack_Msg4=0; - eNB_mac_inst[module_idP].RA_template[i].RA_active=FALSE; - } - } - } - } // RA is scheduled in this subframeP - - // UE specific DCIs - for (ue_mod_id=0;ue_mod_id<NUMBER_OF_UE_MAX;ue_mod_id++) { - //printf("UE_id: %d => status %d\n",UE_id,eNB_dlsch_info[module_idP][UE_id].status); - if (eNB_dlsch_info[module_idP][ue_mod_id].status == S_DL_SCHEDULED) { - - // clear scheduling flag - eNB_dlsch_info[module_idP][ue_mod_id].status = S_DL_WAITING; - rnti = find_UE_RNTI(module_idP,ue_mod_id); - mac_xface->get_ue_active_harq_pid(module_idP,rnti,subframeP,&harq_pid,&round,0); - nb_rb = eNB_mac_inst[module_idP].UE_template[ue_mod_id].nb_rb[harq_pid]; - - DLSCH_dci = (void *)eNB_mac_inst[module_idP].UE_template[ue_mod_id].DLSCH_DCI[harq_pid]; - - - /// Synchronizing rballoc with rballoc_sub - for(i=0;i<mac_xface->lte_frame_parms->N_RBGS;i++){ - rballoc_sub[i] = eNB_mac_inst[module_idP].UE_template[ue_mod_id].rballoc_subband[harq_pid][i]; - if(rballoc_sub[i] == 1) - rballoc |= (0x0001<<i); // TO be FIXED!!!!!! - } - - - switch(mac_xface->get_transmission_mode(module_idP,rnti)) { - default: - - case 1: - - case 2: - LOG_D(MAC,"[USER-PLANE DEFAULT DRB] Adding UE spec DCI for %d PRBS (%x) => ",nb_rb,rballoc); - if (mac_xface->lte_frame_parms->frame_type == TDD) { - switch (mac_xface->lte_frame_parms->N_RB_DL) { - case 6: - ((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,rballoc_sub); - ((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->rah = 0; - size_bytes = sizeof(DCI1_1_5MHz_TDD_t); - size_bits = sizeof_DCI1_1_5MHz_TDD_t; - break; - case 25: - ((DCI1_5MHz_TDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,rballoc_sub); - ((DCI1_5MHz_TDD_t*)DLSCH_dci)->rah = 0; - size_bytes = sizeof(DCI1_5MHz_TDD_t); - size_bits = sizeof_DCI1_5MHz_TDD_t; - break; - case 50: - ((DCI1_10MHz_TDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,rballoc_sub); - ((DCI1_10MHz_TDD_t*)DLSCH_dci)->rah = 0; - size_bytes = sizeof(DCI1_10MHz_TDD_t); - size_bits = sizeof_DCI1_10MHz_TDD_t; - break; - case 100: - ((DCI1_20MHz_TDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,rballoc_sub); - ((DCI1_20MHz_TDD_t*)DLSCH_dci)->rah = 0; - size_bytes = sizeof(DCI1_20MHz_TDD_t); - size_bits = sizeof_DCI1_20MHz_TDD_t; - break; - default: - ((DCI1_5MHz_TDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,rballoc_sub); - ((DCI1_5MHz_TDD_t*)DLSCH_dci)->rah = 0; - size_bytes = sizeof(DCI1_5MHz_TDD_t); - size_bits = sizeof_DCI1_5MHz_TDD_t; - break; - } - - - } - else { - switch(mac_xface->lte_frame_parms->N_RB_DL) { - case 6: - ((DCI1_1_5MHz_FDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,rballoc_sub); - ((DCI1_1_5MHz_FDD_t*)DLSCH_dci)->rah = 0; - size_bytes=sizeof(DCI1_1_5MHz_FDD_t); - size_bits=sizeof_DCI1_1_5MHz_FDD_t; - break; - case 25: - ((DCI1_5MHz_FDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,rballoc_sub); - ((DCI1_5MHz_FDD_t*)DLSCH_dci)->rah = 0; - size_bytes=sizeof(DCI1_5MHz_FDD_t); - size_bits=sizeof_DCI1_5MHz_FDD_t; - break; - case 50: - ((DCI1_10MHz_FDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,rballoc_sub); - ((DCI1_10MHz_FDD_t*)DLSCH_dci)->rah = 0; - size_bytes=sizeof(DCI1_10MHz_FDD_t); - size_bits=sizeof_DCI1_10MHz_FDD_t; - break; - case 100: - ((DCI1_20MHz_FDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,rballoc_sub); - ((DCI1_20MHz_FDD_t*)DLSCH_dci)->rah = 0; - size_bytes=sizeof(DCI1_20MHz_FDD_t); - size_bits=sizeof_DCI1_20MHz_FDD_t; - break; - default: - ((DCI1_5MHz_FDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,rballoc_sub); - ((DCI1_5MHz_FDD_t*)DLSCH_dci)->rah = 0; - size_bytes=sizeof(DCI1_5MHz_FDD_t); - size_bits=sizeof_DCI1_5MHz_FDD_t; - break; - } - } - - add_ue_spec_dci(DCI_pdu, - DLSCH_dci, - rnti, - size_bytes, - process_ue_cqi (module_idP,ue_mod_id),//aggregation, - size_bits, - format1, - 0); - - break; - case 4: - - //if (nb_rb>10) { - // DCI format 2_2A - ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,rballoc_sub); - ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->rah = 0; - add_ue_spec_dci(DCI_pdu, - DLSCH_dci, - rnti, - sizeof(DCI2_5MHz_2A_TDD_t), - process_ue_cqi (module_idP,ue_mod_id),//aggregation, - sizeof_DCI2_5MHz_2A_TDD_t, - format2, - 0); - /*} - else { - ((DCI2_5MHz_2A_L10PRB_TDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,rballoc_sub); - add_ue_spec_dci(DCI_pdu, - DLSCH_dci, - rnti, - sizeof(DCI2_5MHz_2A_L10PRB_TDD_t), - 2,//aggregation, - sizeof_DCI2_5MHz_2A_L10PRB_TDD_t, - format2_2A_L10PRB); - }*/ - break; - case 5: - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,rballoc_sub); - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->rah = 0; - - add_ue_spec_dci(DCI_pdu, - DLSCH_dci, - rnti, - sizeof(DCI1E_5MHz_2A_M10PRB_TDD_t), - process_ue_cqi (module_idP,ue_mod_id),//aggregation, - sizeof_DCI1E_5MHz_2A_M10PRB_TDD_t, - format1E_2A_M10PRB, - 0); - break; - - case 6: - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,rballoc_sub); - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->rah = 0; - - add_ue_spec_dci(DCI_pdu, - DLSCH_dci, - rnti, - sizeof(DCI1E_5MHz_2A_M10PRB_TDD_t), - process_ue_cqi (module_idP,ue_mod_id),//aggregation - sizeof_DCI1E_5MHz_2A_M10PRB_TDD_t, - format1E_2A_M10PRB, - 0); - break; - - } - } - - - } - stop_meas(&eNB_mac_inst[module_idP].fill_DLSCH_dci); -} - - - -void update_ul_dci(module_id_t module_idP,rnti_t rnti,uint8_t dai) { - - DCI_PDU *DCI_pdu = &eNB_mac_inst[module_idP].DCI_pdu; - int i; - DCI0_5MHz_TDD_1_6_t *ULSCH_dci = NULL;; - - if (mac_xface->lte_frame_parms->frame_type == TDD) { - for (i=0;i<DCI_pdu->Num_common_dci+DCI_pdu->Num_ue_spec_dci;i++) { - ULSCH_dci = (DCI0_5MHz_TDD_1_6_t *)DCI_pdu->dci_alloc[i].dci_pdu; - if ((DCI_pdu->dci_alloc[i].format == format0) && (DCI_pdu->dci_alloc[i].rnti == rnti)) - ULSCH_dci->dai = (dai-1)&3; - } - } - // printf("Update UL DCI: DAI %d\n",dai); -} - -void schedule_ue_spec(module_id_t module_idP, - frame_t frameP, - sub_frame_t subframeP, - uint16_t nb_rb_used0, - unsigned int *nCCE_used, - int mbsfn_flag) { - - module_id_t ue_mod_id = -1; - module_id_t next_ue = -1; - unsigned char granted_UEs = 0; - uint16_t nCCE; - unsigned char aggregation; - mac_rlc_status_resp_t rlc_status; - unsigned char header_len_dcch=0, header_len_dcch_tmp=0,header_len_dtch=0,header_len_dtch_tmp=0, ta_len=0; - unsigned char sdu_lcids[11],offset,num_sdus=0; - uint16_t nb_rb,nb_rb_temp,nb_available_rb,TBS,j,sdu_lengths[11],rnti,padding=0,post_padding=0; - unsigned char dlsch_buffer[MAX_DLSCH_PAYLOAD_BYTES]; - unsigned char round = 0; - unsigned char harq_pid = 0; - void *DLSCH_dci = NULL; - LTE_eNB_UE_stats *eNB_UE_stats = NULL; - uint16_t sdu_length_total = 0; - unsigned char DAI; - uint16_t i = 0; - uint8_t dl_pow_off[NUMBER_OF_UE_MAX]; - unsigned char rballoc_sub_UE[NUMBER_OF_UE_MAX][N_RBGS_MAX]; - uint16_t pre_nb_available_rbs[NUMBER_OF_UE_MAX]; - int mcs; - uint16_t min_rb_unit; - short ta_update = 0; - - if (mbsfn_flag>0) - return; - - reset_meas(&eNB_mac_inst[module_idP].schedule_dlsch); - - switch (mac_xface->lte_frame_parms->N_RB_DL) { - case 6: - min_rb_unit=1; - break; - case 25: - min_rb_unit=2; - break; - case 50: - min_rb_unit=3; - break; - case 100: - min_rb_unit=4; - break; - default: - min_rb_unit=2; - break; - } - - //int **rballoc_sub = (int **)malloc(1792*sizeof(int *)); - granted_UEs = find_dlgranted_UEs(module_idP); - - - //weight = get_ue_weight(module_idP,UE_id); - aggregation = 1; // set to the maximum aggregation level - - - /// Initialization for pre-processor - for(i=0;i<NUMBER_OF_UE_MAX;i++){ - pre_nb_available_rbs[i] = 0; - dl_pow_off[i] = 2; - for(j=0;j<mac_xface->lte_frame_parms->N_RBGS;j++){ - // rballoc_sub[j] = 0; - rballoc_sub_UE[i][j] = 0; - } - } - - - for (i = 0; i < NUMBER_OF_UE_MAX; i++) { - PHY_vars_eNB_g[module_idP]->mu_mimo_mode[i].pre_nb_available_rbs = 0; - for (j = 0; j < mac_xface->lte_frame_parms->N_RBGS; j++) { - PHY_vars_eNB_g[module_idP]->mu_mimo_mode[i].rballoc_sub[j] = 0; - } - } - - - // set current available nb_rb and nCCE to maximum - nb_available_rb = mac_xface->lte_frame_parms->N_RB_DL - nb_rb_used0; - nCCE = mac_xface->get_nCCE_max(module_idP) - *nCCE_used; - - // store the goloabl enb stats - eNB_mac_inst[module_idP].eNB_stats.num_dlactive_UEs = granted_UEs; - eNB_mac_inst[module_idP].eNB_stats.available_prbs = nb_available_rb; - eNB_mac_inst[module_idP].eNB_stats.total_available_prbs += nb_available_rb; - eNB_mac_inst[module_idP].eNB_stats.available_ncces = nCCE; - eNB_mac_inst[module_idP].eNB_stats.dlsch_bytes_tx=0; - eNB_mac_inst[module_idP].eNB_stats.dlsch_pdus_tx=0; - - - /// CALLING Pre_Processor for downlink scheduling (Returns estimation of RBs required by each UE and the allocation on sub-band) - start_meas(&eNB_mac_inst[module_idP].schedule_dlsch_preprocessor); - dlsch_scheduler_pre_processor(module_idP, - frameP, - subframeP, - dl_pow_off, - pre_nb_available_rbs, - mac_xface->lte_frame_parms->N_RBGS, - rballoc_sub_UE); - stop_meas(&eNB_mac_inst[module_idP].schedule_dlsch_preprocessor); - - for (ue_mod_id=0;ue_mod_id<granted_UEs;ue_mod_id++) { - - rnti = find_UE_RNTI(module_idP,ue_mod_id); - - eNB_mac_inst[module_idP].eNB_UE_stats[ue_mod_id].crnti= rnti; - eNB_mac_inst[module_idP].eNB_UE_stats[ue_mod_id].rrc_status=mac_get_rrc_status(module_idP,1,ue_mod_id); - if (rnti==0) { - LOG_E(MAC,"Cannot find rnti for UE_id %d (granted UEs %d)\n",ue_mod_id,granted_UEs); - mac_xface->macphy_exit("Cannot find rnti for UE_id");//continue; - } - - eNB_UE_stats = mac_xface->get_eNB_UE_stats(module_idP,rnti); - if (eNB_UE_stats==NULL) - mac_xface->macphy_exit("[MAC][eNB] Cannot find eNB_UE_stats\n"); - - // Get candidate harq_pid from PHY - mac_xface->get_ue_active_harq_pid(module_idP,rnti,subframeP,&harq_pid,&round,0); - // printf("Got harq_pid %d, round %d\n",harq_pid,round); - - - nb_available_rb = pre_nb_available_rbs[ue_mod_id]; - - if ((nb_available_rb == 0) || (nCCE < (1<<aggregation))) { - LOG_D(MAC,"UE %d: nb_availiable_rb exhausted (nb_rb_used %d, nb_available_rb %d, nCCE %d, aggregation %d)\n", - ue_mod_id, nb_rb_used0, nb_available_rb, nCCE, aggregation); - //if(mac_xface->get_transmission_mode(module_idP,rnti)==5) - continue; //to next user (there might be rbs availiable for other UEs in TM5 - // else - // break; - } - sdu_length_total=0; - num_sdus=0; - - // get Round-Robin allocation - next_ue = ue_mod_id;//schedule_next_dlue(module_idP,subframeP); // next scheduled user - // If nobody is left, exit while loop and go to next step - if (next_ue == 255) - break; - - if (mac_xface->lte_frame_parms->frame_type == TDD) { - switch (mac_xface->lte_frame_parms->tdd_config) { - case 0: - if ((subframeP==0)||(subframeP==1)||(subframeP==3)||(subframeP==5)||(subframeP==6)||(subframeP==8)) - eNB_mac_inst[module_idP].UE_template[next_ue].DAI = 0; - case 1: - if ((subframeP==0)||(subframeP==4)||(subframeP==5)||(subframeP==9)) - eNB_mac_inst[module_idP].UE_template[next_ue].DAI = 0; - break; - case 2: - if ((subframeP==4)||(subframeP==5)) - eNB_mac_inst[module_idP].UE_template[next_ue].DAI = 0; - break; - case 3: - if ((subframeP==5)||(subframeP==7)||(subframeP==9)) - eNB_mac_inst[module_idP].UE_template[next_ue].DAI = 0; - break; - case 4: - if ((subframeP==0)||(subframeP==6)) - eNB_mac_inst[module_idP].UE_template[next_ue].DAI = 0; - break; - case 5: - if (subframeP==9) - eNB_mac_inst[module_idP].UE_template[next_ue].DAI = 0; - break; - case 6: - if ((subframeP==0)||(subframeP==1)||(subframeP==5)||(subframeP==6)||(subframeP==9)) - eNB_mac_inst[module_idP].UE_template[next_ue].DAI = 0; - default: - break; - } - } - - // This is an allocated UE_id - rnti = find_UE_RNTI(module_idP,next_ue); - if (rnti==0) - continue; - - eNB_UE_stats = mac_xface->get_eNB_UE_stats(module_idP,rnti); - - if (eNB_UE_stats==NULL) - mac_xface->macphy_exit("[MAC][eNB] Cannot find eNB_UE_stats\n"); - - if (openair_daq_vars.target_ue_dl_mcs <= 0) { - eNB_UE_stats->dlsch_mcs1 = cqi_to_mcs[eNB_UE_stats->DL_cqi[0]]; - LOG_T(MAC,"CQI %d\n",eNB_UE_stats->DL_cqi[0]); - } - else - eNB_UE_stats->dlsch_mcs1 = openair_daq_vars.target_ue_dl_mcs; - - - if(eNB_UE_stats->dlsch_mcs1>22) - eNB_UE_stats->dlsch_mcs1=22; - - - // for TM5, limit the MCS to 16QAM - - - // for EXMIMO, limit the MCS to 16QAM as well -#ifdef EXMIMO - eNB_UE_stats->dlsch_mcs1 = cmin(eNB_UE_stats->dlsch_mcs1,16); -#endif - - // Get candidate harq_pid from PHY - mac_xface->get_ue_active_harq_pid(module_idP,rnti,subframeP,&harq_pid,&round,0); - - eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].harq_pid = harq_pid; - eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].harq_round = round; - // Note this code is for a specific DCI format - DLSCH_dci = (void *)eNB_mac_inst[module_idP].UE_template[next_ue].DLSCH_DCI[harq_pid]; - - for(j=0;j<mac_xface->lte_frame_parms->N_RBGS;j++){ // initializing the rb allocation indicator for each UE - eNB_mac_inst[module_idP].UE_template[next_ue].rballoc_subband[harq_pid][j] = 0; - } - // store stats - eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].dl_cqi= eNB_UE_stats->DL_cqi[0]; - - if (round > 0) { - if (mac_xface->lte_frame_parms->frame_type == TDD) { - eNB_mac_inst[module_idP].UE_template[next_ue].DAI++; - LOG_D(MAC,"DAI update: subframeP %d: UE %d, DAI %d\n",subframeP,next_ue,eNB_mac_inst[module_idP].UE_template[next_ue].DAI); - - update_ul_dci(module_idP,rnti,eNB_mac_inst[module_idP].UE_template[next_ue].DAI); - } - - // get freq_allocation - nb_rb = eNB_mac_inst[module_idP].UE_template[next_ue].nb_rb[harq_pid]; - if (nb_rb <= nb_available_rb) { - - if(nb_rb == pre_nb_available_rbs[next_ue]){ - for(j=0;j<mac_xface->lte_frame_parms->N_RBGS;j++) // for indicating the rballoc for each sub-band - eNB_mac_inst[module_idP].UE_template[next_ue].rballoc_subband[harq_pid][j] = rballoc_sub_UE[next_ue][j];} - else - { - nb_rb_temp = nb_rb; - j = 0; - while((nb_rb_temp > 0) && (j<mac_xface->lte_frame_parms->N_RBGS)){ - if(rballoc_sub_UE[next_ue][j] == 1){ - eNB_mac_inst[module_idP].UE_template[next_ue].rballoc_subband[harq_pid][j] = rballoc_sub_UE[next_ue][j]; - if((j == mac_xface->lte_frame_parms->N_RBGS-1) && - ((mac_xface->lte_frame_parms->N_RB_DL == 25)|| - (mac_xface->lte_frame_parms->N_RB_DL == 50))) - nb_rb_temp = nb_rb_temp - min_rb_unit+1; - else - nb_rb_temp = nb_rb_temp - min_rb_unit; - } - j = j+1; - } - } - - nb_available_rb -= nb_rb; - aggregation = process_ue_cqi(module_idP,next_ue); - nCCE-=(1<<aggregation); // adjust the remaining nCCE - *nCCE_used += (1<<aggregation); - - - PHY_vars_eNB_g[module_idP]->mu_mimo_mode[next_ue].pre_nb_available_rbs = nb_rb; - PHY_vars_eNB_g[module_idP]->mu_mimo_mode[next_ue].dl_pow_off = dl_pow_off[next_ue]; - - for(j=0;j<mac_xface->lte_frame_parms->N_RBGS;j++) - PHY_vars_eNB_g[module_idP]->mu_mimo_mode[next_ue].rballoc_sub[j] = eNB_mac_inst[module_idP].UE_template[next_ue].rballoc_subband[harq_pid][j]; - - switch (mac_xface->get_transmission_mode(module_idP,rnti)) { - case 1: - case 2: - default: - switch (mac_xface->lte_frame_parms->N_RB_DL) { - case 6: - if (mac_xface->lte_frame_parms->frame_type == TDD) { - // ((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->ndi = 0; - ((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->harq_pid = harq_pid; - ((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->rv = round&3; - ((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->dai = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; - LOG_D(MAC,"[eNB %d] Retransmission : harq_pid %d, round %d, dai %d, mcs %d\n",module_idP,harq_pid,round,(eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1),((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->mcs); - } - else { - // ((DCI1_1_5MHz_FDD_t*)DLSCH_dci)->ndi = 0; - ((DCI1_1_5MHz_FDD_t*)DLSCH_dci)->harq_pid = harq_pid; - ((DCI1_1_5MHz_FDD_t*)DLSCH_dci)->rv = round&3; - LOG_D(MAC,"[eNB %d] Retransmission : harq_pid %d, round %d, mcs %d\n",module_idP,harq_pid,round,((DCI1_1_5MHz_FDD_t*)DLSCH_dci)->mcs); - - } - break; - case 25: - if (mac_xface->lte_frame_parms->frame_type == TDD) { - // ((DCI1_5MHz_TDD_t*)DLSCH_dci)->ndi = 0; - ((DCI1_5MHz_TDD_t*)DLSCH_dci)->harq_pid = harq_pid; - ((DCI1_5MHz_TDD_t*)DLSCH_dci)->rv = round&3; - ((DCI1_5MHz_TDD_t*)DLSCH_dci)->dai = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; - LOG_D(MAC,"[eNB %d] Retransmission : harq_pid %d, round %d, dai %d, mcs %d\n",module_idP,harq_pid,round,(eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1),((DCI1_5MHz_TDD_t*)DLSCH_dci)->mcs); - } - else { - // ((DCI1_5MHz_FDD_t*)DLSCH_dci)->ndi = 0; - ((DCI1_5MHz_FDD_t*)DLSCH_dci)->harq_pid = harq_pid; - ((DCI1_5MHz_FDD_t*)DLSCH_dci)->rv = round&3; - LOG_D(MAC,"[eNB %d] Retransmission : harq_pid %d, round %d, mcs %d\n",module_idP,harq_pid,round,((DCI1_5MHz_FDD_t*)DLSCH_dci)->mcs); - - } - break; - case 50: - if (mac_xface->lte_frame_parms->frame_type == TDD) { - // ((DCI1_10MHz_TDD_t*)DLSCH_dci)->ndi = 0; - ((DCI1_10MHz_TDD_t*)DLSCH_dci)->harq_pid = harq_pid; - ((DCI1_10MHz_TDD_t*)DLSCH_dci)->rv = round&3; - ((DCI1_10MHz_TDD_t*)DLSCH_dci)->dai = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; - LOG_D(MAC,"[eNB %d] Retransmission : harq_pid %d, round %d, dai %d, mcs %d\n",module_idP,harq_pid,round,(eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1),((DCI1_10MHz_TDD_t*)DLSCH_dci)->mcs); - } - else { - // ((DCI1_10MHz_FDD_t*)DLSCH_dci)->ndi = 0; - ((DCI1_10MHz_FDD_t*)DLSCH_dci)->harq_pid = harq_pid; - ((DCI1_10MHz_FDD_t*)DLSCH_dci)->rv = round&3; - LOG_D(MAC,"[eNB %d] Retransmission : harq_pid %d, round %d, mcs %d\n",module_idP,harq_pid,round,((DCI1_10MHz_FDD_t*)DLSCH_dci)->mcs); - - } - break; - case 100: - if (mac_xface->lte_frame_parms->frame_type == TDD) { - // ((DCI1_20MHz_TDD_t*)DLSCH_dci)->ndi = 0; - ((DCI1_20MHz_TDD_t*)DLSCH_dci)->harq_pid = harq_pid; - ((DCI1_20MHz_TDD_t*)DLSCH_dci)->rv = round&3; - ((DCI1_20MHz_TDD_t*)DLSCH_dci)->dai = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; - LOG_D(MAC,"[eNB %d] Retransmission : harq_pid %d, round %d, dai %d, mcs %d\n",module_idP,harq_pid,round,(eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1),((DCI1_20MHz_TDD_t*)DLSCH_dci)->mcs); - } - else { - // ((DCI1_20MHz_FDD_t*)DLSCH_dci)->ndi = 0; - ((DCI1_20MHz_FDD_t*)DLSCH_dci)->harq_pid = harq_pid; - ((DCI1_20MHz_FDD_t*)DLSCH_dci)->rv = round&3; - LOG_D(MAC,"[eNB %d] Retransmission : harq_pid %d, round %d, mcs %d\n",module_idP,harq_pid,round,((DCI1_20MHz_FDD_t*)DLSCH_dci)->mcs); - - } - break; - } - break; - case 4: - // if (nb_rb>10) { - ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->ndi1 = 0; - ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->harq_pid = harq_pid; - ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->dai = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; - // } - //else { - // ((DCI2_5MHz_2A_L10PRB_TDD_t*)DLSCH_dci)->ndi1 = 0; - // ((DCI2_5MHz_2A_L10PRB_TDD_t*)DLSCH_dci)->harq_pid = harq_pid; - // ((DCI2_5MHz_2A_L10PRB_TDD_t*)DLSCH_dci)->rv1 = round&3; - // ((DCI2_5MHz_2A_L10PRB_TDD_t*)DLSCH_dci)->dai = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; - // } - break; - case 5: - // if(nb_rb>10){ - //((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->mcs = eNB_UE_stats->DL_cqi[0]<<1; - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->ndi = 0; - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->harq_pid = harq_pid; - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->rv = round&3; - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->dai = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; - if(dl_pow_off[next_ue] == 2) - dl_pow_off[next_ue] = 1; - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->dl_power_off = dl_pow_off[next_ue]; - // } - break; - case 6: - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->ndi = 0; - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->harq_pid = harq_pid; - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->rv = round&3; - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->dai = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->dl_power_off = 1;//dl_pow_off[next_ue]; - break; - } - - add_ue_dlsch_info(module_idP, - next_ue, - subframeP, - S_DL_SCHEDULED); - - //eNB_UE_stats->dlsch_trials[round]++; - eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].num_retransmission+=1; - eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].rbs_used_retx=nb_rb; - eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].total_rbs_used_retx+=nb_rb; - eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].ncce_used_retx=nCCE; - eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].dlsch_mcs1=eNB_UE_stats->dlsch_mcs1; - eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].dlsch_mcs2=eNB_UE_stats->dlsch_mcs1; - } - else { // don't schedule this UE, its retransmission takes more resources than we have - - } - } - else { // This is a potentially new SDU opportunity - - // calculate mcs - - rlc_status.bytes_in_buffer = 0; - // Now check RLC information to compute number of required RBs - // get maximum TBS size for RLC request - //TBS = mac_xface->get_TBS(eNB_UE_stats->DL_cqi[0]<<1,nb_available_rb); - TBS = mac_xface->get_TBS_DL(eNB_UE_stats->dlsch_mcs1,nb_available_rb); - // check first for RLC data on DCCH - // add the length for all the control elements (timing adv, drx, etc) : header + payload -#ifndef EXMIMO_IOT - ta_len = ((eNB_UE_stats->timing_advance_update/4)!=0) ? 2 : 0; -#else - ta_len = 0; -#endif - - header_len_dcch = 2; // 2 bytes DCCH SDU subheader - - - rlc_status = mac_rlc_status_ind( - module_idP, - ue_mod_id, - frameP, - ENB_FLAG_YES, - MBMS_FLAG_NO, - DCCH, - (TBS-ta_len-header_len_dcch)); // transport block set size - - sdu_lengths[0]=0; - if (rlc_status.bytes_in_buffer > 0) { // There is DCCH to transmit - LOG_D(MAC,"[eNB %d] Frame %d, DL-DCCH->DLSCH, Requesting %d bytes from RLC (RRC message)\n",module_idP,frameP,TBS-header_len_dcch); - sdu_lengths[0] += mac_rlc_data_req( - module_idP, - ue_mod_id, - frameP, - ENB_FLAG_YES, - MBMS_FLAG_NO, - DCCH, - (char *)&dlsch_buffer[sdu_lengths[0]]); - - LOG_D(MAC,"[eNB %d][DCCH] Got %d bytes from RLC\n",module_idP,sdu_lengths[0]); - sdu_length_total = sdu_lengths[0]; - sdu_lcids[0] = DCCH; - eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].num_pdu_tx[DCCH]+=1; - eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].num_bytes_tx[DCCH]+=sdu_lengths[0]; - num_sdus = 1; -#ifdef DEBUG_eNB_SCHEDULER - LOG_T(MAC,"[eNB %d][DCCH] Got %d bytes :",module_idP,sdu_lengths[0]); - for (j=0;j<sdu_lengths[0];j++) - LOG_T(MAC,"%x ",dlsch_buffer[j]); - LOG_T(MAC,"\n"); -#endif - } - else { - header_len_dcch = 0; - sdu_length_total = 0; - } - - // check for DCCH1 and update header information (assume 2 byte sub-header) - rlc_status = mac_rlc_status_ind( - module_idP, - ue_mod_id, - frameP, - ENB_FLAG_YES, - MBMS_FLAG_NO, - DCCH+1, - (TBS-ta_len-header_len_dcch-sdu_length_total)); // transport block set size less allocations for timing advance and - // DCCH SDU - - if (rlc_status.bytes_in_buffer > 0) { - LOG_D(MAC,"[eNB %d], Frame %d, DCCH1->DLSCH, Requesting %d bytes from RLC (RRC message)\n", - module_idP,frameP,TBS-header_len_dcch-sdu_length_total); - sdu_lengths[num_sdus] += mac_rlc_data_req( - module_idP, - ue_mod_id, - frameP, - ENB_FLAG_YES, - MBMS_FLAG_NO, - DCCH+1, - (char *)&dlsch_buffer[sdu_lengths[0]]); - - sdu_lcids[num_sdus] = DCCH1; - sdu_length_total += sdu_lengths[num_sdus]; - header_len_dcch += 2; - eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].num_pdu_tx[DCCH1]+=1; - eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].num_bytes_tx[DCCH1]+=sdu_lengths[num_sdus]; - num_sdus++; - LOG_D(MAC,"[eNB %d] Got %d bytes for DCCH from RLC\n",module_idP,sdu_lengths[0]); - } - // check for DTCH and update header information - // here we should loop over all possible DTCH - - header_len_dtch = 3; // 3 bytes DTCH SDU subheader - - LOG_D(MAC,"[eNB %d], Frame %d, DTCH->DLSCH, Checking RLC status (rab %d, tbs %d, len %d)\n", - module_idP,frameP,DTCH,TBS, - TBS-ta_len-header_len_dcch-sdu_length_total-header_len_dtch); - - rlc_status = mac_rlc_status_ind( - module_idP, - ue_mod_id, - frameP, - ENB_FLAG_YES, - MBMS_FLAG_NO, - DTCH, - TBS-ta_len-header_len_dcch-sdu_length_total-header_len_dtch); - - if (rlc_status.bytes_in_buffer > 0) { - LOG_I(MAC,"[eNB %d][USER-PLANE DEFAULT DRB], Frame %d, DTCH->DLSCH, Requesting %d bytes from RLC (hdr len dtch %d)\n", - module_idP,frameP,TBS-header_len_dcch-sdu_length_total-header_len_dtch,header_len_dtch); - sdu_lengths[num_sdus] = mac_rlc_data_req( - module_idP, - ue_mod_id, - frameP, - ENB_FLAG_YES, - MBMS_FLAG_NO, - DTCH, - (char*)&dlsch_buffer[sdu_length_total]); - - LOG_I(MAC,"[eNB %d][USER-PLANE DEFAULT DRB] Got %d bytes for DTCH %d \n",module_idP,sdu_lengths[num_sdus],DTCH); - sdu_lcids[num_sdus] = DTCH; - sdu_length_total += sdu_lengths[num_sdus]; - eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].num_pdu_tx[DTCH]+=1; - eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].num_bytes_tx[DTCH]+=sdu_lengths[num_sdus]; - if (sdu_lengths[num_sdus] < 128) { - header_len_dtch=2; - } - num_sdus++; - } - else { - header_len_dtch = 0; - } - - // there is a payload - if (((sdu_length_total + header_len_dcch + header_len_dtch )> 0)) { - - // Now compute number of required RBs for total sdu length - // Assume RAH format 2 - // adjust header lengths - header_len_dcch_tmp = header_len_dcch; - header_len_dtch_tmp = header_len_dtch; - if (header_len_dtch==0) { - header_len_dcch = (header_len_dcch >0) ? 1 : header_len_dcch; // remove length field - } else { - header_len_dtch = (header_len_dtch > 0) ? 1 :header_len_dtch; // remove length field for the last SDU - } - - - mcs = eNB_UE_stats->dlsch_mcs1; - if (mcs==0) nb_rb = 4; // don't let the TBS get too small - else nb_rb=min_rb_unit; - - TBS = mac_xface->get_TBS_DL(mcs,nb_rb); - - while (TBS < (sdu_length_total + header_len_dcch + header_len_dtch + ta_len)) { - nb_rb += min_rb_unit; // - if (nb_rb>nb_available_rb) { // if we've gone beyond the maximum number of RBs - // (can happen if N_RB_DL is odd) - TBS = mac_xface->get_TBS_DL(eNB_UE_stats->dlsch_mcs1,nb_available_rb); - nb_rb = nb_available_rb; - break; - } - TBS = mac_xface->get_TBS_DL(eNB_UE_stats->dlsch_mcs1,nb_rb); - } - - if(nb_rb == pre_nb_available_rbs[next_ue]) { - for(j=0;j<mac_xface->lte_frame_parms->N_RBGS;j++) {// for indicating the rballoc for each sub-band - eNB_mac_inst[module_idP].UE_template[next_ue].rballoc_subband[harq_pid][j] = rballoc_sub_UE[next_ue][j]; - } - } else - { - nb_rb_temp = nb_rb; - j = 0; - while((nb_rb_temp > 0) && (j<mac_xface->lte_frame_parms->N_RBGS)){ - if(rballoc_sub_UE[next_ue][j] == 1){ - eNB_mac_inst[module_idP].UE_template[next_ue].rballoc_subband[harq_pid][j] = rballoc_sub_UE[next_ue][j]; - if ((j == mac_xface->lte_frame_parms->N_RBGS-1) && - ((mac_xface->lte_frame_parms->N_RB_DL == 25)|| - (mac_xface->lte_frame_parms->N_RB_DL == 50))) - nb_rb_temp = nb_rb_temp - min_rb_unit+1; - else - nb_rb_temp = nb_rb_temp - min_rb_unit; - } - j = j+1; - } - } - - PHY_vars_eNB_g[module_idP]->mu_mimo_mode[next_ue].pre_nb_available_rbs = nb_rb; - PHY_vars_eNB_g[module_idP]->mu_mimo_mode[next_ue].dl_pow_off = dl_pow_off[next_ue]; - - for(j=0;j<mac_xface->lte_frame_parms->N_RBGS;j++) - PHY_vars_eNB_g[module_idP]->mu_mimo_mode[next_ue].rballoc_sub[j] = eNB_mac_inst[module_idP].UE_template[next_ue].rballoc_subband[harq_pid][j]; - - - // decrease mcs until TBS falls below required length - while ((TBS > (sdu_length_total + header_len_dcch + header_len_dtch + ta_len)) && (mcs>0)) { - mcs--; - TBS = mac_xface->get_TBS_DL(mcs,nb_rb); - } - - // if we have decreased too much or we don't have enough RBs, increase MCS - while ((TBS < (sdu_length_total + header_len_dcch + header_len_dtch + ta_len)) && ((( dl_pow_off[next_ue]>0) && (mcs<28)) || ( (dl_pow_off[next_ue]==0) && (mcs<=15)))) { - mcs++; - TBS = mac_xface->get_TBS_DL(mcs,nb_rb); - } - - LOG_D(MAC,"dlsch_mcs before and after the rate matching = (%d, %d)\n",eNB_UE_stats->dlsch_mcs1, mcs); - -#ifdef DEBUG_eNB_SCHEDULER - LOG_D(MAC,"[eNB %d] Generated DLSCH header (mcs %d, TBS %d, nb_rb %d)\n", - module_idP,mcs,TBS,nb_rb); - // msg("[MAC][eNB ] Reminder of DLSCH with random data %d %d %d %d \n", - // TBS, sdu_length_total, offset, TBS-sdu_length_total-offset); -#endif - - if ((TBS - header_len_dcch - header_len_dtch - sdu_length_total - ta_len) <= 2) { - padding = (TBS - header_len_dcch - header_len_dtch - sdu_length_total - ta_len); - post_padding = 0; - } - else { - padding = 0; - // adjust the header len - if (header_len_dtch==0) - header_len_dcch = header_len_dcch_tmp; - else //if (( header_len_dcch==0)&&((header_len_dtch==1)||(header_len_dtch==2))) - header_len_dtch = header_len_dtch_tmp; - - post_padding = TBS - sdu_length_total - header_len_dcch - header_len_dtch - ta_len ; // 1 is for the postpadding header - } -#ifndef EXMIMO_IOT - ta_update = eNB_UE_stats->timing_advance_update/4; -#else - ta_update = 0; -#endif - - offset = generate_dlsch_header((unsigned char*)eNB_mac_inst[module_idP].DLSCH_pdu[(module_id_t)next_ue][0].payload[0], - // offset = generate_dlsch_header((unsigned char*)eNB_mac_inst[0].DLSCH_pdu[0][0].payload[0], - num_sdus, //num_sdus - sdu_lengths, // - sdu_lcids, - 255, // no drx - ta_update, // timing advance - NULL, // contention res id - padding, - post_padding); - //#ifdef DEBUG_eNB_SCHEDULER - LOG_I(MAC,"[eNB %d][USER-PLANE DEFAULT DRB] Generate header : sdu_length_total %d, num_sdus %d, sdu_lengths[0] %d, sdu_lcids[0] %d => payload offset %d,timing advance value : %d, next_ue %d,padding %d,post_padding %d,(mcs %d, TBS %d, nb_rb %d),header_dcch %d, header_dtch %d\n", - module_idP,sdu_length_total,num_sdus,sdu_lengths[0],sdu_lcids[0],offset, - ta_len,next_ue,padding,post_padding,mcs,TBS,nb_rb,header_len_dcch,header_len_dtch); - //#endif - - LOG_T(MAC,"[eNB %d] First 16 bytes of DLSCH : \n"); - for (i=0;i<16;i++) - LOG_T(MAC,"%x.",dlsch_buffer[i]); - LOG_T(MAC,"\n"); +#include "LAYER2/MAC/proto.h" +#include "UTIL/LOG/log.h" +#include "UTIL/LOG/vcd_signal_dumper.h" +#include "UTIL/OPT/opt.h" +#include "OCG.h" +#include "OCG_extern.h" +#include "ARCH/CBMIMO1/DEVICE_DRIVER/extern.h" +#include "ARCH/CBMIMO1/DEVICE_DRIVER/defs.h" +#include "ARCH/CBMIMO1/DEVICE_DRIVER/from_grlib_softregs.h" - // cycle through SDUs and place in dlsch_buffer - memcpy(&eNB_mac_inst[module_idP].DLSCH_pdu[(module_id_t)next_ue][0].payload[0][offset],dlsch_buffer,sdu_length_total); - // memcpy(&eNB_mac_inst[0].DLSCH_pdu[0][0].payload[0][offset],dcch_buffer,sdu_lengths[0]); +#include "RRC/LITE/extern.h" +#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h" - // fill remainder of DLSCH with random data - for (j=0;j<(TBS-sdu_length_total-offset);j++) - eNB_mac_inst[module_idP].DLSCH_pdu[(module_id_t)next_ue][0].payload[0][offset+sdu_length_total+j] = (char)(taus()&0xff); - //eNB_mac_inst[0].DLSCH_pdu[0][0].payload[0][offset+sdu_lengths[0]+j] = (char)(taus()&0xff); +//#include "LAYER2/MAC/pre_processor.c" +#include "pdcp.h" -#if defined(USER_MODE) && defined(OAI_EMU) - /* Tracing of PDU is done on UE side */ - if (oai_emulation.info.opt_enabled) - trace_pdu(1, (uint8_t *)eNB_mac_inst[module_idP].DLSCH_pdu[(module_id_t)next_ue][0].payload[0], - TBS, module_idP, 3, find_UE_RNTI(module_idP,next_ue), - eNB_mac_inst[module_idP].subframe,0,0); - LOG_D(OPT,"[eNB %d][DLSCH] Frame %d rnti %x with size %d\n", - module_idP, frameP, find_UE_RNTI(module_idP,next_ue), TBS); +#if defined(ENABLE_ITTI) +# include "intertask_interface.h" #endif - aggregation = process_ue_cqi(module_idP,next_ue); - nCCE-=(1<<aggregation); // adjust the remaining nCCE - *nCCE_used+=(1<<aggregation); // adjust the remaining nCCE - eNB_mac_inst[module_idP].UE_template[next_ue].nb_rb[harq_pid] = nb_rb; - - add_ue_dlsch_info(module_idP, - next_ue, - subframeP, - S_DL_SCHEDULED); - // store stats - eNB_mac_inst[module_idP].eNB_stats.dlsch_bytes_tx+=sdu_length_total; - eNB_mac_inst[module_idP].eNB_stats.dlsch_pdus_tx+=1; - - eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].rbs_used = nb_rb; - eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].total_rbs_used += nb_rb; - eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].ncce_used = nCCE; - eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].dlsch_mcs1=eNB_UE_stats->dlsch_mcs1; - eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].dlsch_mcs2=mcs; - eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].TBS = TBS; - - eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].overhead_bytes= TBS- sdu_length_total; - eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].total_sdu_bytes+= sdu_length_total; - eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].total_pdu_bytes+= TBS; - eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].total_num_pdus+=1; - - if (mac_xface->lte_frame_parms->frame_type == TDD) { - eNB_mac_inst[module_idP].UE_template[next_ue].DAI++; - // printf("DAI update: subframeP %d: UE %d, DAI %d\n",subframeP,next_ue,eNB_mac_inst[module_idP].UE_template[next_ue].DAI); -#warning only for 5MHz channel - update_ul_dci(module_idP,rnti,eNB_mac_inst[module_idP].UE_template[next_ue].DAI); - } - - switch (mac_xface->get_transmission_mode(module_idP,rnti)) { - case 1: - case 2: - default: - if (mac_xface->lte_frame_parms->frame_type == TDD) { - switch (mac_xface->lte_frame_parms->N_RB_DL) { - case 6: - ((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->mcs = mcs; - ((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->harq_pid = harq_pid; - ((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->ndi = 1-eNB_mac_inst[module_idP].UE_template[next_ue].oldNDI[harq_pid]; - ((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->rv = 0; - ((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->dai = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; - break; - case 25: - ((DCI1_5MHz_TDD_t*)DLSCH_dci)->mcs = mcs; - ((DCI1_5MHz_TDD_t*)DLSCH_dci)->harq_pid = harq_pid; - ((DCI1_5MHz_TDD_t*)DLSCH_dci)->ndi = 1-eNB_mac_inst[module_idP].UE_template[next_ue].oldNDI[harq_pid]; - ((DCI1_5MHz_TDD_t*)DLSCH_dci)->rv = 0; - ((DCI1_5MHz_TDD_t*)DLSCH_dci)->dai = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; - LOG_D(MAC,"Format1 DCI: harq_pid %d, ndi %d\n",harq_pid,((DCI1_5MHz_TDD_t*)DLSCH_dci)->ndi); - break; - case 50: - ((DCI1_10MHz_TDD_t*)DLSCH_dci)->mcs = mcs; - ((DCI1_10MHz_TDD_t*)DLSCH_dci)->harq_pid = harq_pid; - ((DCI1_10MHz_TDD_t*)DLSCH_dci)->ndi = 1-eNB_mac_inst[module_idP].UE_template[next_ue].oldNDI[harq_pid]; - ((DCI1_10MHz_TDD_t*)DLSCH_dci)->rv = 0; - ((DCI1_10MHz_TDD_t*)DLSCH_dci)->dai = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; - break; - case 100: - ((DCI1_20MHz_TDD_t*)DLSCH_dci)->mcs = mcs; - ((DCI1_20MHz_TDD_t*)DLSCH_dci)->harq_pid = harq_pid; - ((DCI1_20MHz_TDD_t*)DLSCH_dci)->ndi = 1-eNB_mac_inst[module_idP].UE_template[next_ue].oldNDI[harq_pid]; - ((DCI1_20MHz_TDD_t*)DLSCH_dci)->rv = 0; - ((DCI1_20MHz_TDD_t*)DLSCH_dci)->dai = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; - break; - default: - ((DCI1_5MHz_TDD_t*)DLSCH_dci)->mcs = mcs; - ((DCI1_5MHz_TDD_t*)DLSCH_dci)->harq_pid = harq_pid; - ((DCI1_5MHz_TDD_t*)DLSCH_dci)->ndi = 1-eNB_mac_inst[module_idP].UE_template[next_ue].oldNDI[harq_pid]; - ((DCI1_5MHz_TDD_t*)DLSCH_dci)->rv = 0; - ((DCI1_5MHz_TDD_t*)DLSCH_dci)->dai = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; - break; - } - } - else { - switch (mac_xface->lte_frame_parms->N_RB_DL) { - case 6: - ((DCI1_1_5MHz_FDD_t*)DLSCH_dci)->mcs = mcs; - ((DCI1_1_5MHz_FDD_t*)DLSCH_dci)->harq_pid = harq_pid; - ((DCI1_1_5MHz_FDD_t*)DLSCH_dci)->ndi = 1-eNB_mac_inst[module_idP].UE_template[next_ue].oldNDI[harq_pid]; - ((DCI1_1_5MHz_FDD_t*)DLSCH_dci)->rv = 0; - break; - case 25: - ((DCI1_5MHz_FDD_t*)DLSCH_dci)->mcs = mcs; - ((DCI1_5MHz_FDD_t*)DLSCH_dci)->harq_pid = harq_pid; - ((DCI1_5MHz_FDD_t*)DLSCH_dci)->ndi = 1-eNB_mac_inst[module_idP].UE_template[next_ue].oldNDI[harq_pid]; - ((DCI1_5MHz_FDD_t*)DLSCH_dci)->rv = 0; - break; - case 50: - ((DCI1_10MHz_FDD_t*)DLSCH_dci)->mcs = mcs; - ((DCI1_10MHz_FDD_t*)DLSCH_dci)->harq_pid = harq_pid; - ((DCI1_10MHz_FDD_t*)DLSCH_dci)->ndi = 1-eNB_mac_inst[module_idP].UE_template[next_ue].oldNDI[harq_pid]; - ((DCI1_10MHz_FDD_t*)DLSCH_dci)->rv = 0; - break; - case 100: - ((DCI1_20MHz_FDD_t*)DLSCH_dci)->mcs = mcs; - ((DCI1_20MHz_FDD_t*)DLSCH_dci)->harq_pid = harq_pid; - ((DCI1_20MHz_FDD_t*)DLSCH_dci)->ndi = 1-eNB_mac_inst[module_idP].UE_template[next_ue].oldNDI[harq_pid]; - ((DCI1_20MHz_FDD_t*)DLSCH_dci)->rv = 0; - break; - default: - ((DCI1_5MHz_FDD_t*)DLSCH_dci)->mcs = mcs; - ((DCI1_5MHz_FDD_t*)DLSCH_dci)->harq_pid = harq_pid; - ((DCI1_5MHz_FDD_t*)DLSCH_dci)->ndi = 1-eNB_mac_inst[module_idP].UE_template[next_ue].oldNDI[harq_pid]; - ((DCI1_5MHz_FDD_t*)DLSCH_dci)->rv = 0; - break; - } - } - break; - case 4: - // if (nb_rb>10) { - ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->mcs1 = mcs; - ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->harq_pid = harq_pid; - ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->ndi1 = 1; - ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->rv1 = round&3; - ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->dai = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; - - //} - /* else { - ((DCI2_5MHz_2A_L10PRB_TDD_t*)DLSCH_dci)->mcs1 = eNB_UE_stats->DL_cqi[0]; - ((DCI2_5MHz_2A_L10PRB_TDD_t*)DLSCH_dci)->harq_pid = harq_pid; - ((DCI2_5MHz_2A_L10PRB_TDD_t*)DLSCH_dci)->ndi1 = 1; - ((DCI2_5MHz_2A_L10PRB_TDD_t*)DLSCH_dci)->rv1 = round&3; - ((DCI2_5MHz_2A_L10PRB_TDD_t*)DLSCH_dci)->tpmi = 5; - ((DCI2_5MHz_2A_L10PRB_TDD_t*)DLSCH_dci)->dai = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; - }*/ - break; - case 5: +#define ENABLE_MAC_PAYLOAD_DEBUG +#define DEBUG_eNB_SCHEDULER 1 +//#define DEBUG_HEADER_PARSING 1 +//#define DEBUG_PACKET_TRACE 1 - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->mcs = mcs; - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->harq_pid = harq_pid; - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->ndi = 1; - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->rv = round&3; - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->dai = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; - if(dl_pow_off[next_ue] == 2) - dl_pow_off[next_ue] = 1; - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->dl_power_off = dl_pow_off[next_ue]; - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->tpmi = 5; - break; - case 6: - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->mcs = mcs; - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->harq_pid = harq_pid; - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->ndi = 1; - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->rv = round&3; - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->dai = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->dl_power_off = 1; - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->tpmi = 5; - break; - } - // Toggle NDI for next time - LOG_D(MAC,"Frame %d, subframeP %d: Toggling Format1 NDI for UE %d (rnti %x/%d) oldNDI %d\n",frameP,subframeP,next_ue, - eNB_mac_inst[module_idP].UE_template[next_ue].rnti,harq_pid,eNB_mac_inst[module_idP].UE_template[next_ue].oldNDI[harq_pid]); - eNB_mac_inst[module_idP].UE_template[next_ue].oldNDI[harq_pid]=1-eNB_mac_inst[module_idP].UE_template[next_ue].oldNDI[harq_pid]; - } +/* + #ifndef USER_MODE + #define msg debug_msg + #endif + */ - else { // There is no data from RLC or MAC header, so don't schedule - } - } - if (mac_xface->lte_frame_parms->frame_type == TDD) { - DAI = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; - LOG_D(MAC,"[eNB %d] Frame %d: DAI %d for UE %d\n",module_idP,frameP,DAI,next_ue); - // Save DAI for Format 0 DCI - switch (mac_xface->lte_frame_parms->tdd_config) { - case 0: - // if ((subframeP==0)||(subframeP==1)||(subframeP==5)||(subframeP==6)) - break; - case 1: - switch (subframeP) { - case 1: - eNB_mac_inst[module_idP].UE_template[next_ue].DAI_ul[7] = DAI; - break; - case 4: - eNB_mac_inst[module_idP].UE_template[next_ue].DAI_ul[8] = DAI; - break; - case 6: - eNB_mac_inst[module_idP].UE_template[next_ue].DAI_ul[2] = DAI; - break; - case 9: - eNB_mac_inst[module_idP].UE_template[next_ue].DAI_ul[3] = DAI; - break; - } - case 2: - // if ((subframeP==3)||(subframeP==8)) - // eNB_mac_inst[module_idP].UE_template[next_ue].DAI_ul = DAI; - break; - case 3: - if ((subframeP==6)||(subframeP==8)||(subframeP==0)) { - LOG_D(MAC,"schedule_ue_spec: setting UL DAI to %d for subframeP %d => %d\n",DAI,subframeP, ((subframeP+8)%10)>>1); - eNB_mac_inst[module_idP].UE_template[next_ue].DAI_ul[((subframeP+8)%10)>>1] = DAI; - } - break; - case 4: - // if ((subframeP==8)||(subframeP==9)) - // eNB_mac_inst[module_idP].UE_template[next_ue].DAI_ul = DAI; - break; - case 5: - // if (subframeP==8) - // eNB_mac_inst[module_idP].UE_template[next_ue].DAI_ul = DAI; - break; - case 6: - // if ((subframeP==1)||(subframeP==4)||(subframeP==6)||(subframeP==9)) - // eNB_mac_inst[module_idP].UE_template[next_ue].DAI_ul = DAI; - break; - default: - break; - } - } - //printf("MAC nCCE : %d\n",*nCCE_used); - } - stop_meas(&eNB_mac_inst[module_idP].schedule_dlsch); -} void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag, frame_t frameP, sub_frame_t subframeP) {//, int calibration_flag) { @@ -4770,3 +462,6 @@ void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag, stop_meas(&eNB_mac_inst[module_idP].eNB_scheduler); } + + + diff --git a/openair2/LAYER2/MAC/eNB_scheduler_bch.c b/openair2/LAYER2/MAC/eNB_scheduler_bch.c new file mode 100644 index 0000000000..8cdcf0ba6b --- /dev/null +++ b/openair2/LAYER2/MAC/eNB_scheduler_bch.c @@ -0,0 +1,188 @@ +/******************************************************************************* + + Eurecom OpenAirInterface + Copyright(c) 1999 - 2010 Eurecom + + This program is free software; you can redistribute it and/or modify it + under the terms and conditions of the GNU General Public License, + version 2, as published by the Free Software Foundation. + + This program is distributed in the hope it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along with + this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + + The full GNU General Public License is included in this distribution in + the file called "COPYING". + + Contact Information + Openair Admin: openair_admin@eurecom.fr + Openair Tech : openair_tech@eurecom.fr + Forums : http://forums.eurecom.fsr/openairinterface + Address : Eurecom, 2229, route des crêtes, 06560 Valbonne Sophia Antipolis, France + + *******************************************************************************/ +/*! \file eNB_scheduler.c + * \brief procedures related to UE on the BCH transport channel + * \author Navid Nikaein and Raymond Knopp + * \date 2011 + * \email: navid.nikaein@eurecom.fr + * \version 0.5 + * @ingroup _mac + + */ + +#include "assertions.h" +#include "PHY/defs.h" +#include "PHY/extern.h" + +#include "SCHED/defs.h" +#include "SCHED/extern.h" + +#include "LAYER2/MAC/defs.h" +#include "LAYER2/MAC/proto.h" +#include "LAYER2/MAC/extern.h" +#include "UTIL/LOG/log.h" +#include "UTIL/LOG/vcd_signal_dumper.h" +#include "UTIL/OPT/opt.h" +#include "OCG.h" +#include "OCG_extern.h" +#include "ARCH/CBMIMO1/DEVICE_DRIVER/extern.h" +#include "ARCH/CBMIMO1/DEVICE_DRIVER/defs.h" +#include "ARCH/CBMIMO1/DEVICE_DRIVER/from_grlib_softregs.h" + +#include "RRC/LITE/extern.h" +#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h" + +//#include "LAYER2/MAC/pre_processor.c" +#include "pdcp.h" + +#if defined(ENABLE_ITTI) +# include "intertask_interface.h" +#endif + +#define ENABLE_MAC_PAYLOAD_DEBUG +#define DEBUG_eNB_SCHEDULER 1 + + +void schedule_SI(module_id_t module_idP,frame_t frameP, unsigned char *nprb,unsigned int *nCCE) { + + start_meas(&eNB_mac_inst[module_idP].schedule_si); + + unsigned char bcch_sdu_length; + int mcs = -1; + void *BCCH_alloc_pdu=(void*)&eNB_mac_inst[module_idP].BCCH_alloc_pdu; + + bcch_sdu_length = mac_rrc_data_req(module_idP, + frameP, + BCCH,1, + &eNB_mac_inst[module_idP].BCCH_pdu.payload[0], + 1, + module_idP, + 0); // not used in this case + if (bcch_sdu_length > 0) { + LOG_D(MAC,"[eNB %d] Frame %d : BCCH->DLSCH, Received %d bytes \n",module_idP,frameP,bcch_sdu_length); + + + if (bcch_sdu_length <= (mac_xface->get_TBS_DL(0,3))) + mcs=0; + else if (bcch_sdu_length <= (mac_xface->get_TBS_DL(1,3))) + mcs=1; + else if (bcch_sdu_length <= (mac_xface->get_TBS_DL(2,3))) + mcs=2; + else if (bcch_sdu_length <= (mac_xface->get_TBS_DL(3,3))) + mcs=3; + else if (bcch_sdu_length <= (mac_xface->get_TBS_DL(4,3))) + mcs=4; + else if (bcch_sdu_length <= (mac_xface->get_TBS_DL(5,3))) + mcs=5; + else if (bcch_sdu_length <= (mac_xface->get_TBS_DL(6,3))) + mcs=6; + else if (bcch_sdu_length <= (mac_xface->get_TBS_DL(7,3))) + mcs=7; + else if (bcch_sdu_length <= (mac_xface->get_TBS_DL(8,3))) + mcs=8; + + if (mac_xface->lte_frame_parms->frame_type == TDD) { + switch (mac_xface->lte_frame_parms->N_RB_DL) { + case 6: + ((DCI1A_1_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->mcs = mcs; + break; + case 25: + ((DCI1A_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->mcs = mcs; + break; + case 50: + ((DCI1A_10MHz_TDD_1_6_t*)BCCH_alloc_pdu)->mcs = mcs; + break; + case 100: + ((DCI1A_20MHz_TDD_1_6_t*)BCCH_alloc_pdu)->mcs = mcs; + break; + + } + } + else { + switch (mac_xface->lte_frame_parms->N_RB_DL) { + case 6: + ((DCI1A_1_5MHz_FDD_t*)BCCH_alloc_pdu)->mcs = mcs; + break; + case 25: + ((DCI1A_5MHz_FDD_t*)BCCH_alloc_pdu)->mcs = mcs; + break; + case 50: + ((DCI1A_10MHz_FDD_t*)BCCH_alloc_pdu)->mcs = mcs; + break; + case 100: + ((DCI1A_20MHz_FDD_t*)BCCH_alloc_pdu)->mcs = mcs; + break; + + } + } + +#if defined(USER_MODE) && defined(OAI_EMU) + if (oai_emulation.info.opt_enabled) { + trace_pdu(1, + &eNB_mac_inst[module_idP].BCCH_pdu.payload[0], + bcch_sdu_length, + 0xffff, + 4, + 0xffff, + eNB_mac_inst[module_idP].subframe, + 0, + 0); + } + LOG_D(OPT,"[eNB %d][BCH] Frame %d trace pdu for rnti %x with size %d\n", + module_idP, frameP, 0xffff, bcch_sdu_length); +#endif + + if (mac_xface->lte_frame_parms->frame_type == TDD) { + LOG_D(MAC,"[eNB] Frame %d : Scheduling BCCH->DLSCH (TDD) for SI %d bytes (mcs %d, rb 3, TBS %d)\n", + frameP, + bcch_sdu_length, + mcs, + mac_xface->get_TBS_DL(mcs,3)); + } + else { + LOG_D(MAC,"[eNB] Frame %d : Scheduling BCCH->DLSCH (FDD) for SI %d bytes (mcs %d, rb 3, TBS %d)\n", + frameP, + bcch_sdu_length, + mcs, + mac_xface->get_TBS_DL(mcs,3)); + } + eNB_mac_inst[module_idP].bcch_active=1; + *nprb=3; + *nCCE=4; + } + else { + eNB_mac_inst[module_idP].bcch_active=0; + *nprb=0; + *nCCE=0; + //LOG_D(MAC,"[eNB %d] Frame %d : BCCH not active \n",Mod_id,frame); + } + // this might be misleading when bcch is inactive + stop_meas(&eNB_mac_inst[module_idP].schedule_si); + return; +} diff --git a/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c b/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c new file mode 100644 index 0000000000..dd87d98b19 --- /dev/null +++ b/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c @@ -0,0 +1,1914 @@ +/******************************************************************************* + + Eurecom OpenAirInterface + Copyright(c) 1999 - 2010 Eurecom + + This program is free software; you can redistribute it and/or modify it + under the terms and conditions of the GNU General Public License, + version 2, as published by the Free Software Foundation. + + This program is distributed in the hope it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along with + this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + + The full GNU General Public License is included in this distribution in + the file called "COPYING". + + Contact Information + Openair Admin: openair_admin@eurecom.fr + Openair Tech : openair_tech@eurecom.fr + Forums : http://forums.eurecom.fsr/openairinterface + Address : Eurecom, 2229, route des crêtes, 06560 Valbonne Sophia Antipolis, France + + *******************************************************************************/ +/*! \file eNB_scheduler.c + * \brief procedures related to UE on the DLSCH transport channel + * \author Navid Nikaein and Raymond Knopp + * \date 2011 + * \email: navid.nikaein@eurecom.fr + * \version 0.5 + * @ingroup _mac + + */ + +#include "assertions.h" +#include "PHY/defs.h" +#include "PHY/extern.h" + +#include "SCHED/defs.h" +#include "SCHED/extern.h" + +#include "LAYER2/MAC/defs.h" +#include "LAYER2/MAC/proto.h" +#include "LAYER2/MAC/extern.h" +#include "UTIL/LOG/log.h" +#include "UTIL/LOG/vcd_signal_dumper.h" +#include "UTIL/OPT/opt.h" +#include "OCG.h" +#include "OCG_extern.h" +#include "ARCH/CBMIMO1/DEVICE_DRIVER/extern.h" +#include "ARCH/CBMIMO1/DEVICE_DRIVER/defs.h" +#include "ARCH/CBMIMO1/DEVICE_DRIVER/from_grlib_softregs.h" + +#include "RRC/LITE/extern.h" +#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h" + +//#include "LAYER2/MAC/pre_processor.c" +#include "pdcp.h" + +#if defined(ENABLE_ITTI) +# include "intertask_interface.h" +#endif + +#define ENABLE_MAC_PAYLOAD_DEBUG +#define DEBUG_eNB_SCHEDULER 1 + + +// function for determining which active ue should be granted resources in downlink based on CQI, SI, and BSR +uint8_t find_dlgranted_UEs(module_id_t module_idP){ + + // all active users should be granted + return(find_active_UEs(module_idP)); +} + +void add_ue_dlsch_info(module_id_t module_idP, module_id_t ue_mod_idP, sub_frame_t subframeP, UE_DLSCH_STATUS status){ + + eNB_dlsch_info[module_idP][ue_mod_idP].rnti = find_UE_RNTI(module_idP,ue_mod_idP); + // eNB_dlsch_info[module_idP][ue_mod_idP].weight = weight; + eNB_dlsch_info[module_idP][ue_mod_idP].subframe = subframeP; + eNB_dlsch_info[module_idP][ue_mod_idP].status = status; + + eNB_dlsch_info[module_idP][ue_mod_idP].serving_num++; + +} + +module_id_t schedule_next_dlue(module_id_t module_idP, sub_frame_t subframeP){ + + module_id_t next_ue; + + for (next_ue=0; next_ue < NUMBER_OF_UE_MAX; next_ue++ ){ + if (eNB_dlsch_info[module_idP][next_ue].status == S_DL_WAITING) + return next_ue; + } + for (next_ue=0; next_ue <NUMBER_OF_UE_MAX; next_ue++ ) + if (eNB_dlsch_info[module_idP][next_ue].status == S_DL_BUFFERED) { + eNB_dlsch_info[module_idP][next_ue].status = S_DL_WAITING; + } + // next_ue = -1; + return (module_id_t)(-1);//next_ue; + +} + +unsigned char generate_dlsch_header(unsigned char *mac_header, + unsigned char num_sdus, + unsigned short *sdu_lengths, + unsigned char *sdu_lcids, + unsigned char drx_cmd, + short timing_advance_cmd, + unsigned char *ue_cont_res_id, + unsigned char short_padding, + unsigned short post_padding) { + + SCH_SUBHEADER_FIXED *mac_header_ptr = (SCH_SUBHEADER_FIXED *)mac_header; + uint8_t first_element=0,last_size=0,i; + uint8_t mac_header_control_elements[16],*ce_ptr; + + ce_ptr = &mac_header_control_elements[0]; + + // compute header components + + if ((short_padding == 1) || (short_padding == 2)) { + mac_header_ptr->R = 0; + mac_header_ptr->E = 0; + mac_header_ptr->LCID = SHORT_PADDING; + first_element=1; + last_size=1; + } + if (short_padding == 2) { + mac_header_ptr->E = 1; + mac_header_ptr++; + mac_header_ptr->R = 0; + mac_header_ptr->E = 0; + mac_header_ptr->LCID = SHORT_PADDING; + last_size=1; + } + + if (drx_cmd != 255) { + if (first_element>0) { + mac_header_ptr->E = 1; + mac_header_ptr++; + } + else { + first_element=1; + } + mac_header_ptr->R = 0; + mac_header_ptr->E = 0; + mac_header_ptr->LCID = DRX_CMD; + last_size=1; + } + + if (timing_advance_cmd != 0) { + if (first_element>0) { + mac_header_ptr->E = 1; + mac_header_ptr++; + } + else { + first_element=1; + } + mac_header_ptr->R = 0; + mac_header_ptr->E = 0; + mac_header_ptr->LCID = TIMING_ADV_CMD; + last_size=1; + // msg("last_size %d,mac_header_ptr %p\n",last_size,mac_header_ptr); + ((TIMING_ADVANCE_CMD *)ce_ptr)->R=0; + ((TIMING_ADVANCE_CMD *)ce_ptr)->TA=timing_advance_cmd&0x3f; + LOG_I(MAC,"timing advance =%d (%d)\n",timing_advance_cmd,((TIMING_ADVANCE_CMD *)ce_ptr)->TA); + ce_ptr+=sizeof(TIMING_ADVANCE_CMD); + //msg("offset %d\n",ce_ptr-mac_header_control_elements); + } + + if (ue_cont_res_id) { + if (first_element>0) { + mac_header_ptr->E = 1; + /* + printf("[eNB][MAC] last subheader : %x (R%d,E%d,LCID%d)\n",*(unsigned char*)mac_header_ptr, + ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->R, + ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->E, + ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->LCID); + */ + mac_header_ptr++; + } + else { + first_element=1; + } + + mac_header_ptr->R = 0; + mac_header_ptr->E = 0; + mac_header_ptr->LCID = UE_CONT_RES; + last_size=1; + + LOG_T(MAC,"[eNB ][RAPROC] Generate contention resolution msg: %x.%x.%x.%x.%x.%x\n", + ue_cont_res_id[0], + ue_cont_res_id[1], + ue_cont_res_id[2], + ue_cont_res_id[3], + ue_cont_res_id[4], + ue_cont_res_id[5]); + + memcpy(ce_ptr,ue_cont_res_id,6); + ce_ptr+=6; + // msg("(cont_res) : offset %d\n",ce_ptr-mac_header_control_elements); + } + + //msg("last_size %d,mac_header_ptr %p\n",last_size,mac_header_ptr); + + for (i=0;i<num_sdus;i++) { + LOG_T(MAC,"[eNB] Generate DLSCH header num sdu %d len sdu %d\n",num_sdus, sdu_lengths[i]); + + if (first_element>0) { + mac_header_ptr->E = 1; + /*msg("last subheader : %x (R%d,E%d,LCID%d)\n",*(unsigned char*)mac_header_ptr, + ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->R, + ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->E, + ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->LCID); + */ + mac_header_ptr+=last_size; + //msg("last_size %d,mac_header_ptr %p\n",last_size,mac_header_ptr); + } + else { + first_element=1; + } + if (sdu_lengths[i] < 128) { + ((SCH_SUBHEADER_SHORT *)mac_header_ptr)->R = 0; + ((SCH_SUBHEADER_SHORT *)mac_header_ptr)->E = 0; + ((SCH_SUBHEADER_SHORT *)mac_header_ptr)->F = 0; + ((SCH_SUBHEADER_SHORT *)mac_header_ptr)->LCID = sdu_lcids[i]; + ((SCH_SUBHEADER_SHORT *)mac_header_ptr)->L = (unsigned char)sdu_lengths[i]; + last_size=2; + } + else { + ((SCH_SUBHEADER_LONG *)mac_header_ptr)->R = 0; + ((SCH_SUBHEADER_LONG *)mac_header_ptr)->E = 0; + ((SCH_SUBHEADER_LONG *)mac_header_ptr)->F = 1; + ((SCH_SUBHEADER_LONG *)mac_header_ptr)->LCID = sdu_lcids[i]; + ((SCH_SUBHEADER_LONG *)mac_header_ptr)->L_MSB = ((unsigned short) sdu_lengths[i]>>8)&0x7f; + ((SCH_SUBHEADER_LONG *)mac_header_ptr)->L_LSB = (unsigned short) sdu_lengths[i]&0xff; + ((SCH_SUBHEADER_LONG *)mac_header_ptr)->padding = 0x00; + last_size=3; +#ifdef DEBUG_HEADER_PARSING + LOG_D(MAC,"[eNB] generate long sdu, size %x (MSB %x, LSB %x)\n", + sdu_lengths[i], + ((SCH_SUBHEADER_LONG *)mac_header_ptr)->L_MSB, + ((SCH_SUBHEADER_LONG *)mac_header_ptr)->L_LSB); +#endif + } + } + /* + + printf("last_size %d,mac_header_ptr %p\n",last_size,mac_header_ptr); + + printf("last subheader : %x (R%d,E%d,LCID%d)\n",*(unsigned char*)mac_header_ptr, + ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->R, + ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->E, + ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->LCID); + + + if (((SCH_SUBHEADER_FIXED*)mac_header_ptr)->LCID < UE_CONT_RES) { + if (((SCH_SUBHEADER_SHORT*)mac_header_ptr)->F == 0) + printf("F = 0, sdu len (L field) %d\n",(((SCH_SUBHEADER_SHORT*)mac_header_ptr)->L)); + else + printf("F = 1, sdu len (L field) %d\n",(((SCH_SUBHEADER_LONG*)mac_header_ptr)->L)); + } + */ + if (post_padding>0) {// we have lots of padding at the end of the packet + mac_header_ptr->E = 1; + mac_header_ptr+=last_size; + // add a padding element + mac_header_ptr->R = 0; + mac_header_ptr->E = 0; + mac_header_ptr->LCID = SHORT_PADDING; + mac_header_ptr++; + } + else { // no end of packet padding + // last SDU subhead is of fixed type (sdu length implicitly to be computed at UE) + mac_header_ptr++; + } + + //msg("After subheaders %d\n",(uint8_t*)mac_header_ptr - mac_header); + + if ((ce_ptr-mac_header_control_elements) > 0) { + // printf("Copying %d bytes for control elements\n",ce_ptr-mac_header_control_elements); + memcpy((void*)mac_header_ptr,mac_header_control_elements,ce_ptr-mac_header_control_elements); + mac_header_ptr+=(unsigned char)(ce_ptr-mac_header_control_elements); + } + //msg("After CEs %d\n",(uint8_t*)mac_header_ptr - mac_header); + + return((unsigned char*)mac_header_ptr - mac_header); + +} + + +void schedule_ue_spec(module_id_t module_idP, + frame_t frameP, + sub_frame_t subframeP, + uint16_t nb_rb_used0, + unsigned int *nCCE_used, + int mbsfn_flag) { + + module_id_t ue_mod_id = -1; + module_id_t next_ue = -1; + unsigned char granted_UEs = 0; + uint16_t nCCE; + unsigned char aggregation; + mac_rlc_status_resp_t rlc_status; + unsigned char header_len_dcch=0, header_len_dcch_tmp=0,header_len_dtch=0,header_len_dtch_tmp=0, ta_len=0; + unsigned char sdu_lcids[11],offset,num_sdus=0; + uint16_t nb_rb,nb_rb_temp,nb_available_rb,TBS,j,sdu_lengths[11],rnti,padding=0,post_padding=0; + unsigned char dlsch_buffer[MAX_DLSCH_PAYLOAD_BYTES]; + unsigned char round = 0; + unsigned char harq_pid = 0; + void *DLSCH_dci = NULL; + LTE_eNB_UE_stats *eNB_UE_stats = NULL; + uint16_t sdu_length_total = 0; + unsigned char DAI; + uint16_t i = 0; + uint8_t dl_pow_off[NUMBER_OF_UE_MAX]; + unsigned char rballoc_sub_UE[NUMBER_OF_UE_MAX][N_RBGS_MAX]; + uint16_t pre_nb_available_rbs[NUMBER_OF_UE_MAX]; + int mcs; + uint16_t min_rb_unit; + short ta_update = 0; + + if (mbsfn_flag>0) + return; + + reset_meas(&eNB_mac_inst[module_idP].schedule_dlsch); + + switch (mac_xface->lte_frame_parms->N_RB_DL) { + case 6: + min_rb_unit=1; + break; + case 25: + min_rb_unit=2; + break; + case 50: + min_rb_unit=3; + break; + case 100: + min_rb_unit=4; + break; + default: + min_rb_unit=2; + break; + } + + //int **rballoc_sub = (int **)malloc(1792*sizeof(int *)); + granted_UEs = find_dlgranted_UEs(module_idP); + + + //weight = get_ue_weight(module_idP,UE_id); + aggregation = 1; // set to the maximum aggregation level + + + /// Initialization for pre-processor + for(i=0;i<NUMBER_OF_UE_MAX;i++){ + pre_nb_available_rbs[i] = 0; + dl_pow_off[i] = 2; + for(j=0;j<mac_xface->lte_frame_parms->N_RBGS;j++){ + // rballoc_sub[j] = 0; + rballoc_sub_UE[i][j] = 0; + } + } + + + for (i = 0; i < NUMBER_OF_UE_MAX; i++) { + PHY_vars_eNB_g[module_idP]->mu_mimo_mode[i].pre_nb_available_rbs = 0; + for (j = 0; j < mac_xface->lte_frame_parms->N_RBGS; j++) { + PHY_vars_eNB_g[module_idP]->mu_mimo_mode[i].rballoc_sub[j] = 0; + } + } + + + // set current available nb_rb and nCCE to maximum + nb_available_rb = mac_xface->lte_frame_parms->N_RB_DL - nb_rb_used0; + nCCE = mac_xface->get_nCCE_max(module_idP) - *nCCE_used; + + // store the goloabl enb stats + eNB_mac_inst[module_idP].eNB_stats.num_dlactive_UEs = granted_UEs; + eNB_mac_inst[module_idP].eNB_stats.available_prbs = nb_available_rb; + eNB_mac_inst[module_idP].eNB_stats.total_available_prbs += nb_available_rb; + eNB_mac_inst[module_idP].eNB_stats.available_ncces = nCCE; + eNB_mac_inst[module_idP].eNB_stats.dlsch_bytes_tx=0; + eNB_mac_inst[module_idP].eNB_stats.dlsch_pdus_tx=0; + + + /// CALLING Pre_Processor for downlink scheduling (Returns estimation of RBs required by each UE and the allocation on sub-band) + start_meas(&eNB_mac_inst[module_idP].schedule_dlsch_preprocessor); + dlsch_scheduler_pre_processor(module_idP, + frameP, + subframeP, + dl_pow_off, + pre_nb_available_rbs, + mac_xface->lte_frame_parms->N_RBGS, + rballoc_sub_UE); + stop_meas(&eNB_mac_inst[module_idP].schedule_dlsch_preprocessor); + + for (ue_mod_id=0;ue_mod_id<granted_UEs;ue_mod_id++) { + + rnti = find_UE_RNTI(module_idP,ue_mod_id); + + eNB_mac_inst[module_idP].eNB_UE_stats[ue_mod_id].crnti= rnti; + eNB_mac_inst[module_idP].eNB_UE_stats[ue_mod_id].rrc_status=mac_get_rrc_status(module_idP,1,ue_mod_id); + if (rnti==0) { + LOG_E(MAC,"Cannot find rnti for UE_id %d (granted UEs %d)\n",ue_mod_id,granted_UEs); + mac_xface->macphy_exit("Cannot find rnti for UE_id");//continue; + } + + eNB_UE_stats = mac_xface->get_eNB_UE_stats(module_idP,rnti); + if (eNB_UE_stats==NULL) + mac_xface->macphy_exit("[MAC][eNB] Cannot find eNB_UE_stats\n"); + + // Get candidate harq_pid from PHY + mac_xface->get_ue_active_harq_pid(module_idP,rnti,subframeP,&harq_pid,&round,0); + // printf("Got harq_pid %d, round %d\n",harq_pid,round); + + + nb_available_rb = pre_nb_available_rbs[ue_mod_id]; + + if ((nb_available_rb == 0) || (nCCE < (1<<aggregation))) { + LOG_D(MAC,"UE %d: nb_availiable_rb exhausted (nb_rb_used %d, nb_available_rb %d, nCCE %d, aggregation %d)\n", + ue_mod_id, nb_rb_used0, nb_available_rb, nCCE, aggregation); + //if(mac_xface->get_transmission_mode(module_idP,rnti)==5) + continue; //to next user (there might be rbs availiable for other UEs in TM5 + // else + // break; + } + sdu_length_total=0; + num_sdus=0; + + // get Round-Robin allocation + next_ue = ue_mod_id;//schedule_next_dlue(module_idP,subframeP); // next scheduled user + // If nobody is left, exit while loop and go to next step + if (next_ue == 255) + break; + + if (mac_xface->lte_frame_parms->frame_type == TDD) { + switch (mac_xface->lte_frame_parms->tdd_config) { + case 0: + if ((subframeP==0)||(subframeP==1)||(subframeP==3)||(subframeP==5)||(subframeP==6)||(subframeP==8)) + eNB_mac_inst[module_idP].UE_template[next_ue].DAI = 0; + case 1: + if ((subframeP==0)||(subframeP==4)||(subframeP==5)||(subframeP==9)) + eNB_mac_inst[module_idP].UE_template[next_ue].DAI = 0; + break; + case 2: + if ((subframeP==4)||(subframeP==5)) + eNB_mac_inst[module_idP].UE_template[next_ue].DAI = 0; + break; + case 3: + if ((subframeP==5)||(subframeP==7)||(subframeP==9)) + eNB_mac_inst[module_idP].UE_template[next_ue].DAI = 0; + break; + case 4: + if ((subframeP==0)||(subframeP==6)) + eNB_mac_inst[module_idP].UE_template[next_ue].DAI = 0; + break; + case 5: + if (subframeP==9) + eNB_mac_inst[module_idP].UE_template[next_ue].DAI = 0; + break; + case 6: + if ((subframeP==0)||(subframeP==1)||(subframeP==5)||(subframeP==6)||(subframeP==9)) + eNB_mac_inst[module_idP].UE_template[next_ue].DAI = 0; + default: + break; + } + } + + // This is an allocated UE_id + rnti = find_UE_RNTI(module_idP,next_ue); + if (rnti==0) + continue; + + eNB_UE_stats = mac_xface->get_eNB_UE_stats(module_idP,rnti); + + if (eNB_UE_stats==NULL) + mac_xface->macphy_exit("[MAC][eNB] Cannot find eNB_UE_stats\n"); + + if (openair_daq_vars.target_ue_dl_mcs <= 0) { + eNB_UE_stats->dlsch_mcs1 = cqi_to_mcs[eNB_UE_stats->DL_cqi[0]]; + LOG_T(MAC,"CQI %d\n",eNB_UE_stats->DL_cqi[0]); + } + else + eNB_UE_stats->dlsch_mcs1 = openair_daq_vars.target_ue_dl_mcs; + + + if(eNB_UE_stats->dlsch_mcs1>22) + eNB_UE_stats->dlsch_mcs1=22; + + + // for TM5, limit the MCS to 16QAM + + + // for EXMIMO, limit the MCS to 16QAM as well +#ifdef EXMIMO + eNB_UE_stats->dlsch_mcs1 = cmin(eNB_UE_stats->dlsch_mcs1,16); +#endif + + // Get candidate harq_pid from PHY + mac_xface->get_ue_active_harq_pid(module_idP,rnti,subframeP,&harq_pid,&round,0); + + eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].harq_pid = harq_pid; + eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].harq_round = round; + // Note this code is for a specific DCI format + DLSCH_dci = (void *)eNB_mac_inst[module_idP].UE_template[next_ue].DLSCH_DCI[harq_pid]; + + for(j=0;j<mac_xface->lte_frame_parms->N_RBGS;j++){ // initializing the rb allocation indicator for each UE + eNB_mac_inst[module_idP].UE_template[next_ue].rballoc_subband[harq_pid][j] = 0; + } + // store stats + eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].dl_cqi= eNB_UE_stats->DL_cqi[0]; + + if (round > 0) { + if (mac_xface->lte_frame_parms->frame_type == TDD) { + eNB_mac_inst[module_idP].UE_template[next_ue].DAI++; + LOG_D(MAC,"DAI update: subframeP %d: UE %d, DAI %d\n",subframeP,next_ue,eNB_mac_inst[module_idP].UE_template[next_ue].DAI); + + update_ul_dci(module_idP,rnti,eNB_mac_inst[module_idP].UE_template[next_ue].DAI); + } + + // get freq_allocation + nb_rb = eNB_mac_inst[module_idP].UE_template[next_ue].nb_rb[harq_pid]; + if (nb_rb <= nb_available_rb) { + + if(nb_rb == pre_nb_available_rbs[next_ue]){ + for(j=0;j<mac_xface->lte_frame_parms->N_RBGS;j++) // for indicating the rballoc for each sub-band + eNB_mac_inst[module_idP].UE_template[next_ue].rballoc_subband[harq_pid][j] = rballoc_sub_UE[next_ue][j];} + else + { + nb_rb_temp = nb_rb; + j = 0; + while((nb_rb_temp > 0) && (j<mac_xface->lte_frame_parms->N_RBGS)){ + if(rballoc_sub_UE[next_ue][j] == 1){ + eNB_mac_inst[module_idP].UE_template[next_ue].rballoc_subband[harq_pid][j] = rballoc_sub_UE[next_ue][j]; + if((j == mac_xface->lte_frame_parms->N_RBGS-1) && + ((mac_xface->lte_frame_parms->N_RB_DL == 25)|| + (mac_xface->lte_frame_parms->N_RB_DL == 50))) + nb_rb_temp = nb_rb_temp - min_rb_unit+1; + else + nb_rb_temp = nb_rb_temp - min_rb_unit; + } + j = j+1; + } + } + + nb_available_rb -= nb_rb; + aggregation = process_ue_cqi(module_idP,next_ue); + nCCE-=(1<<aggregation); // adjust the remaining nCCE + *nCCE_used += (1<<aggregation); + + + PHY_vars_eNB_g[module_idP]->mu_mimo_mode[next_ue].pre_nb_available_rbs = nb_rb; + PHY_vars_eNB_g[module_idP]->mu_mimo_mode[next_ue].dl_pow_off = dl_pow_off[next_ue]; + + for(j=0;j<mac_xface->lte_frame_parms->N_RBGS;j++) + PHY_vars_eNB_g[module_idP]->mu_mimo_mode[next_ue].rballoc_sub[j] = eNB_mac_inst[module_idP].UE_template[next_ue].rballoc_subband[harq_pid][j]; + + switch (mac_xface->get_transmission_mode(module_idP,rnti)) { + case 1: + case 2: + default: + switch (mac_xface->lte_frame_parms->N_RB_DL) { + case 6: + if (mac_xface->lte_frame_parms->frame_type == TDD) { + // ((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->ndi = 0; + ((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->harq_pid = harq_pid; + ((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->rv = round&3; + ((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->dai = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; + LOG_D(MAC,"[eNB %d] Retransmission : harq_pid %d, round %d, dai %d, mcs %d\n",module_idP,harq_pid,round,(eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1),((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->mcs); + } + else { + // ((DCI1_1_5MHz_FDD_t*)DLSCH_dci)->ndi = 0; + ((DCI1_1_5MHz_FDD_t*)DLSCH_dci)->harq_pid = harq_pid; + ((DCI1_1_5MHz_FDD_t*)DLSCH_dci)->rv = round&3; + LOG_D(MAC,"[eNB %d] Retransmission : harq_pid %d, round %d, mcs %d\n",module_idP,harq_pid,round,((DCI1_1_5MHz_FDD_t*)DLSCH_dci)->mcs); + + } + break; + case 25: + if (mac_xface->lte_frame_parms->frame_type == TDD) { + // ((DCI1_5MHz_TDD_t*)DLSCH_dci)->ndi = 0; + ((DCI1_5MHz_TDD_t*)DLSCH_dci)->harq_pid = harq_pid; + ((DCI1_5MHz_TDD_t*)DLSCH_dci)->rv = round&3; + ((DCI1_5MHz_TDD_t*)DLSCH_dci)->dai = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; + LOG_D(MAC,"[eNB %d] Retransmission : harq_pid %d, round %d, dai %d, mcs %d\n",module_idP,harq_pid,round,(eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1),((DCI1_5MHz_TDD_t*)DLSCH_dci)->mcs); + } + else { + // ((DCI1_5MHz_FDD_t*)DLSCH_dci)->ndi = 0; + ((DCI1_5MHz_FDD_t*)DLSCH_dci)->harq_pid = harq_pid; + ((DCI1_5MHz_FDD_t*)DLSCH_dci)->rv = round&3; + LOG_D(MAC,"[eNB %d] Retransmission : harq_pid %d, round %d, mcs %d\n",module_idP,harq_pid,round,((DCI1_5MHz_FDD_t*)DLSCH_dci)->mcs); + + } + break; + case 50: + if (mac_xface->lte_frame_parms->frame_type == TDD) { + // ((DCI1_10MHz_TDD_t*)DLSCH_dci)->ndi = 0; + ((DCI1_10MHz_TDD_t*)DLSCH_dci)->harq_pid = harq_pid; + ((DCI1_10MHz_TDD_t*)DLSCH_dci)->rv = round&3; + ((DCI1_10MHz_TDD_t*)DLSCH_dci)->dai = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; + LOG_D(MAC,"[eNB %d] Retransmission : harq_pid %d, round %d, dai %d, mcs %d\n",module_idP,harq_pid,round,(eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1),((DCI1_10MHz_TDD_t*)DLSCH_dci)->mcs); + } + else { + // ((DCI1_10MHz_FDD_t*)DLSCH_dci)->ndi = 0; + ((DCI1_10MHz_FDD_t*)DLSCH_dci)->harq_pid = harq_pid; + ((DCI1_10MHz_FDD_t*)DLSCH_dci)->rv = round&3; + LOG_D(MAC,"[eNB %d] Retransmission : harq_pid %d, round %d, mcs %d\n",module_idP,harq_pid,round,((DCI1_10MHz_FDD_t*)DLSCH_dci)->mcs); + + } + break; + case 100: + if (mac_xface->lte_frame_parms->frame_type == TDD) { + // ((DCI1_20MHz_TDD_t*)DLSCH_dci)->ndi = 0; + ((DCI1_20MHz_TDD_t*)DLSCH_dci)->harq_pid = harq_pid; + ((DCI1_20MHz_TDD_t*)DLSCH_dci)->rv = round&3; + ((DCI1_20MHz_TDD_t*)DLSCH_dci)->dai = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; + LOG_D(MAC,"[eNB %d] Retransmission : harq_pid %d, round %d, dai %d, mcs %d\n",module_idP,harq_pid,round,(eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1),((DCI1_20MHz_TDD_t*)DLSCH_dci)->mcs); + } + else { + // ((DCI1_20MHz_FDD_t*)DLSCH_dci)->ndi = 0; + ((DCI1_20MHz_FDD_t*)DLSCH_dci)->harq_pid = harq_pid; + ((DCI1_20MHz_FDD_t*)DLSCH_dci)->rv = round&3; + LOG_D(MAC,"[eNB %d] Retransmission : harq_pid %d, round %d, mcs %d\n",module_idP,harq_pid,round,((DCI1_20MHz_FDD_t*)DLSCH_dci)->mcs); + + } + break; + } + break; + case 4: + // if (nb_rb>10) { + ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->ndi1 = 0; + ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->harq_pid = harq_pid; + ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->dai = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; + // } + //else { + // ((DCI2_5MHz_2A_L10PRB_TDD_t*)DLSCH_dci)->ndi1 = 0; + // ((DCI2_5MHz_2A_L10PRB_TDD_t*)DLSCH_dci)->harq_pid = harq_pid; + // ((DCI2_5MHz_2A_L10PRB_TDD_t*)DLSCH_dci)->rv1 = round&3; + // ((DCI2_5MHz_2A_L10PRB_TDD_t*)DLSCH_dci)->dai = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; + // } + break; + case 5: + // if(nb_rb>10){ + //((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->mcs = eNB_UE_stats->DL_cqi[0]<<1; + ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->ndi = 0; + ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->harq_pid = harq_pid; + ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->rv = round&3; + ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->dai = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; + if(dl_pow_off[next_ue] == 2) + dl_pow_off[next_ue] = 1; + ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->dl_power_off = dl_pow_off[next_ue]; + // } + break; + case 6: + ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->ndi = 0; + ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->harq_pid = harq_pid; + ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->rv = round&3; + ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->dai = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; + ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->dl_power_off = 1;//dl_pow_off[next_ue]; + break; + } + + add_ue_dlsch_info(module_idP, + next_ue, + subframeP, + S_DL_SCHEDULED); + + //eNB_UE_stats->dlsch_trials[round]++; + eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].num_retransmission+=1; + eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].rbs_used_retx=nb_rb; + eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].total_rbs_used_retx+=nb_rb; + eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].ncce_used_retx=nCCE; + eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].dlsch_mcs1=eNB_UE_stats->dlsch_mcs1; + eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].dlsch_mcs2=eNB_UE_stats->dlsch_mcs1; + } + else { // don't schedule this UE, its retransmission takes more resources than we have + + } + } + else { // This is a potentially new SDU opportunity + + // calculate mcs + + rlc_status.bytes_in_buffer = 0; + // Now check RLC information to compute number of required RBs + // get maximum TBS size for RLC request + //TBS = mac_xface->get_TBS(eNB_UE_stats->DL_cqi[0]<<1,nb_available_rb); + TBS = mac_xface->get_TBS_DL(eNB_UE_stats->dlsch_mcs1,nb_available_rb); + // check first for RLC data on DCCH + // add the length for all the control elements (timing adv, drx, etc) : header + payload +#ifndef EXMIMO_IOT + ta_len = ((eNB_UE_stats->timing_advance_update/4)!=0) ? 2 : 0; +#else + ta_len = 0; +#endif + + header_len_dcch = 2; // 2 bytes DCCH SDU subheader + + + rlc_status = mac_rlc_status_ind( + module_idP, + ue_mod_id, + frameP, + ENB_FLAG_YES, + MBMS_FLAG_NO, + DCCH, + (TBS-ta_len-header_len_dcch)); // transport block set size + + sdu_lengths[0]=0; + if (rlc_status.bytes_in_buffer > 0) { // There is DCCH to transmit + LOG_D(MAC,"[eNB %d] Frame %d, DL-DCCH->DLSCH, Requesting %d bytes from RLC (RRC message)\n",module_idP,frameP,TBS-header_len_dcch); + sdu_lengths[0] += mac_rlc_data_req( + module_idP, + ue_mod_id, + frameP, + ENB_FLAG_YES, + MBMS_FLAG_NO, + DCCH, + (char *)&dlsch_buffer[sdu_lengths[0]]); + + LOG_D(MAC,"[eNB %d][DCCH] Got %d bytes from RLC\n",module_idP,sdu_lengths[0]); + sdu_length_total = sdu_lengths[0]; + sdu_lcids[0] = DCCH; + eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].num_pdu_tx[DCCH]+=1; + eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].num_bytes_tx[DCCH]+=sdu_lengths[0]; + num_sdus = 1; +#ifdef DEBUG_eNB_SCHEDULER + LOG_T(MAC,"[eNB %d][DCCH] Got %d bytes :",module_idP,sdu_lengths[0]); + for (j=0;j<sdu_lengths[0];j++) + LOG_T(MAC,"%x ",dlsch_buffer[j]); + LOG_T(MAC,"\n"); +#endif + } + else { + header_len_dcch = 0; + sdu_length_total = 0; + } + + // check for DCCH1 and update header information (assume 2 byte sub-header) + rlc_status = mac_rlc_status_ind( + module_idP, + ue_mod_id, + frameP, + ENB_FLAG_YES, + MBMS_FLAG_NO, + DCCH+1, + (TBS-ta_len-header_len_dcch-sdu_length_total)); // transport block set size less allocations for timing advance and + // DCCH SDU + + if (rlc_status.bytes_in_buffer > 0) { + LOG_D(MAC,"[eNB %d], Frame %d, DCCH1->DLSCH, Requesting %d bytes from RLC (RRC message)\n", + module_idP,frameP,TBS-header_len_dcch-sdu_length_total); + sdu_lengths[num_sdus] += mac_rlc_data_req( + module_idP, + ue_mod_id, + frameP, + ENB_FLAG_YES, + MBMS_FLAG_NO, + DCCH+1, + (char *)&dlsch_buffer[sdu_lengths[0]]); + + sdu_lcids[num_sdus] = DCCH1; + sdu_length_total += sdu_lengths[num_sdus]; + header_len_dcch += 2; + eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].num_pdu_tx[DCCH1]+=1; + eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].num_bytes_tx[DCCH1]+=sdu_lengths[num_sdus]; + num_sdus++; + LOG_D(MAC,"[eNB %d] Got %d bytes for DCCH from RLC\n",module_idP,sdu_lengths[0]); + } + // check for DTCH and update header information + // here we should loop over all possible DTCH + + header_len_dtch = 3; // 3 bytes DTCH SDU subheader + + LOG_D(MAC,"[eNB %d], Frame %d, DTCH->DLSCH, Checking RLC status (rab %d, tbs %d, len %d)\n", + module_idP,frameP,DTCH,TBS, + TBS-ta_len-header_len_dcch-sdu_length_total-header_len_dtch); + + rlc_status = mac_rlc_status_ind( + module_idP, + ue_mod_id, + frameP, + ENB_FLAG_YES, + MBMS_FLAG_NO, + DTCH, + TBS-ta_len-header_len_dcch-sdu_length_total-header_len_dtch); + + if (rlc_status.bytes_in_buffer > 0) { + + LOG_I(MAC,"[eNB %d][USER-PLANE DEFAULT DRB], Frame %d, DTCH->DLSCH, Requesting %d bytes from RLC (hdr len dtch %d)\n", + module_idP,frameP,TBS-header_len_dcch-sdu_length_total-header_len_dtch,header_len_dtch); + sdu_lengths[num_sdus] = mac_rlc_data_req( + module_idP, + ue_mod_id, + frameP, + ENB_FLAG_YES, + MBMS_FLAG_NO, + DTCH, + (char*)&dlsch_buffer[sdu_length_total]); + + LOG_I(MAC,"[eNB %d][USER-PLANE DEFAULT DRB] Got %d bytes for DTCH %d \n",module_idP,sdu_lengths[num_sdus],DTCH); + sdu_lcids[num_sdus] = DTCH; + sdu_length_total += sdu_lengths[num_sdus]; + eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].num_pdu_tx[DTCH]+=1; + eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].num_bytes_tx[DTCH]+=sdu_lengths[num_sdus]; + if (sdu_lengths[num_sdus] < 128) { + header_len_dtch=2; + } + num_sdus++; + } + else { + header_len_dtch = 0; + } + + // there is a payload + if (((sdu_length_total + header_len_dcch + header_len_dtch )> 0)) { + + // Now compute number of required RBs for total sdu length + // Assume RAH format 2 + // adjust header lengths + header_len_dcch_tmp = header_len_dcch; + header_len_dtch_tmp = header_len_dtch; + if (header_len_dtch==0) { + header_len_dcch = (header_len_dcch >0) ? 1 : header_len_dcch; // remove length field + } else { + header_len_dtch = (header_len_dtch > 0) ? 1 :header_len_dtch; // remove length field for the last SDU + } + + + mcs = eNB_UE_stats->dlsch_mcs1; + if (mcs==0) nb_rb = 4; // don't let the TBS get too small + else nb_rb=min_rb_unit; + + TBS = mac_xface->get_TBS_DL(mcs,nb_rb); + + while (TBS < (sdu_length_total + header_len_dcch + header_len_dtch + ta_len)) { + nb_rb += min_rb_unit; // + if (nb_rb>nb_available_rb) { // if we've gone beyond the maximum number of RBs + // (can happen if N_RB_DL is odd) + TBS = mac_xface->get_TBS_DL(eNB_UE_stats->dlsch_mcs1,nb_available_rb); + nb_rb = nb_available_rb; + break; + } + TBS = mac_xface->get_TBS_DL(eNB_UE_stats->dlsch_mcs1,nb_rb); + } + + if(nb_rb == pre_nb_available_rbs[next_ue]) { + for(j=0;j<mac_xface->lte_frame_parms->N_RBGS;j++) {// for indicating the rballoc for each sub-band + eNB_mac_inst[module_idP].UE_template[next_ue].rballoc_subband[harq_pid][j] = rballoc_sub_UE[next_ue][j]; + } + } else + { + nb_rb_temp = nb_rb; + j = 0; + while((nb_rb_temp > 0) && (j<mac_xface->lte_frame_parms->N_RBGS)){ + if(rballoc_sub_UE[next_ue][j] == 1){ + eNB_mac_inst[module_idP].UE_template[next_ue].rballoc_subband[harq_pid][j] = rballoc_sub_UE[next_ue][j]; + if ((j == mac_xface->lte_frame_parms->N_RBGS-1) && + ((mac_xface->lte_frame_parms->N_RB_DL == 25)|| + (mac_xface->lte_frame_parms->N_RB_DL == 50))) + nb_rb_temp = nb_rb_temp - min_rb_unit+1; + else + nb_rb_temp = nb_rb_temp - min_rb_unit; + } + j = j+1; + } + } + + PHY_vars_eNB_g[module_idP]->mu_mimo_mode[next_ue].pre_nb_available_rbs = nb_rb; + PHY_vars_eNB_g[module_idP]->mu_mimo_mode[next_ue].dl_pow_off = dl_pow_off[next_ue]; + + for(j=0;j<mac_xface->lte_frame_parms->N_RBGS;j++) + PHY_vars_eNB_g[module_idP]->mu_mimo_mode[next_ue].rballoc_sub[j] = eNB_mac_inst[module_idP].UE_template[next_ue].rballoc_subband[harq_pid][j]; + + + // decrease mcs until TBS falls below required length + while ((TBS > (sdu_length_total + header_len_dcch + header_len_dtch + ta_len)) && (mcs>0)) { + mcs--; + TBS = mac_xface->get_TBS_DL(mcs,nb_rb); + } + + // if we have decreased too much or we don't have enough RBs, increase MCS + while ((TBS < (sdu_length_total + header_len_dcch + header_len_dtch + ta_len)) && ((( dl_pow_off[next_ue]>0) && (mcs<28)) || ( (dl_pow_off[next_ue]==0) && (mcs<=15)))) { + mcs++; + TBS = mac_xface->get_TBS_DL(mcs,nb_rb); + } + + LOG_D(MAC,"dlsch_mcs before and after the rate matching = (%d, %d)\n",eNB_UE_stats->dlsch_mcs1, mcs); + +#ifdef DEBUG_eNB_SCHEDULER + LOG_D(MAC,"[eNB %d] Generated DLSCH header (mcs %d, TBS %d, nb_rb %d)\n", + module_idP,mcs,TBS,nb_rb); + // msg("[MAC][eNB ] Reminder of DLSCH with random data %d %d %d %d \n", + // TBS, sdu_length_total, offset, TBS-sdu_length_total-offset); +#endif + + if ((TBS - header_len_dcch - header_len_dtch - sdu_length_total - ta_len) <= 2) { + padding = (TBS - header_len_dcch - header_len_dtch - sdu_length_total - ta_len); + post_padding = 0; + } + else { + padding = 0; + // adjust the header len + if (header_len_dtch==0) + header_len_dcch = header_len_dcch_tmp; + else //if (( header_len_dcch==0)&&((header_len_dtch==1)||(header_len_dtch==2))) + header_len_dtch = header_len_dtch_tmp; + + post_padding = TBS - sdu_length_total - header_len_dcch - header_len_dtch - ta_len ; // 1 is for the postpadding header + } +#ifndef EXMIMO_IOT + ta_update = eNB_UE_stats->timing_advance_update/4; +#else + ta_update = 0; +#endif + + offset = generate_dlsch_header((unsigned char*)eNB_mac_inst[module_idP].DLSCH_pdu[(module_id_t)next_ue][0].payload[0], + // offset = generate_dlsch_header((unsigned char*)eNB_mac_inst[0].DLSCH_pdu[0][0].payload[0], + num_sdus, //num_sdus + sdu_lengths, // + sdu_lcids, + 255, // no drx + ta_update, // timing advance + NULL, // contention res id + padding, + post_padding); + //#ifdef DEBUG_eNB_SCHEDULER + LOG_I(MAC,"[eNB %d][USER-PLANE DEFAULT DRB] Generate header : sdu_length_total %d, num_sdus %d, sdu_lengths[0] %d, sdu_lcids[0] %d => payload offset %d,timing advance value : %d, next_ue %d,padding %d,post_padding %d,(mcs %d, TBS %d, nb_rb %d),header_dcch %d, header_dtch %d\n", + module_idP,sdu_length_total,num_sdus,sdu_lengths[0],sdu_lcids[0],offset, + ta_len,next_ue,padding,post_padding,mcs,TBS,nb_rb,header_len_dcch,header_len_dtch); + //#endif + + LOG_T(MAC,"[eNB %d] First 16 bytes of DLSCH : \n"); + for (i=0;i<16;i++) + LOG_T(MAC,"%x.",dlsch_buffer[i]); + LOG_T(MAC,"\n"); + + // cycle through SDUs and place in dlsch_buffer + memcpy(&eNB_mac_inst[module_idP].DLSCH_pdu[(module_id_t)next_ue][0].payload[0][offset],dlsch_buffer,sdu_length_total); + // memcpy(&eNB_mac_inst[0].DLSCH_pdu[0][0].payload[0][offset],dcch_buffer,sdu_lengths[0]); + + // fill remainder of DLSCH with random data + for (j=0;j<(TBS-sdu_length_total-offset);j++) + eNB_mac_inst[module_idP].DLSCH_pdu[(module_id_t)next_ue][0].payload[0][offset+sdu_length_total+j] = (char)(taus()&0xff); + //eNB_mac_inst[0].DLSCH_pdu[0][0].payload[0][offset+sdu_lengths[0]+j] = (char)(taus()&0xff); + +#if defined(USER_MODE) && defined(OAI_EMU) + /* Tracing of PDU is done on UE side */ + if (oai_emulation.info.opt_enabled) + trace_pdu(1, (uint8_t *)eNB_mac_inst[module_idP].DLSCH_pdu[(module_id_t)next_ue][0].payload[0], + TBS, module_idP, 3, find_UE_RNTI(module_idP,next_ue), + eNB_mac_inst[module_idP].subframe,0,0); + LOG_D(OPT,"[eNB %d][DLSCH] Frame %d rnti %x with size %d\n", + module_idP, frameP, find_UE_RNTI(module_idP,next_ue), TBS); +#endif + + aggregation = process_ue_cqi(module_idP,next_ue); + nCCE-=(1<<aggregation); // adjust the remaining nCCE + *nCCE_used+=(1<<aggregation); // adjust the remaining nCCE + eNB_mac_inst[module_idP].UE_template[next_ue].nb_rb[harq_pid] = nb_rb; + + add_ue_dlsch_info(module_idP, + next_ue, + subframeP, + S_DL_SCHEDULED); + // store stats + eNB_mac_inst[module_idP].eNB_stats.dlsch_bytes_tx+=sdu_length_total; + eNB_mac_inst[module_idP].eNB_stats.dlsch_pdus_tx+=1; + + eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].rbs_used = nb_rb; + eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].total_rbs_used += nb_rb; + eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].ncce_used = nCCE; + eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].dlsch_mcs1=eNB_UE_stats->dlsch_mcs1; + eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].dlsch_mcs2=mcs; + eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].TBS = TBS; + + eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].overhead_bytes= TBS- sdu_length_total; + eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].total_sdu_bytes+= sdu_length_total; + eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].total_pdu_bytes+= TBS; + eNB_mac_inst[module_idP].eNB_UE_stats[next_ue].total_num_pdus+=1; + + if (mac_xface->lte_frame_parms->frame_type == TDD) { + eNB_mac_inst[module_idP].UE_template[next_ue].DAI++; + // printf("DAI update: subframeP %d: UE %d, DAI %d\n",subframeP,next_ue,eNB_mac_inst[module_idP].UE_template[next_ue].DAI); +#warning only for 5MHz channel + update_ul_dci(module_idP,rnti,eNB_mac_inst[module_idP].UE_template[next_ue].DAI); + } + + switch (mac_xface->get_transmission_mode(module_idP,rnti)) { + case 1: + case 2: + default: + if (mac_xface->lte_frame_parms->frame_type == TDD) { + switch (mac_xface->lte_frame_parms->N_RB_DL) { + case 6: + ((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->mcs = mcs; + ((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->harq_pid = harq_pid; + ((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->ndi = 1-eNB_mac_inst[module_idP].UE_template[next_ue].oldNDI[harq_pid]; + ((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->rv = 0; + ((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->dai = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; + break; + case 25: + ((DCI1_5MHz_TDD_t*)DLSCH_dci)->mcs = mcs; + ((DCI1_5MHz_TDD_t*)DLSCH_dci)->harq_pid = harq_pid; + ((DCI1_5MHz_TDD_t*)DLSCH_dci)->ndi = 1-eNB_mac_inst[module_idP].UE_template[next_ue].oldNDI[harq_pid]; + ((DCI1_5MHz_TDD_t*)DLSCH_dci)->rv = 0; + ((DCI1_5MHz_TDD_t*)DLSCH_dci)->dai = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; + LOG_D(MAC,"Format1 DCI: harq_pid %d, ndi %d\n",harq_pid,((DCI1_5MHz_TDD_t*)DLSCH_dci)->ndi); + break; + case 50: + ((DCI1_10MHz_TDD_t*)DLSCH_dci)->mcs = mcs; + ((DCI1_10MHz_TDD_t*)DLSCH_dci)->harq_pid = harq_pid; + ((DCI1_10MHz_TDD_t*)DLSCH_dci)->ndi = 1-eNB_mac_inst[module_idP].UE_template[next_ue].oldNDI[harq_pid]; + ((DCI1_10MHz_TDD_t*)DLSCH_dci)->rv = 0; + ((DCI1_10MHz_TDD_t*)DLSCH_dci)->dai = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; + break; + case 100: + ((DCI1_20MHz_TDD_t*)DLSCH_dci)->mcs = mcs; + ((DCI1_20MHz_TDD_t*)DLSCH_dci)->harq_pid = harq_pid; + ((DCI1_20MHz_TDD_t*)DLSCH_dci)->ndi = 1-eNB_mac_inst[module_idP].UE_template[next_ue].oldNDI[harq_pid]; + ((DCI1_20MHz_TDD_t*)DLSCH_dci)->rv = 0; + ((DCI1_20MHz_TDD_t*)DLSCH_dci)->dai = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; + break; + default: + ((DCI1_5MHz_TDD_t*)DLSCH_dci)->mcs = mcs; + ((DCI1_5MHz_TDD_t*)DLSCH_dci)->harq_pid = harq_pid; + ((DCI1_5MHz_TDD_t*)DLSCH_dci)->ndi = 1-eNB_mac_inst[module_idP].UE_template[next_ue].oldNDI[harq_pid]; + ((DCI1_5MHz_TDD_t*)DLSCH_dci)->rv = 0; + ((DCI1_5MHz_TDD_t*)DLSCH_dci)->dai = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; + break; + } + } + else { + switch (mac_xface->lte_frame_parms->N_RB_DL) { + case 6: + ((DCI1_1_5MHz_FDD_t*)DLSCH_dci)->mcs = mcs; + ((DCI1_1_5MHz_FDD_t*)DLSCH_dci)->harq_pid = harq_pid; + ((DCI1_1_5MHz_FDD_t*)DLSCH_dci)->ndi = 1-eNB_mac_inst[module_idP].UE_template[next_ue].oldNDI[harq_pid]; + ((DCI1_1_5MHz_FDD_t*)DLSCH_dci)->rv = 0; + break; + case 25: + ((DCI1_5MHz_FDD_t*)DLSCH_dci)->mcs = mcs; + ((DCI1_5MHz_FDD_t*)DLSCH_dci)->harq_pid = harq_pid; + ((DCI1_5MHz_FDD_t*)DLSCH_dci)->ndi = 1-eNB_mac_inst[module_idP].UE_template[next_ue].oldNDI[harq_pid]; + ((DCI1_5MHz_FDD_t*)DLSCH_dci)->rv = 0; + break; + case 50: + ((DCI1_10MHz_FDD_t*)DLSCH_dci)->mcs = mcs; + ((DCI1_10MHz_FDD_t*)DLSCH_dci)->harq_pid = harq_pid; + ((DCI1_10MHz_FDD_t*)DLSCH_dci)->ndi = 1-eNB_mac_inst[module_idP].UE_template[next_ue].oldNDI[harq_pid]; + ((DCI1_10MHz_FDD_t*)DLSCH_dci)->rv = 0; + break; + case 100: + ((DCI1_20MHz_FDD_t*)DLSCH_dci)->mcs = mcs; + ((DCI1_20MHz_FDD_t*)DLSCH_dci)->harq_pid = harq_pid; + ((DCI1_20MHz_FDD_t*)DLSCH_dci)->ndi = 1-eNB_mac_inst[module_idP].UE_template[next_ue].oldNDI[harq_pid]; + ((DCI1_20MHz_FDD_t*)DLSCH_dci)->rv = 0; + break; + default: + ((DCI1_5MHz_FDD_t*)DLSCH_dci)->mcs = mcs; + ((DCI1_5MHz_FDD_t*)DLSCH_dci)->harq_pid = harq_pid; + ((DCI1_5MHz_FDD_t*)DLSCH_dci)->ndi = 1-eNB_mac_inst[module_idP].UE_template[next_ue].oldNDI[harq_pid]; + ((DCI1_5MHz_FDD_t*)DLSCH_dci)->rv = 0; + break; + } + } + break; + case 4: + // if (nb_rb>10) { + ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->mcs1 = mcs; + ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->harq_pid = harq_pid; + ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->ndi1 = 1; + ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->rv1 = round&3; + ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->dai = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; + + //} + /* else { + ((DCI2_5MHz_2A_L10PRB_TDD_t*)DLSCH_dci)->mcs1 = eNB_UE_stats->DL_cqi[0]; + ((DCI2_5MHz_2A_L10PRB_TDD_t*)DLSCH_dci)->harq_pid = harq_pid; + ((DCI2_5MHz_2A_L10PRB_TDD_t*)DLSCH_dci)->ndi1 = 1; + ((DCI2_5MHz_2A_L10PRB_TDD_t*)DLSCH_dci)->rv1 = round&3; + ((DCI2_5MHz_2A_L10PRB_TDD_t*)DLSCH_dci)->tpmi = 5; + ((DCI2_5MHz_2A_L10PRB_TDD_t*)DLSCH_dci)->dai = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; + }*/ + break; + case 5: + + ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->mcs = mcs; + ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->harq_pid = harq_pid; + ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->ndi = 1; + ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->rv = round&3; + ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->dai = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; + if(dl_pow_off[next_ue] == 2) + dl_pow_off[next_ue] = 1; + ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->dl_power_off = dl_pow_off[next_ue]; + ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->tpmi = 5; + break; + case 6: + ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->mcs = mcs; + ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->harq_pid = harq_pid; + ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->ndi = 1; + ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->rv = round&3; + ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->dai = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; + ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->dl_power_off = 1; + ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->tpmi = 5; + break; + } + // Toggle NDI for next time + LOG_D(MAC,"Frame %d, subframeP %d: Toggling Format1 NDI for UE %d (rnti %x/%d) oldNDI %d\n",frameP,subframeP,next_ue, + eNB_mac_inst[module_idP].UE_template[next_ue].rnti,harq_pid,eNB_mac_inst[module_idP].UE_template[next_ue].oldNDI[harq_pid]); + eNB_mac_inst[module_idP].UE_template[next_ue].oldNDI[harq_pid]=1-eNB_mac_inst[module_idP].UE_template[next_ue].oldNDI[harq_pid]; + } + + else { // There is no data from RLC or MAC header, so don't schedule + + } + } + if (mac_xface->lte_frame_parms->frame_type == TDD) { + DAI = (eNB_mac_inst[module_idP].UE_template[next_ue].DAI-1)&3; + LOG_D(MAC,"[eNB %d] Frame %d: DAI %d for UE %d\n",module_idP,frameP,DAI,next_ue); + // Save DAI for Format 0 DCI + + switch (mac_xface->lte_frame_parms->tdd_config) { + case 0: + // if ((subframeP==0)||(subframeP==1)||(subframeP==5)||(subframeP==6)) + break; + case 1: + switch (subframeP) { + case 1: + eNB_mac_inst[module_idP].UE_template[next_ue].DAI_ul[7] = DAI; + break; + case 4: + eNB_mac_inst[module_idP].UE_template[next_ue].DAI_ul[8] = DAI; + break; + case 6: + eNB_mac_inst[module_idP].UE_template[next_ue].DAI_ul[2] = DAI; + break; + case 9: + eNB_mac_inst[module_idP].UE_template[next_ue].DAI_ul[3] = DAI; + break; + } + case 2: + // if ((subframeP==3)||(subframeP==8)) + // eNB_mac_inst[module_idP].UE_template[next_ue].DAI_ul = DAI; + break; + case 3: + if ((subframeP==6)||(subframeP==8)||(subframeP==0)) { + LOG_D(MAC,"schedule_ue_spec: setting UL DAI to %d for subframeP %d => %d\n",DAI,subframeP, ((subframeP+8)%10)>>1); + eNB_mac_inst[module_idP].UE_template[next_ue].DAI_ul[((subframeP+8)%10)>>1] = DAI; + } + break; + case 4: + // if ((subframeP==8)||(subframeP==9)) + // eNB_mac_inst[module_idP].UE_template[next_ue].DAI_ul = DAI; + break; + case 5: + // if (subframeP==8) + // eNB_mac_inst[module_idP].UE_template[next_ue].DAI_ul = DAI; + break; + case 6: + // if ((subframeP==1)||(subframeP==4)||(subframeP==6)||(subframeP==9)) + // eNB_mac_inst[module_idP].UE_template[next_ue].DAI_ul = DAI; + break; + default: + break; + } + } + //printf("MAC nCCE : %d\n",*nCCE_used); + } + stop_meas(&eNB_mac_inst[module_idP].schedule_dlsch); +} + +void fill_DLSCH_dci(module_id_t module_idP,frame_t frameP, sub_frame_t subframeP,uint32_t RBalloc,uint8_t RA_scheduled,int mbsfn_flag) { + + // loop over all allocated UEs and compute frequency allocations for PDSCH + module_id_t ue_mod_id = -1; + uint8_t first_rb,nb_rb=3; + rnti_t rnti; + unsigned char vrb_map[100]; + uint8_t rballoc_sub[mac_xface->lte_frame_parms->N_RBGS]; + //uint8_t number_of_subbands=13; + uint32_t rballoc = RBalloc; + + unsigned char round; + unsigned char harq_pid; + void *DLSCH_dci=NULL; + DCI_PDU *DCI_pdu= &eNB_mac_inst[module_idP].DCI_pdu; + int i; + void *BCCH_alloc_pdu=(void*)&eNB_mac_inst[module_idP].BCCH_alloc_pdu; + int size_bits,size_bytes; + + if (mbsfn_flag>0) + return; + + start_meas(&eNB_mac_inst[module_idP].fill_DLSCH_dci); + + // clear vrb_map + memset(vrb_map,0,100); + + // SI DLSCH + // printf("BCCH check\n"); + if (eNB_mac_inst[module_idP].bcch_active == 1) { + eNB_mac_inst[module_idP].bcch_active = 0; + LOG_D(MAC,"[eNB %d] Frame %d subframeP %d: BCCH active\n", module_idP, frameP, subframeP); + // randomize frequency allocation for SI + first_rb = (unsigned char)(taus()%(mac_xface->lte_frame_parms->N_RB_DL-4)); + if (mac_xface->lte_frame_parms->frame_type == TDD) { + + } + else { + BCCH_alloc_pdu_fdd.rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); + rballoc |= mac_xface->get_rballoc(BCCH_alloc_pdu_fdd.vrb_type,BCCH_alloc_pdu_fdd.rballoc); + } + + vrb_map[first_rb] = 1; + vrb_map[first_rb+1] = 1; + vrb_map[first_rb+2] = 1; + vrb_map[first_rb+3] = 1; + + if (mac_xface->lte_frame_parms->frame_type == TDD) { + switch (mac_xface->lte_frame_parms->N_RB_DL) { + case 6: + ((DCI1A_1_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); + ((DCI1A_1_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->type = 1; + ((DCI1A_1_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->vrb_type = 0; + ((DCI1A_1_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->ndi = 1; + ((DCI1A_1_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rv = 1; + ((DCI1A_1_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->harq_pid = 0; + ((DCI1A_1_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->TPC = 1; + ((DCI1A_1_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->padding = 0; + rballoc |= mac_xface->get_rballoc(0,((DCI1A_1_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rballoc); + add_common_dci(DCI_pdu, + BCCH_alloc_pdu, + SI_RNTI, + sizeof(DCI1A_1_5MHz_TDD_1_6_t), + 2, + sizeof_DCI1A_1_5MHz_TDD_1_6_t, + format1A,0); + break; + case 25: + ((DCI1A_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); + ((DCI1A_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->type = 1; + ((DCI1A_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->vrb_type = 0; + ((DCI1A_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->ndi = 1; + ((DCI1A_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rv = 1; + ((DCI1A_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->harq_pid = 0; + ((DCI1A_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->TPC = 1; + ((DCI1A_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->padding = 0; + rballoc |= mac_xface->get_rballoc(0,((DCI1A_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rballoc); + add_common_dci(DCI_pdu, + BCCH_alloc_pdu, + SI_RNTI, + sizeof(DCI1A_5MHz_TDD_1_6_t), + 2, + sizeof_DCI1A_5MHz_TDD_1_6_t, + format1A,0); + break; + case 50: + ((DCI1A_10MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); + ((DCI1A_10MHz_TDD_1_6_t*)BCCH_alloc_pdu)->type = 1; + ((DCI1A_10MHz_TDD_1_6_t*)BCCH_alloc_pdu)->vrb_type = 0; + ((DCI1A_10MHz_TDD_1_6_t*)BCCH_alloc_pdu)->ndi = 1; + ((DCI1A_10MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rv = 1; + ((DCI1A_10MHz_TDD_1_6_t*)BCCH_alloc_pdu)->harq_pid = 0; + ((DCI1A_10MHz_TDD_1_6_t*)BCCH_alloc_pdu)->TPC = 1; + ((DCI1A_10MHz_TDD_1_6_t*)BCCH_alloc_pdu)->padding = 0; + rballoc |= mac_xface->get_rballoc(0,((DCI1A_10MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rballoc); + add_common_dci(DCI_pdu, + BCCH_alloc_pdu, + SI_RNTI, + sizeof(DCI1A_10MHz_TDD_1_6_t), + 2, + sizeof_DCI1A_10MHz_TDD_1_6_t, + format1A,0); + break; + case 100: + ((DCI1A_20MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); + ((DCI1A_20MHz_TDD_1_6_t*)BCCH_alloc_pdu)->type = 1; + ((DCI1A_20MHz_TDD_1_6_t*)BCCH_alloc_pdu)->vrb_type = 0; + ((DCI1A_20MHz_TDD_1_6_t*)BCCH_alloc_pdu)->ndi = 1; + ((DCI1A_20MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rv = 1; + ((DCI1A_20MHz_TDD_1_6_t*)BCCH_alloc_pdu)->harq_pid = 0; + ((DCI1A_20MHz_TDD_1_6_t*)BCCH_alloc_pdu)->TPC = 1; + ((DCI1A_20MHz_TDD_1_6_t*)BCCH_alloc_pdu)->padding = 0; + rballoc |= mac_xface->get_rballoc(0,((DCI1A_20MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rballoc); + add_common_dci(DCI_pdu, + BCCH_alloc_pdu, + SI_RNTI, + sizeof(DCI1A_20MHz_TDD_1_6_t), + 2, + sizeof_DCI1A_20MHz_TDD_1_6_t, + format1A,0); + break; + } + } + else { + switch (mac_xface->lte_frame_parms->N_RB_DL) { + case 6: + ((DCI1A_1_5MHz_FDD_t*)BCCH_alloc_pdu)->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); + ((DCI1A_1_5MHz_FDD_t*)BCCH_alloc_pdu)->type = 1; + ((DCI1A_1_5MHz_FDD_t*)BCCH_alloc_pdu)->vrb_type = 0; + ((DCI1A_1_5MHz_FDD_t*)BCCH_alloc_pdu)->ndi = 1; + ((DCI1A_1_5MHz_FDD_t*)BCCH_alloc_pdu)->rv = 1; + ((DCI1A_1_5MHz_FDD_t*)BCCH_alloc_pdu)->harq_pid = 0; + ((DCI1A_1_5MHz_FDD_t*)BCCH_alloc_pdu)->TPC = 1; + ((DCI1A_1_5MHz_FDD_t*)BCCH_alloc_pdu)->padding = 0; + + rballoc |= mac_xface->get_rballoc(0,((DCI1A_1_5MHz_FDD_t*)BCCH_alloc_pdu)->rballoc); + add_common_dci(DCI_pdu, + BCCH_alloc_pdu, + SI_RNTI, + sizeof(DCI1A_1_5MHz_FDD_t), + 2, + sizeof_DCI1A_1_5MHz_FDD_t, + format1A,0); + break; + case 25: + ((DCI1A_5MHz_FDD_t*)BCCH_alloc_pdu)->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); + ((DCI1A_5MHz_FDD_t*)BCCH_alloc_pdu)->type = 1; + ((DCI1A_5MHz_FDD_t*)BCCH_alloc_pdu)->vrb_type = 0; + ((DCI1A_5MHz_FDD_t*)BCCH_alloc_pdu)->ndi = 1; + ((DCI1A_5MHz_FDD_t*)BCCH_alloc_pdu)->rv = 1; + ((DCI1A_5MHz_FDD_t*)BCCH_alloc_pdu)->harq_pid = 0; + ((DCI1A_5MHz_FDD_t*)BCCH_alloc_pdu)->TPC = 1; + ((DCI1A_5MHz_FDD_t*)BCCH_alloc_pdu)->padding = 0; + + rballoc |= mac_xface->get_rballoc(0,((DCI1A_5MHz_FDD_t*)BCCH_alloc_pdu)->rballoc); + add_common_dci(DCI_pdu, + BCCH_alloc_pdu, + SI_RNTI, + sizeof(DCI1A_5MHz_FDD_t), + 2, + sizeof_DCI1A_5MHz_FDD_t, + format1A,0); + break; + case 50: + ((DCI1A_10MHz_FDD_t*)BCCH_alloc_pdu)->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); + ((DCI1A_10MHz_FDD_t*)BCCH_alloc_pdu)->type = 1; + ((DCI1A_10MHz_FDD_t*)BCCH_alloc_pdu)->vrb_type = 0; + ((DCI1A_10MHz_FDD_t*)BCCH_alloc_pdu)->ndi = 1; + ((DCI1A_10MHz_FDD_t*)BCCH_alloc_pdu)->rv = 1; + ((DCI1A_10MHz_FDD_t*)BCCH_alloc_pdu)->harq_pid = 0; + ((DCI1A_10MHz_FDD_t*)BCCH_alloc_pdu)->TPC = 1; + ((DCI1A_10MHz_FDD_t*)BCCH_alloc_pdu)->padding = 0; + + rballoc |= mac_xface->get_rballoc(0,((DCI1A_10MHz_FDD_t*)BCCH_alloc_pdu)->rballoc); + add_common_dci(DCI_pdu, + BCCH_alloc_pdu, + SI_RNTI, + sizeof(DCI1A_10MHz_FDD_t), + 2, + sizeof_DCI1A_10MHz_FDD_t, + format1A,0); + break; + case 100: + ((DCI1A_20MHz_FDD_t*)BCCH_alloc_pdu)->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); + ((DCI1A_20MHz_FDD_t*)BCCH_alloc_pdu)->type = 1; + ((DCI1A_20MHz_FDD_t*)BCCH_alloc_pdu)->vrb_type = 0; + ((DCI1A_20MHz_FDD_t*)BCCH_alloc_pdu)->ndi = 1; + ((DCI1A_20MHz_FDD_t*)BCCH_alloc_pdu)->rv = 1; + ((DCI1A_20MHz_FDD_t*)BCCH_alloc_pdu)->harq_pid = 0; + ((DCI1A_20MHz_FDD_t*)BCCH_alloc_pdu)->TPC = 1; + ((DCI1A_20MHz_FDD_t*)BCCH_alloc_pdu)->padding = 0; + + rballoc |= mac_xface->get_rballoc(0,((DCI1A_20MHz_FDD_t*)BCCH_alloc_pdu)->rballoc); + add_common_dci(DCI_pdu, + BCCH_alloc_pdu, + SI_RNTI, + sizeof(DCI1A_20MHz_FDD_t), + 2, + sizeof_DCI1A_20MHz_FDD_t, + format1A,0); + break; + } + } + } + if (RA_scheduled == 1) { + for (i=0;i<NB_RA_PROC_MAX;i++) { + + if (eNB_mac_inst[module_idP].RA_template[i].generate_rar == 1) { + + //FK: postponed to fill_rar + //eNB_mac_inst[module_idP].RA_template[i].generate_rar = 0; + + LOG_D(MAC,"[eNB %d] Frame %d, subframeP %d: Generating RAR DCI (proc %d), RA_active %d format 1A (%d,%d))\n", + module_idP,frameP, subframeP,i, + eNB_mac_inst[module_idP].RA_template[i].RA_active, + eNB_mac_inst[module_idP].RA_template[i].RA_dci_fmt1, + eNB_mac_inst[module_idP].RA_template[i].RA_dci_size_bits1); + // randomize frequency allocation for RA + while (1) { + first_rb = (unsigned char)(taus()%(mac_xface->lte_frame_parms->N_RB_DL-4)); + if ((vrb_map[first_rb] != 1) && (vrb_map[first_rb+3] != 1)) + break; + } + vrb_map[first_rb] = 1; + vrb_map[first_rb+1] = 1; + vrb_map[first_rb+2] = 1; + vrb_map[first_rb+3] = 1; + + if (mac_xface->lte_frame_parms->frame_type == TDD) { + switch(mac_xface->lte_frame_parms->N_RB_DL) { + case 6: + ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->type=1; + ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type=0; + ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->ndi=1; + ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rv=0; + ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->mcs=0; + ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->harq_pid=0; + ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->TPC=1; + ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->padding=0; + ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); + rballoc |= mac_xface->get_rballoc(((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type, + ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc); + break; + case 25: + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->type=1; + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type=0; + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->ndi=1; + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rv=0; + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->mcs=0; + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->harq_pid=0; + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->TPC=1; + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->padding=0; + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); + rballoc |= mac_xface->get_rballoc(((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type, + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc); + break; + case 50: + ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->type=1; + ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type=0; + ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->ndi=1; + ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rv=0; + ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->mcs=0; + ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->harq_pid=0; + ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->TPC=1; + ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->padding=0; + ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); + rballoc |= mac_xface->get_rballoc(((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type, + ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc); + break; + case 100: + ((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->type=1; + ((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type=0; + ((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->ndi=1; + ((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rv=0; + ((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->mcs=0; + ((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->harq_pid=0; + ((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->TPC=1; + ((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->padding=0; + ((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); + rballoc |= mac_xface->get_rballoc(((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type, + ((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc); + break; + default: + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->type=1; + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type=0; + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->ndi=1; + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rv=0; + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->mcs=0; + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->harq_pid=0; + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->TPC=1; + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->padding=0; + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); + rballoc |= mac_xface->get_rballoc(((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type, + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc); + break; + } + } + else { + switch(mac_xface->lte_frame_parms->N_RB_DL) { + case 6: + ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->type=1; + ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type=0; + ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->ndi=1; + ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rv=0; + ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->mcs=0; + ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->harq_pid=0; + ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->TPC=1; + ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->padding=0; + ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); + rballoc |= mac_xface->get_rballoc(((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type, + ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc); + break; + case 25: + ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->type=1; + ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type=0; + ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->ndi=1; + ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rv=0; + ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->mcs=0; + ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->harq_pid=0; + ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->TPC=1; + ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->padding=0; + ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_UL,first_rb,4); + rballoc |= mac_xface->get_rballoc(((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type, + ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc); + break; + case 50: + ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->type=1; + ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type=0; + ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->ndi=1; + ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rv=0; + ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->mcs=0; + ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->harq_pid=0; + ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->TPC=1; + ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->padding=0; + ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); + rballoc |= mac_xface->get_rballoc(((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type, + ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc); + break; + case 100: + ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->type=1; + ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type=0; + ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->ndi=1; + ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rv=0; + ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->mcs=0; + ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->harq_pid=0; + ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->TPC=1; + ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->padding=0; + ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); + rballoc |= mac_xface->get_rballoc(((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->vrb_type, + ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0])->rballoc); + break; + default: + break; + } + } + add_common_dci(DCI_pdu, + (void*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu1[0], + eNB_mac_inst[module_idP].RA_template[i].RA_rnti, + eNB_mac_inst[module_idP].RA_template[i].RA_dci_size_bytes1, + 2, + eNB_mac_inst[module_idP].RA_template[i].RA_dci_size_bits1, + eNB_mac_inst[module_idP].RA_template[i].RA_dci_fmt1, + 1); + + + + LOG_D(MAC,"[eNB %d] Frame %d: Adding common dci for RA%d (RAR) RA_active %d\n",module_idP,frameP,i, + eNB_mac_inst[module_idP].RA_template[i].RA_active); + } + if (eNB_mac_inst[module_idP].RA_template[i].generate_Msg4_dci == 1) { + + // randomize frequency allocation for RA + while (1) { + first_rb = (unsigned char)(taus()%(mac_xface->lte_frame_parms->N_RB_DL-4)); + if ((vrb_map[first_rb] != 1) && (vrb_map[first_rb+3] != 1)) + break; + } + vrb_map[first_rb] = 1; + vrb_map[first_rb+1] = 1; + vrb_map[first_rb+2] = 1; + vrb_map[first_rb+3] = 1; + + if (mac_xface->lte_frame_parms->frame_type == TDD) { + switch (mac_xface->lte_frame_parms->N_RB_DL) { + case 6: + ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->type=1; + ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type=0; + ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rv=0; + ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->harq_pid=0; + ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->TPC=1; + ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->padding=0; + ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc= mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); + rballoc |= mac_xface->get_rballoc(((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type, + ((DCI1A_1_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc); + break; + case 25: + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->type=1; + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type=0; + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rv=0; + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->harq_pid=0; + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->TPC=1; + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->padding=0; + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc= mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); + rballoc |= mac_xface->get_rballoc(((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type, + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc); + break; + case 50: + ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->type=1; + ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type=0; + ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rv=0; + ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->harq_pid=0; + ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->TPC=1; + ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->padding=0; + ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc= mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); + rballoc |= mac_xface->get_rballoc(((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type, + ((DCI1A_10MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc); + break; + case 100: + ((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->type=1; + ((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type=0; + ((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rv=0; + ((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->harq_pid=0; + ((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->TPC=1; + ((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc= mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); + rballoc |= mac_xface->get_rballoc(((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type, + ((DCI1A_20MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc); + break; + default: + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->type=1; + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type=0; + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rv=0; + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->harq_pid=0; + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->TPC=1; + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->padding=0; + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc= mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); + rballoc |= mac_xface->get_rballoc(((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type, + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc); + break; + } + } + else { + switch (mac_xface->lte_frame_parms->N_RB_DL) { + + case 6: + ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->type=1; + ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type=0; + ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rv=0; + ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->harq_pid=0; + ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->TPC=1; + ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->padding=0; + ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc= mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); + rballoc |= mac_xface->get_rballoc(((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type, + ((DCI1A_1_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc); + break; + case 25: + ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->type=1; + ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type=0; + ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rv=0; + ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->harq_pid=0; + ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->TPC=1; + ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->padding=0; + ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc= mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); + rballoc |= mac_xface->get_rballoc(((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type, + ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc); + break; + case 50: + ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->type=1; + ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type=0; + ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rv=0; + ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->harq_pid=0; + ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->TPC=1; + ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->padding=0; + ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc= mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); + rballoc |= mac_xface->get_rballoc(((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type, + ((DCI1A_10MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc); + break; + case 100: + ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->type=1; + ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type=0; + ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rv=0; + ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->harq_pid=0; + ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->TPC=1; + ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->padding=0; + ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc= mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); + rballoc |= mac_xface->get_rballoc(((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type, + ((DCI1A_20MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc); + break; + default: + ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->type=1; + ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type=0; + ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rv=0; + ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->harq_pid=0; + ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->TPC=1; + ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc= mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_DL,first_rb,4); + rballoc |= mac_xface->get_rballoc(((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type, + ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc); + break; + } + } + + add_ue_spec_dci(DCI_pdu, + (void*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0], + eNB_mac_inst[module_idP].RA_template[i].rnti, + eNB_mac_inst[module_idP].RA_template[i].RA_dci_size_bytes2, + 1, + eNB_mac_inst[module_idP].RA_template[i].RA_dci_size_bits2, + eNB_mac_inst[module_idP].RA_template[i].RA_dci_fmt2, + 0); + LOG_D(MAC,"[eNB %d][RAPROC] Frame %d, subframeP %d: Adding ue specific dci (rnti %x) for Msg4\n", + module_idP,frameP,subframeP,eNB_mac_inst[module_idP].RA_template[i].rnti); + eNB_mac_inst[module_idP].RA_template[i].generate_Msg4_dci=0; + + } + else if (eNB_mac_inst[module_idP].RA_template[i].wait_ack_Msg4==1) { + // check HARQ status and retransmit if necessary + LOG_I(MAC,"[eNB %d][RAPROC] Frame %d, subframeP %d: Checking if Msg4 was acknowledged: \n", + module_idP,frameP,subframeP); + // Get candidate harq_pid from PHY + mac_xface->get_ue_active_harq_pid(module_idP,eNB_mac_inst[module_idP].RA_template[i].rnti,subframeP,&harq_pid,&round,0); + if (round>0) { + // we have to schedule a retransmission + if (mac_xface->lte_frame_parms->frame_type == TDD) + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->ndi=1; + else + ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->ndi=1; + // randomize frequency allocation for RA + while (1) { + first_rb = (unsigned char)(taus()%(mac_xface->lte_frame_parms->N_RB_DL-4)); + if ((vrb_map[first_rb] != 1) && (vrb_map[first_rb+3] != 1)) + break; + } + vrb_map[first_rb] = 1; + vrb_map[first_rb+1] = 1; + vrb_map[first_rb+2] = 1; + vrb_map[first_rb+3] = 1; + if (mac_xface->lte_frame_parms->frame_type == TDD) { + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_UL,first_rb,4); + rballoc |= mac_xface->get_rballoc(((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type, + ((DCI1A_5MHz_TDD_1_6_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc); + } + else { + ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_UL,first_rb,4); + rballoc |= mac_xface->get_rballoc(((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->vrb_type, + ((DCI1A_5MHz_FDD_t*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0])->rballoc); + } + + add_ue_spec_dci(DCI_pdu, + (void*)&eNB_mac_inst[module_idP].RA_template[i].RA_alloc_pdu2[0], + eNB_mac_inst[module_idP].RA_template[i].rnti, + eNB_mac_inst[module_idP].RA_template[i].RA_dci_size_bytes2, + 2, + eNB_mac_inst[module_idP].RA_template[i].RA_dci_size_bits2, + eNB_mac_inst[module_idP].RA_template[i].RA_dci_fmt2, + 0); + LOG_W(MAC,"[eNB %d][RAPROC] Frame %d, subframeP %d: Msg4 not acknowledged, adding ue specific dci (rnti %x) for RA (Msg4 Retransmission)\n", + module_idP,frameP,subframeP,eNB_mac_inst[module_idP].RA_template[i].rnti); + } + else { + LOG_I(MAC,"[eNB %d][RAPROC] Frame %d, subframeP %d : Msg4 acknowledged\n",module_idP,frameP,subframeP); + eNB_mac_inst[module_idP].RA_template[i].wait_ack_Msg4=0; + eNB_mac_inst[module_idP].RA_template[i].RA_active=FALSE; + } + } + } + } // RA is scheduled in this subframeP + + // UE specific DCIs + for (ue_mod_id=0;ue_mod_id<NUMBER_OF_UE_MAX;ue_mod_id++) { + //printf("UE_id: %d => status %d\n",UE_id,eNB_dlsch_info[module_idP][UE_id].status); + if (eNB_dlsch_info[module_idP][ue_mod_id].status == S_DL_SCHEDULED) { + + // clear scheduling flag + eNB_dlsch_info[module_idP][ue_mod_id].status = S_DL_WAITING; + rnti = find_UE_RNTI(module_idP,ue_mod_id); + mac_xface->get_ue_active_harq_pid(module_idP,rnti,subframeP,&harq_pid,&round,0); + nb_rb = eNB_mac_inst[module_idP].UE_template[ue_mod_id].nb_rb[harq_pid]; + + DLSCH_dci = (void *)eNB_mac_inst[module_idP].UE_template[ue_mod_id].DLSCH_DCI[harq_pid]; + + + /// Synchronizing rballoc with rballoc_sub + for(i=0;i<mac_xface->lte_frame_parms->N_RBGS;i++){ + rballoc_sub[i] = eNB_mac_inst[module_idP].UE_template[ue_mod_id].rballoc_subband[harq_pid][i]; + if(rballoc_sub[i] == 1) + rballoc |= (0x0001<<i); // TO be FIXED!!!!!! + } + + + switch(mac_xface->get_transmission_mode(module_idP,rnti)) { + default: + + case 1: + + case 2: + LOG_D(MAC,"[USER-PLANE DEFAULT DRB] Adding UE spec DCI for %d PRBS (%x) => ",nb_rb,rballoc); + if (mac_xface->lte_frame_parms->frame_type == TDD) { + switch (mac_xface->lte_frame_parms->N_RB_DL) { + case 6: + ((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,rballoc_sub); + ((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->rah = 0; + size_bytes = sizeof(DCI1_1_5MHz_TDD_t); + size_bits = sizeof_DCI1_1_5MHz_TDD_t; + break; + case 25: + ((DCI1_5MHz_TDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,rballoc_sub); + ((DCI1_5MHz_TDD_t*)DLSCH_dci)->rah = 0; + size_bytes = sizeof(DCI1_5MHz_TDD_t); + size_bits = sizeof_DCI1_5MHz_TDD_t; + break; + case 50: + ((DCI1_10MHz_TDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,rballoc_sub); + ((DCI1_10MHz_TDD_t*)DLSCH_dci)->rah = 0; + size_bytes = sizeof(DCI1_10MHz_TDD_t); + size_bits = sizeof_DCI1_10MHz_TDD_t; + break; + case 100: + ((DCI1_20MHz_TDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,rballoc_sub); + ((DCI1_20MHz_TDD_t*)DLSCH_dci)->rah = 0; + size_bytes = sizeof(DCI1_20MHz_TDD_t); + size_bits = sizeof_DCI1_20MHz_TDD_t; + break; + default: + ((DCI1_5MHz_TDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,rballoc_sub); + ((DCI1_5MHz_TDD_t*)DLSCH_dci)->rah = 0; + size_bytes = sizeof(DCI1_5MHz_TDD_t); + size_bits = sizeof_DCI1_5MHz_TDD_t; + break; + } + + + } + else { + switch(mac_xface->lte_frame_parms->N_RB_DL) { + case 6: + ((DCI1_1_5MHz_FDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,rballoc_sub); + ((DCI1_1_5MHz_FDD_t*)DLSCH_dci)->rah = 0; + size_bytes=sizeof(DCI1_1_5MHz_FDD_t); + size_bits=sizeof_DCI1_1_5MHz_FDD_t; + break; + case 25: + ((DCI1_5MHz_FDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,rballoc_sub); + ((DCI1_5MHz_FDD_t*)DLSCH_dci)->rah = 0; + size_bytes=sizeof(DCI1_5MHz_FDD_t); + size_bits=sizeof_DCI1_5MHz_FDD_t; + break; + case 50: + ((DCI1_10MHz_FDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,rballoc_sub); + ((DCI1_10MHz_FDD_t*)DLSCH_dci)->rah = 0; + size_bytes=sizeof(DCI1_10MHz_FDD_t); + size_bits=sizeof_DCI1_10MHz_FDD_t; + break; + case 100: + ((DCI1_20MHz_FDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,rballoc_sub); + ((DCI1_20MHz_FDD_t*)DLSCH_dci)->rah = 0; + size_bytes=sizeof(DCI1_20MHz_FDD_t); + size_bits=sizeof_DCI1_20MHz_FDD_t; + break; + default: + ((DCI1_5MHz_FDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,rballoc_sub); + ((DCI1_5MHz_FDD_t*)DLSCH_dci)->rah = 0; + size_bytes=sizeof(DCI1_5MHz_FDD_t); + size_bits=sizeof_DCI1_5MHz_FDD_t; + break; + } + } + + add_ue_spec_dci(DCI_pdu, + DLSCH_dci, + rnti, + size_bytes, + process_ue_cqi (module_idP,ue_mod_id),//aggregation, + size_bits, + format1, + 0); + + break; + case 4: + + //if (nb_rb>10) { + // DCI format 2_2A + ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,rballoc_sub); + ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->rah = 0; + add_ue_spec_dci(DCI_pdu, + DLSCH_dci, + rnti, + sizeof(DCI2_5MHz_2A_TDD_t), + process_ue_cqi (module_idP,ue_mod_id),//aggregation, + sizeof_DCI2_5MHz_2A_TDD_t, + format2, + 0); + /*} + else { + ((DCI2_5MHz_2A_L10PRB_TDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,rballoc_sub); + add_ue_spec_dci(DCI_pdu, + DLSCH_dci, + rnti, + sizeof(DCI2_5MHz_2A_L10PRB_TDD_t), + 2,//aggregation, + sizeof_DCI2_5MHz_2A_L10PRB_TDD_t, + format2_2A_L10PRB); + }*/ + break; + case 5: + ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,rballoc_sub); + ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->rah = 0; + + add_ue_spec_dci(DCI_pdu, + DLSCH_dci, + rnti, + sizeof(DCI1E_5MHz_2A_M10PRB_TDD_t), + process_ue_cqi (module_idP,ue_mod_id),//aggregation, + sizeof_DCI1E_5MHz_2A_M10PRB_TDD_t, + format1E_2A_M10PRB, + 0); + break; + + case 6: + ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,rballoc_sub); + ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->rah = 0; + + add_ue_spec_dci(DCI_pdu, + DLSCH_dci, + rnti, + sizeof(DCI1E_5MHz_2A_M10PRB_TDD_t), + process_ue_cqi (module_idP,ue_mod_id),//aggregation + sizeof_DCI1E_5MHz_2A_M10PRB_TDD_t, + format1E_2A_M10PRB, + 0); + break; + + } + } + + + } + stop_meas(&eNB_mac_inst[module_idP].fill_DLSCH_dci); +} + diff --git a/openair2/LAYER2/MAC/eNB_scheduler_mch.c b/openair2/LAYER2/MAC/eNB_scheduler_mch.c new file mode 100644 index 0000000000..5ed1f48da5 --- /dev/null +++ b/openair2/LAYER2/MAC/eNB_scheduler_mch.c @@ -0,0 +1,580 @@ +/******************************************************************************* + + Eurecom OpenAirInterface + Copyright(c) 1999 - 2010 Eurecom + + This program is free software; you can redistribute it and/or modify it + under the terms and conditions of the GNU General Public License, + version 2, as published by the Free Software Foundation. + + This program is distributed in the hope it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along with + this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + + The full GNU General Public License is included in this distribution in + the file called "COPYING". + + Contact Information + Openair Admin: openair_admin@eurecom.fr + Openair Tech : openair_tech@eurecom.fr + Forums : http://forums.eurecom.fsr/openairinterface + Address : Eurecom, 2229, route des crêtes, 06560 Valbonne Sophia Antipolis, France + + *******************************************************************************/ +/*! \file eNB_scheduler_mch.c + * \brief procedures related to UE on the MCH transport channel + * \author Navid Nikaein and Raymond Knopp + * \date 2012 - 2014 + * \email: navid.nikaein@eurecom.fr + * \version 0.5 + * @ingroup _mac + + */ + +#include "assertions.h" +#include "PHY/defs.h" +#include "PHY/extern.h" + +#include "SCHED/defs.h" +#include "SCHED/extern.h" + +#include "LAYER2/MAC/defs.h" +#include "LAYER2/MAC/proto.h" +#include "LAYER2/MAC/extern.h" +#include "UTIL/LOG/log.h" +#include "UTIL/LOG/vcd_signal_dumper.h" +#include "UTIL/OPT/opt.h" +#include "OCG.h" +#include "OCG_extern.h" +#include "ARCH/CBMIMO1/DEVICE_DRIVER/extern.h" +#include "ARCH/CBMIMO1/DEVICE_DRIVER/defs.h" +#include "ARCH/CBMIMO1/DEVICE_DRIVER/from_grlib_softregs.h" + +#include "RRC/LITE/extern.h" +#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h" + +//#include "LAYER2/MAC/pre_processor.c" +#include "pdcp.h" + +#if defined(ENABLE_ITTI) +# include "intertask_interface.h" +#endif + +#define ENABLE_MAC_PAYLOAD_DEBUG +#define DEBUG_eNB_SCHEDULER 1 + + +#ifdef Rel10 +int8_t get_mbsfn_sf_alloction (module_id_t module_idP, uint8_t mbsfn_sync_area){ + // currently there is one-to-one mapping between sf allocation pattern and sync area + if (mbsfn_sync_area > MAX_MBSFN_AREA){ + LOG_W(MAC,"[eNB %d] MBSFN synchronization area %d out of range\n ", module_idP, mbsfn_sync_area); + return -1; + } + else if (eNB_mac_inst[module_idP].mbsfn_SubframeConfig[mbsfn_sync_area] != NULL) + return mbsfn_sync_area; + else { + LOG_W(MAC,"[eNB %d] MBSFN Subframe Config pattern %d not found \n ", module_idP, mbsfn_sync_area); + return -1; + } +} + +int schedule_MBMS(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP) { + + int mcch_flag=0,mtch_flag=0, msi_flag=0; + int mbsfn_period =0;// 1<<(eNB_mac_inst[module_idP].mbsfn_SubframeConfig[0]->radioframeAllocationPeriod); + int mcch_period = 0;//32<<(eNB_mac_inst[module_idP].mbsfn_AreaInfo[0]->mcch_Config_r9.mcch_RepetitionPeriod_r9); + int mch_scheduling_period = 8<<(eNB_mac_inst[module_idP].pmch_Config[0]->mch_SchedulingPeriod_r9); + unsigned char mcch_sdu_length; + unsigned char header_len_mcch=0,header_len_msi=0,header_len_mtch=0, header_len_mtch_temp=0, header_len_mcch_temp=0, header_len_msi_temp=0; + int ii=0, msi_pos=0; + int mcch_mcs = -1; + uint16_t TBS,j,padding=0,post_padding=0; + mac_rlc_status_resp_t rlc_status; + int num_mtch; + int msi_length,i,k; + unsigned char sdu_lcids[11], num_sdus=0, offset=0; + uint16_t sdu_lengths[11], sdu_length_total=0; + unsigned char mch_buffer[MAX_DLSCH_PAYLOAD_BYTES]; // check the max value, this is for dlsch only + + eNB_mac_inst[module_idP].MCH_pdu.Pdu_size=0; + + for (i=0; + i< eNB_mac_inst[module_idP].num_active_mbsfn_area; + i++ ){ + // assume, that there is always a mapping + if ((j=get_mbsfn_sf_alloction(module_idP,i)) == -1) + return 0; + + mbsfn_period = 1<<(eNB_mac_inst[module_idP].mbsfn_SubframeConfig[j]->radioframeAllocationPeriod); + mcch_period = 32<<(eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.mcch_RepetitionPeriod_r9); + msi_pos=0; ii=0; + LOG_D(MAC,"[eNB %d] Frame %d subframeP %d : Checking MBSFN Sync Area %d/%d with SF allocation %d/%d for MCCH and MTCH (mbsfn period %d, mcch period %d)\n", + module_idP,frameP, subframeP,i,eNB_mac_inst[module_idP].num_active_mbsfn_area, + j,eNB_mac_inst[module_idP].num_sf_allocation_pattern,mbsfn_period,mcch_period); + + + switch (eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.signallingMCS_r9) { + case 0: + mcch_mcs = 2; + break; + case 1: + mcch_mcs = 7; + break; + case 2: + mcch_mcs = 13; + break; + case 3: + mcch_mcs = 19; + break; + } + + // 1st: Check the MBSFN subframes from SIB2 info (SF allocation pattern i, max 8 non-overlapping patterns exist) + if (frameP % mbsfn_period == eNB_mac_inst[module_idP].mbsfn_SubframeConfig[j]->radioframeAllocationOffset){ // MBSFN frameP + if (eNB_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.present == MBSFN_SubframeConfig__subframeAllocation_PR_oneFrame){// one-frameP format + + // Find the first subframeP in this MCH to transmit MSI + if (frameP % mch_scheduling_period == eNB_mac_inst[module_idP].mbsfn_SubframeConfig[j]->radioframeAllocationOffset ) { + while (ii == 0) { + ii = eNB_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.choice.oneFrame.buf[0] & (0x80>>msi_pos); + msi_pos++; + } + LOG_D(MAC,"[eNB %d] Frame %d subframeP %d : sync area %d sf allocation pattern %d sf alloc %x msi pos is %d \n", module_idP,frameP, subframeP,i,j,eNB_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.choice.oneFrame.buf[0], msi_pos); + } + + // Check if the subframeP is for MSI, MCCH or MTCHs and Set the correspoding flag to 1 + switch (subframeP) { + case 1: + if (mac_xface->lte_frame_parms->frame_type == FDD) { + if ((eNB_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.choice.oneFrame.buf[0] & MBSFN_FDD_SF1) == MBSFN_FDD_SF1) { + if (msi_pos == 1) + msi_flag = 1; + if ( (frameP % mcch_period == eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.mcch_Offset_r9) && + ((eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.sf_AllocInfo_r9.buf[0] & MBSFN_FDD_SF1) == MBSFN_FDD_SF1) ) + mcch_flag = 1; + mtch_flag = 1; + } + } + break; + + case 2: + if (mac_xface->lte_frame_parms->frame_type == FDD){ + if ((eNB_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.choice.oneFrame.buf[0] & MBSFN_FDD_SF2) == MBSFN_FDD_SF2) { + if (msi_pos == 2) + msi_flag = 1; + if ( (frameP % mcch_period == eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.mcch_Offset_r9) && + ((eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.sf_AllocInfo_r9.buf[0] & MBSFN_FDD_SF2) == MBSFN_FDD_SF2) ) + mcch_flag = 1; + mtch_flag = 1; + } + } + break; + + case 3: + if (mac_xface->lte_frame_parms->frame_type == TDD){// TDD + if ((eNB_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.choice.oneFrame.buf[0] & MBSFN_TDD_SF3) == MBSFN_TDD_SF3) { + if (msi_pos == 1) + msi_flag = 1; + if ( (frameP % mcch_period == eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.mcch_Offset_r9) && + ((eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.sf_AllocInfo_r9.buf[0] & MBSFN_TDD_SF3) == MBSFN_TDD_SF3) ) + mcch_flag = 1; + mtch_flag = 1; + } + } + else {// FDD + if ((eNB_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.choice.oneFrame.buf[0] & MBSFN_FDD_SF3) == MBSFN_FDD_SF3) { + if (msi_pos == 3) + msi_flag = 1; + if ( (frameP % mcch_period == eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.mcch_Offset_r9) && + ((eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.sf_AllocInfo_r9.buf[0] & MBSFN_FDD_SF3) == MBSFN_FDD_SF3) ) + mcch_flag = 1; + mtch_flag = 1; + } + } + break; + + case 4: + if (mac_xface->lte_frame_parms->frame_type == TDD){ + if ((eNB_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.choice.oneFrame.buf[0] & MBSFN_TDD_SF4) == MBSFN_TDD_SF4) { + if (msi_pos == 2) + msi_flag = 1; + if ( (frameP % mcch_period == eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.mcch_Offset_r9) && + ((eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.sf_AllocInfo_r9.buf[0] & MBSFN_TDD_SF4) == MBSFN_TDD_SF4) ) + mcch_flag = 1; + mtch_flag = 1; + } + } + break; + + case 6: + if (mac_xface->lte_frame_parms->frame_type == FDD){ + if ((eNB_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.choice.oneFrame.buf[0] & MBSFN_FDD_SF6) == MBSFN_FDD_SF6) { + if (msi_pos == 4) + msi_flag = 1; + if ( (frameP % mcch_period == eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.mcch_Offset_r9) && + ((eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.sf_AllocInfo_r9.buf[0] & MBSFN_FDD_SF6) == MBSFN_FDD_SF6) ) + mcch_flag = 1; + mtch_flag = 1; + } + } + break; + + case 7: + if (mac_xface->lte_frame_parms->frame_type == TDD){ // TDD + if ((eNB_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.choice.oneFrame.buf[0] & MBSFN_TDD_SF7) == MBSFN_TDD_SF7) { + if (msi_pos == 3) + msi_flag = 1; + if ( (frameP % mcch_period == eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.mcch_Offset_r9) && + ((eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.sf_AllocInfo_r9.buf[0] & MBSFN_TDD_SF7) == MBSFN_TDD_SF7) ) + mcch_flag = 1; + mtch_flag = 1; + } + } + else {// FDD + if ((eNB_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.choice.oneFrame.buf[0] & MBSFN_FDD_SF7) == MBSFN_FDD_SF7) { + if (msi_pos == 5) + msi_flag = 1; + if ( (frameP % mcch_period == eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.mcch_Offset_r9) && + ((eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.sf_AllocInfo_r9.buf[0] & MBSFN_FDD_SF7) == MBSFN_FDD_SF7) ) + mcch_flag = 1; + mtch_flag = 1; + } + } + break; + + case 8: + if (mac_xface->lte_frame_parms->frame_type == TDD){ //TDD + if ((eNB_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.choice.oneFrame.buf[0] & MBSFN_TDD_SF8) == MBSFN_TDD_SF8) { + if (msi_pos == 4) + msi_flag = 1; + if ( (frameP % mcch_period == eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.mcch_Offset_r9) && + ((eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.sf_AllocInfo_r9.buf[0] & MBSFN_TDD_SF8) == MBSFN_TDD_SF8) ) + mcch_flag = 1; + mtch_flag = 1; + } + } + else{ // FDD + if ((eNB_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.choice.oneFrame.buf[0] & MBSFN_FDD_SF8) == MBSFN_FDD_SF8) { + if (msi_pos == 6) + msi_flag = 1; + if ( (frameP % mcch_period == eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.mcch_Offset_r9) && + ((eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.sf_AllocInfo_r9.buf[0] & MBSFN_FDD_SF8) == MBSFN_FDD_SF8) ) + mcch_flag = 1; + mtch_flag = 1; + } + } + break; + + case 9: + if (mac_xface->lte_frame_parms->frame_type == TDD){ + if ((eNB_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.choice.oneFrame.buf[0] & MBSFN_TDD_SF9) == MBSFN_TDD_SF9) { + if (msi_pos == 5) + msi_flag = 1; + if ( (frameP % mcch_period == eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.mcch_Offset_r9) && + ((eNB_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.sf_AllocInfo_r9.buf[0] & MBSFN_TDD_SF9) == MBSFN_TDD_SF9) ) + mcch_flag = 1; + mtch_flag = 1; + } + } + break; + }// end switch + // sf allocation is non-overlapping + if ((msi_flag==1) || (mcch_flag==1) || (mtch_flag==1)){ + LOG_D(MAC,"[eNB %d] Frame %d Subframe %d: sync area %d SF alloc %d: msi flag %d, mcch flag %d, mtch flag %d\n", + module_idP, frameP, subframeP,i,j,msi_flag,mcch_flag,mtch_flag); + break; + } + } + else {// four-frameP format + } + } + } // end of for loop + eNB_mac_inst[module_idP].msi_active=0; + eNB_mac_inst[module_idP].mcch_active=0; + eNB_mac_inst[module_idP].mtch_active=0; + // Calculate the mcs + if ((msi_flag==1) || (mcch_flag==1)) { + eNB_mac_inst[module_idP].MCH_pdu.mcs = mcch_mcs; + } + else if (mtch_flag == 1) { // only MTCH in this subframeP + eNB_mac_inst[module_idP].MCH_pdu.mcs = eNB_mac_inst[module_idP].pmch_Config[0]->dataMCS_r9; + } + + + // 2nd: Create MSI, get MCCH from RRC and MTCHs from RLC + + // there is MSI (MCH Scheduling Info) + if (msi_flag == 1) { + // Create MSI here + uint16_t msi_control_element[29], *msi_ptr; + + msi_ptr = &msi_control_element[0]; + ((MSI_ELEMENT *) msi_ptr)->lcid = MCCH_LCHANID; //MCCH + if (mcch_flag==1) { + ((MSI_ELEMENT *) msi_ptr)->stop_sf_MSB = 0; + ((MSI_ELEMENT *) msi_ptr)->stop_sf_LSB = 0; + } + else { // no mcch for this MSP + ((MSI_ELEMENT *) msi_ptr)->stop_sf_MSB = 0x7;// stop value is 2047 + ((MSI_ELEMENT *) msi_ptr)->stop_sf_LSB = 0xff; + } + msi_ptr+= sizeof(MSI_ELEMENT); + + //Header for MTCHs + num_mtch = eNB_mac_inst[module_idP].mbms_SessionList[0]->list.count; + for (k=0;k<num_mtch;k++) { // loop for all session in this MCH (MCH[0]) at this moment + ((MSI_ELEMENT *) msi_ptr)->lcid = eNB_mac_inst[module_idP].mbms_SessionList[0]->list.array[k]->logicalChannelIdentity_r9;//mtch_lcid; + ((MSI_ELEMENT *) msi_ptr)->stop_sf_MSB = 0; // last subframeP of this mtch (only one mtch now) + ((MSI_ELEMENT *) msi_ptr)->stop_sf_LSB = 0xB; + msi_ptr+=sizeof(MSI_ELEMENT); + } + msi_length = msi_ptr-msi_control_element; + if (msi_length<128) + header_len_msi = 2; + else + header_len_msi = 3; + + LOG_D(MAC,"[eNB %d] Frame %d : MSI->MCH, length of MSI is %d bytes \n",module_idP,frameP,msi_length); + //LOG_D(MAC,"Scheduler: MSI is transmitted in this subframeP \n" ); + + // LOG_D(MAC,"Scheduler: MSI length is %d bytes\n",msi_length); + // Store MSI data to mch_buffer[0] + memcpy((char *)&mch_buffer[sdu_length_total], + msi_control_element, + msi_length); + + sdu_lcids[num_sdus] = MCH_SCHDL_INFO; + sdu_lengths[num_sdus] = msi_length; + sdu_length_total += sdu_lengths[num_sdus]; + LOG_I(MAC,"[eNB %d] Create %d bytes for MSI\n",module_idP,sdu_lengths[num_sdus]); + num_sdus++; + eNB_mac_inst[module_idP].msi_active=1; + } + + // there is MCCH + if (mcch_flag == 1) { + LOG_D(MAC,"[eNB %d] Frame %d Subframe %d: Schedule MCCH MESSAGE (area %d, sfAlloc %d)\n", + module_idP,frameP, subframeP, i, j); + + mcch_sdu_length = mac_rrc_data_req(module_idP, + frameP, + MCCH,1, + &eNB_mac_inst[module_idP].MCCH_pdu.payload[0], + 1,// this is eNB + module_idP, // index + i); // this is the mbsfn sync area index + + if (mcch_sdu_length > 0) { + LOG_D(MAC,"[eNB %d] Frame %d subframeP %d : MCCH->MCH, Received %d bytes from RRC \n",module_idP,frameP,subframeP,mcch_sdu_length); + + header_len_mcch = 2; + if (mac_xface->lte_frame_parms->frame_type == TDD) { + LOG_D(MAC,"[eNB %d] Frame %d subframeP %d: Scheduling MCCH->MCH (TDD) for MCCH message %d bytes (mcs %d )\n", + module_idP, + frameP,subframeP, + mcch_sdu_length, + mcch_mcs); + } + else { + LOG_I(MAC,"[eNB %d] Frame %d subframeP %d: Scheduling MCCH->MCH (FDD) for MCCH message %d bytes (mcs %d)\n", + module_idP, + frameP, subframeP, + mcch_sdu_length, + mcch_mcs); + } + eNB_mac_inst[module_idP].mcch_active=1; + + memcpy((char *)&mch_buffer[sdu_length_total], + &eNB_mac_inst[module_idP].MCCH_pdu.payload[0], + mcch_sdu_length); + sdu_lcids[num_sdus] = MCCH_LCHANID; + sdu_lengths[num_sdus] = mcch_sdu_length; + if (sdu_lengths[num_sdus]>128) + header_len_mcch = 3; + sdu_length_total += sdu_lengths[num_sdus]; + LOG_D(MAC,"[eNB %d] Got %d bytes for MCCH from RRC \n",module_idP,sdu_lengths[num_sdus]); + num_sdus++; + } + } + TBS = mac_xface->get_TBS_DL(eNB_mac_inst[module_idP].MCH_pdu.mcs, mac_xface->lte_frame_parms->N_RB_DL); +#ifdef Rel10 + // do not let mcch and mtch multiplexing when relaying is active + // for sync area 1, so not transmit data + //if ((i == 0) && ((eNB_mac_inst[module_idP].MBMS_flag != multicast_relay) || (eNB_mac_inst[module_idP].mcch_active==0))) { +#endif + // there is MTCHs, loop if there are more than 1 + if (mtch_flag == 1) { + // Calculate TBS + /* if ((msi_flag==1) || (mcch_flag==1)) { + TBS = mac_xface->get_TBS(mcch_mcs, mac_xface->lte_frame_parms->N_RB_DL); + } + else { // only MTCH in this subframeP + TBS = mac_xface->get_TBS(eNB_mac_inst[module_idP].pmch_Config[0]->dataMCS_r9, mac_xface->lte_frame_parms->N_RB_DL); + } + + // get MTCH data from RLC (like for DTCH) + LOG_D(MAC,"[eNB %d] Frame %d subframe %d: Schedule MTCH (area %d, sfAlloc %d)\n",Mod_id,frame,subframe,i,j); + + header_len_mtch = 3; + LOG_D(MAC,"[eNB %d], Frame %d, MTCH->MCH, Checking RLC status (rab %d, tbs %d, len %d)\n", + Mod_id,frame,MTCH,TBS, + TBS-header_len_mcch-header_len_msi-sdu_length_total-header_len_mtch); + + rlc_status = mac_rlc_status_ind(Mod_id,frame,1,RLC_MBMS_YES,MTCH+ (maxDRB + 3) * MAX_MOBILES_PER_RG, + TBS-header_len_mcch-header_len_msi-sdu_length_total-header_len_mtch); + printf("frame %d, subframe %d, rlc_status.bytes_in_buffer is %d\n",frame,subframe, rlc_status.bytes_in_buffer); + + */ + + // get MTCH data from RLC (like for DTCH) + LOG_D(MAC,"[eNB %d] Frame %d subframeP %d: Schedule MTCH (area %d, sfAlloc %d)\n",module_idP,frameP,subframeP,i,j); + + header_len_mtch = 3; + LOG_D(MAC,"[eNB %d], Frame %d, MTCH->MCH, Checking RLC status (rab %d, tbs %d, len %d)\n", + module_idP,frameP,MTCH,TBS, + TBS-header_len_mcch-header_len_msi-sdu_length_total-header_len_mtch); + + rlc_status = mac_rlc_status_ind(module_idP,0,frameP,ENB_FLAG_YES,MBMS_FLAG_YES,MTCH, + TBS-header_len_mcch-header_len_msi-sdu_length_total-header_len_mtch); + LOG_D(MAC,"e-MBMS log channel %u frameP %d, subframeP %d, rlc_status.bytes_in_buffer is %d\n", + MTCH,frameP,subframeP, rlc_status.bytes_in_buffer); + + if (rlc_status.bytes_in_buffer >0) { + LOG_I(MAC,"[eNB %d][MBMS USER-PLANE], Frame %d, MTCH->MCH, Requesting %d bytes from RLC (header len mtch %d)\n", + module_idP,frameP,TBS-header_len_mcch-header_len_msi-sdu_length_total-header_len_mtch,header_len_mtch); + + sdu_lengths[num_sdus] = mac_rlc_data_req( + module_idP, + 0, + frameP, + ENB_FLAG_YES, + MBMS_FLAG_YES, + MTCH, + (char*)&mch_buffer[sdu_length_total]); + //sdu_lengths[num_sdus] = mac_rlc_data_req(module_idP,frameP, MBMS_FLAG_NO, MTCH+(MAX_NUM_RB*(NUMBER_OF_UE_MAX+1)), (char*)&mch_buffer[sdu_length_total]); + LOG_I(MAC,"[eNB %d][MBMS USER-PLANE] Got %d bytes for MTCH %d\n",module_idP,sdu_lengths[num_sdus],MTCH); + eNB_mac_inst[module_idP].mtch_active=1; + sdu_lcids[num_sdus] = MTCH; + sdu_length_total += sdu_lengths[num_sdus]; + if (sdu_lengths[num_sdus] < 128) + header_len_mtch = 2; + num_sdus++; + } + else { + header_len_mtch = 0; + } + } +#ifdef Rel10 + // } +#endif + // FINAL STEP: Prepare and multiplexe MSI, MCCH and MTCHs + if ((sdu_length_total + header_len_msi + header_len_mcch + header_len_mtch) >0) { + // Adjust the last subheader + /* if ((msi_flag==1) || (mcch_flag==1)) { + eNB_mac_inst[module_idP].MCH_pdu.mcs = mcch_mcs; + } + else if (mtch_flag == 1) { // only MTCH in this subframeP + eNB_mac_inst[module_idP].MCH_pdu.mcs = eNB_mac_inst[module_idP].pmch_Config[0]->dataMCS_r9; + } + */ + header_len_mtch_temp = header_len_mtch; + header_len_mcch_temp = header_len_mcch; + header_len_msi_temp = header_len_msi; + if (header_len_mtch>0) + header_len_mtch=1; // remove Length field in the subheader for the last PDU + else if (header_len_mcch>0) + header_len_mcch=1; + else header_len_msi=1; + // Calculate the padding + if ((TBS - header_len_mtch - header_len_mcch - header_len_msi - sdu_length_total) < 0) { + LOG_E(MAC,"Error in building MAC PDU, TBS %d < PDU %d \n", + TBS, header_len_mtch + header_len_mcch + header_len_msi + sdu_length_total); + return; + }else if ((TBS - header_len_mtch - header_len_mcch - header_len_msi - sdu_length_total) <= 2) { + padding = (TBS - header_len_mtch - header_len_mcch - header_len_msi - sdu_length_total); + post_padding = 0; + } + else {// using post_padding, give back the Length field of subheader for the last PDU + padding = 0; + if (header_len_mtch>0) + header_len_mtch = header_len_mtch_temp; + else if (header_len_mcch>0) + header_len_mcch = header_len_mcch_temp; + else header_len_msi = header_len_msi_temp; + post_padding = TBS - sdu_length_total - header_len_msi - header_len_mcch - header_len_mtch; + } + // Generate the MAC Header for MCH + // here we use the function for DLSCH because DLSCH & MCH have the same Header structure + offset = generate_dlsch_header((unsigned char*)eNB_mac_inst[module_idP].MCH_pdu.payload, + num_sdus, + sdu_lengths, + sdu_lcids, + 255, // no drx + 0, // no timing advance + NULL, // no contention res id + padding, + post_padding); + + eNB_mac_inst[module_idP].MCH_pdu.Pdu_size=TBS; + eNB_mac_inst[module_idP].MCH_pdu.sync_area=i; + eNB_mac_inst[module_idP].MCH_pdu.msi_active= eNB_mac_inst[module_idP].msi_active; + eNB_mac_inst[module_idP].MCH_pdu.mcch_active= eNB_mac_inst[module_idP].mcch_active; + eNB_mac_inst[module_idP].MCH_pdu.mtch_active= eNB_mac_inst[module_idP].mtch_active; + LOG_D(MAC," MCS for this sf is %d (mcch active %d, mtch active %d)\n", eNB_mac_inst[module_idP].MCH_pdu.mcs, + eNB_mac_inst[module_idP].MCH_pdu.mcch_active,eNB_mac_inst[module_idP].MCH_pdu.mtch_active ); + LOG_I(MAC,"[eNB %d][MBMS USER-PLANE ] Generate header : sdu_length_total %d, num_sdus %d, sdu_lengths[0] %d, sdu_lcids[0] %d => payload offset %d,padding %d,post_padding %d (mcs %d, TBS %d), header MTCH %d, header MCCH %d, header MSI %d\n", + module_idP,sdu_length_total,num_sdus,sdu_lengths[0],sdu_lcids[0],offset,padding,post_padding,eNB_mac_inst[module_idP].MCH_pdu.mcs,TBS,header_len_mtch, header_len_mcch, header_len_msi); + // copy SDU to mch_pdu after the MAC Header + memcpy(&eNB_mac_inst[module_idP].MCH_pdu.payload[offset],mch_buffer,sdu_length_total); + // filling remainder of MCH with random data if necessery + for (j=0;j<(TBS-sdu_length_total-offset);j++) + eNB_mac_inst[module_idP].MCH_pdu.payload[offset+sdu_length_total+j] = (char)(taus()&0xff); + +#if defined(USER_MODE) && defined(OAI_EMU) + /* Tracing of PDU is done on UE side */ + if (oai_emulation.info.opt_enabled) + trace_pdu(1, (uint8_t *)eNB_mac_inst[module_idP].MCH_pdu.payload, + TBS, module_idP, 6, 0xffff, // M_RNTI = 6 in wirehsark + eNB_mac_inst[module_idP].subframe,0,0); + LOG_D(OPT,"[eNB %d][MCH] Frame %d : MAC PDU with size %d\n", + module_idP, frameP, TBS); +#endif + /* + for (j=0;j<sdu_length_total;j++) + printf("%2x.",eNB_mac_inst[module_idP].MCH_pdu.payload[j+offset]); + printf(" \n");*/ + return 1; + } + else { + eNB_mac_inst[module_idP].MCH_pdu.Pdu_size=0; + eNB_mac_inst[module_idP].MCH_pdu.sync_area=0; + eNB_mac_inst[module_idP].MCH_pdu.msi_active=0; + eNB_mac_inst[module_idP].MCH_pdu.mcch_active=0; + eNB_mac_inst[module_idP].MCH_pdu.mtch_active=0; + // for testing purpose, fill with random data + //for (j=0;j<(TBS-sdu_length_total-offset);j++) + // eNB_mac_inst[module_idP].MCH_pdu.payload[offset+sdu_length_total+j] = (char)(taus()&0xff); + return 0; + } + //this is for testing + /* + if (mtch_flag == 1) { + // LOG_D(MAC,"DUY: mch_buffer length so far is : %ld\n", &mch_buffer[sdu_length_total]-&mch_buffer[0]); + return 1; + } + else + return 0; + */ +} +MCH_PDU *get_mch_sdu(uint8_t module_idP,uint32_t frameP, sub_frame_t subframeP) { + // eNB_mac_inst[module_idP].MCH_pdu.mcs=0; + //LOG_D(MAC," MCH_pdu.mcs is %d\n", eNB_mac_inst[module_idP].MCH_pdu.mcs); + return(&eNB_mac_inst[module_idP].MCH_pdu); +} + +#endif diff --git a/openair2/LAYER2/MAC/eNB_scheduler_primitives.c b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c new file mode 100644 index 0000000000..e4b62a8d11 --- /dev/null +++ b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c @@ -0,0 +1,503 @@ +/******************************************************************************* + + Eurecom OpenAirInterface + Copyright(c) 1999 - 2010 Eurecom + + This program is free software; you can redistribute it and/or modify it + under the terms and conditions of the GNU General Public License, + version 2, as published by the Free Software Foundation. + + This program is distributed in the hope it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along with + this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + + The full GNU General Public License is included in this distribution in + the file called "COPYING". + + Contact Information + Openair Admin: openair_admin@eurecom.fr + Openair Tech : openair_tech@eurecom.fr + Forums : http://forums.eurecom.fsr/openairinterface + Address : Eurecom, 2229, route des crêtes, 06560 Valbonne Sophia Antipolis, France + + *******************************************************************************/ +/*! \file eNB_scheduler.c + * \brief procedures related to UE + * \author Navid Nikaein and Raymond Knopp + * \date 2010 - 2014 + * \email: navid.nikaein@eurecom.fr + * \version 0.5 + * @ingroup _mac + + */ + +#include "assertions.h" +#include "PHY/defs.h" +#include "PHY/extern.h" + +#include "SCHED/defs.h" +#include "SCHED/extern.h" + +#include "LAYER2/MAC/defs.h" +#include "LAYER2/MAC/extern.h" + +#include "LAYER2/MAC/proto.h" +#include "UTIL/LOG/log.h" +#include "UTIL/LOG/vcd_signal_dumper.h" +#include "UTIL/OPT/opt.h" +#include "OCG.h" +#include "OCG_extern.h" +#include "ARCH/CBMIMO1/DEVICE_DRIVER/extern.h" +#include "ARCH/CBMIMO1/DEVICE_DRIVER/defs.h" +#include "ARCH/CBMIMO1/DEVICE_DRIVER/from_grlib_softregs.h" + +#include "RRC/LITE/extern.h" +#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h" + +//#include "LAYER2/MAC/pre_processor.c" +#include "pdcp.h" + +#if defined(ENABLE_ITTI) +# include "intertask_interface.h" +#endif + +#define ENABLE_MAC_PAYLOAD_DEBUG +#define DEBUG_eNB_SCHEDULER 1 + + +void init_ue_sched_info(void){ + module_id_t i,j; + for (i=0;i<NUMBER_OF_eNB_MAX;i++){ + for (j=0;j<NUMBER_OF_UE_MAX;j++){ + // init DL + eNB_dlsch_info[i][j].weight = 0; + eNB_dlsch_info[i][j].subframe = 0; + eNB_dlsch_info[i][j].serving_num = 0; + eNB_dlsch_info[i][j].status = S_DL_NONE; + // init UL + eNB_ulsch_info[i][j].subframe = 0; + eNB_ulsch_info[i][j].serving_num = 0; + eNB_ulsch_info[i][j].status = S_UL_NONE; + } + } +} + + + +unsigned char get_ue_weight(module_id_t module_idP, module_id_t ue_mod_idP){ + + return(eNB_dlsch_info[module_idP][ue_mod_idP].weight); + +} + +DCI_PDU *get_dci_sdu(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP) { + + return(&eNB_mac_inst[module_idP].DCI_pdu); + +} + +module_id_t find_UE_id(module_id_t module_idP, rnti_t rnti) { + + module_id_t ue_mod_id; + + for (ue_mod_id=0;ue_mod_id<NUMBER_OF_UE_MAX;ue_mod_id++) { + // if (mac_get_rrc_status(module_idP,1,ue_mod_id) >= RRC_CONNECTED) { + if (eNB_mac_inst[module_idP].UE_template[ue_mod_id].rnti==rnti) { + return(ue_mod_id); + } + } + return(module_id_t)(-1); + +} + + + +rnti_t find_UE_RNTI(module_id_t module_idP, module_id_t ue_mod_idP) { + + return (eNB_mac_inst[module_idP].UE_template[ue_mod_idP].rnti); + +} +boolean_t is_UE_active(module_id_t module_idP, module_id_t ue_mod_idP ){ + if (eNB_mac_inst[module_idP].UE_template[ue_mod_idP].rnti !=0 ) + return TRUE; + else + return FALSE ; +} +uint8_t find_active_UEs(module_id_t module_idP){ + + module_id_t ue_mod_id = 0; + rnti_t rnti = 0; + uint8_t nb_active_ue = 0; + + for (ue_mod_id=0;ue_mod_id<NUMBER_OF_UE_MAX;ue_mod_id++) { + + if (((rnti=eNB_mac_inst[module_idP].UE_template[ue_mod_id].rnti) !=0)&&(eNB_mac_inst[module_idP].UE_template[ue_mod_id].ul_active==TRUE)){ + + if (mac_xface->get_eNB_UE_stats(module_idP,rnti) != NULL){ // check at the phy enb_ue state for this rnti + nb_active_ue++; + } + else { // this ue is removed at the phy => remove it at the mac as well + mac_remove_ue(module_idP, ue_mod_id); + } + } + } + return(nb_active_ue); +} + + + +// get aggregatiob form phy for a give UE +unsigned char process_ue_cqi (module_id_t module_idP, module_id_t ue_mod_idP) { + unsigned char aggregation=2; + // check the MCS and SNR and set the aggregation accordingly + return aggregation; +} +#ifdef CBA +uint8_t find_num_active_UEs_in_cbagroup(module_id_t module_idP, unsigned char group_id){ + + module_id_t UE_id; + rnti_t rnti; + unsigned char nb_ue_in_pusch=0; + LTE_eNB_UE_stats* eNB_UE_stats; + + for (UE_id=group_id;UE_id<NUMBER_OF_UE_MAX;UE_id+=eNB_mac_inst[module_idP].num_active_cba_groups) { + + if (((rnti=eNB_mac_inst[module_idP].UE_template[UE_id].rnti) !=0) && + (eNB_mac_inst[module_idP].UE_template[UE_id].ul_active==TRUE) && + (mac_get_rrc_status(module_idP,1,UE_id) > RRC_CONNECTED)){ + // && (UE_is_to_be_scheduled(module_idP,UE_id))) + // check at the phy enb_ue state for this rnti + if ((eNB_UE_stats= mac_xface->get_eNB_UE_stats(module_idP,rnti)) != NULL){ + if ((eNB_UE_stats->mode == PUSCH) && (UE_is_to_be_scheduled(module_idP,UE_id) == 0)){ + nb_ue_in_pusch++; + } + } + } + } + return(nb_ue_in_pusch); +} +#endif +int8_t add_new_ue(module_id_t enb_mod_idP, rnti_t rntiP) { + module_id_t ue_mod_id; + int j; + + for (ue_mod_id=0;ue_mod_id<NUMBER_OF_UE_MAX;ue_mod_id++) { + if (eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].rnti == 0) { + eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].rnti = rntiP; + for (j=0;j<8;j++) { + eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].oldNDI[j] = 0; + eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].oldNDI_UL[j] = 0; + } + eNB_ulsch_info[enb_mod_idP][ue_mod_id].status = S_UL_WAITING; + eNB_dlsch_info[enb_mod_idP][ue_mod_id].status = S_UL_WAITING; + LOG_D(MAC,"[eNB] Add UE_id %d : rnti %x\n",ue_mod_id,eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].rnti); + return((int8_t)ue_mod_id); + } + } + return(-1); +} + +int8_t mac_remove_ue(module_id_t enb_mod_idP, module_id_t ue_mod_idP) { + + LOG_I(MAC,"Removing UE %d (rnti %x)\n",ue_mod_idP,eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_idP].rnti); + + // clear all remaining pending transmissions + eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_idP].bsr_info[LCGID0] = 0; + eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_idP].bsr_info[LCGID1] = 0; + eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_idP].bsr_info[LCGID2] = 0; + eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_idP].bsr_info[LCGID3] = 0; + + eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_idP].ul_SR = 0; + eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_idP].rnti = 0; + eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_idP].ul_active = FALSE; + eNB_ulsch_info[enb_mod_idP][ue_mod_idP].rnti = 0; + eNB_ulsch_info[enb_mod_idP][ue_mod_idP].status = S_UL_NONE; + eNB_dlsch_info[enb_mod_idP][ue_mod_idP].rnti = 0; + eNB_dlsch_info[enb_mod_idP][ue_mod_idP].status = S_DL_NONE; + + rrc_eNB_free_UE_index(enb_mod_idP,ue_mod_idP); + + return(1); +} + + + + +void SR_indication(module_id_t enb_mod_idP, frame_t frameP, rnti_t rntiP, sub_frame_t subframeP) { + + module_id_t ue_mod_id = find_UE_id(enb_mod_idP, rntiP); + + if (ue_mod_id != UE_INDEX_INVALID ) { + LOG_D(MAC,"[eNB %d][SR %x] Frame %d subframeP %d Signaling SR for UE %d \n",enb_mod_idP,rntiP,frameP,subframeP, ue_mod_id); + eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].ul_SR = 1; + eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].ul_active = TRUE; + } else { + // AssertFatal(0, "find_UE_id(%u,rnti %d) not found", enb_mod_idP, rntiP); + AssertError(0, 0, "Frame %d: find_UE_id(%u,rnti %d) not found\n", frameP, enb_mod_idP, rntiP); + } +} + + + + +/* + #ifdef Rel10 + unsigned char generate_mch_header( unsigned char *mac_header, + unsigned char num_sdus, + unsigned short *sdu_lengths, + unsigned char *sdu_lcids, + unsigned char msi, + unsigned char short_padding, + unsigned short post_padding) { + + SCH_SUBHEADER_FIXED *mac_header_ptr = (SCH_SUBHEADER_FIXED *)mac_header; + uint8_t first_element=0,last_size=0,i; + uint8_t mac_header_control_elements[2*num_sdus],*ce_ptr; + + ce_ptr = &mac_header_control_elements[0]; + + if ((short_padding == 1) || (short_padding == 2)) { + mac_header_ptr->R = 0; + mac_header_ptr->E = 0; + mac_header_ptr->LCID = SHORT_PADDING; + first_element=1; + last_size=1; + } + if (short_padding == 2) { + mac_header_ptr->E = 1; + mac_header_ptr++; + mac_header_ptr->R = 0; + mac_header_ptr->E = 0; + mac_header_ptr->LCID = SHORT_PADDING; + last_size=1; + } + + // SUBHEADER for MSI CE + if (msi != 0) {// there is MSI MAC Control Element + if (first_element>0) { + mac_header_ptr->E = 1; + mac_header_ptr+=last_size; + } + else { + first_element = 1; + } + if (num_sdus*2 < 128) { + ((SCH_SUBHEADER_SHORT *)mac_header_ptr)->R = 0; + ((SCH_SUBHEADER_SHORT *)mac_header_ptr)->E = 0; + ((SCH_SUBHEADER_SHORT *)mac_header_ptr)->F = 0; + ((SCH_SUBHEADER_SHORT *)mac_header_ptr)->LCID = MCH_SCHDL_INFO; + ((SCH_SUBHEADER_SHORT *)mac_header_ptr)->L = num_sdus*2; + last_size=2; + } + else { + ((SCH_SUBHEADER_LONG *)mac_header_ptr)->R = 0; + ((SCH_SUBHEADER_LONG *)mac_header_ptr)->E = 0; + ((SCH_SUBHEADER_LONG *)mac_header_ptr)->F = 1; + ((SCH_SUBHEADER_LONG *)mac_header_ptr)->LCID = MCH_SCHDL_INFO; + ((SCH_SUBHEADER_LONG *)mac_header_ptr)->L = (num_sdus*2)&0x7fff; + last_size=3; + } + // Create the MSI MAC Control Element here + } + + // SUBHEADER for MAC SDU (MCCH+MTCHs) + for (i=0;i<num_sdus;i++) { + if (first_element>0) { + mac_header_ptr->E = 1; + mac_header_ptr+=last_size; + } + else { + first_element = 1; + } + if (sdu_lengths[i] < 128) { + ((SCH_SUBHEADER_SHORT *)mac_header_ptr)->R = 0; + ((SCH_SUBHEADER_SHORT *)mac_header_ptr)->E = 0; + ((SCH_SUBHEADER_SHORT *)mac_header_ptr)->F = 0; + ((SCH_SUBHEADER_SHORT *)mac_header_ptr)->LCID = sdu_lcids[i]; + ((SCH_SUBHEADER_SHORT *)mac_header_ptr)->L = (unsigned char)sdu_lengths[i]; + last_size=2; + } + else { + ((SCH_SUBHEADER_LONG *)mac_header_ptr)->R = 0; + ((SCH_SUBHEADER_LONG *)mac_header_ptr)->E = 0; + ((SCH_SUBHEADER_LONG *)mac_header_ptr)->F = 1; + ((SCH_SUBHEADER_LONG *)mac_header_ptr)->LCID = sdu_lcids[i]; + ((SCH_SUBHEADER_LONG *)mac_header_ptr)->L = (unsigned short) sdu_lengths[i]&0x7fff; + last_size=3; + } + } + + if (post_padding>0) {// we have lots of padding at the end of the packet + mac_header_ptr->E = 1; + mac_header_ptr+=last_size; + // add a padding element + mac_header_ptr->R = 0; + mac_header_ptr->E = 0; + mac_header_ptr->LCID = SHORT_PADDING; + mac_header_ptr++; + } + else { // no end of packet padding + // last SDU subhead is of fixed type (sdu length implicitly to be computed at UE) + mac_header_ptr++; + } + + // Copy MSI Control Element to the end of the MAC Header if it presents + if ((ce_ptr-mac_header_control_elements) > 0) { + // printf("Copying %d bytes for control elements\n",ce_ptr-mac_header_control_elements); + memcpy((void*)mac_header_ptr,mac_header_control_elements,ce_ptr-mac_header_control_elements); + mac_header_ptr+=(unsigned char)(ce_ptr-mac_header_control_elements); + } + + return((unsigned char*)mac_header_ptr - mac_header); + } + #endif + */ +void add_common_dci(DCI_PDU *DCI_pdu, + void *pdu, + rnti_t rnti, + unsigned char dci_size_bytes, + unsigned char aggregation, + unsigned char dci_size_bits, + unsigned char dci_fmt, + uint8_t ra_flag) { + + memcpy(&DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci].dci_pdu[0],pdu,dci_size_bytes); + DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci].dci_length = dci_size_bits; + DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci].L = aggregation; + DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci].rnti = rnti; + DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci].format = dci_fmt; + DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci].ra_flag = ra_flag; + + + DCI_pdu->Num_common_dci++; + LOG_D(MAC,"add common dci format %d for rnti %d \n",dci_fmt,rnti); +} + +void add_ue_spec_dci(DCI_PDU *DCI_pdu,void *pdu,rnti_t rnti,unsigned char dci_size_bytes,unsigned char aggregation,unsigned char dci_size_bits,unsigned char dci_fmt,uint8_t ra_flag) { + + memcpy(&DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci+DCI_pdu->Num_ue_spec_dci].dci_pdu[0],pdu,dci_size_bytes); + DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci+DCI_pdu->Num_ue_spec_dci].dci_length = dci_size_bits; + DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci+DCI_pdu->Num_ue_spec_dci].L = aggregation; + DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci+DCI_pdu->Num_ue_spec_dci].rnti = rnti; + DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci+DCI_pdu->Num_ue_spec_dci].format = dci_fmt; + DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci+DCI_pdu->Num_ue_spec_dci].ra_flag = ra_flag; + + DCI_pdu->Num_ue_spec_dci++; +} + + + + + +// This has to be updated to include BSR information +uint8_t UE_is_to_be_scheduled(module_id_t module_idP,uint8_t UE_id) { + + + // LOG_D(MAC,"[eNB %d][PUSCH] Frame %d subframeP %d Scheduling UE %d\n",module_idP,rnti,frameP,subframeP, + // UE_id); + + if ((eNB_mac_inst[module_idP].UE_template[UE_id].bsr_info[LCGID0]>0) || + (eNB_mac_inst[module_idP].UE_template[UE_id].bsr_info[LCGID1]>0) || + (eNB_mac_inst[module_idP].UE_template[UE_id].bsr_info[LCGID2]>0) || + (eNB_mac_inst[module_idP].UE_template[UE_id].bsr_info[LCGID3]>0) || + (eNB_mac_inst[module_idP].UE_template[UE_id].ul_SR>0)) // uplink scheduling request + return(1); + else + return(0); +} + + + + +uint32_t allocate_prbs(module_id_t ue_mod_idP,unsigned char nb_rb, uint32_t *rballoc) { + + int i; + uint32_t rballoc_dci=0; + unsigned char nb_rb_alloc=0; + + for (i=0;i<(mac_xface->lte_frame_parms->N_RB_DL-2);i+=2) { + if (((*rballoc>>i)&3)==0) { + *rballoc |= (3<<i); + rballoc_dci |= (1<<((12-i)>>1)); + nb_rb_alloc+=2; + } + if (nb_rb_alloc==nb_rb) + return(rballoc_dci); + } + + if ((mac_xface->lte_frame_parms->N_RB_DL&1)==1) { + if ((*rballoc>>(mac_xface->lte_frame_parms->N_RB_DL-1)&1)==0) { + *rballoc |= (1<<(mac_xface->lte_frame_parms->N_RB_DL-1)); + rballoc_dci |= 1;//(1<<(mac_xface->lte_frame_parms->N_RB_DL>>1)); + } + } + return(rballoc_dci); +} + + +uint32_t allocate_prbs_sub(int nb_rb, uint8_t *rballoc) { + + int check=0;//check1=0,check2=0; + uint32_t rballoc_dci=0; + //uint8_t number_of_subbands=13; + + LOG_T(MAC,"*****Check1RBALLOC****: %d%d%d%d (nb_rb %d,N_RBGS %d)\n", + rballoc[3],rballoc[2],rballoc[1],rballoc[0],nb_rb,mac_xface->lte_frame_parms->N_RBGS); + while((nb_rb >0) && (check < mac_xface->lte_frame_parms->N_RBGS)){ + //printf("rballoc[%d] %d\n",check,rballoc[check]); + if(rballoc[check] == 1){ + rballoc_dci |= (1<<((mac_xface->lte_frame_parms->N_RBGS-1)-check)); + switch (mac_xface->lte_frame_parms->N_RB_DL) { + case 6: + nb_rb--; + case 25: + if ((check == mac_xface->lte_frame_parms->N_RBGS-1)) + nb_rb--; + else + nb_rb-=2; + break; + case 50: + if ((check == mac_xface->lte_frame_parms->N_RBGS-1)) + nb_rb-=2; + else + nb_rb-=3; + break; + case 100: + nb_rb-=4; + break; + } + } + //printf("rb_alloc %x\n",rballoc_dci); + check = check+1; + // check1 = check1+2; + } + // rballoc_dci = (rballoc_dci)&(0x1fff); + LOG_T(MAC,"*********RBALLOC : %x\n",rballoc_dci); + // exit(-1); + return (rballoc_dci); +} + + + + +void update_ul_dci(module_id_t module_idP,rnti_t rnti,uint8_t dai) { + + DCI_PDU *DCI_pdu = &eNB_mac_inst[module_idP].DCI_pdu; + int i; + DCI0_5MHz_TDD_1_6_t *ULSCH_dci = NULL;; + + if (mac_xface->lte_frame_parms->frame_type == TDD) { + for (i=0;i<DCI_pdu->Num_common_dci+DCI_pdu->Num_ue_spec_dci;i++) { + ULSCH_dci = (DCI0_5MHz_TDD_1_6_t *)DCI_pdu->dci_alloc[i].dci_pdu; + if ((DCI_pdu->dci_alloc[i].format == format0) && (DCI_pdu->dci_alloc[i].rnti == rnti)) + ULSCH_dci->dai = (dai-1)&3; + } + } + // printf("Update UL DCI: DAI %d\n",dai); +} + diff --git a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c new file mode 100644 index 0000000000..c502a9d545 --- /dev/null +++ b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c @@ -0,0 +1,861 @@ +/******************************************************************************* + + Eurecom OpenAirInterface + Copyright(c) 1999 - 2010 Eurecom + + This program is free software; you can redistribute it and/or modify it + under the terms and conditions of the GNU General Public License, + version 2, as published by the Free Software Foundation. + + This program is distributed in the hope it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along with + this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + + The full GNU General Public License is included in this distribution in + the file called "COPYING". + + Contact Information + Openair Admin: openair_admin@eurecom.fr + Openair Tech : openair_tech@eurecom.fr + Forums : http://forums.eurecom.fsr/openairinterface + Address : Eurecom, 2229, route des crêtes, 06560 Valbonne Sophia Antipolis, France + + *******************************************************************************/ +/*! \file eNB_scheduler.c + * \brief procedures related to UE on the ULSCH transport channel + * \author Navid Nikaein and Raymond Knopp + * \date 2010 - 2014 + * \email: navid.nikaein@eurecom.fr + * \version 0.5 + * @ingroup _mac + + */ + +#include "assertions.h" +#include "PHY/defs.h" +#include "PHY/extern.h" + +#include "SCHED/defs.h" +#include "SCHED/extern.h" + +#include "LAYER2/MAC/defs.h" +#include "LAYER2/MAC/proto.h" +#include "LAYER2/MAC/extern.h" +#include "UTIL/LOG/log.h" +#include "UTIL/LOG/vcd_signal_dumper.h" +#include "UTIL/OPT/opt.h" +#include "OCG.h" +#include "OCG_extern.h" +#include "ARCH/CBMIMO1/DEVICE_DRIVER/extern.h" +#include "ARCH/CBMIMO1/DEVICE_DRIVER/defs.h" +#include "ARCH/CBMIMO1/DEVICE_DRIVER/from_grlib_softregs.h" + +#include "RRC/LITE/extern.h" +#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h" + +//#include "LAYER2/MAC/pre_processor.c" +#include "pdcp.h" + +#if defined(ENABLE_ITTI) +# include "intertask_interface.h" +#endif + +#define ENABLE_MAC_PAYLOAD_DEBUG +#define DEBUG_eNB_SCHEDULER 1 + + +// This table holds the allowable PRB sizes for ULSCH transmissions +uint8_t rb_table[33] = {1,2,3,4,5,6,8,9,10,12,15,16,18,20,24,25,27,30,32,36,40,45,48,50,54,60,72,75,80,81,90,96,100}; + +uint32_t bytes_to_bsr_index(int32_t nbytes) { + + uint32_t i=0; + + if (nbytes<0) + return(0); + + while ((i<BSR_TABLE_SIZE)&& + (BSR_TABLE[i]<=nbytes)){ + i++; + } + return(i-1); +} + + +void add_ue_ulsch_info(module_id_t module_idP, module_id_t ue_mod_idP, sub_frame_t subframeP, UE_ULSCH_STATUS status){ + + eNB_ulsch_info[module_idP][ue_mod_idP].rnti = find_UE_RNTI(module_idP,ue_mod_idP); + eNB_ulsch_info[module_idP][ue_mod_idP].subframe = subframeP; + eNB_ulsch_info[module_idP][ue_mod_idP].status = status; + + eNB_ulsch_info[module_idP][ue_mod_idP].serving_num++; + +} + +module_id_t schedule_next_ulue(module_id_t module_idP, module_id_t ue_mod_idP, sub_frame_t subframeP){ + + module_id_t next_ue; + + // first phase: scheduling for ACK + switch (subframeP) { + // scheduling for subframeP 2: for scheduled user during subframeP 5 and 6 + case 8: + if ((eNB_dlsch_info[module_idP][ue_mod_idP].status == S_DL_SCHEDULED) && + (eNB_dlsch_info[module_idP][ue_mod_idP].subframe == 5 || eNB_dlsch_info[module_idP][ue_mod_idP].subframe == 6)){ + // set the downlink status + eNB_dlsch_info[module_idP][ue_mod_idP].status = S_DL_BUFFERED; + return ue_mod_idP; + } + break; + // scheduling for subframeP 3: for scheduled user during subframeP 7 and 8 + case 9: + if ((eNB_dlsch_info[module_idP][ue_mod_idP].status == S_DL_SCHEDULED) && + (eNB_dlsch_info[module_idP][ue_mod_idP].subframe == 7 || eNB_dlsch_info[module_idP][ue_mod_idP].subframe == 8)){ + eNB_dlsch_info[module_idP][ue_mod_idP].status = S_DL_BUFFERED; + return ue_mod_idP; + } + break; + // scheduling UL subframeP 4: for scheduled user during subframeP 9 and 0 + case 0 : + if ((eNB_dlsch_info[module_idP][ue_mod_idP].status == S_DL_SCHEDULED) && + (eNB_dlsch_info[module_idP][ue_mod_idP].subframe == 9 || eNB_dlsch_info[module_idP][ue_mod_idP].subframe == 0)){ + eNB_dlsch_info[module_idP][ue_mod_idP].status = S_DL_BUFFERED; + return ue_mod_idP; + } + break; + default: + break; + } + + // second phase + for (next_ue=0; next_ue <NUMBER_OF_UE_MAX; next_ue++ ){ + + if (eNB_ulsch_info[module_idP][next_ue].status == S_UL_WAITING ) + return next_ue; + else if (eNB_ulsch_info[module_idP][next_ue].status == S_UL_SCHEDULED){ + eNB_ulsch_info[module_idP][next_ue].status = S_UL_BUFFERED; + } + } + for (next_ue=0; next_ue <NUMBER_OF_UE_MAX; next_ue++ ){ + if (eNB_ulsch_info[module_idP][next_ue].status != S_UL_NONE )// do this just for active UEs + eNB_ulsch_info[module_idP][next_ue].status = S_UL_WAITING; + } + next_ue = 0; + return next_ue; + +} + + + + + + +unsigned char *parse_ulsch_header(unsigned char *mac_header, + unsigned char *num_ce, + unsigned char *num_sdu, + unsigned char *rx_ces, + unsigned char *rx_lcids, + unsigned short *rx_lengths, + unsigned short tb_length) { + + unsigned char not_done=1,num_ces=0,num_sdus=0,lcid,num_sdu_cnt; + unsigned char *mac_header_ptr = mac_header; + unsigned short length, ce_len=0; + + while (not_done==1) { + + if (((SCH_SUBHEADER_FIXED *)mac_header_ptr)->E == 0) + not_done = 0; + + lcid = ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->LCID; + if (lcid < EXTENDED_POWER_HEADROOM) { + if (not_done==0) { // last MAC SDU, length is implicit + mac_header_ptr++; + length = tb_length-(mac_header_ptr-mac_header)-ce_len; + for (num_sdu_cnt=0; num_sdu_cnt < num_sdus ; num_sdu_cnt++) + length -= rx_lengths[num_sdu_cnt]; + } + else { + if (((SCH_SUBHEADER_SHORT *)mac_header_ptr)->F == 0) { + length = ((SCH_SUBHEADER_SHORT *)mac_header_ptr)->L; + mac_header_ptr += 2;//sizeof(SCH_SUBHEADER_SHORT); + } + else { // F = 1 + length = ((((SCH_SUBHEADER_LONG *)mac_header_ptr)->L_MSB & 0x7f ) << 8 ) | (((SCH_SUBHEADER_LONG *)mac_header_ptr)->L_LSB & 0xff); + mac_header_ptr += 3;//sizeof(SCH_SUBHEADER_LONG); + } + } + LOG_D(MAC,"[eNB] sdu %d lcid %d tb_length %d length %d (offset now %d)\n", + num_sdus,lcid,tb_length, length,mac_header_ptr-mac_header); + rx_lcids[num_sdus] = lcid; + rx_lengths[num_sdus] = length; + num_sdus++; + } + else { // This is a control element subheader POWER_HEADROOM, BSR and CRNTI + if (lcid == SHORT_PADDING) { + mac_header_ptr++; + } + else { + rx_ces[num_ces] = lcid; + num_ces++; + mac_header_ptr++; + if (lcid==LONG_BSR) + ce_len+=3; + else if (lcid==CRNTI) + ce_len+=2; + else if ((lcid==POWER_HEADROOM) || (lcid==TRUNCATED_BSR)|| (lcid== SHORT_BSR)) + ce_len++; + else { + LOG_E(MAC,"unknown CE %d \n", lcid); + exit(-1); + } + } + } + } + *num_ce = num_ces; + *num_sdu = num_sdus; + + return(mac_header_ptr); +} + + +void schedule_ulsch(module_id_t module_idP, frame_t frameP,unsigned char cooperation_flag,sub_frame_t subframeP, unsigned char sched_subframe,unsigned int *nCCE) {//,int calibration_flag) { + + start_meas(&eNB_mac_inst[module_idP].schedule_ulsch); + uint8_t granted_UEs; + unsigned int nCCE_available; + uint16_t first_rb=1,i; + + granted_UEs = find_ulgranted_UEs(module_idP); + nCCE_available = mac_xface->get_nCCE_max(module_idP) - *nCCE; + + // UE data info; + // check which UE has data to transmit + // function to decide the scheduling + // e.g. scheduling_rslt = Greedy(granted_UEs, nb_RB) + + // default function for default scheduling + // + + // output of scheduling, the UE numbers in RBs, where it is in the code??? + // check if RA (Msg3) is active in this subframeP, if so skip the PRBs used for Msg3 + // Msg3 is using 1 PRB so we need to increase first_rb accordingly + // not sure about the break (can there be more than 1 active RA procedure?) + + for (i=0;i<NB_RA_PROC_MAX;i++) { + if ((eNB_mac_inst[module_idP].RA_template[i].RA_active == TRUE) && + (eNB_mac_inst[module_idP].RA_template[i].generate_rar == 0) && + (eNB_mac_inst[module_idP].RA_template[i].Msg3_subframe == sched_subframe)) { + first_rb++; + break; + } + } + + schedule_ulsch_rnti(module_idP, cooperation_flag, frameP, subframeP, sched_subframe, granted_UEs, nCCE, &nCCE_available, &first_rb); + +#ifdef CBA + if ((eNB_mac_inst[module_idP].num_active_cba_groups > 0) && (*nCCE == 0)) + schedule_ulsch_cba_rnti(module_idP, cooperation_flag, frameP, subframeP, sched_subframe, granted_UEs, nCCE, &nCCE_available, &first_rb); +#endif + stop_meas(&eNB_mac_inst[module_idP].schedule_ulsch); + +} + + + +void schedule_ulsch_rnti(module_id_t module_idP, + unsigned char cooperation_flag, + frame_t frameP, + sub_frame_t subframeP, + unsigned char sched_subframe, + uint8_t granted_UEs, + unsigned int *nCCE, + unsigned int *nCCE_available, + uint16_t *first_rb){ + module_id_t ue_mod_id = -1; + module_id_t next_ue = -1; + unsigned char aggregation = 2; + rnti_t rnti = -1; + uint8_t round = 0; + uint8_t harq_pid = 0; + void *ULSCH_dci = NULL; + LTE_eNB_UE_stats *eNB_UE_stats = NULL; + DCI_PDU *DCI_pdu = &eNB_mac_inst[module_idP].DCI_pdu; + uint8_t status = 0; + uint8_t rb_table_index = -1; + uint16_t TBS,i; + uint32_t buffer_occupancy; + uint32_t tmp_bsr; + uint32_t cqi_req,cshift,ndi,mcs,rballoc; + + for (ue_mod_id=0;ue_mod_id<granted_UEs && (*nCCE_available > (1<<aggregation));ue_mod_id++) { + + // msg("[MAC][eNB] subframeP %d: checking UE_id %d\n",subframeP,UE_id); + next_ue = ue_mod_id; // find next ue to schedule + // msg("[MAC][eNB] subframeP %d: next ue %d\n",subframeP,next_ue); + rnti = find_UE_RNTI(module_idP,next_ue); // radio network temp id is obtained + // msg("[MAC][eNB] subframeP %d: rnti %x\n",subframeP,rnti); + + if (rnti==0) // if so, go to next UE + continue; + + eNB_UE_stats = mac_xface->get_eNB_UE_stats(module_idP,rnti); + if (eNB_UE_stats==NULL) + mac_xface->macphy_exit("[MAC][eNB] Cannot find eNB_UE_stats\n"); + + LOG_I(MAC,"[eNB %d] Scheduler Frame %d, subframeP %d, nCCE %d: Checking ULSCH next UE_id %d mode id %d (rnti %x,mode %s), format 0\n", + module_idP,frameP,subframeP,*nCCE,next_ue,module_idP, rnti,mode_string[eNB_UE_stats->mode]); + + if (eNB_UE_stats->mode == PUSCH) { // ue has a ulsch channel + int8_t ret; + // Get candidate harq_pid from PHY + ret = mac_xface->get_ue_active_harq_pid(module_idP,rnti,subframeP,&harq_pid,&round,1); + LOG_I(MAC,"Got harq_pid %d, round %d, next_ue %d\n",harq_pid,round,next_ue); + + /* [SR] 01/07/13: Don't schedule UE if we cannot get harq pid */ +#ifndef EXMIMO_IOT + if ((((UE_is_to_be_scheduled(module_idP,ue_mod_id)>0)) || (round>0) || ((frameP%10)==0)) && (ret == 0)) + // if there is information on bsr of DCCH, DTCH or if there is UL_SR, or if there is a packet to retransmit, or we want to schedule a periodic feedback every 10 frames +#else + if (round==0) +#endif + { + LOG_D(MAC,"[eNB %d][PUSCH %x] Frame %d subframeP %d Scheduling UE %d (SR %d)\n", + module_idP,rnti,frameP,subframeP,ue_mod_id, + eNB_mac_inst[module_idP].UE_template[ue_mod_id].ul_SR); + + // reset the scheduling request + eNB_mac_inst[module_idP].UE_template[ue_mod_id].ul_SR = 0; + + aggregation = process_ue_cqi(module_idP,next_ue); // =2 by default!! + // msg("[MAC][eNB] subframeP %d: aggregation %d\n",subframeP,aggregation); + + status = mac_get_rrc_status(module_idP,1,next_ue); + + if (status < RRC_CONNECTED) + cqi_req = 0; + else + cqi_req = 1; + + + if (round > 0) { + ndi = eNB_mac_inst[module_idP].UE_template[ue_mod_id].oldNDI_UL[harq_pid]; + mcs = (round&3) + 28; //not correct for round==4! + } + else { + ndi = 1-eNB_mac_inst[module_idP].UE_template[ue_mod_id].oldNDI_UL[harq_pid]; + eNB_mac_inst[module_idP].UE_template[ue_mod_id].oldNDI_UL[harq_pid]=ndi; + mcs = openair_daq_vars.target_ue_ul_mcs; + } + + LOG_D(MAC,"[eNB %d] ULSCH scheduler: Ndi %d, mcs %d\n",module_idP,ndi,mcs); + + if((cooperation_flag > 0) && (next_ue == 1)) { // Allocation on same set of RBs + // RIV:resource indication value // function in openair1/PHY/LTE_TRANSPORT/dci_tools.c + rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_UL, + ((next_ue-1)*4),//openair_daq_vars.ue_ul_nb_rb), + 4);//openair_daq_vars.ue_ul_nb_rb); + } + else if ((round==0) && (mcs < 29)) { + rb_table_index = 1; + TBS = mac_xface->get_TBS_UL(mcs,rb_table[rb_table_index]); + buffer_occupancy = ((eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID0] == 0) && + (eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID1] == 0) && + (eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID2] == 0) && + (eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID3] == 0))? + BSR_TABLE[10] : // This is when we've received SR and buffers are fully served + BSR_TABLE[eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID0]]+ + BSR_TABLE[eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID1]]+ + BSR_TABLE[eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID2]]+ + BSR_TABLE[eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID3]]; // This is when remaining data in UE buffers (even if SR is triggered) + + LOG_D(MAC,"[eNB %d][PUSCH %d/%x] Frame %d subframeP %d Scheduled UE, BSR for LCGID0 %d, LCGID1 %d, LCGID2 %d LCGID3 %d, BO %d\n", + module_idP, + ue_mod_id, + rnti, + frameP, + subframeP, + eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID0], + eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID1], + eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID2], + eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID3], + buffer_occupancy); + + while ((TBS < buffer_occupancy) && + rb_table[rb_table_index]<(mac_xface->lte_frame_parms->N_RB_UL-1-*first_rb)){ + // continue until we've exhauster the UEs request or the total number of available PRBs + /* LOG_I(MAC,"[eNB %d][PUSCH %x] Frame %d subframeP %d Scheduled UE (rb_table_index %d => TBS %d)\n", + module_idP,rnti,frameP,subframeP, + rb_table_index,TBS); + */ + rb_table_index++; + TBS = mac_xface->get_TBS_UL(mcs,rb_table[rb_table_index]); + } + + if (rb_table[rb_table_index]>(mac_xface->lte_frame_parms->N_RB_UL-1-*first_rb)) { + rb_table_index--; + TBS = mac_xface->get_TBS_UL(mcs,rb_table[rb_table_index]); + } + //rb_table_index = 8; + + LOG_I(MAC,"[eNB %d][PUSCH %d/%x] Frame %d subframeP %d Scheduled UE (mcs %d, first rb %d, nb_rb %d, rb_table_index %d, TBS %d, harq_pid %d)\n", + module_idP,ue_mod_id,rnti,frameP,subframeP,mcs, + *first_rb,rb_table[rb_table_index], + rb_table_index,mac_xface->get_TBS_UL(mcs,rb_table[rb_table_index]), + harq_pid); + + rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_UL, + *first_rb, + rb_table[rb_table_index]);//openair_daq_vars.ue_ul_nb_rb); + + *first_rb+=rb_table[rb_table_index]; // increment for next UE allocation + eNB_mac_inst[module_idP].UE_template[ue_mod_id].nb_rb_ul[harq_pid] = rb_table[rb_table_index]; //store for possible retransmission + + buffer_occupancy -= mac_xface->get_TBS_UL(mcs,rb_table[rb_table_index]); + i = bytes_to_bsr_index((int32_t)buffer_occupancy); + + // Adjust BSR entries for LCGIDs + if (i>0) { + if (eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID0] <= i) { + tmp_bsr = BSR_TABLE[eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID0]]; + eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID0] = 0; + if (BSR_TABLE[eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID1]] <= (buffer_occupancy-tmp_bsr)) { + tmp_bsr += BSR_TABLE[eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID1]]; + eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID1] = 0; + if (BSR_TABLE[eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID2]] <= (buffer_occupancy-tmp_bsr)) { + tmp_bsr += BSR_TABLE[eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID2]]; + eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID2] = 0; + if (BSR_TABLE[eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID3]] <= (buffer_occupancy-tmp_bsr)) { + tmp_bsr += BSR_TABLE[eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID3]]; + eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID3] = 0; + } else { + eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID3] = bytes_to_bsr_index((int32_t)BSR_TABLE[eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID3]] - ((int32_t)buffer_occupancy - (int32_t)tmp_bsr)); + } + } + else { + eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID2] = bytes_to_bsr_index((int32_t)BSR_TABLE[eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID2]] - ((int32_t)buffer_occupancy -(int32_t)tmp_bsr)); + } + } + else { + eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID1] = bytes_to_bsr_index((int32_t)BSR_TABLE[eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID1]] - (int32_t)buffer_occupancy); + } + } + else { + eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID0] = bytes_to_bsr_index((int32_t)BSR_TABLE[eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID0]] - (int32_t)buffer_occupancy); + } + } + else { // we have flushed all buffers so clear bsr + eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID0] = 0; + eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID1] = 0; + eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID2] = 0; + eNB_mac_inst[module_idP].UE_template[ue_mod_id].bsr_info[LCGID3] = 0; + } + + + } // ndi==1 + else { //we schedule a retransmission + LOG_I(MAC,"[eNB %d][PUSCH %d/%x] Frame %d subframeP %d Scheduled UE retransmission (mcs %d, first rb %d, nb_rb %d, TBS %d, harq_pid %d)\n", + module_idP,ue_mod_id,rnti,frameP,subframeP,mcs, + *first_rb,eNB_mac_inst[module_idP].UE_template[ue_mod_id].nb_rb_ul[harq_pid], + mac_xface->get_TBS_UL(mcs,eNB_mac_inst[module_idP].UE_template[ue_mod_id].nb_rb_ul[harq_pid]), + harq_pid); + + rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_UL, + *first_rb, + eNB_mac_inst[module_idP].UE_template[ue_mod_id].nb_rb_ul[harq_pid]); + + *first_rb+=eNB_mac_inst[module_idP].UE_template[ue_mod_id].nb_rb_ul[harq_pid]; // increment for next UE allocation + } + + // Cyclic shift for DM RS + if(cooperation_flag == 2) { + if(next_ue == 1)// For Distriibuted Alamouti, cyclic shift applied to 2nd UE + cshift = 1; + else + cshift = 0; + } + else + cshift = 0;// values from 0 to 7 can be used for mapping the cyclic shift (36.211 , Table 5.5.2.1.1-1) + + if (mac_xface->lte_frame_parms->frame_type == TDD) { + switch (mac_xface->lte_frame_parms->N_RB_UL) { + case 6: + ULSCH_dci = eNB_mac_inst[module_idP].UE_template[next_ue].ULSCH_DCI[harq_pid]; + + ((DCI0_1_5MHz_TDD_1_6_t *)ULSCH_dci)->type = 0; + ((DCI0_1_5MHz_TDD_1_6_t *)ULSCH_dci)->hopping = 0; + ((DCI0_1_5MHz_TDD_1_6_t *)ULSCH_dci)->rballoc = rballoc; + ((DCI0_1_5MHz_TDD_1_6_t *)ULSCH_dci)->mcs = mcs; + ((DCI0_1_5MHz_TDD_1_6_t *)ULSCH_dci)->ndi = ndi; + ((DCI0_1_5MHz_TDD_1_6_t *)ULSCH_dci)->TPC = 1; + ((DCI0_1_5MHz_TDD_1_6_t *)ULSCH_dci)->cshift = cshift; + ((DCI0_1_5MHz_TDD_1_6_t *)ULSCH_dci)->padding = 0; + ((DCI0_1_5MHz_TDD_1_6_t *)ULSCH_dci)->dai = eNB_mac_inst[module_idP].UE_template[next_ue].DAI_ul[sched_subframe]; + ((DCI0_1_5MHz_TDD_1_6_t *)ULSCH_dci)->cqi_req = cqi_req; + + add_ue_spec_dci(DCI_pdu, + ULSCH_dci, + rnti, + sizeof(DCI0_1_5MHz_TDD_1_6_t), + aggregation, + sizeof_DCI0_1_5MHz_TDD_1_6_t, + format0, + 0); + break; + default: + case 25: + ULSCH_dci = eNB_mac_inst[module_idP].UE_template[next_ue].ULSCH_DCI[harq_pid]; + + ((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->type = 0; + ((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->hopping = 0; + ((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->rballoc = rballoc; + ((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->mcs = mcs; + ((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->ndi = ndi; + ((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->TPC = 1; + ((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->cshift = cshift; + ((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->padding = 0; + ((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->dai = eNB_mac_inst[module_idP].UE_template[next_ue].DAI_ul[sched_subframe]; + ((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->cqi_req = cqi_req; + + add_ue_spec_dci(DCI_pdu, + ULSCH_dci, + rnti, + sizeof(DCI0_5MHz_TDD_1_6_t), + aggregation, + sizeof_DCI0_5MHz_TDD_1_6_t, + format0, + 0); + break; + case 50: + ULSCH_dci = eNB_mac_inst[module_idP].UE_template[next_ue].ULSCH_DCI[harq_pid]; + + ((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->type = 0; + ((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->hopping = 0; + ((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->rballoc = rballoc; + ((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->mcs = mcs; + ((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->ndi = ndi; + ((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->TPC = 1; + ((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->cshift = cshift; + ((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->padding = 0; + ((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->dai = eNB_mac_inst[module_idP].UE_template[next_ue].DAI_ul[sched_subframe]; + ((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->cqi_req = cqi_req; + + add_ue_spec_dci(DCI_pdu, + ULSCH_dci, + rnti, + sizeof(DCI0_10MHz_TDD_1_6_t), + aggregation, + sizeof_DCI0_10MHz_TDD_1_6_t, + format0, + 0); + break; + case 100: + ULSCH_dci = eNB_mac_inst[module_idP].UE_template[next_ue].ULSCH_DCI[harq_pid]; + + ((DCI0_20MHz_TDD_1_6_t *)ULSCH_dci)->type = 0; + ((DCI0_20MHz_TDD_1_6_t *)ULSCH_dci)->hopping = 0; + ((DCI0_20MHz_TDD_1_6_t *)ULSCH_dci)->rballoc = rballoc; + ((DCI0_20MHz_TDD_1_6_t *)ULSCH_dci)->mcs = mcs; + ((DCI0_20MHz_TDD_1_6_t *)ULSCH_dci)->ndi = ndi; + ((DCI0_20MHz_TDD_1_6_t *)ULSCH_dci)->TPC = 1; + ((DCI0_20MHz_TDD_1_6_t *)ULSCH_dci)->cshift = cshift; + ((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->padding = 0; + ((DCI0_20MHz_TDD_1_6_t *)ULSCH_dci)->dai = eNB_mac_inst[module_idP].UE_template[next_ue].DAI_ul[sched_subframe]; + ((DCI0_20MHz_TDD_1_6_t *)ULSCH_dci)->cqi_req = cqi_req; + + add_ue_spec_dci(DCI_pdu, + ULSCH_dci, + rnti, + sizeof(DCI0_20MHz_TDD_1_6_t), + aggregation, + sizeof_DCI0_20MHz_TDD_1_6_t, + format0, + 0); + break; + } + } + else { //FDD + switch (mac_xface->lte_frame_parms->N_RB_UL) { + case 25: + default: + + ULSCH_dci = eNB_mac_inst[module_idP].UE_template[next_ue].ULSCH_DCI[harq_pid]; + + ((DCI0_5MHz_FDD_t *)ULSCH_dci)->type = 0; + ((DCI0_5MHz_FDD_t *)ULSCH_dci)->hopping = 0; + ((DCI0_5MHz_FDD_t *)ULSCH_dci)->rballoc = rballoc; + ((DCI0_5MHz_FDD_t *)ULSCH_dci)->mcs = mcs; + ((DCI0_5MHz_FDD_t *)ULSCH_dci)->ndi = ndi; + ((DCI0_5MHz_FDD_t *)ULSCH_dci)->TPC = 1; + ((DCI0_5MHz_FDD_t *)ULSCH_dci)->cshift = cshift; + ((DCI0_5MHz_FDD_t *)ULSCH_dci)->padding = 0; + ((DCI0_5MHz_FDD_t *)ULSCH_dci)->cqi_req = cqi_req; + + add_ue_spec_dci(DCI_pdu, + ULSCH_dci, + rnti, + sizeof(DCI0_5MHz_FDD_t), + aggregation, + sizeof_DCI0_5MHz_FDD_t, + format0, + 0); + break; + case 6: + ULSCH_dci = eNB_mac_inst[module_idP].UE_template[next_ue].ULSCH_DCI[harq_pid]; + + ((DCI0_1_5MHz_FDD_t *)ULSCH_dci)->type = 0; + ((DCI0_1_5MHz_FDD_t *)ULSCH_dci)->hopping = 0; + ((DCI0_1_5MHz_FDD_t *)ULSCH_dci)->rballoc = rballoc; + ((DCI0_1_5MHz_FDD_t *)ULSCH_dci)->mcs = mcs; + ((DCI0_1_5MHz_FDD_t *)ULSCH_dci)->ndi = ndi; + ((DCI0_1_5MHz_FDD_t *)ULSCH_dci)->TPC = 1; + ((DCI0_1_5MHz_FDD_t *)ULSCH_dci)->cshift = cshift; + ((DCI0_1_5MHz_FDD_t *)ULSCH_dci)->padding = 0; + ((DCI0_1_5MHz_FDD_t *)ULSCH_dci)->cqi_req = cqi_req; + + add_ue_spec_dci(DCI_pdu, + ULSCH_dci, + rnti, + sizeof(DCI0_1_5MHz_FDD_t), + aggregation, + sizeof_DCI0_1_5MHz_FDD_t, + format0, + 0); + break; + case 50: + ULSCH_dci = eNB_mac_inst[module_idP].UE_template[next_ue].ULSCH_DCI[harq_pid]; + + ((DCI0_10MHz_FDD_t *)ULSCH_dci)->type = 0; + ((DCI0_10MHz_FDD_t *)ULSCH_dci)->hopping = 0; + ((DCI0_10MHz_FDD_t *)ULSCH_dci)->rballoc = rballoc; + ((DCI0_10MHz_FDD_t *)ULSCH_dci)->mcs = mcs; + ((DCI0_10MHz_FDD_t *)ULSCH_dci)->ndi = ndi; + ((DCI0_10MHz_FDD_t *)ULSCH_dci)->TPC = 1; + ((DCI0_10MHz_FDD_t *)ULSCH_dci)->padding = 0; + ((DCI0_10MHz_FDD_t *)ULSCH_dci)->cshift = cshift; + ((DCI0_10MHz_FDD_t *)ULSCH_dci)->cqi_req = cqi_req; + + add_ue_spec_dci(DCI_pdu, + ULSCH_dci, + rnti, + sizeof(DCI0_10MHz_FDD_t), + aggregation, + sizeof_DCI0_10MHz_FDD_t, + format0, + 0); + break; + case 100: + ULSCH_dci = eNB_mac_inst[module_idP].UE_template[next_ue].ULSCH_DCI[harq_pid]; + + ((DCI0_20MHz_FDD_t *)ULSCH_dci)->type = 0; + ((DCI0_20MHz_FDD_t *)ULSCH_dci)->hopping = 0; + ((DCI0_20MHz_FDD_t *)ULSCH_dci)->rballoc = rballoc; + ((DCI0_20MHz_FDD_t *)ULSCH_dci)->mcs = mcs; + ((DCI0_20MHz_FDD_t *)ULSCH_dci)->ndi = ndi; + ((DCI0_20MHz_FDD_t *)ULSCH_dci)->TPC = 1; + ((DCI0_20MHz_FDD_t *)ULSCH_dci)->padding = 0; + ((DCI0_20MHz_FDD_t *)ULSCH_dci)->cshift = cshift; + ((DCI0_20MHz_FDD_t *)ULSCH_dci)->cqi_req = cqi_req; + + add_ue_spec_dci(DCI_pdu, + ULSCH_dci, + rnti, + sizeof(DCI0_20MHz_FDD_t), + aggregation, + sizeof_DCI0_20MHz_FDD_t, + format0, + 0); + break; + + } + } + //#ifdef DEBUG_eNB_SCHEDULER + // dump_dci(mac_xface->lte_frame_parms, + // &DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci+DCI_pdu->Num_ue_spec_dci-1]); + //#endif + add_ue_ulsch_info(module_idP, + next_ue, + subframeP, + S_UL_SCHEDULED); + + *nCCE = (*nCCE) + (1<<aggregation); + *nCCE_available = mac_xface->get_nCCE_max(module_idP) - *nCCE; + //msg("[MAC][eNB %d][ULSCH Scheduler] Frame %d, subframeP %d: Generated ULSCH DCI for next UE_id %d, format 0\n", module_idP,frameP,subframeP,next_ue); + + //break; // leave loop after first UE is schedule (avoids m + } // UE_is_to_be_scheduled + } // UE is in PUSCH + } // loop over UE_id +} + +uint8_t find_ulgranted_UEs(module_id_t module_idP){ + + // all active users should be granted + return(find_active_UEs(module_idP)); +} + +unsigned char *get_dlsch_sdu(module_id_t module_idP, frame_t frameP, rnti_t rntiP, uint8_t TBindex) { + + module_id_t ue_mod_id; + + if (rntiP==SI_RNTI) { + LOG_D(MAC,"[eNB %d] Frame %d Get DLSCH sdu for BCCH \n",module_idP,frameP); + + return((unsigned char *)&eNB_mac_inst[module_idP].BCCH_pdu.payload[0]); + } + else if ((ue_mod_id = find_UE_id(module_idP,rntiP)) != UE_INDEX_INVALID ){ + LOG_D(MAC,"[eNB %d] Frame %d: Get DLSCH sdu for rnti %x => UE_id %d\n",module_idP,frameP,rntiP,ue_mod_id); + return((unsigned char *)&eNB_mac_inst[module_idP].DLSCH_pdu[ue_mod_id][TBindex].payload[0]); + } else { + LOG_E(MAC,"[eNB %d] Frame %d: UE with RNTI %x does not exist\n", module_idP,frameP,rntiP); + return NULL; + } + +} + +#ifdef CBA +void schedule_ulsch_cba_rnti(module_id_t module_idP, unsigned char cooperation_flag, frame_t frameP, sub_frame_t subframeP, unsigned char sched_subframe, uint8_t granted_UEs, unsigned int *nCCE, unsigned int *nCCE_available, uint16_t *first_rb){ + + DCI0_5MHz_TDD_1_6_t *ULSCH_dci_tdd16; + DCI0_5MHz_FDD_t *ULSCH_dci_fdd; + DCI_PDU *DCI_pdu= &eNB_mac_inst[module_idP].DCI_pdu; + + uint8_t rb_table_index=0, aggregation=2; + uint32_t rballoc; + uint8_t cba_group, cba_resources; + uint8_t required_rbs[NUM_MAX_CBA_GROUP], weight[NUM_MAX_CBA_GROUP], num_cba_resources[NUM_MAX_CBA_GROUP]; + uint8_t available_rbs= ceil(mac_xface->lte_frame_parms->N_RB_UL-1-*first_rb); + uint8_t remaining_rbs= available_rbs; + uint8_t allocated_rbs; + // We compute the weight of each group and initialize some variables + for (cba_group=0;cba_group<eNB_mac_inst[module_idP].num_active_cba_groups;cba_group++) { + // UEs in PUSCH with traffic + weight[cba_group] = find_num_active_UEs_in_cbagroup(module_idP, cba_group); + required_rbs[cba_group] = 0; + num_cba_resources[cba_group]=0; + } + //LOG_D(MAC, "[eNB ] CBA granted ues are %d\n",granted_UEs ); + for (cba_group=0;cba_group<eNB_mac_inst[module_idP].num_active_cba_groups && (*nCCE_available > (1<<aggregation));cba_group++) { + if (remaining_rbs <= 0 ) + break; + // If the group needs some resource + if ((weight[cba_group] > 0) && eNB_mac_inst[module_idP].cba_rnti[cba_group] != 0){ + // to be refined in case of : granted_UEs >> weight[cba_group]*available_rbs + required_rbs[cba_group] = (uint8_t)ceil((weight[cba_group]*available_rbs)/granted_UEs); + + while (remaining_rbs < required_rbs[cba_group] ) + required_rbs[cba_group]--; + + /* + while (rb_table[rb_table_index] < required_rbs[cba_group]) + rb_table_index++; + + while (rb_table[rb_table_index] > remaining_rbs ) + rb_table_index--; + + remaining_rbs-=rb_table[rb_table_index]; + required_rbs[cba_group]=rb_table[rb_table_index]; + */ + // to be refined + if (weight[cba_group] < required_rbs[cba_group]) + num_cba_resources[cba_group]=(uint8_t)ceil(weight[cba_group]/2.0); + else + num_cba_resources[cba_group]=(uint8_t)ceil(required_rbs[cba_group]/2.0); + + while ((*nCCE) + (1<<aggregation) * num_cba_resources[cba_group] > *nCCE_available) + num_cba_resources[cba_group]--; + + LOG_N(MAC,"[eNB %d] Frame %d, subframeP %d: cba group %d weight/granted_ues %d/%d available/required rb (%d/%d), num resources %d->1 (*scaled down*) \n", + module_idP, frameP, subframeP, cba_group, + weight[cba_group], granted_UEs, available_rbs,required_rbs[cba_group], + num_cba_resources[cba_group]); + + num_cba_resources[cba_group]=1; + + } + } + // phase 2 + for (cba_group=0;cba_group<eNB_mac_inst[module_idP].num_active_cba_groups;cba_group++) { + for (cba_resources=0; cba_resources < num_cba_resources[cba_group]; cba_resources++){ + rb_table_index =0; + // check if there was an allocation for this group in the 1st phase + if (required_rbs[cba_group] == 0 ) + continue; + + while (rb_table[rb_table_index] < (uint8_t) ceil(required_rbs[cba_group] / num_cba_resources[cba_group]) ) + rb_table_index++; + + while (rb_table[rb_table_index] > remaining_rbs ) + rb_table_index--; + + remaining_rbs-=rb_table[rb_table_index]; + allocated_rbs=rb_table[rb_table_index]; + + rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_UL, + *first_rb, + rb_table[rb_table_index]); + + *first_rb+=rb_table[rb_table_index]; + LOG_D(MAC,"[eNB %d] Frame %d, subframeP %d: CBA %d rnti %x, total/required/allocated/remaining rbs (%d/%d/%d/%d), rballoc %d, nCCE (%d/%d)\n", + module_idP, frameP, subframeP, cba_group,eNB_mac_inst[module_idP].cba_rnti[cba_group], + available_rbs, required_rbs[cba_group], allocated_rbs, remaining_rbs,rballoc, + *nCCE_available,*nCCE); + + + if (mac_xface->lte_frame_parms->frame_type == TDD) { + ULSCH_dci_tdd16 = (DCI0_5MHz_TDD_1_6_t *)eNB_mac_inst[module_idP].UE_template[cba_group].ULSCH_DCI[0]; + + ULSCH_dci_tdd16->type = 0; + ULSCH_dci_tdd16->hopping = 0; + ULSCH_dci_tdd16->rballoc = rballoc; + ULSCH_dci_tdd16->mcs = 2; + ULSCH_dci_tdd16->ndi = 1; + ULSCH_dci_tdd16->TPC = 1; + ULSCH_dci_tdd16->cshift = cba_group; + ULSCH_dci_tdd16->dai = eNB_mac_inst[module_idP].UE_template[cba_group].DAI_ul[sched_subframe]; + ULSCH_dci_tdd16->cqi_req = 1; + + //add_ue_spec_dci + add_common_dci(DCI_pdu, + ULSCH_dci_tdd16, + eNB_mac_inst[module_idP].cba_rnti[cba_group], + sizeof(DCI0_5MHz_TDD_1_6_t), + aggregation, + sizeof_DCI0_5MHz_TDD_1_6_t, + format0, + 0); + } + else { + ULSCH_dci_fdd = (DCI0_5MHz_FDD_t *)eNB_mac_inst[module_idP].UE_template[cba_group].ULSCH_DCI[0]; + + ULSCH_dci_fdd->type = 0; + ULSCH_dci_fdd->hopping = 0; + ULSCH_dci_fdd->rballoc = rballoc; + ULSCH_dci_fdd->mcs = 2; + ULSCH_dci_fdd->ndi = 1; + ULSCH_dci_fdd->TPC = 1; + ULSCH_dci_fdd->cshift = 0; + ULSCH_dci_fdd->cqi_req = 1; + + //add_ue_spec_dci + add_common_dci(DCI_pdu, + ULSCH_dci_fdd, + eNB_mac_inst[module_idP].cba_rnti[cba_group], + sizeof(DCI0_5MHz_FDD_t), + aggregation, + sizeof_DCI0_5MHz_FDD_t, + format0, + 0); + } + *nCCE = (*nCCE) + (1<<aggregation) * num_cba_resources[cba_group]; + *nCCE_available = mac_xface->get_nCCE_max(module_idP) - *nCCE; + // break;// for the moment only schedule one + } + } +} +#endif diff --git a/openair2/LAYER2/MAC/extern.h b/openair2/LAYER2/MAC/extern.h index 8b029c08be..23eadab647 100644 --- a/openair2/LAYER2/MAC/extern.h +++ b/openair2/LAYER2/MAC/extern.h @@ -28,8 +28,8 @@ *******************************************************************************/ /*! \file extern.h * \brief mac externs -* \author Raymond Knopp, Navid Nikaein -* \date 2012 +* \author Navid Nikaein and Raymond Knopp +* \date 2010 - 2014 * \version 1.0 * \email navid.nikaein@eurecom.fr * @ingroup _mac diff --git a/openair2/LAYER2/MAC/l1_helpers.c b/openair2/LAYER2/MAC/l1_helpers.c index ef1e921a78..fef9dddb9c 100644 --- a/openair2/LAYER2/MAC/l1_helpers.c +++ b/openair2/LAYER2/MAC/l1_helpers.c @@ -28,9 +28,10 @@ *******************************************************************************/ /*! \file l1_helper.c * \brief phy helper function -* \author Raymond Knopp -* \date 2012 +* \author Navid Nikaein, Raymond Knopp +* \date 2012 - 2014 * \version 0.5 +* \email navid.nikaein@eurecom.fr * @ingroup _mac */ @@ -38,6 +39,7 @@ #include "defs.h" #include "extern.h" #include "UTIL/LOG/log.h" +#include "proto.h" int8_t get_Po_NOMINAL_PUSCH(module_id_t module_idP) { RACH_ConfigCommon_t *rach_ConfigCommon = NULL; diff --git a/openair2/LAYER2/MAC/main.c b/openair2/LAYER2/MAC/main.c index f83918471c..4cba017c9a 100644 --- a/openair2/LAYER2/MAC/main.c +++ b/openair2/LAYER2/MAC/main.c @@ -28,8 +28,8 @@ *******************************************************************************/ /*! \file main.c * \brief top init of Layer 2 - * \author Raymond Knopp and Navid Nikaein - * \date 2011 + * \author Navid Nikaein and Raymond Knopp + * \date 2010 - 2014 * \version 0.5 * \email: navid.nikaein@eurecom.fr * @ingroup _mac @@ -53,6 +53,7 @@ #endif //USER_MODE #include "defs.h" +#include "proto.h" #include "extern.h" #include "assertions.h" #include "PHY_INTERFACE/extern.h" @@ -69,12 +70,10 @@ #include "SCHED/defs.h" -/***********************************************************************/ void dl_phy_sync_success(module_id_t module_idP, frame_t frameP, unsigned char eNB_index, uint8_t first_sync){ //init as MR - /***********************************************************************/ LOG_D(MAC,"[UE %d] Frame %d: PHY Sync to eNB_index %d successful \n", module_idP, frameP, eNB_index); if (first_sync==1) { layer2_init_UE(module_idP); @@ -86,9 +85,8 @@ void dl_phy_sync_success(module_id_t module_idP, } -/***********************************************************************/ void mrbch_phy_sync_failure(module_id_t module_idP, frame_t frameP, uint8_t free_eNB_index){//init as CH - /***********************************************************************/ + LOG_I(MAC,"[eNB %d] Frame %d: PHY Sync failure \n",module_idP,frameP); layer2_init_eNB(module_idP, free_eNB_index); openair_rrc_eNB_init(module_idP); @@ -100,23 +98,19 @@ char layer2_init_eNB(module_id_t module_idP, unsigned char eNB_index){ } -/***********************************************************************/ char layer2_init_UE(module_id_t module_idP){ return 0; } -/***********************************************************************/ void mac_UE_out_of_sync_ind(module_id_t module_idP, frame_t frameP, uint16_t eNB_index){ - /***********************************************************************/ // Mac_rlc_xface->mac_out_of_sync_ind(Mod_id, frameP, eNB_index); } -/***********************************************************************/ int mac_top_init(int eMBMS_active, uint8_t cba_group_active, uint8_t HO_active){ - /***********************************************************************/ + module_id_t Mod_id,i,j; RA_TEMPLATE *RA_template; UE_TEMPLATE *UE_template; @@ -311,9 +305,7 @@ int mac_top_init(int eMBMS_active, uint8_t cba_group_active, uint8_t HO_active){ } -/***********************************************************************/ int mac_init_global_param(void){ - /***********************************************************************/ Mac_rlc_xface = NULL; @@ -374,9 +366,8 @@ int mac_init_global_param(void){ } -/***********************************************************************/ void mac_top_cleanup(void){ - /***********************************************************************/ + #ifndef USER_MODE pdcp_module_cleanup (); #endif diff --git a/openair2/LAYER2/MAC/openair2_proc.c b/openair2/LAYER2/MAC/openair2_proc.c index 6b10383605..5765e17aaa 100644 --- a/openair2/LAYER2/MAC/openair2_proc.c +++ b/openair2/LAYER2/MAC/openair2_proc.c @@ -45,7 +45,7 @@ #include "LAYER2/MAC/extern.h" //#include "RRC/LITE/extern.h" //#include "LAYER2/PDCP/pdcp.h" - +#include "proto.h" #ifndef USER_MODE static int openair2_stats_read(char *buffer, char **my_buffer, off_t off, int length) #else diff --git a/openair2/LAYER2/MAC/pre_processor.c b/openair2/LAYER2/MAC/pre_processor.c index 89ebeeafed..87bcfba206 100644 --- a/openair2/LAYER2/MAC/pre_processor.c +++ b/openair2/LAYER2/MAC/pre_processor.c @@ -1,4 +1,3 @@ - /******************************************************************************* Eurecom OpenAirInterface @@ -29,13 +28,15 @@ *******************************************************************************/ /*! \file pre_processor.c * \brief procedures related to UE - * \author Ankit Bhamri + * \author Navid Nikaein and Ankit Bhamri * \date 2013 + * \email navid.nikaein@eurecom.fr * \version 0.1 * @ingroup _mac */ + #include "PHY/defs.h" #include "PHY/extern.h" @@ -43,6 +44,7 @@ #include "SCHED/extern.h" #include "LAYER2/MAC/defs.h" +#include "LAYER2/MAC/proto.h" #include "LAYER2/MAC/extern.h" #include "UTIL/LOG/log.h" #include "UTIL/OPT/opt.h" @@ -325,10 +327,22 @@ void sort_UEs (module_id_t Mod_id, } else if((j == MAX_NUM_LCID-1)) { - if(eNB_UE_stats1->DL_cqi[0] < eNB_UE_stats2->DL_cqi[0]){ + /* The goal is to sort by priority. + * We use the priority of DTCH logical + * channel. + */ + /*if(eNB_mac_inst[Mod_id].UE_sched_ctrl[next_ue1].priority[3]<eNB_mac_inst[Mod_id].UE_sched_ctrl[next_ue2].priority[3]) + { + UE_id_sorted[i] = next_ue2; + UE_id_sorted[ii] = next_ue1; + } //if the priority is the same then sort by CQI + else if(eNB_mac_inst[Mod_id].UE_sched_ctrl[next_ue1].priority[3]==eNB_mac_inst[Mod_id].UE_sched_ctrl[next_ue2].priority[3]){*/ + + if(eNB_UE_stats1->DL_cqi[0] < eNB_UE_stats2->DL_cqi[0]){ UE_id_sorted[i] = next_ue2; UE_id_sorted[ii] = next_ue1; } + //} } } } @@ -423,6 +437,14 @@ void dlsch_scheduler_pre_processor (module_id_t Mod_id, total_ue_count = total_ue_count + 1; } // hypotetical assignement + /* + * If schedule is enabled and if the priority of the UEs is modified + * The average rbs per logical channel per user will depend on the level of + * priority. Concerning the hypothetical assignement, we should assign more + * rbs to prioritized users. Maybe, we can do a mapping between the + * average rbs per user and the level of priority or multiply the average rbs + * per user by a coefficient which represents the degree of priority. + */ if((total_ue_count > 0) && ( min_rb_unit * total_ue_count <= mac_xface->lte_frame_parms->N_RB_DL ) ) average_rbs_per_user = (uint16_t) ceil(mac_xface->lte_frame_parms->N_RB_DL/total_ue_count); else diff --git a/openair2/LAYER2/MAC/proto.h b/openair2/LAYER2/MAC/proto.h new file mode 100644 index 0000000000..6d55d0db02 --- /dev/null +++ b/openair2/LAYER2/MAC/proto.h @@ -0,0 +1,607 @@ +/******************************************************************************* + + Eurecom OpenAirInterface + Copyright(c) 1999 - 2010 Eurecom + + This program is free software; you can redistribute it and/or modify it + under the terms and conditions of the GNU General Public License, + version 2, as published by the Free Software Foundation. + + This program is distributed in the hope it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along with + this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + + The full GNU General Public License is included in this distribution in + the file called "COPYING". + + Contact Information + Openair Admin: openair_admin@eurecom.fr + Openair Tech : openair_tech@eurecom.fr + Forums : http://forums.eurecom.fsr/openairinterface + Address : Eurecom, 2229, route des crêtes, 06560 Valbonne Sophia Antipolis, France + + *******************************************************************************/ +/*! \file pre_processor.c + * \brief procedures related to UE + * \author Navid Nikaein and Raymond Knopp + * \date 2013 + * \email navid.nikaein@eurecom.fr + * \version 0.1 + * @ingroup _mac + + */ +#ifndef __LAYER2_MAC_PROTO_H__ +#define __LAYER2_MAC_PROTO_H__ + + +void add_ue_spec_dci(DCI_PDU *DCI_pdu,void *pdu,rnti_t rnti,unsigned char dci_size_bytes,unsigned char aggregation,unsigned char dci_size_bits,unsigned char dci_fmt,uint8_t ra_flag); + +extern inline unsigned int taus(void); + +/** \brief First stage of Random-Access Scheduling. Loops over the RA_templates and checks if RAR, Msg3 or its retransmission are to be scheduled in the subframe. It returns the total number of PRB used for RA SDUs. For Msg3 it retrieves the L3msg from RRC and fills the appropriate buffers. For the others it just computes the number of PRBs. Each DCI uses 3 PRBs (format 1A) +for the message. +@param Mod_id Instance ID of eNB +@param frame Frame index +@param subframe Subframe number on which to act +@param nprb Pointer to current PRB count +@param nCCE Pointer to current nCCE count +*/ +void schedule_RA(module_id_t module_idP,frame_t frameP,sub_frame_t subframe,uint8_t Msg3_subframe,uint8_t *nprb,unsigned int *nCCE); + +/** \brief First stage of SI Scheduling. Gets a SI SDU from RRC if available and computes the MCS required to transport it as a function of the SDU length. It assumes a length less than or equal to 64 bytes (MCS 6, 3 PRBs). +@param Mod_id Instance ID of eNB +@param frame Frame index +@param subframe Subframe number on which to act +@param Msg3_subframe Subframe where Msg3 will be transmitted +@param nprb Pointer to current PRB count +@param nCCE Pointer to current nCCE count +*/ +void schedule_SI(module_id_t module_idP,frame_t frameP,uint8_t *nprb,unsigned int *nCCE); + +/** \brief MBMS scheduling: Checking the position for MBSFN subframes. Create MSI, transfer MCCH from RRC to MAC, transfer MTCHs from RLC to MAC. Multiplexing MSI,MCCH&MTCHs. Return 1 if there are MBSFN data being allocated, otherwise return 0; +@param Mod_id Instance ID of eNB +@param frame Frame index +@param subframe Subframe number on which to act +*/ +int schedule_MBMS(module_id_t module_idP,frame_t frameP, sub_frame_t subframe); + +/** \brief check the mapping between sf allocation and sync area, Currently only supports 1:1 mapping +@param Mod_id Instance ID of eNB +@param mbsfn_sync_area index of mbsfn sync area +@param[out] index of sf pattern +*/ +int8_t get_mbsfn_sf_alloction (module_id_t module_idP, uint8_t mbsfn_sync_area); + +/** \brief check the mapping between sf allocation and sync area, Currently only supports 1:1 mapping +@param Mod_id Instance ID of eNB +@param mbsfn_sync_area index of mbsfn sync area +@param eNB_index index of eNB +@param[out] index of sf pattern +*/ +int8_t ue_get_mbsfn_sf_alloction (module_id_t module_idP, uint8_t mbsfn_sync_area, unsigned char eNB_index); + +/** \brief top ULSCH Scheduling for TDD (config 1-6). +@param Mod_id Instance ID of eNB +@param frame Frame index +@param subframe Subframe number on which to act +@param sched_subframe Subframe number where PUSCH is transmitted (for DAI lookup) +@param nCCE Pointer to current nCCE count +*/ +void schedule_ulsch(module_id_t module_idP,frame_t frameP,unsigned char cooperation_flag,sub_frame_t subframe,unsigned char sched_subframe,unsigned int *nCCE); + +/** \brief ULSCH Scheduling per RNTI TDD config (config 1-6). +@param Mod_id Instance ID of eNB +@param frame Frame index +@param subframe Subframe number on which to act +@param sched_subframe Subframe number where PUSCH is transmitted (for DAI lookup) +@param nCCE Pointer to current nCCE count +*/ +void schedule_ulsch_rnti(module_id_t module_idP, unsigned char cooperation_flag, frame_t frameP, sub_frame_t subframe, unsigned char sched_subframe, uint8_t granted_UEs, unsigned int *nCCE, unsigned int *nCCE_available, uint16_t *first_rb); + +/** \brief ULSCH Scheduling for CBA RNTI TDD config (config 1-6). +@param Mod_id Instance ID of eNB +@param frame Frame index +@param subframe Subframe number on which to act +@param sched_subframe Subframe number where PUSCH is transmitted (for DAI lookup) +@param nCCE Pointer to current nCCE count +*/ +void schedule_ulsch_cba_rnti(module_id_t module_idP, unsigned char cooperation_flag, frame_t frameP, sub_frame_t subframe, unsigned char sched_subframe, uint8_t granted_UEs, unsigned int *nCCE, unsigned int *nCCE_available, uint16_t *first_rb); + +/** \brief Second stage of DLSCH scheduling, after schedule_SI, schedule_RA and schedule_dlsch have been called. This routine first allocates random frequency assignments for SI and RA SDUs using distributed VRB allocations and adds the corresponding DCI SDU to the DCI buffer for PHY. It then loops over the UE specific DCIs previously allocated and fills in the remaining DCI fields related to frequency allocation. It assumes localized allocation of type 0 (DCI.rah=0). The allocation is done for tranmission modes 1,2,4. +@param Mod_id Instance of eNB +@param frame Frame index +@param subframe Index of subframe +@param rballoc Bitmask for allowable subband allocations +@param RA_scheduled RA was scheduled in this subframe +@param mbsfn_flag Indicates that this subframe is for MCH/MCCH +*/ +void fill_DLSCH_dci(module_id_t module_idP,frame_t frameP,sub_frame_t subframe,uint32_t rballoc,uint8_t RA_scheduled,int mbsfn_flag); + +/** \brief UE specific DLSCH scheduling. Retrieves next ue to be schduled from round-robin scheduler and gets the appropriate harq_pid for the subframe from PHY. If the process is active and requires a retransmission, it schedules the retransmission with the same PRB count and MCS as the first transmission. Otherwise it consults RLC for DCCH/DTCH SDUs (status with maximum number of available PRBS), builds the MAC header (timing advance sent by default) and copies +@param Mod_id Instance ID of eNB +@param frame Frame index +@param subframe Subframe on which to act +@param nb_rb_used0 Number of PRB used by SI/RA +@param nCCE_used Number of CCE used by SI/RA +@param mbsfn_flag Indicates that MCH/MCCH is in this subframe +*/ +void schedule_ue_spec(module_id_t module_idP,frame_t frameP,sub_frame_t subframe,uint16_t nb_rb_used0,unsigned int *nCCE_used,int mbsfn_flag); + +/** \brief Function for UE/PHY to compute PUSCH transmit power in power-control procedure. + @param Mod_id Module id of UE + @returns Po_NOMINAL_PUSCH (PREAMBLE_RECEIVED_TARGET_POWER+DELTA_PREAMBLE +*/ +int8_t get_Po_NOMINAL_PUSCH(module_id_t module_idP); + +/** \brief Function to compute DELTA_PREAMBLE from 36.321 (for RA power ramping procedure and Msg3 PUSCH power control policy) + @param Mod_id Module id of UE + @returns DELTA_PREAMBLE +*/ +int8_t get_DELTA_PREAMBLE(module_id_t module_idP); + +/** \brief Function for compute deltaP_rampup from 36.321 (for RA power ramping procedure and Msg3 PUSCH power control policy) + @param Mod_id Module id of UE + @returns deltaP_rampup +*/ +int8_t get_deltaP_rampup(module_id_t module_idP); + +//main.c + +void chbch_phy_sync_success(module_id_t module_idP,frame_t frameP,uint8_t eNB_index); + +void mrbch_phy_sync_failure(module_id_t module_idP, frame_t frameP,uint8_t free_eNB_index); + +int mac_top_init(int eMBMS_active, uint8_t cba_group_active, uint8_t HO_active); + +char layer2_init_UE(module_id_t module_idP); + +char layer2_init_eNB(module_id_t module_idP, uint8_t Free_ch_index); + +void mac_switch_node_function(module_id_t module_idP); + +int mac_init_global_param(void); + +void mac_top_cleanup(void); + +void mac_UE_out_of_sync_ind(module_id_t module_idP,frame_t frameP, uint16_t eNB_index); + + +// eNB functions +/* \brief This function assigns pre-available RBS to each UE in specified sub-bands before scheduling is done +@param Mod_id Instance ID of eNB +@param frame Index of frame +@param subframe Index of current subframe +@param dl_pow_off Pointer to store resulting power offset for DCI +@param pre_nb_available_rbs Pointer to store number of remaining rbs after scheduling +@param N_RBS Number of resource block groups +@param rb_alloc_sub Table of resource block groups allocated to each UE + */ + + +void dlsch_scheduler_pre_processor (module_id_t module_idP, + frame_t frameP, + sub_frame_t subframe, + uint8_t *dl_pow_off, + uint16_t *pre_nb_available_rbs, + int N_RBGS, + unsigned char rballoc_sub_UE[NUMBER_OF_UE_MAX][N_RBGS_MAX]); + +/* \brief Function to trigger the eNB scheduling procedure. It is called by PHY at the beginning of each subframe, \f$n$\f + and generates all DLSCH allocations for subframe \f$n\f$ and ULSCH allocations for subframe \f$n+k$\f. The resultant DCI_PDU is + ready after returning from this call. +@param Mod_id Instance ID of eNB +@param cooperation_flag Flag to indicated that this cell has cooperating nodes (i.e. that there are collaborative transport channels that +can be scheduled. +@param subframe Index of current subframe +@param calibration_flag Flag to indicate that eNB scheduler should schedule TDD auto-calibration PUSCH. +*/ +void eNB_dlsch_ulsch_scheduler(module_id_t module_idP, uint8_t cooperation_flag, frame_t frameP, sub_frame_t subframeP);//, int calibration_flag); + +/* \brief Function to retrieve result of scheduling (DCI) in current subframe. Can be called an arbitrary numeber of times after eNB_dlsch_ulsch_scheduler +in a given subframe. +@param Mod_id Instance ID of eNB +@param subframe Index of current subframe +@returns Pointer to generated DCI for subframe +*/ +DCI_PDU *get_dci_sdu(module_id_t module_idP,frame_t frameP,sub_frame_t subframe); + +/* \brief Function to indicate a received preamble on PRACH. It initiates the RA procedure. +@param Mod_id Instance ID of eNB +@param preamble_index index of the received RA request +@param timing_offset Offset in samples of the received PRACH w.r.t. eNB timing. This is used to +*/ +void initiate_ra_proc(module_id_t module_idP,frame_t frameP, uint16_t preamble_index,int16_t timing_offset,uint8_t sect_id,sub_frame_t subframe,uint8_t f_id); + +/* \brief Function in eNB to fill RAR pdu when requested by PHY. This provides a single RAR SDU for the moment and returns the t-CRNTI. +@param Mod_id Instance ID of eNB +@param dlsch_buffer Pointer to DLSCH input buffer +@param N_RB_UL Number of UL resource blocks +@returns t_CRNTI +*/ +uint16_t fill_rar(module_id_t module_idP, + frame_t frameP, + uint8_t *dlsch_buffer, + uint16_t N_RB_UL, + uint8_t input_buffer_length); + +/* \brief This function indicates the end of RA procedure and provides the l3msg received on ULSCH. +@param Mod_id Instance ID of eNB +@param rnti RNTI of UE transmitting l3msg +@param l3msg Pointer to received l3msg +*/ +void terminate_ra_proc(module_id_t module_idP,frame_t frameP, rnti_t rnti, uint8_t *l3msg, uint16_t l3msg_len); + +/* \brief Function to indicate a failed RA response. It removes all temporary variables related to the initial connection of a UE +@param Mod_id Instance ID of eNB +@param preamble_index index of the received RA request. +*/ +void cancel_ra_proc(module_id_t module_idP,frame_t frameP, uint16_t preamble_index); + +/* \brief Function to indicate a received SDU on ULSCH. +@param Mod_id Instance ID of eNB +@param rnti RNTI of UE transmitting the SR +@param sdu Pointer to received SDU +*/ +void rx_sdu(module_id_t module_idP, frame_t frameP, rnti_t rnti, uint8_t *sdu, uint16_t sdu_len); + +/* \brief Function to indicate a scheduled schduling request (SR) was received by eNB. +@param Mod_id Instance ID of eNB +@param rnti RNTI of UE transmitting the SR +@param subframe Index of subframe where SR was received +*/ +void SR_indication(module_id_t module_idP,frame_t frameP,rnti_t rnti, sub_frame_t subframe); + +uint8_t *get_dlsch_sdu(module_id_t module_idP,frame_t frameP,rnti_t rnti,uint8_t TBindex); + +/* \brief Function to retrieve MCH transport block and MCS used for MCH in this MBSFN subframe. Returns null if no MCH is to be transmitted +@param Mod_id Instance ID of eNB +@param frame Index of frame +@param subframe Index of current subframe +@param mcs Pointer to mcs used by PHY (to be filled by MAC) +@returns Pointer to MCH transport block and mcs for subframe +*/ +MCH_PDU *get_mch_sdu(uint8_t Mod_id,uint32_t frame,uint32_t subframe); + + +//added for ALU icic purpose +uint32_t Get_Cell_SBMap(module_id_t module_idP); +void UpdateSBnumber(module_id_t module_idP); +//end ALU's algo + + +void ue_mac_reset (module_id_t module_idP,uint8_t eNB_index); +void ue_init_mac (module_id_t module_idP); +void init_ue_sched_info(void); +void add_ue_ulsch_info (module_id_t module_idP, module_id_t ue_mod_idP, sub_frame_t subframe,UE_ULSCH_STATUS status); +void add_ue_dlsch_info (module_id_t module_idP, module_id_t ue_mod_idP, sub_frame_t subframe,UE_DLSCH_STATUS status); +module_id_t find_UE_id (module_id_t module_idP, rnti_t rnti) ; +rnti_t find_UE_RNTI (module_id_t module_idP, module_id_t ue_mod_idP); +uint8_t find_active_UEs (module_id_t module_idP); +boolean_t is_UE_active (module_id_t module_idP, module_id_t ue_mod_idP ); +uint8_t find_ulgranted_UEs(module_id_t module_idP); +uint8_t find_dlgranted_UEs(module_id_t module_idP); +uint8_t process_ue_cqi (module_id_t module_idP, module_id_t ue_mod_idP); + +int8_t find_active_UEs_with_traffic(module_id_t module_idP); + +uint8_t find_num_active_UEs_in_cbagroup(module_id_t module_idP, unsigned char group_id); +uint8_t UE_is_to_be_scheduled(module_id_t module_idP,uint8_t UE_id); +/** \brief Round-robin scheduler for ULSCH traffic. +@param Mod_id Instance ID for eNB +@param subframe Subframe number on which to act +@returns UE index that is to be scheduled if needed/room +*/ +module_id_t schedule_next_ulue(module_id_t module_idP, module_id_t ue_mod_idP,sub_frame_t subframe); + +/** \brief Round-robin scheduler for DLSCH traffic. +@param Mod_id Instance ID for eNB +@param subframe Subframe number on which to act +@returns UE index that is to be scheduled if needed/room +*/ +module_id_t schedule_next_dlue(module_id_t module_idP, sub_frame_t subframe); + +/* \brief Allocates a set of PRBS for a particular UE. This is a simple function for the moment, later it should process frequency-domain CQI information and/or PMI information. Currently it just returns the first PRBS that are available in the subframe based on the number requested. +@param UE_id Index of UE on which to act +@param nb_rb Number of PRBs allocated to UE by scheduler +@param rballoc Pointer to bit-map of current PRB allocation given to previous users/control channels. This is updated for subsequent calls to the routine. +@returns an rballoc bitmap for resource type 0 allocation (DCI). +*/ +uint32_t allocate_prbs(module_id_t ue_mod_idP,uint8_t nb_rb, uint32_t *rballoc); + +/* \fn uint32_t req_new_ulsch(module_id_t module_idP) +\brief check for a new transmission in any drb +@param Mod_id Instance id of UE in machine +@returns 1 for new transmission, 0 for none +*/ +uint32_t req_new_ulsch(module_id_t module_idP); + +/* \brief Get SR payload (0,1) from UE MAC +@param Mod_id Instance id of UE in machine +@param eNB_id Index of eNB that UE is attached to +@param rnti C_RNTI of UE +@param subframe subframe number +@returns 0 for no SR, 1 for SR +*/ +uint32_t ue_get_SR(module_id_t module_idP, frame_t frameP, uint8_t eNB_id,rnti_t rnti,sub_frame_t subframe); + +uint8_t get_ue_weight(module_id_t module_idP, module_id_t ue_mod_idP); + +// UE functions +void mac_out_of_sync_ind(module_id_t module_idP, frame_t frameP, uint16_t CH_index); + +void ue_decode_si(module_id_t module_idP, frame_t frame, uint8_t CH_index, void *pdu, uint16_t len); + + +void ue_send_sdu(module_id_t module_idP, frame_t frame, uint8_t *sdu,uint16_t sdu_len,uint8_t CH_index); + + +#ifdef Rel10 +/* \brief Called by PHY to transfer MCH transport block to ue MAC. +@param Mod_id Index of module instance +@param frame Frame index +@param sdu Pointer to transport block +@param sdu_len Length of transport block +@param eNB_index Index of attached eNB +@param sync_area the index of MBSFN sync area +*/ +void ue_send_mch_sdu(module_id_t module_idP,frame_t frameP,uint8_t *sdu,uint16_t sdu_len,uint8_t eNB_index,uint8_t sync_area) ; + +/*\brief Function to check if UE PHY needs to decode MCH for MAC. +@param Mod_id Index of protocol instance +@param frame Index of frame +@param subframe Index of subframe +@param eNB_index index of eNB for this MCH +@param[out] sync_area return the sync area +@param[out] mcch_active flag indicating whether this MCCH is active in this SF +*/ +int ue_query_mch(uint8_t Mod_id,uint32_t frame,sub_frame_t subframe, uint8_t eNB_index, uint8_t *sync_area, uint8_t *mcch_active); + +#endif + +/* \brief Called by PHY to get sdu for PUSCH transmission. It performs the following operations: Checks BSR for DCCH, DCCH1 and DTCH corresponding to previous values computed either in SR or BSR procedures. It gets rlc status indications on DCCH,DCCH1 and DTCH and forms BSR elements and PHR in MAC header. CRNTI element is not supported yet. It computes transport block for up to 3 SDUs and generates header and forms the complete MAC SDU. +@param Mod_id Instance id of UE in machine +@param eNB_id Index of eNB that UE is attached to +@param rnti C_RNTI of UE +@param subframe subframe number +@returns 0 for no SR, 1 for SR +*/ +void ue_get_sdu(module_id_t module_idP, frame_t frameP, sub_frame_t subframe, uint8_t eNB_index,uint8_t *ulsch_buffer,uint16_t buflen,uint8_t *access_mode); + +/* \brief Function called by PHY to retrieve information to be transmitted using the RA procedure. If the UE is not in PUSCH mode for a particular eNB index, this is assumed to be an Msg3 and MAC attempts to retrieves the CCCH message from RRC. If the UE is in PUSCH mode for a particular eNB index and PUCCH format 0 (Scheduling Request) is not activated, the MAC may use this resource for random-access to transmit a BSR along with the C-RNTI control element (see 5.1.4 from 36.321) +@param Mod_id Index of UE instance +@param New_Msg3 Flag to indicate this call is for a new Msg3 +@param subframe Index of subframe for PRACH transmission (0 ... 9) +@returns A pointer to a PRACH_RESOURCES_t */ +PRACH_RESOURCES_t *ue_get_rach(module_id_t module_idP,frame_t frameP,uint8_t new_Msg3,sub_frame_t subframe); + +/* \brief Function called by PHY to process the received RAR. It checks that the preamble matches what was sent by the eNB and provides the timing advance and t-CRNTI. +@param Mod_id Index of UE instance +@param dlsch_buffer Pointer to dlsch_buffer containing RAR PDU +@param t_crnti Pointer to PHY variable containing the T_CRNTI +@param preamble_index Preamble Index used by PHY to transmit the PRACH. This should match the received RAR to trigger the rest of +random-access procedure +@returns timing advance or 0xffff if preamble doesn't match +*/ +uint16_t ue_process_rar(module_id_t module_idP, frame_t frameP,uint8_t *dlsch_buffer,uint16_t *t_crnti,uint8_t preamble_index); + + +/* \brief Generate header for UL-SCH. This function parses the desired control elements and sdus and generates the header as described +in 36-321 MAC layer specifications. It returns the number of bytes used for the header to be used as an offset for the payload +in the ULSCH buffer. +@param mac_header Pointer to the first byte of the MAC header (UL-SCH buffer) +@param num_sdus Number of SDUs in the payload +@param short_padding Number of bytes for short padding (0,1,2) +@param sdu_lengths Pointer to array of SDU lengths +@param sdu_lcids Pointer to array of LCIDs (the order must be the same as the SDU length array) +@param power_headroom Pointer to power headroom command (NULL means not present in payload) +@param crnti Pointer to CRNTI command (NULL means not present in payload) +@param truncated_bsr Pointer to Truncated BSR command (NULL means not present in payload) +@param short_bsr Pointer to Short BSR command (NULL means not present in payload) +@param long_bsr Pointer to Long BSR command (NULL means not present in payload) +@param post_padding Number of bytes for padding at the end of MAC PDU +@returns Number of bytes used for header +*/ +unsigned char generate_ulsch_header(uint8_t *mac_header, + uint8_t num_sdus, + uint8_t short_padding, + uint16_t *sdu_lengths, + uint8_t *sdu_lcids, + POWER_HEADROOM_CMD *power_headroom, + uint16_t *crnti, + BSR_SHORT *truncated_bsr, + BSR_SHORT *short_bsr, + BSR_LONG *long_bsr, + unsigned short post_padding); + +/* \brief Parse header for UL-SCH. This function parses the received UL-SCH header as described +in 36-321 MAC layer specifications. It returns the number of bytes used for the header to be used as an offset for the payload +in the ULSCH buffer. +@param mac_header Pointer to the first byte of the MAC header (UL-SCH buffer) +@param num_ces Number of SDUs in the payload +@param num_sdu Number of SDUs in the payload +@param rx_ces Pointer to received CEs in the header +@param rx_lcids Pointer to array of LCIDs (the order must be the same as the SDU length array) +@param rx_lengths Pointer to array of SDU lengths +@returns Pointer to payload following header +*/ +uint8_t *parse_ulsch_header(uint8_t *mac_header, + uint8_t *num_ce, + uint8_t *num_sdu, + uint8_t *rx_ces, + uint8_t *rx_lcids, + uint16_t *rx_lengths, + uint16_t tx_lenght); + + +int l2_init(LTE_DL_FRAME_PARMS *frame_parms,int eMBMS_active, uint8_t cba_group_active, uint8_t HO_active); +int mac_init(void); +int8_t add_new_ue(module_id_t module_idP, rnti_t rnti); +int8_t mac_remove_ue(module_id_t enb_mod_idP, module_id_t ue_mod_idP); + +/*! \fn UE_L2_state_t ue_scheduler(module_id_t module_idP,frame_t frameP, sub_frame_t subframe, lte_subframe_t direction,uint8_t eNB_index) + \brief UE scheduler where all the ue background tasks are done. This function performs the following: 1) Trigger PDCP every 5ms 2) Call RRC for link status return to PHY3) Perform SR/BSR procedures for scheduling feedback 4) Perform PHR procedures. +\param[in] module_idP instance of the UE +\param[in] subframe t the subframe number +\param[in] direction subframe direction +\param[in] eNB_index instance of eNB +@returns L2 state (CONNETION_OK or CONNECTION_LOST or PHY_RESYNCH) +*/ +UE_L2_STATE_t ue_scheduler(module_id_t module_idP,frame_t frameP, sub_frame_t subframe, lte_subframe_t direction,uint8_t eNB_index); + +/*! \fn int use_cba_access(module_id_t module_idP,frame_t frameP,sub_frame_t subframe, uint8_t eNB_index); +\brief determine whether to use cba resource to transmit or not +\param[in] Mod_id instance of the UE +\param[in] frame the frame number +\param[in] subframe the subframe number +\param[in] eNB_index instance of eNB +\param[out] access(1) or postpone (0) +*/ +int use_cba_access(module_id_t module_idP,frame_t frameP,sub_frame_t subframe, uint8_t eNB_index); + +/*! \fn int get_bsr_lcgid (module_id_t module_idP); +\brief determine the lcgid for the bsr +\param[in] Mod_id instance of the UE +\param[out] lcgid +*/ +int get_bsr_lcgid (module_id_t module_idP); + +/*! \fn uint8_t get_bsr_len (module_id_t module_idP, uint16_t bufflen); +\brief determine whether the bsr is short or long assuming that the MAC pdu is built +\param[in] Mod_id instance of the UE +\param[in] bufflen size of phy transport block +\param[out] bsr_len size of bsr control element +*/ +uint8_t get_bsr_len (module_id_t module_idP, uint16_t buflen); + +/*! \fn BSR_SHORT * get_bsr_short(module_id_t module_idP, uint8_t bsr_len) +\brief get short bsr level +\param[in] Mod_id instance of the UE +\param[in] bsr_len indicator for no, short, or long bsr +\param[out] bsr_s pointer to short bsr +*/ +BSR_SHORT *get_bsr_short(module_id_t module_idP, uint8_t bsr_len); + +/*! \fn BSR_LONG * get_bsr_long(module_id_t module_idP, uint8_t bsr_len) +\brief get long bsr level +\param[in] Mod_id instance of the UE +\param[in] bsr_len indicator for no, short, or long bsr +\param[out] bsr_l pointer to long bsr +*/ +BSR_LONG * get_bsr_long(module_id_t module_idP, uint8_t bsr_len); + +/*! \fn boolean_t update_bsr(module_id_t module_idP, frame_t frameP, uint8_t lcid) + \brief get the rlc stats and update the bsr level for each lcid +\param[in] Mod_id instance of the UE +\param[in] frame Frame index +\param[in] lcid logical channel identifier +*/ +boolean_t update_bsr(module_id_t module_idP, frame_t frameP, uint8_t lcid, uint8_t lcgid); + +/*! \fn locate (int *table, int size, int value) + \brief locate the BSR level in the table as defined in 36.321. This function requires that he values in table to be monotonic, either increasing or decreasing. The returned value is not less than 0, nor greater than n-1, where n is the size of table. +\param[in] *table Pointer to BSR table +\param[in] size Size of the table +\param[in] value Value of the buffer +\return the index in the BSR_LEVEL table +*/ +uint8_t locate (const uint32_t *table, int size, int value); + + +/*! \fn int get_sf_periodicBSRTimer(uint8_t periodicBSR_Timer) + \brief get the number of subframe from the periodic BSR timer configured by the higher layers +\param[in] periodicBSR_Timer timer for periodic BSR +\return the number of subframe +*/ +int get_sf_periodicBSRTimer(uint8_t bucketSize); + +/*! \fn int get_ms_bucketsizeduration(uint8_t bucketSize) + \brief get the time in ms form the bucket size duration configured by the higher layer +\param[in] bucketSize the bucket size duration +\return the time in ms +*/ +int get_ms_bucketsizeduration(uint8_t bucketsizeduration); + +/*! \fn int get_sf_retxBSRTimer(uint8_t retxBSR_Timer) + \brief get the number of subframe form the bucket size duration configured by the higher layer +\param[in] retxBSR_Timer timer for regular BSR +\return the time in sf +*/ +int get_sf_retxBSRTimer(uint8_t retxBSR_Timer); + +/*! \fn int get_sf_perioidicPHR_Timer(uint8_t perioidicPHR_Timer){ + \brief get the number of subframe form the periodic PHR timer configured by the higher layer +\param[in] perioidicPHR_Timer timer for reguluar PHR +\return the time in sf +*/ +int get_sf_perioidicPHR_Timer(uint8_t perioidicPHR_Timer); + +/*! \fn int get_sf_prohibitPHR_Timer(uint8_t prohibitPHR_Timer) + \brief get the number of subframe form the prohibit PHR duration configured by the higher layer +\param[in] prohibitPHR_Timer timer for PHR +\return the time in sf +*/ +int get_sf_prohibitPHR_Timer(uint8_t prohibitPHR_Timer); + +/*! \fn int get_db_dl_PathlossChange(uint8_t dl_PathlossChange) + \brief get the db form the path loss change configured by the higher layer +\param[in] dl_PathlossChange path loss for PHR +\return the pathloss in db +*/ +int get_db_dl_PathlossChange(uint8_t dl_PathlossChange); + +/*! \fn uint8_t get_phr_mapping (module_id_t module_idP, uint8_t eNB_index) + \brief get phr mapping as described in 36.313 +\param[in] Mod_id index of eNB +\return phr mapping +*/ +uint8_t get_phr_mapping (module_id_t module_idP, uint8_t eNB_index); + +/*! \fn void update_phr (module_id_t module_idP) + \brief update/reset the phr timers +\param[in] Mod_id index of eNB +\return void +*/ +void update_phr (module_id_t module_idP); + +/*! \brief Function to indicate Msg3 transmission/retransmission which initiates/reset Contention Resolution Timer +\param[in] Mod_id Instance index of UE +\param[in] eNB_id Index of eNB +*/ +void Msg3_tx(module_id_t module_idP,frame_t frameP,uint8_t eNB_id); + + +/*! \brief Function to indicate the transmission of msg1/rach +\param[in] Mod_id Instance index of UE +\param[in] eNB_id Index of eNB +*/ + +void Msg1_tx(module_id_t module_idP,frame_t frameP, uint8_t eNB_id); + +void dl_phy_sync_success(module_id_t module_idP, + frame_t frameP, + unsigned char eNB_index, + uint8_t first_sync); + +int dump_eNB_l2_stats(char *buffer, int length); + +double uniform_rngen(int min, int max); + + +void add_common_dci(DCI_PDU *DCI_pdu, + void *pdu, + rnti_t rnti, + unsigned char dci_size_bytes, + unsigned char aggregation, + unsigned char dci_size_bits, + unsigned char dci_fmt, + uint8_t ra_flag); + +uint32_t allocate_prbs_sub(int nb_rb, uint8_t *rballoc); + +void update_ul_dci(module_id_t module_idP,rnti_t rnti,uint8_t dai); +#endif diff --git a/openair2/LAYER2/MAC/ra_procedures.c b/openair2/LAYER2/MAC/ra_procedures.c index 8cd72af2e2..e3dc6a7fac 100644 --- a/openair2/LAYER2/MAC/ra_procedures.c +++ b/openair2/LAYER2/MAC/ra_procedures.c @@ -29,17 +29,19 @@ /*! \file openair2/LAYER2/MAC/ra_procedures.c * \brief Routines for UE MAC-layer Random-access procedures (36.321) V8.6 2009-03 - * \author R. Knopp + * \author R. Knopp and navid nikaein * \date 2011 * \version 0.1 * \company Eurecom - * \email: knopp@eurecom.fr + * \email: knopp@eurecom.fr and navid nikaein * \note * \warning */ #include "extern.h" #include "defs.h" +#include "proto.h" +#include "UTIL/LOG/vcd_signal_dumper.h" #include "PHY_INTERFACE/defs.h" #include "PHY_INTERFACE/extern.h" #include "COMMON/mac_rrc_primitives.h" @@ -401,3 +403,648 @@ PRACH_RESOURCES_t *ue_get_rach(module_id_t module_idP,frame_t frameP, uint8_t eN } return(NULL); } + +void cancel_ra_proc(module_id_t module_idP, frame_t frameP, rnti_t rnti) { + unsigned char i; + LOG_I(MAC,"[eNB %d][RAPROC] Frame %d Cancelling RA procedure for UE rnti %x\n",module_idP,frameP,rnti); + + for (i=0;i<NB_RA_PROC_MAX;i++) { + if (rnti == eNB_mac_inst[module_idP].RA_template[i].rnti) { + eNB_mac_inst[module_idP].RA_template[i].RA_active=FALSE; + eNB_mac_inst[module_idP].RA_template[i].generate_rar=0; + eNB_mac_inst[module_idP].RA_template[i].generate_Msg4=0; + eNB_mac_inst[module_idP].RA_template[i].wait_ack_Msg4=0; + eNB_mac_inst[module_idP].RA_template[i].timing_offset=0; + eNB_mac_inst[module_idP].RA_template[i].RRC_timer=20; + eNB_mac_inst[module_idP].RA_template[i].rnti = 0; + } + } +} + +void terminate_ra_proc(module_id_t module_idP,frame_t frameP,rnti_t rnti,unsigned char *msg3, uint16_t msg3_len) { + + unsigned char rx_ces[MAX_NUM_CE],num_ce,num_sdu,i,*payload_ptr; + unsigned char rx_lcids[NB_RB_MAX]; + uint16_t rx_lengths[NB_RB_MAX]; + int8_t UE_id; + + LOG_I(MAC,"[eNB %d][RAPROC] Frame %d, Received msg3 %x.%x.%x.%x.%x.%x, Terminating RA procedure for UE rnti %x\n", + module_idP,frameP, + msg3[3],msg3[4],msg3[5],msg3[6],msg3[7], msg3[8], rnti); + + for (i=0;i<NB_RA_PROC_MAX;i++) { + LOG_D(MAC,"[RAPROC] Checking proc %d : rnti (%x, %x), active %d\n",i, + eNB_mac_inst[module_idP].RA_template[i].rnti, rnti, + eNB_mac_inst[module_idP].RA_template[i].RA_active); + if ((eNB_mac_inst[module_idP].RA_template[i].rnti==rnti) && + (eNB_mac_inst[module_idP].RA_template[i].RA_active==TRUE)) { + + payload_ptr = parse_ulsch_header(msg3,&num_ce,&num_sdu,rx_ces,rx_lcids,rx_lengths,msg3_len); + LOG_D(MAC,"[eNB %d][RAPROC] Frame %d Received CCCH: length %d, offset %d\n", + module_idP,frameP,rx_lengths[0],payload_ptr-msg3); + if (/*(num_ce == 0) &&*/ (num_sdu==1) && (rx_lcids[0] == CCCH)) { // This is an RRCConnectionRequest/Restablishment + memcpy(&eNB_mac_inst[module_idP].RA_template[i].cont_res_id[0],payload_ptr,6); + LOG_D(MAC,"[eNB %d][RAPROC] Frame %d Received CCCH: length %d, offset %d\n", + module_idP,frameP,rx_lengths[0],payload_ptr-msg3); + UE_id=add_new_ue(module_idP,eNB_mac_inst[module_idP].RA_template[i].rnti); + if (UE_id==-1) { + mac_xface->macphy_exit("[MAC][eNB] Max user count reached\n"); + } + else { + LOG_I(MAC,"[eNB %d][RAPROC] Frame %d Added user with rnti %x => UE %d\n", + module_idP,frameP,eNB_mac_inst[module_idP].RA_template[i].rnti,UE_id); + } + + if (Is_rrc_registered == 1) + mac_rrc_data_ind(module_idP,frameP,CCCH,(uint8_t *)payload_ptr,rx_lengths[0],1,module_idP,0); + // add_user. This is needed to have the rnti for configuring UE (PHY). The UE is removed if RRC + // doesn't provide a CCCH SDU + + } + else if (num_ce >0) { // handle msg3 which is not RRCConnectionRequest + // process_ra_message(msg3,num_ce,rx_lcids,rx_ces); + } + + eNB_mac_inst[module_idP].RA_template[i].generate_Msg4 = 1; + eNB_mac_inst[module_idP].RA_template[i].wait_ack_Msg4 = 0; + + return; + } // if process is active + + } // loop on RA processes +} + +void rx_sdu(module_id_t enb_mod_idP,frame_t frameP,rnti_t rntiP,uint8_t *sdu, uint16_t sdu_len) { + + unsigned char rx_ces[MAX_NUM_CE],num_ce,num_sdu,i,*payload_ptr; + unsigned char rx_lcids[NB_RB_MAX]; + unsigned short rx_lengths[NB_RB_MAX]; + module_id_t ue_mod_id = find_UE_id(enb_mod_idP,rntiP); + int ii,j; + start_meas(&eNB_mac_inst[enb_mod_idP].rx_ulsch_sdu); + + if ((ue_mod_id > NUMBER_OF_UE_MAX) || (ue_mod_id == -1) || (ue_mod_id == 255) ) + + for(ii=0; ii<NB_RB_MAX; ii++) rx_lengths[ii] = 0; + + vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_RX_SDU,1); + + LOG_D(MAC,"[eNB %d] Received ULSCH sdu from PHY (rnti %x, UE_id %d), parsing header\n",enb_mod_idP,rntiP,ue_mod_id); + payload_ptr = parse_ulsch_header(sdu,&num_ce,&num_sdu,rx_ces,rx_lcids,rx_lengths,sdu_len); + + // control element + for (i=0;i<num_ce;i++) { + + switch (rx_ces[i]) { // implement and process BSR + CRNTI + + case POWER_HEADROOM: + if (ue_mod_id != UE_INDEX_INVALID ){ + eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].phr_info = (payload_ptr[0] & 0x3f);// - PHR_MAPPING_OFFSET; + LOG_D(MAC, "[eNB] MAC CE_LCID %d : Received PHR PH = %d (db)\n", rx_ces[i], eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].phr_info); + } + payload_ptr+=sizeof(POWER_HEADROOM_CMD); + break; + case CRNTI: + LOG_D(MAC, "[eNB] MAC CE_LCID %d : Received CRNTI %d \n", rx_ces[i], payload_ptr[0]); + payload_ptr+=1; + break; + case TRUNCATED_BSR: + case SHORT_BSR: { + if (ue_mod_id != UE_INDEX_INVALID ){ + uint8_t lcgid; + lcgid = (payload_ptr[0] >> 6); + LOG_D(MAC, "[eNB] MAC CE_LCID %d : Received short BSR LCGID = %u bsr = %d\n", + rx_ces[i], lcgid, payload_ptr[0] & 0x3f); + eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].bsr_info[lcgid] = (payload_ptr[0] & 0x3f); + } + payload_ptr += 1;//sizeof(SHORT_BSR); // fixme + } break; + case LONG_BSR: + if (ue_mod_id != UE_INDEX_INVALID ){ + eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].bsr_info[LCGID0] = ((payload_ptr[0] & 0xFC) >> 2); + eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].bsr_info[LCGID1] = + ((payload_ptr[0] & 0x03) << 4) | ((payload_ptr[1] & 0xF0) >> 4); + eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].bsr_info[LCGID2] = + ((payload_ptr[1] & 0x0F) << 2) | ((payload_ptr[2] & 0xC0) >> 6); + eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].bsr_info[LCGID3] = (payload_ptr[2] & 0x3F); + LOG_D(MAC, "[eNB] MAC CE_LCID %d: Received long BSR LCGID0 = %u LCGID1 = " + "%u LCGID2 = %u LCGID3 = %u\n", + rx_ces[i], + eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].bsr_info[LCGID0], + eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].bsr_info[LCGID1], + eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].bsr_info[LCGID2], + eNB_mac_inst[enb_mod_idP].UE_template[ue_mod_id].bsr_info[LCGID3]); + } + payload_ptr += 3;////sizeof(LONG_BSR); + break; + default: + LOG_E(MAC, "[eNB] Received unknown MAC header (0x%02x)\n", rx_ces[i]); + break; + } + } + + for (i=0;i<num_sdu;i++) { + LOG_D(MAC,"SDU Number %d MAC Subheader SDU_LCID %d, length %d\n",i,rx_lcids[i],rx_lengths[i]); + + switch (rx_lcids[i]) { + case CCCH : + LOG_I(MAC,"[eNB %d][RAPROC] Frame %d, Received CCCH: %x.%x.%x.%x.%x.%x, Terminating RA procedure for UE rnti %x\n", + enb_mod_idP,frameP, + payload_ptr[0],payload_ptr[1],payload_ptr[2],payload_ptr[3],payload_ptr[4], payload_ptr[5], rntiP); + + for (ii=0;ii<NB_RA_PROC_MAX;ii++) { + LOG_D(MAC,"[RAPROC] Checking proc %d : rnti (%x, %x), active %d\n",ii, + eNB_mac_inst[enb_mod_idP].RA_template[ii].rnti, rntiP, + eNB_mac_inst[enb_mod_idP].RA_template[ii].RA_active); + + if ((eNB_mac_inst[enb_mod_idP].RA_template[ii].rnti==rntiP) && + (eNB_mac_inst[enb_mod_idP].RA_template[ii].RA_active==TRUE)) { + + //payload_ptr = parse_ulsch_header(msg3,&num_ce,&num_sdu,rx_ces,rx_lcids,rx_lengths,msg3_len); + + if (ue_mod_id == UE_INDEX_INVALID) { + memcpy(&eNB_mac_inst[enb_mod_idP].RA_template[ii].cont_res_id[0],payload_ptr,6); + LOG_I(MAC,"[eNB %d][RAPROC] Frame %d CCCH: Received RRCConnectionRequest: length %d, offset %d\n", + enb_mod_idP,frameP,rx_lengths[ii],payload_ptr-sdu); + if ((ue_mod_id=add_new_ue(enb_mod_idP,eNB_mac_inst[enb_mod_idP].RA_template[ii].rnti)) == -1 ) + mac_xface->macphy_exit("[MAC][eNB] Max user count reached\n"); + else + LOG_I(MAC,"[eNB %d][RAPROC] Frame %d Added user with rnti %x => UE %d\n", + enb_mod_idP,frameP,eNB_mac_inst[enb_mod_idP].RA_template[ii].rnti,ue_mod_id); + } else { + LOG_I(MAC,"[eNB %d][RAPROC] Frame %d CCCH: Received RRCConnectionReestablishment from UE %d: length %d, offset %d\n", + enb_mod_idP,frameP,ue_mod_id,rx_lengths[ii],payload_ptr-sdu); + } + + if (Is_rrc_registered == 1) + mac_rrc_data_ind(enb_mod_idP,frameP,CCCH,(uint8_t *)payload_ptr,rx_lengths[ii],1,enb_mod_idP,0); + + + if (num_ce >0) { // handle msg3 which is not RRCConnectionRequest + // process_ra_message(msg3,num_ce,rx_lcids,rx_ces); + } + + eNB_mac_inst[enb_mod_idP].RA_template[ii].generate_Msg4 = 1; + eNB_mac_inst[enb_mod_idP].RA_template[ii].wait_ack_Msg4 = 0; + + + } // if process is active + + } // loop on RA processes + + break; + case DCCH : + case DCCH1 : + // if(eNB_mac_inst[module_idP].Dcch_lchan[UE_id].Active==1){ + +#if defined(ENABLE_MAC_PAYLOAD_DEBUG) + LOG_T(MAC,"offset: %d\n",(unsigned char)((unsigned char*)payload_ptr-sdu)); + for (j=0;j<32;j++) + LOG_T(MAC,"%x ",payload_ptr[j]); + LOG_T(MAC,"\n"); +#endif + + // This check is just to make sure we didn't get a bogus SDU length, to be removed ... + if (rx_lengths[i]<CCCH_PAYLOAD_SIZE_MAX) { + LOG_D(MAC,"[eNB %d] Frame %d : ULSCH -> UL-DCCH, received %d bytes form UE %d on LCID %d(%d) \n", + enb_mod_idP,frameP, rx_lengths[i], ue_mod_id, rx_lcids[i], rx_lcids[i]); + + mac_rlc_data_ind(enb_mod_idP,ue_mod_id, frameP,ENB_FLAG_YES,MBMS_FLAG_NO, + rx_lcids[i], + (char *)payload_ptr, + rx_lengths[i], + 1, + NULL);//(unsigned int*)crc_status); + eNB_mac_inst[enb_mod_idP].eNB_UE_stats[ue_mod_id].num_pdu_rx[rx_lcids[i]]+=1; + eNB_mac_inst[enb_mod_idP].eNB_UE_stats[ue_mod_id].num_bytes_rx[rx_lcids[i]]+=rx_lengths[i]; + + } + // } + break; + case DTCH: // default DRB + // if(eNB_mac_inst[module_idP].Dcch_lchan[UE_id].Active==1){ + +#if defined(ENABLE_MAC_PAYLOAD_DEBUG) + LOG_T(MAC,"offset: %d\n",(unsigned char)((unsigned char*)payload_ptr-sdu)); + for (j=0;j<32;j++) + LOG_T(MAC,"%x ",payload_ptr[j]); + LOG_T(MAC,"\n"); +#endif + + LOG_D(MAC,"[eNB %d] Frame %d : ULSCH -> UL-DTCH, received %d bytes from UE %d for lcid %d (%d)\n", + enb_mod_idP,frameP, rx_lengths[i], ue_mod_id,rx_lcids[i],rx_lcids[i]); + + if ((rx_lengths[i] <SCH_PAYLOAD_SIZE_MAX) && (rx_lengths[i] > 0) ) { // MAX SIZE OF transport block + mac_rlc_data_ind(enb_mod_idP,ue_mod_id, frameP,ENB_FLAG_YES,MBMS_FLAG_NO, + DTCH, + (char *)payload_ptr, + rx_lengths[i], + 1, + NULL);//(unsigned int*)crc_status); + eNB_mac_inst[enb_mod_idP].eNB_UE_stats[ue_mod_id].num_pdu_rx[rx_lcids[i]]+=1; + eNB_mac_inst[enb_mod_idP].eNB_UE_stats[ue_mod_id].num_bytes_rx[rx_lcids[i]]+=rx_lengths[i]; + + } + // } + break; + default : //if (rx_lcids[i] >= DTCH) { + eNB_mac_inst[enb_mod_idP].eNB_UE_stats[ue_mod_id].num_errors_rx+=1; + LOG_E(MAC,"[eNB %d] received unsupported or unknown LCID %d from UE %d ", rx_lcids[i], ue_mod_id); + break; + } + payload_ptr+=rx_lengths[i]; + + } + + eNB_mac_inst[enb_mod_idP].eNB_UE_stats[ue_mod_id].total_pdu_bytes_rx+=sdu_len; + eNB_mac_inst[enb_mod_idP].eNB_UE_stats[ue_mod_id].total_num_pdus_rx+=1; + + vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_RX_SDU,0); + stop_meas(&eNB_mac_inst[enb_mod_idP].rx_ulsch_sdu); +} + +// First stage of Random-Access Scheduling +void schedule_RA(module_id_t module_idP,frame_t frameP, sub_frame_t subframeP,unsigned char Msg3_subframe,unsigned char *nprb,unsigned int *nCCE) { + + start_meas(&eNB_mac_inst[module_idP].schedule_ra); + RA_TEMPLATE *RA_template = (RA_TEMPLATE *)&eNB_mac_inst[module_idP].RA_template[0]; + unsigned char i;//,harq_pid,round; + uint16_t rrc_sdu_length; + unsigned char lcid,offset; + module_id_t UE_id= UE_INDEX_INVALID; + unsigned short TBsize = -1; + unsigned short msg4_padding,msg4_post_padding,msg4_header; + + for (i=0;i<NB_RA_PROC_MAX;i++) { + + if (RA_template[i].RA_active == TRUE) { + + LOG_I(MAC,"[eNB %d][RAPROC] RA %d is active (generate RAR %d, generate_Msg4 %d, wait_ack_Msg4 %d, rnti %x)\n", + module_idP,i,RA_template[i].generate_rar,RA_template[i].generate_Msg4,RA_template[i].wait_ack_Msg4, RA_template[i].rnti); + + if (RA_template[i].generate_rar == 1) { + *nprb= (*nprb) + 3; + *nCCE = (*nCCE) + 4; + RA_template[i].Msg3_subframe=Msg3_subframe; + } + else if (RA_template[i].generate_Msg4 == 1) { + + // check for Msg4 Message + UE_id = find_UE_id(module_idP,RA_template[i].rnti); + if (Is_rrc_registered == 1) { + + // Get RRCConnectionSetup for Piggyback + rrc_sdu_length = mac_rrc_data_req(module_idP, + frameP, + CCCH,1, + &eNB_mac_inst[module_idP].CCCH_pdu.payload[0], + 1, + module_idP, + 0); // not used in this case + if (rrc_sdu_length == -1) + mac_xface->macphy_exit("[MAC][eNB Scheduler] CCCH not allocated\n"); + else { + //msg("[MAC][eNB %d] Frame %d, subframeP %d: got %d bytes from RRC\n",module_idP,frameP, subframeP,rrc_sdu_length); + } + } + + LOG_I(MAC,"[eNB %d][RAPROC] Frame %d, subframeP %d: UE_id %d, Is_rrc_registered %d, rrc_sdu_length %d\n", + module_idP,frameP, subframeP,UE_id, Is_rrc_registered,rrc_sdu_length); + + if (rrc_sdu_length>0) { + LOG_I(MAC,"[eNB %d][RAPROC] Frame %d, subframeP %d: Generating Msg4 with RRC Piggyback (RA proc %d, RNTI %x)\n", + module_idP,frameP, subframeP,i,RA_template[i].rnti); + + //msg("[MAC][eNB %d][RAPROC] Frame %d, subframeP %d: Received %d bytes for Msg4: \n",module_idP,frameP,subframeP,rrc_sdu_length); + // for (j=0;j<rrc_sdu_length;j++) + // msg("%x ",(unsigned char)eNB_mac_inst[module_idP].CCCH_pdu.payload[j]); + // msg("\n"); + // msg("[MAC][eNB] Frame %d, subframeP %d: Generated DLSCH (Msg4) DCI, format 1A, for UE %d\n",frameP, subframeP,UE_id); + // Schedule Reflection of Connection request + + + + // Compute MCS for 3 PRB + msg4_header = 1+6+1; // CR header, CR CE, SDU header + + if (mac_xface->lte_frame_parms->frame_type == TDD) { + + switch (mac_xface->lte_frame_parms->N_RB_DL) { + case 6: + ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->ndi=1; + + if ((rrc_sdu_length+msg4_header) <= 22) { + ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=4; + TBsize = 22; + } + else if ((rrc_sdu_length+msg4_header) <= 28) { + ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=5; + TBsize = 28; + } + else if ((rrc_sdu_length+msg4_header) <= 32) { + ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=6; + TBsize = 32; + } + else if ((rrc_sdu_length+msg4_header) <= 41) { + ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=7; + TBsize = 41; + } + else if ((rrc_sdu_length+msg4_header) <= 49) { + ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=8; + TBsize = 49; + } + else if ((rrc_sdu_length+msg4_header) <= 57) { + ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=9; + TBsize = 57; + } + break; + case 25: + + ((DCI1A_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->ndi=1; + + if ((rrc_sdu_length+msg4_header) <= 22) { + ((DCI1A_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=4; + TBsize = 22; + } + else if ((rrc_sdu_length+msg4_header) <= 28) { + ((DCI1A_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=5; + TBsize = 28; + } + else if ((rrc_sdu_length+msg4_header) <= 32) { + ((DCI1A_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=6; + TBsize = 32; + } + else if ((rrc_sdu_length+msg4_header) <= 41) { + ((DCI1A_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=7; + TBsize = 41; + } + else if ((rrc_sdu_length+msg4_header) <= 49) { + ((DCI1A_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=8; + TBsize = 49; + } + else if ((rrc_sdu_length+msg4_header) <= 57) { + ((DCI1A_5MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=9; + TBsize = 57; + } + break; + case 50: + + ((DCI1A_10MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->ndi=1; + + if ((rrc_sdu_length+msg4_header) <= 22) { + ((DCI1A_10MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=4; + TBsize = 22; + } + else if ((rrc_sdu_length+msg4_header) <= 28) { + ((DCI1A_10MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=5; + TBsize = 28; + } + else if ((rrc_sdu_length+msg4_header) <= 32) { + ((DCI1A_10MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=6; + TBsize = 32; + } + else if ((rrc_sdu_length+msg4_header) <= 41) { + ((DCI1A_10MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=7; + TBsize = 41; + } + else if ((rrc_sdu_length+msg4_header) <= 49) { + ((DCI1A_10MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=8; + TBsize = 49; + } + else if ((rrc_sdu_length+msg4_header) <= 57) { + ((DCI1A_10MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=9; + TBsize = 57; + } + break; + case 100: + + ((DCI1A_20MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->ndi=1; + + if ((rrc_sdu_length+msg4_header) <= 22) { + ((DCI1A_20MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=4; + TBsize = 22; + } + else if ((rrc_sdu_length+msg4_header) <= 28) { + ((DCI1A_20MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=5; + TBsize = 28; + } + else if ((rrc_sdu_length+msg4_header) <= 32) { + ((DCI1A_20MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=6; + TBsize = 32; + } + else if ((rrc_sdu_length+msg4_header) <= 41) { + ((DCI1A_20MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=7; + TBsize = 41; + } + else if ((rrc_sdu_length+msg4_header) <= 49) { + ((DCI1A_20MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=8; + TBsize = 49; + } + else if ((rrc_sdu_length+msg4_header) <= 57) { + ((DCI1A_20MHz_TDD_1_6_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=9; + TBsize = 57; + } + break; + } + } + else { // FDD DCI + switch (mac_xface->lte_frame_parms->N_RB_DL) { + case 6: + ((DCI1A_1_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->ndi=1; + + if ((rrc_sdu_length+msg4_header) <= 22) { + ((DCI1A_1_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=4; + TBsize = 22; + } + else if ((rrc_sdu_length+msg4_header) <= 28) { + ((DCI1A_1_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=5; + TBsize = 28; + } + else if ((rrc_sdu_length+msg4_header) <= 32) { + ((DCI1A_1_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=6; + TBsize = 32; + } + else if ((rrc_sdu_length+msg4_header) <= 41) { + ((DCI1A_1_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=7; + TBsize = 41; + } + else if ((rrc_sdu_length+msg4_header) <= 49) { + ((DCI1A_1_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=8; + TBsize = 49; + } + else if ((rrc_sdu_length+msg4_header) <= 57) { + ((DCI1A_1_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=9; + TBsize = 57; + } + break; + case 25: + ((DCI1A_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->ndi=1; + + if ((rrc_sdu_length+msg4_header) <= 22) { + ((DCI1A_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=4; + TBsize = 22; + } + else if ((rrc_sdu_length+msg4_header) <= 28) { + ((DCI1A_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=5; + TBsize = 28; + } + else if ((rrc_sdu_length+msg4_header) <= 32) { + ((DCI1A_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=6; + TBsize = 32; + } + else if ((rrc_sdu_length+msg4_header) <= 41) { + ((DCI1A_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=7; + TBsize = 41; + } + else if ((rrc_sdu_length+msg4_header) <= 49) { + ((DCI1A_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=8; + TBsize = 49; + } + else if ((rrc_sdu_length+msg4_header) <= 57) { + ((DCI1A_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=9; + TBsize = 57; + } + break; + case 50: + ((DCI1A_10MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->ndi=1; + + if ((rrc_sdu_length+msg4_header) <= 22) { + ((DCI1A_10MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=4; + TBsize = 22; + } + else if ((rrc_sdu_length+msg4_header) <= 28) { + ((DCI1A_10MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=5; + TBsize = 28; + } + else if ((rrc_sdu_length+msg4_header) <= 32) { + ((DCI1A_10MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=6; + TBsize = 32; + } + else if ((rrc_sdu_length+msg4_header) <= 41) { + ((DCI1A_10MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=7; + TBsize = 41; + } + else if ((rrc_sdu_length+msg4_header) <= 49) { + ((DCI1A_10MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=8; + TBsize = 49; + } + else if ((rrc_sdu_length+msg4_header) <= 57) { + ((DCI1A_5MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=9; + TBsize = 57; + } + break; + case 100: + ((DCI1A_20MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->ndi=1; + + if ((rrc_sdu_length+msg4_header) <= 22) { + ((DCI1A_20MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=4; + TBsize = 22; + } + else if ((rrc_sdu_length+msg4_header) <= 28) { + ((DCI1A_20MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=5; + TBsize = 28; + } + else if ((rrc_sdu_length+msg4_header) <= 32) { + ((DCI1A_20MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=6; + TBsize = 32; + } + else if ((rrc_sdu_length+msg4_header) <= 41) { + ((DCI1A_20MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=7; + TBsize = 41; + } + else if ((rrc_sdu_length+msg4_header) <= 49) { + ((DCI1A_20MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=8; + TBsize = 49; + } + else if ((rrc_sdu_length+msg4_header) <= 57) { + ((DCI1A_20MHz_FDD_t*)&RA_template[i].RA_alloc_pdu2[0])->mcs=9; + TBsize = 57; + } + break; + } + } + RA_template[i].generate_Msg4=0; + RA_template[i].generate_Msg4_dci=1; + RA_template[i].wait_ack_Msg4=1; + RA_template[i].RA_active = FALSE; + lcid=0; + + if ((TBsize - rrc_sdu_length - msg4_header) <= 2) { + msg4_padding = TBsize - rrc_sdu_length - msg4_header; + msg4_post_padding = 0; + } + else { + msg4_padding = 0; + msg4_post_padding = TBsize - rrc_sdu_length - msg4_header -1; + } + LOG_I(MAC,"[eNB %d][RAPROC] Frame %d subframeP %d Msg4 : TBS %d, sdu_len %d, msg4_header %d, msg4_padding %d, msg4_post_padding %d\n", + module_idP,frameP,subframeP,TBsize,rrc_sdu_length,msg4_header,msg4_padding,msg4_post_padding); + offset = generate_dlsch_header((unsigned char*)eNB_mac_inst[module_idP].DLSCH_pdu[(unsigned char)UE_id][0].payload[0], + 1, //num_sdus + &rrc_sdu_length, // + &lcid, // sdu_lcid + 255, // no drx + 0, // no timing advance + RA_template[i].cont_res_id, // contention res id + msg4_padding, // no padding + msg4_post_padding); + + memcpy((void*)&eNB_mac_inst[module_idP].DLSCH_pdu[(unsigned char)UE_id][0].payload[0][(unsigned char)offset], + &eNB_mac_inst[module_idP].CCCH_pdu.payload[0], + rrc_sdu_length); + +#if defined(USER_MODE) && defined(OAI_EMU) + if (oai_emulation.info.opt_enabled){ + trace_pdu(1, (uint8_t *)eNB_mac_inst[module_idP].DLSCH_pdu[(unsigned char)UE_id][0].payload[0], + rrc_sdu_length, UE_id, 3, find_UE_RNTI(module_idP, UE_id), + eNB_mac_inst[module_idP].subframe,0,0); + LOG_D(OPT,"[eNB %d][DLSCH] Frame %d trace pdu for rnti %x with size %d\n", + module_idP, frameP, find_UE_RNTI(module_idP,UE_id), rrc_sdu_length); + } +#endif + *nprb= (*nprb) + 3; + *nCCE = (*nCCE) + 4; + } + //try here + } + /* + else if (eNB_mac_inst[module_idP].RA_template[i].wait_ack_Msg4==1) { + // check HARQ status and retransmit if necessary + LOG_I(MAC,"[eNB %d][RAPROC] Frame %d, subframeP %d: Checking if Msg4 was acknowledged :\n",module_idP,frameP,subframeP); + // Get candidate harq_pid from PHY + mac_xface->get_ue_active_harq_pid(module_idP,eNB_mac_inst[module_idP].RA_template[i].rnti,subframeP,&harq_pid,&round,0); + if (round>0) { + *nprb= (*nprb) + 3; + *nCCE = (*nCCE) + 4; + } + } + */ + } + } + stop_meas(&eNB_mac_inst[module_idP].schedule_ra); +} + +void initiate_ra_proc(module_id_t module_idP, frame_t frameP, uint16_t preamble_index,int16_t timing_offset,uint8_t sect_id,sub_frame_t subframeP,uint8_t f_id) { + + uint8_t i; + + LOG_I(MAC,"[eNB %d][RAPROC] Frame %d Initiating RA procedure for preamble index %d\n",module_idP,frameP,preamble_index); + + for (i=0;i<NB_RA_PROC_MAX;i++) { + if (eNB_mac_inst[module_idP].RA_template[i].RA_active==FALSE) { + eNB_mac_inst[module_idP].RA_template[i].RA_active=TRUE; + eNB_mac_inst[module_idP].RA_template[i].generate_rar=1; + eNB_mac_inst[module_idP].RA_template[i].generate_Msg4=0; + eNB_mac_inst[module_idP].RA_template[i].wait_ack_Msg4=0; + eNB_mac_inst[module_idP].RA_template[i].timing_offset=timing_offset; + // Put in random rnti (to be replaced with proper procedure!!) + eNB_mac_inst[module_idP].RA_template[i].rnti = taus(); + eNB_mac_inst[module_idP].RA_template[i].RA_rnti = 1+subframeP+(10*f_id); + eNB_mac_inst[module_idP].RA_template[i].preamble_index = preamble_index; + LOG_D(MAC,"[eNB %d][RAPROC] Frame %d Activating RAR generation for process %d, rnti %x, RA_active %d\n", + module_idP,frameP,i,eNB_mac_inst[module_idP].RA_template[i].rnti, + eNB_mac_inst[module_idP].RA_template[i].RA_active); + + return; + } + } +} diff --git a/openair2/LAYER2/MAC/rar_tools.c b/openair2/LAYER2/MAC/rar_tools.c index ed89661506..125d63579f 100644 --- a/openair2/LAYER2/MAC/rar_tools.c +++ b/openair2/LAYER2/MAC/rar_tools.c @@ -28,14 +28,15 @@ *******************************************************************************/ /*! \file rar_tools.c * \brief random access tools - * \author Raymond Knopp - * \date 2011 + * \author Raymond Knopp and navid nikaein + * \date 2011 - 2014 * \version 0.5 * @ingroup _mac */ #include "defs.h" +#include "proto.h" #include "extern.h" #include "MAC_INTERFACE/defs.h" #include "MAC_INTERFACE/extern.h" diff --git a/openair2/LAYER2/MAC/ue_procedures.c b/openair2/LAYER2/MAC/ue_procedures.c index ce16e6e505..6bebd64075 100644 --- a/openair2/LAYER2/MAC/ue_procedures.c +++ b/openair2/LAYER2/MAC/ue_procedures.c @@ -28,9 +28,9 @@ *******************************************************************************/ /*! \file ue_procedures.c * \brief procedures related to UE - * \author Raymond Knopp, Navid Nikaein - * \date 2011 - * \version 0.5 + * \author Navid Nikaein and Raymond Knopp + * \date 2010 - 2014 + * \version 1 * \email: navid.nikaein@eurecom.fr * @ingroup _mac @@ -42,6 +42,7 @@ #include "extern.h" #include "defs.h" +#include "proto.h" #ifdef PHY_EMUL # include "SIMULATION/PHY_EMULATION/impl_defs.h" #else diff --git a/openair2/LAYER2/MAC/vars.h b/openair2/LAYER2/MAC/vars.h index 1a62f2b0e6..166ba7ed98 100644 --- a/openair2/LAYER2/MAC/vars.h +++ b/openair2/LAYER2/MAC/vars.h @@ -28,8 +28,8 @@ *******************************************************************************/ /*! \file vars.h * \brief mac vars -* \author Raymond Knopp, Navid Nikaein -* \date 2012 +* \author Navid Nikaein and Raymond Knopp +* \date 2010 - 2014 * \version 1.0 * \email navid.nikaein@eurecom.fr * @ingroup _mac diff --git a/openair2/LAYER2/Makefile.inc b/openair2/LAYER2/Makefile.inc index 0cca89407e..c599b27e4f 100644 --- a/openair2/LAYER2/Makefile.inc +++ b/openair2/LAYER2/Makefile.inc @@ -84,6 +84,11 @@ MAC_OBJS += $(MAC_DIR)/ra_procedures.o MAC_OBJS += $(MAC_DIR)/l1_helpers.o MAC_OBJS += $(MAC_DIR)/rar_tools.o MAC_OBJS += $(MAC_DIR)/eNB_scheduler.o +MAC_OBJS += $(MAC_DIR)/eNB_scheduler_dlsch.o +MAC_OBJS += $(MAC_DIR)/eNB_scheduler_ulsch.o +MAC_OBJS += $(MAC_DIR)/eNB_scheduler_mch.o +MAC_OBJS += $(MAC_DIR)/eNB_scheduler_bch.o +MAC_OBJS += $(MAC_DIR)/eNB_scheduler_primitives.o MAC_OBJS += $(MAC_DIR)/pre_processor.o MAC_OBJS += $(MAC_DIR)/config.o diff --git a/openair2/RRC/LITE/rrc_eNB.c b/openair2/RRC/LITE/rrc_eNB.c index 0319b6d303..24c91ccdc0 100644 --- a/openair2/RRC/LITE/rrc_eNB.c +++ b/openair2/RRC/LITE/rrc_eNB.c @@ -44,6 +44,7 @@ #include "asn1_conversions.h" #include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h" #include "LAYER2/RLC/rlc.h" +#include "LAYER2/MAC/proto.h" #include "UTIL/LOG/log.h" #include "COMMON/mac_rrc_primitives.h" #include "RRC/LITE/MESSAGES/asn1_msg.h" diff --git a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/epc.pft.memphis.conf b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/epc.pft.memphis.conf new file mode 100755 index 0000000000..7630c7b005 --- /dev/null +++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/epc.pft.memphis.conf @@ -0,0 +1,124 @@ +MME : +{ + + REALM = "eur"; + # Define the limits of the system in terms of served eNB and served UE. + # When the limits will be reached, overload procedure will take place. + MAXENB = 10; + MAXUE = 100; + RELATIVE_CAPACITY = 10; + # Display statistics about whole system (expressed in seconds) + MME_STATISTIC_TIMER = 10; + EMERGENCY_ATTACH_SUPPORTED = "no"; + UNAUTHENTICATED_IMSI_SUPPORTED = "no"; + + + DEFAULT_APN = "www.eurecom.fr"; + EMERGENCY_APN = "www.eurecom_sos.fr"; + KASME = "CAFECAFECAFECAFECAFECAFECAFECAFE"; + AUTH_RAND = ( 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04 ); + AUTH_AUTN = ( 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x05, 0x04, 0x03, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 ); + AUTH_XRES = ( 0x67, 0x70, 0x3a, 0x31, 0xf2, 0x2a, 0x2d, 0x51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ); + IP_CAPABILITY = "IPV4V6"; + + + INTERTASK_INTERFACE : + { + # max queue size per task + ITTI_QUEUE_SIZE = 2000000; + }; + + S6A : + { + S6A_CONF = "../epc_nas/UTILS/CONF/s6a.conf"; + }; + + # ------- SCTP definitions + SCTP : + { + # Number of streams to use in input/output + SCTP_INSTREAMS = 32; + SCTP_OUTSTREAMS = 32; + }; + + # ------- S1AP definitions + S1AP : + { + # outcome drop timer value (seconds) + S1AP_OUTCOME_TIMER = 10; + }; + + # ------- MME served GUMMEI + GUMMEI : + { + # MME code DEFAULT = 0 + # size = 8 bits + # maximum of 256 values, comma separated + MME_CODE = [ 30 , 56 , 1 , 8 ]; + + # MME GROUP ID DEFAULT = 0 + # size = 16 bits + # maximum of 65535 values, comma separated + MME_GID = [ 3 , 4 , 5 , 30 , 8 , 9 , 50021 ]; + + # TA (mcc.mnc:tracking area code) DEFAULT = 208.34:0 + # max values = 999.999:65535 + # maximum of 32 values, comma separated + PLMN = ( + {MCC="208" ; MNC="10"; TAC = "1"; }, + {MCC="209" ; MNC="130"; TAC = "4"; }, + {MCC="208" ; MNC="92"; TAC = "1"; } + ); + }; + + NETWORK_INTERFACES : + { + MME_INTERFACE_NAME_FOR_S1_MME = "eth0"; + MME_IPV4_ADDRESS_FOR_S1_MME = "192.168.12.170/24"; + + MME_INTERFACE_NAME_FOR_S11_MME = "none"; + MME_IPV4_ADDRESS_FOR_S11_MME = "192.168.33.170/24"; + }; +}; + +S-GW : +{ + NETWORK_INTERFACES : + { + SGW_INTERFACE_NAME_FOR_S11 = "none"; + SGW_IPV4_ADDRESS_FOR_S11 = "192.168.33.170/24"; + + SGW_INTERFACE_NAME_FOR_S1U_S12_S4_UP = "eth0"; + SGW_IPV4_ADDRESS_FOR_S1U_S12_S4_UP = "192.168.12.170/24"; + + SGW_INTERFACE_NAME_FOR_S5_S8_UP = "none"; + SGW_IPV4_ADDRESS_FOR_S5_S8_UP = "192.168.12.170/24"; + }; +}; + +P-GW = +{ + NETWORK_INTERFACES : + { + PGW_INTERFACE_NAME_FOR_S5_S8 = "none"; + PGW_IPV4_ADDRESS_FOR_S5_S8 = "192.168.12.170/24"; + + PGW_INTERFACE_NAME_FOR_SGI = "none"; + PGW_IPV4_ADDR_FOR_SGI = "192.168.12.170/24"; + }; + + IP_ADDRESS_POOL : + { + IPV4_LIST = ( + "192.168.87.32", + "192.168.88.0<--->192.168.88.255", + "192.168.90.0<--->192.168.90.255" + ); + IPV6_LIST = ( + "2014:01:26::32", + "2014:02:26::0/120" + ); + }; +}; + + diff --git a/targets/SIMU/EXAMPLES/OSD/WEBXML/template_2.xml b/targets/SIMU/EXAMPLES/OSD/WEBXML/template_2.xml index 7b3e2bd316..c2aae58b56 100644 --- a/targets/SIMU/EXAMPLES/OSD/WEBXML/template_2.xml +++ b/targets/SIMU/EXAMPLES/OSD/WEBXML/template_2.xml @@ -30,7 +30,7 @@ <UE_MOBILITY> <UE_INITIAL_DISTRIBUTION>random</UE_INITIAL_DISTRIBUTION> <RANDOM_UE_DISTRIBUTION> - <NUMBER_OF_NODES>1</NUMBER_OF_NODES> + <NUMBER_OF_NODES>2</NUMBER_OF_NODES> </RANDOM_UE_DISTRIBUTION> <UE_MOBILITY_TYPE>RWP</UE_MOBILITY_TYPE> </UE_MOBILITY> @@ -38,7 +38,7 @@ <eNB_MOBILITY> <eNB_INITIAL_DISTRIBUTION>random</eNB_INITIAL_DISTRIBUTION> <RANDOM_eNB_DISTRIBUTION> - <NUMBER_OF_CELLS>1</NUMBER_OF_CELLS> + <NUMBER_OF_CELLS>2</NUMBER_OF_CELLS> </RANDOM_eNB_DISTRIBUTION> <eNB_MOBILITY_TYPE>STATIC</eNB_MOBILITY_TYPE> </eNB_MOBILITY> diff --git a/targets/SIMU/EXAMPLES/OSD/WEBXML/template_4.xml b/targets/SIMU/EXAMPLES/OSD/WEBXML/template_4.xml index fb510bbcd8..45ae081a93 100644 --- a/targets/SIMU/EXAMPLES/OSD/WEBXML/template_4.xml +++ b/targets/SIMU/EXAMPLES/OSD/WEBXML/template_4.xml @@ -12,6 +12,9 @@ <NUMBER_OF_NODES>1</NUMBER_OF_NODES> </RANDOM_UE_DISTRIBUTION> <UE_MOBILITY_TYPE>RWP</UE_MOBILITY_TYPE> + <GRID_WALK> + <GRID_MAP>RESTRICTED</GRID_MAP> + </GRID_WALK> <UE_MOVING_DYNAMICS> <MIN_SPEED_mps>0.01</MIN_SPEED_mps> <MAX_SPEED_mps>10</MAX_SPEED_mps> @@ -30,7 +33,7 @@ <eNB_MOBILITY_TYPE>STATIC</eNB_MOBILITY_TYPE> </eNB_MOBILITY> </MOBILITY> - <OMV>1</OMV> + <!--OMV>1</OMV--> </TOPOLOGY_CONFIG> <EMULATION_CONFIG> diff --git a/targets/SIMU/EXAMPLES/OSD/WEBXML/template_40.xml b/targets/SIMU/EXAMPLES/OSD/WEBXML/template_40.xml index 566a230bf1..c7fdcc4de6 100644 --- a/targets/SIMU/EXAMPLES/OSD/WEBXML/template_40.xml +++ b/targets/SIMU/EXAMPLES/OSD/WEBXML/template_40.xml @@ -46,8 +46,8 @@ <RANDOM_eNB_DISTRIBUTION> <NUMBER_OF_CELLS>1</NUMBER_OF_CELLS> </RANDOM_eNB_DISTRIBUTION> - <eNB_MOBILITY_TYPE>STATIC</eNB_MOBILITY_TYPE> -<!-- <TRACE_MOBILITY_FILE>static_1enb.tr</TRACE_MOBILITY_FILE> --> <!-- file should be located at $(OPENAIR2)/UTIL/OMG/TRACE/, see README there--> + <eNB_MOBILITY_TYPE>STATIC</eNB_MOBILITY_TYPE> + <!--<TRACE_MOBILITY_FILE>static_1enb.tr</TRACE_MOBILITY_FILE>--> <!-- file should be located at $(OPENAIR2)/UTIL/OMG/TRACE/, see README there--> </eNB_MOBILITY> </MOBILITY> </TOPOLOGY_CONFIG> diff --git a/targets/SIMU/USER/event_handler.c b/targets/SIMU/USER/event_handler.c index d7c15e4461..c67b36f3bd 100644 --- a/targets/SIMU/USER/event_handler.c +++ b/targets/SIMU/USER/event_handler.c @@ -36,7 +36,7 @@ #include <stdio.h> #include <stdlib.h> - +// #include "UTIL/LOG/log.h" #include "event_handler.h" //extern frame_t frame; @@ -60,15 +60,15 @@ void add_event(Event_t event) { } elt->event = event; - + //printf("%" PRIu8 "testestest \n", *((uint8_t *) event.value)); if (event_list.head != NULL) event_list_add_element(elt, previous, &event_list); else event_list_add_head(elt, &event_list); - + } -void schedule(Event_Type_t type, int frame, char * key, void * value) { +void schedule(Operation_Type_t op, Event_Type_t type, int frame, char * key, void * value, int ue, int lcid) { Event_t event; event.frame = frame; if (key == NULL) { //Global model update @@ -78,13 +78,76 @@ void schedule(Event_Type_t type, int frame, char * key, void * value) { strcpy(event.key, key); } event.value = value; + //printf("%" PRIu8 "testestest \n",*((uint8_t *)value)); event.type = type; + event.optype = op; + event.lcid = lcid; + event.ue = ue; add_event(event); } +void schedule_delayed(Operation_Type_t op, Event_Type_t type, char * key, void* value, char * date, int ue, int lcid) +{ + printf("Delayed schedule"); + printf("date %s\n", date); +// first get the time from the system + struct tm *pdh; + time_t intps; + intps=time(NULL); + pdh = localtime(&intps); + char *date_cpy = malloc (sizeof (char) * 256); + strcpy(date_cpy,date); +// second count the frame to reach the time + char *heure = NULL; + int heure_int; + int minute_int; + int heure_diff; + int minute_diff; + int ms_diff; + int frame; + + + char *minute = NULL; + heure = strtok(date_cpy,"h"); + //heure = strchr(date,'h'); + printf("heure char : %s", heure); + + minute = strchr(date,'h'); + printf("minute char : %s", minute+1); + + heure_int = atoi(heure); + + minute_int = atoi(minute+1); + heure_diff = heure_int - pdh->tm_hour; + minute_diff = minute_int - pdh->tm_min; + ms_diff = heure_diff*3600*1000 + minute_diff*60*1000; + frame = ms_diff/10; + + /*char stTemp[2]; +int valeur_a_en_entier; + +sprintf(stTemp,"%c",a); +valeur_a_en_entier = atoi(stTemp);*/ +// third schedule with the classic function + printf("schedule_frame %d\n",frame); + printf("test pdh hr : %d\n", pdh->tm_hour); + printf("test heure_diff : %d\n", heure_diff); + printf("test minute_diff : %d\n", minute_diff); + if(frame >= 0) + { + schedule(op,type,frame,key,value,lcid,ue); + } +} + /* * this function can reschedule events in the future to build a desired (more dynamic) scenario * TODO: make sure that OCG OAI_Emulation is decoupled with the local vars + * + * For ET_MAC parameters are first set in the OAI_emulation (OCG) structure and then + * duplicated in the eNB_mac_inst structure + * + * If you want to modifiy a parameter for all UEs, put -1 in the lcid and the ue field when you call + * the schedule function */ void schedule_events(){ @@ -112,8 +175,43 @@ void schedule_events(){ * associated with EMU_ET */ //Emulation_Config * emulation_frame_100; - - + uint8_t a; + + Mac_config* mac_config; + Mac_config* mac_config2; + Mac_config* mac_config3; + Mac_config* mac_config4; + Mac_config* mac_config5; + int i=0; + + mac_config = NULL; + mac_config2 = NULL; + mac_config3 = NULL; + mac_config4 = NULL; + mac_config5 = NULL; + mac_config = malloc(sizeof(Mac_config)); + mac_config2= malloc(sizeof(Mac_config)); + mac_config3= malloc(sizeof(Mac_config)); + mac_config4= malloc(sizeof(Mac_config)); + mac_config5= malloc(sizeof(Mac_config)); + + a = 5; + + uint16_t *priority[11];//={1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2}; + + + int tab[NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX]; + Application_Config* application_config; + application_config = malloc(sizeof(Application_Config)); + for(i=0;i<NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX;i++) + { + tab[i]=i; + application_config->customized_traffic.aggregation_level[i]=i; + } + + mac_config->DCI_aggregation_min = a; + mac_config->DLSCH_dci_size_bits = a; + /* * Step 2: set the desired future changes in the vars */ @@ -130,15 +228,53 @@ void schedule_events(){ //schedule(OAI_ET, 1000, NULL, oai_frame_1000); //schedule(SYS_ET, 200, NULL, system_frame_200); - //schedule(TOPO_ET, 10, NULL, topology_frame_10); + //schedule(READ, TOPO_ET, 10, NULL, ""); //schedule(APP_ET, 20, NULL, application_frame_20); //schedule(EMU_ET, 100, NULL,emulation_frame_100); // protocol dynamic configuration - //schedule(MAC_ET, 100, NULL,mac_frame_100); + schedule(READ, MAC_ET, 115, NULL, "",0,0); + //schedule(READ, MAC_ET, 400, NULL, ""); + //schedule(READ, MAC_ET, 500, NULL, ""); + //schedule(WRITE, MAC_ET, 100, NULL, ""); + //schedule(READ, TOPO_ET,110,NULL,"",0,0); + double b = (double) 45; + //schedule(READ, APP_ET,111,NULL,"",0,0); + //schedule(READ, SYS_ET,112,NULL,"",0,0); + //schedule(READ, EMU_ET,113,NULL,"",-1,-1); + //schedule(WRITE, MAC_ET, 122, "DCI_aggregation_min", mac_config); + //schedule(WRITE, MAC_ET, 123, "max_allowed_rbs", mac_config); + //schedule(WRITE, MAC_ET, 125, "max_mcs", mac_config); + int j=0; + for(i=0;i<NUMBER_OF_UE_MAX;i++) + { + mac_config2[i].DCI_aggregation_min = 1; + for(j=0;j<MAX_NUM_LCID;j++) + { + mac_config2[i].ul_bandwidth[j]= (uint8_t) 4; + mac_config2[i].max_mcs[j]= 1; + } + } + //schedule(READ or WRITE, ET_MAC, frame number, key, mac_config, ue, lcid); + //schedule(WRITE, MAC_ET, 125, "ul_bandwidth", mac_config2,-1,-1); + //schedule(WRITE, MAC_ET, 126, "DCI_aggregation_min", mac_config2,-1,-1); + //schedule(WRITE, MAC_ET, 128, "max_mcs", mac_config2,-1,-1); + mac_config[0].max_mcs[3]= 4; + schedule(WRITE, MAC_ET, 140, "max_mcs", mac_config,0,3); + mac_config2[0].max_mcs[3]= 26; + schedule(WRITE, MAC_ET, 1500, "max_mcs", mac_config2,0,3); + mac_config3[0].max_mcs[3]= 3; + schedule(WRITE, MAC_ET, 1600, "max_mcs", mac_config3,0,3); + mac_config4[0].max_mcs[3]= 26; + schedule(WRITE, MAC_ET, 2400, "max_mcs", mac_config4,0,3); + mac_config5[0].max_mcs[3]= 13; + schedule(WRITE, MAC_ET, 3000, "max_mcs", mac_config5,0,3); + + + printf("schedule_event\n"); - //event_list_display(&event_list); + event_list_display(&event_list); } @@ -150,8 +286,9 @@ void execute_events(frame_t frame){ while ((user_defined_event = event_list_get_head(&event_list)) != NULL) { event = user_defined_event->event; - + if (event.frame == frame) { + //printf("%" PRIu8 "testestest \n", *((uint8_t *) event.value)); switch (event.type) { case OAI_ET: update_oai_model(event.key, event.value); @@ -159,27 +296,27 @@ void execute_events(frame_t frame){ break; case SYS_ET: - update_sys_model(event.key, event.value); + update_sys_model(event); user_defined_event = event_list_remove_head(&event_list); break; case TOPO_ET: - update_topo_model(event.key, event.value); //implement it with assigning the new values to that of oai_emulation & second thing is to ensure mob model is always read from oai_emulation + update_topo_model(event); //implement it with assigning the new values to that of oai_emulation & second thing is to ensure mob model is always read from oai_emulation user_defined_event = event_list_remove_head(&event_list); break; case APP_ET: - update_app_model(event.key, event.value); + update_app_model(event); user_defined_event = event_list_remove_head(&event_list); break; case EMU_ET: - update_emu_model(event.key, event.value); + update_emu_model(event); user_defined_event = event_list_remove_head(&event_list); break; case MAC_ET: - update_mac(event.key, event.value); + update_mac(event); user_defined_event = event_list_remove_head(&event_list); break; @@ -193,287 +330,2870 @@ void execute_events(frame_t frame){ } -void update_mac(char * key, void * value) { + +void update_mac(Event_t event) { + LOG_I(EMU,"A NEW MAC MODEL\n"); + int i = 0; + + if(event.optype == READ) + { + + eNB_MAC_INST *eNB_mac_inst; + eNB_mac_inst = get_eNB_mac_inst(); + printf("eNB_stats\n\n\n"); + if(event.key==NULL) + { + + LOG_I(EMU,"num_dlactive_UEs :"); + printf("%" PRIu16 "\n",eNB_mac_inst->eNB_stats.num_dlactive_UEs); + LOG_I(EMU,"available_prbs :"); + printf("%" PRIu16 "\n",eNB_mac_inst->eNB_stats.available_prbs); + LOG_I(EMU,"total_available_prbs :"); + printf("%" PRIu32 "\n", eNB_mac_inst->eNB_stats.total_available_prbs); + LOG_I(EMU,"available_ncces :"); + printf("%" PRIu16 "\n",eNB_mac_inst->eNB_stats.available_ncces); + LOG_I(EMU,"dlsch_bitrate :"); + printf("%" PRIu32 "\n",eNB_mac_inst->eNB_stats.dlsch_bitrate); + LOG_I(EMU,"dlsch_bytes_tx :"); + printf("%" PRIu32 "\n",eNB_mac_inst->eNB_stats.dlsch_bytes_tx); + LOG_I(EMU,"dlsch_pdus_tx :"); + printf("%" PRIu32 "\n",eNB_mac_inst->eNB_stats.dlsch_pdus_tx); + LOG_I(EMU,"total_dlsch_bitrate :"); + printf("%" PRIu32 "\n",eNB_mac_inst->eNB_stats.total_dlsch_bitrate); + LOG_I(EMU,"total_dlsch_bytes_tx :"); + printf("%" PRIu32 "\n",eNB_mac_inst->eNB_stats.total_dlsch_bytes_tx); + LOG_I(EMU,"total_dlsch_pdus_tx :"); + printf("%" PRIu32 "\n",eNB_mac_inst->eNB_stats.total_dlsch_pdus_tx); + LOG_I(EMU,"ulsch_bitrate :"); + printf("%" PRIu32 "\n",eNB_mac_inst->eNB_stats.ulsch_bitrate); + LOG_I(EMU,"ulsch_bytes_rx :"); + printf("%" PRIu32 "\n",eNB_mac_inst->eNB_stats.ulsch_bytes_rx); + LOG_I(EMU,"ulsch_pdus_rx :"); + printf("%" PRIu64 "\n",eNB_mac_inst->eNB_stats.ulsch_pdus_rx); + } + else if(!strcmp((char *) event.key, "num_dlactive_UEs")) + { + LOG_I(EMU,"num_dlactive_UEs :"); + printf("%" PRIu16 "\n",eNB_mac_inst->eNB_stats.num_dlactive_UEs); + } + else if(!strcmp((char *) event.key, "available_prbs")) + { + LOG_I(EMU,"available_prbs :"); + printf("%" PRIu16 "\n",eNB_mac_inst->eNB_stats.available_prbs); + } + else if(!strcmp((char *) event.key, "total_available_prbs")) + { + LOG_I(EMU,"total_available_prbs :"); + printf("%" PRIu32 "\n", eNB_mac_inst->eNB_stats.total_available_prbs); + } + else if(!strcmp((char *) event.key, "available_ncces")) + { + LOG_I(EMU,"available_ncces :"); + printf("%" PRIu16 "\n",eNB_mac_inst->eNB_stats.available_ncces); + } + else if(!strcmp((char *) event.key, "dlsch_bitrate")) + { + LOG_I(EMU,"dlsch_bitrate :"); + printf("%" PRIu32 "\n",eNB_mac_inst->eNB_stats.dlsch_bitrate); + } + else if(!strcmp((char *) event.key, "dlsch_bytes_tx")) + { + LOG_I(EMU,"dlsch_bytes_tx :"); + printf("%" PRIu32 "\n",eNB_mac_inst->eNB_stats.dlsch_bytes_tx); + } + else if(!strcmp((char *) event.key, "dlsch_pdus_tx")) + { + LOG_I(EMU,"dlsch_pdus_tx :"); + printf("%" PRIu32 "\n",eNB_mac_inst->eNB_stats.dlsch_pdus_tx); + } + else if(!strcmp((char *) event.key, "total_dlsch_bitrate")) + { + LOG_I(EMU,"total_dlsch_bitrate :"); + printf("%" PRIu32 "\n",eNB_mac_inst->eNB_stats.total_dlsch_bitrate); + } + else if(!strcmp((char *) event.key, "total_dlsch_bytes_tx")) + { + LOG_I(EMU,"total_dlsch_bytes_tx :"); + printf("%" PRIu32 "\n",eNB_mac_inst->eNB_stats.total_dlsch_bytes_tx); + } + else if(!strcmp((char *) event.key, "total_dlsch_pdus_tx")) + { + LOG_I(EMU,"total_dlsch_pdus_tx :"); + printf("%" PRIu32 "\n",eNB_mac_inst->eNB_stats.total_dlsch_pdus_tx); + } + else if(!strcmp((char *) event.key, "ulsch_bitrate")) + { + LOG_I(EMU,"ulsch_bitrate :"); + printf("%" PRIu32 "\n",eNB_mac_inst->eNB_stats.ulsch_bitrate); + } + else if(!strcmp((char *) event.key, "ulsch_bytes_rx")) + { + LOG_I(EMU,"ulsch_bytes_rx :"); + printf("%" PRIu32 "\n",eNB_mac_inst->eNB_stats.ulsch_bytes_rx); + } + else if(!strcmp((char *) event.key, "ulsch_pdus_rx")) + { + LOG_I(EMU,"ulsch_pdus_rx :"); + printf("%" PRIu64 "\n",eNB_mac_inst->eNB_stats.ulsch_pdus_rx); + } + } + else if(event.optype == WRITE) + { + LOG_I(EMU,"WRITE OPERATION \n"); + eNB_MAC_INST *eNB_mac_inst; + eNB_mac_inst = get_eNB_mac_inst(); + OAI_Emulation *oai_emulation; + oai_emulation = get_OAI_emulation(); + + if(event.key==NULL && event.value!=NULL) + { + + if((Mac_config *) event.value !=NULL && validate_mac(event)) + { + + Mac_config* mac_config = malloc(sizeof(Mac_config)*16); + mac_config = (Mac_config *) event.value; + LOG_I(EMU,"update complete mac params \n"); + if(event.ue == -1 && event.lcid == -1) + { + for(i=0;i<NUMBER_OF_UE_MAX;i++) + { + if(&mac_config[i].DCI_aggregation_min) + { + LOG_I(EMU,"update dci aggregation min\n"); + oai_emulation->mac_config[i].DCI_aggregation_min= mac_config[i].DCI_aggregation_min; + + eNB_mac_inst->UE_template[i].DCI_aggregation_min = oai_emulation->mac_config[i].DCI_aggregation_min; + LOG_I(EMU,"DCI_aggregation_min UE %d: \n",i); + LOG_I(EMU,"%" PRIu8,eNB_mac_inst->UE_template[i].DCI_aggregation_min); + } + if(&mac_config[i].DLSCH_dci_size_bits !=NULL) + { + oai_emulation->mac_config[i].DLSCH_dci_size_bits= mac_config[i].DLSCH_dci_size_bits; + eNB_mac_inst->UE_template[i].DLSCH_dci_size_bits = oai_emulation->mac_config[i].DLSCH_dci_size_bits; + LOG_I(EMU,"DLSCH_dci_size_bits UE %d: \n",i); + LOG_I(EMU,"%" PRIu8,eNB_mac_inst->UE_template[i].DLSCH_dci_size_bits); + } + if(mac_config[i].priority !=NULL) + { + LOG_I(EMU,"update priority \n"); + int j; + for(j=0;j<MAX_NUM_LCID;j++) + { + + if(&mac_config[i].priority[j]!=NULL) + { + oai_emulation->mac_config[i].priority[j]= mac_config[i].priority[j]; + eNB_mac_inst->UE_sched_ctrl[i].priority[j] = oai_emulation->mac_config[i].priority[j]; + LOG_I(EMU,"priority UE %d LCID %d:",i,j); + LOG_I(EMU,"%" PRIu8 "\n",eNB_mac_inst->UE_sched_ctrl[i].priority[j]); + } + } + } + if(&mac_config[i].ul_bandwidth !=NULL) + { + + int j=0; + for(j=0;j<MAX_NUM_LCID;j++) + { + + oai_emulation->mac_config[i].ul_bandwidth[j]= mac_config[i].ul_bandwidth[j]; + eNB_mac_inst->UE_sched_ctrl[i].ul_bandwidth[j] = oai_emulation->mac_config[i].ul_bandwidth[j]; + LOG_I(EMU,"ul_bandwidth UE %d LCID %d:", i, j); + LOG_I(EMU,"%" PRIu8 "\n",eNB_mac_inst->UE_sched_ctrl[i].ul_bandwidth[j]); + } + } + if(&mac_config[i].dl_bandwidth !=NULL) + { + int j=0; + for(j=0;j<MAX_NUM_LCID;j++) + { + + oai_emulation->mac_config[i].dl_bandwidth[j]= mac_config[i].dl_bandwidth[j]; + eNB_mac_inst->UE_sched_ctrl[i].dl_bandwidth[j] = oai_emulation->mac_config[i].dl_bandwidth[j]; + LOG_I(EMU,"ul_bandwidth UE %d LCID %d:", i, j); + LOG_I(EMU,"%" PRIu8 "\n",eNB_mac_inst->UE_sched_ctrl[i].dl_bandwidth[j]); + } + } + if(&mac_config[i].ue_AggregatedMaximumBitrateDL !=NULL) + { + oai_emulation->mac_config[i].ue_AggregatedMaximumBitrateDL= mac_config[i].ue_AggregatedMaximumBitrateDL; + eNB_mac_inst->UE_sched_ctrl[i].ue_AggregatedMaximumBitrateDL = oai_emulation->mac_config[i].ue_AggregatedMaximumBitrateDL; + LOG_I(EMU,"ue_AggregatedMaximumBitrateDL UE %d:",i ); + LOG_I(EMU,"%" PRIu64 "\n",eNB_mac_inst->UE_sched_ctrl[i].ue_AggregatedMaximumBitrateDL); + } + if(&mac_config[i].ue_AggregatedMaximumBitrateUL !=NULL) + { + oai_emulation->mac_config[i].ue_AggregatedMaximumBitrateUL= mac_config[i].ue_AggregatedMaximumBitrateUL; + eNB_mac_inst->UE_sched_ctrl[i].ue_AggregatedMaximumBitrateUL = oai_emulation->mac_config[i].ue_AggregatedMaximumBitrateUL; + LOG_I(EMU,"ue_AggregatedMaximumBitrateUL UE %d:",i); + LOG_I(EMU,"%" PRIu64 "\n",eNB_mac_inst->UE_sched_ctrl[i].ue_AggregatedMaximumBitrateUL); + } + if(&mac_config[i].cqiSchedInterval !=NULL) + { + oai_emulation->mac_config[i].cqiSchedInterval= mac_config[i].cqiSchedInterval; + eNB_mac_inst->UE_sched_ctrl[i].cqiSchedInterval = oai_emulation->mac_config[i].cqiSchedInterval; + LOG_I(EMU,"cqiSchedInterval UE %d:",i); + LOG_I(EMU,"%" PRIu16 "\n",eNB_mac_inst->UE_sched_ctrl[i].cqiSchedInterval); + } + if(&mac_config[i].mac_ContentionResolutionTimer !=NULL) + { + oai_emulation->mac_config[i].mac_ContentionResolutionTimer= mac_config[i].mac_ContentionResolutionTimer; + eNB_mac_inst->UE_sched_ctrl[i].mac_ContentionResolutionTimer = oai_emulation->mac_config[i].mac_ContentionResolutionTimer; + LOG_I(EMU,"mac_ContentionResolutionTimer UE %:", i); + LOG_I(EMU,"%" PRIu8 "\n",eNB_mac_inst->UE_sched_ctrl[i].mac_ContentionResolutionTimer); + } + if(mac_config->max_allowed_rbs !=NULL) + { + int j=0; + for(j=0;j<MAX_NUM_LCID;j++) + { + oai_emulation->mac_config[i].max_allowed_rbs[j]= mac_config[i].max_allowed_rbs[j]; + eNB_mac_inst->UE_sched_ctrl[i].max_allowed_rbs[j] = oai_emulation->mac_config[i].max_allowed_rbs[j]; + LOG_I(EMU,"max_allowed_rbs UE %d LCID %d:",i,j); + LOG_I(EMU,"%" PRIu16 "\n",eNB_mac_inst->UE_sched_ctrl[i].max_allowed_rbs[j]); + } + } + if(mac_config[i].max_mcs !=NULL) + { + int j=0; + for(j=0;j<MAX_NUM_LCID;j++) + { + oai_emulation->mac_config[i].max_mcs[j]= mac_config[i].max_mcs[j]; + eNB_mac_inst->UE_sched_ctrl[i].max_mcs[j] = oai_emulation->mac_config[i].max_mcs[j]; + LOG_I(EMU,"max_mcs UE %d LCID %d:",i,j); + LOG_I(EMU,"%" PRIu8 "\n",eNB_mac_inst->UE_sched_ctrl[i].max_mcs[j]); + } + + } + } + } + else + { + Mac_config* mac_config = malloc(sizeof(Mac_config)*16); + mac_config = (Mac_config *) event.value; + LOG_I(EMU,"update complete mac params \n"); + i = event.ue; + int j = event.lcid; + + if(&mac_config[i].DCI_aggregation_min) + { + LOG_I(EMU,"update dci aggregation min\n"); + oai_emulation->mac_config[i].DCI_aggregation_min= mac_config[i].DCI_aggregation_min; + // duplication dans le ue template, vérifier la validité avant + eNB_mac_inst->UE_template[i].DCI_aggregation_min = oai_emulation->mac_config[i].DCI_aggregation_min; + LOG_I(EMU,"DCI_aggregation_min UE %d: \n",i); + LOG_I(EMU,"%" PRIu8,eNB_mac_inst->UE_template[i].DCI_aggregation_min); + } + if(&mac_config[i].DLSCH_dci_size_bits !=NULL) + { + oai_emulation->mac_config[i].DLSCH_dci_size_bits= mac_config[i].DLSCH_dci_size_bits; + eNB_mac_inst->UE_template[i].DLSCH_dci_size_bits = oai_emulation->mac_config[i].DLSCH_dci_size_bits; + LOG_I(EMU,"DLSCH_dci_size_bits UE %d: \n",i); + LOG_I(EMU,"%" PRIu8,eNB_mac_inst->UE_template[i].DLSCH_dci_size_bits); + } + if(mac_config[i].priority !=NULL) + { + LOG_I(EMU,"update priority \n"); + + + if(&mac_config[i].priority[j]!=NULL) + { + oai_emulation->mac_config[i].priority[j]= mac_config[i].priority[j]; + eNB_mac_inst->UE_sched_ctrl[i].priority[j] = oai_emulation->mac_config[i].priority[j]; + LOG_I(EMU,"priority UE %d LCID %d:",i,j); + LOG_I(EMU,"%" PRIu8 "\n",eNB_mac_inst->UE_sched_ctrl[i].priority[j]); + } + + } + if(&mac_config[i].ul_bandwidth !=NULL) + { + // faire boucle par ue puis par lcid + + + + oai_emulation->mac_config[i].ul_bandwidth[j]= mac_config[i].ul_bandwidth[j]; + eNB_mac_inst->UE_sched_ctrl[i].ul_bandwidth[j] = oai_emulation->mac_config[i].ul_bandwidth[j]; + LOG_I(EMU,"ul_bandwidth UE %d LCID %d:", i, j); + LOG_I(EMU,"%" PRIu8 "\n",eNB_mac_inst->UE_sched_ctrl[i].ul_bandwidth[j]); + + } + if(&mac_config[i].dl_bandwidth !=NULL) + { + oai_emulation->mac_config[i].dl_bandwidth[j]= mac_config[i].dl_bandwidth[j]; + eNB_mac_inst->UE_sched_ctrl[i].dl_bandwidth[j] = oai_emulation->mac_config[i].dl_bandwidth[j]; + LOG_I(EMU,"ul_bandwidth UE %d LCID %d:", i, j); + LOG_I(EMU,"%" PRIu8 "\n",eNB_mac_inst->UE_sched_ctrl[i].dl_bandwidth[j]); + + } + if(&mac_config[i].min_ul_bandwidth !=NULL) + { + // faire boucle par ue puis par lcid + oai_emulation->mac_config[i].min_ul_bandwidth[j]= mac_config[i].min_ul_bandwidth[j]; + eNB_mac_inst->UE_sched_ctrl[i].min_ul_bandwidth[j] = oai_emulation->mac_config[i].min_ul_bandwidth[j]; + LOG_I(EMU,"min_ul_bandwidth UE %d LCID %d:", i, j); + LOG_I(EMU,"%" PRIu8 "\n",eNB_mac_inst->UE_sched_ctrl[i].min_ul_bandwidth[j]); + + } + if(&mac_config[i].min_dl_bandwidth !=NULL) + { + oai_emulation->mac_config[i].min_dl_bandwidth[j]= mac_config[i].min_dl_bandwidth[j]; + eNB_mac_inst->UE_sched_ctrl[i].min_dl_bandwidth[j] = oai_emulation->mac_config[i].min_dl_bandwidth[j]; + LOG_I(EMU,"min_dl_bandwidth UE %d LCID %d:", i, j); + LOG_I(EMU,"%" PRIu8 "\n",eNB_mac_inst->UE_sched_ctrl[i].min_dl_bandwidth[j]); + + } + if(&mac_config[i].ue_AggregatedMaximumBitrateDL !=NULL) + { + oai_emulation->mac_config[i].ue_AggregatedMaximumBitrateDL= mac_config[i].ue_AggregatedMaximumBitrateDL; + eNB_mac_inst->UE_sched_ctrl[i].ue_AggregatedMaximumBitrateDL = oai_emulation->mac_config[i].ue_AggregatedMaximumBitrateDL; + LOG_I(EMU,"ue_AggregatedMaximumBitrateDL UE %d:",i ); + LOG_I(EMU,"%" PRIu64 "\n",eNB_mac_inst->UE_sched_ctrl[i].ue_AggregatedMaximumBitrateDL); + } + if(&mac_config[i].ue_AggregatedMaximumBitrateUL !=NULL) + { + oai_emulation->mac_config[i].ue_AggregatedMaximumBitrateUL= mac_config[i].ue_AggregatedMaximumBitrateUL; + eNB_mac_inst->UE_sched_ctrl[i].ue_AggregatedMaximumBitrateUL = oai_emulation->mac_config[i].ue_AggregatedMaximumBitrateUL; + LOG_I(EMU,"ue_AggregatedMaximumBitrateUL UE %d:",i); + LOG_I(EMU,"%" PRIu64 "\n",eNB_mac_inst->UE_sched_ctrl[i].ue_AggregatedMaximumBitrateUL); + } + if(&mac_config[i].cqiSchedInterval !=NULL) + { + oai_emulation->mac_config[i].cqiSchedInterval= mac_config[i].cqiSchedInterval; + eNB_mac_inst->UE_sched_ctrl[i].cqiSchedInterval = oai_emulation->mac_config[i].cqiSchedInterval; + LOG_I(EMU,"cqiSchedInterval UE %d:",i); + LOG_I(EMU,"%" PRIu16 "\n",eNB_mac_inst->UE_sched_ctrl[i].cqiSchedInterval); + } + if(&mac_config[i].mac_ContentionResolutionTimer !=NULL) + { + oai_emulation->mac_config[i].mac_ContentionResolutionTimer= mac_config[i].mac_ContentionResolutionTimer; + eNB_mac_inst->UE_sched_ctrl[i].mac_ContentionResolutionTimer = oai_emulation->mac_config[i].mac_ContentionResolutionTimer; + LOG_I(EMU,"mac_ContentionResolutionTimer UE %:", i); + LOG_I(EMU,"%" PRIu8 "\n",eNB_mac_inst->UE_sched_ctrl[i].mac_ContentionResolutionTimer); + } + if(mac_config->max_allowed_rbs !=NULL) + { + + oai_emulation->mac_config[i].max_allowed_rbs[j]= mac_config[i].max_allowed_rbs[j]; + eNB_mac_inst->UE_sched_ctrl[i].max_allowed_rbs[j] = oai_emulation->mac_config[i].max_allowed_rbs[j]; + LOG_I(EMU,"max_allowed_rbs UE %d LCID %d:",i,j); + LOG_I(EMU,"%" PRIu16 "\n",eNB_mac_inst->UE_sched_ctrl[i].max_allowed_rbs[j]); + + } + if(mac_config[i].max_mcs !=NULL) + { + oai_emulation->mac_config[i].max_mcs[j]= mac_config[i].max_mcs[j]; + eNB_mac_inst->UE_sched_ctrl[i].max_mcs[j] = oai_emulation->mac_config[i].max_mcs[j]; + LOG_I(EMU,"max_mcs UE %d LCID %d:",i,j); + LOG_I(EMU,"%" PRIu8 "\n",eNB_mac_inst->UE_sched_ctrl[i].max_mcs[j]); + + } + } + } + } + else if(!strcmp((char *) event.key, "priority") && event.value!=NULL && validate_mac(event)) + { + Mac_config* mac_config = malloc(sizeof(Mac_config)*16); + mac_config = (Mac_config *) event.value; + int j=0; + LOG_I(EMU,"priority update \n"); + if(event.ue == -1) + { + for(i=0;i<MAX_NUM_LCID;i++) + { + for(j=0;j<MAX_NUM_LCID;j++) + { + + if(&mac_config[i].priority[j]!=NULL) + { + oai_emulation->mac_config[i].priority[j]= mac_config[i].priority[j]; + eNB_mac_inst->UE_sched_ctrl[i].priority[j] = oai_emulation->mac_config[i].priority[j]; + LOG_I(EMU,"priority UE %d LCID %d:",i,j); + LOG_I(EMU,"%" PRIu8 "\n",eNB_mac_inst->UE_sched_ctrl[i].priority[j]); + } + } + } + } + else + { + oai_emulation->mac_config[event.ue].priority[event.lcid]= mac_config[event.ue].priority[event.lcid]; + eNB_mac_inst->UE_sched_ctrl[event.ue].priority[event.lcid] = oai_emulation->mac_config[event.ue].priority[event.lcid]; + LOG_I(EMU,"priority UE %d LCID %d:",i,j); + LOG_I(EMU,"%" PRIu8 "\n",eNB_mac_inst->UE_sched_ctrl[event.ue].priority[event.lcid]); + } + } + else if(!strcmp((char *) event.key, "DCI_aggregation_min") && event.value!=NULL && validate_mac(event)) + { + Mac_config* mac_config = malloc(sizeof(Mac_config)*16); + mac_config = (Mac_config *) event.value; + + LOG_I(EMU,"DCI_aggregation_min update \n"); + if(event.ue == -1) + { + for(i=0;i<NUMBER_OF_UE_MAX;i++) + { + oai_emulation->mac_config[i].DCI_aggregation_min=mac_config[i].DCI_aggregation_min; + eNB_mac_inst->UE_template[i].DCI_aggregation_min = oai_emulation->mac_config[i].DCI_aggregation_min; + LOG_I(EMU,"DCI_aggregation_min UE %d : \n", i); + LOG_I(EMU,"%" PRIu8 "\n",eNB_mac_inst->UE_template[i].DCI_aggregation_min); + } + } + else + { + oai_emulation->mac_config[event.ue].DCI_aggregation_min=mac_config[event.ue].DCI_aggregation_min; + eNB_mac_inst->UE_template[event.ue].DCI_aggregation_min = oai_emulation->mac_config[event.ue].DCI_aggregation_min; + LOG_I(EMU,"DCI_aggregation_min UE %d : \n", event.ue); + LOG_I(EMU,"%" PRIu8 "\n",eNB_mac_inst->UE_template[event.ue].DCI_aggregation_min); + } + } + else if(!strcmp((char *) event.key, "DLSCH_dci_size_bits") && event.value!=NULL && validate_mac(event)) + { + Mac_config* mac_config = malloc(sizeof(Mac_config)*16); + mac_config = (Mac_config *) event.value; + + + LOG_I(EMU,"DLSCH_dci_size_bits update \n"); + if(event.ue == -1) + { + for(i=0;i<NUMBER_OF_UE_MAX;i++) + { + oai_emulation->mac_config[i].DLSCH_dci_size_bits=mac_config[i].DLSCH_dci_size_bits; + eNB_mac_inst->UE_template[i].DLSCH_dci_size_bits = oai_emulation->mac_config[i].DLSCH_dci_size_bits; + LOG_I(EMU,"DLSCH_dci_size_bits UE %d: \n", i); + LOG_I(EMU,"%" PRIu8,eNB_mac_inst->UE_template[i].DLSCH_dci_size_bits); + } + } + else + { + oai_emulation->mac_config[event.ue].DLSCH_dci_size_bits=mac_config[event.ue].DLSCH_dci_size_bits; + eNB_mac_inst->UE_template[event.ue].DLSCH_dci_size_bits = oai_emulation->mac_config[event.ue].DLSCH_dci_size_bits; + LOG_I(EMU,"DLSCH_dci_size_bits UE %d: \n", event.ue); + LOG_I(EMU,"%" PRIu8,eNB_mac_inst->UE_template[event.ue].DLSCH_dci_size_bits); + } + + } + else if(!strcmp((char *) event.key, "ul_bandwidth") && event.value!=NULL) + { + + + Mac_config* mac_config = malloc(sizeof(Mac_config)*16); + mac_config = (Mac_config *) event.value; + int j=0; + if(event.ue == -1 && event.lcid == -1) + { + for(i=0;i<NUMBER_OF_UE_MAX;i++) + { + + + for(j=0;j<MAX_NUM_LCID;j++) + { + + if(&mac_config[i].ul_bandwidth[j]!=NULL) + { + oai_emulation->mac_config[i].ul_bandwidth[j]= mac_config[i].ul_bandwidth[j]; + eNB_mac_inst->UE_sched_ctrl[i].ul_bandwidth[j] = oai_emulation->mac_config[i].ul_bandwidth[j]; + LOG_I(EMU,"ul_bandwidth UE %d LCID %d:",i,j); + LOG_I(EMU,"%" PRIu8 "\n",eNB_mac_inst->UE_sched_ctrl[i].ul_bandwidth[j]); + } + } + + } + } + else + { + oai_emulation->mac_config[event.ue].ul_bandwidth[event.lcid]= mac_config[event.ue].ul_bandwidth[event.lcid]; + eNB_mac_inst->UE_sched_ctrl[event.ue].ul_bandwidth[event.lcid] = oai_emulation->mac_config[event.ue].ul_bandwidth[event.lcid]; + LOG_I(EMU,"ul_bandwidth UE %d LCID %d:",event.ue, event.lcid); + LOG_I(EMU,"%" PRIu8 "\n",eNB_mac_inst->UE_sched_ctrl[event.ue].ul_bandwidth[event.lcid]); + } + + } + else if(!strcmp((char *) event.key, "dl_bandwidth") && event.value!=NULL && validate_mac(event)) + { + + Mac_config* mac_config = malloc(sizeof(Mac_config)*16); + mac_config = (Mac_config *) event.value; + int j=0; + if(event.ue == -1 && event.lcid == -1) + { + for(i=0;i<NUMBER_OF_UE_MAX;i++) + { + if(event.value + i !=NULL) + { + + for(j=0;j<MAX_NUM_LCID;j++) + { + + if(&mac_config[i].dl_bandwidth[j]!=NULL) + { + oai_emulation->mac_config[i].dl_bandwidth[j]= mac_config[i].dl_bandwidth[j]; + eNB_mac_inst->UE_sched_ctrl[i].dl_bandwidth[j] = oai_emulation->mac_config[i].dl_bandwidth[j]; + LOG_I(EMU,"dl_bandwidth UE %d LCID %d:",i,j); + LOG_I(EMU,"%" PRIu8 "\n",eNB_mac_inst->UE_sched_ctrl[i].dl_bandwidth[j]); + } + } + } + } + } + else + { + oai_emulation->mac_config[event.ue].dl_bandwidth[event.lcid]= mac_config[event.ue].dl_bandwidth[event.lcid]; + eNB_mac_inst->UE_sched_ctrl[event.ue].dl_bandwidth[event.lcid] = oai_emulation->mac_config[event.ue].dl_bandwidth[event.lcid]; + LOG_I(EMU,"dl_bandwidth UE %d LCID %d:",event.ue, event.lcid); + LOG_I(EMU,"%" PRIu8 "\n",eNB_mac_inst->UE_sched_ctrl[event.ue].dl_bandwidth[event.lcid]); + } + } + else if(!strcmp((char *) event.key, "min_ul_bandwidth") && event.value!=NULL) + { + + + Mac_config* mac_config = malloc(sizeof(Mac_config)*16); + mac_config = (Mac_config *) event.value; + int j=0; + if(event.ue == -1 && event.lcid == -1) + { + for(i=0;i<NUMBER_OF_UE_MAX;i++) + { + + + for(j=0;j<MAX_NUM_LCID;j++) + { + + if(&mac_config[i].min_ul_bandwidth[j]!=NULL) + { + oai_emulation->mac_config[i].min_ul_bandwidth[j]= mac_config[i].min_ul_bandwidth[j]; + eNB_mac_inst->UE_sched_ctrl[i].min_ul_bandwidth[j] = oai_emulation->mac_config[i].min_ul_bandwidth[j]; + LOG_I(EMU,"min_ul_bandwidth UE %d LCID %d:",i,j); + LOG_I(EMU,"%" PRIu8 "\n",eNB_mac_inst->UE_sched_ctrl[i].min_ul_bandwidth[j]); + } + } + + } + } + else + { + oai_emulation->mac_config[event.ue].min_ul_bandwidth[event.lcid]= mac_config[event.ue].min_ul_bandwidth[event.lcid]; + eNB_mac_inst->UE_sched_ctrl[event.ue].min_ul_bandwidth[event.lcid] = oai_emulation->mac_config[event.ue].min_ul_bandwidth[event.lcid]; + LOG_I(EMU,"min_ul_bandwidth UE %d LCID %d:",event.ue, event.lcid); + LOG_I(EMU,"%" PRIu8 "\n",eNB_mac_inst->UE_sched_ctrl[event.ue].min_ul_bandwidth[event.lcid]); + } + + } + else if(!strcmp((char *) event.key, "min_dl_bandwidth") && event.value!=NULL && validate_mac(event)) + { + + Mac_config* mac_config = malloc(sizeof(Mac_config)*16); + mac_config = (Mac_config *) event.value; + int j=0; + if(event.ue == -1 && event.lcid == -1) + { + for(i=0;i<NUMBER_OF_UE_MAX;i++) + { + if(event.value + i !=NULL) + { + + for(j=0;j<MAX_NUM_LCID;j++) + { + + if(&mac_config[i].min_dl_bandwidth[j]!=NULL) + { + oai_emulation->mac_config[i].min_dl_bandwidth[j]= mac_config[i].min_dl_bandwidth[j]; + eNB_mac_inst->UE_sched_ctrl[i].min_dl_bandwidth[j] = oai_emulation->mac_config[i].min_dl_bandwidth[j]; + LOG_I(EMU,"dl_bandwidth UE %d LCID %d:",i,j); + LOG_I(EMU,"%" PRIu8 "\n",eNB_mac_inst->UE_sched_ctrl[i].min_dl_bandwidth[j]); + } + } + } + } + } + else + { + oai_emulation->mac_config[event.ue].min_dl_bandwidth[event.lcid]= mac_config[event.ue].min_dl_bandwidth[event.lcid]; + eNB_mac_inst->UE_sched_ctrl[event.ue].min_dl_bandwidth[event.lcid] = oai_emulation->mac_config[event.ue].min_dl_bandwidth[event.lcid]; + LOG_I(EMU,"min_dl_bandwidth UE %d LCID %d:",event.ue, event.lcid); + LOG_I(EMU,"%" PRIu8 "\n",eNB_mac_inst->UE_sched_ctrl[event.ue].min_dl_bandwidth[event.lcid]); + } + } + else if(!strcmp((char *) event.key, "ue_AggregatedMaximumBitrateDL") && event.value!=NULL && validate_mac(event)) + { + Mac_config* mac_config = malloc(sizeof(Mac_config)*16); + mac_config = (Mac_config *) event.value; + + LOG_I(EMU,"ue_AggregatedMaximumBitrateDL update \n"); + if(event.ue == -1) + { + for(i=0;i<NUMBER_OF_UE_MAX;i++) + { + oai_emulation->mac_config[i].ue_AggregatedMaximumBitrateDL= mac_config[i].ue_AggregatedMaximumBitrateDL; + eNB_mac_inst->UE_sched_ctrl[i].ue_AggregatedMaximumBitrateDL = oai_emulation->mac_config[i].ue_AggregatedMaximumBitrateDL; + LOG_I(EMU,"ue_AggregatedMaximumBitrateDL UE %d:\n",event.ue); + LOG_I(EMU,"%" PRIu64 "\n",eNB_mac_inst->UE_sched_ctrl[i].ue_AggregatedMaximumBitrateDL); + } + } + else + { + oai_emulation->mac_config[event.ue].ue_AggregatedMaximumBitrateDL= mac_config[event.ue].ue_AggregatedMaximumBitrateDL; + eNB_mac_inst->UE_sched_ctrl[event.ue].ue_AggregatedMaximumBitrateDL = oai_emulation->mac_config[event.ue].ue_AggregatedMaximumBitrateDL; + LOG_I(EMU,"ue_AggregatedMaximumBitrateDL UE %d:\n",event.ue); + LOG_I(EMU,"%" PRIu64 "\n",eNB_mac_inst->UE_sched_ctrl[event.ue].ue_AggregatedMaximumBitrateDL); + } + + } + else if(!strcmp((char *) event.key, "ue_AggregatedMaximumBitrateUL") && event.value!=NULL && validate_mac(event)) + { + + Mac_config* mac_config = malloc(sizeof(Mac_config)*16); + mac_config = (Mac_config *) event.value; + + LOG_I(EMU,"ue_AggregatedMaximumBitrateUL update \n"); + if(event.ue == -1) + { + for(i=0;i<NUMBER_OF_UE_MAX;i++) + { + oai_emulation->mac_config[i].ue_AggregatedMaximumBitrateUL= mac_config[i].ue_AggregatedMaximumBitrateUL; + eNB_mac_inst->UE_sched_ctrl[i].ue_AggregatedMaximumBitrateUL = oai_emulation->mac_config[i].ue_AggregatedMaximumBitrateUL; + LOG_I(EMU,"ue_AggregatedMaximumBitrateUL UE %d:\n",i); + LOG_I(EMU,"%" PRIu64 "\n",eNB_mac_inst->UE_sched_ctrl[i].ue_AggregatedMaximumBitrateUL); + } + } + else + { + oai_emulation->mac_config[event.ue].ue_AggregatedMaximumBitrateUL= mac_config[event.ue].ue_AggregatedMaximumBitrateUL; + eNB_mac_inst->UE_sched_ctrl[event.ue].ue_AggregatedMaximumBitrateUL = oai_emulation->mac_config[event.ue].ue_AggregatedMaximumBitrateUL; + LOG_I(EMU,"ue_AggregatedMaximumBitrateUL UE %d:\n",event.ue); + LOG_I(EMU,"%" PRIu64 "\n",eNB_mac_inst->UE_sched_ctrl[event.ue].ue_AggregatedMaximumBitrateUL); + } + + } + else if(!strcmp((char *) event.key, "cqiSchedInterval") && event.value!=NULL && validate_mac(event)) + { + Mac_config* mac_config = malloc(sizeof(Mac_config)*16); + mac_config = (Mac_config *) event.value; + + LOG_I(EMU,"cqiSchedInterval update \n"); + if(event.ue == -1) + { + for(i=0;i<NUMBER_OF_UE_MAX;i++) + { + oai_emulation->mac_config[i].cqiSchedInterval= mac_config[i].cqiSchedInterval; + eNB_mac_inst->UE_sched_ctrl[i].cqiSchedInterval = oai_emulation->mac_config[i].cqiSchedInterval; + LOG_I(EMU,"cqiSchedInterval UE :\n", i); + LOG_I(EMU,"%" PRIu16 "\n",eNB_mac_inst->UE_sched_ctrl[i].cqiSchedInterval); + } + } + else + { + oai_emulation->mac_config[event.ue].cqiSchedInterval= mac_config[event.ue].cqiSchedInterval; + eNB_mac_inst->UE_sched_ctrl[event.ue].cqiSchedInterval = oai_emulation->mac_config[event.ue].cqiSchedInterval; + LOG_I(EMU,"cqiSchedInterval UE :\n", event.ue); + LOG_I(EMU,"%" PRIu16 "\n",eNB_mac_inst->UE_sched_ctrl[event.ue].cqiSchedInterval); + } + } + else if(!strcmp((char *) event.key, "mac_ContentionResolutionTimer") && event.value!=NULL && validate_mac(event)) + { + Mac_config* mac_config = malloc(sizeof(Mac_config)*16); + mac_config = (Mac_config *) event.value; + LOG_I(EMU,"mac_ContentionResolutionTimer update \n"); + if(event.ue == -1) + { + for(i=0;i<NUMBER_OF_UE_MAX;i++) + { + oai_emulation->mac_config[i].mac_ContentionResolutionTimer= mac_config[i].mac_ContentionResolutionTimer; + eNB_mac_inst->UE_sched_ctrl[i].mac_ContentionResolutionTimer = oai_emulation->mac_config[i].mac_ContentionResolutionTimer; + LOG_I(EMU,"mac_ContentionResolutionTimer UE :\n", i); + LOG_I(EMU,"%" PRIu8 "\n",eNB_mac_inst->UE_sched_ctrl[i].mac_ContentionResolutionTimer); + } + } + else + { + oai_emulation->mac_config[event.ue].mac_ContentionResolutionTimer= mac_config[event.ue].mac_ContentionResolutionTimer; + eNB_mac_inst->UE_sched_ctrl[event.ue].mac_ContentionResolutionTimer = oai_emulation->mac_config[event.ue].mac_ContentionResolutionTimer; + LOG_I(EMU,"mac_ContentionResolutionTimer UE :\n", event.ue); + LOG_I(EMU,"%" PRIu8 "\n",eNB_mac_inst->UE_sched_ctrl[event.ue].mac_ContentionResolutionTimer); + } + } + else if(!strcmp((char *) event.key, "max_allowed_rbs") && event.value!=NULL && validate_mac(event)) + { + + + Mac_config* mac_config = malloc(sizeof(Mac_config)*16); + mac_config = (Mac_config *) event.value; + int j=0; + if(event.ue == -1 && event.lcid == -1) + { + for(i=0;i<NUMBER_OF_UE_MAX;i++) + { + if(event.value + i !=NULL) + { + + for(j=0;j<MAX_NUM_LCID;j++) + { + + if(&mac_config[i].max_allowed_rbs[j]!=NULL) + { + oai_emulation->mac_config[i].max_allowed_rbs[j]= mac_config[i].max_allowed_rbs[j]; + eNB_mac_inst->UE_sched_ctrl[i].max_allowed_rbs[j] = oai_emulation->mac_config[i].max_allowed_rbs[j]; + LOG_I(EMU,"max_allowed_rbs UE %d LCID %d:",i,j); + LOG_I(EMU,"%" PRIu16 "\n",eNB_mac_inst->UE_sched_ctrl[i].max_allowed_rbs[j]); + } + } + } + } + } + else + { + oai_emulation->mac_config[event.ue].max_allowed_rbs[event.lcid]= mac_config[event.ue].max_allowed_rbs[event.lcid]; + eNB_mac_inst->UE_sched_ctrl[event.ue].max_allowed_rbs[event.lcid] = oai_emulation->mac_config[event.ue].max_allowed_rbs[event.lcid]; + LOG_I(EMU,"max_allowed_rbs UE %d LCID %d:",event.ue,event.lcid); + LOG_I(EMU,"%" PRIu16 "\n",eNB_mac_inst->UE_sched_ctrl[event.ue].max_allowed_rbs[event.lcid]); + } + + } + else if(!strcmp((char *) event.key, "max_mcs") && event.value!=NULL && validate_mac(event)) + { + + + + Mac_config* mac_config = malloc(sizeof(Mac_config)*16); + mac_config = (Mac_config *) event.value; + int j=0; + if(event.ue == -1 && event.lcid == -1) + { + for(i=0;i<NUMBER_OF_UE_MAX;i++) + { + + for(j=0;j<MAX_NUM_LCID;j++) + { + + if(&mac_config[i].max_mcs[j]!=NULL) + { + oai_emulation->mac_config[i].max_mcs[j]= mac_config[i].max_mcs[j]; + eNB_mac_inst->UE_sched_ctrl[i].max_mcs[j] = oai_emulation->mac_config[i].max_mcs[j]; + LOG_I(EMU,"max_mcs UE %d LCID %d:",i,j); + LOG_I(EMU,"%" PRIu16 "\n",eNB_mac_inst->UE_sched_ctrl[i].max_mcs[j]); + } + } + + } + } + else + { + oai_emulation->mac_config[event.ue].max_mcs[event.lcid]= mac_config[event.ue].max_mcs[event.lcid]; + eNB_mac_inst->UE_sched_ctrl[event.ue].max_mcs[event.lcid] = oai_emulation->mac_config[event.ue].max_mcs[event.lcid]; + LOG_I(EMU,"max_mcs UE %d LCID %d:",event.ue,event.lcid); + LOG_I(EMU,"%" PRIu16 "\n",eNB_mac_inst->UE_sched_ctrl[event.ue].max_mcs[event.lcid]); + } + } + } + } void update_oai_model(char * key, void * value) { + +} + +void update_sys_model(Event_t event) { + + + printf("\n\n\nA NEW SYS MODEL\n\n\n"); + OAI_Emulation *oai_emulation; + oai_emulation = get_OAI_emulation(); + int i=0; + if(event.optype == READ) + { + if(event.key == NULL) + { + LOG_I(EMU,"wall_penetration_loss_dB %G\n",oai_emulation->environment_system_config.wall_penetration_loss_dB); + LOG_I(EMU,"system_bandwidth_MB %G\n",oai_emulation->environment_system_config.system_bandwidth_MB); + LOG_I(EMU,"system_frequency_GHz %G\n",oai_emulation->environment_system_config.system_frequency_GHz); + + //Fading + LOG_I(EMU,"fading.large_scale.selected_option %s\n",oai_emulation->environment_system_config.fading.large_scale.selected_option); + LOG_I(EMU,"fading.large_scale.free_space %d\n",oai_emulation->environment_system_config.fading.large_scale.free_space); + LOG_I(EMU,"fading.large_scale.urban %d\n",oai_emulation->environment_system_config.fading.large_scale.urban); + LOG_I(EMU,"fading.large_scale.rural %d\n",oai_emulation->environment_system_config.fading.large_scale.rural); + + LOG_I(EMU,"fading.small_scale.selected_option %s\n",oai_emulation->environment_system_config.fading.small_scale.selected_option); + LOG_I(EMU,"fading.small_scale.SCM_A %d\n",oai_emulation->environment_system_config.fading.small_scale.SCM_A); + LOG_I(EMU,"fading.small_scale.SCM_B %d\n",oai_emulation->environment_system_config.fading.small_scale.SCM_B); + LOG_I(EMU,"fading.small_scale.SCM_C %d\n",oai_emulation->environment_system_config.fading.small_scale.SCM_C); + LOG_I(EMU,"fading.small_scale.SCM_D %d\n",oai_emulation->environment_system_config.fading.small_scale.SCM_D); + LOG_I(EMU,"fading.small_scale.rayleigh_8tap %d\n",oai_emulation->environment_system_config.fading.small_scale.rayleigh_8tap); + LOG_I(EMU,"fading.small_scale.EPA %d\n",oai_emulation->environment_system_config.fading.small_scale.EPA); + LOG_I(EMU,"fading.small_scale.EVA %d\n",oai_emulation->environment_system_config.fading.small_scale.EVA); + LOG_I(EMU,"fading.small_scale.ETU %d\n",oai_emulation->environment_system_config.fading.small_scale.ETU); + + LOG_I(EMU,"shadowing.decorrelation_distance_m %G\n",oai_emulation->environment_system_config.fading.shadowing.decorrelation_distance_m); + LOG_I(EMU,"shadowing.variance_dB %G\n",oai_emulation->environment_system_config.fading.shadowing.variance_dB); + LOG_I(EMU,"shadowing.inter_site_correlation %G\n",oai_emulation->environment_system_config.fading.shadowing.inter_site_correlation); + + LOG_I(EMU,"free_space_model_parameters.pathloss_exponent %G\n",oai_emulation->environment_system_config.fading.free_space_model_parameters.pathloss_exponent); + LOG_I(EMU,"free_space_model_parameters.pathloss_0_dB %G\n",oai_emulation->environment_system_config.fading.free_space_model_parameters.pathloss_0_dB); + + LOG_I(EMU,"ricean_8tap.rice_factor_dB %G\n",oai_emulation->environment_system_config.fading.ricean_8tap.rice_factor_dB); + + //Antenna + LOG_I(EMU,"antenna.eNB_antenna.number_of_sectors %d\n",oai_emulation->environment_system_config.antenna.eNB_antenna.number_of_sectors); + LOG_I(EMU,"antenna.eNB_antenna.beam_width_dB %G\n",oai_emulation->environment_system_config.antenna.eNB_antenna.beam_width_dB); + LOG_I(EMU,"antenna.eNB_antenna.antenna_gain_dBi %G\n",oai_emulation->environment_system_config.antenna.eNB_antenna.antenna_gain_dBi); + LOG_I(EMU,"antenna.eNB_antenna.tx_power_dBm %G\n",oai_emulation->environment_system_config.antenna.eNB_antenna.tx_power_dBm); + LOG_I(EMU,"antenna.eNB_antenna.rx_noise_level_dB %G\n",oai_emulation->environment_system_config.antenna.eNB_antenna.rx_noise_level_dB); + for (i = 0;i<3; i++) + { + LOG_I(EMU,"antenna.eNB_antenna.alpha_rad %d %G\n",i,oai_emulation->environment_system_config.antenna.eNB_antenna.alpha_rad[i]); + } + for (i = 0;i<3; i++) + { + LOG_I(EMU,"antenna.eNB_antenna.antenna_orientation_degree %d %G\n",i,oai_emulation->environment_system_config.antenna.eNB_antenna.antenna_orientation_degree[i]); + } + + LOG_I(EMU,"antenna.UE_antenna.antenna_gain_dBi %G\n",oai_emulation->environment_system_config.antenna.UE_antenna.antenna_gain_dBi); + LOG_I(EMU,"antenna.UE_antenna.tx_power_dBm %G\n",oai_emulation->environment_system_config.antenna.UE_antenna.tx_power_dBm); + LOG_I(EMU,"antenna.UE_antenna.rx_noise_level_dB %G\n",oai_emulation->environment_system_config.antenna.UE_antenna.rx_noise_level_dB); + } + else if(!strcmp((char *) event.key, "wall_penetration_loss_dB")) + { + LOG_I(EMU,"wall_penetration_loss_dB %G\n",oai_emulation->environment_system_config.wall_penetration_loss_dB); + } + else if(!strcmp((char *) event.key, "system_bandwidth_MB")) + { + LOG_I(EMU,"system_bandwidth_MB %G\n",oai_emulation->environment_system_config.system_bandwidth_MB); + } + else if(!strcmp((char *) event.key, "system_frequency_GHz")) + { + LOG_I(EMU,"system_frequency_GHz %G\n",oai_emulation->environment_system_config.system_frequency_GHz); + } + else if(!strcmp((char *) event.key, "fading.large_scale.selected_option")) + { + LOG_I(EMU,"fading.large_scale.selected_option %s\n",oai_emulation->environment_system_config.fading.large_scale.selected_option); + } + else if(!strcmp((char *) event.key, "fading.large_scale.free_space")) + { + LOG_I(EMU,"fading.large_scale.free_space %d\n",oai_emulation->environment_system_config.fading.large_scale.free_space); + } + else if(!strcmp((char *) event.key, "fading.large_scale.urban")) + { + LOG_I(EMU,"fading.large_scale.urban %d\n",oai_emulation->environment_system_config.fading.large_scale.urban); + } + else if(!strcmp((char *) event.key, "fading.large_scale.rural")) + { + LOG_I(EMU,"fading.large_scale.rural %d\n",oai_emulation->environment_system_config.fading.large_scale.rural); + } + else if(!strcmp((char *) event.key, "fading.small_scale.selected_option")) + { + LOG_I(EMU,"fading.small_scale.selected_option %s\n",oai_emulation->environment_system_config.fading.small_scale.selected_option); + } + else if(!strcmp((char *) event.key, "fading.small_scale.SCM_A")) + { + LOG_I(EMU,"fading.small_scale.SCM_A %d\n",oai_emulation->environment_system_config.fading.small_scale.SCM_A); + } + else if(!strcmp((char *) event.key, "fading.small_scale.SCM_B")) + { + LOG_I(EMU,"fading.small_scale.SCM_B %d\n",oai_emulation->environment_system_config.fading.small_scale.SCM_B); + } + else if(!strcmp((char *) event.key, "fading.small_scale.SCM_C")) + { + LOG_I(EMU,"fading.small_scale.SCM_C %d\n",oai_emulation->environment_system_config.fading.small_scale.SCM_C); + } + else if(!strcmp((char *) event.key, "fading.small_scale.SCM_D")) + { + LOG_I(EMU,"fading.small_scale.SCM_D %d\n",oai_emulation->environment_system_config.fading.small_scale.SCM_D); + } + else if(!strcmp((char *) event.key, "fading.small_scale.rayleigh_8tap")) + { + LOG_I(EMU,"fading.small_scale.rayleigh_8tap %d\n",oai_emulation->environment_system_config.fading.small_scale.rayleigh_8tap); + } + else if(!strcmp((char *) event.key, "fading.small_scale.EPA")) + { + LOG_I(EMU,"fading.small_scale.EPA %d\n",oai_emulation->environment_system_config.fading.small_scale.EPA); + } + else if(!strcmp((char *) event.key, "fading.small_scale.EVA")) + { + LOG_I(EMU,"fading.small_scale.EVA %d\n",oai_emulation->environment_system_config.fading.small_scale.EVA); + } + else if(!strcmp((char *) event.key, "fading.small_scale.ETU")) + { + LOG_I(EMU,"fading.small_scale.ETU %d\n",oai_emulation->environment_system_config.fading.small_scale.ETU); + } + else if(!strcmp((char *) event.key, "shadowing.decorrelation_distance_m")) + { + LOG_I(EMU,"shadowing.decorrelation_distance_m %G\n",oai_emulation->environment_system_config.fading.shadowing.decorrelation_distance_m); + } + else if(!strcmp((char *) event.key, "shadowing.variance_dB")) + { + LOG_I(EMU,"shadowing.variance_dB %G\n",oai_emulation->environment_system_config.fading.shadowing.variance_dB); + } + else if(!strcmp((char *) event.key, "shadowing.inter_site_correlation")) + { + LOG_I(EMU,"shadowing.inter_site_correlation %G\n",oai_emulation->environment_system_config.fading.shadowing.inter_site_correlation); + } + else if(!strcmp((char *) event.key, "free_space_model_parameters.pathloss_exponent")) + { + LOG_I(EMU,"free_space_model_parameters.pathloss_exponent %G\n",oai_emulation->environment_system_config.fading.free_space_model_parameters.pathloss_exponent); + } + else if(!strcmp((char *) event.key, "free_space_model_parameters.pathloss_0_dB")) + { + LOG_I(EMU,"free_space_model_parameters.pathloss_0_dB %G\n",oai_emulation->environment_system_config.fading.free_space_model_parameters.pathloss_0_dB); + } + else if(!strcmp((char *) event.key, "ricean_8tap.rice_factor_dB")) + { + LOG_I(EMU,"ricean_8tap.rice_factor_dB %G\n",oai_emulation->environment_system_config.fading.ricean_8tap.rice_factor_dB); + } + else if(!strcmp((char *) event.key, "antenna.eNB_antenna.number_of_sectors")) + { + LOG_I(EMU,"antenna.eNB_antenna.number_of_sectors %d\n",oai_emulation->environment_system_config.antenna.eNB_antenna.number_of_sectors); + } + else if(!strcmp((char *) event.key, "antenna.eNB_antenna.beam_width_dB")) + { + LOG_I(EMU,"antenna.eNB_antenna.beam_width_dB %G\n",oai_emulation->environment_system_config.antenna.eNB_antenna.beam_width_dB); + } + else if(!strcmp((char *) event.key, "antenna.eNB_antenna.antenna_gain_dBi")) + { + LOG_I(EMU,"antenna.eNB_antenna.antenna_gain_dBi %G\n",oai_emulation->environment_system_config.antenna.eNB_antenna.antenna_gain_dBi); + } + else if(!strcmp((char *) event.key, "antenna.eNB_antenna.tx_power_dBm")) + { + LOG_I(EMU,"antenna.eNB_antenna.tx_power_dBm %G\n",oai_emulation->environment_system_config.antenna.eNB_antenna.tx_power_dBm); + } + else if(!strcmp((char *) event.key, "antenna.eNB_antenna.rx_noise_level_dB")) + { + LOG_I(EMU,"antenna.eNB_antenna.rx_noise_level_dB %G\n",oai_emulation->environment_system_config.antenna.eNB_antenna.rx_noise_level_dB); + } + else if(!strcmp((char *) event.key, "antenna.eNB_antenna.alpha_rad")) + { + for (i = 0;i<3; i++) + { + LOG_I(EMU,"antenna.eNB_antenna.alpha_rad %d %G\n",i,oai_emulation->environment_system_config.antenna.eNB_antenna.alpha_rad[i]); + } + } + else if(!strcmp((char *) event.key, "antenna.eNB_antenna.antenna_orientation_degree")) + { + for (i = 0;i<3; i++) + { + LOG_I(EMU,"antenna.eNB_antenna.antenna_orientation_degree %d %G\n",i,oai_emulation->environment_system_config.antenna.eNB_antenna.antenna_orientation_degree[i]); + } + } + else if(!strcmp((char *) event.key, "antenna.UE_antenna.antenna_gain_dBi")) + { + LOG_I(EMU,"antenna.UE_antenna.antenna_gain_dBi %G\n",oai_emulation->environment_system_config.antenna.UE_antenna.antenna_gain_dBi); + } + else if(!strcmp((char *) event.key, "antenna.UE_antenna.tx_power_dBm")) + { + LOG_I(EMU,"antenna.UE_antenna.tx_power_dBm %G\n",oai_emulation->environment_system_config.antenna.UE_antenna.tx_power_dBm); + } + else if(!strcmp((char *) event.key, "antenna.UE_antenna.rx_noise_level_dB")) + { + LOG_I(EMU,"antenna.UE_antenna.rx_noise_level_dB %G\n",oai_emulation->environment_system_config.antenna.UE_antenna.rx_noise_level_dB); + } + } + else if(event.optype == WRITE) + { + if(event.key == NULL && event.value!=NULL) + { + Environment_System_Config* new_env_config = (Environment_System_Config *) event.value; + oai_emulation->environment_system_config.wall_penetration_loss_dB = new_env_config->wall_penetration_loss_dB; + oai_emulation->environment_system_config.system_bandwidth_MB = new_env_config->system_bandwidth_MB; + oai_emulation->environment_system_config.system_frequency_GHz = new_env_config->system_frequency_GHz; + //Fading + sprintf(oai_emulation->environment_system_config.fading.large_scale.selected_option,"%s",new_env_config->fading.large_scale.selected_option); + oai_emulation->environment_system_config.fading.large_scale.free_space = new_env_config->fading.large_scale.free_space; + oai_emulation->environment_system_config.fading.large_scale.urban = new_env_config->fading.large_scale.urban; + oai_emulation->environment_system_config.fading.large_scale.rural = new_env_config->fading.large_scale.rural; + + sprintf(oai_emulation->environment_system_config.fading.small_scale.selected_option,"%s",new_env_config->fading.small_scale.selected_option); + oai_emulation->environment_system_config.fading.small_scale.SCM_A = new_env_config->fading.small_scale.SCM_A; + oai_emulation->environment_system_config.fading.small_scale.SCM_B = new_env_config->fading.small_scale.SCM_B; + oai_emulation->environment_system_config.fading.small_scale.SCM_C = new_env_config->fading.small_scale.SCM_C; + oai_emulation->environment_system_config.fading.small_scale.SCM_D = new_env_config->fading.small_scale.SCM_D; + oai_emulation->environment_system_config.fading.small_scale.rayleigh_8tap = new_env_config->fading.small_scale.rayleigh_8tap; + oai_emulation->environment_system_config.fading.small_scale.EPA = new_env_config->fading.small_scale.EPA; + oai_emulation->environment_system_config.fading.small_scale.EVA = new_env_config->fading.small_scale.EVA; + oai_emulation->environment_system_config.fading.small_scale.ETU = new_env_config->fading.small_scale.ETU; + + oai_emulation->environment_system_config.fading.shadowing.decorrelation_distance_m = new_env_config->fading.shadowing.decorrelation_distance_m; + oai_emulation->environment_system_config.fading.shadowing.variance_dB = new_env_config->fading.shadowing.variance_dB; + oai_emulation->environment_system_config.fading.shadowing.inter_site_correlation = new_env_config->fading.shadowing.inter_site_correlation; + + oai_emulation->environment_system_config.fading.free_space_model_parameters.pathloss_exponent = new_env_config->fading.free_space_model_parameters.pathloss_exponent; + oai_emulation->environment_system_config.fading.free_space_model_parameters.pathloss_0_dB = new_env_config->fading.free_space_model_parameters.pathloss_0_dB; + + oai_emulation->environment_system_config.fading.ricean_8tap.rice_factor_dB = new_env_config->fading.ricean_8tap.rice_factor_dB; + + //Antenna + oai_emulation->environment_system_config.antenna.eNB_antenna.number_of_sectors = new_env_config->antenna.eNB_antenna.number_of_sectors; + oai_emulation->environment_system_config.antenna.eNB_antenna.beam_width_dB = new_env_config->antenna.eNB_antenna.beam_width_dB; + oai_emulation->environment_system_config.antenna.eNB_antenna.antenna_gain_dBi = new_env_config->antenna.eNB_antenna.antenna_gain_dBi; + oai_emulation->environment_system_config.antenna.eNB_antenna.tx_power_dBm = new_env_config->antenna.eNB_antenna.tx_power_dBm; + oai_emulation->environment_system_config.antenna.eNB_antenna.rx_noise_level_dB = new_env_config->antenna.eNB_antenna.rx_noise_level_dB; + for (i = 0;i<3; i++) + { + oai_emulation->environment_system_config.antenna.eNB_antenna.alpha_rad[i] = new_env_config->antenna.eNB_antenna.alpha_rad[i]; + } + for (i = 0;i<3; i++) + { + oai_emulation->environment_system_config.antenna.eNB_antenna.antenna_orientation_degree[i] = new_env_config->antenna.eNB_antenna.antenna_orientation_degree[i]; + } + + oai_emulation->environment_system_config.antenna.UE_antenna.antenna_gain_dBi = new_env_config->antenna.UE_antenna.antenna_gain_dBi; + oai_emulation->environment_system_config.antenna.UE_antenna.tx_power_dBm = new_env_config->antenna.UE_antenna.tx_power_dBm; + oai_emulation->environment_system_config.antenna.UE_antenna.rx_noise_level_dB = new_env_config->antenna.UE_antenna.rx_noise_level_dB; + } + } } -void update_sys_model(char * key, void * value) { +void update_topo_model(Event_t event) { + + printf("\n\n\nA NEW MOB MODEL\n\n\n"); + OAI_Emulation *oai_emulation; + oai_emulation = get_OAI_emulation(); + + if(event.optype == READ) + { + if(event.key == NULL) + { + //read all values + LOG_I(EMU,"UE Mobility type %s\n",oai_emulation->topology_config.mobility.UE_mobility.UE_mobility_type.selected_option); + LOG_I(EMU,"eNB Mobility type %s\n",oai_emulation->topology_config.mobility.eNB_mobility.eNB_mobility_type.selected_option); + LOG_I(EMU,"grid_trip_type %s\n",oai_emulation->topology_config.mobility.UE_mobility.grid_walk.grid_trip_type.selected_option); + LOG_I(EMU,"UE_moving_dynamics_min_speed_mps %G\n",oai_emulation->topology_config.mobility.UE_mobility.UE_moving_dynamics.min_speed_mps); + LOG_I(EMU,"UE_moving_dynamics_min_sleep_ms %G\n",oai_emulation->topology_config.mobility.UE_mobility.UE_moving_dynamics.min_sleep_ms); + LOG_I(EMU,"UE_moving_dynamics_max_sleep_ms %G\n",oai_emulation->topology_config.mobility.UE_mobility.UE_moving_dynamics.max_sleep_ms); + LOG_I(EMU,"UE_moving_dynamics_max_speed_mps %G\n",oai_emulation->topology_config.mobility.UE_mobility.UE_moving_dynamics.max_speed_mps); + LOG_I(EMU,"UE_moving_dynamics_min_journey_time_ms %G\n",oai_emulation->topology_config.mobility.UE_mobility.UE_moving_dynamics.min_journey_time_ms); + LOG_I(EMU,"UE_moving_dynamics_max_journey_time_ms %G\n",oai_emulation->topology_config.mobility.UE_mobility.UE_moving_dynamics.max_journey_time_ms); + LOG_I(EMU,"grid_map_horizontal_grid %G\n",oai_emulation->topology_config.mobility.UE_mobility.grid_walk.grid_map.horizontal_grid); + LOG_I(EMU,"grid_map_vertical_grid %G\n",oai_emulation->topology_config.mobility.UE_mobility.grid_walk.grid_map.vertical_grid); + LOG_I(EMU,"UE_initial_distribution_selected_option %s\n",oai_emulation->topology_config.mobility.UE_mobility.UE_initial_distribution.selected_option); + LOG_I(EMU,"random_UE_distribution_number_of_nodes %d\n",oai_emulation->topology_config.mobility.UE_mobility.random_UE_distribution.number_of_nodes); + LOG_I(EMU,"concentrated_UE_distribution_number_of_nodes %d\n",oai_emulation->topology_config.mobility.UE_mobility.concentrated_UE_distribution.number_of_nodes); + LOG_I(EMU,"random_grid_number_of_nodes %d\n",oai_emulation->topology_config.mobility.UE_mobility.grid_UE_distribution.random_grid.number_of_nodes); + LOG_I(EMU,"border_grid_number_of_nodes %d\n",oai_emulation->topology_config.mobility.UE_mobility.grid_UE_distribution.border_grid.number_of_nodes); + LOG_I(EMU,"eNB_initial_distribution_selected_option %s\n",oai_emulation->topology_config.mobility.eNB_mobility.eNB_initial_distribution.selected_option); + LOG_I(EMU,"random_eNB_distribution_number_of_cells %d\n",oai_emulation->topology_config.mobility.eNB_mobility.random_eNB_distribution.number_of_cells); + LOG_I(EMU,"hexagonal_eNB_distribution_number_of_cells %d\n",oai_emulation->topology_config.mobility.eNB_mobility.hexagonal_eNB_distribution.number_of_cells); + + LOG_I(EMU,"hexagonal_eNB_distribution_inter_eNB_distance_km %G\n",oai_emulation->topology_config.mobility.eNB_mobility.hexagonal_eNB_distribution.inter_eNB_distance_km); + LOG_I(EMU,"grid_eNB_distribution_number_of_grid_x %d\n",oai_emulation->topology_config.mobility.eNB_mobility.grid_eNB_distribution.number_of_grid_x); + LOG_I(EMU,"grid_eNB_distribution_number_of_grid_y %d\n",oai_emulation->topology_config.mobility.eNB_mobility.grid_eNB_distribution.number_of_grid_y); + + LOG_I(EMU,"trace_config_trace_mobility_file %s\n",oai_emulation->topology_config.mobility.eNB_mobility.trace_config.trace_mobility_file); + LOG_I(EMU,"trace_config_trace_mobility_file %s\n",oai_emulation->topology_config.mobility.UE_mobility.trace_config.trace_mobility_file); + LOG_I(EMU,"sumo_config_command %s\n",oai_emulation->topology_config.mobility.UE_mobility.sumo_config.command); + LOG_I(EMU,"sumo_config_file %s\n",oai_emulation->topology_config.mobility.UE_mobility.sumo_config.file); + + LOG_I(EMU,"sumo_config_start %d\n",oai_emulation->topology_config.mobility.UE_mobility.sumo_config.start); + LOG_I(EMU,"sumo_config_end %d\n",oai_emulation->topology_config.mobility.UE_mobility.sumo_config.end); + LOG_I(EMU,"sumo_config_step %d\n",oai_emulation->topology_config.mobility.UE_mobility.sumo_config.step); // 1000ms + LOG_I(EMU,"sumo_config_hport %d\n",oai_emulation->topology_config.mobility.UE_mobility.sumo_config.hport); + } + else if(!strcmp((char *) event.key, "UE_mobility_type")) + { + LOG_I(EMU,"UE Mobility type %s\n",oai_emulation->topology_config.mobility.UE_mobility.UE_mobility_type.selected_option); + } + else if(!strcmp((char *) event.key, "eNB_mobility_type")) + { + LOG_I(EMU,"eNB Mobility type %s\n",oai_emulation->topology_config.mobility.eNB_mobility.eNB_mobility_type.selected_option); + } + else if(!strcmp((char *) event.key, "grid_trip_type")) + { + LOG_I(EMU,"grid_trip_type %s\n",oai_emulation->topology_config.mobility.UE_mobility.grid_walk.grid_trip_type.selected_option); + } + else if(!strcmp((char *) event.key, "UE_moving_dynamics_min_speed_mps")) + { + LOG_I(EMU,"UE_moving_dynamics_min_speed_mps %G\n",oai_emulation->topology_config.mobility.UE_mobility.UE_moving_dynamics.min_speed_mps); + } + else if(!strcmp((char *) event.key, "UE_moving_dynamics_min_sleep_ms")) + { + LOG_I(EMU,"UE_moving_dynamics_min_sleep_ms %G\n",oai_emulation->topology_config.mobility.UE_mobility.UE_moving_dynamics.min_sleep_ms); + } + else if(!strcmp((char *) event.key, "UE_moving_dynamics_max_sleep_ms")) + { + LOG_I(EMU,"UE_moving_dynamics_max_sleep_ms %G\n",oai_emulation->topology_config.mobility.UE_mobility.UE_moving_dynamics.max_sleep_ms); + } + else if(!strcmp((char *) event.key, "UE_moving_dynamics_max_speed_mps")) + { + LOG_I(EMU,"UE_moving_dynamics_max_speed_mps %G\n",oai_emulation->topology_config.mobility.UE_mobility.UE_moving_dynamics.max_speed_mps); + } + else if(!strcmp((char *) event.key, "UE_moving_dynamics_min_journey_time_ms")) + { + LOG_I(EMU,"UE_moving_dynamics_min_journey_time_ms %G\n",oai_emulation->topology_config.mobility.UE_mobility.UE_moving_dynamics.min_journey_time_ms); + } + else if(!strcmp((char *) event.key, "UE_moving_dynamics_max_journey_time_ms")) + { + LOG_I(EMU,"UE_moving_dynamics_max_journey_time_ms %G\n",oai_emulation->topology_config.mobility.UE_mobility.UE_moving_dynamics.max_journey_time_ms); + } + else if(!strcmp((char *) event.key, "grid_map_horizontal_grid")) + { + LOG_I(EMU,"grid_map_horizontal_grid %G\n",oai_emulation->topology_config.mobility.UE_mobility.grid_walk.grid_map.horizontal_grid); + } + else if(!strcmp((char *) event.key, "grid_map_vertical_grid")) + { + LOG_I(EMU,"grid_map_vertical_grid %G\n",oai_emulation->topology_config.mobility.UE_mobility.grid_walk.grid_map.vertical_grid); + } + else if(!strcmp((char *) event.key, "UE_initial_distribution_selected_option")) + { + LOG_I(EMU,"UE_initial_distribution_selected_option %s\n",oai_emulation->topology_config.mobility.UE_mobility.UE_initial_distribution.selected_option); + } + else if(!strcmp((char *) event.key, "random_UE_distribution_number_of_nodes")) + { + LOG_I(EMU,"random_UE_distribution_number_of_nodes %d\n",oai_emulation->topology_config.mobility.UE_mobility.random_UE_distribution.number_of_nodes); + } + else if(!strcmp((char *) event.key, "concentrated_UE_distribution_number_of_nodes")) + { + LOG_I(EMU,"concentrated_UE_distribution_number_of_nodes %d\n",oai_emulation->topology_config.mobility.UE_mobility.concentrated_UE_distribution.number_of_nodes); + } + else if(!strcmp((char *) event.key, "random_grid_number_of_nodes")) + { + LOG_I(EMU,"random_grid_number_of_nodes %d\n",oai_emulation->topology_config.mobility.UE_mobility.grid_UE_distribution.random_grid.number_of_nodes); + } + else if(!strcmp((char *) event.key, "order_grid_number_of_nodes")) + { + LOG_I(EMU,"border_grid_number_of_nodes %d\n",oai_emulation->topology_config.mobility.UE_mobility.grid_UE_distribution.border_grid.number_of_nodes); + } + else if(!strcmp((char *) event.key, "eNB_initial_distribution_selected_option")) + { + LOG_I(EMU,"eNB_initial_distribution_selected_option %s\n",oai_emulation->topology_config.mobility.eNB_mobility.eNB_initial_distribution.selected_option); + } + else if(!strcmp((char *) event.key, "random_eNB_distribution_number_of_cells")) + { + LOG_I(EMU,"random_eNB_distribution_number_of_cells %d\n",oai_emulation->topology_config.mobility.eNB_mobility.random_eNB_distribution.number_of_cells); + } + else if(!strcmp((char *) event.key, "hexagonal_eNB_distribution_number_of_cells")) + { + LOG_I(EMU,"hexagonal_eNB_distribution_number_of_cells %d\n",oai_emulation->topology_config.mobility.eNB_mobility.hexagonal_eNB_distribution.number_of_cells); + } + else if(!strcmp((char *) event.key, "hexagonal_eNB_distribution_inter_eNB_distance_km")) + { + LOG_I(EMU,"hexagonal_eNB_distribution_inter_eNB_distance_km %G\n",oai_emulation->topology_config.mobility.eNB_mobility.hexagonal_eNB_distribution.inter_eNB_distance_km); + } + else if(!strcmp((char *) event.key, "grid_eNB_distribution_number_of_grid_x")) + { + LOG_I(EMU,"grid_eNB_distribution_number_of_grid_x %d\n",oai_emulation->topology_config.mobility.eNB_mobility.grid_eNB_distribution.number_of_grid_x); + } + else if(!strcmp((char *) event.key, "grid_eNB_distribution_number_of_grid_y")) + { + LOG_I(EMU,"grid_eNB_distribution_number_of_grid_y %d\n",oai_emulation->topology_config.mobility.eNB_mobility.grid_eNB_distribution.number_of_grid_y); + } + else if(!strcmp((char *) event.key, "eNB_mobility_trace_config_trace_mobility_file")) + { + LOG_I(EMU,"eNB_trace_config_trace_mobility_file %s\n",oai_emulation->topology_config.mobility.eNB_mobility.trace_config.trace_mobility_file); + } + else if(!strcmp((char *) event.key, "UE_mobility_trace_config_trace_mobility_file")) + { + LOG_I(EMU,"UE_trace_config_trace_mobility_file %s\n",oai_emulation->topology_config.mobility.UE_mobility.trace_config.trace_mobility_file); + } + else if(!strcmp((char *) event.key, "sumo_config_command")) + { + LOG_I(EMU,"sumo_config_command %s\n",oai_emulation->topology_config.mobility.UE_mobility.sumo_config.command); + } + else if(!strcmp((char *) event.key, "sumo_config_file")) + { + LOG_I(EMU,"sumo_config_file %s\n",oai_emulation->topology_config.mobility.UE_mobility.sumo_config.file); + } + else if(!strcmp((char *) event.key, "sumo_config_start")) + { + LOG_I(EMU,"sumo_config_start %d\n",oai_emulation->topology_config.mobility.UE_mobility.sumo_config.start); + } + else if(!strcmp((char *) event.key, "sumo_config_end")) + { + LOG_I(EMU,"sumo_config_end %d\n",oai_emulation->topology_config.mobility.UE_mobility.sumo_config.end); + } + else if(!strcmp((char *) event.key, "sumo_config_step")) + { + LOG_I(EMU,"sumo_config_step %d\n",oai_emulation->topology_config.mobility.UE_mobility.sumo_config.step); // 1000ms + } + else if(!strcmp((char *) event.key, "sumo_config_hport")) + { + LOG_I(EMU,"sumo_config_hport %d\n",oai_emulation->topology_config.mobility.UE_mobility.sumo_config.hport); + } + } + else if(event.optype == WRITE && event.value !=NULL) + { + Mobility * new_mobility_model = (Mobility *) event.value; + if(event.key == NULL) + { + //global model update + + sprintf(oai_emulation->topology_config.mobility.UE_mobility.UE_mobility_type.selected_option, "%s", new_mobility_model->UE_mobility.UE_mobility_type.selected_option); + oai_emulation->topology_config.mobility.UE_mobility.grid_walk.grid_map.horizontal_grid = new_mobility_model->UE_mobility.grid_walk.grid_map.horizontal_grid; + oai_emulation->topology_config.mobility.UE_mobility.grid_walk.grid_map.vertical_grid = new_mobility_model->UE_mobility.grid_walk.grid_map.vertical_grid; + sprintf(oai_emulation->topology_config.mobility.UE_mobility.grid_walk.grid_trip_type.selected_option, "%s", new_mobility_model->UE_mobility.grid_walk.grid_trip_type.selected_option); + sprintf(oai_emulation->topology_config.mobility.UE_mobility.UE_initial_distribution.selected_option, "%s", new_mobility_model->UE_mobility.UE_initial_distribution.selected_option); + oai_emulation->topology_config.mobility.UE_mobility.random_UE_distribution.number_of_nodes = new_mobility_model->UE_mobility.random_UE_distribution.number_of_nodes; + oai_emulation->topology_config.mobility.UE_mobility.concentrated_UE_distribution.number_of_nodes = new_mobility_model->UE_mobility.concentrated_UE_distribution.number_of_nodes; + oai_emulation->topology_config.mobility.UE_mobility.grid_UE_distribution.random_grid.number_of_nodes = new_mobility_model->UE_mobility.grid_UE_distribution.random_grid.number_of_nodes; + oai_emulation->topology_config.mobility.UE_mobility.grid_UE_distribution.border_grid.number_of_nodes = new_mobility_model->UE_mobility.grid_UE_distribution.border_grid.number_of_nodes; + oai_emulation->topology_config.mobility.UE_mobility.UE_moving_dynamics.min_speed_mps = new_mobility_model->UE_mobility.UE_moving_dynamics.min_speed_mps; + oai_emulation->topology_config.mobility.UE_mobility.UE_moving_dynamics.max_speed_mps = new_mobility_model->UE_mobility.UE_moving_dynamics.max_speed_mps; + oai_emulation->topology_config.mobility.UE_mobility.UE_moving_dynamics.min_sleep_ms = new_mobility_model->UE_mobility.UE_moving_dynamics.min_sleep_ms; + oai_emulation->topology_config.mobility.UE_mobility.UE_moving_dynamics.max_sleep_ms = new_mobility_model->UE_mobility.UE_moving_dynamics.max_sleep_ms; + oai_emulation->topology_config.mobility.UE_mobility.UE_moving_dynamics.min_journey_time_ms = new_mobility_model->UE_mobility.UE_moving_dynamics.min_journey_time_ms; + oai_emulation->topology_config.mobility.UE_mobility.UE_moving_dynamics.max_journey_time_ms = new_mobility_model->UE_mobility.UE_moving_dynamics.max_journey_time_ms; + sprintf(oai_emulation->topology_config.mobility.eNB_mobility.eNB_mobility_type.selected_option, "%s", new_mobility_model->eNB_mobility.eNB_mobility_type.selected_option); + sprintf(oai_emulation->topology_config.mobility.eNB_mobility.eNB_initial_distribution.selected_option, "%s", new_mobility_model->eNB_mobility.eNB_initial_distribution.selected_option); + oai_emulation->topology_config.mobility.eNB_mobility.random_eNB_distribution.number_of_cells = new_mobility_model->eNB_mobility.random_eNB_distribution.number_of_cells; + oai_emulation->topology_config.mobility.eNB_mobility.hexagonal_eNB_distribution.number_of_cells = new_mobility_model->eNB_mobility.hexagonal_eNB_distribution.number_of_cells; + oai_emulation->topology_config.mobility.eNB_mobility.hexagonal_eNB_distribution.inter_eNB_distance_km = new_mobility_model->eNB_mobility.hexagonal_eNB_distribution.inter_eNB_distance_km; + oai_emulation->topology_config.mobility.eNB_mobility.grid_eNB_distribution.number_of_grid_x = new_mobility_model->eNB_mobility.grid_eNB_distribution.number_of_grid_x; + oai_emulation->topology_config.mobility.eNB_mobility.grid_eNB_distribution.number_of_grid_y = new_mobility_model->eNB_mobility.grid_eNB_distribution.number_of_grid_y; + + sprintf(oai_emulation->topology_config.mobility.eNB_mobility.trace_config.trace_mobility_file,"static_1enb.tr"); + sprintf(oai_emulation->topology_config.mobility.UE_mobility.trace_config.trace_mobility_file,"static_2ues.tr"); + sprintf(oai_emulation->topology_config.mobility.UE_mobility.sumo_config.command,"sumo"); + sprintf(oai_emulation->topology_config.mobility.UE_mobility.sumo_config.file,"%s/UTIL/OMG/SUMO/SCENARIOS/scen.sumo.cfg",getenv("OPENAIR2_DIR")); + sprintf(oai_emulation->topology_config.mobility.UE_mobility.sumo_config.hip,"127.0.1.1"); + + oai_emulation->topology_config.mobility.UE_mobility.sumo_config.start = new_mobility_model->UE_mobility.sumo_config.start; + oai_emulation->topology_config.mobility.UE_mobility.sumo_config.end = new_mobility_model->UE_mobility.sumo_config.end; + oai_emulation->topology_config.mobility.UE_mobility.sumo_config.step = new_mobility_model->UE_mobility.sumo_config.step; // 1000ms + oai_emulation->topology_config.mobility.UE_mobility.sumo_config.hport = new_mobility_model->UE_mobility.sumo_config.hport; + } + if(!strcmp((char *) event.key, "UE_mobility_type")) + { + sprintf(oai_emulation->topology_config.mobility.UE_mobility.UE_mobility_type.selected_option, "%s", new_mobility_model->UE_mobility.UE_mobility_type.selected_option); + + } + else if(!strcmp((char *) event.key, "eNB_mobility_type")) + { + sprintf(oai_emulation->topology_config.mobility.eNB_mobility.eNB_mobility_type.selected_option, "%s", new_mobility_model->eNB_mobility.eNB_mobility_type.selected_option); + } + else if(!strcmp((char *) event.key, "grid_trip_type")) + { + sprintf(oai_emulation->topology_config.mobility.UE_mobility.grid_walk.grid_trip_type.selected_option, "%s", new_mobility_model->UE_mobility.grid_walk.grid_trip_type.selected_option); + } + else if(!strcmp((char *) event.key, "UE_moving_dynamics_min_speed_mps")) + { + oai_emulation->topology_config.mobility.UE_mobility.UE_moving_dynamics.min_speed_mps = new_mobility_model->UE_mobility.UE_moving_dynamics.min_speed_mps; + } + else if(!strcmp((char *) event.key, "UE_moving_dynamics_min_sleep_ms")) + { +oai_emulation->topology_config.mobility.UE_mobility.UE_moving_dynamics.min_sleep_ms = new_mobility_model->UE_mobility.UE_moving_dynamics.min_sleep_ms; + } + else if(!strcmp((char *) event.key, "UE_moving_dynamics_max_sleep_ms")) + { +oai_emulation->topology_config.mobility.UE_mobility.UE_moving_dynamics.max_sleep_ms = new_mobility_model->UE_mobility.UE_moving_dynamics.max_sleep_ms; + } + else if(!strcmp((char *) event.key, "UE_moving_dynamics_max_speed_mps")) + { +oai_emulation->topology_config.mobility.UE_mobility.UE_moving_dynamics.max_speed_mps = new_mobility_model->UE_mobility.UE_moving_dynamics.max_speed_mps; + } + else if(!strcmp((char *) event.key, "UE_moving_dynamics_min_journey_time_ms")) + { + oai_emulation->topology_config.mobility.UE_mobility.UE_moving_dynamics.min_journey_time_ms = new_mobility_model->UE_mobility.UE_moving_dynamics.min_journey_time_ms; + } + else if(!strcmp((char *) event.key, "UE_moving_dynamics_max_journey_time_ms")) + { + oai_emulation->topology_config.mobility.UE_mobility.UE_moving_dynamics.max_journey_time_ms = new_mobility_model->UE_mobility.UE_moving_dynamics.max_journey_time_ms; + } + else if(!strcmp((char *) event.key, "grid_map_horizontal_grid")) + { + oai_emulation->topology_config.mobility.UE_mobility.grid_walk.grid_map.horizontal_grid = new_mobility_model->UE_mobility.grid_walk.grid_map.horizontal_grid; + } + else if(!strcmp((char *) event.key, "grid_map_vertical_grid")) + { + oai_emulation->topology_config.mobility.UE_mobility.grid_walk.grid_map.vertical_grid = new_mobility_model->UE_mobility.grid_walk.grid_map.vertical_grid; + } + else if(!strcmp((char *) event.key, "UE_initial_distribution_selected_option")) + { + sprintf(oai_emulation->topology_config.mobility.UE_mobility.UE_initial_distribution.selected_option, "%s", new_mobility_model->UE_mobility.UE_initial_distribution.selected_option); + } + else if(!strcmp((char *) event.key, "random_UE_distribution_number_of_nodes")) + { + oai_emulation->topology_config.mobility.UE_mobility.random_UE_distribution.number_of_nodes = new_mobility_model->UE_mobility.random_UE_distribution.number_of_nodes; + } + else if(!strcmp((char *) event.key, "concentrated_UE_distribution_number_of_nodes")) + { + oai_emulation->topology_config.mobility.UE_mobility.concentrated_UE_distribution.number_of_nodes = new_mobility_model->UE_mobility.concentrated_UE_distribution.number_of_nodes; + } + else if(!strcmp((char *) event.key, "random_grid_number_of_nodes")) + { + oai_emulation->topology_config.mobility.UE_mobility.grid_UE_distribution.random_grid.number_of_nodes = new_mobility_model->UE_mobility.grid_UE_distribution.random_grid.number_of_nodes; + } + else if(!strcmp((char *) event.key, "border_grid_number_of_nodes")) + { + oai_emulation->topology_config.mobility.UE_mobility.grid_UE_distribution.border_grid.number_of_nodes = new_mobility_model->UE_mobility.grid_UE_distribution.border_grid.number_of_nodes; + } + else if(!strcmp((char *) event.key, "eNB_initial_distribution_selected_option")) + { + sprintf(oai_emulation->topology_config.mobility.eNB_mobility.eNB_initial_distribution.selected_option, "%s", new_mobility_model->eNB_mobility.eNB_initial_distribution.selected_option); + } + else if(!strcmp((char *) event.key, "random_eNB_distribution_number_of_cells")) + { + oai_emulation->topology_config.mobility.eNB_mobility.random_eNB_distribution.number_of_cells = new_mobility_model->eNB_mobility.random_eNB_distribution.number_of_cells; + } + else if(!strcmp((char *) event.key, "hexagonal_eNB_distribution_number_of_cells")) + { + oai_emulation->topology_config.mobility.eNB_mobility.hexagonal_eNB_distribution.number_of_cells = new_mobility_model->eNB_mobility.hexagonal_eNB_distribution.number_of_cells; + } + else if(!strcmp((char *) event.key, "hexagonal_eNB_distribution_inter_eNB_distance_km")) + { + oai_emulation->topology_config.mobility.eNB_mobility.hexagonal_eNB_distribution.inter_eNB_distance_km = new_mobility_model->eNB_mobility.hexagonal_eNB_distribution.inter_eNB_distance_km; + } + else if(!strcmp((char *) event.key, "grid_eNB_distribution_number_of_grid_x")) + { + oai_emulation->topology_config.mobility.eNB_mobility.grid_eNB_distribution.number_of_grid_x = new_mobility_model->eNB_mobility.grid_eNB_distribution.number_of_grid_x; + } + else if(!strcmp((char *) event.key, "grid_eNB_distribution_number_of_grid_y")) + { + oai_emulation->topology_config.mobility.eNB_mobility.grid_eNB_distribution.number_of_grid_y = new_mobility_model->eNB_mobility.grid_eNB_distribution.number_of_grid_y; + } + else if(!strcmp((char *) event.key, "eNB_mobility_trace_config_trace_mobility_file")) + { + sprintf(oai_emulation->topology_config.mobility.eNB_mobility.trace_config.trace_mobility_file,"static_1enb.tr"); + } + else if(!strcmp((char *) event.key, "UE_mobility_trace_config_trace_mobility_file")) + { + sprintf(oai_emulation->topology_config.mobility.UE_mobility.trace_config.trace_mobility_file,"static_2ues.tr"); + } + else if(!strcmp((char *) event.key, "sumo_config_command")) + { + sprintf(oai_emulation->topology_config.mobility.UE_mobility.sumo_config.command,"sumo"); + } + else if(!strcmp((char *) event.key, "sumo_config_file")) + { + sprintf(oai_emulation->topology_config.mobility.UE_mobility.sumo_config.file,"%s/UTIL/OMG/SUMO/SCENARIOS/scen.sumo.cfg",getenv("OPENAIR2_DIR")); + } + else if(!strcmp((char *) event.key, "sumo_config_start")) + { + oai_emulation->topology_config.mobility.UE_mobility.sumo_config.start = new_mobility_model->UE_mobility.sumo_config.start; + } + else if(!strcmp((char *) event.key, "sumo_config_end")) + { + oai_emulation->topology_config.mobility.UE_mobility.sumo_config.end = new_mobility_model->UE_mobility.sumo_config.end; + } + else if(!strcmp((char *) event.key, "sumo_config_step")) + { + oai_emulation->topology_config.mobility.UE_mobility.sumo_config.step = new_mobility_model->UE_mobility.sumo_config.step; + } + else if(!strcmp((char *) event.key, "sumo_config_hport")) + { + oai_emulation->topology_config.mobility.UE_mobility.sumo_config.hport = new_mobility_model->UE_mobility.sumo_config.hport; + } + else if(!strcmp((char *) event.key, "sumo_config.hip")) + { + sprintf(oai_emulation->topology_config.mobility.UE_mobility.sumo_config.hip,"127.0.1.1"); + } + + } } -void update_topo_model(char * key, void * value) { - printf("\n\n\nA NEW MOB MODEL\n\n\n"); -/* - if (key != NULL) { //Global model update - Mobility * new_mobility_model = (Mobility *) value; - - sprintf(oai_emulation.topology_config.mobility.UE_mobility.UE_mobility_type.selected_option, "%s", new_mobility_model->UE_mobility.UE_mobility_type.selected_option); - oai_emulation.topology_config.mobility.UE_mobility.grid_walk.grid_map.horizontal_grid = new_mobility_model->UE_mobility.grid_walk.grid_map.horizontal_grid; - oai_emulation.topology_config.mobility.UE_mobility.grid_walk.grid_map.vertical_grid = new_mobility_model->UE_mobility.grid_walk.grid_map.vertical_grid; - sprintf(oai_emulation.topology_config.mobility.UE_mobility.grid_walk.grid_trip_type.selected_option, "%s", new_mobility_model->UE_mobility.grid_walk.grid_trip_type.selected_option); - sprintf(oai_emulation.topology_config.mobility.UE_mobility.UE_initial_distribution.selected_option, "%s", new_mobility_model->UE_mobility.UE_initial_distribution.selected_option); - oai_emulation.topology_config.mobility.UE_mobility.random_UE_distribution.number_of_nodes = new_mobility_model->UE_mobility.random_UE_distribution.number_of_nodes; - oai_emulation.topology_config.mobility.UE_mobility.concentrated_UE_distribution.number_of_nodes = new_mobility_model->UE_mobility.concentrated_UE_distribution.number_of_nodes; - oai_emulation.topology_config.mobility.UE_mobility.grid_UE_distribution.random_grid.number_of_nodes = new_mobility_model->UE_mobility.grid_UE_distribution.random_grid.number_of_nodes; - oai_emulation.topology_config.mobility.UE_mobility.grid_UE_distribution.border_grid.number_of_nodes = new_mobility_model->UE_mobility.grid_UE_distribution.border_grid.number_of_nodes; - oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.min_speed_mps = new_mobility_model->UE_mobility.UE_moving_dynamics.min_speed_mps; - oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.max_speed_mps = new_mobility_model->UE_mobility.UE_moving_dynamics.max_speed_mps; - oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.min_sleep_ms = new_mobility_model->UE_mobility.UE_moving_dynamics.min_sleep_ms; - oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.max_sleep_ms = new_mobility_model->UE_mobility.UE_moving_dynamics.max_sleep_ms; - oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.min_journey_time_ms = new_mobility_model->UE_mobility.UE_moving_dynamics.min_journey_time_ms; - oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.max_journey_time_ms = new_mobility_model->UE_mobility.UE_moving_dynamics.max_journey_time_ms; - sprintf(oai_emulation.topology_config.mobility.eNB_mobility.eNB_mobility_type.selected_option, "%s", new_mobility_model->eNB_mobility.eNB_mobility_type.selected_option); - sprintf(oai_emulation.topology_config.mobility.eNB_mobility.eNB_initial_distribution.selected_option, "%s", new_mobility_model->eNB_mobility.eNB_initial_distribution.selected_option); - oai_emulation.topology_config.mobility.eNB_mobility.random_eNB_distribution.number_of_cells = new_mobility_model->eNB_mobility.random_eNB_distribution.number_of_cells; - oai_emulation.topology_config.mobility.eNB_mobility.hexagonal_eNB_distribution.number_of_cells = new_mobility_model->eNB_mobility.hexagonal_eNB_distribution.number_of_cells; - oai_emulation.topology_config.mobility.eNB_mobility.hexagonal_eNB_distribution.inter_eNB_distance_km = new_mobility_model->eNB_mobility.hexagonal_eNB_distribution.inter_eNB_distance_km; - oai_emulation.topology_config.mobility.eNB_mobility.grid_eNB_distribution.number_of_grid_x = new_mobility_model->eNB_mobility.grid_eNB_distribution.number_of_grid_x; - oai_emulation.topology_config.mobility.eNB_mobility.grid_eNB_distribution.number_of_grid_y = new_mobility_model->eNB_mobility.grid_eNB_distribution.number_of_grid_y; - - sprintf(oai_emulation.topology_config.mobility.eNB_mobility.trace_config.trace_mobility_file,"static_1enb.tr"); - sprintf(oai_emulation.topology_config.mobility.UE_mobility.trace_config.trace_mobility_file,"static_2ues.tr"); - sprintf(oai_emulation.topology_config.mobility.UE_mobility.sumo_config.command,"sumo"); - sprintf(oai_emulation.topology_config.mobility.UE_mobility.sumo_config.file,"%s/UTIL/OMG/SUMO/SCENARIOS/scen.sumo.cfg",getenv("OPENAIR2_DIR")); - sprintf(oai_emulation.topology_config.mobility.UE_mobility.sumo_config.hip,"127.0.1.1"); - - oai_emulation.topology_config.mobility.UE_mobility.sumo_config.start = new_mobility_model->UE_mobility.sumo_config.start; - oai_emulation.topology_config.mobility.UE_mobility.sumo_config.end = new_mobility_model->UE_mobility.sumo_config.end; - oai_emulation.topology_config.mobility.UE_mobility.sumo_config.step = new_mobility_model->UE_mobility.sumo_config.step; // 1000ms - oai_emulation.topology_config.mobility.UE_mobility.sumo_config.hport = new_mobility_model->UE_mobility.sumo_config.hport; - - } else { //Updating a single parameter::: Here I'll only put some examples - - if (!strcmp((char *) key, "UE_mobility_type")) { - sprintf(oai_emulation.topology_config.mobility.UE_mobility.UE_mobility_type.selected_option, "%s", (char *) value); - } else if (!strcmp((char *) key, "eNB_mobility_type")) { - sprintf(oai_emulation.topology_config.mobility.eNB_mobility.eNB_mobility_type.selected_option, "%s", (char *) value); - } else if (!strcmp((char *) key, "grid_trip_type")) { - sprintf(oai_emulation.topology_config.mobility.UE_mobility.grid_walk.grid_trip_type.selected_option, "%s", (char *) value); - } else if (!strcmp((char *) key, "UE_moving_dynamics_min_speed_mps")) { - oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.min_speed_mps = *((double *) value); - } else if (!strcmp((char *) key, "UE_moving_dynamics_max_speed_mps")) { - oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.max_speed_mps = *((double *) value); - } else if (!strcmp((char *) key, "UE_moving_dynamics_min_sleep_ms")) { - oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.min_sleep_ms = *((double *) value); - } else if (!strcmp((char *) key, "UE_moving_dynamics_max_sleep_ms")) { - oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.max_sleep_ms = *((double *) value); - } else if (!strcmp((char *) key, "UE_moving_dynamics_min_journey_time_ms")) { - oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.min_journey_time_ms = *((double *) value); - } else if (!strcmp((char *) key, "UE_moving_dynamics_max_journey_time_ms")) { - oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.max_journey_time_ms = *((double *) value); - } - } - */ +void update_app_model(Event_t event) { + + + printf("\n\n\nA NEW APP MODEL\n\n\n"); + OAI_Emulation *oai_emulation; + oai_emulation = get_OAI_emulation(); + int i=0; + + if(event.optype == READ) + { + if(event.key == NULL) + { + //print all values + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { + LOG_I(EMU,"predefined_traffic.source_id %d: %s\n",i,oai_emulation->application_config.predefined_traffic.source_id[i]); + LOG_I(EMU,"predefined_traffic.background %d %s\n",i,oai_emulation->application_config.predefined_traffic.background[i]); + LOG_I(EMU,"predefined_traffic.aggregation_level %d %d\n",i,oai_emulation->application_config.predefined_traffic.aggregation_level[i]); + if(oai_emulation->application_config.predefined_traffic.destination_id[i]!=NULL) + LOG_I(EMU,"predefined_traffic.destination_id %d %s\n",i,oai_emulation->application_config.predefined_traffic.destination_id[i]); + if(oai_emulation->application_config.customized_traffic.source_id[i]!=NULL) + LOG_I(EMU,"customized_traffic.source_id %d %s\n",i,oai_emulation->application_config.customized_traffic.source_id[i]); + if(oai_emulation->application_config.customized_traffic.destination_id[i]!=NULL) + LOG_I(EMU,"customized_traffic.destination_id %d %s\n",i,oai_emulation->application_config.customized_traffic.destination_id[i]); + if(oai_emulation->application_config.customized_traffic.transport_protocol[i]!=NULL) + LOG_I(EMU,"customized_traffic.transport_protocol %d %s\n",i,oai_emulation->application_config.customized_traffic.transport_protocol[i]); + if(oai_emulation->application_config.customized_traffic.background[i]!=NULL) + LOG_I(EMU,"customized_traffic.background %d %s\n",i,oai_emulation->application_config.customized_traffic.background[i]); + if(oai_emulation->application_config.customized_traffic.ip_version[i]!=NULL) + LOG_I(EMU,"customized_traffic.ip_version %d %s\n",i,oai_emulation->application_config.customized_traffic.ip_version[i]); + LOG_I(EMU,"customized_traffic.aggregation_level %d %d\n",i,oai_emulation->application_config.customized_traffic.aggregation_level[i]); + if(oai_emulation->application_config.customized_traffic.idt_dist[i]!=NULL) + LOG_I(EMU,"customized_traffic.idt_dist %d %s\n",i,oai_emulation->application_config.customized_traffic.idt_dist[i]); + + LOG_I(EMU,"customized_traffic.idt_min_ms %d %d\n",i,oai_emulation->application_config.customized_traffic.idt_min_ms[i]); + LOG_I(EMU,"customized_traffic.idt_max_ms %d %d\n",i,oai_emulation->application_config.customized_traffic.idt_max_ms[i]); + LOG_I(EMU,"customized_traffic.idt_standard_deviation %d %G\n",i,oai_emulation->application_config.customized_traffic.idt_standard_deviation[i]); + LOG_I(EMU,"customized_traffic.idt_lambda %d %G\n",i,oai_emulation->application_config.customized_traffic.idt_lambda[i]); + LOG_I(EMU,"customized_traffic.size_dist %d %s\n",i,oai_emulation->application_config.customized_traffic.size_dist[i]); + LOG_I(EMU,"customized_traffic.size_min_byte %d %d\n",i,oai_emulation->application_config.customized_traffic.size_min_byte[i]);// + LOG_I(EMU,"customized_traffic.size_max_byte %d %d\n",i,oai_emulation->application_config.customized_traffic.size_max_byte[i]);// + LOG_I(EMU,"customized_traffic.size_standard_deviation %d %G\n",i,oai_emulation->application_config.customized_traffic.size_standard_deviation[i]);// + LOG_I(EMU,"customized_traffic.size_lambda %d %G\n",i,oai_emulation->application_config.customized_traffic.size_lambda[i]); + LOG_I(EMU,"ustomized_traffic.stream %d %d\n",i,oai_emulation->application_config.customized_traffic.stream[i]); + LOG_I(EMU,"customized_traffic.destination_port %d %d\n",i,oai_emulation->application_config.customized_traffic.destination_port[i]); + LOG_I(EMU,"customized_traffic.prob_off_pu %d %G\n",i,oai_emulation->application_config.customized_traffic.prob_off_pu[i]); + LOG_I(EMU,"customized_traffic.prob_off_ed %d %G\n",i,oai_emulation->application_config.customized_traffic.prob_off_ed[i]); + LOG_I(EMU,"customized_traffic.prob_off_pe %d %G\n",i,oai_emulation->application_config.customized_traffic.prob_off_pe[i]); + LOG_I(EMU,"customized_traffic.prob_pu_ed %d %G\n",i,oai_emulation->application_config.customized_traffic.prob_pu_ed[i]);// + LOG_I(EMU,"customized_traffic.prob_pu_pe %d %G\n",i,oai_emulation->application_config.customized_traffic.prob_pu_pe[i]); + LOG_I(EMU,"customized_traffic.prob_ed_pe %d %G\n",i,oai_emulation->application_config.customized_traffic.prob_ed_pe[i]); + LOG_I(EMU,"customized_traffic.prob_ed_pu %d %G\n",i,oai_emulation->application_config.customized_traffic.prob_ed_pu[i]); + LOG_I(EMU,"customized_traffic.holding_time_off_ed %d %d\n",i,oai_emulation->application_config.customized_traffic.holding_time_off_ed[i]); + LOG_I(EMU,"customized_traffic.holding_time_off_pu %d %d\n",i,oai_emulation->application_config.customized_traffic.holding_time_off_pu[i]); + LOG_I(EMU,"customized_traffic.holding_time_off_pe %d %d\n",i,oai_emulation->application_config.customized_traffic.holding_time_off_pe[i]); + LOG_I(EMU,"customized_traffic.holding_time_pe_off %d %d\n",i,oai_emulation->application_config.customized_traffic.holding_time_pe_off[i]); + LOG_I(EMU,"customized_traffic.pu_size_pkts %d %d\n",i,oai_emulation->application_config.customized_traffic.pu_size_pkts[i]); + LOG_I(EMU,"customized_traffic.ed_size_pkts %d %d\n",i,oai_emulation->application_config.customized_traffic.ed_size_pkts[i]); + + } + } + else if(!strcmp((char *) event.key, "predefined_traffic.source_id")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + LOG_I(EMU,"predefined_traffic.source_id %d: %s\n",i,oai_emulation->application_config.predefined_traffic.source_id[i]); + } + } + else if(!strcmp((char *) event.key, "predefined_traffic.background")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + LOG_I(EMU,"predefined_traffic.background %d %s\n",i,oai_emulation->application_config.predefined_traffic.background[i]); + } + } + else if(!strcmp((char *) event.key, "predefined_traffic.aggregation_level")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + LOG_I(EMU,"predefined_traffic.aggregation_level %d %d\n",i,oai_emulation->application_config.predefined_traffic.aggregation_level[i]); + } + } + else if(!strcmp((char *) event.key, "predefined_traffic.destination_id")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + if(oai_emulation->application_config.predefined_traffic.destination_id[i]!=NULL) + LOG_I(EMU,"predefined_traffic.destination_id %d %s\n",i,oai_emulation->application_config.predefined_traffic.destination_id[i]); + } + } + else if(!strcmp((char *) event.key, "customized_traffic.source_id")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + if(oai_emulation->application_config.customized_traffic.source_id[i]!=NULL) + LOG_I(EMU,"customized_traffic.source_id %d %s\n",i,oai_emulation->application_config.customized_traffic.source_id[i]); + } + } + else if(!strcmp((char *) event.key, "customized_traffic.destination_id")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + if(oai_emulation->application_config.customized_traffic.destination_id[i]!=NULL) + LOG_I(EMU,"customized_traffic.destination_id %d %s\n",i,oai_emulation->application_config.customized_traffic.destination_id[i]); + } + } + else if(!strcmp((char *) event.key, "customized_traffic.transport_protocol")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + if(oai_emulation->application_config.customized_traffic.transport_protocol[i]!=NULL) + LOG_I(EMU,"customized_traffic.transport_protocol %d %s\n",i,oai_emulation->application_config.customized_traffic.transport_protocol[i]); + } + } + else if(!strcmp((char *) event.key, "customized_traffic.background")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + if(oai_emulation->application_config.customized_traffic.background[i]!=NULL) + LOG_I(EMU,"customized_traffic.background %d %s\n",i,oai_emulation->application_config.customized_traffic.background[i]); + } + } + else if(!strcmp((char *) event.key, "customized_traffic.ip_version")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + if(oai_emulation->application_config.customized_traffic.ip_version[i]!=NULL) + LOG_I(EMU,"customized_traffic.ip_version %d %s\n",i,oai_emulation->application_config.customized_traffic.ip_version[i]); + } + } + else if(!strcmp((char *) event.key, "customized_traffic.aggregation_level")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + LOG_I(EMU,"customized_traffic.aggregation_level %d %d\n",i,oai_emulation->application_config.customized_traffic.aggregation_level[i]); + } + } + else if(!strcmp((char *) event.key, "customized_traffic.idt_dist")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + if(oai_emulation->application_config.customized_traffic.idt_dist[i]!=NULL) + LOG_I(EMU,"customized_traffic.idt_dist %d %s\n",i,oai_emulation->application_config.customized_traffic.idt_dist[i]); + } + } + else if(!strcmp((char *) event.key, "customized_traffic.idt_min_ms")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + LOG_I(EMU,"customized_traffic.idt_min_ms %d %d\n",i,oai_emulation->application_config.customized_traffic.idt_min_ms[i]); + } + } + else if(!strcmp((char *) event.key, "customized_traffic.idt_max_ms")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + LOG_I(EMU,"customized_traffic.idt_max_ms %d %d\n",i,oai_emulation->application_config.customized_traffic.idt_max_ms[i]); + } + } + else if(!strcmp((char *) event.key, "customized_traffic.idt_standard_deviation")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + LOG_I(EMU,"customized_traffic.idt_standard_deviation %d %G\n",i,oai_emulation->application_config.customized_traffic.idt_standard_deviation[i]); + } + } + else if(!strcmp((char *) event.key, "customized_traffic.idt_lambda")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + LOG_I(EMU,"customized_traffic.idt_lambda %d %G\n",i,oai_emulation->application_config.customized_traffic.idt_lambda[i]); + } + } + else if(!strcmp((char *) event.key, "customized_traffic.size_dist")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + LOG_I(EMU,"customized_traffic.size_dist %d %s\n",i,oai_emulation->application_config.customized_traffic.size_dist[i]); + } + } + else if(!strcmp((char *) event.key, "customized_traffic.size_min_byte")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + LOG_I(EMU,"customized_traffic.size_min_byte %d %d\n",i,oai_emulation->application_config.customized_traffic.size_min_byte[i]);// + } + } + else if(!strcmp((char *) event.key, "customized_traffic.size_min_byte")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + LOG_I(EMU,"customized_traffic.size_min_byte %d %d\n",i,oai_emulation->application_config.customized_traffic.size_min_byte[i]);// + } + } + else if(!strcmp((char *) event.key, "customized_traffic.size_max_byte")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + LOG_I(EMU,"customized_traffic.size_max_byte %d %d\n",i,oai_emulation->application_config.customized_traffic.size_max_byte[i]);// + } + } + else if(!strcmp((char *) event.key, "customized_traffic.size_standard_deviation")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + LOG_I(EMU,"customized_traffic.size_standard_deviation %d %G\n",i,oai_emulation->application_config.customized_traffic.size_standard_deviation[i]);// + } + } + else if(!strcmp((char *) event.key, "customized_traffic.size_lambda")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + LOG_I(EMU,"customized_traffic.size_lambda %d %G\n",i,oai_emulation->application_config.customized_traffic.size_lambda[i]); + } + } + else if(!strcmp((char *) event.key, "ustomized_traffic.stream")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + LOG_I(EMU,"ustomized_traffic.stream %d %d\n",i,oai_emulation->application_config.customized_traffic.stream[i]); + } + } + else if(!strcmp((char *) event.key, "customized_traffic.destination_port")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + LOG_I(EMU,"customized_traffic.destination_port %d %d\n",i,oai_emulation->application_config.customized_traffic.destination_port[i]); + } + } + else if(!strcmp((char *) event.key, "customized_traffic.prob_off_pu")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + LOG_I(EMU,"customized_traffic.prob_off_pu %d %G\n",i,oai_emulation->application_config.customized_traffic.prob_off_pu[i]); + } + } + else if(!strcmp((char *) event.key, "customized_traffic.prob_off_ed")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + LOG_I(EMU,"customized_traffic.prob_off_ed %d %G\n",i,oai_emulation->application_config.customized_traffic.prob_off_ed[i]); + } + } + else if(!strcmp((char *) event.key, "customized_traffic.prob_off_pe")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + LOG_I(EMU,"customized_traffic.prob_off_pe %d %G\n",i,oai_emulation->application_config.customized_traffic.prob_off_pe[i]); + } + } + else if(!strcmp((char *) event.key, "customized_traffic.prob_pu_ed")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + LOG_I(EMU,"customized_traffic.prob_pu_ed %d %G\n",i,oai_emulation->application_config.customized_traffic.prob_pu_ed[i]);// + } + } + else if(!strcmp((char *) event.key, "customized_traffic.prob_pu_pe")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + LOG_I(EMU,"customized_traffic.prob_pu_pe %d %G\n",i,oai_emulation->application_config.customized_traffic.prob_pu_pe[i]); + } + } + else if(!strcmp((char *) event.key, "customized_traffic.prob_ed_pe")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + LOG_I(EMU,"customized_traffic.prob_ed_pe %d %G\n",i,oai_emulation->application_config.customized_traffic.prob_ed_pe[i]); + } + } + else if(!strcmp((char *) event.key, "customized_traffic.prob_ed_pu")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + LOG_I(EMU,"customized_traffic.prob_ed_pu %d %G\n",i,oai_emulation->application_config.customized_traffic.prob_ed_pu[i]); + } + } + else if(!strcmp((char *) event.key, "customized_traffic.holding_time_off_ed")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + LOG_I(EMU,"customized_traffic.holding_time_off_ed %d %d\n",i,oai_emulation->application_config.customized_traffic.holding_time_off_ed[i]); + } + } + else if(!strcmp((char *) event.key, "customized_traffic.holding_time_off_pu")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + LOG_I(EMU,"customized_traffic.holding_time_off_pu %d %d\n",i,oai_emulation->application_config.customized_traffic.holding_time_off_pu[i]); + } + } + else if(!strcmp((char *) event.key, "customized_traffic.holding_time_off_pe")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + LOG_I(EMU,"customized_traffic.holding_time_off_pe %d %d\n",i,oai_emulation->application_config.customized_traffic.holding_time_off_pe[i]); + } + } + else if(!strcmp((char *) event.key, "customized_traffic.holding_time_pe_off")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + LOG_I(EMU,"customized_traffic.holding_time_pe_off %d %d\n",i,oai_emulation->application_config.customized_traffic.holding_time_pe_off[i]); + } + } + else if(!strcmp((char *) event.key, "customized_traffic.pu_size_pkts")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + LOG_I(EMU,"customized_traffic.pu_size_pkts %d %d\n",i,oai_emulation->application_config.customized_traffic.pu_size_pkts[i]); + } + } + else if(!strcmp((char *) event.key, "customized_traffic.ed_size_pkts")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + LOG_I(EMU,"customized_traffic.ed_size_pkts %d %d\n",i,oai_emulation->application_config.customized_traffic.ed_size_pkts[i]); + } + } + } + else if(event.optype == WRITE && event.value!=NULL) + { + Application_Config * new_app_config = (Application_Config *) event.value; + if(event.key == NULL) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { + sprintf(oai_emulation->application_config.predefined_traffic.source_id[i],"%s",new_app_config->predefined_traffic.source_id[i]); + // LOG_I(EMU,"predefined_traffic.application_type %d: %s\n",i,oai_emulation->application_config.predefined_traffic.application_type[i]); + sprintf(oai_emulation->application_config.predefined_traffic.background[i],"%s",new_app_config->predefined_traffic.background[i]); + oai_emulation->application_config.predefined_traffic.aggregation_level[i] = new_app_config->predefined_traffic.aggregation_level[i]; + if(oai_emulation->application_config.predefined_traffic.destination_id[i]!=NULL) + sprintf(oai_emulation->application_config.predefined_traffic.destination_id[i],"%s",new_app_config->predefined_traffic.destination_id[i]); + if(oai_emulation->application_config.customized_traffic.source_id[i]!=NULL) + sprintf(oai_emulation->application_config.customized_traffic.source_id[i],"%s",new_app_config->customized_traffic.source_id[i]); + if(oai_emulation->application_config.customized_traffic.destination_id[i]!=NULL) + sprintf(oai_emulation->application_config.customized_traffic.destination_id[i],"%s",new_app_config->customized_traffic.destination_id[i]); + if(oai_emulation->application_config.customized_traffic.transport_protocol[i]!=NULL) + sprintf(oai_emulation->application_config.customized_traffic.transport_protocol[i],"%s",new_app_config->customized_traffic.transport_protocol[i]); + if(oai_emulation->application_config.customized_traffic.background[i]!=NULL) + sprintf(oai_emulation->application_config.customized_traffic.background[i],"%s",new_app_config->customized_traffic.background[i]); + if(oai_emulation->application_config.customized_traffic.ip_version[i]!=NULL) + sprintf(oai_emulation->application_config.customized_traffic.ip_version[i],"%s",new_app_config->customized_traffic.ip_version[i]); + oai_emulation->application_config.customized_traffic.aggregation_level[i] = new_app_config->customized_traffic.aggregation_level[i]; + if(oai_emulation->application_config.customized_traffic.idt_dist[i]!=NULL) + sprintf(oai_emulation->application_config.customized_traffic.idt_dist[i],"%s",new_app_config->customized_traffic.idt_dist[i]); + + oai_emulation->application_config.customized_traffic.idt_min_ms[i] = new_app_config->customized_traffic.idt_min_ms[i]; + oai_emulation->application_config.customized_traffic.idt_max_ms[i] = new_app_config->customized_traffic.idt_max_ms[i]; + oai_emulation->application_config.customized_traffic.idt_standard_deviation[i] = new_app_config->customized_traffic.idt_standard_deviation[i]; + oai_emulation->application_config.customized_traffic.idt_lambda[i] = new_app_config->customized_traffic.idt_lambda[i]; + sprintf(oai_emulation->application_config.customized_traffic.size_dist[i],"%s",new_app_config->customized_traffic.size_dist[i]); + oai_emulation->application_config.customized_traffic.size_min_byte[i] = new_app_config->customized_traffic.size_min_byte[i];// + oai_emulation->application_config.customized_traffic.size_max_byte[i] = new_app_config->customized_traffic.size_max_byte[i];// + oai_emulation->application_config.customized_traffic.size_standard_deviation[i] = new_app_config->customized_traffic.size_standard_deviation[i];// + oai_emulation->application_config.customized_traffic.size_lambda[i] = new_app_config->customized_traffic.size_lambda[i]; + oai_emulation->application_config.customized_traffic.stream[i] = new_app_config->customized_traffic.stream[i]; + oai_emulation->application_config.customized_traffic.destination_port[i] = new_app_config->customized_traffic.destination_port[i]; + oai_emulation->application_config.customized_traffic.prob_off_pu[i] = new_app_config->customized_traffic.prob_off_pu[i]; + oai_emulation->application_config.customized_traffic.prob_off_ed[i] = new_app_config->customized_traffic.prob_off_ed[i]; + oai_emulation->application_config.customized_traffic.prob_off_pe[i] = new_app_config->customized_traffic.prob_off_pe[i]; + oai_emulation->application_config.customized_traffic.prob_pu_ed[i] = new_app_config->customized_traffic.prob_pu_ed[i];// + oai_emulation->application_config.customized_traffic.prob_pu_pe[i] = new_app_config->customized_traffic.prob_pu_pe[i]; + oai_emulation->application_config.customized_traffic.prob_ed_pe[i] = new_app_config->customized_traffic.prob_ed_pe[i]; + oai_emulation->application_config.customized_traffic.prob_ed_pu[i] = new_app_config->customized_traffic.prob_ed_pu[i]; + oai_emulation->application_config.customized_traffic.holding_time_off_ed[i] = new_app_config->customized_traffic.holding_time_off_ed[i]; + oai_emulation->application_config.customized_traffic.holding_time_off_pu[i] = new_app_config->customized_traffic.holding_time_off_pu[i]; + oai_emulation->application_config.customized_traffic.holding_time_off_pe[i] = new_app_config->customized_traffic.holding_time_off_pe[i]; + oai_emulation->application_config.customized_traffic.holding_time_pe_off[i] = new_app_config->customized_traffic.holding_time_pe_off[i]; + oai_emulation->application_config.customized_traffic.pu_size_pkts[i] = new_app_config->customized_traffic.pu_size_pkts[i]; + oai_emulation->application_config.customized_traffic.ed_size_pkts[i] = new_app_config->customized_traffic.ed_size_pkts[i]; + + } + + } + else if(!strcmp((char *) event.key, "predefined_traffic.source_id")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + sprintf(oai_emulation->application_config.predefined_traffic.source_id[i],"%s",new_app_config->predefined_traffic.source_id[i]); + } + } + else if(!strcmp((char *) event.key, "predefined_traffic.background")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + sprintf(oai_emulation->application_config.predefined_traffic.background[i],"%s",new_app_config->predefined_traffic.background[i]); + } + } + else if(!strcmp((char *) event.key, "predefined_traffic.aggregation_level")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + oai_emulation->application_config.predefined_traffic.aggregation_level[i] = new_app_config->predefined_traffic.aggregation_level[i]; + } + } + else if(!strcmp((char *) event.key, "predefined_traffic.destination_id")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + if(oai_emulation->application_config.predefined_traffic.destination_id[i]!=NULL) + sprintf(oai_emulation->application_config.predefined_traffic.destination_id[i],"%s",new_app_config->predefined_traffic.destination_id[i]); + } + } + else if(!strcmp((char *) event.key, "customized_traffic.source_id")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + if(oai_emulation->application_config.customized_traffic.source_id[i]!=NULL) + sprintf(oai_emulation->application_config.customized_traffic.source_id[i],"%s",new_app_config->customized_traffic.source_id[i]); + } + } + else if(!strcmp((char *) event.key, "customized_traffic.destination_id")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + if(oai_emulation->application_config.customized_traffic.destination_id[i]!=NULL) + sprintf(oai_emulation->application_config.customized_traffic.destination_id[i],"%s",new_app_config->customized_traffic.destination_id[i]); + } + } + else if(!strcmp((char *) event.key, "customized_traffic.transport_protocol")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + if(oai_emulation->application_config.customized_traffic.transport_protocol[i]!=NULL) + sprintf(oai_emulation->application_config.customized_traffic.transport_protocol[i],"%s",new_app_config->customized_traffic.transport_protocol[i]); + } + } + else if(!strcmp((char *) event.key, "customized_traffic.background")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + if(oai_emulation->application_config.customized_traffic.background[i]!=NULL) + sprintf(oai_emulation->application_config.customized_traffic.background[i],"%s",new_app_config->customized_traffic.background[i]); + } + } + else if(!strcmp((char *) event.key, "customized_traffic.ip_version")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + if(oai_emulation->application_config.customized_traffic.ip_version[i]!=NULL) + sprintf(oai_emulation->application_config.customized_traffic.ip_version[i],"%s",*((char **) event.value)); + } + } + else if(!strcmp((char *) event.key, "customized_traffic.aggregation_level")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + oai_emulation->application_config.customized_traffic.aggregation_level[i] = new_app_config->customized_traffic.aggregation_level[i]; + } + } + else if(!strcmp((char *) event.key, "customized_traffic.idt_dist")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + if(oai_emulation->application_config.customized_traffic.idt_dist[i]!=NULL) + sprintf(oai_emulation->application_config.customized_traffic.idt_dist[i],"%s",new_app_config->customized_traffic.idt_dist[i]); + } + } + else if(!strcmp((char *) event.key, "customized_traffic.idt_min_ms")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + oai_emulation->application_config.customized_traffic.idt_min_ms[i] = new_app_config->customized_traffic.idt_min_ms[i]; + } + } + else if(!strcmp((char *) event.key, "customized_traffic.idt_max_ms")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + oai_emulation->application_config.customized_traffic.idt_max_ms[i] = new_app_config->customized_traffic.idt_max_ms[i]; + } + } + else if(!strcmp((char *) event.key, "customized_traffic.idt_standard_deviation")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + oai_emulation->application_config.customized_traffic.idt_standard_deviation[i] = new_app_config->customized_traffic.idt_standard_deviation[i]; + } + } + else if(!strcmp((char *) event.key, "customized_traffic.idt_lambda")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + oai_emulation->application_config.customized_traffic.idt_lambda[i] = new_app_config->customized_traffic.idt_lambda[i]; + } + } + else if(!strcmp((char *) event.key, "customized_traffic.size_dist")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + sprintf(oai_emulation->application_config.customized_traffic.size_dist[i],"%s",new_app_config->customized_traffic.size_dist[i]); + } + } + else if(!strcmp((char *) event.key, "customized_traffic.size_min_byte")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + oai_emulation->application_config.customized_traffic.size_min_byte[i] = new_app_config->customized_traffic.size_min_byte[i];// + } + } + else if(!strcmp((char *) event.key, "customized_traffic.size_max_byte")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + oai_emulation->application_config.customized_traffic.size_max_byte[i] = new_app_config->customized_traffic.size_max_byte[i];// + } + } + else if(!strcmp((char *) event.key, "customized_traffic.size_standard_deviation")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + oai_emulation->application_config.customized_traffic.size_standard_deviation[i] = new_app_config->customized_traffic.size_standard_deviation[i]; + } + } + else if(!strcmp((char *) event.key, "customized_traffic.size_lambda")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + oai_emulation->application_config.customized_traffic.size_lambda[i] = new_app_config->customized_traffic.size_lambda[i]; + } + } + else if(!strcmp((char *) event.key, "ustomized_traffic.stream")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + oai_emulation->application_config.customized_traffic.stream[i] = new_app_config->customized_traffic.stream[i]; + } + } + else if(!strcmp((char *) event.key, "customized_traffic.destination_port")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + oai_emulation->application_config.customized_traffic.destination_port[i] = new_app_config->customized_traffic.destination_port[i]; + } + } + else if(!strcmp((char *) event.key, "customized_traffic.prob_off_pu")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + oai_emulation->application_config.customized_traffic.prob_off_pu[i] = new_app_config->customized_traffic.prob_off_pu[i]; + } + } + else if(!strcmp((char *) event.key, "customized_traffic.prob_off_ed")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + oai_emulation->application_config.customized_traffic.prob_off_ed[i] = new_app_config->customized_traffic.prob_off_ed[i]; + } + } + else if(!strcmp((char *) event.key, "customized_traffic.prob_off_pe")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + oai_emulation->application_config.customized_traffic.prob_off_pe[i] = new_app_config->customized_traffic.prob_off_pe[i]; + } + } + else if(!strcmp((char *) event.key, "customized_traffic.prob_pu_ed")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + oai_emulation->application_config.customized_traffic.prob_pu_ed[i] = new_app_config->customized_traffic.prob_pu_ed[i];// + } + } + else if(!strcmp((char *) event.key, "customized_traffic.prob_pu_pe")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + oai_emulation->application_config.customized_traffic.prob_pu_pe[i] = new_app_config->customized_traffic.prob_pu_pe[i]; + } + } + else if(!strcmp((char *) event.key, "customized_traffic.prob_ed_pe")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + oai_emulation->application_config.customized_traffic.prob_ed_pe[i] = new_app_config->customized_traffic.prob_ed_pe[i]; + } + } + else if(!strcmp((char *) event.key, "customized_traffic.prob_ed_pu")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + oai_emulation->application_config.customized_traffic.prob_ed_pu[i] = new_app_config->customized_traffic.prob_ed_pu[i]; + } + } + else if(!strcmp((char *) event.key, "customized_traffic.holding_time_off_ed")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + oai_emulation->application_config.customized_traffic.holding_time_off_ed[i] = new_app_config->customized_traffic.holding_time_off_ed[i]; + } + } + else if(!strcmp((char *) event.key, "customized_traffic.holding_time_off_pu")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + oai_emulation->application_config.customized_traffic.holding_time_off_pu[i] = new_app_config->customized_traffic.holding_time_off_pu[i]; + } + } + else if(!strcmp((char *) event.key, "customized_traffic.holding_time_off_pe")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + oai_emulation->application_config.customized_traffic.holding_time_off_pe[i] = new_app_config->customized_traffic.holding_time_off_pe[i]; + } + } + else if(!strcmp((char *) event.key, "customized_traffic.holding_time_pe_off")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + oai_emulation->application_config.customized_traffic.holding_time_pe_off[i] = new_app_config->customized_traffic.holding_time_pe_off[i]; + } + } + else if(!strcmp((char *) event.key, "customized_traffic.pu_size_pkts")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + oai_emulation->application_config.customized_traffic.pu_size_pkts[i] = new_app_config->customized_traffic.pu_size_pkts[i]; + } + } + else if(!strcmp((char *) event.key, "customized_traffic.ed_size_pkts")) + { + for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) + { + oai_emulation->application_config.customized_traffic.ed_size_pkts[i] = new_app_config->customized_traffic.ed_size_pkts[i]; + } + } + + } } -void update_app_model(char * key, void * value) { - printf("\n\n\nA NEW APP MODEL\n\n\n"); - //int i; -/* +void update_emu_model(Event_t event) { +// Emulation_Config emulation_config; /*!< \brief Emulation configuration */ + + printf("\n\n\nA NEW EMU MODEL\n\n\n"); + OAI_Emulation *oai_emulation; + oai_emulation = get_OAI_emulation(); + int i=0; - if (key != NULL) { //Global model update - Application_Config * new_application_model = (Application_Config *)value; - - sprintf(oai_emulation.application_config.packet_gen_type, "%s", new_application_model->packet_gen_type); - - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - sprintf(oai_emulation.application_config.predefined_traffic.source_id[i], "%s", new_application_model->predefined_traffic.source_id[i]); - sprintf(oai_emulation.application_config.predefined_traffic.application_type[i], "%s", new_application_model->predefined_traffic.application_type[i]); - sprintf(oai_emulation.application_config.predefined_traffic.background[i], "%s", new_application_model->predefined_traffic.background[i]); - oai_emulation.application_config.predefined_traffic.aggregation_level[i] = new_application_model->predefined_traffic.aggregation_level[i]; - oai_emulation.application_config.predefined_traffic.destination_id[i] = new_application_model->predefined_traffic.destination_id[i]; - - sprintf(oai_emulation.application_config.customized_traffic.source_id[i], "%s", new_application_model->customized_traffic.source_id[i]); - sprintf(oai_emulation.application_config.customized_traffic.destination_id[i], "%s", new_application_model->customized_traffic.destination_id[i]); - sprintf(oai_emulation.application_config.customized_traffic.transport_protocol[i], "%s", new_application_model->customized_traffic.transport_protocol[i]); - sprintf(oai_emulation.application_config.customized_traffic.background[i], "%s", new_application_model->customized_traffic.background[i]); - sprintf(oai_emulation.application_config.customized_traffic.ip_version[i], "%s", new_application_model->customized_traffic.ip_version[i]); - oai_emulation.application_config.customized_traffic.aggregation_level[i] = new_application_model->customized_traffic.aggregation_level[i]; - sprintf(oai_emulation.application_config.customized_traffic.idt_dist[i], "%s", new_application_model->customized_traffic.idt_dist[i]); - oai_emulation.application_config.customized_traffic.idt_min_ms[i] = new_application_model->customized_traffic.idt_min_ms[i]; - oai_emulation.application_config.customized_traffic.idt_max_ms[i] = new_application_model->customized_traffic.idt_max_ms[i]; - oai_emulation.application_config.customized_traffic.idt_standard_deviation[i] = new_application_model->customized_traffic.idt_standard_deviation[i]; - oai_emulation.application_config.customized_traffic.idt_lambda[i] = new_application_model->customized_traffic.idt_lambda[i]; - sprintf(oai_emulation.application_config.customized_traffic.size_dist[i], "%s", new_application_model->customized_traffic.size_dist[i]); - oai_emulation.application_config.customized_traffic.size_min_byte[i] = new_application_model->customized_traffic.size_min_byte[i]; - oai_emulation.application_config.customized_traffic.size_max_byte[i] = new_application_model->customized_traffic.size_max_byte[i]; - oai_emulation.application_config.customized_traffic.size_standard_deviation[i] = new_application_model->customized_traffic.size_standard_deviation[i]; - oai_emulation.application_config.customized_traffic.size_lambda[i] = new_application_model->customized_traffic.size_lambda[i]; - oai_emulation.application_config.customized_traffic.stream[i] = new_application_model->customized_traffic.stream[i]; - oai_emulation.application_config.customized_traffic.destination_port[i] = new_application_model->customized_traffic.destination_port[i]; - oai_emulation.application_config.customized_traffic.prob_off_pu[i]= new_application_model->customized_traffic.prob_off_pu[i]; - oai_emulation.application_config.customized_traffic.prob_off_ed[i]= new_application_model->customized_traffic.prob_off_ed[i]; - oai_emulation.application_config.customized_traffic.prob_off_pe[i]= new_application_model->customized_traffic.prob_off_pe[i]; - oai_emulation.application_config.customized_traffic.prob_pu_ed[i]= new_application_model->customized_traffic.prob_pu_ed[i]; - oai_emulation.application_config.customized_traffic.prob_pu_pe[i]= new_application_model->customized_traffic.prob_pu_pe[i]; - oai_emulation.application_config.customized_traffic.prob_ed_pe[i]= new_application_model->customized_traffic.prob_ed_pe[i]; - oai_emulation.application_config.customized_traffic.prob_ed_pu[i]= new_application_model->customized_traffic.prob_ed_pu[i]; - oai_emulation.application_config.customized_traffic.holding_time_off_ed[i]= new_application_model->customized_traffic.holding_time_off_ed[i]; - oai_emulation.application_config.customized_traffic.holding_time_off_pu[i]= new_application_model->customized_traffic.holding_time_off_pu[i]; - oai_emulation.application_config.customized_traffic.holding_time_off_pe[i]= new_application_model->customized_traffic.holding_time_off_pe[i]; - oai_emulation.application_config.customized_traffic.holding_time_pe_off[i]= new_application_model->customized_traffic.holding_time_pe_off[i]; - oai_emulation.application_config.customized_traffic.pu_size_pkts[i]= new_application_model->customized_traffic.pu_size_pkts[i]; - oai_emulation.application_config.customized_traffic.ed_size_pkts[i]= new_application_model->customized_traffic.ed_size_pkts[i]; - } - } else { //Updating a single parameter::: Here I'll only put some examples - - if (!strcmp((char *) key, "packet_gen_type")) { - sprintf(oai_emulation.application_config.packet_gen_type, "%s", (char *) value); - } else if (!strcmp((char *) key, "predefined_traffic_source_id")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - sprintf(oai_emulation.application_config.predefined_traffic.source_id[i], "%s", (char *) value); - } - } else if (!strcmp((char *) key, "predefined_traffic_application_type")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - sprintf(oai_emulation.application_config.predefined_traffic.application_type[i], "%s", (char *) value); - } - } else if (!strcmp((char *) key, "predefined_traffic_background")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - sprintf(oai_emulation.application_config.predefined_traffic.background[i], "%s", (char *) value); - } - } else if (!strcmp((char *) key, "customized_traffic_source_id")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - sprintf(oai_emulation.application_config.customized_traffic.source_id[i], "%s", (char *) value); - } - } else if (!strcmp((char *) key, "customized_traffic_destination_id")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - sprintf(oai_emulation.application_config.customized_traffic.destination_id[i], "%s", (char *) value); - } - } else if (!strcmp((char *) key, "customized_traffic_transport_protocol")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - sprintf(oai_emulation.application_config.customized_traffic.transport_protocol[i], "%s", (char *) value); - } - } else if (!strcmp((char *) key, "customized_traffic_background")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - sprintf(oai_emulation.application_config.customized_traffic.background[i], "%s", (char *) value); - } - } else if (!strcmp((char *) key, "customized_traffic_ip_version")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - sprintf(oai_emulation.application_config.customized_traffic.ip_version[i], "%s", (char *) value); - } - } else if (!strcmp((char *) key, "customized_traffic_idt_dist")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - sprintf(oai_emulation.application_config.customized_traffic.idt_dist[i], "%s", (char *) value); - } - } else if (!strcmp((char *) key, "customized_traffic_size_dist")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - sprintf(oai_emulation.application_config.customized_traffic.size_dist[i], "%s", (char *) value); - } - } else if (!strcmp((char *) key, "predefined_traffic_aggregation_level")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - oai_emulation.application_config.predefined_traffic.aggregation_level[i] = *((int *) value); - } - } else if (!strcmp((char *) key, "predefined_traffic_destination_id")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - oai_emulation.application_config.predefined_traffic.destination_id[i] = *((int *) value); - } - } else if (!strcmp((char *) key, "customized_traffic_aggregation_level")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - oai_emulation.application_config.customized_traffic.aggregation_level[i] = *((int *) value); - } - } else if (!strcmp((char *) key, "customized_traffic_idt_min_ms")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - oai_emulation.application_config.customized_traffic.idt_min_ms[i] = *((int *) value); - } - } else if (!strcmp((char *) key, "customized_traffic_idt_max_ms")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - oai_emulation.application_config.customized_traffic.idt_max_ms[i] = *((int *) value); - } - } else if (!strcmp((char *) key, "customized_traffic_idt_standard_deviation")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - oai_emulation.application_config.customized_traffic.idt_standard_deviation[i] = *((int *) value); - } - } else if (!strcmp((char *) key, "customized_traffic_idt_lambda")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - oai_emulation.application_config.customized_traffic.idt_lambda[i] = *((int *) value); - } - } else if (!strcmp((char *) key, "customized_traffic_size_min_byte")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - oai_emulation.application_config.customized_traffic.size_min_byte[i] = *((int *) value); - } - } else if (!strcmp((char *) key, "customized_traffic_size_max_byte")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - oai_emulation.application_config.customized_traffic.size_max_byte[i] = *((int *) value); - } - } else if (!strcmp((char *) key, "customized_traffic_size_standard_deviation")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - oai_emulation.application_config.customized_traffic.size_standard_deviation[i] = *((int *) value); - } - } else if (!strcmp((char *) key, "customized_traffic_size_lambda")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - oai_emulation.application_config.customized_traffic.size_lambda[i] = *((int *) value); - } - } else if (!strcmp((char *) key, "customized_traffic_stream")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - oai_emulation.application_config.customized_traffic.stream[i] = *((int *) value); - } - } else if (!strcmp((char *) key, "customized_traffic_destination_port")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - oai_emulation.application_config.customized_traffic.destination_port[i] = *((int *) value); - } - } else if (!strcmp((char *) key, "customized_traffic_prob_off_pu")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - oai_emulation.application_config.customized_traffic.prob_off_pu[i] = *((int *) value); - } - } else if (!strcmp((char *) key, "customized_traffic_prob_off_ed")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - oai_emulation.application_config.customized_traffic.prob_off_ed[i] = *((int *) value); - } - } else if (!strcmp((char *) key, "customized_traffic_prob_off_pe")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - oai_emulation.application_config.customized_traffic.prob_off_pe[i] = *((int *) value); - } - } else if (!strcmp((char *) key, "customized_traffic_prob_pu_ed")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - oai_emulation.application_config.customized_traffic.prob_pu_ed[i] = *((int *) value); - } - } else if (!strcmp((char *) key, "customized_traffic_prob_pu_pe")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - oai_emulation.application_config.customized_traffic.prob_pu_pe[i] = *((int *) value); - } - } else if (!strcmp((char *) key, "customized_traffic_prob_ed_pe")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - oai_emulation.application_config.customized_traffic.prob_ed_pe[i] = *((int *) value); - } - } else if (!strcmp((char *) key, "customized_traffic_prob_ed_pu")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - oai_emulation.application_config.customized_traffic.prob_ed_pu[i] = *((int *) value); - } - } else if (!strcmp((char *) key, "customized_traffic_holding_time_off_ed")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - oai_emulation.application_config.customized_traffic.holding_time_off_ed[i] = *((int *) value); - } - } else if (!strcmp((char *) key, "customized_traffic_holding_time_off_pu")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - oai_emulation.application_config.customized_traffic.holding_time_off_pu[i] = *((int *) value); - } - } else if (!strcmp((char *) key, "customized_traffic_holding_time_off_pe")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - oai_emulation.application_config.customized_traffic.holding_time_off_pe[i] = *((int *) value); - } - } else if (!strcmp((char *) key, "customized_traffic_holding_time_pe_off")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - oai_emulation.application_config.customized_traffic.holding_time_pe_off[i] = *((int *) value); - } - } else if (!strcmp((char *) key, "customized_traffic_pu_size_pkts")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - oai_emulation.application_config.customized_traffic.pu_size_pkts[i] = *((int *) value); - } - } else if (!strcmp((char *) key, "customized_traffic_ed_size_pkts")) { - for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++) { - oai_emulation.application_config.customized_traffic.ed_size_pkts[i] = *((int *) value); - } - } - } - */ + if(event.optype == READ) + { + if(event.key == NULL) + { + LOG_I(EMU,"emulation_time_ms %G\n",oai_emulation->emulation_config.emulation_time_ms); + LOG_I(EMU,"curve %s\n",oai_emulation->emulation_config.curve); + LOG_I(EMU,"brackground_stats %s\n",oai_emulation->emulation_config.background_stats); + + //performance metrics + LOG_I(EMU,"performance_metrics.throughput %s\n",oai_emulation->emulation_config.performance_metrics.throughput); + LOG_I(EMU,"performance_metrics.latency %s\n",oai_emulation->emulation_config.performance_metrics.latency); + LOG_I(EMU,"performance_metrics.loss_rate %s\n",oai_emulation->emulation_config.performance_metrics.loss_rate); + LOG_I(EMU,"performance_metrics.owd_radio_access %s\n",oai_emulation->emulation_config.performance_metrics.owd_radio_access); + LOG_I(EMU,"performance_metrics.signalling_overhead %d\n",oai_emulation->emulation_config.performance_metrics.signalling_overhead); + + //Layer + LOG_I(EMU,"layer.phy %d\n",oai_emulation->emulation_config.layer.phy); + LOG_I(EMU,"layer.mac %d\n",oai_emulation->emulation_config.layer.mac); + LOG_I(EMU,"layer.rlc %d\n",oai_emulation->emulation_config.layer.rlc); + LOG_I(EMU,"layer.rrc %d\n",oai_emulation->emulation_config.layer.rrc); + LOG_I(EMU,"layer.pdcp %d\n",oai_emulation->emulation_config.layer.pdcp); + LOG_I(EMU,"layer.omg %d\n",oai_emulation->emulation_config.layer.omg); + LOG_I(EMU,"layer.emu %d\n",oai_emulation->emulation_config.layer.emu); + LOG_I(EMU,"layer.otg %d\n",oai_emulation->emulation_config.layer.otg); + + //Log_emu + LOG_I(EMU,"log_emu.level %s\n",oai_emulation->emulation_config.log_emu.level); + LOG_I(EMU,"log_emu.verbosity %s\n",oai_emulation->emulation_config.log_emu.verbosity); + LOG_I(EMU,"log_emu.interval %d\n",oai_emulation->emulation_config.log_emu.interval); + + //Packet_trace + LOG_I(EMU,"packet_trace.enabled %d\n",oai_emulation->emulation_config.packet_trace.enabled); + LOG_I(EMU,"packet_trace.start_time %u\n",oai_emulation->emulation_config.packet_trace.start_time); + LOG_I(EMU,"packet_trace.end_time %u\n",oai_emulation->emulation_config.packet_trace.end_time); + + //Seed + LOG_I(EMU,"seed.value %d\n",oai_emulation->emulation_config.seed.value); + + } + else if (!strcmp((char *) event.key, "emulation_time_ms")) + { + LOG_I(EMU,"emulation_time_ms %G\n",oai_emulation->emulation_config.emulation_time_ms); + } + else if (!strcmp((char *) event.key, "curve")) + { + LOG_I(EMU,"curve %s\n",oai_emulation->emulation_config.curve); + } + else if (!strcmp((char *) event.key, "brackground_stats")) + { + LOG_I(EMU,"brackground_stats %s\n",oai_emulation->emulation_config.background_stats); + } + else if (!strcmp((char *) event.key, "performance_metrics.throughput")) + { + LOG_I(EMU,"performance_metrics.throughput %s\n",oai_emulation->emulation_config.performance_metrics.throughput); + } + else if (!strcmp((char *) event.key, "performance_metrics.latency")) + { + LOG_I(EMU,"performance_metrics.latency %s\n",oai_emulation->emulation_config.performance_metrics.latency); + } + else if (!strcmp((char *) event.key, "performance_metrics.loss_rate")) + { + LOG_I(EMU,"performance_metrics.loss_rate %s\n",oai_emulation->emulation_config.performance_metrics.loss_rate); + } + else if (!strcmp((char *) event.key, "performance_metrics.owd_radio_access")) + { + LOG_I(EMU,"performance_metrics.owd_radio_access %s\n",oai_emulation->emulation_config.performance_metrics.owd_radio_access); + } + else if (!strcmp((char *) event.key, "performance_metrics.signalling_overhead")) + { + LOG_I(EMU,"performance_metrics.signalling_overhead %d\n",oai_emulation->emulation_config.performance_metrics.signalling_overhead); + } + else if (!strcmp((char *) event.key, "layer.phy")) + { + LOG_I(EMU,"layer.phy %d\n",oai_emulation->emulation_config.layer.phy); + } + else if (!strcmp((char *) event.key, "layer.mac")) + { + LOG_I(EMU,"layer.mac %d\n",oai_emulation->emulation_config.layer.mac); + } + else if (!strcmp((char *) event.key, "layer.rlc")) + { + LOG_I(EMU,"layer.rlc %d\n",oai_emulation->emulation_config.layer.rlc); + } + else if (!strcmp((char *) event.key, "layer.rrc")) + { + LOG_I(EMU,"layer.rrc %d\n",oai_emulation->emulation_config.layer.rrc); + } + else if (!strcmp((char *) event.key, "layer.pdcp")) + { + LOG_I(EMU,"layer.pdcp %d\n",oai_emulation->emulation_config.layer.pdcp); + } + else if (!strcmp((char *) event.key, "layer.omg")) + { + LOG_I(EMU,"layer.omg %d\n",oai_emulation->emulation_config.layer.omg); + } + else if (!strcmp((char *) event.key, "layer.emu")) + { + LOG_I(EMU,"layer.emu %d\n",oai_emulation->emulation_config.layer.emu); + } + else if (!strcmp((char *) event.key, "layer.otg")) + { + LOG_I(EMU,"layer.otg %d\n",oai_emulation->emulation_config.layer.otg); + } + else if (!strcmp((char *) event.key, "log_emu.level")) + { + LOG_I(EMU,"log_emu.level %s\n",oai_emulation->emulation_config.log_emu.level); + } + else if (!strcmp((char *) event.key, "log_emu.verbosity")) + { + LOG_I(EMU,"log_emu.verbosity %s\n",oai_emulation->emulation_config.log_emu.verbosity); + } + else if (!strcmp((char *) event.key, "log_emu.interval")) + { + LOG_I(EMU,"log_emu.interval %d\n",oai_emulation->emulation_config.log_emu.interval); + } + else if (!strcmp((char *) event.key, "packet_trace.enabled")) + { + LOG_I(EMU,"packet_trace.enabled %d\n",oai_emulation->emulation_config.packet_trace.enabled); + } + else if (!strcmp((char *) event.key, "packet_trace.start_time")) + { + LOG_I(EMU,"packet_trace.start_time %u\n",oai_emulation->emulation_config.packet_trace.start_time); + } + else if (!strcmp((char *) event.key, "packet_trace.end_time")) + { + LOG_I(EMU,"packet_trace.end_time %u\n",oai_emulation->emulation_config.packet_trace.end_time); + } + else if (!strcmp((char *) event.key, "customized_traffic_ed_size_pkts")) + { + LOG_I(EMU,"seed.value %d\n",oai_emulation->emulation_config.seed.value); + } + } + else if(event.optype == WRITE && event.value!=NULL) + { + Emulation_Config * new_emu_config = (Emulation_Config *) event.value; + if(event.key==NULL) + { + //update all parameters + + oai_emulation->emulation_config.emulation_time_ms = new_emu_config->emulation_time_ms; + sprintf(oai_emulation->emulation_config.curve,"%s",new_emu_config->curve); + sprintf(oai_emulation->emulation_config.background_stats,"%s",new_emu_config->background_stats); + + //performance metrics + sprintf(oai_emulation->emulation_config.performance_metrics.throughput,"%s",new_emu_config->performance_metrics.throughput); + sprintf(oai_emulation->emulation_config.performance_metrics.latency,"%s",new_emu_config->performance_metrics.latency); + sprintf(oai_emulation->emulation_config.performance_metrics.loss_rate,"%s",new_emu_config->performance_metrics.loss_rate); + sprintf(oai_emulation->emulation_config.performance_metrics.owd_radio_access,"%s",new_emu_config->performance_metrics.owd_radio_access); + oai_emulation->emulation_config.performance_metrics.signalling_overhead = new_emu_config->performance_metrics.signalling_overhead; + + //Layer + oai_emulation->emulation_config.layer.phy = new_emu_config->layer.phy; + oai_emulation->emulation_config.layer.mac = new_emu_config->layer.mac; + oai_emulation->emulation_config.layer.rlc = new_emu_config->layer.rlc; + oai_emulation->emulation_config.layer.rrc = new_emu_config->layer.rrc; + oai_emulation->emulation_config.layer.pdcp = new_emu_config->layer.pdcp; + oai_emulation->emulation_config.layer.omg = new_emu_config->layer.omg; + oai_emulation->emulation_config.layer.emu = new_emu_config->layer.emu; + oai_emulation->emulation_config.layer.otg = new_emu_config->layer.otg; + + //Log_emu + sprintf(oai_emulation->emulation_config.log_emu.level,"%s",new_emu_config->log_emu.level); + sprintf(oai_emulation->emulation_config.log_emu.verbosity,"%s",new_emu_config->log_emu.verbosity); + oai_emulation->emulation_config.log_emu.interval = new_emu_config->log_emu.interval; + + //Packet_trace + oai_emulation->emulation_config.packet_trace.enabled = new_emu_config->packet_trace.enabled ; + oai_emulation->emulation_config.packet_trace.start_time = new_emu_config->packet_trace.start_time; + oai_emulation->emulation_config.packet_trace.end_time = new_emu_config->packet_trace.end_time; + + //Seed + oai_emulation->emulation_config.seed.value = new_emu_config->packet_trace.end_time; + } + else if(event.key != NULL) + { + + if (!strcmp((char *) event.key, "emulation_time_ms")) + { + oai_emulation->emulation_config.emulation_time_ms = new_emu_config->emulation_time_ms; + } + else if (!strcmp((char *) event.key, "curve")) + { + sprintf(oai_emulation->emulation_config.curve,"%s",new_emu_config->curve); + } + else if (!strcmp((char *) event.key, "brackground_stats")) + { + sprintf(oai_emulation->emulation_config.background_stats,"%s",new_emu_config->background_stats); + } + else if (!strcmp((char *) event.key, "performance_metrics.throughput")) + { + sprintf(oai_emulation->emulation_config.performance_metrics.throughput,"%s",new_emu_config->performance_metrics.throughput); + } + else if (!strcmp((char *) event.key, "performance_metrics.latency")) + { + sprintf(oai_emulation->emulation_config.performance_metrics.latency,"%s",new_emu_config->performance_metrics.latency); + } + else if (!strcmp((char *) event.key, "performance_metrics.loss_rate")) + { + sprintf(oai_emulation->emulation_config.performance_metrics.loss_rate,"%s",new_emu_config->performance_metrics.loss_rate); + } + else if (!strcmp((char *) event.key, "performance_metrics.owd_radio_access")) + { + sprintf(oai_emulation->emulation_config.performance_metrics.owd_radio_access,"%s",new_emu_config->performance_metrics.owd_radio_access); + } + else if (!strcmp((char *) event.key, "performance_metrics.signalling_overhead")) + { + oai_emulation->emulation_config.performance_metrics.signalling_overhead = new_emu_config->performance_metrics.signalling_overhead; + } + else if (!strcmp((char *) event.key, "layer.phy")) + { + oai_emulation->emulation_config.layer.phy = new_emu_config->layer.phy; + } + else if (!strcmp((char *) event.key, "layer.mac")) + { + oai_emulation->emulation_config.layer.mac = new_emu_config->layer.mac; + } + else if (!strcmp((char *) event.key, "layer.rlc")) + { + oai_emulation->emulation_config.layer.rlc = new_emu_config->layer.rlc; + } + else if (!strcmp((char *) event.key, "layer.rrc")) + { + oai_emulation->emulation_config.layer.rrc = new_emu_config->layer.rrc; + } + else if (!strcmp((char *) event.key, "layer.pdcp")) + { + oai_emulation->emulation_config.layer.pdcp = new_emu_config->layer.pdcp; + } + else if (!strcmp((char *) event.key, "layer.omg")) + { + oai_emulation->emulation_config.layer.omg = new_emu_config->layer.omg; + } + else if (!strcmp((char *) event.key, "layer.emu")) + { + oai_emulation->emulation_config.layer.emu = new_emu_config->layer.emu; + } + else if (!strcmp((char *) event.key, "layer.otg")) + { + oai_emulation->emulation_config.layer.otg = new_emu_config->layer.otg; + } + else if (!strcmp((char *) event.key, "log_emu.level")) + { + sprintf(oai_emulation->emulation_config.log_emu.level,"%s",new_emu_config->log_emu.level); + } + else if (!strcmp((char *) event.key, "log_emu.verbosity")) + { + sprintf(oai_emulation->emulation_config.log_emu.verbosity,"%s",new_emu_config->log_emu.verbosity); + } + else if (!strcmp((char *) event.key, "log_emu.interval")) + { + oai_emulation->emulation_config.log_emu.interval = new_emu_config->log_emu.interval; + } + else if (!strcmp((char *) event.key, "packet_trace.enabled")) + { + oai_emulation->emulation_config.packet_trace.enabled = new_emu_config->packet_trace.enabled ; + } + else if (!strcmp((char *) event.key, "packet_trace.start_time")) + { + oai_emulation->emulation_config.packet_trace.start_time = new_emu_config->packet_trace.start_time; + } + else if (!strcmp((char *) event.key, "packet_trace.end_time")) + { + oai_emulation->emulation_config.packet_trace.end_time = new_emu_config->packet_trace.end_time; + } + else if (!strcmp((char *) event.key, "customized_traffic_ed_size_pkts")) + { + oai_emulation->emulation_config.seed.value = new_emu_config->packet_trace.end_time; + } + } + } + } -void update_emu_model(char * key, void * value) { + +int validate_mac(Event_t event) +{ + int i=0; + if(event.key ==NULL && event.value!=NULL) + { + Mac_config* mac_config = malloc(sizeof(Mac_config)*16); + mac_config = (Mac_config *) event.value; + + if(event.ue == -1 && event.lcid == -1) + { + for(i=0;i<NUMBER_OF_UE_MAX;i++) + { + if(mac_config[i].DCI_aggregation_min<=0) + { + return 0; + } + if(mac_config[i].DLSCH_dci_size_bits <=0) + { + return 0; + } + if(mac_config[i].priority !=NULL) + { + + int j; + for(j=0;j<MAX_NUM_LCID;j++) + { + + if(mac_config[i].priority[j]<=0) + { + return 0; + } + } + } + if(&mac_config[i].ul_bandwidth !=NULL) + { + // faire boucle par ue puis par lcid + + int j=0; + for(j=0;j<MAX_NUM_LCID;j++) + { + if(!(mac_config[i].ul_bandwidth[j]==6 || mac_config[i].ul_bandwidth[j]==15 || mac_config[i].ul_bandwidth[j]==25 || mac_config[i].ul_bandwidth[j]==50 || mac_config[i].ul_bandwidth[j]==75 || mac_config[i].ul_bandwidth[j]==100)) + return 0; + } + } + if(&mac_config[i].dl_bandwidth !=NULL) + { + int j=0; + for(j=0;j<MAX_NUM_LCID;j++) + { + if(!(mac_config[i].dl_bandwidth[j]==6 || mac_config[i].dl_bandwidth[j]==15 || mac_config[i].dl_bandwidth[j]==25 || mac_config[i].dl_bandwidth[j]==50 || mac_config[i].dl_bandwidth[j]==75 || mac_config[i].dl_bandwidth[j]==100)) + return 0; + } + } + if(&mac_config[i].min_ul_bandwidth !=NULL) + { + // faire boucle par ue puis par lcid + + int j=0; + for(j=0;j<MAX_NUM_LCID;j++) + { + if(!(mac_config[i].min_ul_bandwidth[j]==6 || mac_config[i].min_ul_bandwidth[j]==15 || mac_config[i].min_ul_bandwidth[j]==25 || mac_config[i].min_ul_bandwidth[j]==50 || mac_config[i].min_ul_bandwidth[j]==75 || mac_config[i].min_ul_bandwidth[j]==100)) + return 0; + } + } + if(&mac_config[i].min_dl_bandwidth !=NULL) + { + int j=0; + for(j=0;j<MAX_NUM_LCID;j++) + { + if(!(mac_config[i].min_dl_bandwidth[j]==6 || mac_config[i].min_dl_bandwidth[j]==15 || mac_config[i].min_dl_bandwidth[j]==25 || mac_config[i].min_dl_bandwidth[j]==50 || mac_config[i].min_dl_bandwidth[j]==75 || mac_config[i].min_dl_bandwidth[j]==100)) + return 0; + } + } + if(&mac_config[i].ue_AggregatedMaximumBitrateDL !=NULL) + { + if(!(mac_config[i].ue_AggregatedMaximumBitrateDL>0 && mac_config[i].ue_AggregatedMaximumBitrateDL<10000000000)) + return 0; + } + if(&mac_config[i].ue_AggregatedMaximumBitrateUL !=NULL) + { + if(!(mac_config[i].ue_AggregatedMaximumBitrateUL>0 && mac_config[i].ue_AggregatedMaximumBitrateUL<10000000000)) + return 0; + } + if(&mac_config[i].cqiSchedInterval !=NULL ) + { + if(!(mac_config[i].cqiSchedInterval==1 || mac_config[i].cqiSchedInterval==2 || mac_config[i].cqiSchedInterval==5 || mac_config[i].cqiSchedInterval==10 || mac_config[i].cqiSchedInterval==20 || mac_config[i].cqiSchedInterval==32 || mac_config[i].cqiSchedInterval==40 || mac_config[i].cqiSchedInterval==64 || mac_config[i].cqiSchedInterval==80 || mac_config[i].cqiSchedInterval==128 || mac_config[i].cqiSchedInterval==160)) + return 0; + } + if(&mac_config[i].mac_ContentionResolutionTimer !=NULL) + { + if(!(mac_config[i].mac_ContentionResolutionTimer==8 || mac_config[i].mac_ContentionResolutionTimer==16 || mac_config[i].mac_ContentionResolutionTimer==24 || mac_config[i].mac_ContentionResolutionTimer==32 || mac_config[i].mac_ContentionResolutionTimer==40 || mac_config[i].mac_ContentionResolutionTimer==48 || mac_config[i].mac_ContentionResolutionTimer==56 || mac_config[i].mac_ContentionResolutionTimer==64)) + return 0; + } + if(mac_config->max_allowed_rbs !=NULL) + { + int j=0; + for(j=0;j<MAX_NUM_LCID;j++) + { + if(mac_config[i].max_allowed_rbs[j]<=0) + return 0; + } + } + if(mac_config[i].max_mcs !=NULL) + { + int j=0; + for(j=0;j<MAX_NUM_LCID;j++) + { + if(!(mac_config[i].max_mcs[j]>=0 && mac_config[i].max_mcs[j]<=27)) + return 0; + } + + } + }} + } + if(event.key==NULL && event.value!=NULL && event.ue!=-1 && event.lcid!=-1) + { + //check one param + + Mac_config* mac_config = malloc(sizeof(Mac_config)*16); + mac_config = (Mac_config *) event.value; + + i = event.ue; + int j = event.lcid; + if(&mac_config[i].DCI_aggregation_min) + { + if(mac_config[i].DCI_aggregation_min<=0) + { + return 0; + } + + } + if(&mac_config[i].DLSCH_dci_size_bits !=NULL) + { + if(mac_config[i].DLSCH_dci_size_bits <=0) + { + return 0; + } + } + if(mac_config[i].priority !=NULL) + { + if(&mac_config[i].priority[j]!=NULL) + { + if(mac_config[i].priority[j]<=0) + { + return 0; + } + } + + } + if(&mac_config[i].ul_bandwidth !=NULL) + { + + if(!(mac_config[i].ul_bandwidth[j]==6 || mac_config[i].ul_bandwidth[j]==15 || mac_config[i].ul_bandwidth[j]==25 || mac_config[i].ul_bandwidth[j]==50 || mac_config[i].ul_bandwidth[j]==75 || mac_config[i].ul_bandwidth[j]==100)) + return 0; + + } + if(&mac_config[i].dl_bandwidth !=NULL) + { + + if(!(mac_config[i].dl_bandwidth[j]==6 || mac_config[i].dl_bandwidth[j]==15 || mac_config[i].dl_bandwidth[j]==25 || mac_config[i].dl_bandwidth[j]==50 || mac_config[i].dl_bandwidth[j]==75 || mac_config[i].dl_bandwidth[j]==100)) + return 0; + + } + if(&mac_config[i].min_ul_bandwidth !=NULL) + { + + if(!(mac_config[i].min_ul_bandwidth[j]==6 || mac_config[i].min_ul_bandwidth[j]==15 || mac_config[i].min_ul_bandwidth[j]==25 || mac_config[i].min_ul_bandwidth[j]==50 || mac_config[i].min_ul_bandwidth[j]==75 || mac_config[i].min_ul_bandwidth[j]==100)) + return 0; + + } + if(&mac_config[i].min_dl_bandwidth !=NULL) + { + + if(!(mac_config[i].min_dl_bandwidth[j]==6 || mac_config[i].min_dl_bandwidth[j]==15 || mac_config[i].min_dl_bandwidth[j]==25 || mac_config[i].min_dl_bandwidth[j]==50 || mac_config[i].min_dl_bandwidth[j]==75 || mac_config[i].min_dl_bandwidth[j]==100)) + return 0; + + } + if(&mac_config[i].ue_AggregatedMaximumBitrateDL !=NULL) + { + if(!(mac_config[i].ue_AggregatedMaximumBitrateDL>0 && mac_config[i].ue_AggregatedMaximumBitrateDL<10000000000)) + return 0; + } + if(&mac_config[i].ue_AggregatedMaximumBitrateUL !=NULL) + { + if(!(mac_config[i].ue_AggregatedMaximumBitrateUL>0 && mac_config[i].ue_AggregatedMaximumBitrateUL<10000000000)) + return 0; + } + if(&mac_config[i].cqiSchedInterval !=NULL) + { + if(!(mac_config[i].cqiSchedInterval==1 || mac_config[i].cqiSchedInterval==2 || mac_config[i].cqiSchedInterval==5 || mac_config[i].cqiSchedInterval==10 || mac_config[i].cqiSchedInterval==20 || mac_config[i].cqiSchedInterval==32 || mac_config[i].cqiSchedInterval==40 || mac_config[i].cqiSchedInterval==64 || mac_config[i].cqiSchedInterval==80 || mac_config[i].cqiSchedInterval==128 || mac_config[i].cqiSchedInterval==160)) + return 0; + } + if(&mac_config[i].mac_ContentionResolutionTimer !=NULL) + { + if(!(mac_config[i].mac_ContentionResolutionTimer==8 || mac_config[i].mac_ContentionResolutionTimer==16 || mac_config[i].mac_ContentionResolutionTimer==24 || mac_config[i].mac_ContentionResolutionTimer==32 || mac_config[i].mac_ContentionResolutionTimer==40 || mac_config[i].mac_ContentionResolutionTimer==48 || mac_config[i].mac_ContentionResolutionTimer==56 || mac_config[i].mac_ContentionResolutionTimer==64)) + return 0; + + } + if(mac_config->max_allowed_rbs !=NULL) + { + + if(mac_config[i].max_allowed_rbs[j]<=0) + return 0; + + } + if(mac_config[i].max_mcs !=NULL) + { + if(!(mac_config[i].max_mcs[j]>=0 && mac_config[i].max_mcs[j]<=27)) + return 0; + } + + + } + if(event.key!=NULL && event.value!=NULL) + { + //printf("check one param"); + if(!strcmp((char *) event.key, "priority") && event.value!=NULL) + { + Mac_config* mac_config = malloc(sizeof(Mac_config)*16); + mac_config = (Mac_config *) event.value; + int j=0; + if(event.ue == -1 && event.lcid ==-1) + { + for(i=0;i<MAX_NUM_LCID;i++) + { + for(j=0;j<MAX_NUM_LCID;j++) + { + + if(&mac_config[i].priority[j]!=NULL) + { + if(mac_config[i].priority[j]<=0) + { + return 0; + } + + } + } + } + } + else + { + i = event.ue; + j = event.lcid; + if(mac_config[i].priority[j]<=0) + { + return 0; + } + } + } + else if(!strcmp((char *) event.key, "DCI_aggregation_min") && event.value!=NULL) + { + Mac_config* mac_config = malloc(sizeof(Mac_config)*16); + mac_config = (Mac_config *) event.value; + + if(event.ue == -1) + { + for(i=0;i<NUMBER_OF_UE_MAX;i++) + { + if(mac_config[i].DCI_aggregation_min<=0) + { + return 0; + } + + } + } + else + { + i=event.ue; + if(mac_config[i].DCI_aggregation_min<=0) + { + return 0; + } + + } + } + else if(!strcmp((char *) event.key, "DLSCH_dci_size_bits") && event.value!=NULL) + { + Mac_config* mac_config = malloc(sizeof(Mac_config)*16); + mac_config = (Mac_config *) event.value; + + + + if(event.ue == -1) + { + for(i=0;i<NUMBER_OF_UE_MAX;i++) + { + if(mac_config[i].DLSCH_dci_size_bits <=0) + { + return 0; + } + } + } + else + { + i = event.ue; + if(mac_config[i].DLSCH_dci_size_bits <=0) + { + return 0; + } + } + + } + else if(!strcmp((char *) event.key, "ul_bandwidth") && event.value!=NULL) + { + + Mac_config* mac_config = malloc(sizeof(Mac_config)*16); + mac_config = (Mac_config *) event.value; + int j=0; + if(event.ue == -1 && event.lcid == -1) + { + for(i=0;i<NUMBER_OF_UE_MAX;i++) + { + + //mac_config[i] = *((Mac_config *) event.value + i); + for(j=0;j<MAX_NUM_LCID;j++) + { + + if(&mac_config[i].ul_bandwidth[j]!=NULL) + { + if(!(mac_config[i].ul_bandwidth[j]==6 || mac_config[i].ul_bandwidth[j]==15 || mac_config[i].ul_bandwidth[j]==25 || mac_config[i].ul_bandwidth[j]==50 || mac_config[i].ul_bandwidth[j]==75 || mac_config[i].ul_bandwidth[j]==100)) + return 0; + + } + } + + } + } + else + { + i = event.ue; + j = event.lcid; + if(!(mac_config[i].ul_bandwidth[j]==6 || mac_config[i].ul_bandwidth[j]==15 || mac_config[i].ul_bandwidth[j]==25 || mac_config[i].ul_bandwidth[j]==50 || mac_config[i].ul_bandwidth[j]==75 || mac_config[i].ul_bandwidth[j]==100)) + return 0; + } + + } + else if(!strcmp((char *) event.key, "min_ul_bandwidth") && event.value!=NULL) + { + + Mac_config* mac_config = malloc(sizeof(Mac_config)*16); + mac_config = (Mac_config *) event.value; + int j=0; + if(event.ue == -1 && event.lcid == -1) + { + for(i=0;i<NUMBER_OF_UE_MAX;i++) + { + + //mac_config[i] = *((Mac_config *) event.value + i); + for(j=0;j<MAX_NUM_LCID;j++) + { + + if(&mac_config[i].min_ul_bandwidth[j]!=NULL) + { + if(!(mac_config[i].min_ul_bandwidth[j]==6 || mac_config[i].min_ul_bandwidth[j]==15 || mac_config[i].min_ul_bandwidth[j]==25 || mac_config[i].min_ul_bandwidth[j]==50 || mac_config[i].min_ul_bandwidth[j]==75 || mac_config[i].min_ul_bandwidth[j]==100)) + return 0; + + } + } + + } + } + else + { + i = event.ue; + j = event.lcid; + if(!(mac_config[i].min_ul_bandwidth[j]==6 || mac_config[i].min_ul_bandwidth[j]==15 || mac_config[i].min_ul_bandwidth[j]==25 || mac_config[i].min_ul_bandwidth[j]==50 || mac_config[i].min_ul_bandwidth[j]==75 || mac_config[i].min_ul_bandwidth[j]==100)) + return 0; + } + + } + else if(!strcmp((char *) event.key, "dl_bandwidth") && event.value!=NULL) + { + + + Mac_config* mac_config = malloc(sizeof(Mac_config)*16); + mac_config = (Mac_config *) event.value; + int j=0; + if(event.ue == -1 && event.lcid == -1) + { + for(i=0;i<NUMBER_OF_UE_MAX;i++) + { + if(event.value + i !=NULL) + { + //mac_config[i] = *((Mac_config *) event.value + i); + for(j=0;j<MAX_NUM_LCID;j++) + { + + if(&mac_config[i].dl_bandwidth[j]!=NULL) + { + if(!(mac_config[i].dl_bandwidth[j]==6 || mac_config[i].dl_bandwidth[j]==15 || mac_config[i].dl_bandwidth[j]==25 || mac_config[i].dl_bandwidth[j]==50 || mac_config[i].dl_bandwidth[j]==75 || mac_config[i].dl_bandwidth[j]==100)) + return 0; + + } + } + } + } + } + else + { + i = event.ue; + j = event.lcid; + if(!(mac_config[i].dl_bandwidth[j]==6 || mac_config[i].dl_bandwidth[j]==15 || mac_config[i].dl_bandwidth[j]==25 || mac_config[i].dl_bandwidth[j]==50 || mac_config[i].dl_bandwidth[j]==75 || mac_config[i].dl_bandwidth[j]==100)) + return 0; + } + } + else if(!strcmp((char *) event.key, "min_dl_bandwidth") && event.value!=NULL) + { + + + Mac_config* mac_config = malloc(sizeof(Mac_config)*16); + mac_config = (Mac_config *) event.value; + int j=0; + if(event.ue == -1 && event.lcid == -1) + { + for(i=0;i<NUMBER_OF_UE_MAX;i++) + { + if(event.value + i !=NULL) + { + //mac_config[i] = *((Mac_config *) event.value + i); + for(j=0;j<MAX_NUM_LCID;j++) + { + + if(&mac_config[i].min_dl_bandwidth[j]!=NULL) + { + if(!(mac_config[i].min_dl_bandwidth[j]==6 || mac_config[i].min_dl_bandwidth[j]==15 || mac_config[i].min_dl_bandwidth[j]==25 || mac_config[i].min_dl_bandwidth[j]==50 || mac_config[i].min_dl_bandwidth[j]==75 || mac_config[i].min_dl_bandwidth[j]==100)) + return 0; + + } + } + } + } + } + else + { + i = event.ue; + j = event.lcid; + if(!(mac_config[i].min_dl_bandwidth[j]==6 || mac_config[i].min_dl_bandwidth[j]==15 || mac_config[i].min_dl_bandwidth[j]==25 || mac_config[i].min_dl_bandwidth[j]==50 || mac_config[i].min_dl_bandwidth[j]==75 || mac_config[i].dl_bandwidth[j]==100)) + return 0; + } + } + else if(!strcmp((char *) event.key, "ue_AggregatedMaximumBitrateDL") && event.value!=NULL) + { + Mac_config* mac_config = malloc(sizeof(Mac_config)*16); + mac_config = (Mac_config *) event.value; + + LOG_I(EMU,"ue_AggregatedMaximumBitrateDL update \n"); + + if(event.ue == -1) + { + for(i=0;i<NUMBER_OF_UE_MAX;i++) + { + if(!(mac_config[i].ue_AggregatedMaximumBitrateDL>0 && mac_config[i].ue_AggregatedMaximumBitrateDL<10000000000)) + return 0; + } + } + else + { + i = event.ue; + if(!(mac_config[i].ue_AggregatedMaximumBitrateDL>0 && mac_config[i].ue_AggregatedMaximumBitrateDL<10000000000)) + return 0; + } + + } + else if(!strcmp((char *) event.key, "ue_AggregatedMaximumBitrateUL") && event.value!=NULL) + { + + Mac_config* mac_config = malloc(sizeof(Mac_config)*16); + mac_config = (Mac_config *) event.value; + + + + if(event.ue == -1) + { + for(i=0;i<NUMBER_OF_UE_MAX;i++) + { + if(!(mac_config[i].ue_AggregatedMaximumBitrateUL>0 && mac_config[i].ue_AggregatedMaximumBitrateUL<10000000000)) + return 0; + } + } + else + { + i = event.ue; + if(!(mac_config[i].ue_AggregatedMaximumBitrateUL>0 && mac_config[i].ue_AggregatedMaximumBitrateUL<10000000000)) + return 0; + } + + } + else if(!strcmp((char *) event.key, "cqiSchedInterval") && event.value!=NULL) + { + Mac_config* mac_config = malloc(sizeof(Mac_config)*16); + mac_config = (Mac_config *) event.value; + + if(event.ue == -1) + { + for(i=0;i<NUMBER_OF_UE_MAX;i++) + { + if(!(mac_config[i].cqiSchedInterval==1 || mac_config[i].cqiSchedInterval==2 || mac_config[i].cqiSchedInterval==5 || mac_config[i].cqiSchedInterval==10 || mac_config[i].cqiSchedInterval==20 || mac_config[i].cqiSchedInterval==32 || mac_config[i].cqiSchedInterval==40 || mac_config[i].cqiSchedInterval==64 || mac_config[i].cqiSchedInterval==80 || mac_config[i].cqiSchedInterval==128 || mac_config[i].cqiSchedInterval==160)) + return 0; + } + } + else + { + i = event.ue; + if(!(mac_config[i].cqiSchedInterval==1 || mac_config[i].cqiSchedInterval==2 || mac_config[i].cqiSchedInterval==5 || mac_config[i].cqiSchedInterval==10 || mac_config[i].cqiSchedInterval==20 || mac_config[i].cqiSchedInterval==32 || mac_config[i].cqiSchedInterval==40 || mac_config[i].cqiSchedInterval==64 || mac_config[i].cqiSchedInterval==80 || mac_config[i].cqiSchedInterval==128 || mac_config[i].cqiSchedInterval==160)) + return 0; + } + } + else if(!strcmp((char *) event.key, "mac_ContentionResolutionTimer") && event.value!=NULL) + { + Mac_config* mac_config = malloc(sizeof(Mac_config)*16); + mac_config = (Mac_config *) event.value; + + if(event.ue == -1) + { + for(i=0;i<NUMBER_OF_UE_MAX;i++) + { +if(!(mac_config[i].mac_ContentionResolutionTimer==8 || mac_config[i].mac_ContentionResolutionTimer==16 || mac_config[i].mac_ContentionResolutionTimer==24 || mac_config[i].mac_ContentionResolutionTimer==32 || mac_config[i].mac_ContentionResolutionTimer==40 || mac_config[i].mac_ContentionResolutionTimer==48 || mac_config[i].mac_ContentionResolutionTimer==56 || mac_config[i].mac_ContentionResolutionTimer==64)) + return 0; + } + } + else + { + i=event.ue; +if(!(mac_config[i].mac_ContentionResolutionTimer==8 || mac_config[i].mac_ContentionResolutionTimer==16 || mac_config[i].mac_ContentionResolutionTimer==24 || mac_config[i].mac_ContentionResolutionTimer==32 || mac_config[i].mac_ContentionResolutionTimer==40 || mac_config[i].mac_ContentionResolutionTimer==48 || mac_config[i].mac_ContentionResolutionTimer==56 || mac_config[i].mac_ContentionResolutionTimer==64)) + return 0; + } + } + else if(!strcmp((char *) event.key, "max_allowed_rbs") && event.value!=NULL && validate_mac(event)) + { + + + + Mac_config* mac_config = malloc(sizeof(Mac_config)*16); + mac_config = (Mac_config *) event.value; + int j=0; + if(event.ue == -1 && event.lcid == -1) + { + for(i=0;i<NUMBER_OF_UE_MAX;i++) + { + if(event.value + i !=NULL) + { + + for(j=0;j<MAX_NUM_LCID;j++) + { + + if(&mac_config[i].max_allowed_rbs[j]!=NULL) + { + if(mac_config[i].max_allowed_rbs[j]<=0) + return 0; + } + } + } + } + } + else + { + i = event.ue; + j = event.lcid; + if(mac_config[i].max_allowed_rbs[j]<=0) + return 0; + } + + } + else if(!strcmp((char *) event.key, "max_mcs") && event.value!=NULL) + { + + + + Mac_config* mac_config = malloc(sizeof(Mac_config)*16); + mac_config = (Mac_config *) event.value; + int j=0; + if(event.ue == -1 && event.lcid == -1) + { + for(i=0;i<NUMBER_OF_UE_MAX;i++) + { + for(j=0;j<MAX_NUM_LCID;j++) + { + + if(&mac_config[i].max_mcs[j]!=NULL) + { + if(!(mac_config[i].max_mcs[j]>=0 && mac_config[i].max_mcs[j]<=27)) + return 0; + + } + } + + } + } + else + { + i = event.ue; + j = event.lcid; + if(!(mac_config[i].max_mcs[j]>=0 && mac_config[i].max_mcs[j]<=27)) + return 0; + + } + } + + } + return 1; + } diff --git a/targets/SIMU/USER/event_handler.h b/targets/SIMU/USER/event_handler.h index 10f8251bba..14b05122ab 100644 --- a/targets/SIMU/USER/event_handler.h +++ b/targets/SIMU/USER/event_handler.h @@ -41,7 +41,9 @@ void add_event(Event_t event); -void schedule(Event_Type_t type, int frame, char * key, void* value); +void schedule(Operation_Type_t op, Event_Type_t type, int frame, char * key, void* value, int ue, int lcid); + +void schedule_delayed(Operation_Type_t op, Event_Type_t type, char * key, void* value, char * time, int ue, int lcid); void schedule_events(void); @@ -50,15 +52,18 @@ void execute_events(frame_t frame); void update_oai_model(char * key, void * value); -void update_sys_model(char * key, void * value); +void update_sys_model(Event_t event); + +void update_topo_model(Event_t event); + +void update_app_model(Event_t event); -void update_topo_model(char * key, void * value); +void update_emu_model(Event_t event); -void update_app_model(char * key, void * value); +void update_mac(Event_t event); -void update_emu_model(char * key, void * value); +int validate_mac(Event_t event); -void update_mac(char * key, void * value); /* void schedule_end_of_simulation(End_Of_Sim_Event_Type type, int value); diff --git a/targets/SIMU/USER/oaisim.c b/targets/SIMU/USER/oaisim.c index f56aa030d1..32eb08bbb1 100644 --- a/targets/SIMU/USER/oaisim.c +++ b/targets/SIMU/USER/oaisim.c @@ -49,6 +49,7 @@ //#ifdef OPENAIR2 #include "LAYER2/MAC/defs.h" +#include "LAYER2/MAC/proto.h" #include "LAYER2/MAC/vars.h" #include "pdcp.h" #ifndef CELLULAR @@ -138,8 +139,8 @@ channel_desc_t *UE2eNB[NUMBER_OF_UE_MAX][NUMBER_OF_eNB_MAX]; node_desc_t *enb_data[NUMBER_OF_eNB_MAX]; node_desc_t *ue_data[NUMBER_OF_UE_MAX]; // Added for PHY abstraction -extern Node_list ue_node_list; -extern Node_list enb_node_list; +extern node_list* ue_node_list; +extern node_list* enb_node_list; extern int pdcp_period, omg_period; extern double **s_re, **s_im, **r_re, **r_im, **r_re0, **r_im0; @@ -313,14 +314,14 @@ static void set_cli_start(module_id_t module_idP, uint8_t start) { #endif #ifdef OPENAIR2 -int omv_write(int pfd, Node_list enb_node_list, Node_list ue_node_list, Data_Flow_Unit omv_data) { +int omv_write(int pfd, node_list* enb_node_list, node_list* ue_node_list, Data_Flow_Unit omv_data) { module_id_t i, j; omv_data.end = 0; //omv_data.total_num_nodes = NB_UE_INST + NB_eNB_INST; for (i = 0; i < NB_eNB_INST; i++) { if (enb_node_list != NULL) { - omv_data.geo[i].x = (enb_node_list->node->X_pos < 0.0) ? 0.0 : enb_node_list->node->X_pos; - omv_data.geo[i].y = (enb_node_list->node->Y_pos < 0.0) ? 0.0 : enb_node_list->node->Y_pos; + omv_data.geo[i].x = (enb_node_list->node->x_pos < 0.0) ? 0.0 : enb_node_list->node->x_pos; + omv_data.geo[i].y = (enb_node_list->node->y_pos < 0.0) ? 0.0 : enb_node_list->node->y_pos; omv_data.geo[i].z = 1.0; omv_data.geo[i].mobility_type = oai_emulation.info.omg_model_enb; omv_data.geo[i].node_type = 0; //eNB @@ -339,8 +340,8 @@ int omv_write(int pfd, Node_list enb_node_list, Node_list ue_node_list, Data_Flo } for (i = NB_eNB_INST; i < NB_UE_INST + NB_eNB_INST; i++) { if (ue_node_list != NULL) { - omv_data.geo[i].x = (ue_node_list->node->X_pos < 0.0) ? 0.0 : ue_node_list->node->X_pos; - omv_data.geo[i].y = (ue_node_list->node->Y_pos < 0.0) ? 0.0 : ue_node_list->node->Y_pos; + omv_data.geo[i].x = (ue_node_list->node->x_pos < 0.0) ? 0.0 : ue_node_list->node->x_pos; + omv_data.geo[i].y = (ue_node_list->node->y_pos < 0.0) ? 0.0 : ue_node_list->node->y_pos; omv_data.geo[i].z = 1.0; omv_data.geo[i].mobility_type = oai_emulation.info.omg_model_ue; omv_data.geo[i].node_type = 1; //UE @@ -645,11 +646,13 @@ void *l2l1_task(void *args_p) { } #endif #ifdef DEBUG_OMG +/* if ((((int) oai_emulation.info.time_s) % 100) == 0) { for (UE_inst = oai_emulation.info.first_ue_local; UE_inst < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_inst++) { get_node_position (UE, UE_inst); } } +*/ #endif update_ocm (); @@ -1124,6 +1127,7 @@ int main(int argc, char **argv) { smbv_write_config_from_frame_parms(smbv_fname, &PHY_vars_eNB_g[0]->lte_frame_parms); #endif // add events to future event list: Currently not used + //oai_emulation.info.oeh_enabled = 1; if (oai_emulation.info.oeh_enabled == 1) schedule_events(); @@ -1569,4 +1573,12 @@ void oai_shutdown(void) { LOG_N(EMU, ">>>>>>>>>>>>>>>>>>>>>>>>>>> OAIEMU shutdown <<<<<<<<<<<<<<<<<<<<<<<<<<\n\n"); } +eNB_MAC_INST* get_eNB_mac_inst() +{ + return eNB_mac_inst; +} +OAI_Emulation* get_OAI_emulation() +{ + return &oai_emulation; +} diff --git a/targets/SIMU/USER/oaisim.h b/targets/SIMU/USER/oaisim.h index 1dde3d2360..cf3a6e78ef 100644 --- a/targets/SIMU/USER/oaisim.h +++ b/targets/SIMU/USER/oaisim.h @@ -17,6 +17,8 @@ #include "UTIL/OMV/structures.h" #endif +eNB_MAC_INST* get_eNB_mac_inst(void); +OAI_Emulation* get_OAI_emulation(void); void init_channel_vars(LTE_DL_FRAME_PARMS *frame_parms, double ***s_re,double ***s_im,double ***r_re,double ***r_im,double ***r_re0,double ***r_im0); void do_UL_sig(double **r_re0,double **r_im0,double **r_re,double **r_im,double **s_re,double **s_im,channel_desc_t *UE2eNB[NUMBER_OF_UE_MAX][NUMBER_OF_eNB_MAX],node_desc_t *enb_data[NUMBER_OF_eNB_MAX],node_desc_t *ue_data[NUMBER_OF_UE_MAX],uint16_t next_slot,uint8_t abstraction_flag,LTE_DL_FRAME_PARMS *frame_parms, uint32_t); @@ -25,7 +27,7 @@ void do_DL_sig(double **r_re0,double **r_im0,double **r_re,double **r_im,double void init_ue(node_desc_t *ue_data, UE_Antenna ue_ant);//Abstraction changes void init_enb(node_desc_t *enb_data, eNB_Antenna enb_ant);//Abstraction changes -void extract_position(Node_list input_node_list, node_desc_t**, int nb_nodes);//Abstraction changes +void extract_position(node_list* input_node_list, node_desc_t**, int nb_nodes);//Abstraction changes void get_beta_map(void);//Abstraction changes void get_MIESM_param(void); @@ -46,7 +48,7 @@ void reset_opp_meas(void); void print_opp_meas(void); #ifdef OPENAIR2 -int omv_write (int pfd, Node_list enb_node_list, Node_list ue_node_list, Data_Flow_Unit omv_data); +int omv_write (int pfd, node_list* enb_node_list, node_list* ue_node_list, Data_Flow_Unit omv_data); void omv_end (int pfd, Data_Flow_Unit omv_data); #endif diff --git a/targets/SIMU/USER/oaisim_config.c b/targets/SIMU/USER/oaisim_config.c index 6a22fcd820..d551e9d778 100644 --- a/targets/SIMU/USER/oaisim_config.c +++ b/targets/SIMU/USER/oaisim_config.c @@ -49,6 +49,7 @@ #include "OCG.h" #include "OCG_extern.h" #include "UTIL/OMG/omg.h" +#include "UTIL/OMG/grid.h" #include "UTIL/OTG/otg_tx.h" #include "UTIL/OTG/otg.h" #include "UTIL/OTG/otg_vars.h" @@ -92,9 +93,19 @@ mapping omg_model_names[] = {"RWALK", RWALK}, {"TRACE", TRACE}, {"SUMO", SUMO}, + {"STEADY_RWP", STEADY_RWP}, {"MAX_NUM_MOB_TYPES", MAX_NUM_MOB_TYPES}, {NULL, -1} }; +// subtypes for RWP in grid map +mapping omg_rwp_names[] = +{ + {"MIN_RWP_TYPES", MIN_RWP_TYPES}, + {"RESTRICTED_RWP",RESTIRICTED_RWP}, + {"CONNECTED_DOMAIN", CONNECTED_DOMAIN}, + {"MAX_RWP_TYPES", MAX_RWP_TYPES}, + {NULL, -1} +}; mapping otg_multicast_app_type_names[] = { {"no_predefined_multicast_traffic", 0}, {"mscbr", 1}, @@ -241,8 +252,9 @@ void init_oai_emulation(void) { oai_emulation.topology_config.cell_type.selected_option = "macrocell"; oai_emulation.topology_config.relay.number_of_relays = 0; oai_emulation.topology_config.mobility.UE_mobility.UE_mobility_type.selected_option = "STATIC"; - oai_emulation.topology_config.mobility.UE_mobility.grid_walk.grid_map.horizontal_grid = 1; - oai_emulation.topology_config.mobility.UE_mobility.grid_walk.grid_map.vertical_grid = 1; + oai_emulation.topology_config.mobility.UE_mobility.grid_walk.grid_map.selected_option="MAX_RWP_TYPES"; + //oai_emulation.topology_config.mobility.UE_mobility.grid_walk.grid_map.horizontal_grid = 1; + //oai_emulation.topology_config.mobility.UE_mobility.grid_walk.grid_map.vertical_grid = 1; oai_emulation.topology_config.mobility.UE_mobility.grid_walk.grid_trip_type.selected_option = "random_destination"; oai_emulation.topology_config.mobility.UE_mobility.UE_initial_distribution.selected_option = "random"; oai_emulation.topology_config.mobility.UE_mobility.random_UE_distribution.number_of_nodes = 1; @@ -286,7 +298,7 @@ void init_oai_emulation(void) { oai_emulation.application_config.predefined_traffic.background[i] = "disable"; oai_emulation.application_config.predefined_traffic.aggregation_level[i] = 1; oai_emulation.application_config.predefined_traffic.flow_start[i] = (i+1)*25; - oai_emulation.application_config.predefined_traffic.flow_duration[i] = 100; + oai_emulation.application_config.predefined_traffic.flow_duration[i] = 0xffff; oai_emulation.application_config.predefined_traffic.destination_id[i] = 0; @@ -389,6 +401,7 @@ void init_oai_emulation(void) { oai_emulation.info.omg_model_enb=STATIC; //default to static mobility model oai_emulation.info.omg_model_rn=STATIC; //default to static mobility model oai_emulation.info.omg_model_ue=STATIC; //default to static mobility model + oai_emulation.info.omg_rwp_type = RESTIRICTED_RWP; oai_emulation.info.omg_model_ue_current=STATIC; //default to static mobility model oai_emulation.info.otg_traffic="no_predefined_traffic"; oai_emulation.info.otg_bg_traffic_enabled = 0; // G flag @@ -478,6 +491,10 @@ void oaisim_config(void) { g_log->log_component[OTG_OWD].filelog = 1;*/ ocg_config_app(); // packet generator } + // add a var to control this, and pass this var to OMG + set_component_filelog(OMG); + LOG_I(OMG,"setting OMG file log \n"); + } int olg_config(void) { @@ -584,121 +601,161 @@ int ocg_config_env(void) { } int ocg_config_topo(void) { - // omg - init_omg_global_params(); - - // setup params for openair mobility generator - //common params - - omg_param_list.min_X = 0; - omg_param_list.max_X = oai_emulation.topology_config.area.x_m; - omg_param_list.min_Y = 0; - omg_param_list.max_Y = oai_emulation.topology_config.area.y_m; - // init values - omg_param_list.min_speed = 0.1; - omg_param_list.max_speed = 20.0; - omg_param_list.min_journey_time = 0.1; - omg_param_list.max_journey_time = 10.0; - omg_param_list.min_azimuth = 0; // ??? - omg_param_list.max_azimuth = 360; // ??? - omg_param_list.min_sleep = 0.1; - omg_param_list.max_sleep = 8.0; - - - // init OMG for eNBs - if ((oai_emulation.info.omg_model_enb = map_str_to_int(omg_model_names, oai_emulation.topology_config.mobility.eNB_mobility.eNB_mobility_type.selected_option))== -1) - oai_emulation.info.omg_model_enb = STATIC; - LOG_I(OMG,"eNB mobility model is (%s, %d)\n", - oai_emulation.topology_config.mobility.eNB_mobility.eNB_mobility_type.selected_option, - oai_emulation.info.omg_model_enb); - - if (oai_emulation.info.omg_model_enb == TRACE) { - omg_param_list.mobility_file = (char*) malloc(256);// user-specific trace file "%s/UTIL/OMG/mobility.txt",getenv("OPENAIR2_DIR") - //memset(oai_emulation.topology_config.mobility.UE_mobility.trace_config.trace_mobility_file,0,256); - //sprintf(omg_param_list.mobility_file,"%s",oai_emulation.topology_config.mobility.UE_mobility.trace_config.trace_mobility_file); - sprintf(omg_param_list.mobility_file,"%s/UTIL/OMG/TRACE/%s", - getenv("OPENAIR2_DIR"), - oai_emulation.topology_config.mobility.eNB_mobility.trace_config.trace_mobility_file); - LOG_I(OMG,"TRACE file at %s\n", omg_param_list.mobility_file); + int i; + // omg + init_omg_global_params(); + + // setup params for openair mobility generator + //common params + for(i=0; i < MAX_NUM_NODE_TYPES; i++) { + + omg_param_list[i].min_x = 0; + omg_param_list[i].max_x = oai_emulation.topology_config.area.x_m; + omg_param_list[i].min_y = 0; + omg_param_list[i].max_y= oai_emulation.topology_config.area.y_m; + // init values + omg_param_list[i].min_speed = 0.1; + omg_param_list[i].max_speed = 20.0; + omg_param_list[i].min_journey_time = 0.1; + omg_param_list[i].max_journey_time = 10.0; + omg_param_list[i].min_azimuth = 0; // ??? + omg_param_list[i].max_azimuth = 360; // ??? + omg_param_list[i].min_sleep = 0.1; + omg_param_list[i].max_sleep = 8.0; + omg_param_list[i].nodes_type = i; + omg_param_list[i].nodes=0; + omg_param_list[i].mobility_type=STATIC; + + // init OMG for eNBs + + if(i==eNB) { + if ((oai_emulation.info.omg_model_enb = map_str_to_int(omg_model_names, oai_emulation.topology_config.mobility.eNB_mobility.eNB_mobility_type.selected_option))== -1) + oai_emulation.info.omg_model_enb = STATIC; + + LOG_I(OMG,"eNB mobility model is (%s, %d)\n", + oai_emulation.topology_config.mobility.eNB_mobility.eNB_mobility_type.selected_option, + oai_emulation.info.omg_model_enb); + + omg_param_list[i].mobility_type = oai_emulation.info.omg_model_enb; + omg_param_list[i].nodes = oai_emulation.info.nb_enb_local + oai_emulation.info.nb_rn_local; + omg_param_list[i].seed = oai_emulation.info.seed; // specific seed for enb and ue to avoid node overlapping + + + if (oai_emulation.info.omg_model_enb == TRACE) { + omg_param_list[i].mobility_file = (char*) malloc(256);// user-specific trace file "%s/UTIL/OMG/mobility.txt",getenv("OPENAIR2_DIR") + //memset(oai_emulation.topology_config.mobility.UE_mobility.trace_config.trace_mobility_file,0,256); + //sprintf(omg_param_list.mobility_file,"%s",oai_emulation.topology_config.mobility.UE_mobility.trace_config.trace_mobility_file); + sprintf(omg_param_list[i].mobility_file,"%s/UTIL/OMG/TRACE/%s", + getenv("OPENAIR2_DIR"), + oai_emulation.topology_config.mobility.eNB_mobility.trace_config.trace_mobility_file); + LOG_I(OMG,"TRACE file at %s\n", omg_param_list[i].mobility_file); + // notify the user if the file is not found + } + + + + if (strcmp(oai_emulation.topology_config.mobility.eNB_mobility.eNB_initial_distribution.selected_option, "fixed") == 0) { + omg_param_list[i].user_fixed = true; + omg_param_list[i].fixed_x = (double)oai_emulation.topology_config.mobility.eNB_mobility.fixed_eNB_distribution.pos_x; + omg_param_list[i].fixed_y = (double)oai_emulation.topology_config.mobility.eNB_mobility.fixed_eNB_distribution.pos_y; + } + + /*// at this moment, we use the above moving dynamics for mobile eNB + if (omg_param_list.nodes >0 ) + init_mobility_generator(omg_param_list);*/ + + } + else if (i== UE) { // init OMG for UE + + + // input of OMG: STATIC: 0, RWP: 1, RWALK 2, or TRACE 3, or SUMO or STEADY_RWP + if ((oai_emulation.info.omg_model_ue = map_str_to_int(omg_model_names, oai_emulation.topology_config.mobility.UE_mobility.UE_mobility_type.selected_option))== -1) + oai_emulation.info.omg_model_ue = STATIC; + + LOG_I(OMG,"UE mobility model is (%s, %d)\n", + oai_emulation.topology_config.mobility.UE_mobility.UE_mobility_type.selected_option, + oai_emulation.info.omg_model_ue); + + if (oai_emulation.info.omg_model_ue == RWP) { + oai_emulation.info.omg_rwp_type = map_str_to_int(omg_rwp_names,oai_emulation.topology_config.mobility.UE_mobility.grid_walk.grid_map.selected_option); + if (oai_emulation.info.omg_rwp_type == -1){ + LOG_I(OMG,"Apply standard RWP model \n"); + }else { + LOG_I(OMG,"Apply %s mobility model (%d) \n", oai_emulation.topology_config.mobility.UE_mobility.grid_walk.grid_map.selected_option, + oai_emulation.info.omg_rwp_type); + omg_param_list[i].rwp_type= oai_emulation.info.omg_rwp_type; + omg_param_list[i].max_vertices = + max_vertices_ongrid (omg_param_list[i]); + + omg_param_list[i].max_block_num = + max_connecteddomains_ongrid (omg_param_list[i]); } + } + + omg_param_list[i].mobility_type = oai_emulation.info.omg_model_ue; + omg_param_list[i].nodes = oai_emulation.info.nb_ue_local+ oai_emulation.info.nb_rn_local; + omg_param_list[i].seed = oai_emulation.info.seed + oai_emulation.info.nb_ue_local; //fixme: specific seed for enb and ue to avoid node overlapping - omg_param_list.mobility_type = oai_emulation.info.omg_model_enb; - omg_param_list.nodes_type = eNB; //eNB or eNB + RN - if (strcmp(oai_emulation.topology_config.mobility.eNB_mobility.eNB_initial_distribution.selected_option, "fixed") == 0) { - omg_param_list.user_fixed = true; - omg_param_list.fixed_X = (double)oai_emulation.topology_config.mobility.eNB_mobility.fixed_eNB_distribution.pos_x; - omg_param_list.fixed_Y = (double)oai_emulation.topology_config.mobility.eNB_mobility.fixed_eNB_distribution.pos_y; - } - omg_param_list.nodes = oai_emulation.info.nb_enb_local + oai_emulation.info.nb_rn_local; - omg_param_list.seed = oai_emulation.info.seed; // specific seed for enb and ue to avoid node overlapping + omg_param_list[i].min_speed = (oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.min_speed_mps == 0) ? 0.1 : oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.min_speed_mps; - // at this moment, we use the above moving dynamics for mobile eNB - if (omg_param_list.nodes >0 ) - init_mobility_generator(omg_param_list); + omg_param_list[i].max_speed = (oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.max_speed_mps == 0) ? 0.1 : oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.max_speed_mps; + omg_param_list[i].min_journey_time = (oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.min_journey_time_ms == 0) ? 0.1 : oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.min_journey_time_ms; - // init OMG for UE - // input of OMG: STATIC: 0, RWP: 1, RWALK 2, or TRACE 3, or SUMO - if ((oai_emulation.info.omg_model_ue = map_str_to_int(omg_model_names, oai_emulation.topology_config.mobility.UE_mobility.UE_mobility_type.selected_option))== -1) - oai_emulation.info.omg_model_ue = STATIC; - LOG_I(OMG,"UE mobility model is (%s, %d)\n", - oai_emulation.topology_config.mobility.UE_mobility.UE_mobility_type.selected_option, - oai_emulation.info.omg_model_ue); - omg_param_list.mobility_type = oai_emulation.info.omg_model_ue; - omg_param_list.nodes_type = UE;//UE - omg_param_list.nodes = oai_emulation.info.nb_ue_local+ oai_emulation.info.nb_rn_local; - omg_param_list.seed = oai_emulation.info.seed + oai_emulation.info.nb_ue_local; //fixme: specific seed for enb and ue to avoid node overlapping + omg_param_list[i].max_journey_time = (oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.max_journey_time_ms == 0) ? 0.1 : oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.max_journey_time_ms; - omg_param_list.min_speed = (oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.min_speed_mps == 0) ? 0.1 : oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.min_speed_mps; - omg_param_list.max_speed = (oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.max_speed_mps == 0) ? 0.1 : oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.max_speed_mps; + omg_param_list[i].min_azimuth = 0.1; // wait for advanced OSD + omg_param_list[i].max_azimuth = 360; - omg_param_list.min_journey_time = (oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.min_journey_time_ms == 0) ? 0.1 : oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.min_journey_time_ms; - omg_param_list.max_journey_time = (oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.max_journey_time_ms == 0) ? 0.1 : oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.max_journey_time_ms; + omg_param_list[i].min_sleep = (oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.min_sleep_ms == 0) ? 0.1 : oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.min_sleep_ms; - omg_param_list.min_azimuth = 0.1; // wait for advanced OSD - omg_param_list.max_azimuth = 360; - - omg_param_list.min_sleep = (oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.min_sleep_ms == 0) ? 0.1 : oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.min_sleep_ms; - omg_param_list.max_sleep = (oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.max_sleep_ms == 0) ? 0.1 : oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.max_sleep_ms; + omg_param_list[i].max_sleep = (oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.max_sleep_ms == 0) ? 0.1 : oai_emulation.topology_config.mobility.UE_mobility.UE_moving_dynamics.max_sleep_ms; + if (oai_emulation.info.omg_model_ue == TRACE) { - omg_param_list.mobility_file = (char*) malloc(256);// user-specific trace file "%s/UTIL/OMG/mobility.txt",getenv("OPENAIR2_DIR") + omg_param_list[i].mobility_file = (char*) malloc(256);// user-specific trace file "%s/UTIL/OMG/mobility.txt",getenv("OPENAIR2_DIR") //memset(oai_emulation.topology_config.mobility.UE_mobility.trace_config.trace_mobility_file,0,256); //sprintf(omg_param_list.mobility_file,"%s",oai_emulation.topology_config.mobility.UE_mobility.trace_config.trace_mobility_file); - sprintf(omg_param_list.mobility_file,"%s/UTIL/OMG/TRACE/%s", + sprintf(omg_param_list[i].mobility_file,"%s/UTIL/OMG/TRACE/%s", getenv("OPENAIR2_DIR"), oai_emulation.topology_config.mobility.UE_mobility.trace_config.trace_mobility_file); - LOG_I(OMG,"TRACE file at %s\n", omg_param_list.mobility_file); + LOG_I(OMG,"TRACE file at %s\n", omg_param_list[i].mobility_file); - } else if (oai_emulation.info.omg_model_ue == SUMO){ - omg_param_list.sumo_command = (char*) malloc(20); - sprintf(omg_param_list.sumo_command, "%s", oai_emulation.topology_config.mobility.UE_mobility.sumo_config.command); - omg_param_list.sumo_config = (char*) malloc(256); - sprintf(omg_param_list.sumo_config, "%s", oai_emulation.topology_config.mobility.UE_mobility.sumo_config.file); - omg_param_list.sumo_start = oai_emulation.topology_config.mobility.UE_mobility.sumo_config.start; + } + else if (oai_emulation.info.omg_model_ue == SUMO) { + omg_param_list[i].sumo_command = (char*) malloc(20); + sprintf(omg_param_list[i].sumo_command, "%s", oai_emulation.topology_config.mobility.UE_mobility.sumo_config.command); + omg_param_list[i].sumo_config = (char*) malloc(256); + sprintf(omg_param_list[i].sumo_config, "%s", oai_emulation.topology_config.mobility.UE_mobility.sumo_config.file); + omg_param_list[i].sumo_start = oai_emulation.topology_config.mobility.UE_mobility.sumo_config.start; if (oai_emulation.topology_config.mobility.UE_mobility.sumo_config.end > 0 ) - omg_param_list.sumo_end = oai_emulation.topology_config.mobility.UE_mobility.sumo_config.end; + omg_param_list[i].sumo_end = oai_emulation.topology_config.mobility.UE_mobility.sumo_config.end; else - omg_param_list.sumo_end = (oai_emulation.info.n_frames_flag == 1 ) ? oai_emulation.info.n_frames : 1024 ; // fixme: the else case is infinity + omg_param_list[i].sumo_end = (oai_emulation.info.n_frames_flag == 1 ) ? oai_emulation.info.n_frames : 1024 ; // fixme: the else case is infinity - omg_param_list.sumo_step = oai_emulation.topology_config.mobility.UE_mobility.sumo_config.step=1; // 1000ms - omg_param_list.sumo_host = (char*) malloc(40); - sprintf(omg_param_list.sumo_host,"%s",oai_emulation.topology_config.mobility.UE_mobility.sumo_config.hip); - omg_param_list.sumo_port = oai_emulation.topology_config.mobility.UE_mobility.sumo_config.hport ; + omg_param_list[i].sumo_step = oai_emulation.topology_config.mobility.UE_mobility.sumo_config.step=1; // 1000ms + omg_param_list[i].sumo_host = (char*) malloc(40); + sprintf(omg_param_list[i].sumo_host,"%s",oai_emulation.topology_config.mobility.UE_mobility.sumo_config.hip); + omg_param_list[i].sumo_port = oai_emulation.topology_config.mobility.UE_mobility.sumo_config.hport ; LOG_D(OMG, "opt (%s,%d) cmd (%s,%s) config_file (%s,%s) hip (%s,%s) \n", oai_emulation.topology_config.mobility.UE_mobility.UE_mobility_type.selected_option,oai_emulation.info.omg_model_ue, - omg_param_list.sumo_command, oai_emulation.topology_config.mobility.UE_mobility.sumo_config.command, - omg_param_list.sumo_config, oai_emulation.topology_config.mobility.UE_mobility.sumo_config.file, - omg_param_list.sumo_host, oai_emulation.topology_config.mobility.UE_mobility.sumo_config.hip); + omg_param_list[i].sumo_command, oai_emulation.topology_config.mobility.UE_mobility.sumo_config.command, + omg_param_list[i].sumo_config, oai_emulation.topology_config.mobility.UE_mobility.sumo_config.file, + omg_param_list[i].sumo_host, oai_emulation.topology_config.mobility.UE_mobility.sumo_config.hip); } - if (omg_param_list.nodes >0 ) - init_mobility_generator(omg_param_list); - - if (oai_emulation.topology_config.omv == 1 ) - oai_emulation.info.omv_enabled = 1; - - return 1; + + } + + if (oai_emulation.topology_config.omv == 1 ) + oai_emulation.info.omv_enabled = 1; + + }//for + + + init_mobility_generator(omg_param_list); + + return 1; } diff --git a/targets/SIMU/USER/oaisim_functions.c b/targets/SIMU/USER/oaisim_functions.c index 623c9b2f48..e2abf58eb1 100644 --- a/targets/SIMU/USER/oaisim_functions.c +++ b/targets/SIMU/USER/oaisim_functions.c @@ -43,6 +43,9 @@ #include "PHY/extern.h" #include "MAC_INTERFACE/extern.h" #include "LAYER2/MAC/extern.h" +#ifdef OPENAIR2 +#include "LAYER2/MAC/proto.h" +#endif #include "LAYER2/PDCP_v10.1.0/pdcp.h" #include "LAYER2/PDCP_v10.1.0/pdcp_primitives.h" #include "RRC/LITE/extern.h" @@ -108,11 +111,10 @@ int map1,map2; double **ShaF = NULL; // pointers signal buffers (s = transmit, r,r0 = receive) double **s_re, **s_im, **r_re, **r_im, **r_re0, **r_im0; -Node_list ue_node_list = NULL; -Node_list enb_node_list = NULL; -int pdcp_period = 0; +node_list* ue_node_list = NULL; +node_list* enb_node_list = NULL; int omg_period = 0; - +int pdcp_period = 0; // time calibration for soft realtime mode struct timespec time_spec; @@ -990,11 +992,11 @@ void update_omg (frame_t frameP) { if ((frameP % omg_period) == 0 ) { // call OMG every 10ms update_nodes(oai_emulation.info.time_s); - display_node_list(enb_node_list); - display_node_list(ue_node_list); + //display_node_list(enb_node_list); + //display_node_list(ue_node_list); if (oai_emulation.info.omg_model_ue >= MAX_NUM_MOB_TYPES){ // mix mobility model for(UE_id=oai_emulation.info.first_ue_local; UE_id<(oai_emulation.info.first_ue_local+oai_emulation.info.nb_ue_local);UE_id++){ - new_omg_model = randomGen(STATIC,RWALK); + new_omg_model = randomgen(STATIC,RWALK); LOG_D(OMG, "[UE] Node of ID %d is changing mobility generator ->%d \n", UE_id, new_omg_model); // reset the mobility model for a specific node set_new_mob_type (UE_id, UE, new_omg_model, oai_emulation.info.time_s); @@ -1003,7 +1005,7 @@ void update_omg (frame_t frameP) { if (oai_emulation.info.omg_model_enb >= MAX_NUM_MOB_TYPES) { // mix mobility model for (eNB_id = oai_emulation.info.first_enb_local; eNB_id < (oai_emulation.info.first_enb_local + oai_emulation.info.nb_enb_local); eNB_id++) { - new_omg_model = randomGen (STATIC, RWALK); + new_omg_model = randomgen (STATIC, RWALK); LOG_D (OMG,"[eNB] Node of ID %d is changing mobility generator ->%d \n", eNB_id, new_omg_model); // reset the mobility model for a specific node set_new_mob_type (eNB_id, eNB, new_omg_model, oai_emulation.info.time_s); @@ -1013,8 +1015,10 @@ void update_omg (frame_t frameP) { } void update_omg_ocm() { - enb_node_list = get_current_positions(oai_emulation.info.omg_model_enb, eNB, oai_emulation.info.time_s); - ue_node_list = get_current_positions(oai_emulation.info.omg_model_ue, UE, oai_emulation.info.time_s); + + enb_node_list=get_current_positions(oai_emulation.info.omg_model_enb, eNB, oai_emulation.info.time_s); + ue_node_list=get_current_positions(oai_emulation.info.omg_model_ue, UE, oai_emulation.info.time_s); + } void update_ocm() { @@ -1027,6 +1031,8 @@ void update_ocm() { /* check if the openair channel model is activated used for PHY abstraction : path loss*/ if ((oai_emulation.info.ocm_enabled == 1)&& (ethernet_flag == 0 )) { //LOG_D(OMG," extracting position of eNb...\n"); + display_node_list(enb_node_list); + display_node_list(ue_node_list); extract_position(enb_node_list, enb_data, NB_eNB_INST); //extract_position_fixed_enb(enb_data, NB_eNB_INST,frame); //LOG_D(OMG," extracting position of UE...\n"); diff --git a/targets/SIMU/USER/sinr_sim.c b/targets/SIMU/USER/sinr_sim.c index b80d861399..b626533c2c 100644 --- a/targets/SIMU/USER/sinr_sim.c +++ b/targets/SIMU/USER/sinr_sim.c @@ -48,19 +48,19 @@ extern double MI_map_64qam[3][227]; */ // Extract the positions of UE and ENB from the mobility model -void extract_position (Node_list input_node_list, node_desc_t **node_data, int nb_nodes) { +void extract_position (node_list* input_node_list, node_desc_t **node_data, int nb_nodes) { int i; for (i=0;i<nb_nodes;i++) { if ((input_node_list != NULL) && (node_data[i] != NULL)) { - node_data[i]->x = input_node_list->node->X_pos; + node_data[i]->x = input_node_list->node->x_pos; if (node_data[i]->x <0.0) node_data[i]->x = 0.0; - node_data[i]->y = input_node_list->node->Y_pos; + node_data[i]->y = input_node_list->node->y_pos; if (node_data[i]->y <0.0) node_data[i]->y = 0.0; - LOG_D(OCM, "extract_position: added node_data %d with position X: %f and Y: %f \n", i,input_node_list->node->X_pos, input_node_list->node->Y_pos ); + LOG_D(OCM, "extract_position: added node_data %d with position X: %f and Y: %f \n", i,input_node_list->node->x_pos, input_node_list->node->y_pos ); input_node_list = input_node_list->next; } else { -- GitLab