A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
epc-test-s1u-downlink.cc
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/epc-enb-application.h"
28 #include "ns3/packet-sink-helper.h"
29 #include "ns3/udp-echo-helper.h"
30 #include "ns3/point-to-point-helper.h"
31 #include "ns3/csma-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/config.h"
41 #include "ns3/eps-bearer.h"
42 #include "lte-test-entities.h"
43 
44 namespace ns3 {
45 
46 
47 NS_LOG_COMPONENT_DEFINE ("EpcTestS1uDownlink");
48 
49 
50 
52 {
53  UeDlTestData (uint32_t n, uint32_t s);
54 
55  uint32_t numPkts;
56  uint32_t pktSize;
57 
58  Ptr<PacketSink> serverApp;
59  Ptr<Application> clientApp;
60 };
61 
62 UeDlTestData::UeDlTestData (uint32_t n, uint32_t s)
63  : numPkts (n),
64  pktSize (s)
65 {
66 }
67 
69 {
70  std::vector<UeDlTestData> ues;
71 };
72 
73 
74 
75 class EpcS1uDlTestCase : public TestCase
76 {
77 public:
78  EpcS1uDlTestCase (std::string name, std::vector<EnbDlTestData> v);
79  virtual ~EpcS1uDlTestCase ();
80 
81 private:
82  virtual void DoRun (void);
83  std::vector<EnbDlTestData> m_enbDlTestData;
84 };
85 
86 
87 EpcS1uDlTestCase::EpcS1uDlTestCase (std::string name, std::vector<EnbDlTestData> v)
88  : TestCase (name),
89  m_enbDlTestData (v)
90 {
91 }
92 
93 EpcS1uDlTestCase::~EpcS1uDlTestCase ()
94 {
95 }
96 
97 void
99 {
100  Ptr<EpcHelper> epcHelper = CreateObject<EpcHelper> ();
101  Ptr<Node> pgw = epcHelper->GetPgwNode ();
102 
103  // allow jumbo packets
104  Config::SetDefault ("ns3::CsmaNetDevice::Mtu", UintegerValue (30000));
105  Config::SetDefault ("ns3::PointToPointNetDevice::Mtu", UintegerValue (30000));
106  epcHelper->SetAttribute ("S1uLinkMtu", UintegerValue (30000));
107 
108  // Create a single RemoteHost
109  NodeContainer remoteHostContainer;
110  remoteHostContainer.Create (1);
111  Ptr<Node> remoteHost = remoteHostContainer.Get (0);
112  InternetStackHelper internet;
113  internet.Install (remoteHostContainer);
114 
115  // Create the internet
116  PointToPointHelper p2ph;
117  p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s")));
118  NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost);
119  Ipv4AddressHelper ipv4h;
120  ipv4h.SetBase ("1.0.0.0", "255.0.0.0");
121  ipv4h.Assign (internetDevices);
122 
123  // setup default gateway for the remote hosts
124  Ipv4StaticRoutingHelper ipv4RoutingHelper;
125  Ptr<Ipv4StaticRouting> remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv4> ());
126 
127  // hardcoded UE addresses for now
128  remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask ("255.255.255.0"), 1);
129 
130 
131 
132 
133  NodeContainer enbs;
134  uint16_t cellIdCounter = 0;
135 
136  for (std::vector<EnbDlTestData>::iterator enbit = m_enbDlTestData.begin ();
137  enbit < m_enbDlTestData.end ();
138  ++enbit)
139  {
140  Ptr<Node> enb = CreateObject<Node> ();
141  enbs.Add (enb);
142 
143  // we test EPC without LTE, hence we use:
144  // 1) a CSMA network to simulate the cell
145  // 2) a raw socket opened on the CSMA device to simulate the LTE socket
146 
147  uint16_t cellId = ++cellIdCounter;
148 
149  NodeContainer ues;
150  ues.Create (enbit->ues.size ());
151 
152  NodeContainer cell;
153  cell.Add (ues);
154  cell.Add (enb);
155 
156  CsmaHelper csmaCell;
157  NetDeviceContainer cellDevices = csmaCell.Install (cell);
158 
159  // the eNB's CSMA NetDevice acting as an LTE NetDevice.
160  Ptr<NetDevice> enbDevice = cellDevices.Get (cellDevices.GetN () - 1);
161 
162  // Note that the EpcEnbApplication won't care of the actual NetDevice type
163  epcHelper->AddEnb (enb, enbDevice, cellId);
164 
165  // Plug test RRC entity
166  Ptr<EpcEnbApplication> enbApp = enb->GetApplication (0)->GetObject<EpcEnbApplication> ();
167  NS_ASSERT_MSG (enbApp != 0, "cannot retrieve EpcEnbApplication");
168  Ptr<EpcTestRrc> rrc = CreateObject<EpcTestRrc> ();
169  rrc->SetS1SapProvider (enbApp->GetS1SapProvider ());
170  enbApp->SetS1SapUser (rrc->GetS1SapUser ());
171 
172  // we install the IP stack on UEs only
173  InternetStackHelper internet;
174  internet.Install (ues);
175 
176  // assign IP address to UEs, and install applications
177  for (uint32_t u = 0; u < ues.GetN (); ++u)
178  {
179  Ptr<NetDevice> ueLteDevice = cellDevices.Get (u);
180  Ipv4InterfaceContainer ueIpIface = epcHelper->AssignUeIpv4Address (NetDeviceContainer (ueLteDevice));
181 
182  Ptr<Node> ue = ues.Get (u);
183 
184  // disable IP Forwarding on the UE. This is because we use
185  // CSMA broadcast MAC addresses for this test. The problem
186  // won't happen with a LteUeNetDevice.
187  ue->GetObject<Ipv4> ()->SetAttribute ("IpForward", BooleanValue (false));
188 
189  uint16_t port = 1234;
190  PacketSinkHelper packetSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), port));
191  ApplicationContainer apps = packetSinkHelper.Install (ue);
192  apps.Start (Seconds (1.0));
193  apps.Stop (Seconds (10.0));
194  enbit->ues[u].serverApp = apps.Get (0)->GetObject<PacketSink> ();
195 
196  Time interPacketInterval = Seconds (0.01);
197  UdpEchoClientHelper client (ueIpIface.GetAddress (0), port);
198  client.SetAttribute ("MaxPackets", UintegerValue (enbit->ues[u].numPkts));
199  client.SetAttribute ("Interval", TimeValue (interPacketInterval));
200  client.SetAttribute ("PacketSize", UintegerValue (enbit->ues[u].pktSize));
201  apps = client.Install (remoteHost);
202  apps.Start (Seconds (2.0));
203  apps.Stop (Seconds (10.0));
204  enbit->ues[u].clientApp = apps.Get (0);
205 
206  uint64_t imsi = u+1;
207  epcHelper->AddUe (ueLteDevice, imsi);
208  epcHelper->ActivateEpsBearer (ueLteDevice, imsi, EpcTft::Default (), EpsBearer (EpsBearer::NGBR_VIDEO_TCP_DEFAULT));
209  enbApp->GetS1SapProvider ()->InitialUeMessage (imsi, (uint16_t) imsi);
210  }
211 
212  }
213 
214  Simulator::Run ();
215 
216  for (std::vector<EnbDlTestData>::iterator enbit = m_enbDlTestData.begin ();
217  enbit < m_enbDlTestData.end ();
218  ++enbit)
219  {
220  for (std::vector<UeDlTestData>::iterator ueit = enbit->ues.begin ();
221  ueit < enbit->ues.end ();
222  ++ueit)
223  {
224  NS_TEST_ASSERT_MSG_EQ (ueit->serverApp->GetTotalRx (), (ueit->numPkts) * (ueit->pktSize), "wrong total received bytes");
225  }
226  }
227 
229 }
230 
231 
232 
233 
234 
239 {
240 public:
242 
243 } g_epcS1uDlTestSuiteInstance;
244 
245 EpcS1uDlTestSuite::EpcS1uDlTestSuite ()
246  : TestSuite ("epc-s1u-downlink", SYSTEM)
247 {
248  std::vector<EnbDlTestData> v1;
249  EnbDlTestData e1;
250  UeDlTestData f1 (1, 100);
251  e1.ues.push_back (f1);
252  v1.push_back (e1);
253  AddTestCase (new EpcS1uDlTestCase ("1 eNB, 1UE", v1), TestCase::QUICK);
254 
255 
256  std::vector<EnbDlTestData> v2;
257  EnbDlTestData e2;
258  UeDlTestData f2_1 (1, 100);
259  e2.ues.push_back (f2_1);
260  UeDlTestData f2_2 (2, 200);
261  e2.ues.push_back (f2_2);
262  v2.push_back (e2);
263  AddTestCase (new EpcS1uDlTestCase ("1 eNB, 2UEs", v2), TestCase::QUICK);
264 
265 
266  std::vector<EnbDlTestData> v3;
267  v3.push_back (e1);
268  v3.push_back (e2);
269  AddTestCase (new EpcS1uDlTestCase ("2 eNBs", v3), TestCase::QUICK);
270 
271 
272  EnbDlTestData e3;
273  UeDlTestData f3_1 (3, 50);
274  e3.ues.push_back (f3_1);
275  UeDlTestData f3_2 (5, 1472);
276  e3.ues.push_back (f3_2);
277  UeDlTestData f3_3 (1, 1);
278  e3.ues.push_back (f3_2);
279  std::vector<EnbDlTestData> v4;
280  v4.push_back (e3);
281  v4.push_back (e1);
282  v4.push_back (e2);
283  AddTestCase (new EpcS1uDlTestCase ("3 eNBs", v4), TestCase::QUICK);
284 
285  std::vector<EnbDlTestData> v5;
286  EnbDlTestData e5;
287  UeDlTestData f5 (10, 3000);
288  e5.ues.push_back (f5);
289  v5.push_back (e5);
290  AddTestCase (new EpcS1uDlTestCase ("1 eNB, 10 pkts 3000 bytes each", v5), TestCase::QUICK);
291 
292  std::vector<EnbDlTestData> v6;
293  EnbDlTestData e6;
294  UeDlTestData f6 (50, 3000);
295  e6.ues.push_back (f6);
296  v6.push_back (e6);
297  AddTestCase (new EpcS1uDlTestCase ("1 eNB, 50 pkts 3000 bytes each", v6), TestCase::QUICK);
298 
299  std::vector<EnbDlTestData> v7;
300  EnbDlTestData e7;
301  UeDlTestData f7 (10, 15000);
302  e7.ues.push_back (f7);
303  v7.push_back (e7);
304  AddTestCase (new EpcS1uDlTestCase ("1 eNB, 10 pkts 15000 bytes each", v7), TestCase::QUICK);
305 
306  std::vector<EnbDlTestData> v8;
307  EnbDlTestData e8;
308  UeDlTestData f8 (100, 15000);
309  e8.ues.push_back (f8);
310  v8.push_back (e8);
311  AddTestCase (new EpcS1uDlTestCase ("1 eNB, 100 pkts 15000 bytes each", v8), TestCase::QUICK);
312 }
313 
314 
315 
316 } // namespace ns3
317 
holds a vector of ns3::Application pointers.
keep track of time unit.
Definition: nstime.h:149
an Inet address class
static Ipv4Address GetAny(void)
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
Hold a bool native type.
Definition: boolean.h:38
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
NetDeviceContainer Install(NodeContainer c)
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:210
A suite of tests to run.
Definition: test.h:962
create an application which sends a udp packet and waits for an echo of this packet ...
static Ptr< EpcTft > Default()
Definition: epc-tft.cc:141
static void Run(void)
Definition: simulator.cc:157
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
aggregate IP/TCP/UDP functionality to existing Nodes.
NetDeviceContainer Install(Ptr< Node > node) const
Definition: csma-helper.cc:215
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
Build a set of PointToPointNetDevice objects.
encapsulates test code
Definition: test.h:834
void SetDeviceAttribute(std::string name, const AttributeValue &value)
uint32_t GetN(void) const
Get the number of Ptr<Node> stored in this container.
uint32_t GetN(void) const
Get the number of Ptr<NetDevice> stored in this container.
Class for representing data rates.
Definition: data-rate.h:71
Ptr< Application > GetApplication(uint32_t index) const
Definition: node.cc:159
hold objects of type ns3::Time
Definition: nstime.h:700
Hold an unsigned integer type.
Definition: uinteger.h:46
holds a vector of ns3::NetDevice pointers
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
static void Destroy(void)
Definition: simulator.cc:121
Access to the Ipv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:75
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:667
keep track of a set of node pointers.
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
virtual void DoRun(void)
Implementation to actually run this test case.
void Install(std::string nodeName) const
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
Definition: test.cc:172
build a set of CsmaNetDevice objects
Definition: csma-helper.h:46
#define NS_ASSERT_MSG(condition, message)
Definition: assert.h:86
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
Definition: nstime.h:586
void Add(NodeContainer other)
Append the contents of another NodeContainer to the end of this container.
Ptr< Ipv4StaticRouting > GetStaticRouting(Ptr< Ipv4 > ipv4) const
Helper class that adds ns3::Ipv4StaticRouting objects.
hold objects of type ns3::DataRate
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
ApplicationContainer Install(NodeContainer c) const
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void SetAttribute(std::string name, const AttributeValue &value)
Receive and consume traffic generated to an IP address and port.
Definition: packet-sink.h:68
Ptr< T > GetObject(void) const
Definition: object.h:332
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const