1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
3 * Copyright (c) 2022 Northeastern University
4 * Copyright (c) 2022 Sapienza, University of Rome
5 * Copyright (c) 2022 University of Padova
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation;
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * Author: Andrea Lacava <thecave003@gmail.com>
21 * Tommaso Zugno <tommasozugno@gmail.com>
22 * Michele Polese <michele.polese@gmail.com>
25 #include <ns3/kpm-function-description.h>
26 #include <ns3/asn1c-types.h>
30 #include "RIC-EventTriggerStyle-Item.h"
31 #include "RIC-ReportStyle-Item.h"
36 NS_LOG_COMPONENT_DEFINE ("KpmFunctionDescription");
38 KpmFunctionDescription::KpmFunctionDescription ()
40 E2SM_KPM_RANfunction_Description_t *descriptor = new E2SM_KPM_RANfunction_Description_t ();
41 FillAndEncodeKpmFunctionDescription (descriptor);
42 ASN_STRUCT_FREE_CONTENTS_ONLY (asn_DEF_E2SM_KPM_RANfunction_Description, descriptor);
46 KpmFunctionDescription::~KpmFunctionDescription ()
53 KpmFunctionDescription::Encode (E2SM_KPM_RANfunction_Description_t *descriptor)
55 asn_codec_ctx_t *opt_cod = 0; // disable stack bounds checking
56 // encode the structure into the e2smbuffer
57 asn_encode_to_new_buffer_result_s encodedMsg = asn_encode_to_new_buffer (
58 opt_cod, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_KPM_RANfunction_Description, descriptor);
60 if (encodedMsg.result.encoded < 0)
62 NS_FATAL_ERROR ("Error during the encoding of the RIC Indication Header, errno: "
63 << strerror (errno) << ", failed_type " << encodedMsg.result.failed_type->name
64 << ", structure_ptr " << encodedMsg.result.structure_ptr);
67 m_buffer = encodedMsg.buffer;
68 m_size = encodedMsg.result.encoded;
72 KpmFunctionDescription::FillAndEncodeKpmFunctionDescription (
73 E2SM_KPM_RANfunction_Description_t *ranfunc_desc)
75 std::string shortNameBuffer = "ORAN-WG3-KPM";
76 uint8_t *descriptionBuffer = (uint8_t *) "KPM monitor";
77 uint8_t *oidBuffer = (uint8_t *) "OID123"; // this is optional, dummy value
79 Ptr<OctetString> shortName = Create<OctetString> (shortNameBuffer, shortNameBuffer.size ());
81 ranfunc_desc->ranFunction_Name.ranFunction_ShortName = shortName->GetValue ();
83 long *inst = (long *) calloc (1, sizeof (long));
85 // ranfunc_desc->ranFunction_Name.ranFunction_Description = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
86 ranfunc_desc->ranFunction_Name.ranFunction_Description.buf =
87 (uint8_t *) calloc (1, strlen ((char *) descriptionBuffer));
88 memcpy (ranfunc_desc->ranFunction_Name.ranFunction_Description.buf, descriptionBuffer,
89 strlen ((char *) descriptionBuffer));
90 ranfunc_desc->ranFunction_Name.ranFunction_Description.size = strlen ((char *) descriptionBuffer);
91 ranfunc_desc->ranFunction_Name.ranFunction_Instance = inst;
93 // ranfunc_desc->ranFunction_Name.ranFunction_E2SM_OID = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
94 ranfunc_desc->ranFunction_Name.ranFunction_E2SM_OID.buf =
95 (uint8_t *) calloc (1, strlen ((char *) oidBuffer));
96 memcpy (ranfunc_desc->ranFunction_Name.ranFunction_E2SM_OID.buf, oidBuffer,
97 strlen ((char *) oidBuffer));
98 ranfunc_desc->ranFunction_Name.ranFunction_E2SM_OID.size = strlen ((char *) oidBuffer);
100 RIC_EventTriggerStyle_Item_t *trigger_style =
101 (RIC_EventTriggerStyle_Item_t *) calloc (1, sizeof (RIC_EventTriggerStyle_Item_t));
102 trigger_style->ric_EventTriggerStyle_Type = 1;
103 uint8_t *eventTriggerStyleNameBuffer = (uint8_t *) "Periodic report";
104 // trigger_style->ric_EventTriggerStyle_Name = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
105 trigger_style->ric_EventTriggerStyle_Name.buf =
106 (uint8_t *) calloc (1, strlen ((char *) eventTriggerStyleNameBuffer));
107 memcpy (trigger_style->ric_EventTriggerStyle_Name.buf, eventTriggerStyleNameBuffer,
108 strlen ((char *) eventTriggerStyleNameBuffer));
109 trigger_style->ric_EventTriggerStyle_Name.size = strlen ((char *) eventTriggerStyleNameBuffer);
110 trigger_style->ric_EventTriggerFormat_Type = 1;
112 ranfunc_desc->ric_EventTriggerStyle_List =
113 (E2SM_KPM_RANfunction_Description::
114 E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List *)
115 calloc (1, sizeof (E2SM_KPM_RANfunction_Description::
116 E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List));
118 ASN_SEQUENCE_ADD (&ranfunc_desc->ric_EventTriggerStyle_List->list, trigger_style);
120 RIC_ReportStyle_Item_t *report_style1 =
121 (RIC_ReportStyle_Item_t *) calloc (1, sizeof (RIC_ReportStyle_Item_t));
122 report_style1->ric_ReportStyle_Type = 1;
124 uint8_t *reportStyleNameBuffer =
125 (uint8_t *) "O-CU-CP Measurement Container for the EPC connected deployment";
127 // report_style1->ric_ReportStyle_Name = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
128 report_style1->ric_ReportStyle_Name.buf =
129 (uint8_t *) calloc (1, strlen ((char *) reportStyleNameBuffer));
130 memcpy (report_style1->ric_ReportStyle_Name.buf, reportStyleNameBuffer,
131 strlen ((char *) reportStyleNameBuffer));
132 report_style1->ric_ReportStyle_Name.size = strlen ((char *) reportStyleNameBuffer);
133 report_style1->ric_ReportIndicationHeaderFormat_Type = 1;
134 report_style1->ric_ReportIndicationMessageFormat_Type = 1;
135 ranfunc_desc->ric_ReportStyle_List =
136 (E2SM_KPM_RANfunction_Description::E2SM_KPM_RANfunction_Description__ric_ReportStyle_List *)
137 calloc (1, sizeof (E2SM_KPM_RANfunction_Description::
138 E2SM_KPM_RANfunction_Description__ric_ReportStyle_List));
140 ASN_SEQUENCE_ADD (&ranfunc_desc->ric_ReportStyle_List->list, report_style1);
142 Encode (ranfunc_desc);
144 NS_LOG_INFO (xer_fprint (stderr, &asn_DEF_E2SM_KPM_RANfunction_Description, ranfunc_desc));