Fix wrong usage of memory.
[sim/e2-interface.git] / e2sim / e2sm_examples / kpm_e2sm / src / kpm / encode_kpm.cpp
1 /*****************************************************************************
2 #                                                                            *
3 # Copyright 2020 AT&T Intellectual Property                                  *
4 #                                                                            *
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                                    *
8 #                                                                            *
9 #      http://www.apache.org/licenses/LICENSE-2.0                            *
10 #                                                                            *
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 #                                                                            *
17 ******************************************************************************/
18
19 #include <stdio.h>
20 #include <string.h>
21 #include <iostream>
22 #include <unistd.h>
23 #include <vector>
24
25 #include "encode_kpm.hpp"
26
27 using namespace std;
28
29 void encode_kpm_function_description(E2SM_KPM_RANfunction_Description_t* ranfunc_desc) {
30
31   printf("kpm0\n");
32
33   uint8_t *buf = (uint8_t*)"ORAN-E2SM-KPM";
34   uint8_t *buf2 = (uint8_t*)"KPM monitor";
35   uint8_t *buf3 = (uint8_t*)"OID123";
36   long inst = 1;
37
38   ASN_STRUCT_RESET(asn_DEF_E2SM_KPM_RANfunction_Description, ranfunc_desc);
39
40   ranfunc_desc->ranFunction_Name.ranFunction_ShortName.size = strlen((char*)buf);
41   ranfunc_desc->ranFunction_Name.ranFunction_ShortName.buf = (uint8_t*)calloc(strlen((char*)buf), sizeof(uint8_t));
42   memcpy(ranfunc_desc->ranFunction_Name.ranFunction_ShortName.buf, buf, ranfunc_desc->ranFunction_Name.ranFunction_ShortName.size);
43
44   //  ranfunc_desc->ranFunction_Name.ranFunction_Description = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
45   ranfunc_desc->ranFunction_Name.ranFunction_Description.buf = (uint8_t*)calloc(1,strlen((char*)buf2));
46   memcpy(ranfunc_desc->ranFunction_Name.ranFunction_Description.buf, buf2, strlen((char*)buf2));
47   ranfunc_desc->ranFunction_Name.ranFunction_Description.size = strlen((char*)buf2);
48   ranfunc_desc->ranFunction_Name.ranFunction_Instance = &inst;
49
50   printf("kpm0.9\n");
51
52   //  ranfunc_desc->ranFunction_Name.ranFunction_E2SM_OID = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
53   ranfunc_desc->ranFunction_Name.ranFunction_E2SM_OID.buf = (uint8_t*)calloc(1,strlen((char*)buf3));
54   memcpy(ranfunc_desc->ranFunction_Name.ranFunction_E2SM_OID.buf, buf3, strlen((char*)buf3));
55   ranfunc_desc->ranFunction_Name.ranFunction_E2SM_OID.size = strlen((char*)buf3);
56
57   printf("kpm2\n");
58   
59
60   RIC_EventTriggerStyle_List_t *trigger_style =
61     (RIC_EventTriggerStyle_List_t*)calloc(1, sizeof(RIC_EventTriggerStyle_List_t));
62   trigger_style->ric_EventTriggerStyle_Type = 1;
63   uint8_t *buf4 = (uint8_t*)"Periodic report";
64   //  trigger_style->ric_EventTriggerStyle_Name = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
65   trigger_style->ric_EventTriggerStyle_Name.buf = (uint8_t*)calloc(1,strlen((char*)buf4));
66   memcpy(trigger_style->ric_EventTriggerStyle_Name.buf, buf4, strlen((char*)buf4));
67   trigger_style->ric_EventTriggerStyle_Name.size = strlen((char*)buf4);
68   trigger_style->ric_EventTriggerFormat_Type = 5;
69
70   printf("kpm3\n");
71
72   ranfunc_desc->e2SM_KPM_RANfunction_Item.ric_EventTriggerStyle_List =
73     (E2SM_KPM_RANfunction_Description::E2SM_KPM_RANfunction_Description__e2SM_KPM_RANfunction_Item::E2SM_KPM_RANfunction_Description__e2SM_KPM_RANfunction_Item__ric_EventTriggerStyle_List*)calloc(1,sizeof(E2SM_KPM_RANfunction_Description::E2SM_KPM_RANfunction_Description__e2SM_KPM_RANfunction_Item::E2SM_KPM_RANfunction_Description__e2SM_KPM_RANfunction_Item__ric_EventTriggerStyle_List));
74
75   int ret = ASN_SEQUENCE_ADD(&ranfunc_desc->e2SM_KPM_RANfunction_Item.ric_EventTriggerStyle_List->list , trigger_style);
76   printf("ret is %d\n", ret);
77
78   RIC_ReportStyle_List_t *report_style1 = (RIC_ReportStyle_List_t*)calloc(1, sizeof(RIC_ReportStyle_List_t));
79   report_style1->ric_ReportStyle_Type = 1;
80
81   uint8_t *buf5 = (uint8_t*)"O-DU Measurement Container for the 5GC connected deployment";
82
83   printf("kpm4\n");  
84   
85   //  report_style1->ric_ReportStyle_Name = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
86   report_style1->ric_ReportStyle_Name.buf = (uint8_t*)calloc(1,strlen((char*)buf5));
87   memcpy(report_style1->ric_ReportStyle_Name.buf, buf5, strlen((char*)buf5));
88   report_style1->ric_ReportStyle_Name.size = strlen((char*)buf5);  
89   report_style1->ric_IndicationHeaderFormat_Type = 1;
90   report_style1->ric_IndicationMessageFormat_Type = 1;
91   
92   printf("kpm5\n");  
93
94   RIC_ReportStyle_List_t *report_style2 = (RIC_ReportStyle_List_t*)calloc(1, sizeof(RIC_ReportStyle_List_t));
95   report_style2->ric_ReportStyle_Type = 2;
96   
97   uint8_t *buf6 = (uint8_t*)"O-DU Measurement Container for the EPC connected deployment";
98   
99   //  report_style2->ric_ReportStyle_Name = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
100
101   
102   report_style2->ric_ReportStyle_Name.buf = (uint8_t*)calloc(1,strlen((char*)buf6));
103   memcpy(report_style2->ric_ReportStyle_Name.buf, buf6, strlen((char*)buf6));
104   report_style2->ric_ReportStyle_Name.size = strlen((char*)buf6);  
105   report_style2->ric_IndicationHeaderFormat_Type = 1;
106   report_style2->ric_IndicationMessageFormat_Type = 1;
107
108   printf("kpm6\n");  
109
110   RIC_ReportStyle_List_t *report_style3 = (RIC_ReportStyle_List_t*)calloc(1, sizeof(RIC_ReportStyle_List_t));
111   report_style3->ric_ReportStyle_Type = 3;
112
113   uint8_t *buf7 = (uint8_t*)"O-CU-CP Measurement Container for the 5GC connected deployment";
114
115   //  report_style3->ric_ReportStyle_Name = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
116   report_style3->ric_ReportStyle_Name.buf = (uint8_t*)calloc(1,strlen((char*)buf7));
117   memcpy(report_style3->ric_ReportStyle_Name.buf, buf7, strlen((char*)buf7));
118   report_style3->ric_ReportStyle_Name.size = strlen((char*)buf7);
119   report_style3->ric_IndicationHeaderFormat_Type = 1;
120   report_style3->ric_IndicationMessageFormat_Type = 1;
121
122   RIC_ReportStyle_List_t *report_style4 = (RIC_ReportStyle_List_t*)calloc(1, sizeof(RIC_ReportStyle_List_t));
123   report_style4->ric_ReportStyle_Type = 4;
124
125   uint8_t *buf8 = (uint8_t*)"O-CU-CP Measurement Container for the EPC connected deployment";
126
127   //  report_style3->ric_ReportStyle_Name = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
128   report_style4->ric_ReportStyle_Name.buf = (uint8_t*)calloc(1,strlen((char*)buf8));
129   memcpy(report_style4->ric_ReportStyle_Name.buf, buf8, strlen((char*)buf8));
130   report_style4->ric_ReportStyle_Name.size = strlen((char*)buf8);
131   report_style4->ric_IndicationHeaderFormat_Type = 1;
132   report_style4->ric_IndicationMessageFormat_Type = 1;
133
134   RIC_ReportStyle_List_t *report_style5 = (RIC_ReportStyle_List_t*)calloc(1, sizeof(RIC_ReportStyle_List_t));
135   report_style5->ric_ReportStyle_Type = 5;
136
137   uint8_t *buf9 = (uint8_t*)"O-CU-UP Measurement Container for the 5GC connected deployment";
138
139   //  report_style3->ric_ReportStyle_Name = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
140   report_style5->ric_ReportStyle_Name.buf = (uint8_t*)calloc(1,strlen((char*)buf9));
141   memcpy(report_style5->ric_ReportStyle_Name.buf, buf9, strlen((char*)buf9));
142   report_style5->ric_ReportStyle_Name.size = strlen((char*)buf9);
143   report_style5->ric_IndicationHeaderFormat_Type = 1;
144   report_style5->ric_IndicationMessageFormat_Type = 1;
145
146
147   RIC_ReportStyle_List_t *report_style6 = (RIC_ReportStyle_List_t*)calloc(1, sizeof(RIC_ReportStyle_List_t));
148   report_style6->ric_ReportStyle_Type = 6;
149
150   uint8_t *buf10 = (uint8_t*)"O-CU-UP Measurement Container for the EPC connected deployment";
151
152   //  report_style3->ric_ReportStyle_Name = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
153   report_style6->ric_ReportStyle_Name.buf = (uint8_t*)calloc(1,strlen((char*)buf10));
154   memcpy(report_style6->ric_ReportStyle_Name.buf, buf10, strlen((char*)buf10));
155   report_style6->ric_ReportStyle_Name.size = strlen((char*)buf10);
156   report_style6->ric_IndicationHeaderFormat_Type = 1;
157   report_style6->ric_IndicationMessageFormat_Type = 1;
158   
159
160   ranfunc_desc->e2SM_KPM_RANfunction_Item.ric_ReportStyle_List =
161     (E2SM_KPM_RANfunction_Description::E2SM_KPM_RANfunction_Description__e2SM_KPM_RANfunction_Item::E2SM_KPM_RANfunction_Description__e2SM_KPM_RANfunction_Item__ric_ReportStyle_List*)calloc(1,sizeof(E2SM_KPM_RANfunction_Description::E2SM_KPM_RANfunction_Description__e2SM_KPM_RANfunction_Item::E2SM_KPM_RANfunction_Description__e2SM_KPM_RANfunction_Item__ric_ReportStyle_List));
162   
163   ASN_SEQUENCE_ADD(&ranfunc_desc->e2SM_KPM_RANfunction_Item.ric_ReportStyle_List->list, report_style1);
164   ASN_SEQUENCE_ADD(&ranfunc_desc->e2SM_KPM_RANfunction_Item.ric_ReportStyle_List->list, report_style2);
165   ASN_SEQUENCE_ADD(&ranfunc_desc->e2SM_KPM_RANfunction_Item.ric_ReportStyle_List->list, report_style3);
166   ASN_SEQUENCE_ADD(&ranfunc_desc->e2SM_KPM_RANfunction_Item.ric_ReportStyle_List->list, report_style4);
167   ASN_SEQUENCE_ADD(&ranfunc_desc->e2SM_KPM_RANfunction_Item.ric_ReportStyle_List->list, report_style5);
168   ASN_SEQUENCE_ADD(&ranfunc_desc->e2SM_KPM_RANfunction_Item.ric_ReportStyle_List->list, report_style6);
169
170   xer_fprint(stderr, &asn_DEF_E2SM_KPM_RANfunction_Description, ranfunc_desc);
171
172 }
173
174 void encode_e2sm_kpm_indication_header(E2SM_KPM_IndicationHeader_t *ihead, uint8_t *plmnid_buf, uint8_t *sst_buf, uint8_t *sd_buf,
175                                        long fqival, long qcival, uint8_t *nrcellid_buf, uint8_t *gnbid_buf, int gnbid_unused,
176                                        uint8_t *cuupid_buf, uint8_t *duid_buf, uint8_t *cuupname_buf) {
177
178   
179   //uint8_t *plmnid_buf = (uint8_t*)"747";
180   //uint8_t *sst_buf = (uint8_t*)"1";
181   //uint8_t *sd_buf = (uint8_t*)"100";
182   
183   E2SM_KPM_IndicationHeader_Format1_t* ind_header =
184     (E2SM_KPM_IndicationHeader_Format1_t*)calloc(1,sizeof(E2SM_KPM_IndicationHeader_Format1_t));
185   
186   OCTET_STRING_t *plmnid = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
187   plmnid->buf = (uint8_t*)calloc(3,1);
188   plmnid->size = 3;
189   memcpy(plmnid->buf, plmnid_buf, plmnid->size);
190   
191   //  long fqival = 9;
192   //  long qcival = 9;
193   
194   SNSSAI_t *snssai = (SNSSAI_t*)calloc(1, sizeof(SNSSAI_t));
195   ASN_STRUCT_RESET(asn_DEF_SNSSAI,snssai);
196   snssai->sST.buf = (uint8_t*)calloc(1,1);
197   snssai->sST.size = 1;
198   memcpy(snssai->sST.buf, sst_buf, 1);
199   snssai->sD = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
200   snssai->sD->buf = (uint8_t*)calloc(1,3);
201   snssai->sD->size = 3;
202   memcpy(snssai->sD->buf, sd_buf, 3);
203       
204   BIT_STRING_t *nrcellid = (BIT_STRING_t*)calloc(1, sizeof(BIT_STRING_t));;
205   nrcellid->buf = (uint8_t*)calloc(1,5);
206   nrcellid->size = 5;
207   memcpy(nrcellid->buf, nrcellid_buf, 5);
208   /*
209   nrcellid->buf[0] = 0x22;
210   nrcellid->buf[1] = 0x5B;
211   nrcellid->buf[2] = 0xD6;
212   nrcellid->buf[3] = 0x00;
213   nrcellid->buf[4] = 0x70;
214   */  
215   nrcellid->bits_unused = 4;
216   
217   BIT_STRING_t *gnb_bstring = (BIT_STRING_t*)calloc(1, sizeof(BIT_STRING_t));;
218   gnb_bstring->buf = (uint8_t*)calloc(1,4);
219   gnb_bstring->size = 4;
220   memcpy(gnb_bstring->buf, gnbid_buf, 4);
221   /*
222   gnb_bstring->buf[0] = 0xB5;
223   gnb_bstring->buf[1] = 0xC6;
224   gnb_bstring->buf[2] = 0x77;
225   gnb_bstring->buf[3] = 0x88;
226   */
227   
228   gnb_bstring->bits_unused = gnbid_unused;
229   
230   INTEGER_t *cuup_id = (INTEGER_t*)calloc(1, sizeof(INTEGER_t));
231   //  uint8_t buffer[1];
232   //  buffer[0] = 20000;
233   cuup_id->buf = (uint8_t*)calloc(1,1);
234   memcpy(cuup_id->buf, cuupid_buf, 1);
235   cuup_id->size = 1;
236
237   INTEGER_t *du_id = (INTEGER_t*)calloc(1, sizeof(INTEGER_t));
238   //  uint8_t buffer_duid[1];
239   //  buffer_duid[0] = 20000;
240   du_id->buf = (uint8_t*)calloc(1,1);
241   memcpy(du_id->buf, duid_buf, 1);
242   du_id->size = 1;
243
244
245   //  uint8_t *buf5 = (uint8_t*)"GNBCUUP5";
246   OCTET_STRING_t *cuupname = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
247   cuupname->size = 8;
248   cuupname->buf = (uint8_t*)calloc(1,8);
249   memcpy(cuupname->buf, cuupname_buf, cuupname->size);
250
251
252   ind_header->id_GlobalKPMnode_ID = (GlobalKPMnode_ID*)calloc(1,sizeof(GlobalKPMnode_ID));
253   ind_header->id_GlobalKPMnode_ID->present = GlobalKPMnode_ID_PR_gNB;
254   ind_header->id_GlobalKPMnode_ID->choice.gNB.global_gNB_ID.gnb_id.present = GNB_ID_Choice_PR_gnb_ID;
255   ind_header->id_GlobalKPMnode_ID->choice.gNB.global_gNB_ID.gnb_id.choice.gnb_ID = *gnb_bstring;
256   ind_header->id_GlobalKPMnode_ID->choice.gNB.global_gNB_ID.plmn_id = *plmnid;
257   ind_header->id_GlobalKPMnode_ID->choice.gNB.gNB_CU_UP_ID = cuup_id;
258
259
260   
261   ind_header->nRCGI = (NRCGI*)calloc(1,sizeof(NRCGI));
262   ind_header->nRCGI->pLMN_Identity = *plmnid;
263   ind_header->nRCGI->nRCellIdentity = *nrcellid;
264   if (nrcellid) free(nrcellid);
265   
266   ind_header->pLMN_Identity = plmnid;
267   //  memcpy(ind_header->fiveQI, &fqival, 4);
268   
269   ind_header->sliceID = snssai;
270   //  memcpy(ind_header->qci, &qcival, 4);
271
272
273   ind_header->gNB_Name = (GNB_Name*)calloc(1,sizeof(GNB_Name));
274   ind_header->gNB_Name->present = GNB_Name_PR_gNB_CU_UP_Name;
275   ind_header->gNB_Name->choice.gNB_CU_UP_Name = *cuupname;
276   if (cuupname) free(cuupname);
277
278  
279   ind_header->global_GNB_ID = (GlobalgNB_ID*)calloc(1,sizeof(GlobalgNB_ID));
280   ind_header->global_GNB_ID->plmn_id = *plmnid;
281   ind_header->global_GNB_ID->gnb_id.present = GNB_ID_Choice_PR_gnb_ID;
282   ind_header->global_GNB_ID->gnb_id.choice.gnb_ID = *gnb_bstring;
283
284
285   //  long msg_type = 2;
286   //  ind_header->message_Type = &msg_type;
287   ind_header->gNB_DU_ID = du_id;
288
289   
290   ihead->present = E2SM_KPM_IndicationHeader_PR_indicationHeader_Format1;
291   ihead->choice.indicationHeader_Format1 = *ind_header;
292   if (ind_header) free(ind_header);
293   
294   xer_fprint(stderr, &asn_DEF_E2SM_KPM_IndicationHeader, ihead);
295   
296 }
297
298
299
300 void encode_kpm_ocuup_user_level(RAN_Container_t *ranco,
301                                  uint8_t *plmnid_buf,
302                                  uint8_t *nrcellid_buf,
303                                  uint8_t *crnti_buf,
304                                  int bytes_dl,
305                                  int bytes_ul) {
306
307   uint8_t *buf = (uint8_t*)"2020.06.13 13:01:05.222";
308   Timestamp_t *ts = (Timestamp_t*)calloc(1,sizeof(Timestamp_t));
309   ts->buf = (uint8_t*)calloc(strlen((char*)buf),1);
310   ts->size = strlen((char*)buf);
311   memcpy(ts->buf,buf,ts->size);
312
313   printf("enc1\n");
314
315   CU_UP_Usage_Report_CellResourceReportItem_t  *report_item =
316     (CU_UP_Usage_Report_CellResourceReportItem_t*)calloc(1,sizeof(CU_UP_Usage_Report_CellResourceReportItem_t));
317
318   //  uint8_t *buf2 = (uint8_t*)"747";
319   
320   OCTET_STRING_t *plmnidstr = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
321   plmnidstr->buf = (uint8_t*)calloc(3,1);
322   plmnidstr->size = 3;
323   memcpy(plmnidstr->buf, plmnid_buf, plmnidstr->size);
324
325   printf("enc2\n");  
326
327   NRCellIdentity_t *nrcellid = (NRCellIdentity_t*)calloc(1,sizeof(NRCellIdentity_t));
328   //  uint8_t* buf3 = (uint8_t*)"12340";
329   nrcellid->buf = (uint8_t*)calloc(1,5);
330   memcpy(nrcellid->buf, nrcellid_buf, 5);
331   nrcellid->size = 5;
332   nrcellid->bits_unused = 4;
333
334   NRCGI *nrcgi = (NRCGI*)calloc(1,sizeof(NRCGI));
335   nrcgi->pLMN_Identity = *plmnidstr;
336   nrcgi->nRCellIdentity = *nrcellid;
337   if (plmnidstr) free(plmnidstr);
338   if (nrcellid) free(nrcellid);
339  
340   printf("enc3\n");
341   
342   report_item->nRCGI = *nrcgi;
343   if (nrcgi) free(nrcgi);
344
345   CU_UP_Usage_Report_UeResourceReportItem *ue_report_item =
346     (CU_UP_Usage_Report_UeResourceReportItem*)calloc(1,sizeof(CU_UP_Usage_Report_UeResourceReportItem));
347
348   printf("enc3.2\n");   
349   
350   //  uint8_t* crnti_str = (uint8_t*)"1111";
351   OCTET_STRING *crnti = (OCTET_STRING*)calloc(1,sizeof(OCTET_STRING));
352   crnti->buf = (uint8_t*)calloc(1,4);
353   
354   printf("enc3.3\n");
355   
356   crnti->size = strlen((char*)crnti_buf);
357
358   printf("enc3.4\n");
359   memcpy(crnti->buf, crnti_buf, crnti->size);
360
361   printf("enc4\n");
362
363   INTEGER_t *bytesdl = (INTEGER_t*)calloc(1, sizeof(INTEGER_t));
364   int array_size_dl;
365
366   if (bytes_dl <= 64) {
367     array_size_dl = 1;
368
369     uint8_t buffer[array_size_dl];
370     buffer[0] = bytes_dl & 0xFF;
371     bytesdl->buf = (uint8_t*)calloc(1,1);
372     memcpy(bytesdl->buf,buffer,1);
373     bytesdl->size = 1;
374
375   } else if (bytes_dl <= 16384) {
376     array_size_dl = 2;
377
378     uint8_t buffer[array_size_dl];
379     buffer[0] = (bytes_dl >> 8) & 0xFF;
380     buffer[1] = bytes_dl & 0xFF;
381     bytesdl->buf = (uint8_t*)calloc(2,1);
382     memcpy(bytesdl->buf,buffer,2);
383     bytesdl->size = 2;
384     
385   } else if (bytes_dl <= 4194304) {
386     array_size_dl = 3;
387
388     uint8_t buffer[array_size_dl];
389     buffer[0] = (bytes_dl >> 16) & 0xFF;
390     buffer[1] = (bytes_dl >> 8) & 0xFF;
391     buffer[2] = bytes_dl & 0xFF;
392     bytesdl->buf = (uint8_t*)calloc(3,1);
393     memcpy(bytesdl->buf,buffer,3);
394     bytesdl->size = 3;    
395     
396   } else if (bytes_dl <= 1073741824) {
397     array_size_dl = 4;
398     uint8_t buffer[array_size_dl];
399     buffer[0] = (bytes_dl >> 24) & 0xFF;
400     buffer[1] = (bytes_dl >> 16) & 0xFF;
401     buffer[2] = (bytes_dl >> 8) & 0xFF;
402     buffer[3] = bytes_dl & 0xFF;
403     bytesdl->buf = (uint8_t*)calloc(4,1);
404     memcpy(bytesdl->buf,buffer,4);
405     bytesdl->size = 4;
406   }
407   
408
409   INTEGER_t *bytesul = (INTEGER_t*)calloc(1, sizeof(INTEGER_t));
410
411   int array_size_ul;
412
413   if (bytes_ul <= 64) {
414     array_size_ul = 1;
415
416     uint8_t buffer[array_size_ul];
417     buffer[0] = bytes_ul & 0xFF;
418     bytesul->buf = (uint8_t*)calloc(1,1);
419     memcpy(bytesul->buf,buffer,1);
420     bytesul->size = 1;
421
422   } else if (bytes_ul <= 16384) {
423     array_size_ul = 2;
424
425     uint8_t buffer[array_size_ul];
426     buffer[0] = (bytes_ul >> 8) & 0xFF;
427     buffer[1] = bytes_ul & 0xFF;
428     bytesul->buf = (uint8_t*)calloc(2,1);
429     memcpy(bytesul->buf,buffer,2);
430     bytesul->size = 2;
431     
432   } else if (bytes_ul <= 4194304) {
433     array_size_ul = 3;
434
435     uint8_t buffer[array_size_ul];
436     buffer[0] = (bytes_ul >> 16) & 0xFF;
437     buffer[1] = (bytes_ul >> 8) & 0xFF;
438     buffer[2] = bytes_ul & 0xFF;
439     bytesul->buf = (uint8_t*)calloc(3,1);
440     memcpy(bytesul->buf,buffer,3);
441     bytesul->size = 3;    
442     
443   } else if (bytes_ul <= 1073741824) {
444     array_size_ul = 4;
445     uint8_t buffer[array_size_ul];
446     buffer[0] = (bytes_ul >> 24) & 0xFF;
447     buffer[1] = (bytes_ul >> 16) & 0xFF;
448     buffer[2] = (bytes_ul >> 8) & 0xFF;
449     buffer[3] = bytes_ul & 0xFF;
450     bytesul->buf = (uint8_t*)calloc(4,1);
451     memcpy(bytesul->buf,buffer,4);
452     bytesul->size = 4;
453   }
454   
455   
456   
457   ue_report_item->c_RNTI = *crnti;
458   ue_report_item->pDCPBytesDL = bytesdl;
459   ue_report_item->pDCPBytesUL = bytesul;
460   if (crnti) free(crnti);
461
462
463   ASN_SEQUENCE_ADD(&report_item->ueResourceReportList.list, ue_report_item);  
464
465   ranco->timestamp = *ts;
466   ranco->reportContainer.present = RAN_Container__reportContainer_PR_oCU_UP_UE;
467   ASN_SEQUENCE_ADD(&ranco->reportContainer.choice.oCU_UP_UE.cellResourceReportList.list, report_item);
468   if (ts) free(ts);
469
470   xer_fprint(stderr, &asn_DEF_RAN_Container, ranco);
471
472 }
473
474 void encode_kpm_ocucp_user_level(RAN_Container_t *ranco,
475                                  uint8_t *plmnid_buf,
476                                  uint8_t *nrcellid_buf,
477                                  uint8_t *crnti_buf,
478                                  const uint8_t *serving_buf,
479                                  const uint8_t *neighbor_buf) {
480   uint8_t *buf = (uint8_t*)"2020.06.13 13:01:05.222";
481   Timestamp_t *ts = (Timestamp_t*)calloc(1,sizeof(Timestamp_t));
482   ts->buf = (uint8_t*)calloc(strlen((char*)buf),1);
483   ts->size = strlen((char*)buf);
484   memcpy(ts->buf,buf,ts->size);
485
486   printf("enc1\n");
487
488   CU_CP_Usage_Report_CellResourceReportItem_t  *report_item =
489     (CU_CP_Usage_Report_CellResourceReportItem_t*)calloc(1,sizeof(CU_CP_Usage_Report_CellResourceReportItem_t));
490
491   int plmnid_size = strlen((char*)plmnid_buf);  
492   OCTET_STRING_t *plmnidstr = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
493   plmnidstr->buf = (uint8_t*)calloc(plmnid_size,1);
494   plmnidstr->size = plmnid_size;
495   memcpy(plmnidstr->buf, plmnid_buf, plmnidstr->size);
496
497   printf("enc2\n");
498
499   NRCellIdentity_t *nrcellid = (NRCellIdentity_t*)calloc(1,sizeof(NRCellIdentity_t));
500
501   //  int nrcellid_size = strlen((char*)nrcellid_buf);
502   int nrcellid_size = 5;
503   nrcellid->buf = (uint8_t*)calloc(1, nrcellid_size);
504   memcpy(nrcellid->buf, nrcellid_buf, nrcellid_size);
505   nrcellid->size = 5;
506   nrcellid->bits_unused = 4;
507
508   NRCGI *nrcgi = (NRCGI*)calloc(1,sizeof(NRCGI));
509   nrcgi->pLMN_Identity = *plmnidstr;
510   nrcgi->nRCellIdentity = *nrcellid;
511   if (plmnidstr) free(plmnidstr);
512   if (nrcellid) free(nrcellid);
513  
514   printf("enc3\n");
515   
516   report_item->nRCGI = *nrcgi;
517   if (nrcgi) free(nrcgi);
518
519   CU_CP_Usage_Report_UeResourceReportItem *ue_report_item =
520     (CU_CP_Usage_Report_UeResourceReportItem*)calloc(1,sizeof(CU_CP_Usage_Report_UeResourceReportItem));
521
522   printf("enc3.2\n");
523
524
525   int crnti_size = strlen((char*)crnti_buf);
526   OCTET_STRING *crnti = (OCTET_STRING*)calloc(1,sizeof(OCTET_STRING));
527   crnti->buf = (uint8_t*)calloc(1, crnti_size);
528   
529   printf("enc3.3\n");
530   
531   crnti->size = strlen((char*)crnti_buf);
532
533   printf("enc3.4\n");
534   memcpy(crnti->buf, crnti_buf, crnti->size);
535
536   //  uint8_t *buf_serving = (uint8_t*)"RSRP10";
537
538   int serving_buf_len = strlen((char*)serving_buf);
539   OCTET_STRING_t *servingstr = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
540   servingstr->buf = (uint8_t*)calloc(serving_buf_len,1);
541   servingstr->size = serving_buf_len;
542   memcpy(servingstr->buf, serving_buf, servingstr->size);
543
544
545   int neighbor_buf_len = strlen((char*)neighbor_buf);
546   //  uint8_t *buf_neighbor = (uint8_t*)"-10,-15";
547   OCTET_STRING_t *neighborstr = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
548   ts->buf = (uint8_t*)calloc(neighbor_buf_len,1);
549   neighborstr->buf = (uint8_t*)calloc(neighbor_buf_len,1);
550   neighborstr->size = neighbor_buf_len;
551   memcpy(neighborstr->buf, neighbor_buf, neighborstr->size);
552
553   ue_report_item->c_RNTI = *crnti;
554   ue_report_item->serving_Cell_RF_Type = servingstr;
555   ue_report_item->neighbor_Cell_RF = neighborstr;
556   if (crnti) free(crnti);
557
558
559   ASN_SEQUENCE_ADD(&report_item->ueResourceReportList.list, ue_report_item);  
560
561   ranco->timestamp = *ts;
562   ranco->reportContainer.present = RAN_Container__reportContainer_PR_oCU_CP_UE;
563   ASN_SEQUENCE_ADD(&ranco->reportContainer.choice.oCU_CP_UE.cellResourceReportList.list, report_item);
564   if (ts->buf) free(ts->buf);
565   if (ts) free(ts);
566
567   xer_fprint(stderr, &asn_DEF_RAN_Container, ranco);
568   
569
570 }
571
572 void encode_kpm_ocucp_user_level(RAN_Container_t *ranco) {
573
574   uint8_t *buf = (uint8_t*)"2020.06.13 13:01:05.222";
575   Timestamp_t *ts = (Timestamp_t*)calloc(1,sizeof(Timestamp_t));
576   ts->buf = (uint8_t*)calloc(strlen((char*)buf),1);
577   ts->size = strlen((char*)buf);
578   memcpy(ts->buf,buf,ts->size);
579
580   printf("enc1\n");
581
582   CU_CP_Usage_Report_CellResourceReportItem_t  *report_item =
583     (CU_CP_Usage_Report_CellResourceReportItem_t*)calloc(1,sizeof(CU_CP_Usage_Report_CellResourceReportItem_t));
584
585   uint8_t *buf2 = (uint8_t*)"747";
586   
587   OCTET_STRING_t *plmnidstr = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
588   plmnidstr->buf = (uint8_t*)calloc(3,1);
589   plmnidstr->size = 3;
590   memcpy(plmnidstr->buf, buf2, plmnidstr->size);
591
592   printf("enc2\n");
593
594   NRCellIdentity_t *nrcellid = (NRCellIdentity_t*)calloc(1,sizeof(NRCellIdentity_t));
595   uint8_t* buf3 = (uint8_t*)"12340";
596   nrcellid->buf = (uint8_t*)calloc(1,5);
597   memcpy(nrcellid->buf, buf3, 5);
598   nrcellid->size = 5;
599   nrcellid->bits_unused = 4;
600
601   NRCGI *nrcgi = (NRCGI*)calloc(1,sizeof(NRCGI));
602   nrcgi->pLMN_Identity = *plmnidstr;
603   nrcgi->nRCellIdentity = *nrcellid;
604  
605   printf("enc3\n");
606   
607   report_item->nRCGI = *nrcgi;
608   if (nrcgi) free(nrcgi);
609
610   CU_CP_Usage_Report_UeResourceReportItem *ue_report_item =
611     (CU_CP_Usage_Report_UeResourceReportItem*)calloc(1,sizeof(CU_CP_Usage_Report_UeResourceReportItem));
612
613   printf("enc3.2\n");
614
615   uint8_t* crnti_str = (uint8_t*)"1111";
616   OCTET_STRING *crnti = (OCTET_STRING*)calloc(1,sizeof(OCTET_STRING));
617   crnti->buf = (uint8_t*)calloc(1,4);
618   
619   printf("enc3.3\n");
620   
621   crnti->size = strlen((char*)crnti_str);
622
623   printf("enc3.4\n");
624   memcpy(crnti->buf, crnti_str, crnti->size);
625
626   uint8_t *buf_serving = (uint8_t*)"RSRP10";
627   OCTET_STRING_t *servingstr = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
628   servingstr->buf = (uint8_t*)calloc(6,1);
629   servingstr->size = 6;
630   memcpy(servingstr->buf, buf_serving, servingstr->size);
631
632   uint8_t *buf_neighbor = (uint8_t*)"-10,-15";
633   OCTET_STRING_t *neighborstr = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
634   neighborstr->buf = (uint8_t*)calloc(7,1);
635   neighborstr->size = 7;
636   memcpy(neighborstr->buf, buf_neighbor, neighborstr->size);
637
638   ue_report_item->c_RNTI = *crnti;
639   ue_report_item->serving_Cell_RF_Type = servingstr;
640   ue_report_item->neighbor_Cell_RF = neighborstr;
641
642
643   ASN_SEQUENCE_ADD(&report_item->ueResourceReportList.list, ue_report_item);  
644
645   ranco->timestamp = *ts;
646   ranco->reportContainer.present = RAN_Container__reportContainer_PR_oCU_CP_UE;
647   ASN_SEQUENCE_ADD(&ranco->reportContainer.choice.oCU_CP_UE.cellResourceReportList.list, report_item);
648
649   xer_fprint(stderr, &asn_DEF_RAN_Container, ranco);
650
651 }
652
653
654 void encode_kpm_odu_user_level(RAN_Container_t *ranco,
655                                uint8_t *plmnid_buf,
656                                uint8_t *nrcellid_buf,
657                                uint8_t *crnti_buf,
658                                long prb_usage_dl,
659                                long prb_usage_ul) {
660
661   uint8_t *buf = (uint8_t*)"2020.06.13 13:01:05.222";
662   Timestamp_t *ts = (Timestamp_t*)calloc(1,sizeof(Timestamp_t));
663   ts->buf = (uint8_t*)calloc(strlen((char*)buf),1);
664   ts->size = strlen((char*)buf);
665   memcpy(ts->buf,buf,ts->size);
666
667   printf("enc1\n");
668
669   DU_Usage_Report_CellResourceReportItem_t *report_item =
670     (DU_Usage_Report_CellResourceReportItem_t*)calloc(1,sizeof(DU_Usage_Report_CellResourceReportItem_t));
671
672   //  uint8_t *buf2 = (uint8_t*)"747";
673
674   int plmnid_size = strlen((char*)plmnid_buf);  
675   OCTET_STRING_t *plmnidstr = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
676   plmnidstr->buf = (uint8_t*)calloc(plmnid_size,1);
677   plmnidstr->size = plmnid_size;
678   memcpy(plmnidstr->buf, plmnid_buf, plmnidstr->size);
679
680   printf("enc2\n");  
681
682   NRCellIdentity_t *nrcellid = (NRCellIdentity_t*)calloc(1,sizeof(NRCellIdentity_t));
683
684   //  int nrcellid_size = strlen((char*)nrcellid_buf);
685   int nrcellid_size = 5;
686   nrcellid->buf = (uint8_t*)calloc(1,nrcellid_size);
687   memcpy(nrcellid->buf, nrcellid_buf, nrcellid_size);
688   nrcellid->size = nrcellid_size;
689   nrcellid->bits_unused = 4;
690
691   NRCGI *nrcgi = (NRCGI*)calloc(1,sizeof(NRCGI));
692   nrcgi->pLMN_Identity = *plmnidstr;
693   nrcgi->nRCellIdentity = *nrcellid;
694   if (plmnidstr) free(plmnidstr);
695   if (nrcellid) free(nrcellid);
696  
697   printf("enc3\n"); 
698   
699   report_item->nRCGI = *nrcgi;
700   if (nrcgi) free(nrcgi);
701
702   printf("enc3.1\n");   
703
704   DU_Usage_Report_UeResourceReportItem *ue_report_item =
705     (DU_Usage_Report_UeResourceReportItem*)calloc(1,sizeof(DU_Usage_Report_UeResourceReportItem));
706
707   printf("enc3.2\n");   
708
709   int crnti_size = strlen((char*)crnti_buf);
710
711   OCTET_STRING *crnti = (OCTET_STRING*)calloc(1,sizeof(OCTET_STRING));
712   crnti->buf = (uint8_t*)calloc(1,crnti_size);
713   
714   printf("enc3.3\n");
715   
716   crnti->size = strlen((char*)crnti_buf);
717
718   printf("enc3.4\n");
719   memcpy(crnti->buf, crnti_buf, crnti->size);
720
721   printf("enc4\n");  
722
723   long *p_prb_usage_dl = (long*)calloc(1, sizeof(long));
724   long *p_prb_usage_ul = (long*)calloc(1, sizeof(long));
725   *p_prb_usage_dl = (long)prb_usage_dl;
726   *p_prb_usage_ul = (long)prb_usage_ul;
727   
728   ue_report_item->c_RNTI = *crnti;
729   ue_report_item->dl_PRBUsage = p_prb_usage_dl;
730   if (crnti) free(crnti);
731
732   printf("enc5\n");
733   
734   ue_report_item->ul_PRBUsage = p_prb_usage_ul;
735
736   printf("enc6\n");
737   
738   ASN_SEQUENCE_ADD(&report_item->ueResourceReportList.list, ue_report_item);
739
740   
741   ranco->timestamp = *ts;
742   ranco->reportContainer.present = RAN_Container__reportContainer_PR_oDU_UE;
743   ASN_SEQUENCE_ADD(&ranco->reportContainer.choice.oDU_UE.cellResourceReportList.list, report_item);
744   if (ts) free(ts);
745
746   xer_fprint(stderr, &asn_DEF_RAN_Container, ranco);
747
748   
749 }
750
751 void encode_kpm_report_rancontainer_du_parameterized(E2SM_KPM_IndicationMessage_t* indicationmessage,
752                                                      uint8_t *plmnid_buf,
753                                                      uint8_t *nrcellid_buf,
754                                                      uint8_t *crnti_buf,
755                                                      long prb_usage_dl,
756                                                      long prb_usage_ul) {
757   
758   RAN_Container_t *ranco = (RAN_Container_t*)calloc(1,sizeof(RAN_Container_t));
759   encode_kpm_odu_user_level(ranco,plmnid_buf,nrcellid_buf,crnti_buf,prb_usage_dl,prb_usage_ul);
760
761   printf("After creating RAN container, xer printing it\n");
762   xer_fprint(stderr, &asn_DEF_RAN_Container, ranco);
763
764   PM_Containers_List_t *containers_list = (PM_Containers_List_t*)calloc(1, sizeof(PM_Containers_List_t));
765   ASN_STRUCT_RESET(asn_DEF_PM_Containers_List, containers_list);
766   containers_list->theRANContainer = ranco;
767
768   E2SM_KPM_IndicationMessage_Format1_t *format =
769     (E2SM_KPM_IndicationMessage_Format1_t*)calloc(1, sizeof(E2SM_KPM_IndicationMessage_Format1_t));
770   ASN_STRUCT_RESET(asn_DEF_E2SM_KPM_IndicationMessage_Format1, format);
771
772   int ret = ASN_SEQUENCE_ADD(&format->pm_Containers.list, containers_list);
773   
774   E2SM_KPM_IndicationMessage__indicationMessage_PR pres = E2SM_KPM_IndicationMessage__indicationMessage_PR_indicationMessage_Format1;
775
776   indicationmessage->indicationMessage.present = pres;
777
778   indicationmessage->indicationMessage.choice.indicationMessage_Format1 = *format;
779   if (format) free(format);
780
781   char error_buf[300] = {0, };
782   size_t errlen = 0;
783
784   asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf, &errlen);
785   printf("error length %d\n", errlen);
786   printf("error buf %s\n", error_buf);
787
788   xer_fprint(stderr, &asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage);
789
790   asn_codec_ctx_t *opt_cod;
791
792   uint8_t e2smbuffer[8192] = {0, };
793   size_t e2smbuffer_size = 8192;
794
795   uint8_t e2smbuffer2[8192] = {0, };
796   size_t e2smbuffer_size2 = 8192;
797
798   asn_enc_rval_t er =
799     asn_encode_to_buffer(opt_cod,
800                          ATS_ALIGNED_BASIC_PER,
801                          &asn_DEF_E2SM_KPM_IndicationMessage,
802                          indicationmessage, e2smbuffer, e2smbuffer_size);
803
804   fprintf(stderr, "er encded is %d\n", er.encoded);
805   fprintf(stderr, "after encoding message\n");
806
807
808 }
809
810 void encode_kpm_report_rancontainer_cucp_parameterized(E2SM_KPM_IndicationMessage_t* indicationmessage,
811                                                        uint8_t *plmnid_buf,
812                                                        uint8_t *nrcellid_buf,
813                                                        uint8_t *crnti_buf,
814                                                        const uint8_t *serving_buf,
815                                                        const uint8_t *neighbor_buf) {
816
817   RAN_Container_t *ranco = (RAN_Container_t*)calloc(1,sizeof(RAN_Container_t));
818   encode_kpm_ocucp_user_level(ranco, plmnid_buf,
819                               nrcellid_buf, crnti_buf,
820                               serving_buf, neighbor_buf);
821
822   printf("After creating RAN container, xer printing it\n");
823   xer_fprint(stderr, &asn_DEF_RAN_Container, ranco);
824   
825
826   PM_Containers_List_t *containers_list = (PM_Containers_List_t*)calloc(1, sizeof(PM_Containers_List_t));
827   ASN_STRUCT_RESET(asn_DEF_PM_Containers_List, containers_list);
828   containers_list->theRANContainer = ranco;
829
830   E2SM_KPM_IndicationMessage_Format1_t *format =
831     (E2SM_KPM_IndicationMessage_Format1_t*)calloc(1, sizeof(E2SM_KPM_IndicationMessage_Format1_t));
832   ASN_STRUCT_RESET(asn_DEF_E2SM_KPM_IndicationMessage_Format1, format);
833
834   int ret = ASN_SEQUENCE_ADD(&format->pm_Containers.list, containers_list);
835   
836   E2SM_KPM_IndicationMessage__indicationMessage_PR pres = E2SM_KPM_IndicationMessage__indicationMessage_PR_indicationMessage_Format1;
837
838   indicationmessage->indicationMessage.present = pres;
839
840   indicationmessage->indicationMessage.choice.indicationMessage_Format1 = *format;
841   if (format) free(format);
842
843   char error_buf[300] = {0, };
844   size_t errlen = 0;
845
846   asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf, &errlen);
847   printf("error length %d\n", errlen);
848   printf("error buf %s\n", error_buf);
849
850   xer_fprint(stderr, &asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage);
851
852   asn_codec_ctx_t *opt_cod;
853
854   uint8_t e2smbuffer[8192] = {0, };
855   size_t e2smbuffer_size = 8192;
856
857   uint8_t e2smbuffer2[8192] = {0, };
858   size_t e2smbuffer_size2 = 8192;
859
860   asn_enc_rval_t er =
861     asn_encode_to_buffer(opt_cod,
862                          ATS_ALIGNED_BASIC_PER,
863                          &asn_DEF_E2SM_KPM_IndicationMessage,
864                          indicationmessage, e2smbuffer, e2smbuffer_size);
865
866   fprintf(stderr, "er encded is %d\n", er.encoded);
867   fprintf(stderr, "after encoding message\n");
868   
869 }
870                                                        
871                                                        
872 void encode_kpm_report_rancontainer_cucp(E2SM_KPM_IndicationMessage_t* indicationmessage) {
873
874   RAN_Container_t *ranco = (RAN_Container_t*)calloc(1,sizeof(RAN_Container_t));
875   encode_kpm_ocucp_user_level(ranco);
876
877   PM_Containers_List_t *containers_list = (PM_Containers_List_t*)calloc(1, sizeof(PM_Containers_List_t));
878   ASN_STRUCT_RESET(asn_DEF_PM_Containers_List, containers_list);
879   containers_list->theRANContainer = ranco;
880
881   E2SM_KPM_IndicationMessage_Format1_t *format =
882     (E2SM_KPM_IndicationMessage_Format1_t*)calloc(1, sizeof(E2SM_KPM_IndicationMessage_Format1_t));
883   ASN_STRUCT_RESET(asn_DEF_E2SM_KPM_IndicationMessage_Format1, format);
884
885   int ret = ASN_SEQUENCE_ADD(&format->pm_Containers.list, containers_list);
886   
887   E2SM_KPM_IndicationMessage__indicationMessage_PR pres = E2SM_KPM_IndicationMessage__indicationMessage_PR_indicationMessage_Format1;
888
889   indicationmessage->indicationMessage.present = pres;
890
891   indicationmessage->indicationMessage.choice.indicationMessage_Format1 = *format;
892   if (format) free(format);
893
894   char error_buf[300] = {0, };
895   size_t errlen = 0;
896
897   asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf, &errlen);
898   printf("error length %d\n", errlen);
899   printf("error buf %s\n", error_buf);
900
901   //  xer_fprint(stderr, &asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage);
902
903   asn_codec_ctx_t *opt_cod;
904
905   uint8_t e2smbuffer[8192] = {0, };
906   size_t e2smbuffer_size = 8192;
907
908   uint8_t e2smbuffer2[8192] = {0, };
909   size_t e2smbuffer_size2 = 8192;
910
911   asn_enc_rval_t er =
912     asn_encode_to_buffer(opt_cod,
913                          ATS_ALIGNED_BASIC_PER,
914                          &asn_DEF_E2SM_KPM_IndicationMessage,
915                          indicationmessage, e2smbuffer, e2smbuffer_size);
916
917   fprintf(stderr, "er encded is %d\n", er.encoded);
918   fprintf(stderr, "after encoding message\n");
919
920
921 }
922
923 void encode_kpm_report_rancontainer_cuup_parameterized(E2SM_KPM_IndicationMessage_t* indicationmessage,
924                                                        uint8_t *plmnid_buf,
925                                                        uint8_t *nrcellid_buf,
926                                                        uint8_t *crnti_buf,
927                                                        int pdcp_bytesdl,
928                                                        int pdcp_bytesul) {
929
930   RAN_Container_t *ranco = (RAN_Container_t*)calloc(1,sizeof(RAN_Container_t));
931   encode_kpm_ocuup_user_level(ranco,plmnid_buf,nrcellid_buf,crnti_buf,pdcp_bytesdl,pdcp_bytesul);
932
933   fprintf(stderr, "After creating RAN container, xer printing it\n");
934   xer_fprint(stderr, &asn_DEF_RAN_Container, ranco);  
935
936   PM_Containers_List_t *containers_list = (PM_Containers_List_t*)calloc(1, sizeof(PM_Containers_List_t));
937   ASN_STRUCT_RESET(asn_DEF_PM_Containers_List, containers_list);
938   containers_list->theRANContainer = ranco;
939
940   E2SM_KPM_IndicationMessage_Format1_t *format =
941     (E2SM_KPM_IndicationMessage_Format1_t*)calloc(1, sizeof(E2SM_KPM_IndicationMessage_Format1_t));
942   ASN_STRUCT_RESET(asn_DEF_E2SM_KPM_IndicationMessage_Format1, format);
943
944   int ret = ASN_SEQUENCE_ADD(&format->pm_Containers.list, containers_list);
945   
946   E2SM_KPM_IndicationMessage__indicationMessage_PR pres = E2SM_KPM_IndicationMessage__indicationMessage_PR_indicationMessage_Format1;
947
948   indicationmessage->indicationMessage.present = pres;
949
950   indicationmessage->indicationMessage.choice.indicationMessage_Format1 = *format;
951   if (format) free(format);
952
953   char error_buf[300] = {0, };
954   size_t errlen = 0;
955
956   asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf, &errlen);
957   printf("error length %d\n", errlen);
958   printf("error buf %s\n", error_buf);
959
960   xer_fprint(stderr, &asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage);
961
962   asn_codec_ctx_t *opt_cod;
963
964   uint8_t e2smbuffer[8192] = {0, };
965   size_t e2smbuffer_size = 8192;
966
967   uint8_t e2smbuffer2[8192] = {0, };
968   size_t e2smbuffer_size2 = 8192;
969
970   //  xer_fprint(stderr, &asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage);  
971
972   asn_enc_rval_t er =
973     asn_encode_to_buffer(opt_cod,
974                          ATS_ALIGNED_BASIC_PER,
975                          &asn_DEF_E2SM_KPM_IndicationMessage,
976                          indicationmessage, e2smbuffer, e2smbuffer_size);
977
978   fprintf(stderr, "er encded is %d\n", er.encoded);
979   fprintf(stderr, "after encoding message\n");  
980
981
982 }
983
984 void encode_kpm_report_rancontainer_cuup(E2SM_KPM_IndicationMessage_t* indicationmessage) {
985
986   RAN_Container_t *ranco = (RAN_Container_t*)calloc(1,sizeof(RAN_Container_t));
987   //encode_kpm_ocuup_user_level(ranco);
988
989   
990   uint8_t *buf = (uint8_t*)"2020.06.13 13:01:05.222";
991   Timestamp_t *ts = (Timestamp_t*)calloc(1,sizeof(Timestamp_t));
992   ts->buf = (uint8_t*)calloc(strlen((char*)buf),1);
993   ts->size = strlen((char*)buf);
994   memcpy(ts->buf,buf,ts->size);
995
996   printf("enc1\n");
997
998   CU_CP_Usage_Report_CellResourceReportItem_t  *report_item =
999     (CU_CP_Usage_Report_CellResourceReportItem_t*)calloc(1,sizeof(CU_CP_Usage_Report_CellResourceReportItem_t));
1000
1001   uint8_t *buf2 = (uint8_t*)"747";
1002   
1003   OCTET_STRING_t *plmnidstr = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
1004   plmnidstr->buf = (uint8_t*)calloc(3,1);
1005   plmnidstr->size = 3;
1006   memcpy(plmnidstr->buf, buf2, plmnidstr->size);
1007
1008   printf("enc2\n");  
1009
1010   NRCellIdentity_t *nrcellid = (NRCellIdentity_t*)calloc(1,sizeof(NRCellIdentity_t));
1011   uint8_t* buf3 = (uint8_t*)"12340";
1012   nrcellid->buf = (uint8_t*)calloc(1,5);
1013   memcpy(nrcellid->buf, buf3, 5);
1014   nrcellid->size = 5;
1015   nrcellid->bits_unused = 4;
1016
1017   NRCGI *nrcgi = (NRCGI*)calloc(1,sizeof(NRCGI));
1018   nrcgi->pLMN_Identity = *plmnidstr;
1019   nrcgi->nRCellIdentity = *nrcellid;
1020   if (plmnidstr) free(plmnidstr);
1021   if (nrcellid) free(nrcellid);
1022  
1023   printf("enc3\n"); 
1024   
1025   report_item->nRCGI = *nrcgi;
1026   if (nrcgi) free(nrcgi);
1027
1028   CU_CP_Usage_Report_UeResourceReportItem *ue_report_item =
1029     (CU_CP_Usage_Report_UeResourceReportItem*)calloc(1,sizeof(CU_CP_Usage_Report_UeResourceReportItem));
1030
1031   printf("enc3.2\n");
1032
1033   uint8_t* crnti_str = (uint8_t*)"1111";
1034   OCTET_STRING *crnti = (OCTET_STRING*)calloc(1,sizeof(OCTET_STRING));
1035   crnti->buf = (uint8_t*)calloc(1,4);
1036   
1037   printf("enc3.3\n");
1038   
1039   crnti->size = strlen((char*)crnti_str);
1040
1041   printf("enc3.4\n");
1042   memcpy(crnti->buf, crnti_str, crnti->size);
1043
1044   uint8_t *buf_serving = (uint8_t*)"RSRP10";
1045   OCTET_STRING_t *servingstr = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
1046   servingstr->buf = (uint8_t*)calloc(6,1);
1047   servingstr->size = 6;
1048   memcpy(servingstr->buf, buf_serving, servingstr->size);
1049
1050   uint8_t *buf_neighbor = (uint8_t*)"-10,-15";
1051   OCTET_STRING_t *neighborstr = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
1052   neighborstr->buf = (uint8_t*)calloc(7,1);
1053   neighborstr->size = 7;
1054   memcpy(neighborstr->buf, buf_neighbor, neighborstr->size);
1055
1056   ue_report_item->c_RNTI = *crnti;
1057   ue_report_item->serving_Cell_RF_Type = servingstr;
1058   ue_report_item->neighbor_Cell_RF = neighborstr;
1059
1060
1061   ASN_SEQUENCE_ADD(&report_item->ueResourceReportList.list, ue_report_item);
1062
1063   ranco->timestamp = *ts;
1064   ranco->reportContainer.present = RAN_Container__reportContainer_PR_oCU_CP_UE;
1065   ASN_SEQUENCE_ADD(&ranco->reportContainer.choice.oCU_CP_UE.cellResourceReportList.list, report_item);
1066
1067   //  xer_fprint(stderr, &asn_DEF_RAN_Container, ranco);
1068   
1069
1070   PM_Containers_List_t *containers_list = (PM_Containers_List_t*)calloc(1, sizeof(PM_Containers_List_t));
1071   ASN_STRUCT_RESET(asn_DEF_PM_Containers_List, containers_list);
1072   containers_list->theRANContainer = ranco;
1073
1074   E2SM_KPM_IndicationMessage_Format1_t *format =
1075     (E2SM_KPM_IndicationMessage_Format1_t*)calloc(1, sizeof(E2SM_KPM_IndicationMessage_Format1_t));
1076   ASN_STRUCT_RESET(asn_DEF_E2SM_KPM_IndicationMessage_Format1, format);
1077
1078   int ret = ASN_SEQUENCE_ADD(&format->pm_Containers.list, containers_list);
1079   
1080   E2SM_KPM_IndicationMessage__indicationMessage_PR pres = E2SM_KPM_IndicationMessage__indicationMessage_PR_indicationMessage_Format1;
1081
1082   indicationmessage->indicationMessage.present = pres;
1083
1084   indicationmessage->indicationMessage.choice.indicationMessage_Format1 = *format;
1085   if (format) free(format);
1086
1087   char error_buf[300] = {0, };
1088   size_t errlen = 0;
1089
1090   asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf, &errlen);
1091   printf("error length %d\n", errlen);
1092   printf("error buf %s\n", error_buf);
1093
1094   xer_fprint(stderr, &asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage);
1095
1096   asn_codec_ctx_t *opt_cod;
1097
1098   uint8_t e2smbuffer[8192] = {0, };
1099   size_t e2smbuffer_size = 8192;
1100
1101   uint8_t e2smbuffer2[8192] = {0, };
1102   size_t e2smbuffer_size2 = 8192;
1103
1104   asn_enc_rval_t er =
1105     asn_encode_to_buffer(opt_cod,
1106                          ATS_ALIGNED_BASIC_PER,
1107                          &asn_DEF_E2SM_KPM_IndicationMessage,
1108                          indicationmessage, e2smbuffer, e2smbuffer_size);
1109
1110   fprintf(stderr, "er encded is %d\n", er.encoded);
1111   fprintf(stderr, "after encoding message\n");
1112
1113
1114 }
1115
1116 void encode_kpm_report_style1_parameterized(E2SM_KPM_IndicationMessage_t* indicationmessage,
1117                                             long fiveqi,
1118                                             long dl_prb_usage,
1119                                             long ul_prb_usage,
1120                                             uint8_t* sst_buf,
1121                                             uint8_t* sd_buf,
1122                                             uint8_t* plmnid_buf,
1123                                             uint8_t* nrcellid_buf,
1124                                             long *dl_prbs,
1125                                             long *ul_prbs) {
1126
1127
1128   asn_codec_ctx_t *opt_cod;
1129
1130   FQIPERSlicesPerPlmnPerCellListItem_t *fqi_item =
1131     (FQIPERSlicesPerPlmnPerCellListItem_t*)calloc(1,sizeof(FQIPERSlicesPerPlmnPerCellListItem_t));
1132
1133   long *p_dl_prb_usage = (long*)calloc(1, sizeof(long));
1134   long *p_ul_prb_usage = (long*)calloc(1, sizeof(long));
1135   *p_dl_prb_usage = (long)dl_prb_usage;
1136   *p_ul_prb_usage = (long)ul_prb_usage;
1137
1138   fqi_item->fiveQI = fiveqi;
1139   fqi_item->dl_PRBUsage = p_dl_prb_usage;
1140   fqi_item->ul_PRBUsage = p_ul_prb_usage;
1141
1142   uint8_t *buf1 = (uint8_t*)"4";  
1143
1144   //  std::string sd = "SD1";
1145   //  std::vector<uint8_t> sdvec(sd.begin(), sd.end());
1146   //  uint8_t *bufz = &sdvec[0];
1147   uint8_t *bufz = (uint8_t*)"SD1";
1148   
1149   SNSSAI_t *snssai = (SNSSAI_t*)calloc(1, sizeof(SNSSAI_t));
1150   ASN_STRUCT_RESET(asn_DEF_SNSSAI,snssai);
1151   snssai->sST.buf = (uint8_t*)calloc(1,1);
1152   snssai->sST.size = 1;
1153   memcpy(snssai->sST.buf, sst_buf, 1);
1154   snssai->sD = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
1155   snssai->sD->buf = (uint8_t*)calloc(1,3);
1156   snssai->sD->size = 3;
1157   memcpy(snssai->sD->buf, sd_buf, 3);
1158   
1159   
1160   SlicePerPlmnPerCellListItem_t *sliceitem =
1161     (SlicePerPlmnPerCellListItem_t*)calloc(1,sizeof(SlicePerPlmnPerCellListItem_t));
1162   sliceitem->sliceID = *snssai;
1163   ASN_SEQUENCE_ADD(&sliceitem->fQIPERSlicesPerPlmnPerCellList.list, fqi_item);
1164   if (snssai) free(snssai);
1165
1166   uint8_t *buf2 = (uint8_t*)"747";
1167   
1168   OCTET_STRING_t *plmnid = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
1169   plmnid->buf = (uint8_t*)calloc(3,1);
1170   plmnid->size = 3;
1171   memcpy(plmnid->buf, plmnid_buf, plmnid->size);  
1172
1173   ServedPlmnPerCellListItem_t *percellitem1 =
1174     (ServedPlmnPerCellListItem_t*)calloc(1,sizeof(ServedPlmnPerCellListItem_t));
1175   percellitem1->pLMN_Identity = *plmnid;
1176   percellitem1->du_PM_5GC = (FGC_DU_PM_Container*)calloc(1,sizeof(FGC_DU_PM_Container));
1177   ASN_SEQUENCE_ADD(&percellitem1->du_PM_5GC->slicePerPlmnPerCellList.list, sliceitem);
1178   if (plmnid) free(plmnid);
1179
1180   OCTET_STRING_t *plmnidstr = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
1181   plmnidstr->buf = (uint8_t*)calloc(3,1);
1182   plmnidstr->size = 3;
1183   memcpy(plmnidstr->buf, plmnid_buf, plmnidstr->size);
1184
1185   printf("enc2\n");  
1186
1187   NRCellIdentity_t *nrcellid = (NRCellIdentity_t*)calloc(1,sizeof(NRCellIdentity_t));
1188   uint8_t* buf3 = (uint8_t*)"12340";
1189   nrcellid->buf = (uint8_t*)calloc(1,5);
1190   memcpy(nrcellid->buf, nrcellid_buf, 5);
1191   nrcellid->size = 5;
1192   nrcellid->bits_unused = 4;
1193
1194   NRCGI *nrcgi = (NRCGI*)calloc(1,sizeof(NRCGI));
1195   nrcgi->pLMN_Identity = *plmnidstr;
1196   nrcgi->nRCellIdentity = *nrcellid;
1197   if (plmnidstr) free(plmnidstr);
1198   if (nrcellid) free(nrcellid);
1199     
1200
1201   CellResourceReportListItem_t *listitem1 = (CellResourceReportListItem_t*)calloc(1,sizeof(CellResourceReportListItem_t));
1202   listitem1->nRCGI = *nrcgi;
1203   listitem1->dl_TotalofAvailablePRBs = dl_prbs;
1204   listitem1->ul_TotalofAvailablePRBs = ul_prbs;
1205   ASN_SEQUENCE_ADD(&listitem1->servedPlmnPerCellList.list, percellitem1);
1206   if (nrcgi) free(nrcgi);
1207   
1208
1209   ODU_PF_Container_t *ducont = (ODU_PF_Container_t*)calloc(1,sizeof(ODU_PF_Container_t));
1210   ASN_STRUCT_RESET(asn_DEF_ODU_PF_Container, ducont);
1211   int ret = ASN_SEQUENCE_ADD(&ducont->cellResourceReportList.list, listitem1);
1212   
1213   PF_Container_PR pres1 = PF_Container_PR_oDU;
1214
1215   PF_Container_t *pfcontainer = (PF_Container_t*)calloc(1, sizeof(PF_Container_t));
1216   ASN_STRUCT_RESET(asn_DEF_PF_Container, pfcontainer);
1217   pfcontainer->present = pres1;
1218   pfcontainer->choice.oDU = *ducont;
1219   if (ducont) free(ducont);
1220
1221   PM_Containers_List_t *containers_list = (PM_Containers_List_t*)calloc(1, sizeof(PM_Containers_List_t));
1222   ASN_STRUCT_RESET(asn_DEF_PM_Containers_List, containers_list);
1223   containers_list->performanceContainer = pfcontainer;
1224
1225   E2SM_KPM_IndicationMessage_Format1_t *format =
1226     (E2SM_KPM_IndicationMessage_Format1_t*)calloc(1, sizeof(E2SM_KPM_IndicationMessage_Format1_t));
1227   ASN_STRUCT_RESET(asn_DEF_E2SM_KPM_IndicationMessage_Format1, format);
1228
1229   ret = ASN_SEQUENCE_ADD(&format->pm_Containers.list, containers_list);
1230   
1231   E2SM_KPM_IndicationMessage__indicationMessage_PR pres = E2SM_KPM_IndicationMessage__indicationMessage_PR_indicationMessage_Format1;
1232
1233   indicationmessage->indicationMessage.present = pres;
1234
1235   indicationmessage->indicationMessage.choice.indicationMessage_Format1 = *format;
1236   if (format) free(format);
1237
1238   char error_buf[300] = {0, };
1239   size_t errlen = 0;
1240
1241   asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf, &errlen);
1242   printf("error length %d\n", errlen);
1243   printf("error buf %s\n", error_buf);
1244
1245   xer_fprint(stderr, &asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage);
1246   
1247
1248   uint8_t e2smbuffer[8192] = {0, };
1249   size_t e2smbuffer_size = 8192;
1250
1251   uint8_t e2smbuffer2[8192] = {0, };
1252   size_t e2smbuffer_size2 = 8192;  
1253
1254   asn_enc_rval_t er =
1255     asn_encode_to_buffer(opt_cod,
1256                          ATS_ALIGNED_BASIC_PER,
1257                          &asn_DEF_E2SM_KPM_IndicationMessage,
1258                          indicationmessage, e2smbuffer, e2smbuffer_size);
1259
1260   fprintf(stderr, "er encded is %d\n", er.encoded);
1261   fprintf(stderr, "after encoding message\n");
1262
1263
1264 }
1265
1266
1267 void encode_kpm_report_style1(E2SM_KPM_IndicationMessage_t* indicationmessage) {
1268
1269   long fiveqi = 8;
1270   long dl_prb_usage = 50;
1271   long ul_prb_usage = 70;
1272
1273   asn_codec_ctx_t *opt_cod;
1274
1275   FQIPERSlicesPerPlmnPerCellListItem_t *fqi_item =
1276     (FQIPERSlicesPerPlmnPerCellListItem_t*)calloc(1,sizeof(FQIPERSlicesPerPlmnPerCellListItem_t));
1277   fqi_item->fiveQI = fiveqi;
1278   fqi_item->dl_PRBUsage = &dl_prb_usage;
1279   fqi_item->ul_PRBUsage = &ul_prb_usage;
1280
1281   uint8_t *buf1 = (uint8_t*)"4";  
1282   //  std::string sd = "SD1";
1283   //  std::vector<uint8_t> sdvec(sd.begin(), sd.end());
1284   //  uint8_t *bufz = &sdvec[0];
1285   uint8_t *bufz = (uint8_t*)"SD1";
1286   
1287   SNSSAI_t *snssai = (SNSSAI_t*)calloc(1, sizeof(SNSSAI_t));
1288   ASN_STRUCT_RESET(asn_DEF_SNSSAI,snssai);
1289   snssai->sST.buf = (uint8_t*)calloc(1,1);
1290   snssai->sST.size = 1;
1291   memcpy(snssai->sST.buf, buf1, 1);
1292   snssai->sD = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
1293   snssai->sD->buf = (uint8_t*)calloc(1,3);
1294   snssai->sD->size = 3;
1295   memcpy(snssai->sD->buf, bufz, 3);
1296   
1297   
1298   SlicePerPlmnPerCellListItem_t *sliceitem =
1299     (SlicePerPlmnPerCellListItem_t*)calloc(1,sizeof(SlicePerPlmnPerCellListItem_t));
1300   sliceitem->sliceID = *snssai;
1301   ASN_SEQUENCE_ADD(&sliceitem->fQIPERSlicesPerPlmnPerCellList.list, fqi_item);
1302   if (snssai) free(snssai);
1303
1304   uint8_t *buf2 = (uint8_t*)"747";
1305   
1306   OCTET_STRING_t *plmnid = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
1307   plmnid->buf = (uint8_t*)calloc(3,1);
1308   plmnid->size = 3;
1309   memcpy(plmnid->buf, buf2, plmnid->size);  
1310
1311   ServedPlmnPerCellListItem_t *percellitem1 =
1312     (ServedPlmnPerCellListItem_t*)calloc(1,sizeof(ServedPlmnPerCellListItem_t));
1313   percellitem1->pLMN_Identity = *plmnid;
1314   percellitem1->du_PM_5GC = (FGC_DU_PM_Container*)calloc(1,sizeof(FGC_DU_PM_Container));
1315   ASN_SEQUENCE_ADD(&percellitem1->du_PM_5GC->slicePerPlmnPerCellList.list, sliceitem);
1316
1317   OCTET_STRING_t *plmnidstr = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
1318   plmnidstr->buf = (uint8_t*)calloc(3,1);
1319   plmnidstr->size = 3;
1320   memcpy(plmnidstr->buf, buf2, plmnidstr->size);
1321
1322   printf("enc2\n");  
1323
1324   NRCellIdentity_t *nrcellid = (NRCellIdentity_t*)calloc(1,sizeof(NRCellIdentity_t));
1325   uint8_t* buf3 = (uint8_t*)"12340";
1326   nrcellid->buf = (uint8_t*)calloc(1,5);
1327   memcpy(nrcellid->buf, buf3, 5);
1328   nrcellid->size = 5;
1329   nrcellid->bits_unused = 4;
1330
1331   NRCGI *nrcgi = (NRCGI*)calloc(1,sizeof(NRCGI));
1332   nrcgi->pLMN_Identity = *plmnidstr;
1333   nrcgi->nRCellIdentity = *nrcellid;
1334   if (plmnidstr) free(plmnidstr);
1335   if (nrcellid) free(nrcellid);
1336     
1337   long dl_prbs = (long)100;
1338   long ul_prbs = (long)120;
1339
1340   CellResourceReportListItem_t *listitem1 = (CellResourceReportListItem_t*)calloc(1,sizeof(CellResourceReportListItem_t));
1341   listitem1->nRCGI = *nrcgi;
1342   listitem1->dl_TotalofAvailablePRBs = &dl_prbs;
1343   listitem1->ul_TotalofAvailablePRBs = &ul_prbs;
1344   ASN_SEQUENCE_ADD(&listitem1->servedPlmnPerCellList.list, percellitem1);
1345   if (nrcgi) free(nrcgi);
1346   
1347
1348   ODU_PF_Container_t *ducont = (ODU_PF_Container_t*)calloc(1,sizeof(ODU_PF_Container_t));
1349   ASN_STRUCT_RESET(asn_DEF_ODU_PF_Container, ducont);
1350   int ret = ASN_SEQUENCE_ADD(&ducont->cellResourceReportList.list, listitem1);
1351   
1352   PF_Container_PR pres1 = PF_Container_PR_oDU;
1353
1354   PF_Container_t *pfcontainer = (PF_Container_t*)calloc(1, sizeof(PF_Container_t));
1355   ASN_STRUCT_RESET(asn_DEF_PF_Container, pfcontainer);
1356   pfcontainer->present = pres1;
1357   pfcontainer->choice.oDU = *ducont;
1358   if (ducont) free(ducont);
1359
1360   PM_Containers_List_t *containers_list = (PM_Containers_List_t*)calloc(1, sizeof(PM_Containers_List_t));
1361   ASN_STRUCT_RESET(asn_DEF_PM_Containers_List, containers_list);
1362   containers_list->performanceContainer = pfcontainer;
1363
1364   E2SM_KPM_IndicationMessage_Format1_t *format =
1365     (E2SM_KPM_IndicationMessage_Format1_t*)calloc(1, sizeof(E2SM_KPM_IndicationMessage_Format1_t));
1366   ASN_STRUCT_RESET(asn_DEF_E2SM_KPM_IndicationMessage_Format1, format);
1367
1368   ret = ASN_SEQUENCE_ADD(&format->pm_Containers.list, containers_list);
1369   
1370   E2SM_KPM_IndicationMessage__indicationMessage_PR pres = E2SM_KPM_IndicationMessage__indicationMessage_PR_indicationMessage_Format1;
1371
1372   indicationmessage->indicationMessage.present = pres;
1373
1374   indicationmessage->indicationMessage.choice.indicationMessage_Format1 = *format;
1375   if (format) free(format);
1376
1377   char error_buf[300] = {0, };
1378   size_t errlen = 0;
1379
1380   asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf, &errlen);
1381   printf("error length %d\n", errlen);
1382   printf("error buf %s\n", error_buf);
1383
1384   xer_fprint(stderr, &asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage);
1385   
1386
1387   uint8_t e2smbuffer[8192] = {0, };
1388   size_t e2smbuffer_size = 8192;
1389
1390   uint8_t e2smbuffer2[8192] = {0, };
1391   size_t e2smbuffer_size2 = 8192;  
1392
1393   asn_enc_rval_t er =
1394     asn_encode_to_buffer(opt_cod,
1395                          ATS_ALIGNED_BASIC_PER,
1396                          &asn_DEF_E2SM_KPM_IndicationMessage,
1397                          indicationmessage, e2smbuffer, e2smbuffer_size);
1398
1399   fprintf(stderr, "er encded is %d\n", er.encoded);
1400   fprintf(stderr, "after encoding message\n");
1401
1402
1403 }
1404
1405 void encode_kpm_report_style5_parameterized(E2SM_KPM_IndicationMessage_t* indicationmessage,
1406                                             uint8_t *gnbcuupname_buf,
1407                                             int bytes_dl,
1408                                             int bytes_ul,
1409                                             uint8_t *sst_buf,
1410                                             uint8_t *sd_buf,
1411                                             uint8_t *plmnid_buf) {
1412   
1413   ASN_STRUCT_RESET(asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage);
1414
1415
1416   //  uint8_t *buf = (uint8_t*)"GNBCUUP5";
1417   OCTET_STRING_t *gnbcuupname = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
1418   gnbcuupname->size = 8;
1419   gnbcuupname->buf = (uint8_t*)calloc(1,8);
1420   memcpy(gnbcuupname->buf, gnbcuupname_buf, gnbcuupname->size);
1421
1422
1423   //We need to convert bytes_dl into array of uint8_t
1424
1425   int array_size_dl;
1426
1427   INTEGER_t *bytesdl = (INTEGER_t*)calloc(1, sizeof(INTEGER_t));
1428
1429   if (bytes_dl <= 64) {
1430     array_size_dl = 1;
1431
1432     uint8_t buffer[array_size_dl];
1433     buffer[0] = bytes_dl & 0xFF;
1434     bytesdl->buf = (uint8_t*)calloc(1,1);
1435     memcpy(bytesdl->buf,buffer,1);
1436     bytesdl->size = 1;
1437
1438   } else if (bytes_dl <= 16384) {
1439     array_size_dl = 2;
1440
1441     uint8_t buffer[array_size_dl];
1442     buffer[0] = (bytes_dl >> 8) & 0xFF;
1443     buffer[1] = bytes_dl & 0xFF;
1444     bytesdl->buf = (uint8_t*)calloc(2,1);
1445     memcpy(bytesdl->buf,buffer,2);
1446     bytesdl->size = 2;
1447     
1448   } else if (bytes_dl <= 4194304) {
1449     array_size_dl = 3;
1450
1451     uint8_t buffer[array_size_dl];
1452     buffer[0] = (bytes_dl >> 16) & 0xFF;
1453     buffer[1] = (bytes_dl >> 8) & 0xFF;
1454     buffer[2] = bytes_dl & 0xFF;
1455     bytesdl->buf = (uint8_t*)calloc(3,1);
1456     memcpy(bytesdl->buf,buffer,3);
1457     bytesdl->size = 3;    
1458     
1459   } else if (bytes_dl <= 1073741824) {
1460     array_size_dl = 4;
1461     uint8_t buffer[array_size_dl];
1462     buffer[0] = (bytes_dl >> 24) & 0xFF;
1463     buffer[1] = (bytes_dl >> 16) & 0xFF;
1464     buffer[2] = (bytes_dl >> 8) & 0xFF;
1465     buffer[3] = bytes_dl & 0xFF;
1466     bytesdl->buf = (uint8_t*)calloc(4,1);
1467     memcpy(bytesdl->buf,buffer,4);
1468     bytesdl->size = 4;
1469   }
1470   
1471   
1472   //We need to convert bytes_ul into array of uint8_t
1473   INTEGER_t *bytesul = (INTEGER_t*)calloc(1, sizeof(INTEGER_t));
1474
1475   int array_size_ul;
1476
1477   if (bytes_ul <= 64) {
1478     array_size_ul = 1;
1479
1480     uint8_t buffer[array_size_ul];
1481     buffer[0] = bytes_ul & 0xFF;
1482     bytesul->buf = (uint8_t*)calloc(1,1);
1483     memcpy(bytesul->buf,buffer,1);
1484     bytesul->size = 1;
1485
1486   } else if (bytes_ul <= 16384) {
1487     array_size_ul = 2;
1488
1489     uint8_t buffer[array_size_ul];
1490     buffer[0] = (bytes_ul >> 8) & 0xFF;
1491     buffer[1] = bytes_ul & 0xFF;
1492     bytesul->buf = (uint8_t*)calloc(2,1);
1493     memcpy(bytesul->buf,buffer,2);
1494     bytesul->size = 2;
1495     
1496   } else if (bytes_ul <= 4194304) {
1497     array_size_ul = 3;
1498
1499     uint8_t buffer[array_size_ul];
1500     buffer[0] = (bytes_ul >> 16) & 0xFF;
1501     buffer[1] = (bytes_ul >> 8) & 0xFF;
1502     buffer[2] = bytes_ul & 0xFF;
1503     bytesul->buf = (uint8_t*)calloc(3,1);
1504     memcpy(bytesul->buf,buffer,3);
1505     bytesul->size = 3;    
1506     
1507   } else if (bytes_ul <= 1073741824) {
1508     array_size_ul = 4;
1509     uint8_t buffer[array_size_ul];
1510     buffer[0] = (bytes_ul >> 24) & 0xFF;
1511     buffer[1] = (bytes_ul >> 16) & 0xFF;
1512     buffer[2] = (bytes_ul >> 8) & 0xFF;
1513     buffer[3] = bytes_ul & 0xFF;
1514     bytesul->buf = (uint8_t*)calloc(4,1);
1515     memcpy(bytesul->buf,buffer,4);
1516     bytesul->size = 4;
1517   }
1518   
1519   long fqi = 9;
1520   FQIPERSlicesPerPlmnListItem_t *fqilistitem = (FQIPERSlicesPerPlmnListItem_t*)calloc(1, sizeof(FQIPERSlicesPerPlmnListItem_t));
1521   ASN_STRUCT_RESET(asn_DEF_FQIPERSlicesPerPlmnListItem, fqilistitem);
1522   fqilistitem->fiveQI = fqi;
1523   fqilistitem->pDCPBytesDL = bytesdl;
1524   fqilistitem->pDCPBytesUL = bytesul;
1525
1526
1527   uint8_t *buf1 = (uint8_t*)"4";  
1528   uint8_t *bufz = (uint8_t*)"SD1";
1529   
1530   SNSSAI_t *snssai = (SNSSAI_t*)calloc(1, sizeof(SNSSAI_t));
1531   ASN_STRUCT_RESET(asn_DEF_SNSSAI,snssai);
1532   snssai->sST.buf = (uint8_t*)calloc(1,1);
1533   snssai->sST.size = 1;
1534   memcpy(snssai->sST.buf, sst_buf, 1);
1535   snssai->sD = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
1536   snssai->sD->buf = (uint8_t*)calloc(1,3);
1537   snssai->sD->size = 3;
1538   memcpy(snssai->sD->buf, sd_buf, 3);
1539
1540   
1541
1542   SliceToReportListItem_t *slicelistitem = (SliceToReportListItem_t*)calloc(1,sizeof(SliceToReportListItem_t));
1543   ASN_STRUCT_RESET(asn_DEF_SliceToReportListItem, slicelistitem);
1544   slicelistitem->sliceID = *snssai;
1545   int ret = ASN_SEQUENCE_ADD(&slicelistitem->fQIPERSlicesPerPlmnList.list, fqilistitem);
1546   if (snssai) free(snssai);
1547
1548   asn_codec_ctx_t *opt_cod;  
1549
1550
1551   uint8_t e2smbuffera[8192] = {0, };
1552   size_t e2smbuffer_sizea = 8192;
1553
1554
1555
1556   asn_enc_rval_t era =
1557     asn_encode_to_buffer(opt_cod,
1558                          ATS_ALIGNED_BASIC_PER,
1559                          &asn_DEF_SliceToReportListItem,
1560                          slicelistitem, e2smbuffera, e2smbuffer_sizea);
1561   fprintf(stderr, "inner er encded is %d\n", era.encoded);
1562   fprintf(stderr, "after encoding message\n");      
1563
1564
1565
1566   FGC_CUUP_PM_Format_t *pm_format = (FGC_CUUP_PM_Format_t*)calloc(1,sizeof(FGC_CUUP_PM_Format_t));
1567   ASN_STRUCT_RESET(asn_DEF_FGC_CUUP_PM_Format, pm_format);
1568   ret = ASN_SEQUENCE_ADD(&pm_format->sliceToReportList.list, slicelistitem);
1569
1570   uint8_t *buf2 = (uint8_t*)"747";
1571   //  std::string pl = "PLMNID7";
1572   //  std::vector<uint8_t> plvec(pl.begin(), pl.end());
1573   //  uint8_t *buf2 = &plvec[0];
1574   
1575   OCTET_STRING_t *plmnid = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
1576   plmnid->buf = (uint8_t*)calloc(3,1);
1577   plmnid->size = 3;
1578   memcpy(plmnid->buf, plmnid_buf, plmnid->size);
1579
1580
1581   PlmnID_List_t *plmnidlist = (PlmnID_List_t*)calloc(1,sizeof(PlmnID_List_t));
1582   ASN_STRUCT_RESET(asn_DEF_PlmnID_List, plmnidlist);
1583   plmnidlist->pLMN_Identity = *plmnid;
1584   plmnidlist->cu_UP_PM_5GC = pm_format;
1585   if (plmnid) free(plmnid);
1586
1587   CUUPMeasurement_Container_t *meas_cont = (CUUPMeasurement_Container_t*)calloc(1, sizeof(CUUPMeasurement_Container_t));
1588   ASN_STRUCT_RESET(asn_DEF_CUUPMeasurement_Container, meas_cont);
1589   ret = ASN_SEQUENCE_ADD(&meas_cont->plmnList.list, plmnidlist);
1590
1591
1592   
1593   
1594   PF_ContainerListItem_t *listitem1 = (PF_ContainerListItem_t*)calloc(1, sizeof(PF_ContainerListItem_t));
1595   ASN_STRUCT_RESET(asn_DEF_PF_ContainerListItem, listitem1);
1596   listitem1->interface_type = 2;
1597   listitem1->o_CU_UP_PM_Container = *meas_cont;
1598   if (meas_cont) free(meas_cont);
1599
1600   OCUUP_PF_Container_t *cuupcont = (OCUUP_PF_Container_t*)calloc(1,sizeof(OCUUP_PF_Container_t));
1601   ASN_STRUCT_RESET(asn_DEF_OCUUP_PF_Container, cuupcont);
1602   cuupcont->gNB_CU_UP_Name = gnbcuupname;
1603   ret = ASN_SEQUENCE_ADD(&cuupcont->pf_ContainerList.list, listitem1);
1604   
1605   PF_Container_PR pres1 = PF_Container_PR_oCU_UP;
1606
1607   PF_Container_t *pfcontainer = (PF_Container_t*)calloc(1, sizeof(PF_Container_t));
1608   ASN_STRUCT_RESET(asn_DEF_PF_Container, pfcontainer);
1609   pfcontainer->present = pres1;
1610   pfcontainer->choice.oCU_UP = *cuupcont;
1611   if (cuupcont) free(cuupcont);
1612
1613   PM_Containers_List_t *containers_list = (PM_Containers_List_t*)calloc(1, sizeof(PM_Containers_List_t));
1614   ASN_STRUCT_RESET(asn_DEF_PM_Containers_List, containers_list);
1615   containers_list->performanceContainer = pfcontainer;
1616
1617   E2SM_KPM_IndicationMessage_Format1_t *format =
1618     (E2SM_KPM_IndicationMessage_Format1_t*)calloc(1, sizeof(E2SM_KPM_IndicationMessage_Format1_t));
1619   ASN_STRUCT_RESET(asn_DEF_E2SM_KPM_IndicationMessage_Format1, format);
1620
1621   ret = ASN_SEQUENCE_ADD(&format->pm_Containers.list, containers_list);
1622   
1623   E2SM_KPM_IndicationMessage__indicationMessage_PR pres = E2SM_KPM_IndicationMessage__indicationMessage_PR_indicationMessage_Format1;
1624
1625   indicationmessage->indicationMessage.present = pres;
1626
1627   indicationmessage->indicationMessage.choice.indicationMessage_Format1 = *format;
1628   if (format) free(format);
1629
1630   char error_buf[300] = {0, };
1631   size_t errlen = 0;
1632
1633   asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf, &errlen);
1634   printf("error length %d\n", errlen);
1635   printf("error buf %s\n", error_buf);
1636
1637   xer_fprint(stderr, &asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage);
1638   
1639
1640   uint8_t e2smbuffer[8192] = {0, };
1641   size_t e2smbuffer_size = 8192;
1642
1643   uint8_t e2smbuffer2[8192] = {0, };
1644   size_t e2smbuffer_size2 = 8192;  
1645
1646   asn_enc_rval_t er =
1647     asn_encode_to_buffer(opt_cod,
1648                          ATS_ALIGNED_BASIC_PER,
1649                          &asn_DEF_E2SM_KPM_IndicationMessage,
1650                          indicationmessage, e2smbuffer, e2smbuffer_size);
1651
1652   fprintf(stderr, "er encded is %d\n", er.encoded);
1653   fprintf(stderr, "after encoding message\n");  
1654
1655
1656 }
1657
1658 void encode_kpm_report_style5(E2SM_KPM_IndicationMessage_t* indicationmessage) {
1659
1660   ASN_STRUCT_RESET(asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage);
1661
1662
1663   uint8_t *buf = (uint8_t*)"GNBCUUP5";
1664   OCTET_STRING_t *gnbcuupname = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
1665   gnbcuupname->size = 8;
1666   gnbcuupname->buf = (uint8_t*)calloc(1,8);
1667   memcpy(gnbcuupname->buf, buf, gnbcuupname->size);
1668
1669
1670   INTEGER_t *bytesdl = (INTEGER_t*)calloc(1, sizeof(INTEGER_t));
1671   uint8_t buffer[1];
1672   buffer[0]= 40000;
1673   bytesdl->buf = (uint8_t*)calloc(1,1);
1674   memcpy(bytesdl->buf, buffer,1);
1675   bytesdl->size = 1;
1676
1677   INTEGER_t *bytesul = (INTEGER_t*)calloc(1, sizeof(INTEGER_t));
1678   uint8_t buffer1[1];
1679   buffer1[0] = 50000;
1680   bytesul->buf = (uint8_t*)calloc(1,1);
1681   memcpy(bytesul->buf, buffer1, 1);
1682   bytesul->size = 1;
1683
1684   FQIPERSlicesPerPlmnListItem_t *fqilistitem = (FQIPERSlicesPerPlmnListItem_t*)calloc(1, sizeof(FQIPERSlicesPerPlmnListItem_t));
1685   ASN_STRUCT_RESET(asn_DEF_FQIPERSlicesPerPlmnListItem, fqilistitem);
1686   fqilistitem->fiveQI = 9;
1687   fqilistitem->pDCPBytesDL = bytesdl;
1688   fqilistitem->pDCPBytesUL = bytesul;
1689
1690
1691   uint8_t *buf1 = (uint8_t*)"4";  
1692   uint8_t *bufz = (uint8_t*)"SD1";
1693   
1694   SNSSAI_t *snssai = (SNSSAI_t*)calloc(1, sizeof(SNSSAI_t));
1695   ASN_STRUCT_RESET(asn_DEF_SNSSAI,snssai);
1696   snssai->sST.buf = (uint8_t*)calloc(1,1);
1697   snssai->sST.size = 1;
1698   memcpy(snssai->sST.buf, buf1, 1);
1699   snssai->sD = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
1700   snssai->sD->buf = (uint8_t*)calloc(1,3);
1701   snssai->sD->size = 3;
1702   memcpy(snssai->sD->buf, bufz, 3);
1703
1704   
1705
1706   SliceToReportListItem_t *slicelistitem = (SliceToReportListItem_t*)calloc(1,sizeof(SliceToReportListItem_t));
1707   ASN_STRUCT_RESET(asn_DEF_SliceToReportListItem, slicelistitem);
1708   slicelistitem->sliceID = *snssai;
1709   int ret = ASN_SEQUENCE_ADD(&slicelistitem->fQIPERSlicesPerPlmnList.list, fqilistitem);
1710   if (snssai) free(snssai);
1711
1712   asn_codec_ctx_t *opt_cod;  
1713
1714
1715   uint8_t e2smbuffera[8192] = {0, };
1716   size_t e2smbuffer_sizea = 8192;
1717
1718
1719
1720   asn_enc_rval_t era =
1721     asn_encode_to_buffer(opt_cod,
1722                          ATS_ALIGNED_BASIC_PER,
1723                          &asn_DEF_SliceToReportListItem,
1724                          slicelistitem, e2smbuffera, e2smbuffer_sizea);
1725   fprintf(stderr, "inner er encded is %d\n", era.encoded);
1726   fprintf(stderr, "after encoding message\n");
1727
1728
1729
1730   FGC_CUUP_PM_Format_t *pm_format = (FGC_CUUP_PM_Format_t*)calloc(1,sizeof(FGC_CUUP_PM_Format_t));
1731   ASN_STRUCT_RESET(asn_DEF_FGC_CUUP_PM_Format, pm_format);
1732   ret = ASN_SEQUENCE_ADD(&pm_format->sliceToReportList.list, slicelistitem);
1733
1734   uint8_t *buf2 = (uint8_t*)"747";
1735   //  std::string pl = "PLMNID7";
1736   //  std::vector<uint8_t> plvec(pl.begin(), pl.end());
1737   //  uint8_t *buf2 = &plvec[0];
1738   
1739   OCTET_STRING_t *plmnid = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
1740   plmnid->buf = (uint8_t*)calloc(3,1);
1741   plmnid->size = 3;
1742   memcpy(plmnid->buf, buf2, plmnid->size);
1743
1744
1745   PlmnID_List_t *plmnidlist = (PlmnID_List_t*)calloc(1,sizeof(PlmnID_List_t));
1746   ASN_STRUCT_RESET(asn_DEF_PlmnID_List, plmnidlist);
1747   plmnidlist->pLMN_Identity = *plmnid;
1748   plmnidlist->cu_UP_PM_5GC = pm_format;
1749
1750   CUUPMeasurement_Container_t *meas_cont = (CUUPMeasurement_Container_t*)calloc(1, sizeof(CUUPMeasurement_Container_t));
1751   ASN_STRUCT_RESET(asn_DEF_CUUPMeasurement_Container, meas_cont);
1752   ret = ASN_SEQUENCE_ADD(&meas_cont->plmnList.list, plmnidlist);
1753
1754
1755   
1756   
1757   PF_ContainerListItem_t *listitem1 = (PF_ContainerListItem_t*)calloc(1, sizeof(PF_ContainerListItem_t));
1758   ASN_STRUCT_RESET(asn_DEF_PF_ContainerListItem, listitem1);
1759   listitem1->interface_type = 2;
1760   listitem1->o_CU_UP_PM_Container = *meas_cont;
1761   if (meas_cont) free(meas_cont);
1762
1763   OCUUP_PF_Container_t *cuupcont = (OCUUP_PF_Container_t*)calloc(1,sizeof(OCUUP_PF_Container_t));
1764   ASN_STRUCT_RESET(asn_DEF_OCUUP_PF_Container, cuupcont);
1765   cuupcont->gNB_CU_UP_Name = gnbcuupname;
1766   ret = ASN_SEQUENCE_ADD(&cuupcont->pf_ContainerList.list, listitem1);
1767   
1768   PF_Container_PR pres1 = PF_Container_PR_oCU_UP;
1769
1770   PF_Container_t *pfcontainer = (PF_Container_t*)calloc(1, sizeof(PF_Container_t));
1771   ASN_STRUCT_RESET(asn_DEF_PF_Container, pfcontainer);
1772   pfcontainer->present = pres1;
1773   pfcontainer->choice.oCU_UP = *cuupcont;
1774   if (cuupcont) free(cuupcont);
1775
1776   PM_Containers_List_t *containers_list = (PM_Containers_List_t*)calloc(1, sizeof(PM_Containers_List_t));
1777   ASN_STRUCT_RESET(asn_DEF_PM_Containers_List, containers_list);
1778   containers_list->performanceContainer = pfcontainer;
1779
1780   E2SM_KPM_IndicationMessage_Format1_t *format =
1781     (E2SM_KPM_IndicationMessage_Format1_t*)calloc(1, sizeof(E2SM_KPM_IndicationMessage_Format1_t));
1782   ASN_STRUCT_RESET(asn_DEF_E2SM_KPM_IndicationMessage_Format1, format);
1783
1784   ret = ASN_SEQUENCE_ADD(&format->pm_Containers.list, containers_list);
1785   
1786   E2SM_KPM_IndicationMessage__indicationMessage_PR pres = E2SM_KPM_IndicationMessage__indicationMessage_PR_indicationMessage_Format1;
1787
1788   indicationmessage->indicationMessage.present = pres;
1789
1790   indicationmessage->indicationMessage.choice.indicationMessage_Format1 = *format;
1791   if (format) free(format);
1792
1793   char error_buf[300] = {0, };
1794   size_t errlen = 0;
1795
1796   asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf, &errlen);
1797   printf("error length %d\n", errlen);
1798   printf("error buf %s\n", error_buf);
1799
1800   xer_fprint(stderr, &asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage);
1801   
1802
1803   uint8_t e2smbuffer[8192] = {0, };
1804   size_t e2smbuffer_size = 8192;
1805
1806   uint8_t e2smbuffer2[8192] = {0, };
1807   size_t e2smbuffer_size2 = 8192;  
1808
1809   asn_enc_rval_t er =
1810     asn_encode_to_buffer(opt_cod,
1811                          ATS_ALIGNED_BASIC_PER,
1812                          &asn_DEF_E2SM_KPM_IndicationMessage,
1813                          indicationmessage, e2smbuffer, e2smbuffer_size);
1814
1815   fprintf(stderr, "er encded is %d\n", er.encoded);
1816   fprintf(stderr, "after encoding message\n");
1817
1818 }
1819
1820
1821 void encode_kpm(E2SM_KPM_IndicationMessage_t* indicationmessage) {
1822
1823   /*
1824   ASN_STRUCT_RESET(asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage);
1825   //std::string gn = "GNBCUUP5";
1826   //std::vector<uint8_t> gnvec(gn.begin(), gn.end());
1827   //uint8_t *buf = &gnvec[0];
1828   uint8_t *buf = (uint8_t*)"GNBCUUP5";
1829   OCTET_STRING_t *gnbcuupname = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
1830   gnbcuupname->size = 8;
1831   gnbcuupname->buf = (uint8_t*)calloc(1,8);
1832   memcpy(gnbcuupname->buf, buf, gnbcuupname->size);
1833
1834
1835   INTEGER_t *bytesdl = (INTEGER_t*)calloc(1, sizeof(INTEGER_t));
1836   uint8_t buffer[1];
1837   buffer[0]= 40000;
1838   bytesdl->buf = (uint8_t*)calloc(1,1);
1839   memcpy(bytesdl->buf, buffer,1);
1840   bytesdl->size = 1;
1841
1842   INTEGER_t *bytesul = (INTEGER_t*)calloc(1, sizeof(INTEGER_t));
1843   uint8_t buffer1[1];
1844   buffer1[0] = 50000;
1845   bytesul->buf = (uint8_t*)calloc(1,1);
1846   memcpy(bytesul->buf, buffer1, 1);
1847   bytesul->size = 1;
1848
1849   FQIPERSlicesPerPlmnListItem_t *fqilistitem = (FQIPERSlicesPerPlmnListItem_t*)calloc(1, sizeof(FQIPERSlicesPerPlmnListItem_t));
1850   ASN_STRUCT_RESET(asn_DEF_FQIPERSlicesPerPlmnListItem, fqilistitem);
1851   fqilistitem->fiveQI = 9;
1852   fqilistitem->pDCPBytesDL = bytesdl;
1853   fqilistitem->pDCPBytesUL = bytesul;
1854
1855
1856
1857   //  std::string sl = "SLICE4";
1858   //  std::vector<uint8_t> slvec(sl.begin(), sl.end());
1859   //  uint8_t *buf1 = &slvec[0];
1860   uint8_t *buf1 = (uint8_t*)"4";  
1861   OCTET_STRING_t *sst = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
1862   sst->size = 6;
1863   sst->buf = (uint8_t*)calloc(1,6);
1864   memcpy(sst->buf,buf1,sst->size);
1865
1866   //  std::string sd = "SD1";
1867   //  std::vector<uint8_t> sdvec(sd.begin(), sd.end());
1868   //  uint8_t *bufz = &sdvec[0];
1869   uint8_t *bufz = (uint8_t*)"SD1";
1870   OCTET_STRING_t *sds = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
1871   sds->size = 3;
1872   sds->buf = (uint8_t*)calloc(1,3);
1873   memcpy(sds->buf, bufz, sds->size);
1874
1875   
1876   SNSSAI_t *snssai = (SNSSAI_t*)calloc(1, sizeof(SNSSAI_t));
1877   ASN_STRUCT_RESET(asn_DEF_SNSSAI,snssai);
1878   snssai->sST.buf = (uint8_t*)calloc(1,1);
1879   snssai->sST.size = 1;
1880   memcpy(snssai->sST.buf, buf1, 1);
1881   snssai->sD = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
1882   snssai->sD->buf = (uint8_t*)calloc(1,3);
1883   snssai->sD->size = 3;
1884   memcpy(snssai->sD->buf, bufz, 3);
1885
1886   
1887
1888   SliceToReportListItem_t *slicelistitem = (SliceToReportListItem_t*)calloc(1,sizeof(SliceToReportListItem_t));
1889   ASN_STRUCT_RESET(asn_DEF_SliceToReportListItem, slicelistitem);
1890   slicelistitem->sliceID = *snssai;
1891   int ret = ASN_SEQUENCE_ADD(&slicelistitem->fQIPERSlicesPerPlmnList.list, fqilistitem);
1892
1893   asn_codec_ctx_t *opt_cod;  
1894
1895
1896   uint8_t e2smbuffera[8192];
1897   size_t e2smbuffer_sizea = 8192;
1898
1899
1900
1901   asn_enc_rval_t era =
1902     asn_encode_to_buffer(opt_cod,
1903                          ATS_ALIGNED_BASIC_PER,
1904                          &asn_DEF_SliceToReportListItem,
1905                          slicelistitem, e2smbuffera, e2smbuffer_sizea);
1906   fprintf(stderr, "inner er encded is %d\n", era.encoded);
1907   fprintf(stderr, "after encoding message\n");      
1908
1909
1910
1911   FGC_CUUP_PM_Format_t *pm_format = (FGC_CUUP_PM_Format_t*)calloc(1,sizeof(FGC_CUUP_PM_Format_t));
1912   ASN_STRUCT_RESET(asn_DEF_FGC_CUUP_PM_Format, pm_format);
1913   ret = ASN_SEQUENCE_ADD(&pm_format->sliceToReportList.list, slicelistitem);
1914
1915   uint8_t *buf2 = (uint8_t*)"747";
1916   //  std::string pl = "PLMNID7";
1917   //  std::vector<uint8_t> plvec(pl.begin(), pl.end());
1918   //  uint8_t *buf2 = &plvec[0];
1919   
1920   OCTET_STRING_t *plmnid = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
1921   plmnid->buf = (uint8_t*)calloc(3,1);
1922   plmnid->size = 3;
1923   memcpy(plmnid->buf, buf2, plmnid->size);
1924
1925
1926   PlmnID_List_t *plmnidlist = (PlmnID_List_t*)calloc(1,sizeof(PlmnID_List_t));
1927   ASN_STRUCT_RESET(asn_DEF_PlmnID_List, plmnidlist);
1928   plmnidlist->pLMN_Identity = *plmnid;
1929   plmnidlist->cu_UP_PM_5GC = pm_format;
1930
1931   CUUPMeasurement_Container_t *meas_cont = (CUUPMeasurement_Container_t*)calloc(1, sizeof(CUUPMeasurement_Container_t));
1932   ASN_STRUCT_RESET(asn_DEF_CUUPMeasurement_Container, meas_cont);
1933   ret = ASN_SEQUENCE_ADD(&meas_cont->plmnList.list, plmnidlist);
1934
1935
1936   
1937   
1938   PF_ContainerListItem_t *listitem1 = (PF_ContainerListItem_t*)calloc(1, sizeof(PF_ContainerListItem_t));
1939   ASN_STRUCT_RESET(asn_DEF_PF_ContainerListItem, listitem1);
1940   listitem1->interface_type = 2;
1941   listitem1->o_CU_UP_PM_Container = *meas_cont;
1942
1943   OCUUP_PF_Container_t *cuupcont = (OCUUP_PF_Container_t*)calloc(1,sizeof(OCUUP_PF_Container_t));
1944   ASN_STRUCT_RESET(asn_DEF_OCUUP_PF_Container, cuupcont);
1945   cuupcont->gNB_CU_UP_Name = gnbcuupname;
1946   ret = ASN_SEQUENCE_ADD(&cuupcont->pf_ContainerList.list, listitem1);
1947   
1948   PF_Container_PR pres1 = PF_Container_PR_oCU_UP;
1949
1950   PF_Container_t *pfcontainer = (PF_Container_t*)calloc(1, sizeof(PF_Container_t));
1951   ASN_STRUCT_RESET(asn_DEF_PF_Container, pfcontainer);
1952   pfcontainer->present = pres1;
1953   pfcontainer->choice.oCU_UP = *cuupcont;
1954
1955   PM_Containers_List_t *containers_list = (PM_Containers_List_t*)calloc(1, sizeof(PM_Containers_List_t));
1956   ASN_STRUCT_RESET(asn_DEF_PM_Containers_List, containers_list);
1957   containers_list->performanceContainer = pfcontainer;
1958
1959   E2SM_KPM_IndicationMessage_Format1_t *format =
1960     (E2SM_KPM_IndicationMessage_Format1_t*)calloc(1, sizeof(E2SM_KPM_IndicationMessage_Format1_t));
1961   ASN_STRUCT_RESET(asn_DEF_E2SM_KPM_IndicationMessage_Format1, format);
1962
1963   ret = ASN_SEQUENCE_ADD(&format->pm_Containers.list, containers_list);
1964   
1965   E2SM_KPM_IndicationMessage_PR pres = E2SM_KPM_IndicationMessage_PR_indicationMessage_Format1;
1966
1967   indicationmessage->present = pres;
1968
1969   indicationmessage->choice.indicationMessage_Format1 = *format;
1970
1971   char *error_buf = (char*)calloc(300, sizeof(char));
1972   size_t errlen;
1973
1974   asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf, &errlen);
1975   printf("error length %d\n", errlen);
1976   printf("error buf %s\n", error_buf);
1977
1978   xer_fprint(stderr, &asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage);
1979   
1980
1981   uint8_t e2smbuffer[8192];
1982   size_t e2smbuffer_size = 8192;
1983
1984   uint8_t e2smbuffer2[8192];
1985   size_t e2smbuffer_size2 = 8192;  
1986
1987   asn_enc_rval_t er =
1988     asn_encode_to_buffer(opt_cod,
1989                          ATS_ALIGNED_BASIC_PER,
1990                          &asn_DEF_E2SM_KPM_IndicationMessage,
1991                          indicationmessage, e2smbuffer, e2smbuffer_size);
1992
1993   fprintf(stderr, "er encded is %d\n", er.encoded);
1994   fprintf(stderr, "after encoding message\n");
1995
1996   */
1997 }
1998
1999 /*
2000 void encode_kpm_bak(E2SM_KPM_IndicationMessage_t* indicationmessage) {
2001   ASN_STRUCT_RESET(asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage);
2002   std::string gn = "GNBCUUP5";
2003   std::vector<uint8_t> gnvec(gn.begin(), gn.end());
2004   uint8_t *buf = &gnvec[0];
2005   OCTET_STRING_t *gnbcuupname = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
2006   gnbcuupname->size = 8;
2007   gnbcuupname->buf = (uint8_t*)calloc(1,8);
2008   memcpy(gnbcuupname->buf, buf, gnbcuupname->size);
2009
2010
2011   INTEGER_t *bytesdl = (INTEGER_t*)calloc(1, sizeof(INTEGER_t));
2012   uint8_t buffer[1];
2013   buffer[0]= 40000;
2014   bytesdl->buf = (uint8_t*)calloc(1,1);
2015   memcpy(bytesdl->buf, buffer,1);
2016   bytesdl->size = 1;
2017
2018   INTEGER_t *bytesul = (INTEGER_t*)calloc(1, sizeof(INTEGER_t));
2019   uint8_t buffer1[1];
2020   buffer1[0] = 50000;
2021   bytesul->buf = (uint8_t*)calloc(1,1);
2022   memcpy(bytesul->buf, buffer1, 1);
2023   bytesul->size = 1;
2024
2025   FQIPERSlicesPerPlmnListItem_t *fqilistitem = (FQIPERSlicesPerPlmnListItem_t*)calloc(1, sizeof(FQIPERSlicesPerPlmnListItem_t));
2026   ASN_STRUCT_RESET(asn_DEF_FQIPERSlicesPerPlmnListItem, fqilistitem);
2027   fqilistitem->fiveQI = 9;
2028   fqilistitem->pDCPBytesDL = bytesdl;
2029   fqilistitem->pDCPBytesUL = bytesul;
2030
2031
2032
2033   std::string sl = "SLICE4";
2034   std::vector<uint8_t> slvec(sl.begin(), sl.end());
2035   //  uint8_t *buf1 = &slvec[0];
2036   uint8_t *buf1 = (uint8_t*)"SLICE4";  
2037   OCTET_STRING_t *sst = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
2038   sst->size = 6;
2039   sst->buf = (uint8_t*)calloc(1,6);
2040   memcpy(sst->buf,buf1,sst->size);
2041
2042   std::string sd = "SD1";
2043   std::vector<uint8_t> sdvec(sd.begin(), sd.end());
2044   //  uint8_t *bufz = &sdvec[0];
2045   uint8_t *bufz = (uint8_t*)"SD1";
2046   OCTET_STRING_t *sds = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
2047   sds->size = 3;
2048   sds->buf = (uint8_t*)calloc(1,3);
2049   memcpy(sds->buf, bufz, sds->size);
2050
2051   
2052   SNSSAI_t *snssai = (SNSSAI_t*)calloc(1, sizeof(SNSSAI_t));
2053   ASN_STRUCT_RESET(asn_DEF_SNSSAI,snssai);
2054   snssai->sST.buf = (uint8_t*)calloc(6,1);
2055   snssai->sST.size = 6;
2056   memcpy(snssai->sST.buf, buf1, 6);
2057   snssai->sD = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
2058   snssai->sD->buf = (uint8_t*)calloc(1,3);
2059   snssai->sD->size = 3;
2060   memcpy(snssai->sD->buf, bufz, 3);
2061
2062   
2063
2064   SliceToReportListItem_t *slicelistitem = (SliceToReportListItem_t*)calloc(1,sizeof(SliceToReportListItem_t));
2065   ASN_STRUCT_RESET(asn_DEF_SliceToReportListItem, slicelistitem);
2066   slicelistitem->sliceID = *snssai;
2067   int ret = ASN_SEQUENCE_ADD(&slicelistitem->fQIPERSlicesPerPlmnList.list, fqilistitem);
2068
2069   uint8_t e2smbuffera[8192];
2070   size_t e2smbuffer_sizea = 8192;  
2071
2072   auto era =
2073     asn_encode_to_buffer(nullptr,
2074                          ATS_ALIGNED_BASIC_PER,
2075                          &asn_DEF_SliceToReportListItem,
2076                          slicelistitem, e2smbuffera, e2smbuffer_sizea);
2077   fprintf(stderr, "inner er encded is %d\n", era.encoded);
2078   fprintf(stderr, "after encoding message\n");      
2079
2080   FGC_CUUP_PM_Format_t *pm_format = (FGC_CUUP_PM_Format_t*)calloc(1,sizeof(FGC_CUUP_PM_Format_t));
2081   ASN_STRUCT_RESET(asn_DEF_FGC_CUUP_PM_Format, pm_format);
2082   ret = ASN_SEQUENCE_ADD(&pm_format->sliceToReportList.list, slicelistitem);
2083
2084   std::string pl = "PLMNID7";
2085   std::vector<uint8_t> plvec(pl.begin(), pl.end());
2086   uint8_t *buf2 = &plvec[0];
2087   
2088   OCTET_STRING_t *plmnid = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
2089   plmnid->buf = (uint8_t*)calloc(1,7);
2090   plmnid->size = 7;  
2091   memcpy(plmnid->buf, buf2, plmnid->size);
2092
2093
2094   PlmnID_List_t *plmnidlist = (PlmnID_List_t*)calloc(1,sizeof(PlmnID_List_t));
2095   ASN_STRUCT_RESET(asn_DEF_PlmnID_List, plmnidlist);
2096   plmnidlist->pLMN_Identity = *plmnid;
2097   plmnidlist->cu_UP_PM_5GC = pm_format;
2098
2099   CUUPMeasurement_Container_t *meas_cont = (CUUPMeasurement_Container_t*)calloc(1, sizeof(CUUPMeasurement_Container_t));
2100   ASN_STRUCT_RESET(asn_DEF_CUUPMeasurement_Container, meas_cont);
2101   ret = ASN_SEQUENCE_ADD(&meas_cont->plmnList.list, plmnidlist);
2102
2103
2104   
2105   
2106   PF_ContainerListItem_t *listitem1 = (PF_ContainerListItem_t*)calloc(1, sizeof(PF_ContainerListItem_t));
2107   ASN_STRUCT_RESET(asn_DEF_PF_ContainerListItem, listitem1);
2108   listitem1->interface_type = 2;
2109   listitem1->o_CU_UP_PM_Container = *meas_cont;
2110
2111   OCUUP_PF_Container_t *cuupcont = (OCUUP_PF_Container_t*)calloc(1,sizeof(OCUUP_PF_Container_t));
2112   ASN_STRUCT_RESET(asn_DEF_OCUUP_PF_Container, cuupcont);
2113   cuupcont->gNB_CU_UP_Name = gnbcuupname;
2114   ret = ASN_SEQUENCE_ADD(&cuupcont->pf_ContainerList.list, listitem1);
2115   
2116   PF_Container_PR pres1 = PF_Container_PR_oCU_UP;
2117
2118   PF_Container_t *pfcontainer = (PF_Container_t*)calloc(1, sizeof(PF_Container_t));
2119   ASN_STRUCT_RESET(asn_DEF_PF_Container, pfcontainer);
2120   pfcontainer->present = pres1;
2121   pfcontainer->choice.oCU_UP = *cuupcont;
2122
2123   PM_Containers_List_t *containers_list = (PM_Containers_List_t*)calloc(1, sizeof(PM_Containers_List_t));
2124   ASN_STRUCT_RESET(asn_DEF_PM_Containers_List, containers_list);
2125   containers_list->performanceContainer = pfcontainer;
2126
2127   E2SM_KPM_IndicationMessage_Format1_t *format =
2128     (E2SM_KPM_IndicationMessage_Format1_t*)calloc(1, sizeof(E2SM_KPM_IndicationMessage_Format1_t));
2129   ASN_STRUCT_RESET(asn_DEF_E2SM_KPM_IndicationMessage_Format1, format);
2130
2131   ret = ASN_SEQUENCE_ADD(&format->pm_Containers.list, containers_list);
2132   
2133   E2SM_KPM_IndicationMessage_PR pres = E2SM_KPM_IndicationMessage_PR_indicationMessage_Format1;
2134
2135   indicationmessage->present = pres;
2136
2137   indicationmessage->choice.indicationMessage_Format1 = *format;
2138
2139   char *error_buf = (char*)calloc(300, sizeof(char));
2140   size_t errlen;
2141
2142   asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf, &errlen);
2143   printf("error length %d\n", errlen);
2144   printf("error buf %s\n", error_buf);
2145   
2146
2147   uint8_t e2smbuffer[8192];
2148   size_t e2smbuffer_size = 8192;
2149
2150   uint8_t e2smbuffer2[8192];
2151   size_t e2smbuffer_size2 = 8192;  
2152
2153   auto er =
2154     asn_encode_to_buffer(nullptr,
2155                          ATS_ALIGNED_BASIC_PER,
2156                          &asn_DEF_E2SM_KPM_IndicationMessage,
2157                          indicationmessage, e2smbuffer, e2smbuffer_size);
2158
2159   fprintf(stderr, "er encded is %d\n", er.encoded);
2160   fprintf(stderr, "after encoding message\n");
2161
2162   
2163 }
2164 */