flexran_agent_handler.c 6.95 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
 */ 
nikaeinn's avatar
nikaeinn committed
21

22 23
/*! \file flexran_agent_handler.c
 * \brief FlexRAN agent tx and rx message handler 
24
 * \author Xenofon Foukas and Navid Nikaein
nikaeinn's avatar
nikaeinn committed
25 26 27 28 29
 * \date 2016
 * \version 0.1
 */


30 31
#include "flexran_agent_common.h"
#include "flexran_agent_mac.h"
nikaeinn's avatar
nikaeinn committed
32 33 34 35
#include "log.h"

#include "assertions.h"

36 37 38
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*/
39
  {0, 0, 0}, /*PROTOCOL__FLEXRAN_MESSAGE__MSG_ECHO_REPLY_MSG*/ //Must add handler when receiving echo reply
40
  {flexran_agent_mac_handle_stats, 0, 0}, /*PROTOCOL__FLEXRAN_MESSAGE__MSG_STATS_REQUEST_MSG*/
41 42 43
  {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*/
44
  {flexran_agent_enb_config_reply, 0, 0}, /*PROTOCOL__FLEXRAN_MESSAGE__MSG_ENB_CONFIG_REQUEST_MSG*/
45
  {0, 0, 0}, /*PROTOCOL__FLEXRAN_MESSAGE__MSG_ENB_CONFIG_REPLY_MSG*/
46
  {flexran_agent_ue_config_reply, 0, 0}, /*PROTOCOL__FLEXRAN_MESSAGE__MSG_UE_CONFIG_REQUEST_MSG*/
47
  {0, 0, 0}, /*PROTOCOL__FLEXRAN_MESSAGE__MSG_UE_CONFIG_REPLY_MSG*/
48
  {flexran_agent_lc_config_reply, 0, 0}, /*PROTOCOL__FLEXRAN_MESSAGE__MSG_LC_CONFIG_REQUEST_MSG*/
49
  {0, 0, 0}, /*PROTOCOL__FLEXRAN_MESSAGE__MSG_LC_CONFIG_REPLY_MSG*/
50
  {flexran_agent_mac_handle_dl_mac_config, 0, 0}, /*PROTOCOL__FLEXRAN_MESSAGE__MSG_DL_MAC_CONFIG_MSG*/
51
  {0, 0, 0}, /*PROTOCOL__FLEXRAN_MESSAGE__MSG_UE_STATE_CHANGE_MSG*/
52 53
  {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
54 55
};

56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
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,
74 75
};

76
static const char *flexran_agent_direction2String[] = {
nikaeinn's avatar
nikaeinn committed
77 78 79 80 81 82 83
  "", /* not_set  */
  "originating message", /* originating message */
  "successfull outcome", /* successfull outcome */
  "unsuccessfull outcome", /* unsuccessfull outcome */
};


84 85 86
Protocol__FlexranMessage* flexran_agent_handle_message (mid_t mod_id,
							uint8_t *data, 
							uint32_t size){
nikaeinn's avatar
nikaeinn committed
87
  
88
  Protocol__FlexranMessage *decoded_message, *reply_message;
nikaeinn's avatar
nikaeinn committed
89 90 91
  err_code_t err_code;
  DevAssert(data != NULL);

92
  if (flexran_agent_deserialize_message(data, size, &decoded_message) < 0) {
93
    err_code= PROTOCOL__FLEXRAN_ERR__MSG_DECODING;
nikaeinn's avatar
nikaeinn committed
94 95 96
    goto error; 
  }
  
97
  if ((decoded_message->msg_case > sizeof(agent_messages_callback) / (3 * sizeof(flexran_agent_message_decoded_callback))) || 
98 99
      (decoded_message->msg_dir > PROTOCOL__FLEXRAN_DIRECTION__UNSUCCESSFUL_OUTCOME)){
    err_code= PROTOCOL__FLEXRAN_ERR__MSG_NOT_HANDLED;
100
    goto error;
nikaeinn's avatar
nikaeinn committed
101 102
  }
    
nikaeinn's avatar
nikaeinn committed
103
  if (agent_messages_callback[decoded_message->msg_case-1][decoded_message->msg_dir-1] == NULL) {
104
    err_code= PROTOCOL__FLEXRAN_ERR__MSG_NOT_SUPPORTED;
nikaeinn's avatar
nikaeinn committed
105 106 107 108
    goto error;

  }

nikaeinn's avatar
nikaeinn committed
109
  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
110 111
  if ( err_code < 0 ){
    goto error;
112
  } else if (err_code == 1) { //If err_code > 1, we do not want to dispose the message yet
113
    protocol__flexran_message__free_unpacked(decoded_message, NULL);
nikaeinn's avatar
nikaeinn committed
114
  }
115
  return reply_message;
nikaeinn's avatar
nikaeinn committed
116 117
  
error:
118
  LOG_E(FLEXRAN_AGENT,"errno %d occured\n",err_code);
119
  return NULL;
nikaeinn's avatar
nikaeinn committed
120 121 122 123 124

}



125 126
void * flexran_agent_pack_message(Protocol__FlexranMessage *msg, 
				  uint32_t * size){
nikaeinn's avatar
nikaeinn committed
127 128

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

152
Protocol__FlexranMessage *flexran_agent_handle_timed_task(void *args) {
153
  err_code_t err_code;
154
  flexran_agent_timer_args_t *timer_args = (flexran_agent_timer_args_t *) args;
155

156
  Protocol__FlexranMessage *timed_task, *reply_message;
157
  timed_task = timer_args->msg;
158
  err_code = ((*agent_messages_callback[timed_task->msg_case-1][timed_task->msg_dir-1])(timer_args->mod_id, (void *) timed_task, &reply_message));
159 160 161 162 163
  if ( err_code < 0 ){
    goto error;
  }

  return reply_message;
nikaeinn's avatar
nikaeinn committed
164
  
165
 error:
166
  LOG_E(FLEXRAN_AGENT,"errno %d occured\n",err_code);
167
  return NULL;
nikaeinn's avatar
nikaeinn committed
168 169
}

170
Protocol__FlexranMessage* flexran_agent_process_timeout(long timer_id, void* timer_args){
171
    
172
  struct flexran_agent_timer_element_s *found = get_timer_entry(timer_id);
173 174
 
  if (found == NULL ) goto error;
175
  LOG_I(FLEXRAN_AGENT, "Found the entry (%p): timer_id is 0x%lx  0x%lx\n", found, timer_id, found->timer_id);
176 177
  
  if (timer_args == NULL)
178
    LOG_W(FLEXRAN_AGENT,"null timer args\n");
179
  
180
  return found->cb(timer_args);
nikaeinn's avatar
nikaeinn committed
181

182
 error:
183
  LOG_E(FLEXRAN_AGENT, "can't get the timer element\n");
184 185
  return TIMER_ELEMENT_NOT_FOUND;
}
186

187
err_code_t flexran_agent_destroy_flexran_message(Protocol__FlexranMessage *msg) {
188 189
  return ((*message_destruction_callback[msg->msg_case-1])(msg));
}