ISSUE ID:- RICAPP-216
[ric-app/bouncer.git] / Bouncer / e2sm_kpm / wrapper.c
1 #include <errno.h>
2 #include "wrapper.h"
3 #include <stdio.h>
4
5
6 // int main() {
7
8 //      long id[] = {1,2,3,4};
9
10 //      void *buffer[8] = {} ;
11 //      unsigned int sizeBuffer = 8;
12 //      long actionDefCount = 8;
13 //      long measId = 1;
14 //      long ricStyleType = 1;
15 //      long periods = 1;
16 //      void *plm[8] = {} ;
17 //      unsigned int sizePlm = 8;
18 //      void *nRc[8] = {} ;
19 //      unsigned int sizenRc = 8;
20
21 //      int a = e2sm_encode_ric_action_definition(buffer, sizeBuffer, actionDefCount, measId, ricStyleType, periods, plm, nRc);
22
23 //      printf("%d", a);
24
25 //      return 0;
26 // }
27
28 ssize_t e2sm_encode_ric_event_trigger_definition(void *buffer, size_t buf_size, size_t event_trigger_count, long *RT_periods) {
29         E2SM_KPM_EventTriggerDefinition_t *eventTriggerDef = (E2SM_KPM_EventTriggerDefinition_t *)calloc(1, sizeof(E2SM_KPM_EventTriggerDefinition_t));
30         if(!eventTriggerDef) {
31                 fprintf(stderr, "Alloc EventTriggerDefinition failed\n");
32                 return -1;
33         }
34
35         E2SM_KPM_EventTriggerDefinition_Format1_t *innerDef = (E2SM_KPM_EventTriggerDefinition_Format1_t *)calloc(1, sizeof(E2SM_KPM_EventTriggerDefinition_Format1_t));
36         if(!innerDef) {
37                 fprintf(stderr, "alloc EventTriggerDefinition Format1 failed\n");
38                 ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_EventTriggerDefinition, eventTriggerDef);
39                 return -1;
40         }
41
42         eventTriggerDef->eventDefinition_formats.present = E2SM_KPM_EventTriggerDefinition__eventDefinition_formats_PR_eventDefinition_Format1;
43         eventTriggerDef->eventDefinition_formats.choice.eventDefinition_Format1 = innerDef;
44
45         // struct E2SM_KPM_EventTriggerDefinition_Format1__policyTest_List *policyTestList = (struct E2SM_KPM_EventTriggerDefinition_Format1__policyTest_List *)calloc(1, sizeof(struct E2SM_KPM_EventTriggerDefinition_Format1__policyTest_List));
46         // innerDef->policyTest_List = policyTestList;
47         
48         // int index = 0;
49         // while(index < event_trigger_count) {
50         //      Trigger_ConditionIE_Item *triggerCondition = (Trigger_ConditionIE_Item *)calloc(1, sizeof(Trigger_ConditionIE_Item));
51         //      assert(triggerCondition != 0);
52         //      triggerCondition->report_Period_IE = RT_periods[index];
53         //      ASN_SEQUENCE_ADD(&policyTestList->list, triggerCondition);
54         //      index++;
55         // }
56
57         asn_enc_rval_t encode_result;
58     encode_result = uper_encode_to_buffer(&asn_DEF_E2SM_KPM_EventTriggerDefinition, NULL, eventTriggerDef, buffer, buf_size);
59     ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_EventTriggerDefinition, eventTriggerDef);
60     if(encode_result.encoded == -1) {
61         fprintf(stderr, "Cannot encode %s: %s\n", encode_result.failed_type->name, strerror(errno));
62         return -1;
63     } else {
64             return encode_result.encoded;
65         }
66 }
67 // int main() {
68
69 //      long id[] = {1,2,3,4};
70
71 //      void *buffer[8] = {} ;
72 //      unsigned int sizeBuffer = 8;
73 //      long actionDefCount = 8;
74 //      long measId = 1;
75 //      long ricStyleType = 1;
76 //      long periods = 1;
77 //      void *plm[8] = {} ;
78 //      unsigned int sizePlm = 8;
79 //      void *nRc[8] = {} ;
80 //      unsigned int sizenRc = 8;
81
82 //      int a = e2sm_encode_ric_action_definition(buffer, sizeBuffer, actionDefCount, measId, ricStyleType, periods, plm, nRc);
83
84 //      printf("%d", a);
85
86 //      return 0;
87 // }
88
89 /*
90 ssize_t e2sm_encode_ric_action_definition(void *buffer, size_t buf_size, long action_Def_count, long meas_ID, long ric_style_type, long GR_periods, Plm plm, Nrc nRc) {
91         E2SM_KPM_ActionDefinition_t *actionDef = (E2SM_KPM_ActionDefinition_t *)calloc(1, sizeof(E2SM_KPM_ActionDefinition_t));
92         if(!actionDef) {
93                 fprintf(stderr, "alloc RIC ActionDefinition failed\n");
94                 return -1;
95         }
96
97         E2SM_KPM_ActionDefinition_Format1_t *actionDefFor1 = (E2SM_KPM_ActionDefinition_Format1_t *)calloc(1, sizeof(E2SM_KPM_ActionDefinition_Format1_t));
98         if(!actionDefFor1) {
99                 ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_ActionDefinition, actionDef);
100                 fprintf(stderr, "alloc RIC ActionDefinition failed\n");
101                 return -1;
102         }
103         CGI_t *cellGlobal = (CGI_t *)calloc(1, sizeof(CGI_t));
104         if(!cellGlobal) {
105                 fprintf(stderr, "alloc RIC ActionDefinition failed\n");
106                 return -1;
107         }
108
109         NR_CGI_t *nrCGIs = (NR_CGI_t *)calloc(1, sizeof(NR_CGI_t));
110         if(!nrCGIs) {
111                 fprintf(stderr, "alloc RIC ActionDefinition failed\n");
112                 return -1;
113         }
114
115         actionDef->ric_Style_Type = ric_style_type;
116         actionDef->actionDefinition_formats.present = E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format1;
117         actionDef->actionDefinition_formats.choice.actionDefinition_Format1 = actionDefFor1;
118         actionDefFor1->granulPeriod = GR_periods;
119         actionDefFor1->cellGlobalID = cellGlobal;
120         cellGlobal->present = CGI_PR_nR_CGI;
121         cellGlobal->choice.nR_CGI = nrCGIs;
122
123
124         int plmSize = plm.size;
125         if(plmSize != 0) {
126
127         }
128
129     PLMNIdentity_t *plms = &nrCGIs->pLMNIdentity;
130     plms->buf = (uint8_t *)calloc(1, plmSize);
131     if(!plms->buf) {
132         fprintf(stderr, "alloc plms failed\n");
133             ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_ActionDefinition, actionDef);
134         return -1;
135     }
136
137     memcpy(plms->buf, plm.plms, plmSize);
138     plms->size = plmSize;
139         
140
141         int nRcSize = nRc.size;
142
143         NRCellIdentity_t *nRCs = &nrCGIs->nRCellIdentity;
144     nRCs->buf = (uint8_t *)calloc(1, nRcSize);
145     if(!nRCs->buf) {
146         fprintf(stderr, "alloc nRCs failed\n");
147             ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_ActionDefinition, actionDef);
148         return -1;
149     }
150
151     memcpy(nRCs->buf, nRc.nRcs, nRcSize);
152     nRCs->size = nRcSize; 
153
154
155         MeasurementInfoList_t *infoList = &actionDefFor1->measInfoList;
156         
157         int index = 0;
158         while(index < action_Def_count) {
159                 MeasurementInfoItem_t *infoItem = (MeasurementInfoItem_t *)calloc(1, sizeof(MeasurementInfoItem_t));
160                 // if(!infoItem) {
161                 //      fprintf(stderr, "alloc Measurement Info Item failed\n");
162                 //     ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_ActionDefinition, actionDef);
163                 // return -1;
164                 // }
165                 assert(infoItem != 0);
166
167         
168                 MeasurementType_t *measureType = &infoItem->measType;
169
170                 measureType->present = MeasurementType_PR_measID;
171                 measureType->choice.measID = meas_ID;
172
173
174                 LabelInfoList_t *lableList = &infoItem->labelInfoList;
175
176                 ASN_SEQUENCE_ADD(&infoList->list, infoItem);
177         index++;
178         }
179
180         asn_enc_rval_t encode_result;
181     encode_result = uper_encode_to_buffer(&asn_DEF_E2SM_KPM_ActionDefinition, NULL,actionDef, buffer, buf_size);
182     ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_ActionDefinition, actionDef);
183
184         if(encode_result.encoded == -1) {
185             fprintf(stderr, "Cannot encode %s: %s\n", encode_result.failed_type->name, strerror(errno));
186             return -1;
187         } else {
188                 fprintf(stderr, "successfully\n");
189         return encode_result.encoded;
190     }
191 }
192 */
193 E2SM_KPM_IndicationHeader_t* e2sm_decode_ric_indication_header(void *buffer, size_t buf_size) {
194         asn_dec_rval_t decode_result;
195     E2SM_KPM_IndicationHeader_t *indHdr = 0;
196      //fprintf(stderr, "\nbuffer= %p",buffer);
197         //fprintf(stdout, "\nbuf_size=%ld",buf_size);
198         //fprintf(stdout, "\nE2SM_KPM_IndicationHeader_t_size=%ld",sizeof(E2SM_KPM_IndicationHeader_t));
199    //decode_result = uper_decode_complete(NULL, &asn_DEF_E2SM_KPM_IndicationHeader, (void **)&indHdr, (char*)buffer, buf_size);
200    //ATS_ALIGNED_CANONICAL_PER
201     decode_result =asn_decode(0,ATS_ALIGNED_BASIC_PER,&asn_DEF_E2SM_KPM_IndicationHeader,(void **)&indHdr,buffer,buf_size);
202     if(decode_result.code == RC_OK) {
203         // xer_fprint(stderr, &asn_DEF_E2SM_KPM_IndicationHeader, indHdr);
204         return indHdr;
205     }
206      else if (decode_result.code ==RC_WMORE ) {
207         //xer_fprint(stderr, &asn_DEF_E2SM_KPM_IndicationHeader, indHdr);
208          //fprintf(stderr, "\n decode_result.consumed= %ld \n",decode_result.consumed);
209         fprintf(stderr, "\nheader RC_WMORE ");
210         return indHdr;
211         }
212
213     else {
214         ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationHeader, indHdr);
215         return NULL;
216     }
217 }
218
219 void e2sm_free_ric_indication_header(E2SM_KPM_IndicationHeader_t* indHdr) {
220         ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationHeader, indHdr);
221 }
222
223 E2SM_KPM_IndicationMessage_t* e2sm_decode_ric_indication_message(void *buffer, size_t buf_size) {
224         asn_dec_rval_t decode_result;
225      E2SM_KPM_IndicationMessage_t *indMsg = 0;
226      //fprintf(stdout, "\nbuffer= %p",buffer);
227      //fprintf(stdout, "\nbuf_size=%ld",buf_size);
228      //fprintf(stdout, "\nE2SM_KPM_IndicationMessage_t size=%ld",sizeof(E2SM_KPM_IndicationMessage_t));
229     //decode_result = uper_decode_complete(NULL, &asn_DEF_E2SM_KPM_IndicationMessage, (void **)&indMsg, (char *)buffer, buf_size);
230     //ATS_ALIGNED_CANONICAL_PER
231    decode_result =asn_decode(0,ATS_ALIGNED_BASIC_PER,&asn_DEF_E2SM_KPM_IndicationMessage,(void **)&indMsg,buffer,buf_size);
232     if(decode_result.code == RC_OK) {
233             //xer_fprint(stdout, &asn_DEF_E2SM_KPM_IndicationMessage, indMsg);
234         return indMsg;
235     }
236      else if (decode_result.code ==RC_WMORE ) {
237          //xer_fprint(stderr, &asn_DEF_E2SM_KPM_IndicationMessage, indMsg);
238          //fprintf(stderr, "\n MSG decode_result.consumed= %ld \n",decode_result.consumed);
239              fprintf(stderr, "\n MSG RC_WMORE ");
240              return NULL;
241      }
242
243     else {
244         ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationMessage, indMsg);
245         return NULL;
246     }
247 }
248
249 void e2sm_free_ric_indication_message(E2SM_KPM_IndicationMessage_t* indMsg) {
250         ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_IndicationMessage, indMsg);
251 }
252