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