A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
test-lte-handover-spectrum-model.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2026 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Gabriel Ferreira <gabrielcarvfer@gmail.com>
7 */
8
9#include "ns3/application-container.h"
10#include "ns3/boolean.h"
11#include "ns3/config.h"
12#include "ns3/constant-velocity-mobility-model.h"
13#include "ns3/data-rate.h"
14#include "ns3/double.h"
15#include "ns3/epc-tft.h"
16#include "ns3/eps-bearer.h"
17#include "ns3/inet-socket-address.h"
18#include "ns3/internet-stack-helper.h"
19#include "ns3/ipv4-address-helper.h"
20#include "ns3/ipv4-interface-container.h"
21#include "ns3/ipv4-static-routing-helper.h"
22#include "ns3/ipv4-static-routing.h"
23#include "ns3/lte-helper.h"
24#include "ns3/mobility-helper.h"
25#include "ns3/net-device-container.h"
26#include "ns3/node-container.h"
27#include "ns3/nstime.h"
28#include "ns3/packet-sink-helper.h"
29#include "ns3/point-to-point-epc-helper.h"
30#include "ns3/point-to-point-helper.h"
31#include "ns3/position-allocator.h"
32#include "ns3/rng-seed-manager.h"
33#include "ns3/simulator.h"
34#include "ns3/test.h"
35#include "ns3/udp-client-server-helper.h"
36#include "ns3/uinteger.h"
37
38using namespace ns3;
39
40NS_LOG_COMPONENT_DEFINE("LteHandoverSpectrumModelTest");
41
42/**
43 * @ingroup lte-test
44 *
45 * @brief Regression test for @issueid{447}: a UE handing over between cells must
46 * not abort with the spectrum-model mismatch assertion
47 * (m_spectrumModel == x.m_spectrumModel) in SpectrumValue.
48 *
49 * During a handover the UE PHY is reconfigured to the target cell, which
50 * changes the spectrum model of its noise/interference PSDs. A downlink
51 * control reception associated with the previous configuration can complete
52 * after the reconfiguration, so LteUePhy::GenerateMixedCqiReport() must not
53 * divide two SpectrumValue objects with different spectrum models.
54 *
55 * The test runs a compact mobile multi-UE A3-RSRP handover scenario with the
56 * control and data error models enabled (which trigger the handover/RLF
57 * activity that exposes the race) and verifies that the simulation runs to
58 * completion.
59 */
61{
62 public:
65
66 private:
67 void DoRun() override;
68};
69
71 : TestCase("Handover does not abort on spectrum-model mismatch (issue #447)")
72{
73}
74
78
79void
81{
82 // Deterministic run.
85
86 const double simTime = 5.0; // the pre-fix abort occurs at ~2.4 s
87 const uint16_t numberOfUes = 30;
88 const uint16_t numberOfCells = 5;
89 const double speed = 16.0;
90
91 Config::SetDefault("ns3::LteRlcUm::MaxTxBufferSize", UintegerValue(60 * 1024));
92 Config::SetDefault("ns3::LteHelper::UseIdealRrc", BooleanValue(false));
93 Config::SetDefault("ns3::LteSpectrumPhy::CtrlErrorModelEnabled", BooleanValue(true));
94 Config::SetDefault("ns3::LteSpectrumPhy::DataErrorModelEnabled", BooleanValue(true));
95 // Radio link failure timers.
96 Config::SetDefault("ns3::LteUeRrc::N310", UintegerValue(1));
97 Config::SetDefault("ns3::LteUeRrc::N311", UintegerValue(1));
98 Config::SetDefault("ns3::LteUeRrc::T310", TimeValue(Seconds(1)));
99
102 lteHelper->SetEpcHelper(epcHelper);
103 lteHelper->SetPathlossModelType(TypeId::LookupByName("ns3::LogDistancePropagationLossModel"));
104 lteHelper->SetSchedulerType("ns3::PfFfMacScheduler");
105 lteHelper->SetHandoverAlgorithmType("ns3::A3RsrpHandoverAlgorithm");
106 lteHelper->SetHandoverAlgorithmAttribute("Hysteresis", DoubleValue(3.0));
107 lteHelper->SetHandoverAlgorithmAttribute("TimeToTrigger", TimeValue(MilliSeconds(256)));
108
109 // Internet / remote host.
110 Ptr<Node> pgw = epcHelper->GetPgwNode();
111 NodeContainer remoteHostContainer;
112 remoteHostContainer.Create(1);
113 Ptr<Node> remoteHost = remoteHostContainer.Get(0);
114 InternetStackHelper internet;
115 internet.Install(remoteHostContainer);
117 p2ph.SetDeviceAttribute("DataRate", DataRateValue(DataRate("100Gb/s")));
118 p2ph.SetDeviceAttribute("Mtu", UintegerValue(1500));
119 p2ph.SetChannelAttribute("Delay", TimeValue(Seconds(0.010)));
120 NetDeviceContainer internetDevices = p2ph.Install(pgw, remoteHost);
121 Ipv4AddressHelper ipv4h;
122 ipv4h.SetBase("1.0.0.0", "255.0.0.0");
123 Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign(internetDevices);
124 Ipv4Address remoteHostAddr = internetIpIfaces.GetAddress(1);
125 Ipv4StaticRoutingHelper ipv4RoutingHelper;
126 Ptr<Ipv4StaticRouting> remoteHostStaticRouting =
127 ipv4RoutingHelper.GetStaticRouting(remoteHost->GetObject<Ipv4>());
128 remoteHostStaticRouting->AddNetworkRouteTo(Ipv4Address("7.0.0.0"), Ipv4Mask("255.0.0.0"), 1);
129
130 // eNodeBs: one macro plus several small cells along a line.
131 NodeContainer enbNodes;
132 enbNodes.Create(numberOfCells);
134 enbPosition->Add(Vector(500, 0, 0)); // macro
135 enbPosition->Add(Vector(10, 0, 0));
136 enbPosition->Add(Vector(30, 0, 0));
137 enbPosition->Add(Vector(50, 0, 0));
138 enbPosition->Add(Vector(70, 0, 0));
139 MobilityHelper enbMobility;
140 enbMobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
141 enbMobility.SetPositionAllocator(enbPosition);
142 enbMobility.Install(enbNodes);
143
144 NetDeviceContainer enbDevs;
145 Config::SetDefault("ns3::LteEnbPhy::TxPower", DoubleValue(43.0));
146 enbDevs.Add(lteHelper->InstallEnbDevice(enbNodes.Get(0)));
147 Config::SetDefault("ns3::LteEnbPhy::TxPower", DoubleValue(20.0));
148 for (uint16_t j = 1; j < numberOfCells; j++)
149 {
150 enbDevs.Add(lteHelper->InstallEnbDevice(enbNodes.Get(j)));
151 }
152
153 // UEs moving along the line of small cells.
154 NodeContainer ueNodes;
155 ueNodes.Create(numberOfUes);
156 MobilityHelper ueMobility;
157 ueMobility.SetMobilityModel("ns3::ConstantVelocityMobilityModel");
158 ueMobility.Install(ueNodes);
159 for (uint16_t i = 0; i < numberOfUes; i++)
160 {
161 ueNodes.Get(i)->GetObject<MobilityModel>()->SetPosition(Vector(0, 0, 0));
162 ueNodes.Get(i)->GetObject<ConstantVelocityMobilityModel>()->SetVelocity(
163 Vector(speed, 0, 0));
164 }
165 NetDeviceContainer ueDevs = lteHelper->InstallUeDevice(ueNodes);
166 internet.Install(ueNodes);
167 Ipv4InterfaceContainer ueIpIfaces = epcHelper->AssignUeIpv4Address(NetDeviceContainer(ueDevs));
168
169 for (uint16_t i = 0; i < numberOfUes; i++)
170 {
171 lteHelper->Attach(ueDevs.Get(i));
172 }
173
174 // Downlink/uplink traffic and a dedicated bearer per UE. The scenario
175 // mirrors the reporter's repro (sinks at both ends, a short packet
176 // interval) which exposes the handover activity that triggers the bug.
178 startTime->SetAttribute("Min", DoubleValue(0));
179 startTime->SetAttribute("Max", DoubleValue(0.010));
180 uint16_t dlPort = 10000;
181 uint16_t ulPort = 20000;
182 for (uint16_t u = 0; u < numberOfUes; ++u)
183 {
184 Ptr<Node> ue = ueNodes.Get(u);
185 Ptr<Ipv4StaticRouting> ueStaticRouting =
186 ipv4RoutingHelper.GetStaticRouting(ue->GetObject<Ipv4>());
187 ueStaticRouting->SetDefaultRoute(epcHelper->GetUeDefaultGatewayAddress(), 1);
188
189 ++dlPort;
190 ++ulPort;
191
192 UdpClientHelper dlClientHelper(ueIpIfaces.GetAddress(u), dlPort);
193 dlClientHelper.SetAttribute("Interval", TimeValue(MilliSeconds(1)));
194 dlClientHelper.SetAttribute("MaxPackets", UintegerValue(1000000));
195 ApplicationContainer dlApps = dlClientHelper.Install(remoteHost);
196 PacketSinkHelper dlSink("ns3::UdpSocketFactory",
198 dlApps.Add(dlSink.Install(ue));
199
200 UdpClientHelper ulClientHelper(remoteHostAddr, ulPort);
201 ulClientHelper.SetAttribute("Interval", TimeValue(MilliSeconds(1)));
202 ulClientHelper.SetAttribute("MaxPackets", UintegerValue(1000000));
203 ApplicationContainer ulApps = ulClientHelper.Install(ue);
204 PacketSinkHelper ulSink("ns3::UdpSocketFactory",
206 ulApps.Add(ulSink.Install(remoteHost));
207
210 dlpf.localPortStart = dlPort;
211 dlpf.localPortEnd = dlPort;
212 tft->Add(dlpf);
214 ulpf.remotePortStart = ulPort;
215 ulpf.remotePortEnd = ulPort;
216 tft->Add(ulpf);
218 lteHelper->ActivateDedicatedEpsBearer(ueDevs.Get(u), bearer, tft);
219
220 Time appStart = Seconds(startTime->GetValue());
221 dlApps.Start(appStart);
222 ulApps.Start(appStart);
223 }
224
225 lteHelper->AddX2Interface(enbNodes);
226
227 Simulator::Stop(Seconds(simTime));
229
230 // Reaching this point means the simulation completed without the
231 // spectrum-model mismatch assertion aborting it (@issueid{447}).
232 NS_TEST_ASSERT_MSG_EQ(Simulator::Now().GetSeconds() >= simTime - 1e-6,
233 true,
234 "Simulation did not run to completion");
235
237}
238
239/**
240 * @ingroup lte-test
241 *
242 * @brief Test suite for the handover spectrum-model regression test.
243 */
249
255
256/// Static variable for test initialization
uint32_t u
Regression test for Issue 447: a UE handing over between cells must not abort with the spectrum-model...
void DoRun() override
Implementation to actually run this TestCase.
Test suite for the handover spectrum-model regression test.
holds a vector of ns3::Application pointers.
void Start(Time start) const
Start all of the Applications in this container at the start time given as a parameter.
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container.
ApplicationContainer Install(NodeContainer c)
Install an application on each node of the input container configured with all the attributes set wit...
void SetAttribute(const std::string &name, const AttributeValue &value)
Helper function used to set the underlying application attributes.
Mobility model for which the current speed does not change once it has been set and until it is set a...
Class for representing data rates.
Definition data-rate.h:78
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
This class contains the specification of EPS Bearers.
Definition eps-bearer.h:80
@ NGBR_IMS
Non-GBR IMS Signalling.
Definition eps-bearer.h:109
an Inet address class
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Ipv4 addresses are stored in host order in this class.
static Ipv4Address GetAny()
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition ipv4.h:69
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
a class to represent an Ipv4 address mask
Helper class that adds ns3::Ipv4StaticRouting objects.
Ptr< Ipv4StaticRouting > GetStaticRouting(Ptr< Ipv4 > ipv4) const
Try and find the static routing protocol as either the main routing protocol or in the list of routin...
Helper class used to assign positions and mobility models to nodes.
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
void SetMobilityModel(std::string type, Ts &&... args)
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
Keep track of the current position and velocity of an object.
holds a vector of ns3::NetDevice pointers
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition object.h:518
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
Build a set of PointToPointNetDevice objects.
void SetDeviceAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each NetDevice created by the helper.
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
NetDeviceContainer Install(NodeContainer c)
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
static void SetRun(uint64_t run)
Set the run number of simulation.
static void SetSeed(uint32_t seed)
Set the seed.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:125
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:191
static void Run()
Run the simulation.
Definition simulator.cc:161
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:169
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:296
@ EXTENSIVE
Medium length test.
Definition test.h:1058
TestCase(const TestCase &)=delete
Caller graph was not generated because of its size.
Type
Type of test.
Definition test.h:1271
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
Definition test.cc:494
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Definition type-id.cc:874
Create a client application which sends UDP packets carrying a 32bit sequence number and a 64 bit tim...
Hold an unsigned integer type.
Definition uinteger.h:34
void SetDefault(std::string name, const AttributeValue &value)
Definition config.cc:886
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:201
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:627
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:492
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition test.h:133
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1313
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1330
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Implement the data structure representing a TrafficFlowTemplate Packet Filter.
Definition epc-tft.h:60
uint16_t localPortEnd
end of the port number range of the UE
Definition epc-tft.h:121
uint16_t remotePortEnd
end of the port number range of the remote host
Definition epc-tft.h:119
uint16_t remotePortStart
start of the port number range of the remote host
Definition epc-tft.h:118
uint16_t localPortStart
start of the port number range of the UE
Definition epc-tft.h:120
static LteHandoverSpectrumModelTestSuite g_lteHandoverSpectrumModelTestSuite
Static variable for test initialization.