First release
[sim/ns3-o-ran-e2.git] / model / oran-interface.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 ORAN_INTERFACE_H
26 #define ORAN_INTERFACE_H
27
28 #include "ns3/object.h"
29 #include <ns3/kpm-indication.h>
30 #include <ns3/kpm-function-description.h>
31 #include <ns3/ric-control-function-description.h>
32 #include <ns3/ric-control-message.h>
33 #include "e2sim.hpp"
34
35 namespace ns3 {
36   
37   class E2Termination : public Object 
38   {
39     public:
40
41       E2Termination();
42
43       /**
44       *
45       * \param ricAddress RIC IP address
46       * \param ricPort RIC port
47       * \param clientPort the local port to which the client will bind 
48       * \param gnbId the GNB ID
49       * \param plmnId the PLMN ID
50       */
51       E2Termination(const std::string ricAddress, 
52                   const uint16_t ricPort,
53                   const uint16_t clientPort,
54                   const std::string gnbId,
55                   const std::string plmnId);
56       
57       virtual ~E2Termination ();
58       
59       /**
60       *  inherited from Object
61       * @return
62       */
63       static TypeId GetTypeId();
64       
65       /**
66       * Start the E2 termination.
67       * Create a separate thread to host the execution of e2sim. The thread will 
68       * execute the method DoStart.  
69       */
70       void Start ();
71       
72       /**
73       * Register an E2 Service Model.
74       * Create a RAN Function Description item containing the configurations 
75       * for the SM, add it to the list of supported RAN functions, and 
76       * register a callback.
77       * Whenever a RIC Subscription Request to this RAN Function is received, 
78       * the callback is triggered.  
79       *
80       * \param ranFunctionId ID used to identify the KPM RAN Function
81       * \param ranFunctionDescription 
82       * \param cb callback that will be triggered if the RIC subscribes to 
83       *        this function
84       */
85       void RegisterKpmCallbackToE2Sm (long ranFunctionId, 
86                          Ptr<FunctionDescription> ranFunctionDescription, 
87                          SubscriptionCallback sbCb);
88
89       /**
90       * Register an E2 Service Model.
91       * Create a RAN Function Description item containing the configurations 
92       * for the SM, add it to the list of supported RAN functions, and 
93       * register a callback.
94       * Whenever a Sm message to this RAN Function is received, 
95       * the callback is triggered.  
96       *
97       * \param ranFunctionId ID used to identify the KPM RAN Function
98       * \param ranFunctionDescription 
99       * \param cb callback that will be triggered if the RIC subscribes to 
100       *        this function
101       */
102       void RegisterSmCallbackToE2Sm (long ranFunctionId,
103                                      Ptr<FunctionDescription> ranFunctionDescription,
104                                      SmCallback smCb);
105
106       /**
107       * Struct holding the values returned by ProcessRicSubscriptionRequest
108       */
109       struct RicSubscriptionRequest_rval_s
110       {
111         uint16_t requestorId; //!< RIC Requestor ID
112         uint16_t instanceId; //!< RIC Instance ID
113         uint16_t ranFuncionId; //!< RAN Function ID
114         uint8_t actionId; //!< RIC Action ID
115       }; 
116
117       /**
118       * Process RIC Subscription Request.
119       * This function processes the RIC Subscription Request and sends the 
120       * RIC Subscription Response.
121       *
122       * \param sub_req_pdu request message
123       * \return RIC subscription request parameters
124       */
125       RicSubscriptionRequest_rval_s ProcessRicSubscriptionRequest (E2AP_PDU_t* sub_req_pdu);
126
127       /**
128       * Sends an E2 message to the RIC
129       * This function encodes and sends an E2 message to the RIC
130       *
131       * \param pdu the PDU of the message
132       */
133       void SendE2Message (E2AP_PDU* pdu);   
134
135     private:
136       /**
137       * Run the e2sim main loop.
138       * Starts the e2sim main loop, it will open a socket towards the RIC and 
139       * start the reception routine.
140       */
141       void DoStart ();
142
143       /**
144        * \brief Accessory function to populate to the registration of the ran function description to e2sim
145        * 
146        * \param ranFunctionId 
147        * \param ranFunctionDescription 
148        */
149       void RegisterFunctionDescToE2Sm (long ranFunctionId,
150                                 Ptr<FunctionDescription> ranFunctionDescription);
151
152       E2Sim* m_e2sim; //!< pointer to an instance of the O-RAN E2 simulator
153       std::string m_ricAddress; //!< IP address of the RIC
154       uint16_t m_ricPort; //!< port of the RIC
155       uint16_t m_clientPort; //!< local bind port
156       std::string m_gnbId; //!< GNB id
157       std::string m_plmnId; //!< PLMN Id
158   };
159 }
160
161 #endif /* ORAN_INTERFACE_H */