A Discrete-Event Network Simulator
API
lte-test-rlc-am-e2e.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2012 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Manuel Requena <manuel.requena@cttc.es>
19  * Nicola Baldo <nbaldo@cttc.es>
20  */
21 
22 #include "ns3/config.h"
23 #include "ns3/simulator.h"
24 #include "ns3/pointer.h"
25 #include "ns3/log.h"
26 #include "ns3/packet.h"
27 #include "ns3/node-container.h"
28 #include "ns3/net-device-container.h"
29 #include "ns3/error-model.h"
30 #include "ns3/rng-seed-manager.h"
31 #include "ns3/radio-bearer-stats-calculator.h"
32 #include "ns3/lte-rlc-header.h"
33 #include "ns3/lte-rlc-um.h"
34 #include "ns3/config-store.h"
35 
36 #include "lte-test-rlc-am-e2e.h"
37 #include "lte-simple-helper.h"
38 #include "lte-test-entities.h"
39 
40 
41 using namespace ns3;
42 
43 NS_LOG_COMPONENT_DEFINE ("LteRlcAmE2eTest");
44 
46  : TestSuite ("lte-rlc-am-e2e", SYSTEM)
47 {
48  // NS_LOG_INFO ("Creating LteRlcAmE2eTestSuite");
49 
50  double losses[] = {0.0, 0.05, 0.10, 0.15, 0.25, 0.50, 0.75, 0.90, 0.95};
51  uint32_t runs[] = {1111, 2222, 3333, 4444, 5555, 6666, 7777, 8888, 9999, 11110,
52  12221, 13332, 14443, 15554, 16665, 17776, 18887, 19998, 21109, 22220,
53  23331, 24442, 25553, 26664, 27775, 28886, 29997, 31108, 32219, 33330};
54 
55  for ( uint32_t l = 0 ; l < (sizeof (losses) / sizeof (double)) ; l++ )
56  {
57  for ( uint32_t s = 0 ; s < (sizeof (runs) / sizeof (uint32_t)) ; s++ )
58  {
59  for (uint32_t sduArrivalType = 0; sduArrivalType <= 1; ++sduArrivalType)
60  {
61  std::ostringstream name;
62  name << " losses = " << losses[l] * 100 << "%; run = " << runs[s];
63 
64  bool bulkSduArrival;
65  switch (sduArrivalType)
66  {
67  case 0:
68  bulkSduArrival = false;
69  name << "; continuous SDU arrival";
70  break;
71  case 1:
72  bulkSduArrival = true;
73  name << "; bulk SDU arrival";
74  break;
75  default:
76  NS_FATAL_ERROR ("unsupported option");
77  break;
78  }
79 
80  TestCase::TestDuration testDuration;
81  if (l == 1 && s == 0)
82  {
83  testDuration = TestCase::QUICK;
84  }
85  else if (s <= 4)
86  {
87  testDuration = TestCase::EXTENSIVE;
88  }
89  else
90  {
91  testDuration = TestCase::TAKES_FOREVER;
92  }
93  AddTestCase (new LteRlcAmE2eTestCase (name.str (), runs[s], losses[l], bulkSduArrival), testDuration);
94  }
95  }
96  }
97 }
98 
100 
101 LteRlcAmE2eTestCase::LteRlcAmE2eTestCase (std::string name, uint32_t run, double losses, bool bulkSduArrival)
102  : TestCase (name),
103  m_run (run),
104  m_losses (losses),
105  m_bulkSduArrival (bulkSduArrival),
106  m_dlDrops (0),
107  m_ulDrops (0)
108 {
109  NS_LOG_INFO ("Creating LteRlcAmTestingTestCase: " + name);
110 }
111 
113 {
114 }
115 
116 
117 void
119 {
120  // NS_LOG_FUNCTION (this);
121  m_dlDrops++;
122 }
123 
124 void
126 {
127  // NS_LOG_FUNCTION (this);
128  m_ulDrops++;
129 }
130 
131 void
133 {
134  uint16_t numberOfNodes = 1;
135 
136  // LogLevel level = (LogLevel) (LOG_LEVEL_ALL | LOG_PREFIX_TIME | LOG_PREFIX_NODE | LOG_PREFIX_FUNC);
137  // LogComponentEnable ("LteRlcAmE2eTest", level);
138  // LogComponentEnable ("ErrorModel", level);
139  // LogComponentEnable ("LteSimpleHelper", level);
140  // LogComponentEnable ("LteSimpleNetDevice", level);
141  // LogComponentEnable ("SimpleNetDevice", level);
142  // LogComponentEnable ("SimpleChannel", level);
143  // LogComponentEnable ("LteTestEntities", level);
144  // LogComponentEnable ("LtePdcp", level);
145  // LogComponentEnable ("LteRlc", level);
146  // LogComponentEnable ("LteRlcUm", level);
147  // LogComponentEnable ("LteRlcAm", level);
148 
149  Config::SetGlobal ("RngRun", UintegerValue (m_run));
150  Config::SetDefault ("ns3::LteRlcAm::PollRetransmitTimer", TimeValue (MilliSeconds (20)));
151  Config::SetDefault ("ns3::LteRlcAm::ReorderingTimer", TimeValue (MilliSeconds (10)));
152  Config::SetDefault ("ns3::LteRlcAm::StatusProhibitTimer", TimeValue (MilliSeconds (40)));
153 
154  Ptr<LteSimpleHelper> lteSimpleHelper = CreateObject<LteSimpleHelper> ();
155  // lteSimpleHelper->EnableLogComponents ();
156  // lteSimpleHelper->EnableTraces ();
157 
158  lteSimpleHelper->SetAttribute ("RlcEntity", StringValue ("RlcAm"));
159 
160  // eNB and UE nodes
161  NodeContainer ueNodes;
162  NodeContainer enbNodes;
163  enbNodes.Create (numberOfNodes);
164  ueNodes.Create (numberOfNodes);
165 
166  // Install LTE Devices to the nodes
167  NetDeviceContainer enbLteDevs = lteSimpleHelper->InstallEnbDevice (enbNodes);
168  NetDeviceContainer ueLteDevs = lteSimpleHelper->InstallUeDevice (ueNodes);
169 
170  // Note: Just one eNB and UE is supported. Everything is done in InstallEnbDevice and InstallUeDevice
171 
172  // Attach one UE per eNodeB
173  // for (uint16_t i = 0; i < numberOfNodes; i++)
174  // {
175  // lteSimpleHelper->Attach (ueLteDevs.Get(i), enbLteDevs.Get(i));
176  // }
177 
178  // lteSimpleHelper->ActivateEpsBearer (ueLteDevs, EpsBearer (EpsBearer::NGBR_VIDEO_TCP_DEFAULT), EpcTft::Default ());
179 
180 
181  // Error models: downlink and uplink
182  Ptr<RateErrorModel> dlEm = CreateObject<RateErrorModel> ();
183  // fix the stream so that subsequent test cases get a number from the same stream
184  // if RngRun is different, the number shall then be different
185  dlEm->AssignStreams (3);
186  dlEm->SetAttribute ("ErrorRate", DoubleValue (m_losses));
187  dlEm->SetAttribute ("ErrorUnit", StringValue ("ERROR_UNIT_PACKET"));
188 
189 // Ptr<RateErrorModel> ueEm = CreateObjectWithAttributes<RateErrorModel> ("RanVar", StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=1.0]"));
190 // ueEm->SetAttribute ("ErrorRate", DoubleValue (m_losses));
191 // ueEm->SetAttribute ("ErrorUnit", StringValue ("ERROR_UNIT_PACKET"));
192 
193  // The below hooks will cause drops and receptions to be counted
194  ueLteDevs.Get (0)->SetAttribute ("ReceiveErrorModel", PointerValue (dlEm));
195  ueLteDevs.Get (0)->TraceConnectWithoutContext ("PhyRxDrop", MakeCallback (&LteRlcAmE2eTestCase::DlDropEvent, this));
196 // enbLteDevs.Get (0)->SetAttribute ("ReceiveErrorModel", PointerValue (enbEm));
197 // enbLteDevs.Get (0)->TraceConnectWithoutContext ("PhyRxDrop", MakeCallback (&LteRlcAmE2eTestCase::EnbDropEvent, this));
198 
199 
200 
201  uint32_t sduSizeBytes = 100;
202  uint32_t numSdu = 1000;
203  double sduStartTimeSeconds = 0.100;
204  double sduStopTimeSeconds;
205  double sduArrivalTimeSeconds;
206  uint32_t dlTxOppSizeBytes = 150;
207  double dlTxOpprTimeSeconds = 0.003;
208  uint32_t ulTxOppSizeBytes = 140;
209  double ulTxOpprTimeSeconds = 0.003;
210 
211  if (m_bulkSduArrival)
212  {
213  sduStopTimeSeconds = sduStartTimeSeconds + 0.010;
214  }
215  else
216  {
217  sduStopTimeSeconds = sduStartTimeSeconds + 10;
218  }
219  sduArrivalTimeSeconds = (sduStopTimeSeconds - sduStartTimeSeconds) / numSdu;
220 
221 
222 
223  // Sending packets from RRC layer
224  lteSimpleHelper->m_enbRrc->SetArrivalTime (Seconds (sduArrivalTimeSeconds));
225  lteSimpleHelper->m_enbRrc->SetPduSize (sduSizeBytes);
226 
227  // MAC sends transmission opportunities (TxOpp)
228  lteSimpleHelper->m_enbMac->SetTxOppSize (dlTxOppSizeBytes);
229  lteSimpleHelper->m_enbMac->SetTxOppTime (Seconds (dlTxOpprTimeSeconds));
230  lteSimpleHelper->m_enbMac->SetTxOpportunityMode (LteTestMac::AUTOMATIC_MODE);
231 
232  // MAC sends transmission opportunities (TxOpp)
233  lteSimpleHelper->m_ueMac->SetTxOppSize (ulTxOppSizeBytes);
234  lteSimpleHelper->m_ueMac->SetTxOppTime (Seconds (ulTxOpprTimeSeconds));
235  lteSimpleHelper->m_ueMac->SetTxOpportunityMode (LteTestMac::AUTOMATIC_MODE);
236 
237  // Start/Stop pseudo-application at RRC layer
238  Simulator::Schedule (Seconds (sduStartTimeSeconds), &LteTestRrc::Start, lteSimpleHelper->m_enbRrc);
239  Simulator::Schedule (Seconds (sduStopTimeSeconds), &LteTestRrc::Stop, lteSimpleHelper->m_enbRrc);
240 
241 
242  double maxDlThroughput = (dlTxOppSizeBytes/(dlTxOppSizeBytes+4.0))*(dlTxOppSizeBytes/dlTxOpprTimeSeconds) * (1.0-m_losses);
243  const double statusProhibitSeconds = 0.020;
244  double pollFrequency = (1.0/dlTxOpprTimeSeconds)*(1-m_losses);
245  double statusFrequency = std::min (pollFrequency, 1.0/statusProhibitSeconds);
246  const uint32_t numNackSnPerStatusPdu = (ulTxOppSizeBytes*8 - 14)/10;
247  double maxRetxThroughput = ((double)numNackSnPerStatusPdu*(double)dlTxOppSizeBytes)*statusFrequency;
248  double throughput = std::min (maxDlThroughput, maxRetxThroughput);
249  double totBytes = ((sduSizeBytes) * (sduStopTimeSeconds - sduStartTimeSeconds) / sduArrivalTimeSeconds);
250 
251 
252  // note: the throughput estimation is valid only for the full buffer
253  // case. However, the test sends a finite number of SDUs. Hence, the
254  // estimated throughput will only be effective at the beginning of
255  // the test. Towards the end of the test, two issues are present:
256  // 1) no new data is transmitted, hence less feedback is sent,
257  // hence the transmission rate for the last PDUs to be
258  // retransmitted is much lower. This effect can be best noteed
259  // at very high loss rates, and can be adjusted by timers and
260  // params.
261  // 2) throuhgput is not meaningful, you need to evaluate the time
262  // it takes for all PDUs to be (re)transmitted successfully,
263  // i.e., how long it takes for the TX and reTX queues to deplete.
264 
265  // Estimating correctly this effect would require a complex stateful
266  // model (e.g., a Markov chain model) so to avoid the hassle we just
267  // use a margin here which we empirically determine as something we
268  // think reasonable based on the PDU loss rate
269  Time margin;
270  if (m_losses < 0.07)
271  {
272  margin = Seconds (0.500);
273  }
274  else if (m_losses < 0.20)
275  {
276  margin = Seconds (1);
277  }
278  else if (m_losses < 0.50)
279  {
280  margin = Seconds (2);
281  }
282  else if (m_losses < 0.70)
283  {
284  margin = Seconds (10);
285  }
286  else if (m_losses < 0.91)
287  {
288  margin = Seconds (20);
289  }
290  else // 0.95
291  {
292  margin = Seconds (30);
293  }
294  Time stopTime = Seconds (std::max (sduStartTimeSeconds + totBytes/throughput, sduStopTimeSeconds)) + margin;
295 
296  NS_LOG_INFO ("statusFrequency=" << statusFrequency << ", maxDlThroughput=" << maxDlThroughput << ", maxRetxThroughput=" << maxRetxThroughput << ", totBytes=" << totBytes << ", stopTime=" << stopTime.GetSeconds () << "s");
297 
298  Simulator::Stop (stopTime);
299  Simulator::Run ();
300 
301  uint32_t txEnbRrcPdus = lteSimpleHelper->m_enbRrc->GetTxPdus ();
302  uint32_t rxUeRrcPdus = lteSimpleHelper->m_ueRrc->GetRxPdus ();
303 
304  uint32_t txEnbRlcPdus = lteSimpleHelper->m_enbMac->GetTxPdus ();
305  uint32_t rxUeRlcPdus = lteSimpleHelper->m_ueMac->GetRxPdus ();
306 
307  NS_LOG_INFO ("Run = " << m_run);
308  NS_LOG_INFO ("Loss rate (%) = " << uint32_t (m_losses * 100));
309 
310 
311  NS_LOG_INFO ("RLC PDUs TX: " << txEnbRlcPdus
312  << " RX: " << rxUeRlcPdus
313  << " LOST: " << m_dlDrops
314  << " (" << (100.0 * (double) m_dlDrops)/txEnbRlcPdus << "%)");
315 
316  NS_TEST_ASSERT_MSG_EQ (txEnbRlcPdus, rxUeRlcPdus + m_dlDrops, "lost RLC PDUs don't match TX + RX");
317 
318  NS_LOG_INFO ("eNB tx RRC count = " << txEnbRrcPdus);
319  NS_LOG_INFO ("UE rx RRC count = " << rxUeRrcPdus);
320 
321 
322  NS_TEST_ASSERT_MSG_EQ (txEnbRrcPdus, rxUeRrcPdus,
323  "TX PDUs (" << txEnbRrcPdus << ") != RX PDUs (" << rxUeRrcPdus << ")");
324 
325  Simulator::Destroy ();
326 }
Ptr< LteTestRrc > m_enbRrc
ENB RRC.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
Hold variables of type string.
Definition: string.h:41
Test suite for RlcAmE2e test case.
#define min(a, b)
Definition: 80211b.c:42
A suite of tests to run.
Definition: test.h:1343
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:379
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
bool m_bulkSduArrival
bulk SDU arrival
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1286
Ptr< LteTestRrc > m_ueRrc
UE RRC.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
void SetTxOpportunityMode(uint8_t mode)
Set transmit opportunity mode.
Ptr< LteTestMac > m_ueMac
UE MAC.
encapsulates test code
Definition: test.h:1153
Test cases used for the test suite lte-rlc-am-e2e.
Ptr< LteTestMac > m_enbMac
ENB MAC.
double m_losses
error rate
#define max(a, b)
Definition: 80211b.c:43
AttributeValue implementation for Time.
Definition: nstime.h:1342
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
Hold an unsigned integer type.
Definition: uinteger.h:44
#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:166
uint32_t m_ulDrops
number of UL drops
holds a vector of ns3::NetDevice pointers
NetDeviceContainer InstallEnbDevice(NodeContainer c)
create a set of eNB devices
Time stopTime
uint32_t GetRxPdus(void)
Get the receive PDUs.
void SetTxOppTime(Time txOppTime)
Set transmit opportunity time.
TestDuration
How long the test takes to execute.
Definition: test.h:1157
uint32_t GetTxPdus(void)
Get the transmit PDUs.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
Hold objects of type Ptr<T>.
Definition: pointer.h:36
NetDeviceContainer InstallUeDevice(NodeContainer c)
create a set of UE devices
uint32_t m_run
rng run
static LteRlcAmE2eTestSuite lteRlcAmE2eTestSuite
void SetTxOppSize(uint32_t txOppSize)
Set transmit opportunity time.
void SetGlobal(std::string name, const AttributeValue &value)
Definition: config.cc:889
virtual void DoRun(void)
Implementation to actually run this TestCase.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1278
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:849
void DlDropEvent(Ptr< const Packet > p)
DL drop event.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
Definition: error-model.cc:222
This class can be used to hold variables of floating point type such as &#39;double&#39; or &#39;float&#39;...
Definition: double.h:41
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:185
void UlDropEvent(Ptr< const Packet > p)
UL drop event.
uint32_t m_dlDrops
number of Dl drops
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1642