Updated INFO.yaml file
[ric-app/kpimon.git] / src / message_processor_class.cc
1 /*\r
2 ==================================================================================\r
3 \r
4         Copyright (c) 2018-2019 SAMSUNG and AT&T Intellectual Property.\r
5 \r
6    Licensed under the Apache License, Version 2.0 (the "License");\r
7    you may not use this file except in compliance with the License.\r
8    You may obtain a copy of the License at\r
9 \r
10        http://www.apache.org/licenses/LICENSE-2.0\r
11 \r
12    Unless required by applicable law or agreed to in writing, software\r
13    distributed under the License is distributed on an "AS IS" BASIS,\r
14    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
15    See the License for the specific language governing permissions and\r
16    limitations under the License.\r
17 ==================================================================================\r
18 */\r
19 \r
20 \r
21 #include <message_processor_class.hpp>\r
22 \r
23 void message_processor::register_subscription_handler(SubscriptionHandler * sub){\r
24   _ref_sub_handler = sub;\r
25 }\r
26 \r
27 // main message processing \r
28 bool message_processor::operator()(redisContext *redis_context, rmr_mbuf_t *message){\r
29 \r
30   bool res;\r
31   int message_type, procedure_code;\r
32   asn_dec_rval_t rval;\r
33   size_t buf_size = BUFFER_LENGTH;\r
34   size_t mlen;\r
35   _num_messages ++;\r
36   std::string response;\r
37 \r
38   // main message processing code\r
39   switch(message->mtype){\r
40     \r
41   case RIC_INDICATION:\r
42 \r
43     e2ap_recv_pdu = 0;\r
44     e2sm_header = 0;\r
45    \r
46     rval = asn_decode(0,ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, (void**)&(e2ap_recv_pdu), message->payload, message->len);\r
47 \r
48     if(likely(rval.code == RC_OK)){\r
49       num_indications ++;\r
50       res = indication_processor.get_fields(e2ap_recv_pdu->choice.initiatingMessage, indication_data);\r
51       if (unlikely(!res)){\r
52         mdclog_write(MDCLOG_ERR, "Error :: %s, %d :: Could not get fields from RICindication message\n", __FILE__, __LINE__);\r
53         return false;\r
54       }\r
55       //std::cout <<"+++++++++++++++++++++++ E2AP Indication ++++++++++++++++++++++++" << std::endl;\r
56       //xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2ap_recv_pdu);\r
57       //std::cout <<"+++++++++++++++++++++++ E2AP Indication ++++++++++++++++++++++++" << std::endl;\r
58     }\r
59     else{\r
60       num_err_indications ++;\r
61       mdclog_write(MDCLOG_ERR, "Error :: %s, %d: Error decoding E2AP PDU\n", __FILE__, __LINE__);\r
62       return false;\r
63     }\r
64 \r
65     mdclog_write(MDCLOG_INFO, "E2AP INDICATION :: Successfully received E2AP Indication message with id = %d, sequence no = %d, Number of indication messages = %lu, Number of erroneous indications = %lu\n", indication_data.req_id, indication_data.req_seq_no, num_indications, num_err_indications);\r
66       \r
67     //Decode the SM header\r
68     rval = asn_decode(0, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_gNB_X2_indicationHeader, (void**)&(e2sm_header), indication_data.indication_header, indication_data.indication_header_size);\r
69     if (likely(rval.code == RC_OK)){\r
70       res = e2sm_indication_processor.get_header_fields(e2sm_header, header_helper);\r
71       if (unlikely(!res)){\r
72         mdclog_write(MDCLOG_ERR, "Error :: %s, %d :: Could not get fields from E2SM HEADER\n", __FILE__, __LINE__);\r
73         return false;\r
74       }\r
75       \r
76       // std::cout <<"+++++++++++++++++++++++ E2SM Indication Header ++++++++++++++++++++++++" << std::endl;\r
77       // xer_fprint(stdout, &asn_DEF_E2SM_gNB_X2_indicationHeader, e2sm_header);\r
78       // std::cout <<"+++++++++++++++++++++++ E2SM Indication Header ++++++++++++++++++++++++" << std::endl;    \r
79     }\r
80     else{\r
81       mdclog_write(MDCLOG_ERR, "Error :: %s, %d: Error decoding E2SM Header.", __FILE__, __LINE__);\r
82       return false;\r
83     }\r
84     mdclog_write(MDCLOG_DEBUG, "E2SM INDICATION HEADER :: Successfully decoded E2SM Indication Header of size %lu\n", indication_data.indication_header_size);\r
85 \r
86     // Do the further decoding here for KPI message\r
87 \r
88     res = (*_ref_kpi_msg_handler)(redis_context, indication_data.indication_msg, indication_data.indication_msg_size);\r
89 \r
90     if(unlikely(!res)){\r
91       return false;\r
92     }\r
93     // NOTE : We assume RICindicationMessage contains payload (not E2SM message)\r
94     ASN_STRUCT_FREE(asn_DEF_E2SM_gNB_X2_indicationHeader, e2sm_header);\r
95     ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, e2ap_recv_pdu);\r
96 \r
97     break;\r
98 \r
99   case (RIC_SUB_RESP):\r
100   case (RIC_SUB_FAILURE):\r
101     if (_ref_sub_handler != NULL){\r
102       mdclog_write(MDCLOG_INFO, "Received subscription message of type = %d", message->mtype);\r
103       _ref_sub_handler->Response(message->mtype, message->payload, message->len);\r
104     }\r
105     else{\r
106       mdclog_write(MDCLOG_ERR, " Error :: %s, %d : Subscription handler not assigned in message processor !", __FILE__, __LINE__);\r
107       return false;\r
108     }\r
109     \r
110     break;\r
111 \r
112   default:\r
113     mdclog_write(MDCLOG_ERR, "Error :: Unknown message type %d received from RMR", message->mtype);\r
114   };\r
115   \r
116   return false;\r
117 };\r
118 \r
119 \r
120 unsigned long const message_processor::get_messages (void){\r
121     return _num_messages;\r
122 };\r
123 \r