proto_agent_handler.c 4.81 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 30 31 32 33 34 35 36 37 38
/*******************************************************************************
    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.

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

/*! \file enb_agent_handler.c
 * \brief enb agent tx and rx message handler 
 * \author Navid Nikaein and Xenofon Foukas 
 * \date 2016
 * \version 0.1
 */


#include "proto_agent_common.h"
39
#include "common/utils/LOG/log.h"
40 41
#include "assertions.h"

42
proto_agent_message_decoded_callback proto_agent_messages_callback[][3] = {
43
  {proto_agent_hello, 0, 0},
44
  {proto_agent_echo_reply, 0, 0},
45
  {0, just_print, 0},
46
  {proto_agent_pdcp_data_req_ack, 0, 0},
47
  {0, proto_agent_get_ack_result, 0},
48 49
  {proto_agent_pdcp_data_ind_ack, 0, 0},
  {0, just_print, 0},
50 51
};

52
proto_agent_message_destruction_callback proto_message_destruction_callback[] = {
53
  proto_agent_destroy_hello,
54 55
  proto_agent_destroy_echo_request,
  proto_agent_destroy_echo_reply,
56 57
  proto_agent_destroy_pdcp_data_req,
  proto_agent_destroy_pdcp_data_req_ack,
58 59 60
  proto_agent_destroy_pdcp_data_ind,
  proto_agent_destroy_pdcp_data_ind_ack,

61 62
};

63 64 65 66 67 68
//static const char *proto_agent_direction2String[] = {
//  "", /* not_set  */
//  "originating message", /* originating message */
//  "successfull outcome", /* successfull outcome */
//  "unsuccessfull outcome", /* unsuccessfull outcome */
//};
69 70


71
Protocol__FlexsplitMessage* proto_agent_handle_message (mod_id_t mod_id,
72
						    uint8_t *data, 
73
						    int size){
74
  
75 76
  Protocol__FlexsplitMessage *decoded_message = NULL;
  Protocol__FlexsplitMessage *reply_message = NULL;
77 78 79
  err_code_t err_code;
  DevAssert(data != NULL);

80
  LOG_D(PROTO_AGENT, "Deserializing message with size %u \n", size);
81
  if (proto_agent_deserialize_message(data, (int) size, &decoded_message) < 0) {
82 83 84
    err_code= PROTOCOL__FLEXSPLIT_ERR__MSG_DECODING;
    goto error; 
  }
85 86 87
  Protocol__FspHeader *header = (Protocol__FspHeader*) decoded_message;
  if (header->has_type)
   {
88
    LOG_D(PROTO_AGENT, "Deserialized MSG type is %d and %u\n", decoded_message->msg_case, decoded_message->msg_dir);
89 90
   }

91
  if ((decoded_message->msg_case > sizeof(proto_agent_messages_callback) / (3*sizeof(proto_agent_message_decoded_callback))) || 
92 93 94
      (decoded_message->msg_dir > PROTOCOL__FLEXSPLIT_DIRECTION__UNSUCCESSFUL_OUTCOME))
  {
      err_code= PROTOCOL__FLEXSPLIT_ERR__MSG_NOT_HANDLED;
95
      LOG_D(PROTO_AGENT,"Handling message: MSG NOT handled, going to error\n");
96 97
      goto error;
  }
98
  
99
  err_code = ((*proto_agent_messages_callback[decoded_message->msg_case-1][decoded_message->msg_dir-1])(mod_id, (void *) decoded_message, &reply_message));
100

101 102
  if ( err_code < 0 )
  {
103
    LOG_I(PROTO_AGENT, "decoded_message case : %d, direction : %d \n", decoded_message->msg_case-1, decoded_message->msg_dir-1);
104
    goto error;
105 106 107
  }
  else if (err_code == 1) 
  {
108 109
    protocol__flexsplit_message__free_unpacked(decoded_message, NULL);
  }
110
  LOG_D(PROTO_AGENT,"Returning REPLY message after the callback\n");
111 112
  return reply_message;
  
113
 error:
114 115 116 117 118 119
  LOG_E(PROTO_AGENT,"errno %d occured\n",err_code);
  return NULL;
}



120 121 122
uint8_t *proto_agent_pack_message(Protocol__FlexsplitMessage *msg, int *size)
{
  uint8_t *buffer;
123 124 125 126 127 128 129 130
  err_code_t err_code = PROTOCOL__FLEXSPLIT_ERR__NO_ERR;
  
  if (proto_agent_serialize_message(msg, &buffer, size) < 0 ) {
    err_code = PROTOCOL__FLEXSPLIT_ERR__MSG_ENCODING;
    goto error;
  }
  
  //TODO call proper destroy function
131
  
132
  err_code = ((*proto_message_destruction_callback[msg->msg_case-1])(msg));
133 134 135
  
  DevAssert(buffer !=NULL);
  
136
  LOG_D(PROTO_AGENT,"Serialized the enb mac stats reply (size %d)\n", *size);
137 138 139 140 141 142 143 144 145
  return buffer;
  
 error : 
  LOG_E(PROTO_AGENT,"errno %d occured\n",err_code);
  
  return NULL;   
}

err_code_t proto_agent_destroy_flexsplit_message(Protocol__FlexsplitMessage *msg) {
146
  return ((*proto_message_destruction_callback[msg->msg_case-1])(msg));
147
}