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