flexran_agent_common.h 17 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/*******************************************************************************
    OpenAirInterface
    Copyright(c) 1999 - 2014 Eurecom

    OpenAirInterface is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.


    OpenAirInterface is distributed in the hope that 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 OpenAirInterface.The full GNU General Public License is
   included in this distribution in the file called "COPYING". If not,
   see <http://www.gnu.org/licenses/>.

  Contact Information
  OpenAirInterface Admin: openair_admin@eurecom.fr
  OpenAirInterface Tech : openair_tech@eurecom.fr
  OpenAirInterface Dev  : openair4g-devel@lists.eurecom.fr

  Address      : Eurecom, Compus SophiaTech 450, route des chappes, 06451 Biot, France.

 *******************************************************************************/

30
/*! \file flexran_agent_common.h
31
 * \brief common message primitves and utilities 
32
 * \author Xenofon Foukas, Mohamed Kassem and Navid Nikaein
33 34 35 36 37 38
 * \date 2016
 * \version 0.1
 */



39 40
#ifndef FLEXRAN_AGENT_COMMON_H_
#define FLEXRAN_AGENT_COMMON_H_
41

42
#include <time.h>
43 44

#include "header.pb-c.h"
45
#include "flexran.pb-c.h"
46 47 48
#include "stats_messages.pb-c.h"
#include "stats_common.pb-c.h"

49
#include "flexran_agent_defs.h"
50
#include "enb_config.h"
51 52 53 54 55 56 57 58

#include "LAYER2/MAC/extern.h"
#include "LAYER2/RLC/rlc.h"

# include "tree.h"
# include "intertask_interface.h"
# include "timer.h"

59
#define FLEXRAN_VERSION 0
60

61
typedef int (*flexran_agent_message_decoded_callback)(
62
	mid_t mod_id,
63
       	const void *params,
64
	Protocol__FlexranMessage **msg
65 66
);

67
typedef int (*flexran_agent_message_destruction_callback)(
68
	Protocol__FlexranMessage *msg
69 70
);

71
/**********************************
72
 * FlexRAN protocol messages helper 
73 74 75
 * functions and generic handlers
 **********************************/

76
/* Helper functions for message (de)serialization */
77 78
int flexran_agent_serialize_message(Protocol__FlexranMessage *msg, void **buf, int *size);
int flexran_agent_deserialize_message(void *data, int size, Protocol__FlexranMessage **msg);
79

80 81
/* Serialize message and then destroy the input flexran msg. Should be called when protocol
   message is created dynamically */
82
void * flexran_agent_pack_message(Protocol__FlexranMessage *msg, 
83 84
			      uint32_t * size);

85
/* Calls destructor of the given message */
86
err_code_t flexran_agent_destroy_flexran_message(Protocol__FlexranMessage *msg);
87

88
/* Function to create the header for any FlexRAN protocol message */
89
int flexran_create_header(xid_t xid, Protocol__FlexType type, Protocol__FlexHeader **header);
90

91
/* Hello protocol message constructor and destructor */
92 93
int flexran_agent_hello(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg);
int flexran_agent_destroy_hello(Protocol__FlexranMessage *msg);
94

95
/* Echo request protocol message constructor and destructor */
96 97
int flexran_agent_echo_request(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg);
int flexran_agent_destroy_echo_request(Protocol__FlexranMessage *msg);
98

99
/* Echo reply protocol message constructor and destructor */
100 101
int flexran_agent_echo_reply(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg);
int flexran_agent_destroy_echo_reply(Protocol__FlexranMessage *msg);
102

103
/* eNodeB configuration reply message constructor and destructor */
104 105
int flexran_agent_enb_config_reply(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg);
int flexran_agent_destroy_enb_config_reply(Protocol__FlexranMessage *msg);
106

107
/* UE configuration reply message constructor and destructor */
108 109
int flexran_agent_ue_config_reply(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg);
int flexran_agent_destroy_ue_config_reply(Protocol__FlexranMessage *msg);
110

111
/* Logical channel reply configuration message constructor and destructor */
112 113
int flexran_agent_lc_config_reply(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg);
int flexran_agent_destroy_lc_config_reply(Protocol__FlexranMessage *msg);
114

115
/* eNodeB configuration request message constructor and destructor */
116 117
int flexran_agent_enb_config_request(mid_t mod_id, const void* params, Protocol__FlexranMessage **msg);
int flexran_agent_destroy_enb_config_request(Protocol__FlexranMessage *msg);
118

119 120
/* UE configuration request message constructor */
/* TODO: Need to define and implement destructor */
121
int flexran_agent_destroy_ue_config_request(Protocol__FlexranMessage *msg);
122

123 124
/* Logical channel configuration request message constructor */
/* TODO: Need to define and implement destructor */
125
int flexran_agent_destroy_lc_config_request(Protocol__FlexranMessage *msg);
126

127
/* UE state change message constructor and destructor */
128 129
int flexran_agent_ue_state_change(mid_t mod_id, uint32_t rnti, uint8_t state_change);
int flexran_agent_destroy_ue_state_change(Protocol__FlexranMessage *msg);
130

131
/* Control delegation message constructor and destructor */
132 133
int flexran_agent_control_delegation(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg);
int flexran_agent_destroy_control_delegation(Protocol__FlexranMessage *msg);
134

135
/* Policy reconfiguration message constructor and destructor */
136 137
int flexran_agent_reconfiguration(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg);
int flexran_agent_destroy_agent_reconfiguration(Protocol__FlexranMessage *msg);
138

139
/* FlexRAN protocol message dispatcher function */
140
Protocol__FlexranMessage* flexran_agent_handle_message (mid_t mod_id, 
141 142 143
						    uint8_t *data, 
						    uint32_t size);

144
/* Function to be used to send a message to a dispatcher once the appropriate event is triggered. */
145
Protocol__FlexranMessage *flexran_agent_handle_timed_task(void *args);
146

147 148 149 150 151 152 153



/****************************
 * get generic info from RAN
 ****************************/

154
void flexran_set_enb_vars(mid_t mod_id, ran_name_t ran);
155

156
int flexran_get_current_time_ms (mid_t mod_id, int subframe_flag);
157

158 159 160
/*Return the current frame number
 *Could be using implementation specific numbering of frames
 */
161
unsigned int flexran_get_current_frame(mid_t mod_id);
162 163

/*Return the current SFN (0-1023)*/ 
164
unsigned int flexran_get_current_system_frame_num(mid_t mod_id);
165

166
unsigned int flexran_get_current_subframe(mid_t mod_id);
167

168
/*Return the frame and subframe number in compact 16-bit format.
169
  Bits 0-3 subframe, rest for frame. Required by FlexRAN protocol*/
170
uint16_t flexran_get_sfn_sf (mid_t mod_id);
171

172 173 174
/* Return a future frame and subframe number that is ahead_of_time
   subframes later in compact 16-bit format. Bits 0-3 subframe,
   rest for frame */
175
uint16_t flexran_get_future_sfn_sf(mid_t mod_id, int ahead_of_time);
176

177
/* Return the number of attached UEs */
178
int flexran_get_num_ues(mid_t mod_id);
179

180
/* Get the rnti of a UE with id ue_id */
181
int flexran_get_ue_crnti (mid_t mod_id, mid_t ue_id);
182

183 184
/* Get the RLC buffer status report of a ue for a designated
   logical channel id */
185
int flexran_get_ue_bsr (mid_t mod_id, mid_t ue_id, lcid_t lcid);
186

187
/* Get power headroom of UE with id ue_id */
188
int flexran_get_ue_phr (mid_t mod_id, mid_t ue_id);
189

190
/* Get the UE wideband CQI */
191
int flexran_get_ue_wcqi (mid_t mod_id, mid_t ue_id);
192

193
/* Get the transmission queue size for a UE with a channel_id logical channel id */
194
int flexran_get_tx_queue_size(mid_t mod_id, mid_t ue_id, logical_chan_id_t channel_id);
195

196
/* Return timing advance MAC control element for a designated cell and UE */
197
int flexran_get_MAC_CE_bitmap_TA(mid_t mod_id, mid_t ue_id, int CC_id);
198

199
/* Get the number of active component carriers for a specific UE */
200
int flexran_get_active_CC(mid_t mod_id, mid_t ue_id);
201

202
/* Get the rank indicator for a designated cell and UE */
203
int flexran_get_current_RI(mid_t mod_id, mid_t ue_id, int CC_id);
204

205
/* See TS 36.213, section 10.1 */
206
int flexran_get_n1pucch_an(mid_t mod_id, int CC_id);
207

208
/* See TS 36.211, section 5.4 */
209
int flexran_get_nRB_CQI(mid_t mod_id, int CC_id);
210

211
/* See TS 36.211, section 5.4 */
212
int flexran_get_deltaPUCCH_Shift(mid_t mod_id, int CC_id);
213

214
/* See TS 36.211, section 5.7.1 */
215
int flexran_get_prach_ConfigIndex(mid_t mod_id, int CC_id);
216

217
/* See TS 36.211, section 5.7.1 */
218
int flexran_get_prach_FreqOffset(mid_t mod_id, int CC_id);
219

220
/* See TS 36.321 */
221
int flexran_get_maxHARQ_Msg3Tx(mid_t mod_id, int CC_id);
222

223
/* Get the length of the UL cyclic prefix */
224
int flexran_get_ul_cyclic_prefix_length(mid_t mod_id, int CC_id);
225

226
/* Get the length of the DL cyclic prefix */
227
int flexran_get_dl_cyclic_prefix_length(mid_t mod_id, int CC_id);
228

229
/* Get the physical cell id of a cell */
230
int flexran_get_cell_id(mid_t mod_id, int CC_id);
231

232
/* See TS 36.211, section 5.5.3.2 */
233
int flexran_get_srs_BandwidthConfig(mid_t mod_id, int CC_id);
234

235
/* See TS 36.211, table 5.5.3.3-1 and 2 */
236
int flexran_get_srs_SubframeConfig(mid_t mod_id, int CC_id);
237

238 239
/* Boolean value. See TS 36.211,
   section 5.5.3.2. TDD only */
240
int flexran_get_srs_MaxUpPts(mid_t mod_id, int CC_id);
241

242
/* Get number of DL resource blocks */
243
int flexran_get_N_RB_DL(mid_t mod_id, int CC_id);
244

245
/* Get number of UL resource blocks */
246
int flexran_get_N_RB_UL(mid_t mod_id, int CC_id);
247

248
/* Get DL/UL subframe assignment. TDD only */
249
int flexran_get_subframe_assignment(mid_t mod_id, int CC_id);
250

251
/* TDD only. See TS 36.211, table 4.2.1 */
252
int flexran_get_special_subframe_assignment(mid_t mod_id, int CC_id);
253

254
/* Get the duration of the random access response window in subframes */
255
int flexran_get_ra_ResponseWindowSize(mid_t mod_id, int CC_id);
256

257
/* Get timer used for random access */
258
int flexran_get_mac_ContentionResolutionTimer(mid_t mod_id, int CC_id);
259

260
/* Get type of duplex mode (FDD/TDD) */
261
int flexran_get_duplex_mode(mid_t mod_id, int CC_id);
262

263
/* Get the SI window length */
264
long flexran_get_si_window_length(mid_t mod_id, int CC_id);
265

266
/* Get the number of PDCCH symbols configured for the cell */
267
int flexran_get_num_pdcch_symb(mid_t mod_id, int CC_id);
268

269
/* See TS 36.213, sec 5.1.1.1 */
270
int flexran_get_tpc(mid_t mod_id, mid_t ue_id);
MKassem's avatar
MKassem committed
271

272 273 274
/* Get the first available HARQ process for a specific cell and UE during 
   a designated frame and subframe. Returns 0 for success. The id and the 
   status of the HARQ process are stored in id and status respectively */
275 276
int flexran_get_harq(const mid_t mod_id, const uint8_t CC_id, const mid_t ue_id,
		     const int frame, const uint8_t subframe, int *id, int *status);
277

278
/* Reported values for uplink power control */
279
int flexran_get_p0_pucch_dbm(mid_t mod_id, mid_t ue_id, int CC_id);
280

281
int flexran_get_p0_nominal_pucch(mid_t mod_id, int CC_id);
282

283 284 285 286 287 288
/*
 * ************************************
 * Get Messages for UE Configuration Reply
 * ************************************
 */

289 290 291
/* Get timer in subframes. Controls the synchronization
   status of the UE, not the actual timing 
   advance procedure. See TS 36.321 */
292
int flexran_get_time_alignment_timer(mid_t mod_id, mid_t ue_id);
293

294
/* Get measurement gap configuration. See TS 36.133 */
295
int flexran_get_meas_gap_config(mid_t mod_id, mid_t ue_id);
296

297
/* Get measurement gap configuration offset if applicable */
298
int flexran_get_meas_gap_config_offset(mid_t mod_id, mid_t ue_id);
299

300 301
/* DL aggregated bit-rate of non-gbr bearer
   per UE. See TS 36.413 */
302
int flexran_get_ue_aggregated_max_bitrate_dl (mid_t mod_id, mid_t ue_id);
303

304 305
/* UL aggregated bit-rate of non-gbr bearer
   per UE. See TS 36.413 */
306
int flexran_get_ue_aggregated_max_bitrate_ul (mid_t mod_id, mid_t ue_id);
307

308 309
/* Only half-duplex support. FDD
   operation. Boolean value */
310
int flexran_get_half_duplex(mid_t ue_id);
311

312 313
/* Support of intra-subframe hopping.
   Boolean value */
314
int flexran_get_intra_sf_hopping(mid_t ue_id);
315

316 317
/* UE support for type 2 hopping with
   n_sb>1 */
318
int flexran_get_type2_sb_1(mid_t ue_id);
319

320
/* Get the UE category */
321
int flexran_get_ue_category(mid_t ue_id);
322

323 324
/* UE support for resource allocation
   type 1 */
325
int flexran_get_res_alloc_type1(mid_t ue_id);
326

327
/* Get UE transmission mode */
328
int flexran_get_ue_transmission_mode(mid_t mod_id, mid_t ue_id);
329

330
/* Boolean value. See TS 36.321 */
331
int flexran_get_tti_bundling(mid_t mod_id, mid_t ue_id);
332

333 334
/* The max HARQ retransmission for UL.
   See TS 36.321 */
335
int flexran_get_maxHARQ_TX(mid_t mod_id, mid_t ue_id);
336

337
/* See TS 36.213 */
338
int flexran_get_beta_offset_ack_index(mid_t mod_id, mid_t ue_id);
339

340
/* See TS 36.213 */
341
int flexran_get_beta_offset_ri_index(mid_t mod_id, mid_t ue_id);
342

343
/* See TS 36.213 */
344
int flexran_get_beta_offset_cqi_index(mid_t mod_id, mid_t ue_id);
345

346
/* Boolean. See TS36.213, Section 10.1 */
347
int flexran_get_simultaneous_ack_nack_cqi(mid_t mod_id, mid_t ue_id);
348

349
/* Boolean. See TS 36.213, Section 8.2 */
350
int flexran_get_ack_nack_simultaneous_trans(mid_t mod_id,mid_t ue_id);
351

352
/* Get aperiodic CQI report mode */
353
int flexran_get_aperiodic_cqi_rep_mode(mid_t mod_id,mid_t ue_id);
354

355
/* Get ACK/NACK feedback mode. TDD only */
356
int flexran_get_tdd_ack_nack_feedback(mid_t mod_id, mid_t ue_id);
357

358
/* See TS36.213, section 10.1 */
359
int flexran_get_ack_nack_repetition_factor(mid_t mod_id, mid_t ue_id);
360

361
/* Boolean. Extended buffer status report size */
362
int flexran_get_extended_bsr_size(mid_t mod_id, mid_t ue_id);
363

364
/* Get number of UE transmission antennas */
365
int flexran_get_ue_transmission_antenna(mid_t mod_id, mid_t ue_id);
366

367
/* Get logical channel group of a channel with id lc_id */
368
int flexran_get_lcg(mid_t ue_id, mid_t lc_id);
369

370
/* Get direction of logical channel with id lc_id */
371
int flexran_get_direction(mid_t ue_id, mid_t lc_id);
372

373 374 375 376 377 378 379 380 381 382 383 384
/*******************
 * timer primitves
 *******************/

#define TIMER_NULL                 -1 
#define TIMER_TYPE_INVALIDE        -2
#define	TIMER_SETUP_FAILED         -3
#define	TIMER_REMOVED_FAILED       -4
#define	TIMER_ELEMENT_NOT_FOUND    -5


/* Type of the callback executed when the timer expired */
385
typedef Protocol__FlexranMessage *(*flexran_agent_timer_callback_t)(void*);
386 387 388

typedef enum {
  /* oneshot timer:  */
389
  FLEXRAN_AGENT_TIMER_TYPE_ONESHOT = 0x0,
390 391

  /* periodic timer  */
392
  FLEXRAN_AGENT_TIMER_TYPE_PERIODIC = 0x1,
393 394

  /* Inactive state: initial state for any timer. */
395
  FLEXRAN_AGENT_TIMER_TYPE_EVENT_DRIVEN = 0x2,
396 397
  
  /* Max number of states available */
398 399
  FLEXRAN_AGENT_TIMER_TYPE_MAX,
} flexran_agent_timer_type_t;
400 401 402

typedef enum {
  /* Inactive state: initial state for any timer. */
403
  FLEXRAN_AGENT_TIMER_STATE_INACTIVE = 0x0,
404 405

  /* Inactive state: initial state for any timer. */
406
  FLEXRAN_AGENT_TIMER_STATE_ACTIVE = 0x1,
407 408

  /* Inactive state: initial state for any timer. */
409
  FLEXRAN_AGENT_TIMER_STATE_STOPPED = 0x2,
410 411
  
  /* Max number of states available */
412 413
  FLEXRAN_AGENT_TIMER_STATE_MAX,
} flexran_agent_timer_state_t;
414

415
typedef struct flexran_agent_timer_args_s{
416
  mid_t            mod_id;
417
  Protocol__FlexranMessage *msg;
418
} flexran_agent_timer_args_t;
419 420 421



422 423
typedef struct flexran_agent_timer_element_s{
  RB_ENTRY(flexran_agent_timer_element_s) entry;
424 425 426 427

  agent_id_t             agent_id;
  instance_t       instance;
  
428 429
  flexran_agent_timer_type_t  type;
  flexran_agent_timer_state_t state;
430 431 432 433 434

  uint32_t interval_sec;
  uint32_t interval_usec;

  long timer_id;  /* Timer id returned by the timer API*/
435 436
  xid_t xid; /*The id of the task as received by the controller
	       message*/
437
  
438 439
  flexran_agent_timer_callback_t cb;
  flexran_agent_timer_args_t *timer_args;
440
  
441
} flexran_agent_timer_element_t;
442

443 444 445
typedef struct flexran_agent_timer_instance_s{
  RB_HEAD(flexran_agent_map, flexran_agent_timer_element_s) flexran_agent_head;
}flexran_agent_timer_instance_t;
446

447

448
err_code_t flexran_agent_init_timer(void);
449

450 451
/* Create a timer for some agent related event with id xid. Will store the id 
   of the generated timer in timer_id */
452
err_code_t flexran_agent_create_timer(uint32_t interval_sec,
453 454 455 456
				  uint32_t interval_usec,
				  agent_id_t     agent_id,
				  instance_t     instance,
				  uint32_t timer_type,
457
				  xid_t xid,
458
				  flexran_agent_timer_callback_t cb,
459 460 461
				  void*    timer_args,
				  long *timer_id);

462
/* Destroy all existing timers */
463
err_code_t flexran_agent_destroy_timers(void);
464 465

/* Destroy the timer with the given timer_id */
466
err_code_t flexran_agent_destroy_timer(long timer_id);
467 468

/* Destroy the timer for task with id xid */
469
err_code_t flexran_agent_destroy_timer_by_task_id(xid_t xid);
470

471
/* Stop a timer */
472
err_code_t flexran_agent_stop_timer(long timer_id);
473

474
/* Restart the given timer */
475
err_code_t flexran_agent_restart_timer(long *timer_id);
476

477
/* Find the timer with the given timer_id */
478
struct flexran_agent_timer_element_s * get_timer_entry(long timer_id);
479

480
/* Obtain the protocol message stored in the given expired timer */
481
Protocol__FlexranMessage * flexran_agent_process_timeout(long timer_id, void* timer_args);
482

483
/* Comparator function comparing two timers. Decides the ordering of the timers */
484
int flexran_agent_compare_timer(struct flexran_agent_timer_element_s *a, struct flexran_agent_timer_element_s *b);
485

486
/*Specify a delay in nanoseconds to timespec and sleep until then*/
487
void flexran_agent_sleep_until(struct timespec *ts, int delay);
488

489
/* RB_PROTOTYPE is for .h files */
490
RB_PROTOTYPE(flexran_agent_map, flexran_agent_timer_element_s, entry, flexran_agent_compare_timer);
491 492


493
#endif