A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
epc-test-s1u-downlink.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/epc-helper.h"
27 #include "ns3/packet-sink-helper.h"
28 #include "ns3/udp-echo-helper.h"
29 #include "ns3/point-to-point-helper.h"
30 #include "ns3/csma-helper.h"
31 #include "ns3/internet-stack-helper.h"
32 #include "ns3/ipv4-address-helper.h"
33 #include "ns3/inet-socket-address.h"
34 #include "ns3/packet-sink.h"
35 #include <ns3/ipv4-static-routing-helper.h>
36 #include <ns3/ipv4-static-routing.h>
37 #include "ns3/boolean.h"
38 #include "ns3/uinteger.h"
39 #include "ns3/config.h"
40 
41 
42 
43 namespace ns3 {
44 
45 
46 NS_LOG_COMPONENT_DEFINE ("EpcTestS1uDownlink");
47 
48 
49 
51 {
52  UeDlTestData (uint32_t n, uint32_t s);
53 
54  uint32_t numPkts;
55  uint32_t pktSize;
56 
59 };
60 
61 UeDlTestData::UeDlTestData (uint32_t n, uint32_t s)
62  : numPkts (n),
63  pktSize (s)
64 {
65 }
66 
68 {
69  std::vector<UeDlTestData> ues;
70 };
71 
72 
73 class EpcS1uDlTestCase : public TestCase
74 {
75 public:
76  EpcS1uDlTestCase (std::string name, std::vector<EnbDlTestData> v);
77  virtual ~EpcS1uDlTestCase ();
78 
79 private:
80  virtual void DoRun (void);
81  std::vector<EnbDlTestData> m_enbDlTestData;
82 };
83 
84 
85 EpcS1uDlTestCase::EpcS1uDlTestCase (std::string name, std::vector<EnbDlTestData> v)
86  : TestCase (name),
87  m_enbDlTestData (v)
88 {
89 }
90 
92 {
93 }
94 
95 void
97 {
98  Ptr<EpcHelper> epcHelper = CreateObject<EpcHelper> ();
99  Ptr<Node> pgw = epcHelper->GetPgwNode ();
100 
101  // allow jumbo packets
102  Config::SetDefault ("ns3::CsmaNetDevice::Mtu", UintegerValue (30000));
103  Config::SetDefault ("ns3::PointToPointNetDevice::Mtu", UintegerValue (30000));
104  epcHelper->SetAttribute ("S1uLinkMtu", UintegerValue (30000));
105 
106  // Create a single RemoteHost
107  NodeContainer remoteHostContainer;
108  remoteHostContainer.Create (1);
109  Ptr<Node> remoteHost = remoteHostContainer.Get (0);
110  InternetStackHelper internet;
111  internet.Install (remoteHostContainer);
112 
113  // Create the internet
114  PointToPointHelper p2ph;
115  p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s")));
116  NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost);
117  Ipv4AddressHelper ipv4h;
118  ipv4h.SetBase ("1.0.0.0", "255.0.0.0");
119  ipv4h.Assign (internetDevices);
120 
121  // setup default gateway for the remote hosts
122  Ipv4StaticRoutingHelper ipv4RoutingHelper;
123  Ptr<Ipv4StaticRouting> remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv4> ());
124 
125  // hardcoded UE addresses for now
126  remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask ("255.255.255.0"), 1);
127 
128 
129 
130 
131  NodeContainer enbs;
132 
133  for (std::vector<EnbDlTestData>::iterator enbit = m_enbDlTestData.begin ();
134  enbit < m_enbDlTestData.end ();
135  ++enbit)
136  {
137  Ptr<Node> enb = CreateObject<Node> ();
138  enbs.Add (enb);
139 
140  // we test EPC without LTE, hence we use:
141  // 1) a CSMA network to simulate the cell
142  // 2) a raw socket opened on the CSMA device to simulate the LTE socket
143 
144  NodeContainer ues;
145  ues.Create (enbit->ues.size ());
146 
147  NodeContainer cell;
148  cell.Add (ues);
149  cell.Add (enb);
150 
151  CsmaHelper csmaCell;
152  NetDeviceContainer cellDevices = csmaCell.Install (cell);
153 
154  // the eNB's CSMA NetDevice acting as an LTE NetDevice.
155  Ptr<NetDevice> lteEnbNetDevice = cellDevices.Get (cellDevices.GetN () - 1);
156 
157  // Note that the EpcEnbApplication won't care of the actual NetDevice type
158  epcHelper->AddEnb (enb, lteEnbNetDevice);
159 
160  // we install the IP stack on UEs only
161  InternetStackHelper internet;
162  internet.Install (ues);
163 
164  // assign IP address to UEs, and install applications
165  for (uint32_t u = 0; u < ues.GetN (); ++u)
166  {
167  Ptr<NetDevice> ueLteDevice = cellDevices.Get (u);
168  Ipv4InterfaceContainer ueIpIface = epcHelper->AssignUeIpv4Address (NetDeviceContainer (ueLteDevice));
169 
170  Ptr<Node> ue = ues.Get (u);
171 
172  // disable IP Forwarding on the UE. This is because we use
173  // CSMA broadcast MAC addresses for this test. The problem
174  // won't happen with a LteUeNetDevice.
175  ue->GetObject<Ipv4> ()->SetAttribute ("IpForward", BooleanValue (false));
176 
177  uint16_t port = 1234;
178  PacketSinkHelper packetSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), port));
179  ApplicationContainer apps = packetSinkHelper.Install (ue);
180  apps.Start (Seconds (1.0));
181  apps.Stop (Seconds (10.0));
182  enbit->ues[u].serverApp = apps.Get (0)->GetObject<PacketSink> ();
183 
184  Time interPacketInterval = Seconds (0.01);
185  UdpEchoClientHelper client (ueIpIface.GetAddress (0), port);
186  client.SetAttribute ("MaxPackets", UintegerValue (enbit->ues[u].numPkts));
187  client.SetAttribute ("Interval", TimeValue (interPacketInterval));
188  client.SetAttribute ("PacketSize", UintegerValue (enbit->ues[u].pktSize));
189  apps = client.Install (remoteHost);
190  apps.Start (Seconds (2.0));
191  apps.Stop (Seconds (10.0));
192  enbit->ues[u].clientApp = apps.Get (0);
193 
194  uint16_t rnti = u+1;
195  uint16_t lcid = 1;
196  epcHelper->ActivateEpsBearer (ueLteDevice, lteEnbNetDevice, EpcTft::Default (), rnti, lcid);
197 
198  }
199 
200  }
201 
202  Simulator::Run ();
203 
204  for (std::vector<EnbDlTestData>::iterator enbit = m_enbDlTestData.begin ();
205  enbit < m_enbDlTestData.end ();
206  ++enbit)
207  {
208  for (std::vector<UeDlTestData>::iterator ueit = enbit->ues.begin ();
209  ueit < enbit->ues.end ();
210  ++ueit)
211  {
212  NS_TEST_ASSERT_MSG_EQ (ueit->serverApp->GetTotalRx (), (ueit->numPkts) * (ueit->pktSize), "wrong total received bytes");
213  }
214  }
215 
217 }
218 
219 
220 
221 
222 
227 {
228 public:
230 
232 
234  : TestSuite ("epc-s1u-downlink", SYSTEM)
235 {
236  std::vector<EnbDlTestData> v1;
237  EnbDlTestData e1;
238  UeDlTestData f1 (1, 100);
239  e1.ues.push_back (f1);
240  v1.push_back (e1);
241  AddTestCase (new EpcS1uDlTestCase ("1 eNB, 1UE", v1));
242 
243 
244  std::vector<EnbDlTestData> v2;
245  EnbDlTestData e2;
246  UeDlTestData f2_1 (1, 100);
247  e2.ues.push_back (f2_1);
248  UeDlTestData f2_2 (2, 200);
249  e2.ues.push_back (f2_2);
250  v2.push_back (e2);
251  AddTestCase (new EpcS1uDlTestCase ("1 eNB, 2UEs", v2));
252 
253 
254  std::vector<EnbDlTestData> v3;
255  v3.push_back (e1);
256  v3.push_back (e2);
257  AddTestCase (new EpcS1uDlTestCase ("2 eNBs", v3));
258 
259 
260  EnbDlTestData e3;
261  UeDlTestData f3_1 (3, 50);
262  e3.ues.push_back (f3_1);
263  UeDlTestData f3_2 (5, 1472);
264  e3.ues.push_back (f3_2);
265  UeDlTestData f3_3 (1, 1);
266  e3.ues.push_back (f3_2);
267  std::vector<EnbDlTestData> v4;
268  v4.push_back (e3);
269  v4.push_back (e1);
270  v4.push_back (e2);
271  AddTestCase (new EpcS1uDlTestCase ("3 eNBs", v4));
272 
273  std::vector<EnbDlTestData> v5;
274  EnbDlTestData e5;
275  UeDlTestData f5 (10, 3000);
276  e5.ues.push_back (f5);
277  v5.push_back (e5);
278  AddTestCase (new EpcS1uDlTestCase ("1 eNB, 10 pkts 3000 bytes each", v5));
279 
280  std::vector<EnbDlTestData> v6;
281  EnbDlTestData e6;
282  UeDlTestData f6 (50, 3000);
283  e6.ues.push_back (f6);
284  v6.push_back (e6);
285  AddTestCase (new EpcS1uDlTestCase ("1 eNB, 50 pkts 3000 bytes each", v6));
286 
287  std::vector<EnbDlTestData> v7;
288  EnbDlTestData e7;
289  UeDlTestData f7 (10, 15000);
290  e7.ues.push_back (f7);
291  v7.push_back (e7);
292  AddTestCase (new EpcS1uDlTestCase ("1 eNB, 10 pkts 15000 bytes each", v7));
293 
294  std::vector<EnbDlTestData> v8;
295  EnbDlTestData e8;
296  UeDlTestData f8 (100, 15000);
297  e8.ues.push_back (f8);
298  v8.push_back (e8);
299  AddTestCase (new EpcS1uDlTestCase ("1 eNB, 100 pkts 15000 bytes each", v8));
300 }
301 
302 
303 
304 } // namespace ns3
305