Added IndicationMessage
[ric-app/hw.git] / test / test_e2sm.h
index 2300303..82b0bfb 100644 (file)
 #include<iostream>
 #include<gtest/gtest.h>
 
-#include "subscription_request.hpp"
 #include "xapp.hpp"
-#include "e2sm_helpers.hpp"
-#include "e2sm_subscription.hpp"
-#include "e2sm_indication.hpp"
 #include "e2sm_control.hpp"
+#include "e2ap_indication.hpp"
+#include "e2sm_indication.hpp"
+#include "e2ap_control.hpp"
 
 using namespace std;
-TEST(E2SM, SubscriptionRequest)
+TEST(E2SM, IndicationMessageEncode)
 {
+       unsigned char buff[1024];
+       size_t buf_len = 1024;
 
-       unsigned char event_buf[128];
-       size_t event_buf_len = 128;
-
-       unsigned char act_buf[128];
-       size_t act_buf_len = 128;
-
-       bool res;
-
-
-       e2sm_subscription_helper e2sm_subsdata;
-       std::unique_ptr<ranparam_helper> *ranhelp;
-       e2sm_subscription e2sm_subs;
-
-
-       e2sm_subsdata.triger_nature = 0;
 
-       int param_id = 1;
-       unsigned char param_name[20];
-       strcpy((char*)param_name,"ParamName");
-       int param_name_len = strlen((const char*)param_name);
+       HWIndicationHeader headerObj;
+       headerObj.set_ricIndicationHeader(1);
+       std::cout << headerObj.get_error() << std::endl;
 
-       int param_test = 0;
-       unsigned char param_value[20];
-       strcpy((char*)param_value,"ParamValue");
-       int param_value_len = strlen((const char*)param_value);
+       HWIndicationMessage messageObj;
+       messageObj.set_hw_message("HelloWorld-E2SM");
+       std::cout << messageObj.get_error() << std::endl;
 
-       e2sm_subsdata.add_param(param_id, param_name, param_name_len, param_test, param_value, param_value_len);
+       E2APIndication<HWIndicationHeader,HWIndicationMessage>::IndicationIEs infoObj;
+       infoObj.set_ranFunctionID(1);
+       infoObj.set_ricActionID(1);
+       infoObj.set_ricRequestorID(1);
+       infoObj.set_ricIndicationHeader(headerObj);
+       infoObj.set_ricIndicationMessage(messageObj);
 
+       E2APIndication<HWIndicationHeader,HWIndicationMessage> e2obj(infoObj);
 
-       // Encode the event trigger definition
-       res = e2sm_subs.encode_event_trigger(&event_buf[0], &event_buf_len, e2sm_subsdata);
-       if(!res)
-               std::cout << e2sm_subs.get_error() << std::endl;
+       bool res = e2obj.encode(buff, &buf_len);
+                       if(!res)
+                       {
+                               std::cout << e2obj.get_error() << std::endl;
+                       }
+                       ASSERT_TRUE(res);
 
-       ASSERT_TRUE(res);
 
-       // Encode the action defintion
-       res = e2sm_subs.encode_action_defn(&act_buf[0], &act_buf_len, e2sm_subsdata);
-       if(!res)
-               std::cout << e2sm_subs.get_error() << std::endl;
-       ASSERT_TRUE(res);
+       FILE * pFile;
+       pFile = fopen ("indication2.per","w");
+       if (pFile!=NULL)
+        {
+             fputs ((const char*)buff,pFile);
+                 fclose (pFile);
+         }
 
 }
-TEST(E2SM, IndicationMessage)
+TEST(E2SM, IndicationMessageDecode)
 {
-
-       unsigned char header_buf[128];
-       size_t header_buf_len = 128;
-
-       unsigned char msg_buf[128];
-       size_t msg_buf_len = 128;
-
-       bool res;
-       asn_dec_rval_t retval;
-
-
-       e2sm_indication_helper e2sm_inddata;
-       e2sm_indication e2sm_inds;
-
-       unsigned char msg[20] = "HelloWorld";
-
-       e2sm_inddata.header = 1001;
-       e2sm_inddata.message = msg;
-       e2sm_inddata.message_len = strlen((const char*)e2sm_inddata.message);
-
-
-       // Encode the indication header
-       res = e2sm_inds.encode_indication_header(&header_buf[0], &header_buf_len, e2sm_inddata);
-       if(!res)
-               std::cout << e2sm_inds.get_error() << std::endl;
-
-       ASSERT_TRUE(res);
-
-       // Encode the indication message
-       res = e2sm_inds.encode_indication_message(&msg_buf[0], &msg_buf_len, e2sm_inddata);
-       if(!res)
-               std::cout << e2sm_inds.get_error() << std::endl;
-       ASSERT_TRUE(res);
-
-       //decode the indication header
-       e2sm_indication_helper e2sm_decodedata;
-
-
-       E2SM_HelloWorld_IndicationHeader_t *header = 0; // used for decoding
-       retval = asn_decode(0, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_HelloWorld_IndicationHeader, (void**)&(header), &header_buf[0], header_buf_len);
-
-       ASSERT_TRUE(retval.code == RC_OK);
-       res = e2sm_inds.get_fields(header, e2sm_decodedata);
-
-       //decode the indication message
-
-       E2SM_HelloWorld_IndicationMessage_t *mesg = 0; // used for decoding
-       retval = asn_decode(0, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_HelloWorld_IndicationMessage, (void**)&(mesg), &msg_buf[0], msg_buf_len);
-
-       ASSERT_TRUE(retval.code == RC_OK);
-       res = e2sm_inds.get_fields(mesg, e2sm_decodedata);
-
-
-       std::cout << "Indication Header:" << e2sm_decodedata.header << std::endl;
-       std::cout << "Indication Message:" << e2sm_decodedata.message << std::endl;
-       std::cout << "Indication Message Len:" << e2sm_decodedata.message_len << std::endl;
-
-       ASSERT_EQ(e2sm_inddata.header, e2sm_decodedata.header);
-       ASSERT_EQ(e2sm_inddata.message_len, e2sm_decodedata.message_len);
-       for (int i = 0; i < e2sm_inddata.message_len; ++i) {
-         EXPECT_EQ(e2sm_inddata.message[i], e2sm_decodedata.message[i]) << "Encoded and Decoded Msg differ at index " << i;
+       unsigned char e2ap_buff[4096];
+       char filename[100] = "indication2.per";
+       FILE *fp;
+       fp = fopen(filename,"rb");
+       if(!fp) {
+                    perror(filename);
+                    exit(1); }
+
+          size_t e2ap_buff_size = fread(e2ap_buff, 1, 4096, fp);
+          fclose(fp);
+       if(!e2ap_buff_size){
+             fprintf(stderr, "%s: Empty or broken\n", filename);
+              exit(1);
+                  } else {
+              fprintf(stderr, "e2ap buffer size: %ld \n", e2ap_buff_size);
+       }
+
+    bool decode_status = true;
+    try{
+       E2APIndication<HWIndicationHeader,HWIndicationMessage> e2obj(&e2ap_buff[0],&e2ap_buff_size);
+       E2APIndication<HWIndicationHeader,HWIndicationMessage>::IndicationIEs indIEs = e2obj.getIndicationIEs();
+       std::cout << indIEs.get_ricRequestorID() << std::endl;
+
+       size_t hsize = indIEs.get_ricIndicationHeader_size();
+       unsigned char* hvalue = (unsigned char*)indIEs.get_ricIndicationHeader();
+       HWIndicationHeader headerObj(&hvalue[0], &hsize);
+
+         size_t msize = indIEs.get_ricIndicationMessage_size();
+         auto mvalue = (unsigned char*)indIEs.get_ricIndicationMessage();
+         HWIndicationMessage msgObj(&mvalue[0], &msize);
+
+    } catch(const char* e){
+               decode_status = false;
+               std::cout << "Error Message: " << e << std::endl;
        }
 
 
+       ASSERT_TRUE(decode_status);
+
 }
 
 TEST(E2SM, ControlMessage)
 {
 
-       unsigned char header_buf[128];
-       size_t header_buf_len = 128;
-
-       unsigned char msg_buf[128];
-       size_t msg_buf_len = 128;
-
-       bool res;
-       asn_dec_rval_t retval;
+       unsigned char buff[1024];
+       size_t buf_len = 1024;
 
 
-       e2sm_control_helper e2sm_cntrldata;
-       e2sm_control e2sm_cntrl;
 
-       unsigned char msg[20] = "HelloWorld";
+       HWControlMessage msgObj;
+       msgObj.set_ricControlMessage("ControlMessage");
 
-       e2sm_cntrldata.header = 1001;
-       e2sm_cntrldata.message = msg;
-       e2sm_cntrldata.message_len = strlen((const char*)e2sm_cntrldata.message);
+       HWControlHeader headObj;
+       headObj.set_ricControlHeader(1);
 
+       E2APControlMessage<HWControlHeader,HWControlMessage>::ControlRequestIEs infoObj;
+       infoObj.set_ranFunctionID(1);
+       infoObj.set_ricRequestorID(1);
+       infoObj.set_ricControlHeader(headObj);
+       infoObj.set_ricControlMessage(msgObj);
 
-       // Encode the indication header
-       res = e2sm_cntrl.encode_control_header(&header_buf[0], &header_buf_len, e2sm_cntrldata);
-       if(!res)
-               std::cout << e2sm_cntrl.get_error() << std::endl;
 
-       ASSERT_TRUE(res);
+       E2APControlMessage<HWControlHeader,HWControlMessage>  cntrlObj(infoObj);
 
-       // Encode the indication message
-       res = e2sm_cntrl.encode_control_message(&msg_buf[0], &msg_buf_len, e2sm_cntrldata);
-       if(!res)
-               std::cout << e2sm_cntrl.get_error() << std::endl;
-       ASSERT_TRUE(res);
+       bool res = cntrlObj.encode(buff, &buf_len);
+               if(!res)
+               {
+                       std::cout << cntrlObj.get_error() << std::endl;
+               }
+               ASSERT_TRUE(res);
 }
 
 #endif /* TEST_TEST_ASN_H_ */