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/point-to-point-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 
51 
53 {
54  UeDlTestData (uint32_t n, uint32_t s);
55 
56  uint32_t numPkts;
57  uint32_t pktSize;
58 
61 };
62 
63 UeDlTestData::UeDlTestData (uint32_t n, uint32_t s)
64  : numPkts (n),
65  pktSize (s)
66 {
67 }
68 
70 {
71  std::vector<UeDlTestData> ues;
72 };
73 
74 
75 
76 class EpcS1uDlTestCase : public TestCase
77 {
78 public:
79  EpcS1uDlTestCase (std::string name, std::vector<EnbDlTestData> v);
80  virtual ~EpcS1uDlTestCase ();
81 
82 private:
83  virtual void DoRun (void);
84  std::vector<EnbDlTestData> m_enbDlTestData;
85 };
86 
87 
88 EpcS1uDlTestCase::EpcS1uDlTestCase (std::string name, std::vector<EnbDlTestData> v)
89  : TestCase (name),
90  m_enbDlTestData (v)
91 {
92 }
93 
95 {
96 }
97 
98 void
100 {
101  Ptr<PointToPointEpcHelper> epcHelper = CreateObject<PointToPointEpcHelper> ();
102  Ptr<Node> pgw = epcHelper->GetPgwNode ();
103 
104  // allow jumbo packets
105  Config::SetDefault ("ns3::CsmaNetDevice::Mtu", UintegerValue (30000));
106  Config::SetDefault ("ns3::PointToPointNetDevice::Mtu", UintegerValue (30000));
107  epcHelper->SetAttribute ("S1uLinkMtu", UintegerValue (30000));
108 
109  // Create a single RemoteHost
110  NodeContainer remoteHostContainer;
111  remoteHostContainer.Create (1);
112  Ptr<Node> remoteHost = remoteHostContainer.Get (0);
113  InternetStackHelper internet;
114  internet.Install (remoteHostContainer);
115 
116  // Create the internet
117  PointToPointHelper p2ph;
118  p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s")));
119  NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost);
120  Ipv4AddressHelper ipv4h;
121  ipv4h.SetBase ("1.0.0.0", "255.0.0.0");
122  ipv4h.Assign (internetDevices);
123 
124  // setup default gateway for the remote hosts
125  Ipv4StaticRoutingHelper ipv4RoutingHelper;
126  Ptr<Ipv4StaticRouting> remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv4> ());
127 
128  // hardcoded UE addresses for now
129  remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask ("255.255.255.0"), 1);
130 
131 
132 
133 
134  NodeContainer enbs;
135  uint16_t cellIdCounter = 0;
136 
137  for (std::vector<EnbDlTestData>::iterator enbit = m_enbDlTestData.begin ();
138  enbit < m_enbDlTestData.end ();
139  ++enbit)
140  {
141  Ptr<Node> enb = CreateObject<Node> ();
142  enbs.Add (enb);
143 
144  // we test EPC without LTE, hence we use:
145  // 1) a CSMA network to simulate the cell
146  // 2) a raw socket opened on the CSMA device to simulate the LTE socket
147 
148  uint16_t cellId = ++cellIdCounter;
149 
150  NodeContainer ues;
151  ues.Create (enbit->ues.size ());
152 
153  NodeContainer cell;
154  cell.Add (ues);
155  cell.Add (enb);
156 
157  CsmaHelper csmaCell;
158  NetDeviceContainer cellDevices = csmaCell.Install (cell);
159 
160  // the eNB's CSMA NetDevice acting as an LTE NetDevice.
161  Ptr<NetDevice> enbDevice = cellDevices.Get (cellDevices.GetN () - 1);
162 
163  // Note that the EpcEnbApplication won't care of the actual NetDevice type
164  epcHelper->AddEnb (enb, enbDevice, cellId);
165 
166  // Plug test RRC entity
167  Ptr<EpcEnbApplication> enbApp = enb->GetApplication (0)->GetObject<EpcEnbApplication> ();
168  NS_ASSERT_MSG (enbApp != 0, "cannot retrieve EpcEnbApplication");
169  Ptr<EpcTestRrc> rrc = CreateObject<EpcTestRrc> ();
170  rrc->SetS1SapProvider (enbApp->GetS1SapProvider ());
171  enbApp->SetS1SapUser (rrc->GetS1SapUser ());
172 
173  // we install the IP stack on UEs only
174  InternetStackHelper internet;
175  internet.Install (ues);
176 
177  // assign IP address to UEs, and install applications
178  for (uint32_t u = 0; u < ues.GetN (); ++u)
179  {
180  Ptr<NetDevice> ueLteDevice = cellDevices.Get (u);
181  Ipv4InterfaceContainer ueIpIface = epcHelper->AssignUeIpv4Address (NetDeviceContainer (ueLteDevice));
182 
183  Ptr<Node> ue = ues.Get (u);
184 
185  // disable IP Forwarding on the UE. This is because we use
186  // CSMA broadcast MAC addresses for this test. The problem
187  // won't happen with a LteUeNetDevice.
188  ue->GetObject<Ipv4> ()->SetAttribute ("IpForward", BooleanValue (false));
189 
190  uint16_t port = 1234;
191  PacketSinkHelper packetSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), port));
192  ApplicationContainer apps = packetSinkHelper.Install (ue);
193  apps.Start (Seconds (1.0));
194  apps.Stop (Seconds (10.0));
195  enbit->ues[u].serverApp = apps.Get (0)->GetObject<PacketSink> ();
196 
197  Time interPacketInterval = Seconds (0.01);
198  UdpEchoClientHelper client (ueIpIface.GetAddress (0), port);
199  client.SetAttribute ("MaxPackets", UintegerValue (enbit->ues[u].numPkts));
200  client.SetAttribute ("Interval", TimeValue (interPacketInterval));
201  client.SetAttribute ("PacketSize", UintegerValue (enbit->ues[u].pktSize));
202  apps = client.Install (remoteHost);
203  apps.Start (Seconds (2.0));
204  apps.Stop (Seconds (10.0));
205  enbit->ues[u].clientApp = apps.Get (0);
206 
207  uint64_t imsi = u+1;
208  epcHelper->AddUe (ueLteDevice, imsi);
209  epcHelper->ActivateEpsBearer (ueLteDevice, imsi, EpcTft::Default (), EpsBearer (EpsBearer::NGBR_VIDEO_TCP_DEFAULT));
210  enbApp->GetS1SapProvider ()->InitialUeMessage (imsi, (uint16_t) imsi);
211  }
212 
213  }
214 
215  Simulator::Run ();
216 
217  for (std::vector<EnbDlTestData>::iterator enbit = m_enbDlTestData.begin ();
218  enbit < m_enbDlTestData.end ();
219  ++enbit)
220  {
221  for (std::vector<UeDlTestData>::iterator ueit = enbit->ues.begin ();
222  ueit < enbit->ues.end ();
223  ++ueit)
224  {
225  NS_TEST_ASSERT_MSG_EQ (ueit->serverApp->GetTotalRx (), (ueit->numPkts) * (ueit->pktSize), "wrong total received bytes");
226  }
227  }
228 
230 }
231 
232 
233 
234 
235 
240 {
241 public:
243 
245 
247  : TestSuite ("epc-s1u-downlink", SYSTEM)
248 {
249  std::vector<EnbDlTestData> v1;
250  EnbDlTestData e1;
251  UeDlTestData f1 (1, 100);
252  e1.ues.push_back (f1);
253  v1.push_back (e1);
254  AddTestCase (new EpcS1uDlTestCase ("1 eNB, 1UE", v1), TestCase::QUICK);
255 
256 
257  std::vector<EnbDlTestData> v2;
258  EnbDlTestData e2;
259  UeDlTestData f2_1 (1, 100);
260  e2.ues.push_back (f2_1);
261  UeDlTestData f2_2 (2, 200);
262  e2.ues.push_back (f2_2);
263  v2.push_back (e2);
264  AddTestCase (new EpcS1uDlTestCase ("1 eNB, 2UEs", v2), TestCase::QUICK);
265 
266 
267  std::vector<EnbDlTestData> v3;
268  v3.push_back (e1);
269  v3.push_back (e2);
270  AddTestCase (new EpcS1uDlTestCase ("2 eNBs", v3), TestCase::QUICK);
271 
272 
273  EnbDlTestData e3;
274  UeDlTestData f3_1 (3, 50);
275  e3.ues.push_back (f3_1);
276  UeDlTestData f3_2 (5, 1472);
277  e3.ues.push_back (f3_2);
278  UeDlTestData f3_3 (1, 1);
279  e3.ues.push_back (f3_2);
280  std::vector<EnbDlTestData> v4;
281  v4.push_back (e3);
282  v4.push_back (e1);
283  v4.push_back (e2);
284  AddTestCase (new EpcS1uDlTestCase ("3 eNBs", v4), TestCase::QUICK);
285 
286  std::vector<EnbDlTestData> v5;
287  EnbDlTestData e5;
288  UeDlTestData f5 (10, 3000);
289  e5.ues.push_back (f5);
290  v5.push_back (e5);
291  AddTestCase (new EpcS1uDlTestCase ("1 eNB, 10 pkts 3000 bytes each", v5), TestCase::QUICK);
292 
293  std::vector<EnbDlTestData> v6;
294  EnbDlTestData e6;
295  UeDlTestData f6 (50, 3000);
296  e6.ues.push_back (f6);
297  v6.push_back (e6);
298  AddTestCase (new EpcS1uDlTestCase ("1 eNB, 50 pkts 3000 bytes each", v6), TestCase::QUICK);
299 
300  std::vector<EnbDlTestData> v7;
301  EnbDlTestData e7;
302  UeDlTestData f7 (10, 15000);
303  e7.ues.push_back (f7);
304  v7.push_back (e7);
305  AddTestCase (new EpcS1uDlTestCase ("1 eNB, 10 pkts 15000 bytes each", v7), TestCase::QUICK);
306 
307  std::vector<EnbDlTestData> v8;
308  EnbDlTestData e8;
309  UeDlTestData f8 (100, 15000);
310  e8.ues.push_back (f8);
311  v8.push_back (e8);
312  AddTestCase (new EpcS1uDlTestCase ("1 eNB, 100 pkts 15000 bytes each", v8), TestCase::QUICK);
313 }
314 
315 
316 
317 } // namespace ns3
318 
holds a vector of ns3::Application pointers.
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
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
NS_LOG_COMPONENT_DEFINE("GrantedTimeWindowMpiInterface")
holds a vector of std::pair of Ptr and interface index.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr 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:1025
EpcS1uDlTestCase(std::string name, std::vector< EnbDlTestData > v)
Create an application which sends a UDP packet and waits for an echo of this packet.
static Ptr< EpcTft > Default()
creates a TFT matching any traffic
Definition: epc-tft.cc:142
static void Run(void)
Run the simulation until one of:
Definition: simulator.cc:157
aggregate IP/TCP/UDP functionality to existing Nodes.
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::CsmaChannel with the attributes configured by CsmaHelper::SetChannelAttri...
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:849
void SetDeviceAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each NetDevice created by the helper.
uint16_t port
Definition: dsdv-manet.cc:44
uint32_t GetN(void) const
Get the number of Ptr stored in this container.
uint32_t GetN(void) const
Get the number of Ptr stored in this container.
Class for representing data rates.
Definition: data-rate.h:71
This class contains the specification of EPS Bearers.
Definition: eps-bearer.h:71
Ptr< Application > GetApplication(uint32_t index) const
Definition: node.cc:158
UeDlTestData(uint32_t n, uint32_t s)
hold objects of type ns3::Time
Definition: nstime.h:961
Hold an unsigned integer type.
Definition: uinteger.h:46
Ptr< SampleEmitter > s
holds a vector of ns3::NetDevice pointers
Test that the S1-U interface implementation works correctly.
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
Ptr< PacketSink > serverApp
static void Destroy(void)
Every event scheduled by the Simulator::insertAtDestroy method is invoked.
Definition: simulator.cc:121
Ptr< Application > clientApp
Access to the Ipv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:75
std::vector< UeDlTestData > ues
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 stored in this container at a given index.
virtual void DoRun(void)
Implementation to actually run this TestCase.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
Definition: test.cc:173
build a set of CsmaNetDevice objects
Definition: csma-helper.h:46
#define NS_ASSERT_MSG(condition, message)
Definition: assert.h:86
Fast test.
Definition: test.h:857
ns3::EpcS1uDlTestSuite g_epcS1uDlTestSuiteInstance
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...
This application is installed inside eNBs and provides the bridge functionality for user data plane p...
void Add(NodeContainer other)
Append the contents of another NodeContainer to the end of this container.
Ptr< Ipv4StaticRouting > GetStaticRouting(Ptr< Ipv4 > ipv4) const
Try and find the static routing protocol as either the main routing protocol or in the list of routin...
Helper class that adds ns3::Ipv4StaticRouting objects.
hold objects of type ns3::DataRate
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
ApplicationContainer Install(NodeContainer c) const
Install an ns3::PacketSinkApplication on each node of the input container configured with all the att...
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)
Record an attribute to be set in each Application after it is is created.
Receive and consume traffic generated to an IP address and port.
Definition: packet-sink.h:68
Ptr< T > GetObject(void) const
Definition: object.h:361
std::vector< EnbDlTestData > m_enbDlTestData
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
#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
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const