2 # ==================================================================================
3 # Copyright (c) 2020 HCL Technologies Limited.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 # ==================================================================================
19 #include "msgs_proc.hpp"
22 bool XappMsgHandler::encode_subscription_delete_request(unsigned char* buffer, size_t *buf_len){
24 subscription_helper sub_helper;
25 sub_helper.set_request(0); // requirement of subscription manager ... ?
26 sub_helper.set_function_id(0);
28 subscription_delete e2ap_sub_req_del;
30 // generate the delete request pdu
32 bool res = e2ap_sub_req_del.encode_e2ap_subscription(&buffer[0], buf_len, sub_helper);
34 mdclog_write(MDCLOG_ERR, "%s, %d: Error encoding subscription delete request pdu. Reason = %s", __FILE__, __LINE__, e2ap_sub_req_del.get_error().c_str());
42 bool XappMsgHandler::decode_subscription_response(unsigned char* data_buf, size_t data_size){
44 subscription_helper subhelper;
45 subscription_response subresponse;
47 E2AP_PDU_t *e2pdu = 0;
51 ASN_STRUCT_RESET(asn_DEF_E2AP_PDU, e2pdu);
53 rval = asn_decode(0,ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, (void**)&e2pdu, data_buf, data_size);
57 //Put in Subscription Response Object.
58 //asn_fprint(stdout, &asn_DEF_E2AP_PDU, e2pdu);
61 mdclog_write(MDCLOG_ERR, "RC_WMORE");
65 mdclog_write(MDCLOG_ERR, "RC_FAIL");
71 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, e2pdu);
76 /*bool XappMsgHandler::a1_policy_handler(char * message, int *message_len, a1_policy_helper &helper){
78 rapidjson::Document doc;
79 if (doc.Parse<kParseStopWhenDoneFlag>(message).HasParseError()){
80 mdclog_write(MDCLOG_ERR, "Error: %s, %d :: Could not decode A1 JSON message %s\n", __FILE__, __LINE__, message);
85 rapidjson::Pointer temp1("/operation");
86 rapidjson::Value * ref1 = temp1.Get(doc);
88 mdclog_write(MDCLOG_ERR, "Error : %s, %d:: Could not extract policy type id from %s\n", __FILE__, __LINE__, message);
92 helper.operation = ref1->GetString();
94 // Extract policy id type
95 rapidjson::Pointer temp2("/policy_type_id");
96 rapidjson::Value * ref2 = temp2.Get(doc);
98 mdclog_write(MDCLOG_ERR, "Error : %s, %d:: Could not extract policy type id from %s\n", __FILE__, __LINE__, message);
101 //helper.policy_type_id = ref2->GetString();
102 helper.policy_type_id = to_string(ref2->GetInt());
104 // Extract policy instance id
105 rapidjson::Pointer temp("/policy_instance_id");
106 rapidjson::Value * ref = temp.Get(doc);
108 mdclog_write(MDCLOG_ERR, "Error : %s, %d:: Could not extract policy type id from %s\n", __FILE__, __LINE__, message);
111 helper.policy_instance_id = ref->GetString();
113 if (helper.policy_type_id == "1" && helper.operation == "CREATE"){
114 helper.status = "OK";
115 Document::AllocatorType& alloc = doc.GetAllocator();
118 handler_id.SetString(helper.handler_id.c_str(), helper.handler_id.length(), alloc);
121 status.SetString(helper.status.c_str(), helper.status.length(), alloc);
124 doc.AddMember("handler_id", handler_id, alloc);
125 doc.AddMember("status",status, alloc);
126 doc.RemoveMember("operation");
128 Writer<StringBuffer> writer(buffer);
130 strncpy(message,buffer.GetString(), buffer.GetLength());
131 *message_len = buffer.GetLength();
138 //For processing received messages.XappMsgHandler should mention if resend is required or not.
139 void XappMsgHandler::operator()(rmr_mbuf_t *message, bool *resend){
141 if (message->len > MAX_RMR_RECV_SIZE){
142 mdclog_write(MDCLOG_ERR, "Error : %s, %d, RMR message larger than %d. Ignoring ...", __FILE__, __LINE__, MAX_RMR_RECV_SIZE);
145 //a1_policy_helper helper;
147 switch(message->mtype){
148 //need to fix the health check.
149 case (RIC_HEALTH_CHECK_REQ):
150 message->mtype = RIC_HEALTH_CHECK_RESP; // if we're here we are running and all is ok
151 message->sub_id = -1;
152 strncpy( (char*)message->payload, "Bouncer OK\n", rmr_payload_size( message) );
157 mdclog_write(MDCLOG_INFO, "Received subscription message of type = %d", message->mtype);
158 unsigned char *me_id;
159 if( (me_id = (unsigned char *) malloc( sizeof( unsigned char ) * RMR_MAX_MEID )) == NULL ) {
160 mdclog_write(MDCLOG_ERR, "Error : %s, %d : malloc failed for me_id", __FILE__, __LINE__);
161 me_id = rmr_get_meid(message, NULL);
163 rmr_get_meid(message, me_id);
166 mdclog_write(MDCLOG_ERR, " Error :: %s, %d : rmr_get_meid failed me_id is NULL", __FILE__, __LINE__);
169 mdclog_write(MDCLOG_INFO,"RMR Received MEID: %s",me_id);
170 if(_ref_sub_handler !=NULL){
171 _ref_sub_handler->manage_subscription_response(message->mtype, reinterpret_cast< char const* >(me_id));
173 mdclog_write(MDCLOG_ERR, " Error :: %s, %d : Subscription handler not assigned in message processor !", __FILE__, __LINE__);
177 mdclog_write(MDCLOG_INFO, "Free RMR Received MEID memory: %s(0x%x)", me_id, me_id);
181 case (RIC_INDICATION):
182 mdclog_write(MDCLOG_INFO, "Received indication message of type = %d", message->mtype);
183 message->mtype = RIC_CONTROL_REQ; // if we're here we are running and all is ok
184 message->sub_id = -1;
185 strncpy((char*)message->payload, "Bouncer Control OK\n", rmr_payload_size(message));
189 /*case A1_POLICY_REQ:
191 mdclog_write(MDCLOG_INFO, "In Message Handler: Received A1_POLICY_REQ.");
192 helper.handler_id = xapp_id;
194 res = a1_policy_handler((char*)message->payload, &message->len, helper);
196 message->mtype = A1_POLICY_RESP; // if we're here we are running and all is ok
197 message->sub_id = -1;
204 mdclog_write(MDCLOG_ERR, "Error :: Unknown message type %d received from RMR", message->mtype);