A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
test-lte-epc-e2e-data.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 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: Nicola Baldo <nbaldo@cttc.es>
19  */
20 
21 
22 
23 #include "ns3/simulator.h"
24 #include "ns3/log.h"
25 #include "ns3/test.h"
26 #include "ns3/lte-helper.h"
27 #include "ns3/epc-helper.h"
28 #include "ns3/packet-sink-helper.h"
29 #include "ns3/udp-client-server-helper.h"
30 #include "ns3/udp-echo-helper.h"
31 #include "ns3/point-to-point-helper.h"
32 #include "ns3/internet-stack-helper.h"
33 #include "ns3/ipv4-address-helper.h"
34 #include "ns3/inet-socket-address.h"
35 #include "ns3/packet-sink.h"
36 #include <ns3/ipv4-static-routing-helper.h>
37 #include <ns3/ipv4-static-routing.h>
38 #include "ns3/boolean.h"
39 #include "ns3/uinteger.h"
40 #include "ns3/double.h"
41 #include "ns3/abort.h"
42 #include "ns3/mobility-helper.h"
43 
44 
45 
46 
47 namespace ns3 {
48 
49 
50 NS_LOG_COMPONENT_DEFINE ("LteEpcE2eData");
51 
52 
53 
55 {
56  BearerTestData (uint32_t n, uint32_t s, double i);
57 
58  uint32_t numPkts;
59  uint32_t pktSize;
61 
64 
67 };
68 
69  BearerTestData::BearerTestData (uint32_t n, uint32_t s, double i)
70  : numPkts (n),
71  pktSize (s),
72  interPacketInterval (Seconds (i))
73 {
74 }
75 
76 struct UeTestData
77 {
78  std::vector<BearerTestData> bearers;
79 };
80 
82 {
83  std::vector<UeTestData> ues;
84 };
85 
86 
88 {
89 public:
90  LteEpcE2eDataTestCase (std::string name, std::vector<EnbTestData> v);
91  virtual ~LteEpcE2eDataTestCase ();
92 
93 private:
94  virtual void DoRun (void);
95  std::vector<EnbTestData> m_enbTestData;
96 };
97 
98 
99 LteEpcE2eDataTestCase::LteEpcE2eDataTestCase (std::string name, std::vector<EnbTestData> v)
100  : TestCase (name),
101  m_enbTestData (v)
102 {
103 }
104 
106 {
107 }
108 
109 void
111 {
112  Config::SetDefault ("ns3::LteSpectrumPhy::PemEnabled", BooleanValue (false));
113  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
114  Ptr<EpcHelper> epcHelper = CreateObject<EpcHelper> ();
115  lteHelper->SetEpcHelper (epcHelper);
116 
117  lteHelper->SetAttribute("PathlossModel",
118  StringValue("ns3::FriisPropagationLossModel"));
119 
120  // allow jumbo frames on the S1-U link
121  epcHelper->SetAttribute ("S1uLinkMtu", UintegerValue (30000));
122 
123  Ptr<Node> pgw = epcHelper->GetPgwNode ();
124 
125  // Create a single RemoteHost
126  NodeContainer remoteHostContainer;
127  remoteHostContainer.Create (1);
128  Ptr<Node> remoteHost = remoteHostContainer.Get (0);
129  InternetStackHelper internet;
130  internet.Install (remoteHostContainer);
131 
132  // Create the internet
133  PointToPointHelper p2ph;
134  p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s")));
135  p2ph.SetDeviceAttribute ("Mtu", UintegerValue (30000)); // jumbo frames here as well
136  p2ph.SetChannelAttribute ("Delay", TimeValue (Seconds (0.010)));
137  NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost);
138  Ipv4AddressHelper ipv4h;
139  ipv4h.SetBase ("1.0.0.0", "255.0.0.0");
140  Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign (internetDevices);
141  Ipv4Address remoteHostAddr = internetIpIfaces.GetAddress (1);
142 
143  // setup default gateway for the remote hosts
144  Ipv4StaticRoutingHelper ipv4RoutingHelper;
145  Ptr<Ipv4StaticRouting> remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv4> ());
146 
147  // hardcoded UE addresses for now
148  remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask ("255.255.255.0"), 1);
149 
150 
151  NodeContainer enbs;
152  enbs.Create (m_enbTestData.size ());
153  MobilityHelper enbMobility;
154  enbMobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
155  enbMobility.SetPositionAllocator ("ns3::GridPositionAllocator",
156  "MinX", DoubleValue (0.0),
157  "MinY", DoubleValue (0.0),
158  "DeltaX", DoubleValue (10000.0),
159  "DeltaY", DoubleValue (10000.0),
160  "GridWidth", UintegerValue (3),
161  "LayoutType", StringValue ("RowFirst"));
162  enbMobility.Install (enbs);
163  NetDeviceContainer enbLteDevs = lteHelper->InstallEnbDevice (enbs);
164  NetDeviceContainer::Iterator enbLteDevIt = enbLteDevs.Begin ();
165 
166  uint16_t ulPort = 1000;
167 
168  for (std::vector<EnbTestData>::iterator enbit = m_enbTestData.begin ();
169  enbit < m_enbTestData.end ();
170  ++enbit, ++enbLteDevIt)
171  {
172  NS_ABORT_IF (enbLteDevIt == enbLteDevs.End ());
173 
174 
175 
176  NodeContainer ues;
177  ues.Create (enbit->ues.size ());
178  Vector enbPosition = (*enbLteDevIt)->GetNode ()->GetObject<MobilityModel> ()->GetPosition ();
179  MobilityHelper ueMobility;
180  ueMobility.SetPositionAllocator ("ns3::UniformDiscPositionAllocator",
181  "X", DoubleValue (enbPosition.x),
182  "Y", DoubleValue (enbPosition.y),
183  "rho", DoubleValue (100.0));
184  ueMobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
185  ueMobility.Install (ues);
186  NetDeviceContainer ueLteDevs = lteHelper->InstallUeDevice (ues);
187  lteHelper->Attach (ueLteDevs, *enbLteDevIt);
188 
189  // we install the IP stack on the UEs
190  InternetStackHelper internet;
191  internet.Install (ues);
192 
193 
194  // assign IP address to UEs, and install applications
195  for (uint32_t u = 0; u < ues.GetN (); ++u)
196  {
197 
198  Ptr<Node> ue = ues.Get (u);
199  Ptr<NetDevice> ueLteDevice = ueLteDevs.Get (u);
200  Ipv4InterfaceContainer ueIpIface = epcHelper->AssignUeIpv4Address (NetDeviceContainer (ueLteDevice));
201  // set the default gateway for the UE
202  Ptr<Ipv4StaticRouting> ueStaticRouting = ipv4RoutingHelper.GetStaticRouting (ue->GetObject<Ipv4> ());
203  ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress (), 1);
204 
205  uint16_t dlPort = 2000;
206  for (uint32_t b = 0; b < enbit->ues.at (u).bearers.size (); ++b)
207  {
208  BearerTestData& bearerTestData = enbit->ues.at (u).bearers.at (b);
209 
210  { // Downlink
211  ++dlPort;
212  PacketSinkHelper packetSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), dlPort));
213  ApplicationContainer apps = packetSinkHelper.Install (ue);
214  apps.Start (Seconds (0.01));
215  bearerTestData.dlServerApp = apps.Get (0)->GetObject<PacketSink> ();
216 
217  UdpEchoClientHelper client (ueIpIface.GetAddress (0), dlPort);
218  client.SetAttribute ("MaxPackets", UintegerValue (bearerTestData.numPkts));
219  client.SetAttribute ("Interval", TimeValue (bearerTestData.interPacketInterval));
220  client.SetAttribute ("PacketSize", UintegerValue (bearerTestData.pktSize));
221  apps = client.Install (remoteHost);
222  apps.Start (Seconds (0.01));
223  bearerTestData.dlClientApp = apps.Get (0);
224  }
225 
226  { // Uplink
227  ++ulPort;
228  PacketSinkHelper packetSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), ulPort));
229  ApplicationContainer apps = packetSinkHelper.Install (remoteHost);
230  apps.Start (Seconds (0.5));
231  bearerTestData.ulServerApp = apps.Get (0)->GetObject<PacketSink> ();
232 
233  UdpEchoClientHelper client (remoteHostAddr, ulPort);
234  client.SetAttribute ("MaxPackets", UintegerValue (bearerTestData.numPkts));
235  client.SetAttribute ("Interval", TimeValue (bearerTestData.interPacketInterval));
236  client.SetAttribute ("PacketSize", UintegerValue (bearerTestData.pktSize));
237  apps = client.Install (ue);
238  apps.Start (Seconds (0.5));
239  bearerTestData.ulClientApp = apps.Get (0);
240  }
241 
243 
244  Ptr<EpcTft> tft = Create<EpcTft> ();
246  dlpf.localPortStart = dlPort;
247  dlpf.localPortEnd = dlPort;
248  tft->Add (dlpf);
250  ulpf.remotePortStart = ulPort;
251  ulpf.remotePortEnd = ulPort;
252  tft->Add (ulpf);
253 
254  lteHelper->ActivateEpsBearer (ueLteDevice, epsBearer, tft);
255  }
256  }
257 
258  }
259 
260  Config::Set ("/NodeList/*/DeviceList/*/LteEnbRrc/UeMap/*/RadioBearerMap/*/LteRlc/MaxTxBufferSize",
261  UintegerValue (2 * 1024 * 1024));
262  Config::Set ("/NodeList/*/DeviceList/*/LteUeRrc/RadioBearerMap/*/LteRlc/MaxTxBufferSize",
263  UintegerValue (2 * 1024 * 1024));
264 
265  lteHelper->EnableRlcTraces ();
266  lteHelper->EnablePdcpTraces ();
267  Time simulationTime = Seconds (2.0);
268  lteHelper->GetPdcpStats ()->SetAttribute ("EpochDuration", TimeValue (simulationTime));
269 
270 
271  Simulator::Stop (simulationTime);
272  Simulator::Run ();
273 
274  static uint64_t imsiCounter = 0;
275 
276  for (std::vector<EnbTestData>::iterator enbit = m_enbTestData.begin ();
277  enbit < m_enbTestData.end ();
278  ++enbit)
279  {
280  for (std::vector<UeTestData>::iterator ueit = enbit->ues.begin ();
281  ueit < enbit->ues.end ();
282  ++ueit)
283  {
284  uint64_t imsi = ++imsiCounter;
285  for (uint32_t b = 0; b < ueit->bearers.size (); ++b)
286  {
287  uint8_t lcid = b+1;
288  NS_TEST_ASSERT_MSG_EQ (lteHelper->GetPdcpStats ()->GetDlTxPackets (imsi, lcid),
289  ueit->bearers.at (b).numPkts,
290  "wrong TX PDCP packets in downlink for IMSI=" << imsi << " LCID=" << (uint16_t) lcid);
291  NS_TEST_ASSERT_MSG_EQ (lteHelper->GetPdcpStats ()->GetDlRxPackets (imsi, lcid),
292  ueit->bearers.at (b).numPkts,
293  "wrong RX PDCP packets in downlink for IMSI=" << imsi << " LCID=" << (uint16_t) lcid);
294  NS_TEST_ASSERT_MSG_EQ (lteHelper->GetPdcpStats ()->GetUlTxPackets (imsi, lcid),
295  ueit->bearers.at (b).numPkts,
296  "wrong TX PDCP packets in uplink for IMSI=" << imsi << " LCID=" << (uint16_t) lcid);
297  NS_TEST_ASSERT_MSG_EQ (lteHelper->GetPdcpStats ()->GetUlRxPackets (imsi, lcid),
298  ueit->bearers.at (b).numPkts,
299  "wrong RX PDCP packets in uplink for IMSI=" << imsi << " LCID=" << (uint16_t) lcid);
300 
301  NS_TEST_ASSERT_MSG_EQ (ueit->bearers.at (b).dlServerApp->GetTotalRx (),
302  (ueit->bearers.at (b).numPkts) * (ueit->bearers.at (b).pktSize),
303  "wrong total received bytes in downlink");
304  NS_TEST_ASSERT_MSG_EQ (ueit->bearers.at (b).ulServerApp->GetTotalRx (),
305  (ueit->bearers.at (b).numPkts) * (ueit->bearers.at (b).pktSize),
306  "wrong total received bytes in uplink");
307  }
308  }
309  }
310 
312 }
313 
314 
315 
316 
317 
322 {
323 public:
325 
327 
329  : TestSuite ("lte-epc-e2e-data", SYSTEM)
330 {
331  std::vector<EnbTestData> v1;
332  EnbTestData e1;
333  UeTestData u1;
334  BearerTestData f1 (1, 100, 0.01);
335  u1.bearers.push_back (f1);
336  e1.ues.push_back (u1);
337  v1.push_back (e1);
338  AddTestCase (new LteEpcE2eDataTestCase ("1 eNB, 1UE", v1));
339 
340  std::vector<EnbTestData> v2;
341  EnbTestData e2;
342  UeTestData u2_1;
343  BearerTestData f2_1 (1, 100, 0.01);
344  u2_1.bearers.push_back (f2_1);
345  e2.ues.push_back (u2_1);
346  UeTestData u2_2;
347  BearerTestData f2_2 (2, 200, 0.01);
348  u2_2.bearers.push_back (f2_2);
349  e2.ues.push_back (u2_2);
350  v2.push_back (e2);
351  AddTestCase (new LteEpcE2eDataTestCase ("1 eNB, 2UEs", v2));
352 
353  std::vector<EnbTestData> v3;
354  v3.push_back (e1);
355  v3.push_back (e2);
356  AddTestCase (new LteEpcE2eDataTestCase ("2 eNBs", v3));
357 
358  EnbTestData e4;
359  UeTestData u4_1;
360  BearerTestData f4_1 (3, 50, 0.01);
361  u4_1.bearers.push_back (f4_1);
362  e4.ues.push_back (u4_1);
363  UeTestData u4_2;
364  BearerTestData f4_2 (5, 1400, 0.01);
365  u4_2.bearers.push_back (f4_2);
366  e4.ues.push_back (u4_2);
367  UeTestData u4_3;
368  BearerTestData f4_3 (1, 12, 0.01);
369  u4_3.bearers.push_back (f4_3);
370  e4.ues.push_back (u4_3);
371  std::vector<EnbTestData> v4;
372  v4.push_back (e4);
373  v4.push_back (e1);
374  v4.push_back (e2);
375  AddTestCase (new LteEpcE2eDataTestCase ("3 eNBs", v4));
376 
377  EnbTestData e5;
378  UeTestData u5;
379  BearerTestData f5 (5, 1000, 0.01);
380  u5.bearers.push_back (f5);
381  e5.ues.push_back (u5);
382  std::vector<EnbTestData> v5;
383  v5.push_back (e5);
384  AddTestCase (new LteEpcE2eDataTestCase ("1 eNB, 1UE with 1000 byte packets", v5));
385 
386 
387  EnbTestData e6;
388  UeTestData u6;
389  BearerTestData f6 (5, 1400, 0.01);
390  u6.bearers.push_back (f6);
391  e6.ues.push_back (u6);
392  std::vector<EnbTestData> v6;
393  v6.push_back (e6);
394  AddTestCase (new LteEpcE2eDataTestCase ("1 eNB, 1UE with 1400 byte packets", v6));
395 
396  EnbTestData e7;
397  UeTestData u7;
398  BearerTestData f7_1 (1, 1400, 0.01);
399  u7.bearers.push_back (f7_1);
400  BearerTestData f7_2 (1, 100, 0.01);
401  u7.bearers.push_back (f7_2);
402  e7.ues.push_back (u7);
403  std::vector<EnbTestData> v7;
404  v7.push_back (e7);
405  AddTestCase (new LteEpcE2eDataTestCase ("1 eNB, 1UE with 2 bearers", v7));
406 
407  EnbTestData e8;
408  UeTestData u8;
409  BearerTestData f8 (100, 15000, 0.001);
410  u8.bearers.push_back (f8);
411  e8.ues.push_back (u8);
412  std::vector<EnbTestData> v8;
413  v8.push_back (e8);
414  AddTestCase (new LteEpcE2eDataTestCase ("1 eNB, 1UE with fragmentation", v8));
415 
416 
417  EnbTestData e9;
418  UeTestData u9;
419  BearerTestData f9 (1000, 20, 0.0001);
420  u9.bearers.push_back (f9);
421  e9.ues.push_back (u9);
422  std::vector<EnbTestData> v9;
423  v9.push_back (e9);
424  AddTestCase (new LteEpcE2eDataTestCase ("1 eNB, 1UE with aggregation", v9));
425 
426 
427 }
428 
429 
430 
431 } // namespace ns3
432