A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
lte-test-rlc-um-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  */
20 
21 #include "ns3/config.h"
22 #include "ns3/simulator.h"
23 #include "ns3/pointer.h"
24 #include "ns3/log.h"
25 #include "ns3/packet.h"
26 #include "ns3/node-container.h"
27 #include "ns3/net-device-container.h"
28 #include "ns3/error-model.h"
29 #include "ns3/rng-seed-manager.h"
30 #include "ns3/radio-bearer-stats-calculator.h"
31 #include "ns3/lte-rlc-header.h"
32 #include "ns3/lte-rlc-um.h"
33 
34 #include "lte-simple-helper.h"
35 #include "lte-test-entities.h"
36 #include "lte-test-rlc-um-e2e.h"
37 
38 
39 NS_LOG_COMPONENT_DEFINE ("LteRlcUmE2eTest");
40 
41 namespace ns3 {
42 
43 
53  : TestSuite ("lte-rlc-um-e2e", SYSTEM)
54 {
55  // NS_LOG_INFO ("Creating LteRlcUmE2eTestSuite");
56 
57  double losses[] = {0.0, 0.10, 0.25, 0.50, 0.75, 0.90, 1.00};
58  uint32_t seeds[] = {1111, 2222, 3333, 4444, 5555, 6666, 7777, 8888, 9999, 10101};
59 
60  for ( uint32_t l = 0 ; l < (sizeof (losses) / sizeof (double)) ; l++ )
61  {
62  for ( uint32_t s = 0 ; s < (sizeof (seeds) / sizeof (uint32_t)) ; s++ )
63  {
64  std::ostringstream name;
65  name << " Losses = " << losses[l] << "%. Seed = " << seeds[s];
66  TestCase::TestDuration testDuration;
67  if (l == 1 && s == 0)
68  {
69  testDuration = TestCase::QUICK;
70  }
71  else
72  {
73  testDuration = TestCase::EXTENSIVE;
74  }
75  AddTestCase (new LteRlcUmE2eTestCase (name.str (), seeds[s], losses[l]), testDuration);
76  }
77  }
78 }
79 
81 
82 
87 LteRlcUmE2eTestCase::LteRlcUmE2eTestCase (std::string name, uint32_t seed, double losses)
88  : TestCase (name)
89 {
90  // NS_LOG_UNCOND ("Creating LteRlcUmTestingTestCase: " + name);
91 
92  m_seed = seed;
93  m_losses = losses;
94 
95  m_dlDrops = 0;
96  m_ulDrops = 0;
97 }
98 
100 {
101 }
102 
103 
104 void
106 {
107  // NS_LOG_FUNCTION (this);
108  m_dlDrops++;
109 }
110 
111 void
113 {
114  // NS_LOG_FUNCTION (this);
115  m_ulDrops++;
116 }
117 
118 void
120 {
121  uint16_t numberOfNodes = 1;
122 
123  // LogLevel level = (LogLevel) (LOG_LEVEL_ALL | LOG_PREFIX_TIME | LOG_PREFIX_NODE | LOG_PREFIX_FUNC);
124  // LogComponentEnable ("LteRlcUmE2eTest", level);
125  // LogComponentEnable ("ErrorModel", level);
126  // LogComponentEnable ("LteSimpleHelper", level);
127  // LogComponentEnable ("LteSimpleNetDevice", level);
128  // LogComponentEnable ("SimpleNetDevice", level);
129  // LogComponentEnable ("SimpleChannel", level);
130  // LogComponentEnable ("LteTestEntities", level);
131  // LogComponentEnable ("LtePdcp", level);
132  // LogComponentEnable ("LteRlc", level);
133  // LogComponentEnable ("LteRlcUm", level);
134  // LogComponentEnable ("LteRlcAm", level);
135 
137 
138  Ptr<LteSimpleHelper> lteSimpleHelper = CreateObject<LteSimpleHelper> ();
139  // lteSimpleHelper->EnableLogComponents ();
140  // lteSimpleHelper->EnableTraces ();
141 
142  lteSimpleHelper->SetAttribute ("RlcEntity", StringValue ("RlcUm"));
143 
144  // eNB and UE nodes
145  NodeContainer ueNodes;
146  NodeContainer enbNodes;
147  enbNodes.Create (numberOfNodes);
148  ueNodes.Create (numberOfNodes);
149 
150  // Install LTE Devices to the nodes
151  NetDeviceContainer enbLteDevs = lteSimpleHelper->InstallEnbDevice (enbNodes);
152  NetDeviceContainer ueLteDevs = lteSimpleHelper->InstallUeDevice (ueNodes);
153 
154  // Note: Just one eNB and UE are supported. Everything is done in InstallEnbDevice and InstallUeDevice
155 
156  // Attach one UE per eNodeB
157  // for (uint16_t i = 0; i < numberOfNodes; i++)
158  // {
159  // lteSimpleHelper->Attach (ueLteDevs.Get(i), enbLteDevs.Get(i));
160  // }
161 
162  // lteSimpleHelper->ActivateEpsBearer (ueLteDevs, EpsBearer (EpsBearer::NGBR_VIDEO_TCP_DEFAULT), EpcTft::Default ());
163 
164  // Error models: downlink and uplink
165  Ptr<RateErrorModel> dlEm = CreateObject<RateErrorModel> ();
166  dlEm->SetAttribute ("ErrorRate", DoubleValue (m_losses));
167  dlEm->SetAttribute ("ErrorUnit", StringValue ("ERROR_UNIT_PACKET"));
168 
169  Ptr<RateErrorModel> ulEm = CreateObject<RateErrorModel> ();
170  ulEm->SetAttribute ("ErrorRate", DoubleValue (m_losses));
171  ulEm->SetAttribute ("ErrorUnit", StringValue ("ERROR_UNIT_PACKET"));
172 
173  // The below hooks will cause drops to be counted at simple phy layer
174  ueLteDevs.Get (0)->SetAttribute ("ReceiveErrorModel", PointerValue (dlEm));
175  ueLteDevs.Get (0)->TraceConnectWithoutContext ("PhyRxDrop", MakeCallback (&LteRlcUmE2eTestCase::DlDropEvent, this));
176  enbLteDevs.Get (0)->SetAttribute ("ReceiveErrorModel", PointerValue (ulEm));
177  enbLteDevs.Get (0)->TraceConnectWithoutContext ("PhyRxDrop", MakeCallback (&LteRlcUmE2eTestCase::UlDropEvent, this));
178 
179  // Sending packets from eNB RRC layer (eNB -> UE)
180  lteSimpleHelper->m_enbRrc->SetArrivalTime (Seconds (0.010));
181  lteSimpleHelper->m_enbRrc->SetPduSize (100);
182 
183  // MAC sends transmission opportunities (TxOpp)
184  lteSimpleHelper->m_enbMac->SetTxOppSize (150);
185  lteSimpleHelper->m_enbMac->SetTxOppTime (Seconds (0.005));
186  lteSimpleHelper->m_enbMac->SetTxOpportunityMode (LteTestMac::RANDOM_MODE);
187 
188  // Sending packets from UE RRC layer (UE -> eNB)
189  lteSimpleHelper->m_ueRrc->SetArrivalTime (Seconds (0.010));
190  lteSimpleHelper->m_ueRrc->SetPduSize (100);
191 
192  // MAC sends transmission opportunities (TxOpp)
193  lteSimpleHelper->m_ueMac->SetTxOppSize (150);
194  lteSimpleHelper->m_ueMac->SetTxOppTime (Seconds (0.005));
195  lteSimpleHelper->m_ueMac->SetTxOpportunityMode (LteTestMac::RANDOM_MODE);
196 
197  // Start/Stop pseudo-application at eNB RRC
198  Simulator::Schedule (Seconds (0.100), &LteTestRrc::Start, lteSimpleHelper->m_enbRrc);
199  Simulator::Schedule (Seconds (10.100), &LteTestRrc::Stop, lteSimpleHelper->m_enbRrc);
200 
201  // Start/Stop pseudo-application at UE RRC
202  Simulator::Schedule (Seconds (20.100), &LteTestRrc::Start, lteSimpleHelper->m_ueRrc);
203  Simulator::Schedule (Seconds (30.100), &LteTestRrc::Stop, lteSimpleHelper->m_ueRrc);
204 
205 
206  Simulator::Stop (Seconds (31.000));
207  Simulator::Run ();
208 
209  uint32_t txEnbRrcPdus = lteSimpleHelper->m_enbRrc->GetTxPdus ();
210  uint32_t rxUeRrcPdus = lteSimpleHelper->m_ueRrc->GetRxPdus ();
211 
212  uint32_t txUeRrcPdus = lteSimpleHelper->m_ueRrc->GetTxPdus ();
213  uint32_t rxEnbRrcPdus = lteSimpleHelper->m_enbRrc->GetRxPdus ();
214 
215  // NS_LOG_INFO ("Seed = " << m_seed);
216  // NS_LOG_INFO ("Losses (%) = " << uint32_t (m_losses * 100));
217 
218  // NS_LOG_INFO ("dl dev drops = " << m_dlDrops);
219  // NS_LOG_INFO ("ul dev drops = " << m_ulDrops);
220 
221  // NS_LOG_INFO ("eNB tx RRC count = " << txEnbRrcPdus);
222  // NS_LOG_INFO ("eNB rx RRC count = " << rxEnbRrcPdus);
223  // NS_LOG_INFO ("UE tx RRC count = " << txUeRrcPdus);
224  // NS_LOG_INFO ("UE rx RRC count = " << rxUeRrcPdus);
225 
226  NS_LOG_INFO (m_seed << "\t" << m_losses << "\t" << txEnbRrcPdus << "\t" << rxUeRrcPdus << "\t" << m_dlDrops);
227  NS_LOG_INFO (m_seed << "\t" << m_losses << "\t" << txUeRrcPdus << "\t" << rxEnbRrcPdus << "\t" << m_ulDrops);
228 
229  NS_TEST_ASSERT_MSG_EQ (txEnbRrcPdus, rxUeRrcPdus + m_dlDrops,
230  "Downlink: TX PDUs (" << txEnbRrcPdus << ") != RX PDUs (" << rxUeRrcPdus << ") + DROPS (" << m_dlDrops << ")");
231  NS_TEST_ASSERT_MSG_EQ (txUeRrcPdus, rxEnbRrcPdus + m_ulDrops,
232  "Uplink: TX PDUs (" << txUeRrcPdus << ") != RX PDUs (" << rxEnbRrcPdus << ") + DROPS (" << m_ulDrops << ")");
233 
235 }
236 
237 } // namespace ns3
238 
hold variables of type string
Definition: string.h:19
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
A suite of tests to run.
Definition: test.h:1025
static void Run(void)
Run the simulation until one of:
Definition: simulator.cc:157
Test x.x.x RLC UM: End-to-end flow.
#define NS_LOG_INFO(msg)
Definition: log.h:298
encapsulates test code
Definition: test.h:849
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
Definition: simulator.h:824
void UlDropEvent(Ptr< const Packet > p)
LteRlcUmE2eTestSuite()
Test x.x.x RLC UM: End-to-end flow.
Ptr< SampleEmitter > s
void Start()
START.
Medium length test.
Definition: test.h:858
holds a vector of ns3::NetDevice pointers
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1238
static void Destroy(void)
Every event scheduled by the Simulator::insertAtDestroy method is invoked.
Definition: simulator.cc:121
static LteRlcUmE2eTestSuite lteRlcUmE2eTestSuite
TestDuration
How long the test takes to execute.
Definition: test.h:856
keep track of a set of node pointers.
hold objects of type Ptr
Definition: pointer.h:33
void DlDropEvent(Ptr< const Packet > p)
NS_LOG_COMPONENT_DEFINE("LteRlcUmE2eTest")
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
Definition: test.cc:173
static void SetSeed(uint32_t seed)
set the seed it will duplicate the seed value 6 times
Fast test.
Definition: test.h:857
static void Stop(void)
If an event invokes this method, it will be the last event scheduled by the Simulator::run method bef...
Definition: simulator.cc:165
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Hold a floating point type.
Definition: double.h:41
virtual void DoRun(void)
Implementation to actually run this TestCase.
#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:137