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/core-module.h"
26 #include "ns3/oran-interface.h"
27 #include "encode_e2apv1.hpp"
33 Ptr<E2Termination> e2Term;
34 // TODO create getters for these parameters in e2Term
35 std::string plmId = "111";
37 const std::string gnb = std::to_string (cellId);
40 * Creates an empty RIC Report message and send it to the RIC
42 * \param params the RIC Subscription Request parameters
44 static void BuildAndSendReportMessage (E2Termination::RicSubscriptionRequest_rval_s params)
46 KpmIndicationHeader::KpmRicIndicationHeaderValues headerValues;
47 headerValues.m_plmId = plmId;
48 headerValues.m_gnbId = cellId;
49 headerValues.m_nrCellId = cellId;
51 Ptr<KpmIndicationHeader> header = Create<KpmIndicationHeader> (KpmIndicationHeader::GlobalE2nodeType::gNB, headerValues);
53 KpmIndicationMessage::KpmIndicationMessageValues msgValues;
55 Ptr<OCuUpContainerValues> cuUpValues = Create<OCuUpContainerValues> ();
56 cuUpValues->m_plmId = plmId;
57 cuUpValues->m_pDCPBytesUL = 100;
58 cuUpValues->m_pDCPBytesDL = 100;
59 msgValues.m_pmContainerValues = cuUpValues;
61 Ptr<MeasurementItemList> ue0DummyValues = Create<MeasurementItemList> ("UE-0");
62 ue0DummyValues->AddItem<long> ("DRB.PdcpSduVolumeDl_Filter.UEID", 6);
63 ue0DummyValues->AddItem<long> ("QosFlow.PdcpPduVolumeDL_Filter.UEID", 7);
64 ue0DummyValues->AddItem<long> ("Tot.PdcpSduNbrDl.UEID", 8);
65 ue0DummyValues->AddItem<long> ("DRB.PdcpPduNbrDl.Qos.UEID", 9);
66 ue0DummyValues->AddItem<double> ("DRB.IPThpDl.UEID", 10.0);
67 ue0DummyValues->AddItem<double> ("DRB.IPLateDl.UEID", 11.0);
68 msgValues.m_ueIndications.insert (ue0DummyValues);
70 Ptr<MeasurementItemList> ue1DummyValues = Create<MeasurementItemList> ("UE-1");;
71 ue1DummyValues->AddItem<long> ("DRB.PdcpSduVolumeDl_Filter.UEID", 6);
72 ue1DummyValues->AddItem<long> ("QosFlow.PdcpPduVolumeDL_Filter.UEID", 7);
73 ue1DummyValues->AddItem<long> ("Tot.PdcpSduNbrDl.UEID", 8);
74 ue1DummyValues->AddItem<long> ("DRB.PdcpPduNbrDl.Qos.UEID", 9);
75 ue1DummyValues->AddItem<double> ("DRB.IPThpDl.UEID", 10.0);
76 ue1DummyValues->AddItem<double> ("DRB.IPLateDl.UEID", 11.0);
77 msgValues.m_ueIndications.insert (ue1DummyValues);
79 Ptr<KpmIndicationMessage> msg = Create<KpmIndicationMessage> (msgValues);
81 E2AP_PDU *pdu_cuup_ue = new E2AP_PDU;
82 encoding::generate_e2apv1_indication_request_parameterized(pdu_cuup_ue,
87 1, // TODO sequence number
88 (uint8_t*) header->m_buffer, // buffer containing the encoded header
89 header->m_size, // size of the encoded header
90 (uint8_t*) msg->m_buffer, // buffer containing the encoded message
91 msg->m_size); // size of the encoded message
92 e2Term->SendE2Message (pdu_cuup_ue);
98 * KPM Subscription Request callback.
99 * This function is triggered whenever a RIC Subscription Request for
100 * the KPM RAN Function is received.
102 * \param pdu request message
104 static void KpmSubscriptionCallback (E2AP_PDU_t* sub_req_pdu)
106 NS_LOG_UNCOND ("\n\nReceived RIC Subscription Request");
108 E2Termination::RicSubscriptionRequest_rval_s params = e2Term->ProcessRicSubscriptionRequest (sub_req_pdu);
109 NS_LOG_UNCOND ("requestorId " << +params.requestorId <<
110 ", instanceId " << +params.instanceId <<
111 ", ranFuncionId " << +params.ranFuncionId <<
112 ", actionId " << +params.actionId);
114 BuildAndSendReportMessage (params);
118 * RIC Control Message callback.
119 * This function is triggered whenever a RIC Control Message is received.
121 * \param pdu request message
124 RicControlMessageCallback (E2AP_PDU_t *ric_ctrl_pdu)
126 NS_LOG_UNCOND ("\n\nReceived RIC Control Message");
128 RicControlMessage msg = RicControlMessage (ric_ctrl_pdu);
129 // TODO log something
134 main (int argc, char *argv[])
136 LogComponentEnable ("Asn1Types", LOG_LEVEL_ALL);
137 LogComponentEnable ("RicControlMessage", LOG_LEVEL_ALL);
138 e2Term = CreateObject<E2Termination> ("10.244.0.191", 36422, 38472, gnb, plmId);
139 Ptr<KpmFunctionDescription> kpmFd = Create<KpmFunctionDescription> ();
140 e2Term->RegisterKpmCallbackToE2Sm (200, kpmFd, &KpmSubscriptionCallback);
141 Ptr<RicControlFunctionDescription> rcFd = Create<RicControlFunctionDescription> ();
142 e2Term->RegisterSmCallbackToE2Sm (300, rcFd, &RicControlMessageCallback);