flexran_agent_handler.c 7.16 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
/*! \file flexran_agent_handler.c
 * \brief FlexRAN agent tx and rx message handler 
32
 * \author Xenofon Foukas and Navid Nikaein
nikaeinn's avatar
nikaeinn committed
33 34 35 36 37
 * \date 2016
 * \version 0.1
 */


38 39
#include "flexran_agent_common.h"
#include "flexran_agent_mac.h"
nikaeinn's avatar
nikaeinn committed
40 41 42 43
#include "log.h"

#include "assertions.h"

44 45 46
flexran_agent_message_decoded_callback agent_messages_callback[][3] = {
  {flexran_agent_hello, 0, 0}, /*PROTOCOL__FLEXRAN_MESSAGE__MSG_HELLO_MSG*/
  {flexran_agent_echo_reply, 0, 0}, /*PROTOCOL__FLEXRAN_MESSAGE__MSG_ECHO_REQUEST_MSG*/
47
  {0, 0, 0}, /*PROTOCOL__FLEXRAN_MESSAGE__MSG_ECHO_REPLY_MSG*/ //Must add handler when receiving echo reply
48
  {flexran_agent_mac_handle_stats, 0, 0}, /*PROTOCOL__FLEXRAN_MESSAGE__MSG_STATS_REQUEST_MSG*/
49 50 51
  {0, 0, 0}, /*PROTOCOL__FLEXRAN_MESSAGE__MSG_STATS_REPLY_MSG*/
  {0, 0, 0}, /*PROTOCOK__FLEXRAN_MESSAGE__MSG_SF_TRIGGER_MSG*/
  {0, 0, 0}, /*PROTOCOL__FLEXRAN_MESSAGE__MSG_UL_SR_INFO_MSG*/
52
  {flexran_agent_enb_config_reply, 0, 0}, /*PROTOCOL__FLEXRAN_MESSAGE__MSG_ENB_CONFIG_REQUEST_MSG*/
53
  {0, 0, 0}, /*PROTOCOL__FLEXRAN_MESSAGE__MSG_ENB_CONFIG_REPLY_MSG*/
54
  {flexran_agent_ue_config_reply, 0, 0}, /*PROTOCOL__FLEXRAN_MESSAGE__MSG_UE_CONFIG_REQUEST_MSG*/
55
  {0, 0, 0}, /*PROTOCOL__FLEXRAN_MESSAGE__MSG_UE_CONFIG_REPLY_MSG*/
56
  {flexran_agent_lc_config_reply, 0, 0}, /*PROTOCOL__FLEXRAN_MESSAGE__MSG_LC_CONFIG_REQUEST_MSG*/
57
  {0, 0, 0}, /*PROTOCOL__FLEXRAN_MESSAGE__MSG_LC_CONFIG_REPLY_MSG*/
58
  {flexran_agent_mac_handle_dl_mac_config, 0, 0}, /*PROTOCOL__FLEXRAN_MESSAGE__MSG_DL_MAC_CONFIG_MSG*/
59
  {0, 0, 0}, /*PROTOCOL__FLEXRAN_MESSAGE__MSG_UE_STATE_CHANGE_MSG*/
60 61
  {flexran_agent_control_delegation, 0, 0}, /*PROTOCOL__FLEXRAN_MESSAGE__MSG_CONTROL_DELEGATION_MSG*/
  {flexran_agent_reconfiguration, 0, 0}, /*PROTOCOL__FLEXRAN_MESSAGE__MSG_AGENT_RECONFIGURATION_MSG*/
nikaeinn's avatar
nikaeinn committed
62 63
};

64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
flexran_agent_message_destruction_callback message_destruction_callback[] = {
  flexran_agent_destroy_hello,
  flexran_agent_destroy_echo_request,
  flexran_agent_destroy_echo_reply,
  flexran_agent_mac_destroy_stats_request,
  flexran_agent_mac_destroy_stats_reply,
  flexran_agent_mac_destroy_sf_trigger,
  flexran_agent_mac_destroy_sr_info,
  flexran_agent_destroy_enb_config_request,
  flexran_agent_destroy_enb_config_reply,
  flexran_agent_destroy_ue_config_request,
  flexran_agent_destroy_ue_config_reply,
  flexran_agent_destroy_lc_config_request,
  flexran_agent_destroy_lc_config_reply,
  flexran_agent_mac_destroy_dl_config,
  flexran_agent_destroy_ue_state_change,
  flexran_agent_destroy_control_delegation,
  flexran_agent_destroy_agent_reconfiguration,
82 83
};

84
static const char *flexran_agent_direction2String[] = {
nikaeinn's avatar
nikaeinn committed
85 86 87 88 89 90 91
  "", /* not_set  */
  "originating message", /* originating message */
  "successfull outcome", /* successfull outcome */
  "unsuccessfull outcome", /* unsuccessfull outcome */
};


92 93 94
Protocol__FlexranMessage* flexran_agent_handle_message (mid_t mod_id,
							uint8_t *data, 
							uint32_t size){
nikaeinn's avatar
nikaeinn committed
95
  
96
  Protocol__FlexranMessage *decoded_message, *reply_message;
nikaeinn's avatar
nikaeinn committed
97 98 99
  err_code_t err_code;
  DevAssert(data != NULL);

100
  if (flexran_agent_deserialize_message(data, size, &decoded_message) < 0) {
101
    err_code= PROTOCOL__FLEXRAN_ERR__MSG_DECODING;
nikaeinn's avatar
nikaeinn committed
102 103 104
    goto error; 
  }
  
105
  if ((decoded_message->msg_case > sizeof(agent_messages_callback) / (3 * sizeof(flexran_agent_message_decoded_callback))) || 
106 107
      (decoded_message->msg_dir > PROTOCOL__FLEXRAN_DIRECTION__UNSUCCESSFUL_OUTCOME)){
    err_code= PROTOCOL__FLEXRAN_ERR__MSG_NOT_HANDLED;
108
    goto error;
nikaeinn's avatar
nikaeinn committed
109 110
  }
    
nikaeinn's avatar
nikaeinn committed
111
  if (agent_messages_callback[decoded_message->msg_case-1][decoded_message->msg_dir-1] == NULL) {
112
    err_code= PROTOCOL__FLEXRAN_ERR__MSG_NOT_SUPPORTED;
nikaeinn's avatar
nikaeinn committed
113 114 115 116
    goto error;

  }

nikaeinn's avatar
nikaeinn committed
117
  err_code = ((*agent_messages_callback[decoded_message->msg_case-1][decoded_message->msg_dir-1])(mod_id, (void *) decoded_message, &reply_message));
nikaeinn's avatar
nikaeinn committed
118 119
  if ( err_code < 0 ){
    goto error;
120
  } else if (err_code == 1) { //If err_code > 1, we do not want to dispose the message yet
121
    protocol__flexran_message__free_unpacked(decoded_message, NULL);
nikaeinn's avatar
nikaeinn committed
122
  }
123
  return reply_message;
nikaeinn's avatar
nikaeinn committed
124 125
  
error:
126
  LOG_E(FLEXRAN_AGENT,"errno %d occured\n",err_code);
127
  return NULL;
nikaeinn's avatar
nikaeinn committed
128 129 130 131 132

}



133 134
void * flexran_agent_pack_message(Protocol__FlexranMessage *msg, 
				  uint32_t * size){
nikaeinn's avatar
nikaeinn committed
135 136

  void * buffer;
137
  err_code_t err_code = PROTOCOL__FLEXRAN_ERR__NO_ERR;
nikaeinn's avatar
nikaeinn committed
138
  
139
  if (flexran_agent_serialize_message(msg, &buffer, size) < 0 ) {
140
    err_code = PROTOCOL__FLEXRAN_ERR__MSG_ENCODING;
nikaeinn's avatar
nikaeinn committed
141 142 143 144
    goto error;
  }
  
  // free the msg --> later keep this in the data struct and just update the values
145
  //TODO call proper destroy function
146
  err_code = ((*message_destruction_callback[msg->msg_case-1])(msg));
nikaeinn's avatar
nikaeinn committed
147 148
  
  DevAssert(buffer !=NULL);
149
  
150
  LOG_D(FLEXRAN_AGENT,"Serilized the enb mac stats reply (size %d)\n", *size);
151
  
nikaeinn's avatar
nikaeinn committed
152
  return buffer;
153 154
  
 error : 
155
  LOG_E(FLEXRAN_AGENT,"errno %d occured\n",err_code);
156
  
157 158 159
  return NULL;   
}

160
Protocol__FlexranMessage *flexran_agent_handle_timed_task(void *args) {
161
  err_code_t err_code;
162
  flexran_agent_timer_args_t *timer_args = (flexran_agent_timer_args_t *) args;
163

164
  Protocol__FlexranMessage *timed_task, *reply_message;
165
  timed_task = timer_args->msg;
166
  err_code = ((*agent_messages_callback[timed_task->msg_case-1][timed_task->msg_dir-1])(timer_args->mod_id, (void *) timed_task, &reply_message));
167 168 169 170 171
  if ( err_code < 0 ){
    goto error;
  }

  return reply_message;
nikaeinn's avatar
nikaeinn committed
172
  
173
 error:
174
  LOG_E(FLEXRAN_AGENT,"errno %d occured\n",err_code);
175
  return NULL;
nikaeinn's avatar
nikaeinn committed
176 177
}

178
Protocol__FlexranMessage* flexran_agent_process_timeout(long timer_id, void* timer_args){
179
    
180
  struct flexran_agent_timer_element_s *found = get_timer_entry(timer_id);
181 182
 
  if (found == NULL ) goto error;
183
  LOG_I(FLEXRAN_AGENT, "Found the entry (%p): timer_id is 0x%lx  0x%lx\n", found, timer_id, found->timer_id);
184 185
  
  if (timer_args == NULL)
186
    LOG_W(FLEXRAN_AGENT,"null timer args\n");
187
  
188
  return found->cb(timer_args);
nikaeinn's avatar
nikaeinn committed
189

190
 error:
191
  LOG_E(FLEXRAN_AGENT, "can't get the timer element\n");
192 193
  return TIMER_ELEMENT_NOT_FOUND;
}
194

195
err_code_t flexran_agent_destroy_flexran_message(Protocol__FlexranMessage *msg) {
196 197
  return ((*message_destruction_callback[msg->msg_case-1])(msg));
}