First release
[sim/ns3-o-ran-e2.git] / model / asn1c-types.h
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2022 Northeastern University
4  * Copyright (c) 2022 Sapienza, University of Rome
5  * Copyright (c) 2022 University of Padova
6  *
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;
10  *
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.
15  *
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
19  *
20  * Author: Andrea Lacava <thecave003@gmail.com>
21  *                 Tommaso Zugno <tommasozugno@gmail.com>
22  *                 Michele Polese <michele.polese@gmail.com>
23  */
24
25 #ifndef ASN1C_TYPES_H
26 #define ASN1C_TYPES_H
27
28 #include "ns3/object.h"
29 #include <ns3/math.h>
30
31 extern "C" {
32   #include "OCTET_STRING.h"
33   #include "BIT_STRING.h"
34   #include "PM-Info-Item.h"
35   #include "SNSSAI.h"
36   #include "RRCEvent.h"
37   #include "L3-RRC-Measurements.h"
38   #include "ServingCellMeasurements.h"
39   #include "MeasResultNeighCells.h"
40   #include "MeasResultNR.h"
41   #include "MeasResultEUTRA.h"
42   #include "MeasResultPCell.h"
43   #include "MeasResultListEUTRA.h"
44   #include "MeasResultListNR.h"
45   #include "MeasResultServMO.h"
46   #include "MeasResultServMOList.h"
47   #include "MeasQuantityResults.h"
48   #include "ResultsPerSSB-Index.h"
49   #include "ResultsPerCSI-RS-Index.h"
50   #include "E2SM-RC-ControlMessage-Format1.h"
51   #include "RANParameter-Item.h"
52   #include "RANParameter-ValueType.h"
53   #include "RANParameter-ELEMENT.h"
54   #include "RANParameter-STRUCTURE.h"
55 }
56
57 namespace ns3 {
58
59 /**
60 * Wrapper for class for OCTET STRING  
61 */
62 class OctetString : public SimpleRefCount<OctetString>
63 {
64 public:
65   OctetString (std::string value, size_t size);
66   OctetString (void *value, size_t size);
67   ~OctetString ();
68   OCTET_STRING_t *GetPointer ();
69   OCTET_STRING_t GetValue ();
70   std::string DecodeContent ();
71
72 private:
73   void CreateBaseOctetString (size_t size);
74   OCTET_STRING_t *m_octetString;
75 };
76
77 /**
78 * Wrapper for class for BIT STRING  
79 */
80 class BitString : public SimpleRefCount<BitString>
81 {
82 public:
83   BitString (std::string value, size_t size);
84   BitString (std::string value, size_t size, size_t bits_unused);
85   ~BitString ();
86   BIT_STRING_t *GetPointer ();
87   BIT_STRING_t GetValue ();
88   // TODO maybe a to string or a decode method should be created
89
90 private:
91   BIT_STRING_t *m_bitString;
92 };
93
94 class NrCellId : public SimpleRefCount<NrCellId>
95 {
96 public: 
97   NrCellId (uint16_t value);
98   virtual ~NrCellId ();
99   BIT_STRING_t *GetPointer ();
100   BIT_STRING_t GetValue ();
101   
102 private: 
103   Ptr<BitString> m_bitString;
104 };
105
106 /**
107 * Wrapper for class for S-NSSAI  
108 */
109 class Snssai : public SimpleRefCount<Snssai>
110 {
111 public:
112   Snssai (std::string sst);
113   Snssai (std::string sst, std::string sd);
114   ~Snssai ();
115   SNSSAI_t *GetPointer ();
116   SNSSAI_t GetValue ();
117
118 private:
119   OCTET_STRING_t *m_sst;
120   OCTET_STRING_t *m_sd;
121   SNSSAI_t *m_sNssai;
122 };
123
124 /**
125 * Wrapper for class for MeasQuantityResults_t
126 */
127 class MeasQuantityResultsWrap : public SimpleRefCount<MeasQuantityResultsWrap>
128 {
129 public:
130   MeasQuantityResultsWrap ();
131   ~MeasQuantityResultsWrap ();
132   MeasQuantityResults_t *GetPointer ();
133   MeasQuantityResults_t GetValue ();
134   void AddRsrp (long rsrp);
135   void AddRsrq (long rsrq);
136   void AddSinr (long sinr);
137
138 private:
139   MeasQuantityResults_t *m_measQuantityResults;
140 };
141
142 /**
143 * Wrapper for class for ResultsPerCSI_RS_Index_t
144 */
145 class ResultsPerCsiRsIndex : public SimpleRefCount<ResultsPerCsiRsIndex>
146 {
147 public:
148   ResultsPerCsiRsIndex (long csiRsIndex, MeasQuantityResults_t *csiRsResults);
149   ResultsPerCsiRsIndex (long csiRsIndex);
150   ResultsPerCSI_RS_Index_t *GetPointer ();
151   ResultsPerCSI_RS_Index_t GetValue ();
152
153 private:
154   ResultsPerCSI_RS_Index_t *m_resultsPerCsiRsIndex;
155 };
156
157 /**
158 * Wrapper for class for ResultsPerSSB_Index_t
159 */
160 class ResultsPerSSBIndex : public SimpleRefCount<ResultsPerSSBIndex>
161 {
162 public:
163   ResultsPerSSBIndex (long ssbIndex, MeasQuantityResults_t *ssbResults);
164   ResultsPerSSBIndex (long ssbIndex);
165   ResultsPerSSB_Index_t *GetPointer ();
166   ResultsPerSSB_Index_t GetValue ();
167
168 private:
169   ResultsPerSSB_Index_t *m_resultsPerSSBIndex;
170 };
171
172 /**
173 * Wrapper for class for MeasResultNR_t
174 */
175 class MeasResultNr : public SimpleRefCount<MeasResultNr>
176 {
177 public:
178   enum ResultCell { SSB = 0, CSI_RS = 1 };
179   MeasResultNr (long physCellId);
180   MeasResultNr ();
181   ~MeasResultNr ();
182   MeasResultNR_t *GetPointer ();
183   MeasResultNR_t GetValue ();
184   void AddCellResults (ResultCell cell, MeasQuantityResults_t *results);
185   void AddPerSsbIndexResults (ResultsPerSSB_Index_t *resultsSsbIndex);
186   void AddPerCsiRsIndexResults (ResultsPerCSI_RS_Index_t *resultsCsiRsIndex);
187   void AddPhyCellId (long physCellId);
188
189 private:
190   MeasResultNR_t *m_measResultNr;
191   bool m_shouldFree;
192 };
193
194 /**
195 * Wrapper for class for MeasResultEUTRA_t
196 */
197 class MeasResultEutra : public SimpleRefCount<MeasResultEutra>
198 {
199 public:
200   MeasResultEutra (long eutraPhysCellId, long rsrp, long rsrq, long sinr);
201   MeasResultEutra (long eutraPhysCellId);
202   MeasResultEUTRA_t *GetPointer ();
203   MeasResultEUTRA_t GetValue ();
204   void AddRsrp (long rsrp);
205   void AddRsrq (long rsrq);
206   void AddSinr (long sinr);
207
208 private:
209   MeasResultEUTRA_t *m_measResultEutra;
210 };
211
212 /**
213 * Wrapper for class for MeasResultPCell_t
214 */
215 class MeasResultPCellWrap : public SimpleRefCount<MeasResultPCellWrap>
216 {
217 public:
218   MeasResultPCellWrap (long eutraPhysCellId, long rsrpResult, long rsrqResult);
219   MeasResultPCellWrap (long eutraPhysCellId);
220   MeasResultPCell_t *GetPointer ();
221   MeasResultPCell_t GetValue ();
222   void AddRsrpResult (long rsrpResult);
223   void AddRsrqResult (long rsrqResult);
224
225 private:
226   MeasResultPCell_t *m_measResultPCell;
227 };
228
229 /**
230 * Wrapper for class for MeasResultServMO_t
231 */
232 class MeasResultServMo : public SimpleRefCount<MeasResultServMo>
233 {
234 public:
235   MeasResultServMo (long servCellId, MeasResultNR_t measResultServingCell,
236                     MeasResultNR_t *measResultBestNeighCell);
237   MeasResultServMo (long servCellId, MeasResultNR_t measResultServingCell);
238   MeasResultServMO_t *GetPointer ();
239   MeasResultServMO_t GetValue ();
240
241 private:
242   MeasResultServMO_t *m_measResultServMo;
243 };
244
245 /**
246 * Wrapper for class for ServingCellMeasurements_t
247 */
248 class ServingCellMeasurementsWrap : public SimpleRefCount<ServingCellMeasurementsWrap>
249 {
250 public:
251   ServingCellMeasurementsWrap (ServingCellMeasurements_PR present);
252   ServingCellMeasurements_t *GetPointer ();
253   ServingCellMeasurements_t GetValue ();
254   void AddMeasResultPCell (MeasResultPCell_t *measResultPCell);
255   void AddMeasResultServMo (MeasResultServMO_t *measResultServMO);
256
257 private:
258   ServingCellMeasurements_t *m_servingCellMeasurements;
259   MeasResultServMOList_t *m_nr_measResultServingMOList;
260 };
261
262 /**
263 * Wrapper for class for L3 RRC Measurements
264 */
265 class L3RrcMeasurements : public SimpleRefCount<L3RrcMeasurements>
266 {
267 public:
268   int MAX_MEAS_RESULTS_ITEMS = 8; // Maximum 8 per UE (standard)
269   L3RrcMeasurements (RRCEvent_t rrcEvent);
270   L3RrcMeasurements (L3_RRC_Measurements_t *l3RrcMeasurements);
271   ~L3RrcMeasurements ();
272   L3_RRC_Measurements_t *GetPointer ();
273   L3_RRC_Measurements_t GetValue ();
274
275   void AddMeasResultEUTRANeighCells (MeasResultEUTRA_t *measResultItemEUTRA);
276   void AddMeasResultNRNeighCells (MeasResultNR_t *measResultItemNR);
277   void AddServingCellMeasurement (ServingCellMeasurements_t *servingCellMeasurements);
278   void AddNeighbourCellMeasurement (long neighCellId, long sinr);
279
280   static Ptr<L3RrcMeasurements> CreateL3RrcUeSpecificSinrServing (long servingCellId,
281                                                                   long physCellId, long sinr);
282
283   static Ptr<L3RrcMeasurements> CreateL3RrcUeSpecificSinrNeigh ();
284
285   // TODO change definition and return the values (to be used for decoding)
286   static void ExtractMeasurementsFromL3RrcMeas (L3_RRC_Measurements_t *l3RrcMeasurements);
287   
288   /**
289    * Returns the input SINR on a 0-127 scale
290    * 
291    * Refer to 3GPP TS 38.133 V17.2.0(2021-06), Table 10.1.16.1-1: SS-SINR and CSI-SINR measurement report mapping
292    * 
293    * @param sinr 
294    * @return double 
295    */
296   static double ThreeGppMapSinr (double sinr);
297
298 private:
299   void addMeasResultNeighCells (MeasResultNeighCells_PR present);
300   L3_RRC_Measurements_t *m_l3RrcMeasurements;
301   MeasResultListEUTRA_t *m_measResultListEUTRA;
302   MeasResultListNR_t *m_measResultListNR;
303   int m_measItemsCounter;
304 };
305
306 /**
307 * Wrapper for class for PM_Info_Item_t
308 */
309 class MeasurementItem : public SimpleRefCount<MeasurementItem>
310 {
311 public:
312   MeasurementItem (std::string name, long value);
313   MeasurementItem (std::string name, double value);
314   MeasurementItem (std::string name, Ptr<L3RrcMeasurements> value);
315   ~MeasurementItem ();
316   PM_Info_Item_t *GetPointer ();
317   PM_Info_Item_t GetValue ();
318
319 private:
320   MeasurementItem (std::string name);
321   void CreateMeasurementValue (MeasurementValue_PR measurementValue_PR);
322   // Main struct to be compiled
323   PM_Info_Item_t *m_measurementItem;
324
325   // Accessory structs that we must track to release memory after use
326   MeasurementTypeName_t *m_measName;
327   MeasurementValue_t *m_pmVal;
328   MeasurementType_t *m_pmType;
329 };
330
331 /**
332 * Wrapper for class for RANParameter_Item_t 
333 */
334 class RANParameterItem : public SimpleRefCount<RANParameterItem>
335 {
336 public:
337   enum ValueType{ Nothing = 0, Int = 1, OctectString = 2 };
338   RANParameterItem (RANParameter_Item_t *ranParameterItem);
339   ~RANParameterItem ();
340   RANParameter_Item_t *GetPointer ();
341   RANParameter_Item_t GetValue ();
342
343   ValueType m_valueType;
344   long m_valueInt;
345   Ptr<OctetString> m_valueStr;
346
347   static std::vector<RANParameterItem>
348   ExtractRANParametersFromRANParameter (RANParameter_Item_t *ranParameterItem);
349
350 private:
351   // Main struct
352   RANParameter_Item_t *m_ranParameterItem;
353   BOOLEAN_t *m_keyFlag;
354 };
355
356 } // namespace ns3
357 #endif /* ASN1C_TYPES_H */