5G-LENA nr-v3.3-159-ga6832aa7
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
cttc-3gpp-channel-simple-ran.cc
Go to the documentation of this file.
1// Copyright (c) 2020 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
2//
3// SPDX-License-Identifier: GPL-2.0-only
4
18#include "ns3/antenna-module.h"
19#include "ns3/config-store.h"
20#include "ns3/core-module.h"
21#include "ns3/grid-scenario-helper.h"
22#include "ns3/internet-module.h"
23#include "ns3/ipv4-global-routing-helper.h"
24#include "ns3/log.h"
25#include "ns3/mobility-module.h"
26#include "ns3/network-module.h"
27#include "ns3/nr-eps-bearer-tag.h"
28#include "ns3/nr-helper.h"
29#include "ns3/nr-module.h"
30#include "ns3/nr-point-to-point-epc-helper.h"
31
32using namespace ns3;
33
34/*
35 * Enable the logs of the file by enabling the component "Cttc3gppChannelSimpleRan",
36 * in this way:
37 * $ export NS_LOG="Cttc3gppChannelSimpleRan=level_info|prefix_func|prefix_time"
38 */
39NS_LOG_COMPONENT_DEFINE("Cttc3gppChannelSimpleRan");
40
41static bool g_rxPdcpCallbackCalled = false;
42static bool g_rxRxRlcPDUCallbackCalled = false;
43
51static void
52SendPacket(Ptr<NetDevice> device, Address& addr, uint32_t packetSize)
53{
54 Ptr<Packet> pkt = Create<Packet>(packetSize);
55 Ipv4Header ipv4Header;
56 ipv4Header.SetProtocol(UdpL4Protocol::PROT_NUMBER);
57 pkt->AddHeader(ipv4Header);
58 NrEpsBearerTag tag(1, 1);
59 pkt->AddPacketTag(tag);
60 device->Send(pkt, addr, Ipv4L3Protocol::PROT_NUMBER);
61}
62
72void
73RxPdcpPDU(std::string path, uint16_t rnti, uint8_t lcid, uint32_t bytes, uint64_t pdcpDelay)
74{
75 std::cout << "\n Packet PDCP delay:" << pdcpDelay << "\n";
76 g_rxPdcpCallbackCalled = true;
77}
78
89void
90RxRlcPDU(std::string path, uint16_t rnti, uint8_t lcid, uint32_t bytes, uint64_t rlcDelay)
91{
92 std::cout << "\n\n Data received at RLC layer at:" << Simulator::Now() << std::endl;
93 std::cout << "\n rnti:" << rnti << std::endl;
94 std::cout << "\n lcid:" << (unsigned)lcid << std::endl;
95 std::cout << "\n bytes :" << bytes << std::endl;
96 std::cout << "\n delay :" << rlcDelay << std::endl;
97 g_rxRxRlcPDUCallbackCalled = true;
98}
99
103void
105{
106 Config::Connect("/NodeList/*/DeviceList/*/NrUeRrc/DataRadioBearerMap/1/NrPdcp/RxPDU",
107 MakeCallback(&RxPdcpPDU));
108
109 Config::Connect("/NodeList/*/DeviceList/*/NrUeRrc/DataRadioBearerMap/1/NrRlc/RxPDU",
110 MakeCallback(&RxRlcPDU));
111}
112
116void
118{
119 Config::Connect("/NodeList/*/DeviceList/*/NrGnbRrc/UeMap/*/DataRadioBearerMap/*/NrPdcp/RxPDU",
120 MakeCallback(&RxPdcpPDU));
121
122 Config::Connect("/NodeList/*/DeviceList/*/NrGnbRrc/UeMap/*/DataRadioBearerMap/*/NrRlc/RxPDU",
123 MakeCallback(&RxRlcPDU));
124}
125
126int
127main(int argc, char* argv[])
128{
129 uint16_t numerologyBwp1 = 0;
130 uint32_t udpPacketSize = 1000;
131 double centralFrequencyBand1 = 28e9;
132 double bandwidthBand1 = 400e6;
133 uint16_t gNbNum = 1;
134 uint16_t ueNumPergNb = 1;
135 bool enableUl = false;
136
137 Time sendPacketTime = Seconds(0.4);
138
139 CommandLine cmd(__FILE__);
140 cmd.AddValue("numerologyBwp1", "The numerology to be used in bandwidth part 1", numerologyBwp1);
141 cmd.AddValue("centralFrequencyBand1",
142 "The system frequency to be used in band 1",
143 centralFrequencyBand1);
144 cmd.AddValue("bandwidthBand1", "The system bandwidth to be used in band 1", bandwidthBand1);
145 cmd.AddValue("packetSize", "packet size in bytes", udpPacketSize);
146 cmd.AddValue("enableUl", "Enable Uplink", enableUl);
147 cmd.Parse(argc, argv);
148
149 int64_t randomStream = 1;
150 // Create the scenario
151 GridScenarioHelper gridScenario;
152 gridScenario.SetRows(1);
153 gridScenario.SetColumns(gNbNum);
154 gridScenario.SetHorizontalBsDistance(5.0);
155 gridScenario.SetBsHeight(10.0);
156 gridScenario.SetUtHeight(1.5);
157 // must be set before BS number
158 gridScenario.SetSectorization(GridScenarioHelper::SINGLE);
159 gridScenario.SetBsNumber(gNbNum);
160 gridScenario.SetUtNumber(ueNumPergNb * gNbNum);
161 gridScenario.SetScenarioHeight(3); // Create a 3x3 scenario where the UE will
162 gridScenario.SetScenarioLength(3); // be distributed.
163 randomStream += gridScenario.AssignStreams(randomStream);
164 gridScenario.CreateScenario();
165
166 Ptr<NrPointToPointEpcHelper> nrEpcHelper = CreateObject<NrPointToPointEpcHelper>();
167 Ptr<IdealBeamformingHelper> idealBeamformingHelper = CreateObject<IdealBeamformingHelper>();
168 Ptr<NrHelper> nrHelper = CreateObject<NrHelper>();
169 Ptr<NrChannelHelper> channelHelper = CreateObject<NrChannelHelper>();
170
171 nrHelper->SetBeamformingHelper(idealBeamformingHelper);
172 nrHelper->SetEpcHelper(nrEpcHelper);
173 // Configure the spectrum channel
174 channelHelper->ConfigureFactories("UMi", "Default", "ThreeGpp");
175 Config::SetDefault("ns3::ThreeGppChannelModel::UpdatePeriod", TimeValue(MilliSeconds(0)));
176 channelHelper->SetChannelConditionModelAttribute("UpdatePeriod", TimeValue(MilliSeconds(0)));
177 channelHelper->SetPathlossAttribute("ShadowingEnabled", BooleanValue(false));
178
179 // Create one operational band containing one CC with one bandwidth part
181 CcBwpCreator ccBwpCreator;
182 const uint8_t numCcPerBand = 1;
183
184 // Create the configuration for the CcBwpHelper
185 CcBwpCreator::SimpleOperationBandConf bandConf1(centralFrequencyBand1,
186 bandwidthBand1,
187 numCcPerBand);
188
189 // By using the configuration created, it is time to make the operation band
190 OperationBandInfo band1 = ccBwpCreator.CreateOperationBandContiguousCc(bandConf1);
191 // Set and create the channel
192 channelHelper->AssignChannelsToBands({band1});
193 allBwps = CcBwpCreator::GetAllBwps({band1});
194
195 nrHelper->SetSchedulerAttribute("FixedMcsDl", BooleanValue(true));
196 nrHelper->SetSchedulerAttribute("StartingMcsDl", UintegerValue(28));
197
198 // Beamforming method
199 idealBeamformingHelper->SetAttribute("BeamformingMethod",
200 TypeIdValue(DirectPathBeamforming::GetTypeId()));
201
202 // Antennas for all the UEs
203 nrHelper->SetUeAntennaAttribute("NumRows", UintegerValue(2));
204 nrHelper->SetUeAntennaAttribute("NumColumns", UintegerValue(4));
205 nrHelper->SetUeAntennaAttribute("AntennaElement",
206 PointerValue(CreateObject<IsotropicAntennaModel>()));
207
208 // Antennas for all the gNbs
209 nrHelper->SetGnbAntennaAttribute("NumRows", UintegerValue(4));
210 nrHelper->SetGnbAntennaAttribute("NumColumns", UintegerValue(8));
211 nrHelper->SetGnbAntennaAttribute("AntennaElement",
212 PointerValue(CreateObject<IsotropicAntennaModel>()));
213
214 // Install and get the pointers to the NetDevices
215 NetDeviceContainer gnbNetDev =
216 nrHelper->InstallGnbDevice(gridScenario.GetBaseStations(), allBwps);
217 NetDeviceContainer ueNetDev =
218 nrHelper->InstallUeDevice(gridScenario.GetUserTerminals(), allBwps);
219
220 randomStream += nrHelper->AssignStreams(gnbNetDev, randomStream);
221 randomStream += nrHelper->AssignStreams(ueNetDev, randomStream);
222
223 // Set the attribute of the netdevice (gnbNetDev.Get (0)) and bandwidth part (0)
224 nrHelper->GetGnbPhy(gnbNetDev.Get(0), 0)
225 ->SetAttribute("Numerology", UintegerValue(numerologyBwp1));
226
227 InternetStackHelper internet;
228 internet.Install(gridScenario.GetUserTerminals());
229 Ipv4InterfaceContainer ueIpIface;
230 ueIpIface = nrEpcHelper->AssignUeIpv4Address(NetDeviceContainer(ueNetDev));
231
232 if (enableUl)
233 {
234 Simulator::Schedule(sendPacketTime,
235 &SendPacket,
236 ueNetDev.Get(0),
237 gnbNetDev.Get(0)->GetAddress(),
238 udpPacketSize);
239 }
240 else
241 {
242 Simulator::Schedule(sendPacketTime,
243 &SendPacket,
244 gnbNetDev.Get(0),
245 ueNetDev.Get(0)->GetAddress(),
246 udpPacketSize);
247 }
248
249 // attach UEs to the closest gNB
250 nrHelper->AttachToClosestGnb(ueNetDev, gnbNetDev);
251
252 if (enableUl)
253 {
254 std::cout << "\n Sending data in uplink." << std::endl;
255 Simulator::Schedule(Seconds(0.2), &ConnectUlPdcpRlcTraces);
256 }
257 else
258 {
259 std::cout << "\n Sending data in downlink." << std::endl;
260 Simulator::Schedule(Seconds(0.2), &ConnectPdcpRlcTraces);
261 }
262
263 nrHelper->EnableTraces();
264
265 Simulator::Stop(Seconds(1));
266 Simulator::Run();
267 Simulator::Destroy();
268
269 if (g_rxPdcpCallbackCalled && g_rxRxRlcPDUCallbackCalled)
270 {
271 return EXIT_SUCCESS;
272 }
273 else
274 {
275 return EXIT_FAILURE;
276 }
277}
Manages the correct creation of operation bands, component carriers and bandwidth parts.
OperationBandInfo CreateOperationBandContiguousCc(const SimpleOperationBandConf &conf)
Create an operation band with the CC specified.
static BandwidthPartInfoPtrVector GetAllBwps(const std::vector< std::reference_wrapper< OperationBandInfo > > &operationBands)
Get all the BWP pointers from the specified vector of operation bands.
static TypeId GetTypeId()
Get the type id.
The GridScenarioHelper class.
void SetRows(uint32_t r)
SetRows.
void SetHorizontalBsDistance(double d)
SetHorizontalBsDistance.
void CreateScenario() override
Create the scenario, with the configured parameter.
int64_t AssignStreams(int64_t stream)
void SetColumns(uint32_t c)
SetColumns.
const NodeContainer & GetUserTerminals() const
Get the list of user nodes.
void SetBsNumber(std::size_t n)
Set the number of base stations.
void SetUtNumber(std::size_t n)
Set the number of UT/UE.
const NodeContainer & GetBaseStations() const
Get the list of gnb/base station nodes.
void SetBsHeight(double h)
SetGnbHeight.
void SetUtHeight(double h)
SetUeHeight.
void SetSectorization(SiteSectorizationType numSectors)
Sets the number of sectors of every site.
void ConnectUlPdcpRlcTraces()
static void SendPacket(Ptr< NetDevice > device, Address &addr, uint32_t packetSize)
void ConnectPdcpRlcTraces()
void RxPdcpPDU(std::string path, uint16_t rnti, uint8_t lcid, uint32_t bytes, uint64_t pdcpDelay)
void RxRlcPDU(std::string path, uint16_t rnti, uint8_t lcid, uint32_t bytes, uint64_t rlcDelay)
std::vector< std::reference_wrapper< BandwidthPartInfoPtr > > BandwidthPartInfoPtrVector
vector of unique_ptr of BandwidthPartInfo
Minimum configuration requirements for a OperationBand.
Operation band information structure.