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