A Discrete-Event Network Simulator
API
lte-test-ipv6-routing.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2017 Jadavpur University, India
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: Manoj Kumar Rana <manoj24.rana@gmail.com>
19  */
20 
21 #include "ns3/lte-helper.h"
22 #include "ns3/epc-helper.h"
23 #include "ns3/core-module.h"
24 #include "ns3/network-module.h"
25 #include "ns3/ipv4-global-routing-helper.h"
26 #include "ns3/ipv6-static-routing.h"
27 #include "ns3/internet-module.h"
28 #include "ns3/mobility-module.h"
29 #include "ns3/lte-module.h"
30 #include "ns3/applications-module.h"
31 #include "ns3/point-to-point-helper.h"
32 #include "ns3/config-store.h"
33 #include <algorithm>
34 
35 
36 /* *
37  * Scenario: 3 UEs, 2 ENBs, 1 Remote Host, UE0<-->ENB0, UE1<-->ENB0, UE2<-->ENB1
38  Servers: UE1, UE2, Remote Host
39  Client: UE0 (3 clients)
40  UDP Echo Packets transmitted between client and server
41 
42  * Pass criteria: 1) Every UDP Echo Request and Reply messages sent and received respectively
43  at UE0 must be matched by their UID, source address, destination address,
44  source port and destination port
45  2) Every request reply must follow proper route (e.g. In case of UE0->UE1,
46  packet must travel this route: UE0->ENB0->PGW->ENB1->UE1->ENB1->PGW->ENB0->UE0)
47  3) The above check also ensures no redundancy of the followed route for a packet
48 * */
49 
50 
51 
52 using namespace ns3;
53 
61 {
62 public:
64  virtual ~LteIpv6RoutingTestCase ();
65 
69  void Checker ();
70 
77  void SentAtClient (Ptr<const Packet> p, Ptr<Ipv6> ipv6, uint32_t interface);
78 
85  void ReceivedAtClient (Ptr<const Packet> p, Ptr<Ipv6> ipv6, uint32_t interface);
86 
91  void EnbToPgw (Ptr<Packet> p);
92 
97  void TunToPgw (Ptr<Packet> p);
98 
99 private:
100  virtual void DoRun (void);
103  std::list<uint64_t> m_pgwUidRxFrmEnb;
104  std::list<uint64_t> m_pgwUidRxFrmTun;
105 
106  std::list<Ptr<Packet> > m_clientTxPkts;
107  std::list<Ptr<Packet> > m_clientRxPkts;
108 };
109 
110 
112  : TestCase ("Test IPv6 Routing at LTE")
113 {
114 }
115 
117 {
118 }
119 
121 {
122  Ipv6Header ipv6Header;
123  p->PeekHeader (ipv6Header);
124  if (ipv6Header.GetNextHeader () == UdpL4Protocol::PROT_NUMBER)
125  {
126  m_clientTxPkts.push_back (p->Copy ());
127  }
128 }
129 
131 {
132  Ipv6Header ipv6Header;
133  p->PeekHeader (ipv6Header);
134  if (ipv6Header.GetNextHeader () == UdpL4Protocol::PROT_NUMBER)
135  {
136  m_clientRxPkts.push_back (p->Copy ());
137  }
138 }
139 
141 {
142  Ipv6Header ipv6Header;
143  p->PeekHeader (ipv6Header);
144  if (ipv6Header.GetNextHeader () == UdpL4Protocol::PROT_NUMBER)
145  {
146  m_pgwUidRxFrmEnb.push_back (p->GetUid ());
147  }
148 }
149 
151 {
152  Ipv6Header ipv6Header;
153  p->PeekHeader (ipv6Header);
154  if (ipv6Header.GetNextHeader () == UdpL4Protocol::PROT_NUMBER)
155  {
156  m_pgwUidRxFrmTun.push_back (p->GetUid ());
157  }
158 }
159 
161 {
162  bool b = false;
163  bool check = true;
164  //Extract each received reply packet of the client
165  for (std::list<Ptr<Packet> >::iterator it1 = m_clientRxPkts.begin (); it1 != m_clientRxPkts.end (); it1++)
166  {
167  Ipv6Header ipv6header1;
168  UdpHeader udpHeader1;
169  Ptr<Packet> p1 = (*it1)->Copy ();
170  p1->RemoveHeader (ipv6header1);
171  uint64_t uid = p1->GetUid ();
172  p1->RemoveHeader (udpHeader1);
173  //Search each packet in list of sent request packet of the client
174  for (std::list<Ptr<Packet> >::iterator it2 = m_clientTxPkts.begin (); it2 != m_clientTxPkts.end (); it2++)
175  {
176  Ptr<Packet> p2 = (*it2)->Copy ();
177  Ipv6Header ipv6header2;
178  p2->RemoveHeader (ipv6header2);
179  Ipv6Address sorceAddress = ipv6header2.GetSource ();
180  Ipv6Address destinationAddress = ipv6header2.GetDestination ();
181  UdpHeader udpHeader2;
182  p2->RemoveHeader (udpHeader2);
183  uint16_t sourcePort;
184  uint16_t destinationPort;
185  sourcePort = udpHeader2.GetSourcePort ();
186  destinationPort = udpHeader2.GetDestinationPort ();
187  //Check whether the uids, addresses and ports match
188  if ((p2->GetUid () == p1->GetUid ())
189  && sorceAddress == ipv6header1.GetDestination ()
190  && destinationAddress == ipv6header1.GetSource ()
191  && sourcePort == udpHeader1.GetDestinationPort ()
192  && destinationPort == udpHeader1.GetSourcePort ())
193  {
194  b = true;
195  break;
196  }
197  }
198  check &= b;
199  if (std::find (m_pgwUidRxFrmEnb.begin (), m_pgwUidRxFrmEnb.end (), uid) != m_pgwUidRxFrmEnb.end ())
200  {
201  check &= true;
202  m_pgwUidRxFrmEnb.remove (uid);
203  }
204  if (std::find (m_pgwUidRxFrmTun.begin (), m_pgwUidRxFrmTun.end (), uid) != m_pgwUidRxFrmTun.end ())
205  {
206  check &= true;
207  m_pgwUidRxFrmTun.remove (uid);
208  }
209  b = false;
210  }
211 
212  NS_TEST_ASSERT_MSG_EQ (check, true, "Failure Happens IPv6 routing of LENA");
213  NS_TEST_ASSERT_MSG_EQ (m_clientTxPkts.size (), m_clientRxPkts.size (), "No. of Request and Reply messages mismatch");
214  NS_TEST_ASSERT_MSG_EQ (m_pgwUidRxFrmEnb.size (), 0, "Route is not Redundant in Lte IPv6 test");
215  NS_TEST_ASSERT_MSG_EQ (m_pgwUidRxFrmTun.size (), 0, "Route is not Redundant in Lte IPv6 test");
216 
217 }
218 
219 void
221 {
222  double distance = 60.0;
223 
224  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
225  Ptr<PointToPointEpcHelper> epcHelper = CreateObject<PointToPointEpcHelper> ();
226  lteHelper->SetEpcHelper (epcHelper);
227 
228  ConfigStore inputConfig;
229  inputConfig.ConfigureDefaults ();
230 
231  Ptr<Node> pgw = epcHelper->GetPgwNode ();
232 
233  // Create a single RemoteHost
234  NodeContainer remoteHostContainer;
235  remoteHostContainer.Create (1);
236  Ptr<Node> remoteHost = remoteHostContainer.Get (0);
237  InternetStackHelper internet;
238  internet.Install (remoteHostContainer);
239 
240  // Create the Internet
241  PointToPointHelper p2ph;
242  p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s")));
243  p2ph.SetDeviceAttribute ("Mtu", UintegerValue (1500));
244  p2ph.SetChannelAttribute ("Delay", TimeValue (Seconds (0.010)));
245  NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost);
246 
247  NodeContainer ueNodes;
248  NodeContainer enbNodes;
249  enbNodes.Create (2);
250  ueNodes.Create (3);
251 
252  // Install Mobility Model
253  Ptr<ListPositionAllocator> positionAlloc1 = CreateObject<ListPositionAllocator> ();
254  Ptr<ListPositionAllocator> positionAlloc2 = CreateObject<ListPositionAllocator> ();
255 
256  positionAlloc1->Add (Vector (distance * 0, 0, 0));
257  positionAlloc1->Add (Vector (distance * 0 + 5, 0, 0));
258  positionAlloc1->Add (Vector (distance * 1, 0, 0));
259 
260  positionAlloc2->Add (Vector (distance * 0, 0, 0));
261  positionAlloc2->Add (Vector (distance * 1, 0, 0));
262 
264  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
265  mobility.SetPositionAllocator (positionAlloc1);
266  mobility.Install (ueNodes);
267 
268  mobility.SetPositionAllocator (positionAlloc2);
269  mobility.Install (enbNodes);
270 
271  // Install the IP stack on the UEs
272  internet.Install (ueNodes);
273 
274  // Install LTE Devices to the nodes
275  NetDeviceContainer enbLteDevs = lteHelper->InstallEnbDevice (enbNodes);
276  NetDeviceContainer ueLteDevs = lteHelper->InstallUeDevice (ueNodes);
277 
278  // Assign IP address to UEs, and install applications
279  m_ueIpIface = epcHelper->AssignUeIpv6Address (NetDeviceContainer (ueLteDevs));
280 
281  Ipv6StaticRoutingHelper ipv6RoutingHelper;
282 
283  for (uint32_t u = 0; u < ueNodes.GetN (); ++u)
284  {
285  Ptr<Node> ueNode = ueNodes.Get (u);
286  // Set the default gateway for the UE
287  Ptr<Ipv6StaticRouting> ueStaticRouting = ipv6RoutingHelper.GetStaticRouting (ueNode->GetObject<Ipv6> ());
288  ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress6 (), 1);
289  }
290 
291  // Attach two UEs at first eNodeB and one UE at second eNodeB
292  lteHelper->Attach (ueLteDevs.Get (0), enbLteDevs.Get (0));
293  lteHelper->Attach (ueLteDevs.Get (1), enbLteDevs.Get (0));
294  lteHelper->Attach (ueLteDevs.Get (2), enbLteDevs.Get (1));
295 
296  Ipv6AddressHelper ipv6h;
297  ipv6h.SetBase (Ipv6Address ("6001:db80::"), Ipv6Prefix (64));
298  Ipv6InterfaceContainer internetIpIfaces = ipv6h.Assign (internetDevices);
299 
300  internetIpIfaces.SetForwarding (0, true);
301  internetIpIfaces.SetDefaultRouteInAllNodes (0);
302 
303  Ptr<Ipv6StaticRouting> remoteHostStaticRouting = ipv6RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv6> ());
304  remoteHostStaticRouting->AddNetworkRouteTo ("7777:f00d::", Ipv6Prefix (64), internetIpIfaces.GetAddress (0, 1), 1, 0);
305 
306  // interface 0 is localhost, 1 is the p2p device
307  m_remoteHostAddr = internetIpIfaces.GetAddress (1, 1);
308 
309  // Install and start applications on UEs and remote host
310  UdpEchoServerHelper echoServer1 (10);
311  UdpEchoServerHelper echoServer2 (11);
312  UdpEchoServerHelper echoServer3 (12);
313 
314  ApplicationContainer serverApps = echoServer1.Install (remoteHost);
315  serverApps.Add (echoServer2.Install (ueNodes.Get (1)));
316  serverApps.Add (echoServer3.Install (ueNodes.Get (2)));
317 
318  serverApps.Start (Seconds (4.0));
319  serverApps.Stop (Seconds (12.0));
320 
321  UdpEchoClientHelper echoClient1 (m_remoteHostAddr, 10);
322  UdpEchoClientHelper echoClient2 (m_ueIpIface.GetAddress (1,1), 11);
323  UdpEchoClientHelper echoClient3 (m_ueIpIface.GetAddress (2,1), 12);
324 
325  echoClient1.SetAttribute ("MaxPackets", UintegerValue (1000));
326  echoClient1.SetAttribute ("Interval", TimeValue (Seconds (0.2)));
327  echoClient1.SetAttribute ("PacketSize", UintegerValue (1024));
328 
329  echoClient2.SetAttribute ("MaxPackets", UintegerValue (1000));
330  echoClient2.SetAttribute ("Interval", TimeValue (Seconds (0.2)));
331  echoClient2.SetAttribute ("PacketSize", UintegerValue (1024));
332 
333  echoClient3.SetAttribute ("MaxPackets", UintegerValue (1000));
334  echoClient3.SetAttribute ("Interval", TimeValue (Seconds (0.2)));
335  echoClient3.SetAttribute ("PacketSize", UintegerValue (1024));
336 
337  ApplicationContainer clientApps1 = echoClient1.Install (ueNodes.Get (0));
338  ApplicationContainer clientApps2 = echoClient2.Install (ueNodes.Get (0));
339  ApplicationContainer clientApps3 = echoClient3.Install (ueNodes.Get (0));
340 
341  clientApps1.Start (Seconds (4.0));
342  clientApps1.Stop (Seconds (6.0));
343 
344  clientApps2.Start (Seconds (6.1));
345  clientApps2.Stop (Seconds (8.0));
346 
347  clientApps3.Start (Seconds (8.1));
348  clientApps3.Stop (Seconds (10.0));
349 
350  //Set Cllback for Client Sent and Received packets
351  Ptr<Ipv6L3Protocol> ipL3 = (ueNodes.Get (0))->GetObject<Ipv6L3Protocol> ();
352  ipL3->TraceConnectWithoutContext ("Tx", MakeCallback (&LteIpv6RoutingTestCase::SentAtClient, this));
353  ipL3->TraceConnectWithoutContext ("Rx", MakeCallback (&LteIpv6RoutingTestCase::ReceivedAtClient, this));
354 
355  //Set Callback at SgwPgWApplication of epc to get the packets from enb and from tunnel net device
356  Ptr<Application> appPgw = pgw->GetApplication (0);
359 
360  Simulator::Schedule (Time (Seconds (12.0)), &LteIpv6RoutingTestCase::Checker, this);
361 
362  Simulator::Stop (Seconds (14));
363  Simulator::Run ();
364 
365  Simulator::Destroy ();
366 }
367 
368 
373 {
374 public:
376 };
377 
379  : TestSuite ("lte-ipv6-routing-test", UNIT)
380 {
381  AddTestCase (new LteIpv6RoutingTestCase, TestCase::QUICK);
382 }
383 
Lte Ipv6 routing test case.
Ipv6InterfaceContainer m_ueIpIface
IPv6 interface container for ue.
void TunToPgw(Ptr< Packet > p)
Received Packet at pgw from enb.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Ipv6Address m_remoteHostAddr
remote host address
void ReceivedAtClient(Ptr< const Packet > p, Ptr< Ipv6 > ipv6, uint32_t interface)
Received Packets at client's IPv6 interface.
std::list< Ptr< Packet > > m_clientTxPkts
list of sent packets from client
std::list< uint64_t > m_pgwUidRxFrmTun
list of uids of packets received at pgw from tunnel net device
void EnbToPgw(Ptr< Packet > p)
Received Packet at pgw from enb.
void Checker()
Initialize testing parameters.
std::list< Ptr< Packet > > m_clientRxPkts
list of received packets at client
void SentAtClient(Ptr< const Packet > p, Ptr< Ipv6 > ipv6, uint32_t interface)
sent Packets from client's IPv6 interface.
std::list< uint64_t > m_pgwUidRxFrmEnb
list of uids of packets received at pgw from enb
holds a vector of ns3::Application pointers.
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter.
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
Introspection did not find any typical Config paths.
Definition: config-store.h:60
void ConfigureDefaults(void)
Configure the default values.
Class for representing data rates.
Definition: data-rate.h:89
AttributeValue implementation for DataRate.
Definition: data-rate.h:298
aggregate IP/TCP/UDP functionality to existing Nodes.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
Helper class to auto-assign global IPv6 unicast addresses.
void SetBase(Ipv6Address network, Ipv6Prefix prefix, Ipv6Address base=Ipv6Address("::1"))
Set the base network number, network prefix, and base interface ID.
Ipv6InterfaceContainer Assign(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer with auto-assigned addresses.
Describes an IPv6 address.
Definition: ipv6-address.h:50
Packet header for IPv6.
Definition: ipv6-header.h:36
Ipv6Address GetSource(void) const
Get the "Source address" field.
Definition: ipv6-header.cc:105
uint8_t GetNextHeader(void) const
Get the next header.
Definition: ipv6-header.cc:80
Ipv6Address GetDestination(void) const
Get the "Destination address" field.
Definition: ipv6-header.cc:125
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition: ipv6.h:82
Keep track of a set of IPv6 interfaces.
void SetForwarding(uint32_t i, bool state)
Set the state of the stack (act as a router or as an host) for the specified index.
void SetDefaultRouteInAllNodes(uint32_t router)
Set the default route for all the devices (except the router itself).
Ipv6Address GetAddress(uint32_t i, uint32_t j) const
Get the address for the specified index.
Describes an IPv6 prefix.
Definition: ipv6-address.h:456
Helper class that adds ns3::Ipv6StaticRouting objects.
Ptr< Ipv6StaticRouting > GetStaticRouting(Ptr< Ipv6 > ipv6) const
Get Ipv6StaticRouting pointer from IPv6 stack.
void SetEpcHelper(Ptr< EpcHelper > h)
Set the EpcHelper to be used to setup the EPC network in conjunction with the setup of the LTE radio ...
Definition: lte-helper.cc:272
NetDeviceContainer InstallEnbDevice(NodeContainer c)
Create a set of eNodeB devices.
Definition: lte-helper.cc:474
void Attach(NetDeviceContainer ueDevices)
Enables automatic attachment of a set of UE devices to a suitable cell using Idle mode initial cell s...
Definition: lte-helper.cc:959
NetDeviceContainer InstallUeDevice(NodeContainer c)
Create a set of UE devices.
Definition: lte-helper.cc:489
Helper class used to assign positions and mobility models to nodes.
holds a vector of ns3::NetDevice pointers
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
virtual Ipv6InterfaceContainer AssignUeIpv6Address(NetDeviceContainer ueDevices)
Assign IPv6 addresses to UE devices.
virtual Ptr< Node > GetPgwNode() const
Get the PGW node.
virtual Ipv6Address GetUeDefaultGatewayAddress6()
keep track of a set of node pointers.
uint32_t GetN(void) const
Get the number of Ptr<Node> stored in this container.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Ptr< Application > GetApplication(uint32_t index) const
Retrieve the index-th Application associated to this node.
Definition: node.cc:170
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:364
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
uint64_t GetUid(void) const
Returns the packet's Uid.
Definition: packet.cc:390
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:290
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
Build a set of PointToPointNetDevice objects.
void SetDeviceAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each NetDevice created by the helper.
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
NetDeviceContainer Install(NodeContainer c)
encapsulates test code
Definition: test.h:994
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
A suite of tests to run.
Definition: test.h:1188
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
AttributeValue implementation for Time.
Definition: nstime.h:1308
Create an application which sends a UDP packet and waits for an echo of this packet.
void SetAttribute(std::string name, const AttributeValue &value)
Record an attribute to be set in each Application after it is is created.
ApplicationContainer Install(Ptr< Node > node) const
Create a udp echo client application on the specified node.
Create a server application which waits for input UDP packets and sends them back to the original sen...
ApplicationContainer Install(Ptr< Node > node) const
Create a UdpEchoServerApplication on the specified Node.
Packet header for UDP packets.
Definition: udp-header.h:40
uint16_t GetSourcePort(void) const
Definition: udp-header.cc:65
uint16_t GetDestinationPort(void) const
Definition: udp-header.cc:70
Hold an unsigned integer type.
Definition: uinteger.h:44
#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:141
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
static LteIpv6RoutingTestSuite lteipv6testsuite
serverApps
Definition: first.py:52
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1648
mobility
Definition: third.py:108
#define list