A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
lte-test-rlc-am-e2e.cc
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 #include "ns3/config-store.h"
34 
35 #include "lte-test-rlc-am-e2e.h"
36 #include "lte-simple-helper.h"
37 #include "lte-test-entities.h"
38 
39 
40 NS_LOG_COMPONENT_DEFINE ("LteRlcAmE2eTest");
41 
42 namespace ns3 {
43 
44 
54  : TestSuite ("lte-rlc-am-e2e", SYSTEM)
55 {
56  // NS_LOG_INFO ("Creating LteRlcAmE2eTestSuite");
57 
58  double losses[] = {0.0, 0.10, 0.25, 0.50, 0.75, 0.90, 0.95};
59  uint32_t seeds[] = {1111, 2222, 3333, 4444, 5555, 6666, 7777, 8888, 9999, 10101};
60 
61  for ( uint32_t l = 0 ; l < (sizeof (losses) / sizeof (double)) ; l++ )
62  {
63  for ( uint32_t s = 0 ; s < (sizeof (seeds) / sizeof (uint32_t)) ; s++ )
64  {
65  std::ostringstream name;
66  name << " Losses = " << losses[l] * 100 << "%. Seed = " << seeds[s];
67  TestCase::TestDuration testDuration;
68  if (l == 1 && s == 0)
69  {
70  testDuration = TestCase::QUICK;
71  }
72  else
73  {
74  testDuration = TestCase::EXTENSIVE;
75  }
76  AddTestCase (new LteRlcAmE2eTestCase (name.str (), seeds[s], losses[l]), testDuration);
77  }
78  }
79 }
80 
81 static LteRlcAmE2eTestSuite lteRlcAmE2eTestSuite;
82 
83 
88 LteRlcAmE2eTestCase::LteRlcAmE2eTestCase (std::string name, uint32_t seed, double losses)
89  : TestCase (name)
90 {
91  // NS_LOG_UNCOND ("Creating LteRlcAmTestingTestCase: " + name);
92 
93  m_seed = seed;
94  m_losses = losses;
95 
96  m_dlDrops = 0;
97  m_ulDrops = 0;
98 }
99 
100 LteRlcAmE2eTestCase::~LteRlcAmE2eTestCase ()
101 {
102 }
103 
104 
105 void
106 LteRlcAmE2eTestCase::DlDropEvent (Ptr<const Packet> p)
107 {
108  // NS_LOG_FUNCTION (this);
109  m_dlDrops++;
110 }
111 
112 void
113 LteRlcAmE2eTestCase::UlDropEvent (Ptr<const Packet> p)
114 {
115  // NS_LOG_FUNCTION (this);
116  m_ulDrops++;
117 }
118 
119 void
121 {
122  uint16_t numberOfNodes = 1;
123 
124  // LogLevel level = (LogLevel) (LOG_LEVEL_ALL | LOG_PREFIX_TIME | LOG_PREFIX_NODE | LOG_PREFIX_FUNC);
125  // LogComponentEnable ("LteRlcAmE2eTest", level);
126  // LogComponentEnable ("ErrorModel", level);
127  // LogComponentEnable ("LteSimpleHelper", level);
128  // LogComponentEnable ("LteSimpleNetDevice", level);
129  // LogComponentEnable ("SimpleNetDevice", level);
130  // LogComponentEnable ("SimpleChannel", level);
131  // LogComponentEnable ("LteTestEntities", level);
132  // LogComponentEnable ("LtePdcp", level);
133  // LogComponentEnable ("LteRlc", level);
134  // LogComponentEnable ("LteRlcUm", level);
135  // LogComponentEnable ("LteRlcAm", level);
136 
137  RngSeedManager::SetSeed (m_seed);
138 
139  Ptr<LteSimpleHelper> lteSimpleHelper = CreateObject<LteSimpleHelper> ();
140  // lteSimpleHelper->EnableLogComponents ();
141  // lteSimpleHelper->EnableTraces ();
142 
143  lteSimpleHelper->SetAttribute ("RlcEntity", StringValue ("RlcAm"));
144 
145  // eNB and UE nodes
146  NodeContainer ueNodes;
147  NodeContainer enbNodes;
148  enbNodes.Create (numberOfNodes);
149  ueNodes.Create (numberOfNodes);
150 
151  // Install LTE Devices to the nodes
152  NetDeviceContainer enbLteDevs = lteSimpleHelper->InstallEnbDevice (enbNodes);
153  NetDeviceContainer ueLteDevs = lteSimpleHelper->InstallUeDevice (ueNodes);
154 
155  // Note: Just one eNB and UE is supported. Everything is done in InstallEnbDevice and InstallUeDevice
156 
157  // Attach one UE per eNodeB
158  // for (uint16_t i = 0; i < numberOfNodes; i++)
159  // {
160  // lteSimpleHelper->Attach (ueLteDevs.Get(i), enbLteDevs.Get(i));
161  // }
162 
163  // lteSimpleHelper->ActivateEpsBearer (ueLteDevs, EpsBearer (EpsBearer::NGBR_VIDEO_TCP_DEFAULT), EpcTft::Default ());
164 
165 
166  // Error models: downlink and uplink
167  Ptr<RateErrorModel> dlEm = CreateObject<RateErrorModel> ();
168  dlEm->SetAttribute ("ErrorRate", DoubleValue (m_losses));
169  dlEm->SetAttribute ("ErrorUnit", StringValue ("ERROR_UNIT_PACKET"));
170 
171 // Ptr<RateErrorModel> ueEm = CreateObjectWithAttributes<RateErrorModel> ("RanVar", StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=1.0]"));
172 // ueEm->SetAttribute ("ErrorRate", DoubleValue (m_losses));
173 // ueEm->SetAttribute ("ErrorUnit", StringValue ("ERROR_UNIT_PACKET"));
174 
175  // The below hooks will cause drops and receptions to be counted
176  ueLteDevs.Get (0)->SetAttribute ("ReceiveErrorModel", PointerValue (dlEm));
177  ueLteDevs.Get (0)->TraceConnectWithoutContext ("PhyRxDrop", MakeCallback (&LteRlcAmE2eTestCase::DlDropEvent, this));
178 // enbLteDevs.Get (0)->SetAttribute ("ReceiveErrorModel", PointerValue (enbEm));
179 // enbLteDevs.Get (0)->TraceConnectWithoutContext ("PhyRxDrop", MakeCallback (&LteRlcAmE2eTestCase::EnbDropEvent, this));
180 
181  // Sending packets from RRC layer
182  lteSimpleHelper->m_enbRrc->SetArrivalTime (Seconds (0.010));
183  lteSimpleHelper->m_enbRrc->SetPduSize (100);
184 
185  // MAC sends transmission opportunities (TxOpp)
186  lteSimpleHelper->m_enbMac->SetTxOppSize (150);
187  lteSimpleHelper->m_enbMac->SetTxOppTime (Seconds (0.005));
188  lteSimpleHelper->m_enbMac->SetTxOpportunityMode (LteTestMac::RANDOM_MODE);
189 
190  // MAC sends transmission opportunities (TxOpp)
191  lteSimpleHelper->m_ueMac->SetTxOppSize (140);
192  lteSimpleHelper->m_ueMac->SetTxOppTime (Seconds (0.015));
193  lteSimpleHelper->m_ueMac->SetTxOpportunityMode (LteTestMac::RANDOM_MODE);
194 
195  // Start/Stop pseudo-application at RRC layer
196  Simulator::Schedule (Seconds (0.100), &LteTestRrc::Start, lteSimpleHelper->m_enbRrc);
197  Simulator::Schedule (Seconds (10.100), &LteTestRrc::Stop, lteSimpleHelper->m_enbRrc);
198 
199 
200  Simulator::Stop (Seconds (100.000));
201  Simulator::Run ();
202 
203  uint32_t txEnbRrcPdus = lteSimpleHelper->m_enbRrc->GetTxPdus ();
204  uint32_t rxUeRrcPdus = lteSimpleHelper->m_ueRrc->GetRxPdus ();
205 
206  // NS_LOG_INFO ("Seed = " << m_seed);
207  // NS_LOG_INFO ("Losses (%) = " << uint32_t (m_losses * 100));
208 
209  // NS_LOG_INFO ("dl dev drops = " << m_dlDrops);
210  // NS_LOG_INFO ("ul dev drops = " << m_ulDrops);
211 
212  // NS_LOG_INFO ("eNB tx RRC count = " << txEnbRrcPdus);
213  // NS_LOG_INFO ("eNB rx RRC count = " << rxEnbRrcPdus);
214  // NS_LOG_INFO ("UE tx RRC count = " << txUeRrcPdus);
215  // NS_LOG_INFO ("UE rx RRC count = " << rxUeRrcPdus);
216 
217  NS_LOG_INFO (m_seed << "\t" << m_losses << "\t" << txEnbRrcPdus << "\t" << rxUeRrcPdus << "\t" << m_dlDrops);
218 
219  NS_TEST_ASSERT_MSG_EQ (txEnbRrcPdus, rxUeRrcPdus,
220  "TX PDUs (" << txEnbRrcPdus << ") != RX PDUs (" << rxUeRrcPdus << ")");
221 
223 }
224 
225 } // namespace ns3
226 
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
hold variables of type string
Definition: string.h:19
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
A suite of tests to run.
Definition: test.h:962
static void Run(void)
Definition: simulator.cc:157
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
#define NS_LOG_INFO(msg)
Definition: log.h:264
encapsulates test code
Definition: test.h:834
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Definition: simulator.h:820
virtual void DoRun(void)
Implementation to actually run this test case.
Fast test.
Definition: test.h:843
holds a vector of ns3::NetDevice pointers
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:502
static void Destroy(void)
Definition: simulator.cc:121
TestDuration
How long the test takes to execute.
Definition: test.h:841
keep track of a set of node pointers.
hold objects of type Ptr<T>
Definition: pointer.h:33
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
Definition: test.cc:172
static void SetSeed(uint32_t seed)
set the seed it will duplicate the seed value 6 times
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
Definition: nstime.h:586
static void Stop(void)
Definition: simulator.cc:164
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Hold an floating point type.
Definition: double.h:41