flexran_agent_common.h 17.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
 * the OAI Public License, Version 1.0  (the "License"); you may not use this file
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */ 
21

22
/*! \file flexran_agent_common.h
23
 * \brief common message primitves and utilities 
24
 * \author Xenofon Foukas, Mohamed Kassem and Navid Nikaein
25 26 27 28 29 30
 * \date 2016
 * \version 0.1
 */



31 32
#ifndef FLEXRAN_AGENT_COMMON_H_
#define FLEXRAN_AGENT_COMMON_H_
33

34
#include <time.h>
35 36

#include "header.pb-c.h"
37
#include "flexran.pb-c.h"
38 39 40
#include "stats_messages.pb-c.h"
#include "stats_common.pb-c.h"

41
#include "flexran_agent_defs.h"
MKassem's avatar
MKassem committed
42
#include "enb_config.h"
43 44 45 46 47 48 49 50

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

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

51
#define FLEXRAN_VERSION 0
52

53
typedef int (*flexran_agent_message_decoded_callback)(
54
	mid_t mod_id,
55
       	const void *params,
56
	Protocol__FlexranMessage **msg
57 58
);

59
typedef int (*flexran_agent_message_destruction_callback)(
60
	Protocol__FlexranMessage *msg
61 62
);

63
/**********************************
64
 * FlexRAN protocol messages helper 
65 66 67
 * functions and generic handlers
 **********************************/

68
/* Helper functions for message (de)serialization */
69 70
int flexran_agent_serialize_message(Protocol__FlexranMessage *msg, void **buf, int *size);
int flexran_agent_deserialize_message(void *data, int size, Protocol__FlexranMessage **msg);
71

72 73
/* Serialize message and then destroy the input flexran msg. Should be called when protocol
   message is created dynamically */
74
void * flexran_agent_pack_message(Protocol__FlexranMessage *msg, 
75 76
			      uint32_t * size);

77
/* Calls destructor of the given message */
78
err_code_t flexran_agent_destroy_flexran_message(Protocol__FlexranMessage *msg);
79

80
/* Function to create the header for any FlexRAN protocol message */
81
int flexran_create_header(xid_t xid, Protocol__FlexType type, Protocol__FlexHeader **header);
82

83
/* Hello protocol message constructor and destructor */
84 85
int flexran_agent_hello(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg);
int flexran_agent_destroy_hello(Protocol__FlexranMessage *msg);
86

87
/* Echo request protocol message constructor and destructor */
88 89
int flexran_agent_echo_request(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg);
int flexran_agent_destroy_echo_request(Protocol__FlexranMessage *msg);
90

91
/* Echo reply protocol message constructor and destructor */
92 93
int flexran_agent_echo_reply(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg);
int flexran_agent_destroy_echo_reply(Protocol__FlexranMessage *msg);
94

95
/* eNodeB configuration reply message constructor and destructor */
96 97
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);
98

99
/* UE configuration reply message constructor and destructor */
100 101
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);
102

103
/* Logical channel reply configuration message constructor and destructor */
104 105
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);
106

107
/* eNodeB configuration request message constructor and destructor */
108 109
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);
110

111 112
/* UE configuration request message constructor */
/* TODO: Need to define and implement destructor */
113
int flexran_agent_destroy_ue_config_request(Protocol__FlexranMessage *msg);
114

115 116
/* Logical channel configuration request message constructor */
/* TODO: Need to define and implement destructor */
117
int flexran_agent_destroy_lc_config_request(Protocol__FlexranMessage *msg);
118

119
/* UE state change message constructor and destructor */
120 121
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);
122

123
/* Control delegation message constructor and destructor */
124 125
int flexran_agent_control_delegation(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg);
int flexran_agent_destroy_control_delegation(Protocol__FlexranMessage *msg);
126

127
/* Policy reconfiguration message constructor and destructor */
128 129
int flexran_agent_reconfiguration(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg);
int flexran_agent_destroy_agent_reconfiguration(Protocol__FlexranMessage *msg);
130

131
/* FlexRAN protocol message dispatcher function */
132
Protocol__FlexranMessage* flexran_agent_handle_message (mid_t mod_id, 
133 134 135
						    uint8_t *data, 
						    uint32_t size);

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

139 140 141 142 143 144 145



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

146
void flexran_set_enb_vars(mid_t mod_id, ran_name_t ran);
147

148
int flexran_get_current_time_ms (mid_t mod_id, int subframe_flag);
149

150 151 152
/*Return the current frame number
 *Could be using implementation specific numbering of frames
 */
153
unsigned int flexran_get_current_frame(mid_t mod_id);
154 155

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

158
unsigned int flexran_get_current_subframe(mid_t mod_id);
159

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

164 165 166
/* 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 */
167
uint16_t flexran_get_future_sfn_sf(mid_t mod_id, int ahead_of_time);
168

169
/* Return the number of attached UEs */
170
int flexran_get_num_ues(mid_t mod_id);
171

172
/* Get the rnti of a UE with id ue_id */
173
int flexran_get_ue_crnti (mid_t mod_id, mid_t ue_id);
174

175 176
/* Get the RLC buffer status report of a ue for a designated
   logical channel id */
177
int flexran_get_ue_bsr (mid_t mod_id, mid_t ue_id, lcid_t lcid);
178

179
/* Get power headroom of UE with id ue_id */
180
int flexran_get_ue_phr (mid_t mod_id, mid_t ue_id);
181

182
/* Get the UE wideband CQI */
183
int flexran_get_ue_wcqi (mid_t mod_id, mid_t ue_id);
184

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

188 189 190
/* Update the timing advance status (find out whether a timing advance command is required) */
int flexran_update_TA(mid_t mod_id, mid_t ue_id, int CC_id);

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

194
/* Get the number of active component carriers for a specific UE */
195
int flexran_get_active_CC(mid_t mod_id, mid_t ue_id);
196

197
/* Get the rank indicator for a designated cell and UE */
198
int flexran_get_current_RI(mid_t mod_id, mid_t ue_id, int CC_id);
199

200
/* See TS 36.213, section 10.1 */
201
int flexran_get_n1pucch_an(mid_t mod_id, int CC_id);
MKassem's avatar
MKassem committed
202

203
/* See TS 36.211, section 5.4 */
204
int flexran_get_nRB_CQI(mid_t mod_id, int CC_id);
MKassem's avatar
MKassem committed
205

206
/* See TS 36.211, section 5.4 */
207
int flexran_get_deltaPUCCH_Shift(mid_t mod_id, int CC_id);
MKassem's avatar
MKassem committed
208

209
/* See TS 36.211, section 5.7.1 */
210
int flexran_get_prach_ConfigIndex(mid_t mod_id, int CC_id);
MKassem's avatar
MKassem committed
211

212
/* See TS 36.211, section 5.7.1 */
213
int flexran_get_prach_FreqOffset(mid_t mod_id, int CC_id);
MKassem's avatar
MKassem committed
214

215
/* See TS 36.321 */
216
int flexran_get_maxHARQ_Msg3Tx(mid_t mod_id, int CC_id);
MKassem's avatar
MKassem committed
217

218
/* Get the length of the UL cyclic prefix */
219
int flexran_get_ul_cyclic_prefix_length(mid_t mod_id, int CC_id);
MKassem's avatar
MKassem committed
220

221
/* Get the length of the DL cyclic prefix */
222
int flexran_get_dl_cyclic_prefix_length(mid_t mod_id, int CC_id);
MKassem's avatar
MKassem committed
223

224
/* Get the physical cell id of a cell */
225
int flexran_get_cell_id(mid_t mod_id, int CC_id);
MKassem's avatar
MKassem committed
226

227
/* See TS 36.211, section 5.5.3.2 */
228
int flexran_get_srs_BandwidthConfig(mid_t mod_id, int CC_id);
MKassem's avatar
MKassem committed
229

230
/* See TS 36.211, table 5.5.3.3-1 and 2 */
231
int flexran_get_srs_SubframeConfig(mid_t mod_id, int CC_id);
MKassem's avatar
MKassem committed
232

233 234
/* Boolean value. See TS 36.211,
   section 5.5.3.2. TDD only */
235
int flexran_get_srs_MaxUpPts(mid_t mod_id, int CC_id);
MKassem's avatar
MKassem committed
236

237
/* Get number of DL resource blocks */
238
int flexran_get_N_RB_DL(mid_t mod_id, int CC_id);
MKassem's avatar
MKassem committed
239

240
/* Get number of UL resource blocks */
241
int flexran_get_N_RB_UL(mid_t mod_id, int CC_id);
MKassem's avatar
MKassem committed
242

243 244 245
/* Get number of resource block groups */
int flexran_get_N_RBG(mid_t mod_id, int CC_id);

246
/* Get DL/UL subframe assignment. TDD only */
247
int flexran_get_subframe_assignment(mid_t mod_id, int CC_id);
MKassem's avatar
MKassem committed
248

249
/* TDD only. See TS 36.211, table 4.2.1 */
250
int flexran_get_special_subframe_assignment(mid_t mod_id, int CC_id);
MKassem's avatar
MKassem committed
251

252
/* Get the duration of the random access response window in subframes */
253
int flexran_get_ra_ResponseWindowSize(mid_t mod_id, int CC_id);
MKassem's avatar
MKassem committed
254

255
/* Get timer used for random access */
256
int flexran_get_mac_ContentionResolutionTimer(mid_t mod_id, int CC_id);
MKassem's avatar
MKassem committed
257

258
/* Get type of duplex mode (FDD/TDD) */
259
int flexran_get_duplex_mode(mid_t mod_id, int CC_id);
MKassem's avatar
MKassem committed
260

261
/* Get the SI window length */
262
long flexran_get_si_window_length(mid_t mod_id, int CC_id);
MKassem's avatar
MKassem committed
263

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

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

270 271 272
/* 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 */
273
int flexran_get_harq(const mid_t mod_id, const uint8_t CC_id, const mid_t ue_id,
274
		     const int frame, const uint8_t subframe, int *id, int *round);
275

276
/* Uplink power control management*/
277
int flexran_get_p0_pucch_dbm(mid_t mod_id, mid_t ue_id, int CC_id);
278

279
int flexran_get_p0_nominal_pucch(mid_t mod_id, int CC_id);
280

281 282 283 284 285
int flexran_get_p0_pucch_status(mid_t mod_id, mid_t ue_id, int CC_id);

int flexran_update_p0_pucch(mid_t mod_id, mid_t ue_id, int CC_id);


286 287 288 289 290 291
/*
 * ************************************
 * Get Messages for UE Configuration Reply
 * ************************************
 */

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

297
/* Get measurement gap configuration. See TS 36.133 */
298
int flexran_get_meas_gap_config(mid_t mod_id, mid_t ue_id);
299

300
/* Get measurement gap configuration offset if applicable */
301
int flexran_get_meas_gap_config_offset(mid_t mod_id, mid_t ue_id);
302

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

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

311 312
/* Only half-duplex support. FDD
   operation. Boolean value */
313
int flexran_get_half_duplex(mid_t ue_id);
314

315 316
/* Support of intra-subframe hopping.
   Boolean value */
317
int flexran_get_intra_sf_hopping(mid_t ue_id);
318

319 320
/* UE support for type 2 hopping with
   n_sb>1 */
321
int flexran_get_type2_sb_1(mid_t ue_id);
322

323
/* Get the UE category */
324
int flexran_get_ue_category(mid_t ue_id);
325

326 327
/* UE support for resource allocation
   type 1 */
328
int flexran_get_res_alloc_type1(mid_t ue_id);
329

330
/* Get UE transmission mode */
331
int flexran_get_ue_transmission_mode(mid_t mod_id, mid_t ue_id);
332

333
/* Boolean value. See TS 36.321 */
334
int flexran_get_tti_bundling(mid_t mod_id, mid_t ue_id);
335

336 337
/* The max HARQ retransmission for UL.
   See TS 36.321 */
338
int flexran_get_maxHARQ_TX(mid_t mod_id, mid_t ue_id);
339

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

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

346
/* See TS 36.213 */
347
int flexran_get_beta_offset_cqi_index(mid_t mod_id, mid_t ue_id);
348

349
/* Boolean. See TS36.213, Section 10.1 */
350
int flexran_get_simultaneous_ack_nack_cqi(mid_t mod_id, mid_t ue_id);
351

352
/* Boolean. See TS 36.213, Section 8.2 */
353
int flexran_get_ack_nack_simultaneous_trans(mid_t mod_id,mid_t ue_id);
354

355
/* Get aperiodic CQI report mode */
356
int flexran_get_aperiodic_cqi_rep_mode(mid_t mod_id,mid_t ue_id);
357

358
/* Get ACK/NACK feedback mode. TDD only */
359
int flexran_get_tdd_ack_nack_feedback(mid_t mod_id, mid_t ue_id);
360

361
/* See TS36.213, section 10.1 */
362
int flexran_get_ack_nack_repetition_factor(mid_t mod_id, mid_t ue_id);
363

364
/* Boolean. Extended buffer status report size */
365
int flexran_get_extended_bsr_size(mid_t mod_id, mid_t ue_id);
366

367
/* Get number of UE transmission antennas */
368
int flexran_get_ue_transmission_antenna(mid_t mod_id, mid_t ue_id);
369

370
/* Get logical channel group of a channel with id lc_id */
371
int flexran_get_lcg(mid_t ue_id, mid_t lc_id);
372

373
/* Get direction of logical channel with id lc_id */
374
int flexran_get_direction(mid_t ue_id, mid_t lc_id);
375

376 377 378 379 380 381 382 383 384 385 386 387
/*******************
 * 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 */
388
typedef Protocol__FlexranMessage *(*flexran_agent_timer_callback_t)(void*);
389 390 391

typedef enum {
  /* oneshot timer:  */
392
  FLEXRAN_AGENT_TIMER_TYPE_ONESHOT = 0x0,
393 394

  /* periodic timer  */
395
  FLEXRAN_AGENT_TIMER_TYPE_PERIODIC = 0x1,
396 397

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

typedef enum {
  /* Inactive state: initial state for any timer. */
406
  FLEXRAN_AGENT_TIMER_STATE_INACTIVE = 0x0,
407 408

  /* Inactive state: initial state for any timer. */
409
  FLEXRAN_AGENT_TIMER_STATE_ACTIVE = 0x1,
410 411

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

418
typedef struct flexran_agent_timer_args_s{
419
  mid_t            mod_id;
420
  Protocol__FlexranMessage *msg;
421
} flexran_agent_timer_args_t;
422 423 424



425 426
typedef struct flexran_agent_timer_element_s{
  RB_ENTRY(flexran_agent_timer_element_s) entry;
427 428 429 430

  agent_id_t             agent_id;
  instance_t       instance;
  
431 432
  flexran_agent_timer_type_t  type;
  flexran_agent_timer_state_t state;
433 434 435 436 437

  uint32_t interval_sec;
  uint32_t interval_usec;

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

446 447 448
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;
449

450

451
err_code_t flexran_agent_init_timer(void);
452

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

465
/* Destroy all existing timers */
466
err_code_t flexran_agent_destroy_timers(void);
467 468

/* Destroy the timer with the given timer_id */
469
err_code_t flexran_agent_destroy_timer(long timer_id);
470 471

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

474
/* Stop a timer */
475
err_code_t flexran_agent_stop_timer(long timer_id);
476

477
/* Restart the given timer */
478
err_code_t flexran_agent_restart_timer(long *timer_id);
479

480
/* Find the timer with the given timer_id */
481
struct flexran_agent_timer_element_s * get_timer_entry(long timer_id);
482

483
/* Obtain the protocol message stored in the given expired timer */
484
Protocol__FlexranMessage * flexran_agent_process_timeout(long timer_id, void* timer_args);
485

486
/* Comparator function comparing two timers. Decides the ordering of the timers */
487
int flexran_agent_compare_timer(struct flexran_agent_timer_element_s *a, struct flexran_agent_timer_element_s *b);
488

489
/*Specify a delay in nanoseconds to timespec and sleep until then*/
490
void flexran_agent_sleep_until(struct timespec *ts, int delay);
491

492
/* RB_PROTOTYPE is for .h files */
493
RB_PROTOTYPE(flexran_agent_map, flexran_agent_timer_element_s, entry, flexran_agent_compare_timer);
494 495


496
#endif