A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
epc-test-s1u-uplink.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007,2008,2009 INRIA, UDCAST
4  * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * The original version of UdpClient is by Amine Ismail
20  * <amine.ismail@sophia.inria.fr> <amine.ismail@udcast.com>
21  * The rest of the code (including modifying UdpClient into
22  * LteRadioBearerTagUdpClient) is by Nicola Baldo <nbaldo@cttc.es>
23  */
24 
25 
26 
27 #include "ns3/simulator.h"
28 #include "ns3/log.h"
29 #include "ns3/test.h"
30 #include "ns3/epc-helper.h"
31 #include "ns3/packet-sink-helper.h"
32 #include "ns3/point-to-point-helper.h"
33 #include "ns3/csma-helper.h"
34 #include "ns3/internet-stack-helper.h"
35 #include "ns3/ipv4-address-helper.h"
36 #include "ns3/inet-socket-address.h"
37 #include "ns3/packet-sink.h"
38 #include <ns3/ipv4-static-routing-helper.h>
39 #include <ns3/ipv4-static-routing.h>
40 #include <ns3/ipv4-interface.h>
41 #include <ns3/mac48-address.h>
42 #include "ns3/seq-ts-header.h"
43 #include "ns3/lte-radio-bearer-tag.h"
44 #include "ns3/arp-cache.h"
45 #include "ns3/boolean.h"
46 #include "ns3/uinteger.h"
47 #include "ns3/config.h"
48 
49 namespace ns3 {
50 
51 
52 
53 NS_LOG_COMPONENT_DEFINE ("EpcTestS1uUplink");
54 
55 /*
56  * A Udp client. Sends UDP packet carrying sequence number and time
57  * stamp but also including the LteRadioBearerTag. This tag is normally
58  * generated by the LteEnbNetDevice when forwarding packet in the
59  * uplink. But in this test we don't have the LteEnbNetDevice, because
60  * we test the S1-U interface with simpler devices to make sure it
61  * just works.
62  *
63  */
65 {
66 public:
67  static TypeId
68  GetTypeId (void);
69 
71  LteRadioBearerTagUdpClient (uint16_t rnti, uint8_t lcid);
72 
73  virtual ~LteRadioBearerTagUdpClient ();
74 
80  void SetRemote (Ipv4Address ip, uint16_t port);
81 
82 protected:
83  virtual void DoDispose (void);
84 
85 private:
86 
87  virtual void StartApplication (void);
88  virtual void StopApplication (void);
89 
90  void ScheduleTransmit (Time dt);
91  void Send (void);
92 
93  uint32_t m_count;
95  uint32_t m_size;
96 
97  uint32_t m_sent;
100  uint16_t m_peerPort;
102 
103  uint16_t m_rnti;
104  uint8_t m_lcid;
105 
106 };
107 
108 
109 
110 TypeId
112 {
113  static TypeId tid = TypeId ("ns3::LteRadioBearerTagUdpClient")
115  .AddConstructor<LteRadioBearerTagUdpClient> ()
116  .AddAttribute ("MaxPackets",
117  "The maximum number of packets the application will send",
118  UintegerValue (100),
119  MakeUintegerAccessor (&LteRadioBearerTagUdpClient::m_count),
120  MakeUintegerChecker<uint32_t> ())
121  .AddAttribute ("Interval",
122  "The time to wait between packets", TimeValue (Seconds (1.0)),
123  MakeTimeAccessor (&LteRadioBearerTagUdpClient::m_interval),
124  MakeTimeChecker ())
125  .AddAttribute (
126  "RemoteAddress",
127  "The destination Ipv4Address of the outbound packets",
128  Ipv4AddressValue (),
129  MakeIpv4AddressAccessor (&LteRadioBearerTagUdpClient::m_peerAddress),
130  MakeIpv4AddressChecker ())
131  .AddAttribute ("RemotePort", "The destination port of the outbound packets",
132  UintegerValue (100),
133  MakeUintegerAccessor (&LteRadioBearerTagUdpClient::m_peerPort),
134  MakeUintegerChecker<uint16_t> ())
135  .AddAttribute ("PacketSize",
136  "Size of packets generated. The minimum packet size is 12 bytes which is the size of the header carrying the sequence number and the time stamp.",
137  UintegerValue (1024),
138  MakeUintegerAccessor (&LteRadioBearerTagUdpClient::m_size),
139  MakeUintegerChecker<uint32_t> ())
140  ;
141  return tid;
142 }
143 
145  : m_rnti (0),
146  m_lcid (0)
147 {
149  m_sent = 0;
150  m_socket = 0;
151  m_sendEvent = EventId ();
152 }
153 
155  : m_rnti (rnti),
156  m_lcid (lcid)
157 {
159  m_sent = 0;
160  m_socket = 0;
161  m_sendEvent = EventId ();
162 }
163 
165 {
167 }
168 
169 void
171 {
172  m_peerAddress = ip;
173  m_peerPort = port;
174 }
175 
176 void
178 {
181 }
182 
183 void
185 {
187 
188  if (m_socket == 0)
189  {
190  TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
192  m_socket->Bind ();
194  }
195 
198 }
199 
200 void
202 {
205 }
206 
207 void
209 {
212  SeqTsHeader seqTs;
213  seqTs.SetSeq (m_sent);
214  Ptr<Packet> p = Create<Packet> (m_size-(8+4)); // 8+4 : the size of the seqTs header
215  p->AddHeader (seqTs);
216 
218  p->AddPacketTag (tag);
219 
220  if ((m_socket->Send (p)) >= 0)
221  {
222  ++m_sent;
223  NS_LOG_INFO ("TraceDelay TX " << m_size << " bytes to "
224  << m_peerAddress << " Uid: " << p->GetUid ()
225  << " Time: " << (Simulator::Now ()).GetSeconds ());
226 
227  }
228  else
229  {
230  NS_LOG_INFO ("Error while sending " << m_size << " bytes to "
231  << m_peerAddress);
232  }
233 
234  if (m_sent < m_count)
235  {
237  }
238 }
239 
240 
241 
243 {
244  UeUlTestData (uint32_t n, uint32_t s, uint16_t r, uint8_t l);
245 
246  uint32_t numPkts;
247  uint32_t pktSize;
248  uint16_t rnti;
249  uint8_t lcid;
250 
253 };
254 
255  UeUlTestData::UeUlTestData (uint32_t n, uint32_t s, uint16_t r, uint8_t l)
256  : numPkts (n),
257  pktSize (s),
258  rnti (r),
259  lcid (l)
260 {
261 }
262 
264 {
265  std::vector<UeUlTestData> ues;
266 };
267 
268 
270 {
271 public:
272  EpcS1uUlTestCase (std::string name, std::vector<EnbUlTestData> v);
273  virtual ~EpcS1uUlTestCase ();
274 
275 private:
276  virtual void DoRun (void);
277  std::vector<EnbUlTestData> m_enbUlTestData;
278 };
279 
280 
281 EpcS1uUlTestCase::EpcS1uUlTestCase (std::string name, std::vector<EnbUlTestData> v)
282  : TestCase (name),
283  m_enbUlTestData (v)
284 {
285 }
286 
288 {
289 }
290 
291 void
293 {
294  Ptr<EpcHelper> epcHelper = CreateObject<EpcHelper> ();
295  Ptr<Node> pgw = epcHelper->GetPgwNode ();
296 
297  // allow jumbo packets
298  Config::SetDefault ("ns3::CsmaNetDevice::Mtu", UintegerValue (30000));
299  Config::SetDefault ("ns3::PointToPointNetDevice::Mtu", UintegerValue (30000));
300  epcHelper->SetAttribute ("S1uLinkMtu", UintegerValue (30000));
301 
302  // Create a single RemoteHost
303  NodeContainer remoteHostContainer;
304  remoteHostContainer.Create (1);
305  Ptr<Node> remoteHost = remoteHostContainer.Get (0);
306  InternetStackHelper internet;
307  internet.Install (remoteHostContainer);
308 
309  // Create the internet
310  PointToPointHelper p2ph;
311  p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s")));
312  NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost);
313  Ipv4AddressHelper ipv4h;
314  ipv4h.SetBase ("1.0.0.0", "255.0.0.0");
315  Ipv4InterfaceContainer internetNodesIpIfaceContainer = ipv4h.Assign (internetDevices);
316 
317  // setup default gateway for the remote hosts
318  Ipv4StaticRoutingHelper ipv4RoutingHelper;
319  Ptr<Ipv4StaticRouting> remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv4> ());
320 
321  // hardcoded UE addresses for now
322  remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask ("255.255.255.0"), 1);
323 
324 
325 
326  uint16_t udpSinkPort = 1234;
327 
328  NodeContainer enbs;
329 
330  for (std::vector<EnbUlTestData>::iterator enbit = m_enbUlTestData.begin ();
331  enbit < m_enbUlTestData.end ();
332  ++enbit)
333  {
334  Ptr<Node> enb = CreateObject<Node> ();
335  enbs.Add (enb);
336 
337  // we test EPC without LTE, hence we use:
338  // 1) a CSMA network to simulate the cell
339  // 2) a raw socket opened on the CSMA device to simulate the LTE socket
340 
341  NodeContainer ues;
342  ues.Create (enbit->ues.size ());
343 
344  NodeContainer cell;
345  cell.Add (ues);
346  cell.Add (enb);
347 
348  CsmaHelper csmaCell;
349  NetDeviceContainer cellDevices = csmaCell.Install (cell);
350 
351  // the eNB's CSMA NetDevice acting as an LTE NetDevice.
352  Ptr<NetDevice> lteEnbNetDevice = cellDevices.Get (cellDevices.GetN () - 1);
353 
354  // Note that the EpcEnbApplication won't care of the actual NetDevice type
355  epcHelper->AddEnb (enb, lteEnbNetDevice);
356 
357  // we install the IP stack on UEs only
358  InternetStackHelper internet;
359  internet.Install (ues);
360 
361  // assign IP address to UEs, and install applications
362  for (uint32_t u = 0; u < ues.GetN (); ++u)
363  {
364  Ptr<NetDevice> ueLteDevice = cellDevices.Get (u);
365  Ipv4InterfaceContainer ueIpIface = epcHelper->AssignUeIpv4Address (NetDeviceContainer (ueLteDevice));
366 
367  Ptr<Node> ue = ues.Get (u);
368 
369  // disable IP Forwarding on the UE. This is because we use
370  // CSMA broadcast MAC addresses for this test. The problem
371  // won't happen with a LteUeNetDevice.
372  Ptr<Ipv4> ueIpv4 = ue->GetObject<Ipv4> ();
373  ueIpv4->SetAttribute ("IpForward", BooleanValue (false));
374 
375  // tell the UE to route all packets to the GW
376  Ptr<Ipv4StaticRouting> ueStaticRouting = ipv4RoutingHelper.GetStaticRouting (ueIpv4);
377  Ipv4Address gwAddr = epcHelper->GetUeDefaultGatewayAddress ();
378  NS_LOG_INFO ("GW address: " << gwAddr);
379  ueStaticRouting->SetDefaultRoute (gwAddr, 1);
380 
381  // since the UEs in this test use CSMA with IP enabled, and
382  // the eNB uses CSMA but without IP, we fool the UE's ARP
383  // cache into thinking that the IP address of the GW can be
384  // reached by sending a CSMA packet to the broadcast
385  // address, so the eNB will get it.
386  int32_t ueLteIpv4IfIndex = ueIpv4->GetInterfaceForDevice (ueLteDevice);
387  Ptr<Ipv4L3Protocol> ueIpv4L3Protocol = ue->GetObject<Ipv4L3Protocol> ();
388  Ptr<Ipv4Interface> ueLteIpv4Iface = ueIpv4L3Protocol->GetInterface (ueLteIpv4IfIndex);
389  Ptr<ArpCache> ueArpCache = ueLteIpv4Iface->GetArpCache ();
390  ueArpCache->SetAliveTimeout (Seconds (1000));
391  ArpCache::Entry* arpCacheEntry = ueArpCache->Add (gwAddr);
392  arpCacheEntry->MarkWaitReply(0);
393  arpCacheEntry->MarkAlive (Mac48Address::GetBroadcast ());
394 
395 
396  PacketSinkHelper packetSinkHelper ("ns3::UdpSocketFactory",
397  InetSocketAddress (Ipv4Address::GetAny (), udpSinkPort));
398  ApplicationContainer sinkApp = packetSinkHelper.Install (remoteHost);
399  sinkApp.Start (Seconds (1.0));
400  sinkApp.Stop (Seconds (10.0));
401  enbit->ues[u].serverApp = sinkApp.Get (0)->GetObject<PacketSink> ();
402 
403  Time interPacketInterval = Seconds (0.01);
404  Ptr<LteRadioBearerTagUdpClient> client = CreateObject<LteRadioBearerTagUdpClient> (enbit->ues[u].rnti, enbit->ues[u].lcid);
405  client->SetAttribute ("RemoteAddress", Ipv4AddressValue (internetNodesIpIfaceContainer.GetAddress (1)));
406  client->SetAttribute ("RemotePort", UintegerValue (udpSinkPort));
407  client->SetAttribute ("MaxPackets", UintegerValue (enbit->ues[u].numPkts));
408  client->SetAttribute ("Interval", TimeValue (interPacketInterval));
409  client->SetAttribute ("PacketSize", UintegerValue (enbit->ues[u].pktSize));
410  ue->AddApplication (client);
411  ApplicationContainer clientApp;
412  clientApp.Add (client);
413  clientApp.Start (Seconds (2.0));
414  clientApp.Stop (Seconds (10.0));
415  enbit->ues[u].clientApp = client;
416 
417  uint16_t rnti = u+1;
418  uint16_t lcid = 1;
419  epcHelper->ActivateEpsBearer (ueLteDevice, lteEnbNetDevice, EpcTft::Default (), rnti, lcid);
420 
421  // need this since all sinks are installed in the same node
422  ++udpSinkPort;
423  }
424 
425  }
426 
427  Simulator::Run ();
428 
429  for (std::vector<EnbUlTestData>::iterator enbit = m_enbUlTestData.begin ();
430  enbit < m_enbUlTestData.end ();
431  ++enbit)
432  {
433  for (std::vector<UeUlTestData>::iterator ueit = enbit->ues.begin ();
434  ueit < enbit->ues.end ();
435  ++ueit)
436  {
437  NS_TEST_ASSERT_MSG_EQ (ueit->serverApp->GetTotalRx (), (ueit->numPkts) * (ueit->pktSize), "wrong total received bytes");
438  }
439  }
440 
442 }
443 
444 
445 
446 
447 
452 {
453 public:
455 
457 
459  : TestSuite ("epc-s1u-uplink", SYSTEM)
460 {
461  std::vector<EnbUlTestData> v1;
462  EnbUlTestData e1;
463  UeUlTestData f1 (1, 100, 1, 1);
464  e1.ues.push_back (f1);
465  v1.push_back (e1);
466  AddTestCase (new EpcS1uUlTestCase ("1 eNB, 1UE", v1));
467 
468 
469  std::vector<EnbUlTestData> v2;
470  EnbUlTestData e2;
471  UeUlTestData f2_1 (1, 100, 1, 1);
472  e2.ues.push_back (f2_1);
473  UeUlTestData f2_2 (2, 200, 2, 1);
474  e2.ues.push_back (f2_2);
475  v2.push_back (e2);
476  AddTestCase (new EpcS1uUlTestCase ("1 eNB, 2UEs", v2));
477 
478 
479  std::vector<EnbUlTestData> v3;
480  v3.push_back (e1);
481  v3.push_back (e2);
482  AddTestCase (new EpcS1uUlTestCase ("2 eNBs", v3));
483 
484 
485  EnbUlTestData e3;
486  UeUlTestData f3_1 (3, 50, 1, 1);
487  e3.ues.push_back (f3_1);
488  UeUlTestData f3_2 (5, 1472, 2, 1);
489  e3.ues.push_back (f3_2);
490  UeUlTestData f3_3 (1, 1, 3, 1);
491  e3.ues.push_back (f3_2);
492  std::vector<EnbUlTestData> v4;
493  v4.push_back (e3);
494  v4.push_back (e1);
495  v4.push_back (e2);
496  AddTestCase (new EpcS1uUlTestCase ("3 eNBs", v4));
497 
498  std::vector<EnbUlTestData> v5;
499  EnbUlTestData e5;
500  UeUlTestData f5 (10, 3000, 1, 1);
501  e5.ues.push_back (f5);
502  v5.push_back (e5);
503  AddTestCase (new EpcS1uUlTestCase ("1 eNB, 10 pkts 3000 bytes each", v5));
504 
505  std::vector<EnbUlTestData> v6;
506  EnbUlTestData e6;
507  UeUlTestData f6 (50, 3000, 1, 1);
508  e6.ues.push_back (f6);
509  v6.push_back (e6);
510  AddTestCase (new EpcS1uUlTestCase ("1 eNB, 50 pkts 3000 bytes each", v6));
511 
512  std::vector<EnbUlTestData> v7;
513  EnbUlTestData e7;
514  UeUlTestData f7 (10, 15000, 1, 1);
515  e7.ues.push_back (f7);
516  v7.push_back (e7);
517  AddTestCase (new EpcS1uUlTestCase ("1 eNB, 10 pkts 15000 bytes each", v7));
518 
519  std::vector<EnbUlTestData> v8;
520  EnbUlTestData e8;
521  UeUlTestData f8 (100, 15000, 1, 1);
522  e8.ues.push_back (f8);
523  v8.push_back (e8);
524  AddTestCase (new EpcS1uUlTestCase ("1 eNB, 100 pkts 15000 bytes each", v8));
525 
526 }
527 
528 
529 
530 } // namespace ns3
531