First release
[sim/ns3-o-ran-e2.git] / model / kpm-indication.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 KPM_INDICATION_H
26 #define KPM_INDICATION_H
27
28 #include "ns3/object.h"
29 #include <set>
30
31 extern "C" {
32   #include "E2SM-KPM-RANfunction-Description.h"
33   #include "E2SM-KPM-IndicationHeader.h"
34   #include "E2SM-KPM-IndicationMessage.h"
35   #include "RAN-Container.h"
36   #include "PF-Container.h"
37   #include "OCUUP-PF-Container.h"
38   #include "OCUCP-PF-Container.h"
39   #include "ODU-PF-Container.h"
40   #include "PF-ContainerListItem.h"
41   #include "asn1c-types.h"
42 }
43
44 namespace ns3 {
45
46   class KpmIndicationHeader : public SimpleRefCount<KpmIndicationHeader>
47   {
48   public:
49     enum GlobalE2nodeType { gNB = 0, eNB = 1, ng_eNB = 2, en_gNB = 3 };
50
51     const static int TIMESTAMP_LIMIT_SIZE = 8;
52     /**
53     * Holds the values to be used to fill the RIC Indication header 
54     */
55     struct KpmRicIndicationHeaderValues
56     {
57       // E2SM-KPM Indication Header Format 1
58       // KPM Node ID IE
59       std::string m_gnbId; //!< gNB ID bit string 
60       // TODO not supported
61       // uint64_t m_cuUpId; //!< gNB-CU-UP ID, integer [0, 2^36-1], optional
62       
63       // Cell Global ID (NR CGI) IE
64       uint16_t m_nrCellId; //!< NR, bit string
65       
66       // PLMN ID IE
67       std::string m_plmId; //!< PLMN identity, octet string, 3 bytes
68       
69       // Slice ID (S-NSSAI) IE // TODO not supported
70       // std::string m_sst; //!< SNSSAI sST, 1 byte
71       // std::string m_sd; //!< SNSSAI sD, 3 bytes, optional
72       
73       // FiveQI IE // TODO not supported
74       // uint8_t m_fiveqi; //!< fiveQI, integer [0, 255], optional
75       
76       // QCI IE // TODO not supported
77       // long m_qci; //!< QCI, integer [0, 255], optional
78       
79       // TODO this value is placed in a fiels which seems not to be defined 
80       // in the specs. See line 301 in encode_kpm.cpp
81       // the field is called gNB_DU_ID
82       // it should be part of KPM Node ID IE
83       // m_duId
84     
85       // TODO this value is placed in a fiels which seems not to be defined 
86       // in the specs. See line 290 in encode_kpm.cpp, the field is called
87       // gNB_Name
88       // m_cuUpName
89       
90       // CollectionTimeStamp
91       uint64_t m_timestamp;
92     };
93     
94     KpmIndicationHeader (GlobalE2nodeType nodeType,KpmRicIndicationHeaderValues values);
95     ~KpmIndicationHeader ();
96     void* m_buffer;
97     size_t m_size;
98     
99   private: 
100     /**
101     * Fills the KPM INDICATION Header descriptor
102     * This function fills the RIC Indication Header with the provided 
103     * values
104     *
105     * \param descriptor object representing the KPM INDICATION Header
106     * \param values struct holding the values to be used to fill the header 
107     */
108     void FillAndEncodeKpmRicIndicationHeader (E2SM_KPM_IndicationHeader_t* descriptor, 
109                                               KpmRicIndicationHeaderValues values);
110     
111     void Encode (E2SM_KPM_IndicationHeader_t* descriptor);
112
113     GlobalE2nodeType m_nodeType;
114     };
115
116   class MeasurementItemList : public SimpleRefCount<MeasurementItemList>
117   {
118   private:
119     Ptr<OctetString> m_id; // ID, contains the UE IMSI if used to carry UE-specific measurement items
120     std::vector<Ptr<MeasurementItem>> m_items; //!< list of Measurement Information Items
121   public:
122     MeasurementItemList ();
123     MeasurementItemList (std::string ueId);
124      ~MeasurementItemList ();
125
126     // NOTE defined here to avoid undefined references
127     template<class T> 
128     void AddItem (std::string name, T value)
129     {
130       Ptr<MeasurementItem> item = Create<MeasurementItem> (name, value);
131       m_items.push_back (item);
132     }
133     
134     std::vector<Ptr<MeasurementItem>> GetItems();
135     OCTET_STRING_t GetId ();
136   };
137
138   /**
139   * Base class to carry PM Container values  
140   */    
141   class PmContainerValues : public SimpleRefCount<PmContainerValues> 
142   {
143   public:
144     virtual ~PmContainerValues () = default;
145   };
146
147   /**
148   * Contains the values to be inserted in the O-CU-CP Measurement Container  
149   */
150   class OCuCpContainerValues : public PmContainerValues
151   {
152   public:
153     uint16_t m_numActiveUes; //!< mean number of RRC connections
154   };
155   
156   /**
157   * Contains the values to be inserted in the O-CU-UP Measurement Container  
158   */
159   class OCuUpContainerValues : public PmContainerValues
160   {
161   public:
162     std::string m_plmId; //!< PLMN identity, octet string, 3 bytes
163     long m_pDCPBytesUL; //!< total PDCP bytes transmitted UL
164     long m_pDCPBytesDL; //!< total PDCP bytes transmitted DL
165   };
166
167   /**
168   * Contains the values to be inserted in the O-DU EPC Measurement Container  
169   */
170   class EpcDuPmContainer : public SimpleRefCount<EpcDuPmContainer>
171   {
172   public:
173     long m_qci; //!< QCI value
174     long m_dlPrbUsage; //!< Used number of PRBs in an average of DL for the monitored slice during E2 reporting period
175     long m_ulPrbUsage; //!< Used number of PRBs in an average of UL for the monitored slice during E2 reporting period
176     virtual ~EpcDuPmContainer () = default;
177   };
178
179   /**
180   * Contains the values to be inserted in the O-DU 5GC Measurement Container  
181   */
182   class FiveGcDuPmContainer : public SimpleRefCount<FiveGcDuPmContainer>
183   {
184   public:
185     // Snssai m_sliceId; //!< S-NSSAI
186     long m_fiveQi; //!< 5QI value
187     long m_dlPrbUsage; //!< Used number of PRBs in an average of DL for the monitored slice during E2 reporting period
188     long m_ulPrbUsage; //!< Used number of PRBs in an average of UL for the monitored slice during E2 reporting period
189     virtual ~FiveGcDuPmContainer () = default;
190   };
191
192   class ServedPlmnPerCell : public SimpleRefCount<ServedPlmnPerCell>
193   {
194   public:
195     std::string m_plmId; //!< PLMN identity, octet string, 3 bytes
196     uint16_t m_nrCellId;
197     std::set<Ptr<EpcDuPmContainer>> m_perQciReportItems;
198   };
199
200   class CellResourceReport : public SimpleRefCount<CellResourceReport>
201   {
202   public:
203     std::string m_plmId; //!< PLMN identity, octet string, 3 bytes
204     uint16_t m_nrCellId;
205     long dlAvailablePrbs;
206     long ulAvailablePrbs;
207     std::set<Ptr<ServedPlmnPerCell>> m_servedPlmnPerCellItems;
208   };
209
210   /**
211   * Contains the values to be inserted in the O-DU Measurement Container  
212   */
213   class ODuContainerValues : public PmContainerValues
214   {
215   public:
216     std::set<Ptr<CellResourceReport>> m_cellResourceReportItems;
217   };
218
219   class KpmIndicationMessage : public SimpleRefCount<KpmIndicationMessage>
220   {
221   public:
222     
223     /**
224     * Holds the values to be used to fill the RIC Indication Message 
225     */
226     struct KpmIndicationMessageValues
227     {
228       std::string m_cellObjectId; //!< Cell Object ID
229       Ptr<PmContainerValues> m_pmContainerValues; //!< struct containing values to be inserted in the PM Container
230       Ptr<MeasurementItemList> m_cellMeasurementItems; //!< list of cell-specific Measurement Information Items
231       std::set<Ptr<MeasurementItemList>> m_ueIndications; //!< list of Measurement Information Items
232     };
233
234     KpmIndicationMessage (KpmIndicationMessageValues values);
235     ~KpmIndicationMessage ();
236     
237     void* m_buffer;
238     size_t m_size;
239     
240   private:
241     static void CheckConstraints (KpmIndicationMessageValues values);
242     void FillPmContainer (PF_Container_t *ranContainer, 
243                           Ptr<PmContainerValues> values);
244     void FillOCuUpContainer (PF_Container_t *ranContainer, 
245                             Ptr<OCuUpContainerValues> values);
246     void FillOCuCpContainer (PF_Container_t *ranContainer, 
247                              Ptr<OCuCpContainerValues> values);
248     void FillODuContainer (PF_Container_t *ranContainer, 
249                            Ptr<ODuContainerValues> values);
250     void FillAndEncodeKpmIndicationMessage (E2SM_KPM_IndicationMessage_t *descriptor,
251                                             KpmIndicationMessageValues values);
252     void Encode (E2SM_KPM_IndicationMessage_t *descriptor);
253   };
254 }
255
256 #endif /* KPM_INDICATION_H */