SIM-116: Update list of performance metrics in E2 setup request for oransim
[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_Filter", 
32   "DRB.RlcSduTransmittedVolumeUL_Filter", 
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;
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   }
312
313   // xer_fprint(stderr, &asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage);
314 }
315
316 void cell_meas_kpm_report_indication_message_style_1_initialized(
317     E2SM_KPM_IndicationMessage_t* indicationmessage, long fiveqi, long dl_prb_usage,
318     long ul_prb_usage, uint8_t* nrcellid_buf, long* dl_prbs, long* ul_prbs) {
319   LOG_I("Preparing indication message for cell measurement report");
320
321   asn_codec_ctx_t* opt_cod;
322
323   GranularityPeriod_t period = 1;
324   MeasurementData_t* measData = (MeasurementData_t*)calloc(1, sizeof(MeasurementData_t));
325   MeasurementDataItem_t* measDataItem =
326       (MeasurementDataItem_t*)calloc(1, sizeof(MeasurementDataItem_t));
327   MeasurementRecord_t* measDataItem_record =
328       (MeasurementRecord_t*)calloc(1, sizeof(MeasurementRecord_t));
329   MeasurementRecordItem_t* measDataRecordItem =
330       (MeasurementRecordItem_t*)calloc(1, sizeof(MeasurementRecordItem_t));
331
332   measDataRecordItem->present = MeasurementRecordItem_PR_integer;
333   measDataRecordItem->choice.integer = 1;
334
335   ASN_SEQUENCE_ADD(&measDataItem_record->list, measDataRecordItem);
336
337   measDataItem->measRecord = *measDataItem_record;
338   measDataItem->incompleteFlag = (long*)calloc(1, sizeof(long));
339   *measDataItem->incompleteFlag = 0;
340   ASN_SEQUENCE_ADD(&measData->list, measDataItem);
341
342   E2SM_KPM_IndicationMessage_Format1_t* format = (E2SM_KPM_IndicationMessage_Format1_t*)calloc(
343       1, sizeof(E2SM_KPM_IndicationMessage_Format1_t));
344   format->granulPeriod = (GranularityPeriod_t*)calloc(1, sizeof(GranularityPeriod_t));
345   *format->granulPeriod = period;
346   format->measData = *measData;
347
348   MeasurementInfoList_t* measList =
349       (MeasurementInfoList_t*)calloc(1, sizeof(MeasurementInfoList_t));
350   MeasurementInfoItem_t* measItem =
351       (MeasurementInfoItem_t*)calloc(1, sizeof(MeasurementInfoItem_t));
352   LabelInfoList_t* labelList = (LabelInfoList_t*)calloc(1, sizeof(LabelInfoList_t));
353   LabelInfoItem_t* labelItem = (LabelInfoItem_t*)calloc(1, sizeof(LabelInfoItem_t));
354   MeasurementLabel_t* measLabel = (MeasurementLabel_t*)calloc(1, sizeof(MeasurementLabel_t));
355
356   uint8_t* plmnid_buf = (uint8_t*)"747";
357   uint8_t* sst_buf = (uint8_t*)"1";
358   uint8_t* sd_buf = (uint8_t*)"100";
359
360   S_NSSAI_t* snssai = (S_NSSAI_t*)calloc(1, sizeof(S_NSSAI_t));
361   snssai->sST.buf = (uint8_t*)calloc(strlen((char*)sst_buf), sizeof(uint8_t));
362   snssai->sST.size = strlen((char*)sst_buf);
363   memcpy(snssai->sST.buf, sst_buf, strlen((char*)sst_buf));
364
365   snssai->sD = (SD_t*)calloc(1, sizeof(SD_t));
366   snssai->sD->buf = (uint8_t*)calloc(strlen((char*)sd_buf), sizeof(uint8_t));
367   snssai->sD->size = strlen((char*)sd_buf);
368   memcpy(snssai->sD->buf, sd_buf, strlen((char*)sd_buf));
369
370   int plmnid_size = strlen((char*)plmnid_buf);
371   PLMNIdentity_t* plmnidstr = (PLMNIdentity_t*)calloc(1, sizeof(PLMNIdentity_t));
372   plmnidstr->buf = (uint8_t*)calloc(plmnid_size, 1);
373   plmnidstr->size = plmnid_size;
374   memcpy(plmnidstr->buf, plmnid_buf, plmnidstr->size);
375
376   measLabel->plmnID = plmnidstr;
377   measLabel->sliceID = snssai;
378
379   labelItem->measLabel = *measLabel;
380   ASN_SEQUENCE_ADD(&labelList->list, labelItem);
381   measItem->labelInfoList = *labelList;
382   if (labelList) free(labelList);
383   MeasurementType_t measType;
384   measType.present = MeasurementType_PR_measID;
385   measType.choice.measID = 1;
386   measItem->measType = measType;
387   ASN_SEQUENCE_ADD(&measList->list, measItem);
388
389   format->measInfoList = measList;
390
391   E2SM_KPM_IndicationMessage__indicationMessage_formats_PR pres =
392       E2SM_KPM_IndicationMessage__indicationMessage_formats_PR_indicationMessage_Format1;
393
394   indicationmessage->indicationMessage_formats.present = pres;
395   indicationmessage->indicationMessage_formats.choice.indicationMessage_Format1 = format;
396
397   char error_buf[300] = {
398       0,
399   };
400   size_t errlen = 0;
401
402   int ret = asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf,
403                                   &errlen);
404
405   if (ret) {
406     LOG_I("Constraint validation of indication message failed: %s\n", error_buf);
407   }
408 }
409
410 void encode_kpm_report_style1(E2SM_KPM_IndicationMessage_t* indicationmessage) {
411   long fiveqi = 8;
412   long dl_prb_usage = 50;
413   long ul_prb_usage = 70;
414
415   asn_codec_ctx_t* opt_cod;
416
417   GranularityPeriod_t period = 1;
418   MeasurementData_t measData;
419   MeasurementDataItem_t measDataItem;
420   MeasurementRecord_t measDataItem_record;
421   MeasurementRecordItem_t measDataRecordItem;
422
423   measDataRecordItem.present = MeasurementRecordItem_PR_real;
424   measDataRecordItem.choice.real = 1.5;
425
426   ASN_SEQUENCE_ADD(&measDataItem_record.list, &measDataRecordItem);
427
428   measDataItem.measRecord = measDataItem_record;
429   ASN_SEQUENCE_ADD(&measData.list, &measDataItem);
430
431   E2SM_KPM_IndicationMessage_Format1_t* format = (E2SM_KPM_IndicationMessage_Format1_t*)calloc(
432       1, sizeof(E2SM_KPM_IndicationMessage_Format1_t));
433   ASN_STRUCT_RESET(asn_DEF_E2SM_KPM_IndicationMessage_Format1, format);
434
435   format->granulPeriod = &period;
436   format->measData = measData;
437
438   E2SM_KPM_IndicationMessage__indicationMessage_formats_PR pres =
439       E2SM_KPM_IndicationMessage__indicationMessage_formats_PR_indicationMessage_Format1;
440
441   indicationmessage->indicationMessage_formats.present = pres;
442
443   indicationmessage->indicationMessage_formats.choice.indicationMessage_Format1 = format;
444   if (format) free(format);
445
446   char error_buf[300] = {
447       0,
448   };
449   size_t errlen = 0;
450
451   int ret = asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf,
452                                   &errlen);
453
454   if (ret) {
455     LOG_I("Constraint validation of indication message failed: %s\n", error_buf);
456   }
457
458   uint8_t e2smbuffer[8192] = {
459       0,
460   };
461   size_t e2smbuffer_size = 8192;
462
463   asn_enc_rval_t er =
464       asn_encode_to_buffer(opt_cod, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_KPM_IndicationMessage,
465                            indicationmessage, e2smbuffer, e2smbuffer_size);
466
467   if (er.encoded == -1) {
468     LOG_E("Failed to serialize message. Detail: %s.\n", asn_DEF_E2SM_KPM_IndicationMessage.name);
469     exit(1);
470   } else if (er.encoded > e2smbuffer_size) {
471     LOG_E("Buffer of size %zu is too small for %s, need %zu\n", e2smbuffer_size, asn_DEF_E2SM_KPM_IndicationMessage.name, er.encoded);
472     exit(1);
473   }
474 }
475
476 void encode_kpm(E2SM_KPM_IndicationMessage_t* indicationmessage) {
477   /*
478   ASN_STRUCT_RESET(asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage);
479   //std::string gn = "GNBCUUP5";
480   //std::vector<uint8_t> gnvec(gn.begin(), gn.end());
481   //uint8_t *buf = &gnvec[0];
482   uint8_t *buf = (uint8_t*)"GNBCUUP5";
483   OCTET_STRING_t *gnbcuupname = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
484   gnbcuupname->size = 8;
485   gnbcuupname->buf = (uint8_t*)calloc(1,8);
486   memcpy(gnbcuupname->buf, buf, gnbcuupname->size);
487
488
489   INTEGER_t *bytesdl = (INTEGER_t*)calloc(1, sizeof(INTEGER_t));
490   uint8_t buffer[1];
491   buffer[0]= 40000;
492   bytesdl->buf = (uint8_t*)calloc(1,1);
493   memcpy(bytesdl->buf, buffer,1);
494   bytesdl->size = 1;
495
496   INTEGER_t *bytesul = (INTEGER_t*)calloc(1, sizeof(INTEGER_t));
497   uint8_t buffer1[1];
498   buffer1[0] = 50000;
499   bytesul->buf = (uint8_t*)calloc(1,1);
500   memcpy(bytesul->buf, buffer1, 1);
501   bytesul->size = 1;
502
503   FQIPERSlicesPerPlmnListItem_t *fqilistitem = (FQIPERSlicesPerPlmnListItem_t*)calloc(1,
504   sizeof(FQIPERSlicesPerPlmnListItem_t)); ASN_STRUCT_RESET(asn_DEF_FQIPERSlicesPerPlmnListItem,
505   fqilistitem); fqilistitem->fiveQI = 9; fqilistitem->pDCPBytesDL = bytesdl;
506   fqilistitem->pDCPBytesUL = bytesul;
507
508
509
510   //  std::string sl = "SLICE4";
511   //  std::vector<uint8_t> slvec(sl.begin(), sl.end());
512   //  uint8_t *buf1 = &slvec[0];
513   uint8_t *buf1 = (uint8_t*)"4";
514   OCTET_STRING_t *sst = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
515   sst->size = 6;
516   sst->buf = (uint8_t*)calloc(1,6);
517   memcpy(sst->buf,buf1,sst->size);
518
519   //  std::string sd = "SD1";
520   //  std::vector<uint8_t> sdvec(sd.begin(), sd.end());
521   //  uint8_t *bufz = &sdvec[0];
522   uint8_t *bufz = (uint8_t*)"SD1";
523   OCTET_STRING_t *sds = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
524   sds->size = 3;
525   sds->buf = (uint8_t*)calloc(1,3);
526   memcpy(sds->buf, bufz, sds->size);
527
528
529   SNSSAI_t *snssai = (SNSSAI_t*)calloc(1, sizeof(SNSSAI_t));
530   ASN_STRUCT_RESET(asn_DEF_SNSSAI,snssai);
531   snssai->sST.buf = (uint8_t*)calloc(1,1);
532   snssai->sST.size = 1;
533   memcpy(snssai->sST.buf, buf1, 1);
534   snssai->sD = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
535   snssai->sD->buf = (uint8_t*)calloc(1,3);
536   snssai->sD->size = 3;
537   memcpy(snssai->sD->buf, bufz, 3);
538
539
540
541   SliceToReportListItem_t *slicelistitem =
542   (SliceToReportListItem_t*)calloc(1,sizeof(SliceToReportListItem_t));
543   ASN_STRUCT_RESET(asn_DEF_SliceToReportListItem, slicelistitem);
544   slicelistitem->sliceID = *snssai;
545   int ret = ASN_SEQUENCE_ADD(&slicelistitem->fQIPERSlicesPerPlmnList.list, fqilistitem);
546
547   asn_codec_ctx_t *opt_cod;
548
549
550   uint8_t e2smbuffera[8192];
551   size_t e2smbuffer_sizea = 8192;
552
553
554
555   asn_enc_rval_t era =
556     asn_encode_to_buffer(opt_cod,
557        ATS_ALIGNED_BASIC_PER,
558        &asn_DEF_SliceToReportListItem,
559        slicelistitem, e2smbuffera, e2smbuffer_sizea);
560   fprintf(stderr, "inner er encded is %d\n", era.encoded);
561   fprintf(stderr, "after encoding message");
562
563
564
565   FGC_CUUP_PM_Format_t *pm_format = (FGC_CUUP_PM_Format_t*)calloc(1,sizeof(FGC_CUUP_PM_Format_t));
566   ASN_STRUCT_RESET(asn_DEF_FGC_CUUP_PM_Format, pm_format);
567   ret = ASN_SEQUENCE_ADD(&pm_format->sliceToReportList.list, slicelistitem);
568
569   uint8_t *buf2 = (uint8_t*)"747";
570   //  std::string pl = "PLMNID7";
571   //  std::vector<uint8_t> plvec(pl.begin(), pl.end());
572   //  uint8_t *buf2 = &plvec[0];
573
574   OCTET_STRING_t *plmnid = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
575   plmnid->buf = (uint8_t*)calloc(3,1);
576   plmnid->size = 3;
577   memcpy(plmnid->buf, buf2, plmnid->size);
578
579
580   PlmnID_List_t *plmnidlist = (PlmnID_List_t*)calloc(1,sizeof(PlmnID_List_t));
581   ASN_STRUCT_RESET(asn_DEF_PlmnID_List, plmnidlist);
582   plmnidlist->pLMN_Identity = *plmnid;
583   plmnidlist->cu_UP_PM_5GC = pm_format;
584
585   CUUPMeasurement_Container_t *meas_cont = (CUUPMeasurement_Container_t*)calloc(1,
586   sizeof(CUUPMeasurement_Container_t)); ASN_STRUCT_RESET(asn_DEF_CUUPMeasurement_Container,
587   meas_cont); ret = ASN_SEQUENCE_ADD(&meas_cont->plmnList.list, plmnidlist);
588
589
590
591
592   PF_ContainerListItem_t *listitem1 = (PF_ContainerListItem_t*)calloc(1,
593   sizeof(PF_ContainerListItem_t)); ASN_STRUCT_RESET(asn_DEF_PF_ContainerListItem, listitem1);
594   listitem1->interface_type = 2;
595   listitem1->o_CU_UP_PM_Container = *meas_cont;
596
597   OCUUP_PF_Container_t *cuupcont = (OCUUP_PF_Container_t*)calloc(1,sizeof(OCUUP_PF_Container_t));
598   ASN_STRUCT_RESET(asn_DEF_OCUUP_PF_Container, cuupcont);
599   cuupcont->gNB_CU_UP_Name = gnbcuupname;
600   ret = ASN_SEQUENCE_ADD(&cuupcont->pf_ContainerList.list, listitem1);
601
602   PF_Container_PR pres1 = PF_Container_PR_oCU_UP;
603
604   PF_Container_t *pfcontainer = (PF_Container_t*)calloc(1, sizeof(PF_Container_t));
605   ASN_STRUCT_RESET(asn_DEF_PF_Container, pfcontainer);
606   pfcontainer->present = pres1;
607   pfcontainer->choice.oCU_UP = *cuupcont;
608
609   PM_Containers_List_t *containers_list = (PM_Containers_List_t*)calloc(1,
610   sizeof(PM_Containers_List_t)); ASN_STRUCT_RESET(asn_DEF_PM_Containers_List, containers_list);
611   containers_list->performanceContainer = pfcontainer;
612
613   E2SM_KPM_IndicationMessage_Format1_t *format =
614     (E2SM_KPM_IndicationMessage_Format1_t*)calloc(1, sizeof(E2SM_KPM_IndicationMessage_Format1_t));
615   ASN_STRUCT_RESET(asn_DEF_E2SM_KPM_IndicationMessage_Format1, format);
616
617   ret = ASN_SEQUENCE_ADD(&format->pm_Containers.list, containers_list);
618
619   E2SM_KPM_IndicationMessage_PR pres = E2SM_KPM_IndicationMessage_PR_indicationMessage_Format1;
620
621   indicationmessage->present = pres;
622
623   indicationmessage->choice.indicationMessage_Format1 = *format;
624
625   char *error_buf = (char*)calloc(300, sizeof(char));
626   size_t errlen;
627
628   asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf, &errlen);
629   printf("error length %d\n", errlen);
630   printf("error buf %s\n", error_buf);
631
632   xer_fprint(stderr, &asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage);
633
634
635   uint8_t e2smbuffer[8192];
636   size_t e2smbuffer_size = 8192;
637
638   uint8_t e2smbuffer2[8192];
639   size_t e2smbuffer_size2 = 8192;
640
641   asn_enc_rval_t er =
642     asn_encode_to_buffer(opt_cod,
643        ATS_ALIGNED_BASIC_PER,
644        &asn_DEF_E2SM_KPM_IndicationMessage,
645        indicationmessage, e2smbuffer, e2smbuffer_size);
646
647   fprintf(stderr, "er encded is %d\n", er.encoded);
648   fprintf(stderr, "after encoding message");
649
650   */
651 }
652
653 /*
654 void encode_kpm_bak(E2SM_KPM_IndicationMessage_t* indicationmessage) {
655   ASN_STRUCT_RESET(asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage);
656   std::string gn = "GNBCUUP5";
657   std::vector<uint8_t> gnvec(gn.begin(), gn.end());
658   uint8_t *buf = &gnvec[0];
659   OCTET_STRING_t *gnbcuupname = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
660   gnbcuupname->size = 8;
661   gnbcuupname->buf = (uint8_t*)calloc(1,8);
662   memcpy(gnbcuupname->buf, buf, gnbcuupname->size);
663
664
665   INTEGER_t *bytesdl = (INTEGER_t*)calloc(1, sizeof(INTEGER_t));
666   uint8_t buffer[1];
667   buffer[0]= 40000;
668   bytesdl->buf = (uint8_t*)calloc(1,1);
669   memcpy(bytesdl->buf, buffer,1);
670   bytesdl->size = 1;
671
672   INTEGER_t *bytesul = (INTEGER_t*)calloc(1, sizeof(INTEGER_t));
673   uint8_t buffer1[1];
674   buffer1[0] = 50000;
675   bytesul->buf = (uint8_t*)calloc(1,1);
676   memcpy(bytesul->buf, buffer1, 1);
677   bytesul->size = 1;
678
679   FQIPERSlicesPerPlmnListItem_t *fqilistitem = (FQIPERSlicesPerPlmnListItem_t*)calloc(1,
680 sizeof(FQIPERSlicesPerPlmnListItem_t)); ASN_STRUCT_RESET(asn_DEF_FQIPERSlicesPerPlmnListItem,
681 fqilistitem); fqilistitem->fiveQI = 9; fqilistitem->pDCPBytesDL = bytesdl; fqilistitem->pDCPBytesUL
682 = bytesul;
683
684
685
686   std::string sl = "SLICE4";
687   std::vector<uint8_t> slvec(sl.begin(), sl.end());
688   //  uint8_t *buf1 = &slvec[0];
689   uint8_t *buf1 = (uint8_t*)"SLICE4";
690   OCTET_STRING_t *sst = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
691   sst->size = 6;
692   sst->buf = (uint8_t*)calloc(1,6);
693   memcpy(sst->buf,buf1,sst->size);
694
695   std::string sd = "SD1";
696   std::vector<uint8_t> sdvec(sd.begin(), sd.end());
697   //  uint8_t *bufz = &sdvec[0];
698   uint8_t *bufz = (uint8_t*)"SD1";
699   OCTET_STRING_t *sds = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
700   sds->size = 3;
701   sds->buf = (uint8_t*)calloc(1,3);
702   memcpy(sds->buf, bufz, sds->size);
703
704
705   SNSSAI_t *snssai = (SNSSAI_t*)calloc(1, sizeof(SNSSAI_t));
706   ASN_STRUCT_RESET(asn_DEF_SNSSAI,snssai);
707   snssai->sST.buf = (uint8_t*)calloc(6,1);
708   snssai->sST.size = 6;
709   memcpy(snssai->sST.buf, buf1, 6);
710   snssai->sD = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
711   snssai->sD->buf = (uint8_t*)calloc(1,3);
712   snssai->sD->size = 3;
713   memcpy(snssai->sD->buf, bufz, 3);
714
715
716
717   SliceToReportListItem_t *slicelistitem =
718 (SliceToReportListItem_t*)calloc(1,sizeof(SliceToReportListItem_t));
719   ASN_STRUCT_RESET(asn_DEF_SliceToReportListItem, slicelistitem);
720   slicelistitem->sliceID = *snssai;
721   int ret = ASN_SEQUENCE_ADD(&slicelistitem->fQIPERSlicesPerPlmnList.list, fqilistitem);
722
723   uint8_t e2smbuffera[8192];
724   size_t e2smbuffer_sizea = 8192;
725
726   auto era =
727     asn_encode_to_buffer(nullptr,
728        ATS_ALIGNED_BASIC_PER,
729        &asn_DEF_SliceToReportListItem,
730        slicelistitem, e2smbuffera, e2smbuffer_sizea);
731   fprintf(stderr, "inner er encded is %d\n", era.encoded);
732   fprintf(stderr, "after encoding message");
733
734   FGC_CUUP_PM_Format_t *pm_format = (FGC_CUUP_PM_Format_t*)calloc(1,sizeof(FGC_CUUP_PM_Format_t));
735   ASN_STRUCT_RESET(asn_DEF_FGC_CUUP_PM_Format, pm_format);
736   ret = ASN_SEQUENCE_ADD(&pm_format->sliceToReportList.list, slicelistitem);
737
738   std::string pl = "PLMNID7";
739   std::vector<uint8_t> plvec(pl.begin(), pl.end());
740   uint8_t *buf2 = &plvec[0];
741
742   OCTET_STRING_t *plmnid = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
743   plmnid->buf = (uint8_t*)calloc(1,7);
744   plmnid->size = 7;
745   memcpy(plmnid->buf, buf2, plmnid->size);
746
747
748   PlmnID_List_t *plmnidlist = (PlmnID_List_t*)calloc(1,sizeof(PlmnID_List_t));
749   ASN_STRUCT_RESET(asn_DEF_PlmnID_List, plmnidlist);
750   plmnidlist->pLMN_Identity = *plmnid;
751   plmnidlist->cu_UP_PM_5GC = pm_format;
752
753   CUUPMeasurement_Container_t *meas_cont = (CUUPMeasurement_Container_t*)calloc(1,
754 sizeof(CUUPMeasurement_Container_t)); ASN_STRUCT_RESET(asn_DEF_CUUPMeasurement_Container,
755 meas_cont); ret = ASN_SEQUENCE_ADD(&meas_cont->plmnList.list, plmnidlist);
756
757
758
759
760   PF_ContainerListItem_t *listitem1 = (PF_ContainerListItem_t*)calloc(1,
761 sizeof(PF_ContainerListItem_t)); ASN_STRUCT_RESET(asn_DEF_PF_ContainerListItem, listitem1);
762   listitem1->interface_type = 2;
763   listitem1->o_CU_UP_PM_Container = *meas_cont;
764
765   OCUUP_PF_Container_t *cuupcont = (OCUUP_PF_Container_t*)calloc(1,sizeof(OCUUP_PF_Container_t));
766   ASN_STRUCT_RESET(asn_DEF_OCUUP_PF_Container, cuupcont);
767   cuupcont->gNB_CU_UP_Name = gnbcuupname;
768   ret = ASN_SEQUENCE_ADD(&cuupcont->pf_ContainerList.list, listitem1);
769
770   PF_Container_PR pres1 = PF_Container_PR_oCU_UP;
771
772   PF_Container_t *pfcontainer = (PF_Container_t*)calloc(1, sizeof(PF_Container_t));
773   ASN_STRUCT_RESET(asn_DEF_PF_Container, pfcontainer);
774   pfcontainer->present = pres1;
775   pfcontainer->choice.oCU_UP = *cuupcont;
776
777   PM_Containers_List_t *containers_list = (PM_Containers_List_t*)calloc(1,
778 sizeof(PM_Containers_List_t)); ASN_STRUCT_RESET(asn_DEF_PM_Containers_List, containers_list);
779   containers_list->performanceContainer = pfcontainer;
780
781   E2SM_KPM_IndicationMessage_Format1_t *format =
782     (E2SM_KPM_IndicationMessage_Format1_t*)calloc(1, sizeof(E2SM_KPM_IndicationMessage_Format1_t));
783   ASN_STRUCT_RESET(asn_DEF_E2SM_KPM_IndicationMessage_Format1, format);
784
785   ret = ASN_SEQUENCE_ADD(&format->pm_Containers.list, containers_list);
786
787   E2SM_KPM_IndicationMessage_PR pres = E2SM_KPM_IndicationMessage_PR_indicationMessage_Format1;
788
789   indicationmessage->present = pres;
790
791   indicationmessage->choice.indicationMessage_Format1 = *format;
792
793   char *error_buf = (char*)calloc(300, sizeof(char));
794   size_t errlen;
795
796   asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf, &errlen);
797   printf("error length %d\n", errlen);
798   printf("error buf %s\n", error_buf);
799
800
801   uint8_t e2smbuffer[8192];
802   size_t e2smbuffer_size = 8192;
803
804   uint8_t e2smbuffer2[8192];
805   size_t e2smbuffer_size2 = 8192;
806
807   auto er =
808     asn_encode_to_buffer(nullptr,
809        ATS_ALIGNED_BASIC_PER,
810        &asn_DEF_E2SM_KPM_IndicationMessage,
811        indicationmessage, e2smbuffer, e2smbuffer_size);
812
813   fprintf(stderr, "er encded is %d\n", er.encoded);
814   fprintf(stderr, "after encoding message");
815
816
817 }
818 */