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