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