enb_agent_common.h 9.13 KB
Newer Older
nikaeinn's avatar
nikaeinn committed
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 31 32
/*! \file enb_agent_common.h
 * \brief common message primitves and utilities 
 * \author Navid Nikaein and Xenofon Foukas
nikaeinn's avatar
nikaeinn committed
33 34 35 36 37 38 39 40 41
 * \date 2016
 * \version 0.1
 */



#ifndef ENB_AGENT_COMMON_H_
#define ENB_AGENT_COMMON_H_

42
#include <time.h>
nikaeinn's avatar
nikaeinn committed
43 44 45 46 47 48

#include "header.pb-c.h"
#include "progran.pb-c.h"
#include "stats_messages.pb-c.h"
#include "stats_common.pb-c.h"

49
# include "enb_agent_defs.h"
MKassem's avatar
MKassem committed
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"

nikaeinn's avatar
nikaeinn committed
59 60 61
#define PROGRAN_VERSION 0

typedef int (*enb_agent_message_decoded_callback)(
62
	mid_t mod_id,
63
       	const void *params,
nikaeinn's avatar
nikaeinn committed
64
	Protocol__ProgranMessage **msg
65 66 67 68
);

typedef int (*enb_agent_message_destruction_callback)(
	Protocol__ProgranMessage *msg
nikaeinn's avatar
nikaeinn committed
69 70
);

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

nikaeinn's avatar
nikaeinn committed
76 77 78
int enb_agent_serialize_message(Protocol__ProgranMessage *msg, void **buf, int *size);
int enb_agent_deserialize_message(void *data, int size, Protocol__ProgranMessage **msg);

79 80 81
void * enb_agent_pack_message(Protocol__ProgranMessage *msg, 
			      uint32_t * size);

82 83
err_code_t enb_agent_destroy_progran_message(Protocol__ProgranMessage *msg);

84
int prp_create_header(xid_t xid, Protocol__PrpType type, Protocol__PrpHeader **header);
nikaeinn's avatar
nikaeinn committed
85

86
int enb_agent_hello(mid_t mod_id, const void *params, Protocol__ProgranMessage **msg);
nikaeinn's avatar
nikaeinn committed
87 88
int enb_agent_destroy_hello(Protocol__ProgranMessage *msg);

89
int enb_agent_echo_request(mid_t mod_id, const void *params, Protocol__ProgranMessage **msg);
nikaeinn's avatar
nikaeinn committed
90 91
int enb_agent_destroy_echo_request(Protocol__ProgranMessage *msg);

92
int enb_agent_echo_reply(mid_t mod_id, const void *params, Protocol__ProgranMessage **msg);
nikaeinn's avatar
nikaeinn committed
93 94
int enb_agent_destroy_echo_reply(Protocol__ProgranMessage *msg);

95 96 97 98 99 100 101 102 103
int enb_agent_enb_config_reply(mid_t mod_id, const void *params, Protocol__ProgranMessage **msg);
int enb_agent_destroy_enb_config_reply(Protocol__ProgranMessage *msg);

int enb_agent_ue_config_reply(mid_t mod_id, const void *params, Protocol__ProgranMessage **msg);
int enb_agent_destroy_ue_config_reply(Protocol__ProgranMessage *msg);

int enb_agent_lc_config_reply(mid_t mod_id, const void *params, Protocol__ProgranMessage **msg);
int enb_agent_destroy_lc_config_reply(Protocol__ProgranMessage *msg);

MKassem's avatar
MKassem committed
104
int enb_agent_enb_config_request(mid_t mod_id, const void* params, Protocol__ProgranMessage **msg);
105 106 107 108 109 110
int enb_agent_destroy_enb_config_request(Protocol__ProgranMessage *msg);

int enb_agent_destroy_ue_config_request(Protocol__ProgranMessage *msg);

int enb_agent_destroy_lc_config_request(Protocol__ProgranMessage *msg);

nikaeinn's avatar
nikaeinn committed
111

112
Protocol__ProgranMessage* enb_agent_handle_message (mid_t mod_id, 
nikaeinn's avatar
nikaeinn committed
113 114 115
						    uint8_t *data, 
						    uint32_t size);

116 117
Protocol__ProgranMessage *enb_agent_handle_timed_task(void *args);

118 119 120 121 122 123 124 125 126 127 128



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

void set_enb_vars(mid_t mod_id, ran_name_t ran);

int get_current_time_ms (mid_t mod_id, int subframe_flag);

129 130 131 132 133 134 135
/*Return the current frame number
 *Could be using implementation specific numbering of frames
 */
unsigned int get_current_frame(mid_t mod_id);

/*Return the current SFN (0-1023)*/ 
unsigned int get_current_system_frame_num(mid_t mod_id);
136

137
unsigned int get_current_subframe(mid_t mod_id);
138

139
/*Return the frame and subframe number in compact 16-bit format.
140
  Bits 0-3 subframe, rest for frame. Required by progRAN protocol*/
141 142
uint16_t get_sfn_sf (mid_t mod_id);

143 144 145 146 147 148 149 150 151 152
int get_num_ues(mid_t mod_id);

int get_ue_crnti (mid_t mod_id, mid_t ue_id);

int get_ue_bsr (mid_t mod_id, mid_t ue_id, lcid_t lcid);

int get_ue_phr (mid_t mod_id, mid_t ue_id);

int get_ue_wcqi (mid_t mod_id, mid_t ue_id);

153
int get_tx_queue_size(mid_t mod_id, mid_t ue_id, logical_chan_id_t channel_id);
154

155 156 157 158 159
int get_MAC_CE_bitmap_TA(mid_t mod_id, mid_t ue_id);

int get_active_CC(mid_t mod_id, mid_t ue_id);

int get_current_RI(mid_t mod_id, mid_t ue_id, int CC_id);
160

MKassem's avatar
MKassem committed
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
int get_n1pucch_an(mid_t mod_id, int CC_id);

int get_nRB_CQI(mid_t mod_id, int CC_id);

int get_deltaPUCCH_Shift(mid_t mod_id, int CC_id);

int get_prach_ConfigIndex(mid_t mod_id, int CC_id);

int get_prach_FreqOffset(mid_t mod_id, int CC_id);

int get_maxHARQ_Msg3Tx(mid_t mod_id, int CC_id);

int get_ul_cyclic_prefix_length(mid_t mod_id, int CC_id);

int get_dl_cyclic_prefix_length(mid_t mod_id, int CC_id);

int get_cell_id(mid_t mod_id, int CC_id);

int get_srs_BandwidthConfig(mid_t mod_id, int CC_id);

int get_srs_SubframeConfig(mid_t mod_id, int CC_id);

int get_srs_MaxUpPts(mid_t mod_id, int CC_id);

int get_N_RB_DL(mid_t mod_id, int CC_id);

int get_N_RB_UL(mid_t mod_id, int CC_id);

int get_subframe_assignment(mid_t mod_id, int CC_id);

int get_special_subframe_assignment(mid_t mod_id, int CC_id);

int get_ra_ResponseWindowSize(mid_t mod_id, int CC_id);

int get_mac_ContentionResolutionTimer(mid_t mod_id, int CC_id);

int get_duplex_mode(mid_t mod_id, int CC_id);

long get_si_window_length(mid_t mod_id, int CC_id);

int get_num_pdcch_symb(mid_t mod_id, int CC_id);
202 203 204 205 206 207 208 209 210 211 212 213 214 215


/*******************
 * 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 */
216
typedef Protocol__ProgranMessage *(*enb_agent_timer_callback_t)(void*);
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247

typedef enum {
  /* oneshot timer:  */
  ENB_AGENT_TIMER_TYPE_ONESHOT = 0x0,

  /* periodic timer  */
  ENB_AGENT_TIMER_TYPE_PERIODIC = 0x1,

  /* Inactive state: initial state for any timer. */
  ENB_AGENT_TIMER_TYPE_EVENT_DRIVEN = 0x2,
  
  /* Max number of states available */
  ENB_AGENT_TIMER_TYPE_MAX,
} eNB_agent_timer_type_t;

typedef enum {
  /* Inactive state: initial state for any timer. */
  ENB_AGENT_TIMER_STATE_INACTIVE = 0x0,

  /* Inactive state: initial state for any timer. */
  ENB_AGENT_TIMER_STATE_ACTIVE = 0x1,

  /* Inactive state: initial state for any timer. */
  ENB_AGENT_TIMER_STATE_STOPPED = 0x2,
  
  /* Max number of states available */
  ENB_AGENT_TIMER_STATE_MAX,
} eNB_agent_timer_state_t;

typedef struct enb_agent_timer_args_s{
  mid_t            mod_id;
248
  Protocol__ProgranMessage *msg;
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
} enb_agent_timer_args_t;



typedef struct enb_agent_timer_element_s{
  RB_ENTRY(enb_agent_timer_element_s) entry;

  agent_id_t             agent_id;
  instance_t       instance;
  
  eNB_agent_timer_type_t  type;
  eNB_agent_timer_state_t state;

  uint32_t interval_sec;
  uint32_t interval_usec;

  long timer_id;  /* Timer id returned by the timer API*/
266 267
  xid_t xid; /*The id of the task as received by the controller
	       message*/
268 269
  
  enb_agent_timer_callback_t cb;
270
  enb_agent_timer_args_t *timer_args;
271 272 273
  
} enb_agent_timer_element_t;

274 275 276
typedef struct enb_agent_timer_instance_s{
  RB_HEAD(enb_agent_map, enb_agent_timer_element_s) enb_agent_head;
}enb_agent_timer_instance_t;
277 278 279 280 281 282 283 284

err_code_t enb_agent_init_timer(void);

err_code_t enb_agent_create_timer(uint32_t interval_sec,
				  uint32_t interval_usec,
				  agent_id_t     agent_id,
				  instance_t     instance,
				  uint32_t timer_type,
285
				  xid_t xid,
286 287 288 289 290 291
				  enb_agent_timer_callback_t cb,
				  void*    timer_args,
				  long *timer_id);

err_code_t enb_agent_destroy_timers(void);
err_code_t enb_agent_destroy_timer(long timer_id);
292
err_code_t enb_agent_destroy_timer_by_task_id(xid_t xid);
293 294 295 296 297 298 299

err_code_t enb_agent_stop_timer(long timer_id);

err_code_t enb_agent_restart_timer(long *timer_id);

struct enb_agent_timer_element_s * get_timer_entry(long timer_id);

300
Protocol__ProgranMessage * enb_agent_process_timeout(long timer_id, void* timer_args);
301

302
int enb_agent_compare_timer(struct enb_agent_timer_element_s *a, struct enb_agent_timer_element_s *b);
303

304 305 306
/*Specify a delay in nanoseconds to timespec and sleep until then*/
void enb_agent_sleep_until(struct timespec *ts, int delay);

307 308 309 310
/* RB_PROTOTYPE is for .h files */
RB_PROTOTYPE(enb_agent_map, enb_agent_timer_element_s, entry, enb_agent_compare_timer);


nikaeinn's avatar
nikaeinn committed
311 312 313 314 315 316 317 318
#endif