7ab086c49e4ff1e8368b65b7513784f49250ab9a
[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 <unistd.h>
22
23 #include <iostream>
24 #include <vector>
25
26 #include "encode_kpm.hpp"
27 #include "e2sim_defs.h"
28 using namespace std;
29
30 const char* performance_measurements[] = {
31   "DRB.RlcSduTransmittedVolumeDL",
32   "DRB.RlcSduTransmittedVolumeUL",
33   "DRB.PerDataVolumeDLDist.Bin",
34   "DRB.PerDataVolumeULDist.Bin",
35   "DRB.RlcPacketDropRateDLDist",
36   "DRB.PacketLossRateULDist",
37   "L1M.DL-SS-RSRP.SSB",
38   "L1M.DL-SS-SINR.SSB",
39   "L1M.UL-SRS-RSRP"
40   };
41
42 int NUMBER_MEASUREMENTS = 9;
43
44 void encode_kpm_function_description(E2SM_KPM_RANfunction_Description_t* ranfunc_desc) {
45   uint8_t* short_name = (uint8_t*)"ORAN-E2SM-KPM";
46   uint8_t* func_desc = (uint8_t*)"KPM Monitor";
47   uint8_t* e2sm_odi = (uint8_t*)"OID123";
48
49   LOG_I("short_name: %s, func_desc: %s, e2sm_odi: %s", short_name, func_desc, e2sm_odi);
50   ASN_STRUCT_RESET(asn_DEF_E2SM_KPM_RANfunction_Description, ranfunc_desc);
51
52   ranfunc_desc->ranFunction_Name.ranFunction_ShortName.size = strlen((char*)short_name);
53   ranfunc_desc->ranFunction_Name.ranFunction_ShortName.buf =
54       (uint8_t*)calloc(strlen((char*)short_name), sizeof(uint8_t));
55   memcpy(ranfunc_desc->ranFunction_Name.ranFunction_ShortName.buf, short_name,
56          ranfunc_desc->ranFunction_Name.ranFunction_ShortName.size);
57
58   ranfunc_desc->ranFunction_Name.ranFunction_Description.buf =
59       (uint8_t*)calloc(1, strlen((char*)func_desc));
60   memcpy(ranfunc_desc->ranFunction_Name.ranFunction_Description.buf, func_desc,
61          strlen((char*)func_desc));
62   ranfunc_desc->ranFunction_Name.ranFunction_Description.size = strlen((char*)func_desc);
63   ranfunc_desc->ranFunction_Name.ranFunction_Instance = (long *)calloc(1, sizeof(long));
64   *ranfunc_desc->ranFunction_Name.ranFunction_Instance = 1;
65
66   ranfunc_desc->ranFunction_Name.ranFunction_E2SM_OID.buf =
67       (uint8_t*)calloc(1, strlen((char*)e2sm_odi));
68   memcpy(ranfunc_desc->ranFunction_Name.ranFunction_E2SM_OID.buf, e2sm_odi,
69          strlen((char*)e2sm_odi));
70   ranfunc_desc->ranFunction_Name.ranFunction_E2SM_OID.size = strlen((char*)e2sm_odi);
71
72   LOG_I("Initialize event trigger style list structure");
73
74   RIC_EventTriggerStyle_Item_t* trigger_style =
75       (RIC_EventTriggerStyle_Item_t*)calloc(1, sizeof(RIC_EventTriggerStyle_Item_t));
76   trigger_style->ric_EventTriggerStyle_Type = 1;
77   uint8_t* style_name = (uint8_t*)"Periodic Report";
78   trigger_style->ric_EventTriggerStyle_Name.buf = (uint8_t*)calloc(1, strlen((char*)style_name));
79   memcpy(trigger_style->ric_EventTriggerStyle_Name.buf, style_name, strlen((char*)style_name));
80   trigger_style->ric_EventTriggerStyle_Name.size = strlen((char*)style_name);
81   trigger_style->ric_EventTriggerFormat_Type = 1;
82
83   ranfunc_desc->ric_EventTriggerStyle_List =
84       (E2SM_KPM_RANfunction_Description::
85            E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List*)
86           calloc(1, sizeof(E2SM_KPM_RANfunction_Description::
87                                E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List));
88
89   int ret = ASN_SEQUENCE_ADD(&ranfunc_desc->ric_EventTriggerStyle_List->list, trigger_style);
90
91   LOG_I("Initialize report style structure");
92
93   MeasurementInfo_Action_List_t* measInfo_Action_List =
94       (MeasurementInfo_Action_List_t*)calloc(1, sizeof(MeasurementInfo_Action_List_t));
95
96   for (int i = 0; i < NUMBER_MEASUREMENTS; i++) {
97     uint8_t* metrics = (uint8_t *)performance_measurements[i];
98     MeasurementInfo_Action_Item_t* measItem =
99         (MeasurementInfo_Action_Item_t*)calloc(1, sizeof(MeasurementInfo_Action_Item_t));
100     measItem->measName.buf = (uint8_t*)calloc(1, strlen((char*)metrics));
101     memcpy(measItem->measName.buf, metrics, strlen((char*)metrics));
102
103     measItem->measName.size = strlen((char*)metrics);
104
105     measItem->measID = (MeasurementTypeID_t*)calloc(1, sizeof(MeasurementTypeID_t));
106     *measItem->measID = i+1;
107
108     ASN_SEQUENCE_ADD(&measInfo_Action_List->list, measItem);
109   }
110
111   RIC_ReportStyle_Item_t* report_style1 =
112       (RIC_ReportStyle_Item_t*)calloc(1, sizeof(RIC_ReportStyle_Item_t));
113   report_style1->ric_ReportStyle_Type = 1;
114
115   uint8_t* buf5 = (uint8_t*)"E2 Node Measurement";
116   report_style1->ric_ReportStyle_Name.buf = (uint8_t*)calloc(1, strlen((char*)buf5));
117   memcpy(report_style1->ric_ReportStyle_Name.buf, buf5, strlen((char*)buf5));
118   report_style1->ric_ReportStyle_Name.size = strlen((char*)buf5);
119   report_style1->ric_ActionFormat_Type = 1;
120   report_style1->ric_IndicationHeaderFormat_Type = 1;
121   report_style1->ric_IndicationMessageFormat_Type = 1;
122   report_style1->measInfo_Action_List = *measInfo_Action_List;
123
124   RIC_ReportStyle_Item_t* report_style2 =
125       (RIC_ReportStyle_Item_t*)calloc(1, sizeof(RIC_ReportStyle_Item_t));
126   report_style2->ric_ReportStyle_Type = 2;
127
128   uint8_t* buf6 = (uint8_t*)"E2 Node Measurement for a single UE";
129   report_style2->ric_ReportStyle_Name.buf = (uint8_t*)calloc(1, strlen((char*)buf6));
130   memcpy(report_style2->ric_ReportStyle_Name.buf, buf6, strlen((char*)buf6));
131   report_style2->ric_ReportStyle_Name.size = strlen((char*)buf6);
132   report_style2->ric_ActionFormat_Type = 2;
133   report_style2->ric_IndicationHeaderFormat_Type = 1;
134   report_style2->ric_IndicationMessageFormat_Type = 1;
135   report_style2->measInfo_Action_List = *measInfo_Action_List;
136
137   RIC_ReportStyle_Item_t* report_style3 =
138       (RIC_ReportStyle_Item_t*)calloc(1, sizeof(RIC_ReportStyle_Item_t));
139   report_style3->ric_ReportStyle_Type = 3;
140
141   uint8_t* buf7 = (uint8_t*)"Condition-based, UE-level E2 Node Measurement";
142
143   report_style3->ric_ReportStyle_Name.buf = (uint8_t*)calloc(1, strlen((char*)buf7));
144   memcpy(report_style3->ric_ReportStyle_Name.buf, buf7, strlen((char*)buf7));
145   report_style3->ric_ReportStyle_Name.size = strlen((char*)buf7);
146   report_style3->ric_ActionFormat_Type = 3;
147   report_style3->ric_IndicationHeaderFormat_Type = 1;
148   report_style3->ric_IndicationMessageFormat_Type = 2;
149   report_style3->measInfo_Action_List = *measInfo_Action_List;
150
151   RIC_ReportStyle_Item_t* report_style4 =
152       (RIC_ReportStyle_Item_t*)calloc(1, sizeof(RIC_ReportStyle_Item_t));
153   report_style4->ric_ReportStyle_Type = 4;
154
155   uint8_t* buf8 = (uint8_t*)"Common Condition-based, UE-level Measurement";
156
157   report_style4->ric_ReportStyle_Name.buf = (uint8_t*)calloc(1, strlen((char*)buf8));
158   memcpy(report_style4->ric_ReportStyle_Name.buf, buf8, strlen((char*)buf8));
159   report_style4->ric_ReportStyle_Name.size = strlen((char*)buf8);
160   report_style4->ric_ActionFormat_Type = 4;
161   report_style4->ric_IndicationHeaderFormat_Type = 1;
162   report_style4->ric_IndicationMessageFormat_Type = 3;
163   report_style4->measInfo_Action_List = *measInfo_Action_List;
164
165   RIC_ReportStyle_Item_t* report_style5 =
166       (RIC_ReportStyle_Item_t*)calloc(1, sizeof(RIC_ReportStyle_Item_t));
167   report_style5->ric_ReportStyle_Type = 5;
168
169   uint8_t* buf9 = (uint8_t*)"E2 Node Measurement for multiple UEs";
170
171   report_style5->ric_ReportStyle_Name.buf = (uint8_t*)calloc(1, strlen((char*)buf9));
172   memcpy(report_style5->ric_ReportStyle_Name.buf, buf9, strlen((char*)buf9));
173   report_style5->ric_ReportStyle_Name.size = strlen((char*)buf9);
174   report_style5->ric_ActionFormat_Type = 5;
175   report_style5->ric_IndicationHeaderFormat_Type = 1;
176   report_style5->ric_IndicationMessageFormat_Type = 3;
177   report_style5->measInfo_Action_List = *measInfo_Action_List;
178
179   ranfunc_desc->ric_ReportStyle_List =
180       (E2SM_KPM_RANfunction_Description::E2SM_KPM_RANfunction_Description__ric_ReportStyle_List*)
181           calloc(1, sizeof(E2SM_KPM_RANfunction_Description::
182                                E2SM_KPM_RANfunction_Description__ric_ReportStyle_List));
183
184   ASN_SEQUENCE_ADD(&ranfunc_desc->ric_ReportStyle_List->list, report_style1);
185   ASN_SEQUENCE_ADD(&ranfunc_desc->ric_ReportStyle_List->list, report_style2);
186   ASN_SEQUENCE_ADD(&ranfunc_desc->ric_ReportStyle_List->list, report_style3);
187   ASN_SEQUENCE_ADD(&ranfunc_desc->ric_ReportStyle_List->list, report_style4);
188   ASN_SEQUENCE_ADD(&ranfunc_desc->ric_ReportStyle_List->list, report_style5);
189
190   // xer_fprint(stderr, &asn_DEF_E2SM_KPM_RANfunction_Description, ranfunc_desc);
191 }
192
193 void kpm_report_indication_header_initialized(E2SM_KPM_IndicationHeader_t* ihead,
194                                               uint8_t* plmnid_buf, uint8_t* sst_buf,
195                                               uint8_t* sd_buf, long fqival, long qcival,
196                                               uint8_t* nrcellid_buf, uint8_t* gnbid_buf,
197                                               int gnbid_unused, uint8_t* cuupid_buf,
198                                               uint8_t* duid_buf, uint8_t* cuupname_buf) {
199   LOG_I("Start initializing mocked indication header");
200   E2SM_KPM_IndicationHeader_Format1_t* ind_header =
201       (E2SM_KPM_IndicationHeader_Format1_t*)calloc(1, sizeof(E2SM_KPM_IndicationHeader_Format1_t));
202
203   ASN_STRUCT_RESET(asn_DEF_E2SM_KPM_IndicationMessage_Format1, ind_header);
204
205   uint8_t* buf2 = (uint8_t*)"ORANSim";
206   ind_header->senderName = (PrintableString_t*)calloc(1, sizeof(PrintableString_t));
207   ind_header->senderName->buf = (uint8_t*)calloc(1, strlen((char*)buf2));
208   memcpy(ind_header->senderName->buf, buf2, strlen((char*)buf2));
209   ind_header->senderName->size = strlen((char*)buf2);
210
211   uint8_t* buf3 = (uint8_t*)"simulator";
212   ind_header->senderType = (PrintableString_t*)calloc(1, sizeof(PrintableString_t));
213   ind_header->senderType->buf = (uint8_t*)calloc(1, strlen((char*)buf3));
214   memcpy(ind_header->senderType->buf, buf3, strlen((char*)buf3));
215   ind_header->senderType->size = strlen((char*)buf3);
216
217   uint8_t* buf4 = (uint8_t*)"ORAN-SC";
218   ind_header->vendorName = (PrintableString_t*)calloc(1, sizeof(PrintableString_t));
219   ind_header->vendorName->buf = (uint8_t*)calloc(1, strlen((char*)buf4));
220   memcpy(ind_header->vendorName->buf, buf4, strlen((char*)buf4));
221   ind_header->vendorName->size = strlen((char*)buf4);
222
223   uint8_t* buf = (uint8_t*)"20200613";
224   TimeStamp_t* ts = (TimeStamp_t*)calloc(1, sizeof(TimeStamp_t));
225   ts->buf = (uint8_t*)calloc(strlen((char*)buf), 1);
226   ts->size = strlen((char*)buf);
227   memcpy(ts->buf, buf, ts->size);
228
229   ind_header->colletStartTime = *ts;
230   if (ts) free(ts);
231
232   ihead->indicationHeader_formats.present =
233       E2SM_KPM_IndicationHeader__indicationHeader_formats_PR_indicationHeader_Format1;
234   ihead->indicationHeader_formats.choice.indicationHeader_Format1 = ind_header;
235
236 }
237
238 void ue_meas_kpm_report_indication_message_initialized(
239     E2SM_KPM_IndicationMessage_t* indicationmessage, uint8_t* nrcellid_buf, uint8_t* crnti_buf,
240     const uint8_t* serving_buf, const uint8_t* neighbor_buf) {
241   
242   MeasurementRecord_t* measDataItem_record = (MeasurementRecord_t*)calloc(1, sizeof(MeasurementRecord_t));
243   for (size_t i = 0; i < NUMBER_MEASUREMENTS; i++)
244   {
245     MeasurementRecordItem_t* measDataRecordItem = (MeasurementRecordItem_t*)calloc(1, sizeof(MeasurementRecordItem_t));
246     measDataRecordItem->present = MeasurementRecordItem_PR_integer;
247     measDataRecordItem->choice.integer = 1;
248
249     ASN_SEQUENCE_ADD(&measDataItem_record->list, measDataRecordItem);
250   }
251
252   MeasurementDataItem_t* measDataItem = (MeasurementDataItem_t*)calloc(1, sizeof(MeasurementDataItem_t));
253   measDataItem->measRecord = *measDataItem_record;
254   measDataItem->incompleteFlag = (long*)calloc(1, sizeof(long));
255   *measDataItem->incompleteFlag = 0;
256
257   MeasurementData_t* measData = (MeasurementData_t*)calloc(1, sizeof(MeasurementData_t));
258   ASN_SEQUENCE_ADD(&measData->list, measDataItem);
259
260   MeasurementInfoList_t* measList = (MeasurementInfoList_t*)calloc(1, sizeof(MeasurementInfoList_t));
261   for (size_t i = 0; i < NUMBER_MEASUREMENTS; i++)
262   {
263     MeasurementLabel_t* measLabel = (MeasurementLabel_t*)calloc(1, sizeof(MeasurementLabel_t));
264     measLabel->noLabel = (long *)calloc(1, sizeof(long));
265     *measLabel->noLabel = 0;
266
267     LabelInfoItem_t* labelItem = (LabelInfoItem_t*)calloc(1, sizeof(LabelInfoItem_t));
268     labelItem->measLabel = *measLabel;
269
270     LabelInfoList_t* labelList = (LabelInfoList_t*)calloc(1, sizeof(LabelInfoList_t));
271     ASN_SEQUENCE_ADD(&labelList->list, labelItem);
272
273     MeasurementType_t measType;
274     measType.present = MeasurementType_PR_measID;
275     uint8_t* metrics = (uint8_t *)performance_measurements[i];
276     measType.choice.measName.buf = (uint8_t*)calloc(1, strlen((char*)metrics));
277     memcpy(measType.choice.measName.buf, metrics, strlen((char*)metrics));
278     measType.choice.measName.size = strlen((char*)metrics);
279
280     MeasurementInfoItem_t* measItem = (MeasurementInfoItem_t*)calloc(1, sizeof(MeasurementInfoItem_t));
281     measItem->measType = measType;
282     measItem->labelInfoList = *labelList;
283     if (labelList) free(labelList);
284     
285     ASN_SEQUENCE_ADD(&measList->list, measItem);
286   }
287   
288   E2SM_KPM_IndicationMessage_Format1_t* format = (E2SM_KPM_IndicationMessage_Format1_t*)calloc(
289       1, sizeof(E2SM_KPM_IndicationMessage_Format1_t));
290   format->granulPeriod = (GranularityPeriod_t*)calloc(1, sizeof(GranularityPeriod_t));
291   *format->granulPeriod = 1;
292   format->measData = *measData;
293   format->measInfoList = measList;
294
295   E2SM_KPM_IndicationMessage__indicationMessage_formats_PR pres =
296       E2SM_KPM_IndicationMessage__indicationMessage_formats_PR_indicationMessage_Format1;
297
298   indicationmessage->indicationMessage_formats.present = pres;
299   indicationmessage->indicationMessage_formats.choice.indicationMessage_Format1 = format;
300
301   char error_buf[300] = {
302       0,
303   };
304   size_t errlen = 0;
305
306   int ret = asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf,
307                                   &errlen);
308
309   if (ret) {
310     LOG_I("Constraint validation of indication message failed: %s", error_buf);
311     exit(1);
312   }
313
314   // xer_fprint(stderr, &asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage);
315 }
316
317 void cell_meas_kpm_report_indication_message_style_1_initialized(
318     E2SM_KPM_IndicationMessage_t* indicationmessage, long fiveqi, long dl_prb_usage,
319     long ul_prb_usage, uint8_t* nrcellid_buf, long* dl_prbs, long* ul_prbs) {
320   LOG_I("Preparing indication message for cell measurement report");
321
322   asn_codec_ctx_t* opt_cod;
323
324   GranularityPeriod_t period = 1;
325   MeasurementData_t* measData = (MeasurementData_t*)calloc(1, sizeof(MeasurementData_t));
326   MeasurementDataItem_t* measDataItem =
327       (MeasurementDataItem_t*)calloc(1, sizeof(MeasurementDataItem_t));
328   MeasurementRecord_t* measDataItem_record =
329       (MeasurementRecord_t*)calloc(1, sizeof(MeasurementRecord_t));
330   MeasurementRecordItem_t* measDataRecordItem =
331       (MeasurementRecordItem_t*)calloc(1, sizeof(MeasurementRecordItem_t));
332
333   measDataRecordItem->present = MeasurementRecordItem_PR_integer;
334   measDataRecordItem->choice.integer = 1;
335
336   ASN_SEQUENCE_ADD(&measDataItem_record->list, measDataRecordItem);
337
338   measDataItem->measRecord = *measDataItem_record;
339   measDataItem->incompleteFlag = (long*)calloc(1, sizeof(long));
340   *measDataItem->incompleteFlag = 0;
341   ASN_SEQUENCE_ADD(&measData->list, measDataItem);
342
343   E2SM_KPM_IndicationMessage_Format1_t* format = (E2SM_KPM_IndicationMessage_Format1_t*)calloc(
344       1, sizeof(E2SM_KPM_IndicationMessage_Format1_t));
345   format->granulPeriod = (GranularityPeriod_t*)calloc(1, sizeof(GranularityPeriod_t));
346   *format->granulPeriod = period;
347   format->measData = *measData;
348
349   MeasurementInfoList_t* measList =
350       (MeasurementInfoList_t*)calloc(1, sizeof(MeasurementInfoList_t));
351   MeasurementInfoItem_t* measItem =
352       (MeasurementInfoItem_t*)calloc(1, sizeof(MeasurementInfoItem_t));
353   LabelInfoList_t* labelList = (LabelInfoList_t*)calloc(1, sizeof(LabelInfoList_t));
354   LabelInfoItem_t* labelItem = (LabelInfoItem_t*)calloc(1, sizeof(LabelInfoItem_t));
355   MeasurementLabel_t* measLabel = (MeasurementLabel_t*)calloc(1, sizeof(MeasurementLabel_t));
356
357   uint8_t* plmnid_buf = (uint8_t*)"747";
358   uint8_t* sst_buf = (uint8_t*)"1";
359   uint8_t* sd_buf = (uint8_t*)"100";
360
361   S_NSSAI_t* snssai = (S_NSSAI_t*)calloc(1, sizeof(S_NSSAI_t));
362   snssai->sST.buf = (uint8_t*)calloc(strlen((char*)sst_buf), sizeof(uint8_t));
363   snssai->sST.size = strlen((char*)sst_buf);
364   memcpy(snssai->sST.buf, sst_buf, strlen((char*)sst_buf));
365
366   snssai->sD = (SD_t*)calloc(1, sizeof(SD_t));
367   snssai->sD->buf = (uint8_t*)calloc(strlen((char*)sd_buf), sizeof(uint8_t));
368   snssai->sD->size = strlen((char*)sd_buf);
369   memcpy(snssai->sD->buf, sd_buf, strlen((char*)sd_buf));
370
371   int plmnid_size = strlen((char*)plmnid_buf);
372   PLMNIdentity_t* plmnidstr = (PLMNIdentity_t*)calloc(1, sizeof(PLMNIdentity_t));
373   plmnidstr->buf = (uint8_t*)calloc(plmnid_size, 1);
374   plmnidstr->size = plmnid_size;
375   memcpy(plmnidstr->buf, plmnid_buf, plmnidstr->size);
376
377   measLabel->plmnID = plmnidstr;
378   measLabel->sliceID = snssai;
379
380   labelItem->measLabel = *measLabel;
381   ASN_SEQUENCE_ADD(&labelList->list, labelItem);
382   measItem->labelInfoList = *labelList;
383   if (labelList) free(labelList);
384   MeasurementType_t measType;
385   measType.present = MeasurementType_PR_measID;
386   measType.choice.measID = 1;
387   measItem->measType = measType;
388   ASN_SEQUENCE_ADD(&measList->list, measItem);
389
390   format->measInfoList = measList;
391
392   E2SM_KPM_IndicationMessage__indicationMessage_formats_PR pres =
393       E2SM_KPM_IndicationMessage__indicationMessage_formats_PR_indicationMessage_Format1;
394
395   indicationmessage->indicationMessage_formats.present = pres;
396   indicationmessage->indicationMessage_formats.choice.indicationMessage_Format1 = format;
397
398   char error_buf[300] = {
399       0,
400   };
401   size_t errlen = 0;
402
403   int ret = asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf,
404                                   &errlen);
405
406   if (ret) {
407     LOG_I("Constraint validation of indication message failed: %s\n", error_buf);
408     exit(1);
409   }
410 }
411
412 void encode_kpm_report_style1(E2SM_KPM_IndicationMessage_t* indicationmessage) {
413   long fiveqi = 8;
414   long dl_prb_usage = 50;
415   long ul_prb_usage = 70;
416
417   asn_codec_ctx_t* opt_cod;
418
419   GranularityPeriod_t period = 1;
420   MeasurementData_t measData;
421   MeasurementDataItem_t measDataItem;
422   MeasurementRecord_t measDataItem_record;
423   MeasurementRecordItem_t measDataRecordItem;
424
425   measDataRecordItem.present = MeasurementRecordItem_PR_real;
426   measDataRecordItem.choice.real = 1.5;
427
428   ASN_SEQUENCE_ADD(&measDataItem_record.list, &measDataRecordItem);
429
430   measDataItem.measRecord = measDataItem_record;
431   ASN_SEQUENCE_ADD(&measData.list, &measDataItem);
432
433   E2SM_KPM_IndicationMessage_Format1_t* format = (E2SM_KPM_IndicationMessage_Format1_t*)calloc(
434       1, sizeof(E2SM_KPM_IndicationMessage_Format1_t));
435   ASN_STRUCT_RESET(asn_DEF_E2SM_KPM_IndicationMessage_Format1, format);
436
437   format->granulPeriod = &period;
438   format->measData = measData;
439
440   E2SM_KPM_IndicationMessage__indicationMessage_formats_PR pres =
441       E2SM_KPM_IndicationMessage__indicationMessage_formats_PR_indicationMessage_Format1;
442
443   indicationmessage->indicationMessage_formats.present = pres;
444
445   indicationmessage->indicationMessage_formats.choice.indicationMessage_Format1 = format;
446   if (format) free(format);
447
448   char error_buf[300] = {
449       0,
450   };
451   size_t errlen = 0;
452
453   int ret = asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf,
454                                   &errlen);
455
456   if (ret) {
457     LOG_I("Constraint validation of indication message failed: %s\n", error_buf);
458     exit(1);
459   }
460
461   uint8_t e2smbuffer[8192] = {
462       0,
463   };
464   size_t e2smbuffer_size = 8192;
465
466   asn_enc_rval_t er =
467       asn_encode_to_buffer(opt_cod, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_KPM_IndicationMessage,
468                            indicationmessage, e2smbuffer, e2smbuffer_size);
469
470   if (er.encoded == -1) {
471     LOG_E("Failed to serialize message. Detail: %s.\n", asn_DEF_E2SM_KPM_IndicationMessage.name);
472     exit(1);
473   } else if (er.encoded > e2smbuffer_size) {
474     LOG_E("Buffer of size %zu is too small for %s, need %zu\n", e2smbuffer_size, asn_DEF_E2SM_KPM_IndicationMessage.name, er.encoded);
475     exit(1);
476   }
477 }
478
479 void encode_kpm(E2SM_KPM_IndicationMessage_t* indicationmessage) {
480   /*
481   ASN_STRUCT_RESET(asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage);
482   //std::string gn = "GNBCUUP5";
483   //std::vector<uint8_t> gnvec(gn.begin(), gn.end());
484   //uint8_t *buf = &gnvec[0];
485   uint8_t *buf = (uint8_t*)"GNBCUUP5";
486   OCTET_STRING_t *gnbcuupname = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
487   gnbcuupname->size = 8;
488   gnbcuupname->buf = (uint8_t*)calloc(1,8);
489   memcpy(gnbcuupname->buf, buf, gnbcuupname->size);
490
491
492   INTEGER_t *bytesdl = (INTEGER_t*)calloc(1, sizeof(INTEGER_t));
493   uint8_t buffer[1];
494   buffer[0]= 40000;
495   bytesdl->buf = (uint8_t*)calloc(1,1);
496   memcpy(bytesdl->buf, buffer,1);
497   bytesdl->size = 1;
498
499   INTEGER_t *bytesul = (INTEGER_t*)calloc(1, sizeof(INTEGER_t));
500   uint8_t buffer1[1];
501   buffer1[0] = 50000;
502   bytesul->buf = (uint8_t*)calloc(1,1);
503   memcpy(bytesul->buf, buffer1, 1);
504   bytesul->size = 1;
505
506   FQIPERSlicesPerPlmnListItem_t *fqilistitem = (FQIPERSlicesPerPlmnListItem_t*)calloc(1,
507   sizeof(FQIPERSlicesPerPlmnListItem_t)); ASN_STRUCT_RESET(asn_DEF_FQIPERSlicesPerPlmnListItem,
508   fqilistitem); fqilistitem->fiveQI = 9; fqilistitem->pDCPBytesDL = bytesdl;
509   fqilistitem->pDCPBytesUL = bytesul;
510
511
512
513   //  std::string sl = "SLICE4";
514   //  std::vector<uint8_t> slvec(sl.begin(), sl.end());
515   //  uint8_t *buf1 = &slvec[0];
516   uint8_t *buf1 = (uint8_t*)"4";
517   OCTET_STRING_t *sst = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
518   sst->size = 6;
519   sst->buf = (uint8_t*)calloc(1,6);
520   memcpy(sst->buf,buf1,sst->size);
521
522   //  std::string sd = "SD1";
523   //  std::vector<uint8_t> sdvec(sd.begin(), sd.end());
524   //  uint8_t *bufz = &sdvec[0];
525   uint8_t *bufz = (uint8_t*)"SD1";
526   OCTET_STRING_t *sds = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
527   sds->size = 3;
528   sds->buf = (uint8_t*)calloc(1,3);
529   memcpy(sds->buf, bufz, sds->size);
530
531
532   SNSSAI_t *snssai = (SNSSAI_t*)calloc(1, sizeof(SNSSAI_t));
533   ASN_STRUCT_RESET(asn_DEF_SNSSAI,snssai);
534   snssai->sST.buf = (uint8_t*)calloc(1,1);
535   snssai->sST.size = 1;
536   memcpy(snssai->sST.buf, buf1, 1);
537   snssai->sD = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
538   snssai->sD->buf = (uint8_t*)calloc(1,3);
539   snssai->sD->size = 3;
540   memcpy(snssai->sD->buf, bufz, 3);
541
542
543
544   SliceToReportListItem_t *slicelistitem =
545   (SliceToReportListItem_t*)calloc(1,sizeof(SliceToReportListItem_t));
546   ASN_STRUCT_RESET(asn_DEF_SliceToReportListItem, slicelistitem);
547   slicelistitem->sliceID = *snssai;
548   int ret = ASN_SEQUENCE_ADD(&slicelistitem->fQIPERSlicesPerPlmnList.list, fqilistitem);
549
550   asn_codec_ctx_t *opt_cod;
551
552
553   uint8_t e2smbuffera[8192];
554   size_t e2smbuffer_sizea = 8192;
555
556
557
558   asn_enc_rval_t era =
559     asn_encode_to_buffer(opt_cod,
560        ATS_ALIGNED_BASIC_PER,
561        &asn_DEF_SliceToReportListItem,
562        slicelistitem, e2smbuffera, e2smbuffer_sizea);
563   fprintf(stderr, "inner er encded is %d\n", era.encoded);
564   fprintf(stderr, "after encoding message");
565
566
567
568   FGC_CUUP_PM_Format_t *pm_format = (FGC_CUUP_PM_Format_t*)calloc(1,sizeof(FGC_CUUP_PM_Format_t));
569   ASN_STRUCT_RESET(asn_DEF_FGC_CUUP_PM_Format, pm_format);
570   ret = ASN_SEQUENCE_ADD(&pm_format->sliceToReportList.list, slicelistitem);
571
572   uint8_t *buf2 = (uint8_t*)"747";
573   //  std::string pl = "PLMNID7";
574   //  std::vector<uint8_t> plvec(pl.begin(), pl.end());
575   //  uint8_t *buf2 = &plvec[0];
576
577   OCTET_STRING_t *plmnid = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
578   plmnid->buf = (uint8_t*)calloc(3,1);
579   plmnid->size = 3;
580   memcpy(plmnid->buf, buf2, plmnid->size);
581
582
583   PlmnID_List_t *plmnidlist = (PlmnID_List_t*)calloc(1,sizeof(PlmnID_List_t));
584   ASN_STRUCT_RESET(asn_DEF_PlmnID_List, plmnidlist);
585   plmnidlist->pLMN_Identity = *plmnid;
586   plmnidlist->cu_UP_PM_5GC = pm_format;
587
588   CUUPMeasurement_Container_t *meas_cont = (CUUPMeasurement_Container_t*)calloc(1,
589   sizeof(CUUPMeasurement_Container_t)); ASN_STRUCT_RESET(asn_DEF_CUUPMeasurement_Container,
590   meas_cont); ret = ASN_SEQUENCE_ADD(&meas_cont->plmnList.list, plmnidlist);
591
592
593
594
595   PF_ContainerListItem_t *listitem1 = (PF_ContainerListItem_t*)calloc(1,
596   sizeof(PF_ContainerListItem_t)); ASN_STRUCT_RESET(asn_DEF_PF_ContainerListItem, listitem1);
597   listitem1->interface_type = 2;
598   listitem1->o_CU_UP_PM_Container = *meas_cont;
599
600   OCUUP_PF_Container_t *cuupcont = (OCUUP_PF_Container_t*)calloc(1,sizeof(OCUUP_PF_Container_t));
601   ASN_STRUCT_RESET(asn_DEF_OCUUP_PF_Container, cuupcont);
602   cuupcont->gNB_CU_UP_Name = gnbcuupname;
603   ret = ASN_SEQUENCE_ADD(&cuupcont->pf_ContainerList.list, listitem1);
604
605   PF_Container_PR pres1 = PF_Container_PR_oCU_UP;
606
607   PF_Container_t *pfcontainer = (PF_Container_t*)calloc(1, sizeof(PF_Container_t));
608   ASN_STRUCT_RESET(asn_DEF_PF_Container, pfcontainer);
609   pfcontainer->present = pres1;
610   pfcontainer->choice.oCU_UP = *cuupcont;
611
612   PM_Containers_List_t *containers_list = (PM_Containers_List_t*)calloc(1,
613   sizeof(PM_Containers_List_t)); ASN_STRUCT_RESET(asn_DEF_PM_Containers_List, containers_list);
614   containers_list->performanceContainer = pfcontainer;
615
616   E2SM_KPM_IndicationMessage_Format1_t *format =
617     (E2SM_KPM_IndicationMessage_Format1_t*)calloc(1, sizeof(E2SM_KPM_IndicationMessage_Format1_t));
618   ASN_STRUCT_RESET(asn_DEF_E2SM_KPM_IndicationMessage_Format1, format);
619
620   ret = ASN_SEQUENCE_ADD(&format->pm_Containers.list, containers_list);
621
622   E2SM_KPM_IndicationMessage_PR pres = E2SM_KPM_IndicationMessage_PR_indicationMessage_Format1;
623
624   indicationmessage->present = pres;
625
626   indicationmessage->choice.indicationMessage_Format1 = *format;
627
628   char *error_buf = (char*)calloc(300, sizeof(char));
629   size_t errlen;
630
631   asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf, &errlen);
632   printf("error length %d\n", errlen);
633   printf("error buf %s\n", error_buf);
634
635   xer_fprint(stderr, &asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage);
636
637
638   uint8_t e2smbuffer[8192];
639   size_t e2smbuffer_size = 8192;
640
641   uint8_t e2smbuffer2[8192];
642   size_t e2smbuffer_size2 = 8192;
643
644   asn_enc_rval_t er =
645     asn_encode_to_buffer(opt_cod,
646        ATS_ALIGNED_BASIC_PER,
647        &asn_DEF_E2SM_KPM_IndicationMessage,
648        indicationmessage, e2smbuffer, e2smbuffer_size);
649
650   fprintf(stderr, "er encded is %d\n", er.encoded);
651   fprintf(stderr, "after encoding message");
652
653   */
654 }
655
656 /*
657 void encode_kpm_bak(E2SM_KPM_IndicationMessage_t* indicationmessage) {
658   ASN_STRUCT_RESET(asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage);
659   std::string gn = "GNBCUUP5";
660   std::vector<uint8_t> gnvec(gn.begin(), gn.end());
661   uint8_t *buf = &gnvec[0];
662   OCTET_STRING_t *gnbcuupname = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
663   gnbcuupname->size = 8;
664   gnbcuupname->buf = (uint8_t*)calloc(1,8);
665   memcpy(gnbcuupname->buf, buf, gnbcuupname->size);
666
667
668   INTEGER_t *bytesdl = (INTEGER_t*)calloc(1, sizeof(INTEGER_t));
669   uint8_t buffer[1];
670   buffer[0]= 40000;
671   bytesdl->buf = (uint8_t*)calloc(1,1);
672   memcpy(bytesdl->buf, buffer,1);
673   bytesdl->size = 1;
674
675   INTEGER_t *bytesul = (INTEGER_t*)calloc(1, sizeof(INTEGER_t));
676   uint8_t buffer1[1];
677   buffer1[0] = 50000;
678   bytesul->buf = (uint8_t*)calloc(1,1);
679   memcpy(bytesul->buf, buffer1, 1);
680   bytesul->size = 1;
681
682   FQIPERSlicesPerPlmnListItem_t *fqilistitem = (FQIPERSlicesPerPlmnListItem_t*)calloc(1,
683 sizeof(FQIPERSlicesPerPlmnListItem_t)); ASN_STRUCT_RESET(asn_DEF_FQIPERSlicesPerPlmnListItem,
684 fqilistitem); fqilistitem->fiveQI = 9; fqilistitem->pDCPBytesDL = bytesdl; fqilistitem->pDCPBytesUL
685 = bytesul;
686
687
688
689   std::string sl = "SLICE4";
690   std::vector<uint8_t> slvec(sl.begin(), sl.end());
691   //  uint8_t *buf1 = &slvec[0];
692   uint8_t *buf1 = (uint8_t*)"SLICE4";
693   OCTET_STRING_t *sst = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
694   sst->size = 6;
695   sst->buf = (uint8_t*)calloc(1,6);
696   memcpy(sst->buf,buf1,sst->size);
697
698   std::string sd = "SD1";
699   std::vector<uint8_t> sdvec(sd.begin(), sd.end());
700   //  uint8_t *bufz = &sdvec[0];
701   uint8_t *bufz = (uint8_t*)"SD1";
702   OCTET_STRING_t *sds = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
703   sds->size = 3;
704   sds->buf = (uint8_t*)calloc(1,3);
705   memcpy(sds->buf, bufz, sds->size);
706
707
708   SNSSAI_t *snssai = (SNSSAI_t*)calloc(1, sizeof(SNSSAI_t));
709   ASN_STRUCT_RESET(asn_DEF_SNSSAI,snssai);
710   snssai->sST.buf = (uint8_t*)calloc(6,1);
711   snssai->sST.size = 6;
712   memcpy(snssai->sST.buf, buf1, 6);
713   snssai->sD = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
714   snssai->sD->buf = (uint8_t*)calloc(1,3);
715   snssai->sD->size = 3;
716   memcpy(snssai->sD->buf, bufz, 3);
717
718
719
720   SliceToReportListItem_t *slicelistitem =
721 (SliceToReportListItem_t*)calloc(1,sizeof(SliceToReportListItem_t));
722   ASN_STRUCT_RESET(asn_DEF_SliceToReportListItem, slicelistitem);
723   slicelistitem->sliceID = *snssai;
724   int ret = ASN_SEQUENCE_ADD(&slicelistitem->fQIPERSlicesPerPlmnList.list, fqilistitem);
725
726   uint8_t e2smbuffera[8192];
727   size_t e2smbuffer_sizea = 8192;
728
729   auto era =
730     asn_encode_to_buffer(nullptr,
731        ATS_ALIGNED_BASIC_PER,
732        &asn_DEF_SliceToReportListItem,
733        slicelistitem, e2smbuffera, e2smbuffer_sizea);
734   fprintf(stderr, "inner er encded is %d\n", era.encoded);
735   fprintf(stderr, "after encoding message");
736
737   FGC_CUUP_PM_Format_t *pm_format = (FGC_CUUP_PM_Format_t*)calloc(1,sizeof(FGC_CUUP_PM_Format_t));
738   ASN_STRUCT_RESET(asn_DEF_FGC_CUUP_PM_Format, pm_format);
739   ret = ASN_SEQUENCE_ADD(&pm_format->sliceToReportList.list, slicelistitem);
740
741   std::string pl = "PLMNID7";
742   std::vector<uint8_t> plvec(pl.begin(), pl.end());
743   uint8_t *buf2 = &plvec[0];
744
745   OCTET_STRING_t *plmnid = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
746   plmnid->buf = (uint8_t*)calloc(1,7);
747   plmnid->size = 7;
748   memcpy(plmnid->buf, buf2, plmnid->size);
749
750
751   PlmnID_List_t *plmnidlist = (PlmnID_List_t*)calloc(1,sizeof(PlmnID_List_t));
752   ASN_STRUCT_RESET(asn_DEF_PlmnID_List, plmnidlist);
753   plmnidlist->pLMN_Identity = *plmnid;
754   plmnidlist->cu_UP_PM_5GC = pm_format;
755
756   CUUPMeasurement_Container_t *meas_cont = (CUUPMeasurement_Container_t*)calloc(1,
757 sizeof(CUUPMeasurement_Container_t)); ASN_STRUCT_RESET(asn_DEF_CUUPMeasurement_Container,
758 meas_cont); ret = ASN_SEQUENCE_ADD(&meas_cont->plmnList.list, plmnidlist);
759
760
761
762
763   PF_ContainerListItem_t *listitem1 = (PF_ContainerListItem_t*)calloc(1,
764 sizeof(PF_ContainerListItem_t)); ASN_STRUCT_RESET(asn_DEF_PF_ContainerListItem, listitem1);
765   listitem1->interface_type = 2;
766   listitem1->o_CU_UP_PM_Container = *meas_cont;
767
768   OCUUP_PF_Container_t *cuupcont = (OCUUP_PF_Container_t*)calloc(1,sizeof(OCUUP_PF_Container_t));
769   ASN_STRUCT_RESET(asn_DEF_OCUUP_PF_Container, cuupcont);
770   cuupcont->gNB_CU_UP_Name = gnbcuupname;
771   ret = ASN_SEQUENCE_ADD(&cuupcont->pf_ContainerList.list, listitem1);
772
773   PF_Container_PR pres1 = PF_Container_PR_oCU_UP;
774
775   PF_Container_t *pfcontainer = (PF_Container_t*)calloc(1, sizeof(PF_Container_t));
776   ASN_STRUCT_RESET(asn_DEF_PF_Container, pfcontainer);
777   pfcontainer->present = pres1;
778   pfcontainer->choice.oCU_UP = *cuupcont;
779
780   PM_Containers_List_t *containers_list = (PM_Containers_List_t*)calloc(1,
781 sizeof(PM_Containers_List_t)); ASN_STRUCT_RESET(asn_DEF_PM_Containers_List, containers_list);
782   containers_list->performanceContainer = pfcontainer;
783
784   E2SM_KPM_IndicationMessage_Format1_t *format =
785     (E2SM_KPM_IndicationMessage_Format1_t*)calloc(1, sizeof(E2SM_KPM_IndicationMessage_Format1_t));
786   ASN_STRUCT_RESET(asn_DEF_E2SM_KPM_IndicationMessage_Format1, format);
787
788   ret = ASN_SEQUENCE_ADD(&format->pm_Containers.list, containers_list);
789
790   E2SM_KPM_IndicationMessage_PR pres = E2SM_KPM_IndicationMessage_PR_indicationMessage_Format1;
791
792   indicationmessage->present = pres;
793
794   indicationmessage->choice.indicationMessage_Format1 = *format;
795
796   char *error_buf = (char*)calloc(300, sizeof(char));
797   size_t errlen;
798
799   asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf, &errlen);
800   printf("error length %d\n", errlen);
801   printf("error buf %s\n", error_buf);
802
803
804   uint8_t e2smbuffer[8192];
805   size_t e2smbuffer_size = 8192;
806
807   uint8_t e2smbuffer2[8192];
808   size_t e2smbuffer_size2 = 8192;
809
810   auto er =
811     asn_encode_to_buffer(nullptr,
812        ATS_ALIGNED_BASIC_PER,
813        &asn_DEF_E2SM_KPM_IndicationMessage,
814        indicationmessage, e2smbuffer, e2smbuffer_size);
815
816   fprintf(stderr, "er encded is %d\n", er.encoded);
817   fprintf(stderr, "after encoding message");
818
819
820 }
821 */