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