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 
55 {
56 public:
58  virtual ~LteIpv6RoutingTestCase ();
59 
63  void Checker ();
64 
71  void SentAtClient (Ptr<const Packet> p, Ptr<Ipv6> ipv6, uint32_t interface);
72 
79  void ReceivedAtClient (Ptr<const Packet> p, Ptr<Ipv6> ipv6, uint32_t interface);
80 
85  void EnbToPgw (Ptr<Packet> p);
86 
91  void TunToPgw (Ptr<Packet> p);
92 
93 private:
94  virtual void DoRun (void);
97  std::list<uint64_t> m_pgwUidRxFrmEnb;
98  std::list<uint64_t> m_pgwUidRxFrmTun;
99 
100  std::list<Ptr<Packet> > m_clientTxPkts;
101  std::list<Ptr<Packet> > m_clientRxPkts;
102 };
103 
104 
106  : TestCase ("Test IPv6 Routing at LTE")
107 {
108 }
109 
111 {
112 }
113 
115 {
116  Ipv6Header ipv6Header;
117  p->PeekHeader (ipv6Header);
118  if (ipv6Header.GetNextHeader () == UdpL4Protocol::PROT_NUMBER)
119  {
120  m_clientTxPkts.push_back (p->Copy ());
121  }
122 }
123 
125 {
126  Ipv6Header ipv6Header;
127  p->PeekHeader (ipv6Header);
128  if (ipv6Header.GetNextHeader () == UdpL4Protocol::PROT_NUMBER)
129  {
130  m_clientRxPkts.push_back (p->Copy ());
131  }
132 }
133 
135 {
136  Ipv6Header ipv6Header;
137  p->PeekHeader (ipv6Header);
138  if (ipv6Header.GetNextHeader () == UdpL4Protocol::PROT_NUMBER)
139  {
140  m_pgwUidRxFrmEnb.push_back (p->GetUid ());
141  }
142 }
143 
145 {
146  Ipv6Header ipv6Header;
147  p->PeekHeader (ipv6Header);
148  if (ipv6Header.GetNextHeader () == UdpL4Protocol::PROT_NUMBER)
149  {
150  m_pgwUidRxFrmTun.push_back (p->GetUid ());
151  }
152 }
153 
155 {
156  bool b = false;
157  bool check = true;
158  //Extract each received reply packet of the client
159  for (std::list<Ptr<Packet> >::iterator it1 = m_clientRxPkts.begin (); it1 != m_clientRxPkts.end (); it1++)
160  {
161  Ipv6Header ipv6header1;
162  UdpHeader udpHeader1;
163  Ptr<Packet> p1 = (*it1)->Copy ();
164  p1->RemoveHeader (ipv6header1);
165  uint64_t uid = p1->GetUid ();
166  p1->RemoveHeader (udpHeader1);
167  //Search each packet in list of sent request packet of the client
168  for (std::list<Ptr<Packet> >::iterator it2 = m_clientTxPkts.begin (); it2 != m_clientTxPkts.end (); it2++)
169  {
170  Ptr<Packet> p2 = (*it2)->Copy ();
171  Ipv6Header ipv6header2;
172  p2->RemoveHeader (ipv6header2);
173  Ipv6Address sorceAddress = ipv6header2.GetSourceAddress ();
174  Ipv6Address destinationAddress = ipv6header2.GetDestinationAddress ();
175  UdpHeader udpHeader2;
176  p2->RemoveHeader (udpHeader2);
177  uint16_t sourcePort;
178  uint16_t destinationPort;
179  sourcePort = udpHeader2.GetSourcePort ();
180  destinationPort = udpHeader2.GetDestinationPort ();
181  //Check whether the uids, addresses and ports match
182  if ((p2->GetUid () == p1->GetUid ()) && sorceAddress.IsEqual (ipv6header1.GetDestinationAddress ()) && destinationAddress.IsEqual (ipv6header1.GetSourceAddress ()) && sourcePort == udpHeader1.GetDestinationPort () && destinationPort == udpHeader1.GetSourcePort ())
183  {
184  b = true;
185  break;
186  }
187  }
188  check &= b;
189  if (std::find (m_pgwUidRxFrmEnb.begin (), m_pgwUidRxFrmEnb.end (), uid) != m_pgwUidRxFrmEnb.end ())
190  {
191  check &= true;
192  m_pgwUidRxFrmEnb.remove (uid);
193  }
194  if (std::find (m_pgwUidRxFrmTun.begin (), m_pgwUidRxFrmTun.end (), uid) != m_pgwUidRxFrmTun.end ())
195  {
196  check &= true;
197  m_pgwUidRxFrmTun.remove (uid);
198  }
199  b = false;
200  }
201 
202  NS_TEST_ASSERT_MSG_EQ (check, true, "Failure Happens IPv6 routing of LENA");
203  NS_TEST_ASSERT_MSG_EQ (m_clientTxPkts.size (), m_clientRxPkts.size (), "No. of Request and Reply messages mismatch");
204  NS_TEST_ASSERT_MSG_EQ (m_pgwUidRxFrmEnb.size (), 0, "Route is not Redundant in Lte IPv6 test");
205  NS_TEST_ASSERT_MSG_EQ (m_pgwUidRxFrmTun.size (), 0, "Route is not Redundant in Lte IPv6 test");
206 
207 }
208 
209 void
211 {
212  double distance = 60.0;
213 
214  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
215  Ptr<PointToPointEpcHelper> epcHelper = CreateObject<PointToPointEpcHelper> ();
216  lteHelper->SetEpcHelper (epcHelper);
217 
218  ConfigStore inputConfig;
219  inputConfig.ConfigureDefaults ();
220 
221  Ptr<Node> pgw = epcHelper->GetPgwNode ();
222 
223  // Create a single RemoteHost
224  NodeContainer remoteHostContainer;
225  remoteHostContainer.Create (1);
226  Ptr<Node> remoteHost = remoteHostContainer.Get (0);
227  InternetStackHelper internet;
228  internet.Install (remoteHostContainer);
229 
230  // Create the Internet
231  PointToPointHelper p2ph;
232  p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s")));
233  p2ph.SetDeviceAttribute ("Mtu", UintegerValue (1500));
234  p2ph.SetChannelAttribute ("Delay", TimeValue (Seconds (0.010)));
235  NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost);
236 
237  NodeContainer ueNodes;
238  NodeContainer enbNodes;
239  enbNodes.Create (2);
240  ueNodes.Create (3);
241 
242  // Install Mobility Model
243  Ptr<ListPositionAllocator> positionAlloc1 = CreateObject<ListPositionAllocator> ();
244  Ptr<ListPositionAllocator> positionAlloc2 = CreateObject<ListPositionAllocator> ();
245 
246  positionAlloc1->Add (Vector (distance * 0, 0, 0));
247  positionAlloc1->Add (Vector (distance * 0 + 5, 0, 0));
248  positionAlloc1->Add (Vector (distance * 1, 0, 0));
249 
250  positionAlloc2->Add (Vector (distance * 0, 0, 0));
251  positionAlloc2->Add (Vector (distance * 1, 0, 0));
252 
254  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
255  mobility.SetPositionAllocator (positionAlloc1);
256  mobility.Install (ueNodes);
257 
258  mobility.SetPositionAllocator (positionAlloc2);
259  mobility.Install (enbNodes);
260 
261  // Install the IP stack on the UEs
262  internet.Install (ueNodes);
263 
264  // Install LTE Devices to the nodes
265  NetDeviceContainer enbLteDevs = lteHelper->InstallEnbDevice (enbNodes);
266  NetDeviceContainer ueLteDevs = lteHelper->InstallUeDevice (ueNodes);
267 
268  // Assign IP address to UEs, and install applications
269  m_ueIpIface = epcHelper->AssignUeIpv6Address (NetDeviceContainer (ueLteDevs));
270 
271  Ipv6StaticRoutingHelper ipv6RoutingHelper;
272 
273  for (uint32_t u = 0; u < ueNodes.GetN (); ++u)
274  {
275  Ptr<Node> ueNode = ueNodes.Get (u);
276  // Set the default gateway for the UE
277  Ptr<Ipv6StaticRouting> ueStaticRouting = ipv6RoutingHelper.GetStaticRouting (ueNode->GetObject<Ipv6> ());
278  ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress6 (), 1);
279  }
280 
281  // Attach two UEs at first eNodeB and one UE at second eNodeB
282  lteHelper->Attach (ueLteDevs.Get (0), enbLteDevs.Get (0));
283  lteHelper->Attach (ueLteDevs.Get (1), enbLteDevs.Get (0));
284  lteHelper->Attach (ueLteDevs.Get (2), enbLteDevs.Get (1));
285 
286  Ipv6AddressHelper ipv6h;
287  ipv6h.SetBase (Ipv6Address ("6001:db80::"), Ipv6Prefix (64));
288  Ipv6InterfaceContainer internetIpIfaces = ipv6h.Assign (internetDevices);
289 
290  internetIpIfaces.SetForwarding (0, true);
291  internetIpIfaces.SetDefaultRouteInAllNodes (0);
292 
293  Ptr<Ipv6StaticRouting> remoteHostStaticRouting = ipv6RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv6> ());
294  remoteHostStaticRouting->AddNetworkRouteTo ("7777:f00d::", Ipv6Prefix (64), internetIpIfaces.GetAddress (0, 1), 1, 0);
295 
296  // interface 0 is localhost, 1 is the p2p device
297  m_remoteHostAddr = internetIpIfaces.GetAddress (1, 1);
298 
299  // Install and start applications on UEs and remote host
300  UdpEchoServerHelper echoServer1 (10);
301  UdpEchoServerHelper echoServer2 (11);
302  UdpEchoServerHelper echoServer3 (12);
303 
304  ApplicationContainer serverApps = echoServer1.Install (remoteHost);
305  serverApps.Add (echoServer2.Install (ueNodes.Get (1)));
306  serverApps.Add (echoServer3.Install (ueNodes.Get (2)));
307 
308  serverApps.Start (Seconds (4.0));
309  serverApps.Stop (Seconds (12.0));
310 
311  UdpEchoClientHelper echoClient1 (m_remoteHostAddr, 10);
312  UdpEchoClientHelper echoClient2 (m_ueIpIface.GetAddress (1,1), 11);
313  UdpEchoClientHelper echoClient3 (m_ueIpIface.GetAddress (2,1), 12);
314 
315  echoClient1.SetAttribute ("MaxPackets", UintegerValue (1000));
316  echoClient1.SetAttribute ("Interval", TimeValue (Seconds (0.2)));
317  echoClient1.SetAttribute ("PacketSize", UintegerValue (1024));
318 
319  echoClient2.SetAttribute ("MaxPackets", UintegerValue (1000));
320  echoClient2.SetAttribute ("Interval", TimeValue (Seconds (0.2)));
321  echoClient2.SetAttribute ("PacketSize", UintegerValue (1024));
322 
323  echoClient3.SetAttribute ("MaxPackets", UintegerValue (1000));
324  echoClient3.SetAttribute ("Interval", TimeValue (Seconds (0.2)));
325  echoClient3.SetAttribute ("PacketSize", UintegerValue (1024));
326 
327  ApplicationContainer clientApps1 = echoClient1.Install (ueNodes.Get (0));
328  ApplicationContainer clientApps2 = echoClient2.Install (ueNodes.Get (0));
329  ApplicationContainer clientApps3 = echoClient3.Install (ueNodes.Get (0));
330 
331  clientApps1.Start (Seconds (4.0));
332  clientApps1.Stop (Seconds (6.0));
333 
334  clientApps2.Start (Seconds (6.1));
335  clientApps2.Stop (Seconds (8.0));
336 
337  clientApps3.Start (Seconds (8.1));
338  clientApps3.Stop (Seconds (10.0));
339 
340  //Set Cllback for Client Sent and Received packets
341  Ptr<Ipv6L3Protocol> ipL3 = (ueNodes.Get (0))->GetObject<Ipv6L3Protocol> ();
344 
345  //Set Callback at SgwPgWApplication of epc to get the packets from enb and from tunnel net device
346  Ptr<Application> appPgw = pgw->GetApplication (0);
349 
350  Simulator::Schedule (Time (Seconds (12.0)), &LteIpv6RoutingTestCase::Checker, this);
351 
352  Simulator::Stop (Seconds (14));
353  Simulator::Run ();
354 
355  Simulator::Destroy ();
356 }
357 
358 
363 {
364 public:
366 };
367 
369  : TestSuite ("lte-ipv6-routing-test", UNIT)
370 {
371  AddTestCase (new LteIpv6RoutingTestCase, TestCase::QUICK);
372 }
373 
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
uint8_t GetNextHeader(void) const
Get the next header.
Definition: ipv6-header.cc:80
holds a vector of ns3::Application pointers.
Introspection did not find any typical Config paths.
Definition: config-store.h:59
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Packet header for IPv6.
Definition: ipv6-header.h:34
std::list< Ptr< Packet > > m_clientTxPkts
list of sent packets from client
NetDeviceContainer InstallEnbDevice(NodeContainer c)
Create a set of eNodeB devices.
Definition: lte-helper.cc:474
Keep track of a set of IPv6 interfaces.
Ipv6InterfaceContainer m_ueIpIface
IPv6 interface container for ue.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition: ipv6.h:81
void SetDefaultRouteInAllNodes(uint32_t router)
Set the default route for all the devices (except the router itself).
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
NetDeviceContainer Install(NodeContainer c)
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container. ...
A suite of tests to run.
Definition: test.h:1342
uint64_t GetUid(void) const
Returns the packet's Uid.
Definition: packet.cc:390
Create an application which sends a UDP packet and waits for an echo of this packet.
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:957
Ptr< Ipv6StaticRouting > GetStaticRouting(Ptr< Ipv6 > ipv6) const
Get Ipv6StaticRouting pointer from IPv6 stack.
aggregate IP/TCP/UDP functionality to existing Nodes.
bool IsEqual(const Ipv6Address &other) const
Comparison operation between two Ipv6Addresses.
void SetBase(Ipv6Address network, Ipv6Prefix prefix, Ipv6Address base=Ipv6Address("::1"))
Set the base network number, network prefix, and base interface ID.
Build a set of PointToPointNetDevice objects.
encapsulates test code
Definition: test.h:1155
void SetDeviceAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each NetDevice created by the helper.
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.
ApplicationContainer Install(Ptr< Node > node) const
Create a UdpEchoServerApplication on the specified Node.
Ipv6InterfaceContainer Assign(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer with auto-assigned addresses.
uint32_t GetN(void) const
Get the number of Ptr stored in this container.
Class for representing data rates.
Definition: data-rate.h:88
Create a server application which waits for input UDP packets and sends them back to the original sen...
Ptr< Application > GetApplication(uint32_t index) const
Retrieve the index-th Application associated to this node.
Definition: node.cc:168
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
void TunToPgw(Ptr< Packet > p)
Received Packet at pgw from enb.
tuple mobility
Definition: third.py:101
AttributeValue implementation for Time.
Definition: nstime.h:1069
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
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:168
holds a vector of ns3::NetDevice pointers
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
void AddNetworkRouteTo(Ipv6Address network, Ipv6Prefix networkPrefix, Ipv6Address nextHop, uint32_t interface, uint32_t metric=0)
Add route to network.
void ReceivedAtClient(Ptr< const Packet > p, Ptr< Ipv6 > ipv6, uint32_t interface)
Received Packets at client's IPv6 interface.
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
#define list
std::list< uint64_t > m_pgwUidRxFrmTun
list of uids of packets received at pgw from tunnel net device
tuple serverApps
Definition: first.py:45
void ConfigureDefaults(void)
Configure the default values.
Ipv6Address m_remoteHostAddr
remote host address
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:290
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:293
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
void EnbToPgw(Ptr< Packet > p)
Received Packet at pgw from enb.
Helper class that adds ns3::Ipv6StaticRouting objects.
void SetMobilityModel(std::string type, std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue())
uint16_t GetSourcePort(void) const
Definition: udp-header.cc:65
Packet header for UDP packets.
Definition: udp-header.h:39
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
std::list< Ptr< Packet > > m_clientRxPkts
list of received packets at client
virtual void DoRun(void)
Implementation to actually run this TestCase.
std::list< uint64_t > m_pgwUidRxFrmEnb
list of uids of packets received at pgw from enb
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
Helper class to auto-assign global IPv6 unicast addresses.
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.
Describes an IPv6 address.
Definition: ipv6-address.h:49
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
void Checker()
Initialize testing parameters.
void SetDefaultRoute(Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address("::"), uint32_t metric=0)
Set the default route.
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
AttributeValue implementation for DataRate.
Definition: data-rate.h:242
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
Ipv6Address GetSourceAddress(void) const
Get the "Source address" field.
Definition: ipv6-header.cc:100
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1007
void SentAtClient(Ptr< const Packet > p, Ptr< Ipv6 > ipv6, uint32_t interface)
sent Packets from client's IPv6 interface.
void Add(Vector v)
Add a position to the list of positions.
Describes an IPv6 prefix.
Definition: ipv6-address.h:428
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.
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
uint16_t GetDestinationPort(void) const
Definition: udp-header.cc:70
ApplicationContainer Install(Ptr< Node > node) const
Create a udp echo client application on the specified node.
Ipv6Address GetAddress(uint32_t i, uint32_t j) const
Get the address for the specified index.
Ipv6Address GetDestinationAddress(void) const
Get the "Destination address" field.
Definition: ipv6-header.cc:110
static LteIpv6RoutingTestSuite lteipv6testsuite