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.GetSourceAddress ();
180  Ipv6Address destinationAddress = ipv6header2.GetDestinationAddress ();
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 ()) && sorceAddress.IsEqual (ipv6header1.GetDestinationAddress ()) && destinationAddress.IsEqual (ipv6header1.GetSourceAddress ()) && sourcePort == udpHeader1.GetDestinationPort () && destinationPort == udpHeader1.GetSourcePort ())
189  {
190  b = true;
191  break;
192  }
193  }
194  check &= b;
195  if (std::find (m_pgwUidRxFrmEnb.begin (), m_pgwUidRxFrmEnb.end (), uid) != m_pgwUidRxFrmEnb.end ())
196  {
197  check &= true;
198  m_pgwUidRxFrmEnb.remove (uid);
199  }
200  if (std::find (m_pgwUidRxFrmTun.begin (), m_pgwUidRxFrmTun.end (), uid) != m_pgwUidRxFrmTun.end ())
201  {
202  check &= true;
203  m_pgwUidRxFrmTun.remove (uid);
204  }
205  b = false;
206  }
207 
208  NS_TEST_ASSERT_MSG_EQ (check, true, "Failure Happens IPv6 routing of LENA");
209  NS_TEST_ASSERT_MSG_EQ (m_clientTxPkts.size (), m_clientRxPkts.size (), "No. of Request and Reply messages mismatch");
210  NS_TEST_ASSERT_MSG_EQ (m_pgwUidRxFrmEnb.size (), 0, "Route is not Redundant in Lte IPv6 test");
211  NS_TEST_ASSERT_MSG_EQ (m_pgwUidRxFrmTun.size (), 0, "Route is not Redundant in Lte IPv6 test");
212 
213 }
214 
215 void
217 {
218  double distance = 60.0;
219 
220  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
221  Ptr<PointToPointEpcHelper> epcHelper = CreateObject<PointToPointEpcHelper> ();
222  lteHelper->SetEpcHelper (epcHelper);
223 
224  ConfigStore inputConfig;
225  inputConfig.ConfigureDefaults ();
226 
227  Ptr<Node> pgw = epcHelper->GetPgwNode ();
228 
229  // Create a single RemoteHost
230  NodeContainer remoteHostContainer;
231  remoteHostContainer.Create (1);
232  Ptr<Node> remoteHost = remoteHostContainer.Get (0);
233  InternetStackHelper internet;
234  internet.Install (remoteHostContainer);
235 
236  // Create the Internet
237  PointToPointHelper p2ph;
238  p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s")));
239  p2ph.SetDeviceAttribute ("Mtu", UintegerValue (1500));
240  p2ph.SetChannelAttribute ("Delay", TimeValue (Seconds (0.010)));
241  NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost);
242 
243  NodeContainer ueNodes;
244  NodeContainer enbNodes;
245  enbNodes.Create (2);
246  ueNodes.Create (3);
247 
248  // Install Mobility Model
249  Ptr<ListPositionAllocator> positionAlloc1 = CreateObject<ListPositionAllocator> ();
250  Ptr<ListPositionAllocator> positionAlloc2 = CreateObject<ListPositionAllocator> ();
251 
252  positionAlloc1->Add (Vector (distance * 0, 0, 0));
253  positionAlloc1->Add (Vector (distance * 0 + 5, 0, 0));
254  positionAlloc1->Add (Vector (distance * 1, 0, 0));
255 
256  positionAlloc2->Add (Vector (distance * 0, 0, 0));
257  positionAlloc2->Add (Vector (distance * 1, 0, 0));
258 
260  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
261  mobility.SetPositionAllocator (positionAlloc1);
262  mobility.Install (ueNodes);
263 
264  mobility.SetPositionAllocator (positionAlloc2);
265  mobility.Install (enbNodes);
266 
267  // Install the IP stack on the UEs
268  internet.Install (ueNodes);
269 
270  // Install LTE Devices to the nodes
271  NetDeviceContainer enbLteDevs = lteHelper->InstallEnbDevice (enbNodes);
272  NetDeviceContainer ueLteDevs = lteHelper->InstallUeDevice (ueNodes);
273 
274  // Assign IP address to UEs, and install applications
275  m_ueIpIface = epcHelper->AssignUeIpv6Address (NetDeviceContainer (ueLteDevs));
276 
277  Ipv6StaticRoutingHelper ipv6RoutingHelper;
278 
279  for (uint32_t u = 0; u < ueNodes.GetN (); ++u)
280  {
281  Ptr<Node> ueNode = ueNodes.Get (u);
282  // Set the default gateway for the UE
283  Ptr<Ipv6StaticRouting> ueStaticRouting = ipv6RoutingHelper.GetStaticRouting (ueNode->GetObject<Ipv6> ());
284  ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress6 (), 1);
285  }
286 
287  // Attach two UEs at first eNodeB and one UE at second eNodeB
288  lteHelper->Attach (ueLteDevs.Get (0), enbLteDevs.Get (0));
289  lteHelper->Attach (ueLteDevs.Get (1), enbLteDevs.Get (0));
290  lteHelper->Attach (ueLteDevs.Get (2), enbLteDevs.Get (1));
291 
292  Ipv6AddressHelper ipv6h;
293  ipv6h.SetBase (Ipv6Address ("6001:db80::"), Ipv6Prefix (64));
294  Ipv6InterfaceContainer internetIpIfaces = ipv6h.Assign (internetDevices);
295 
296  internetIpIfaces.SetForwarding (0, true);
297  internetIpIfaces.SetDefaultRouteInAllNodes (0);
298 
299  Ptr<Ipv6StaticRouting> remoteHostStaticRouting = ipv6RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv6> ());
300  remoteHostStaticRouting->AddNetworkRouteTo ("7777:f00d::", Ipv6Prefix (64), internetIpIfaces.GetAddress (0, 1), 1, 0);
301 
302  // interface 0 is localhost, 1 is the p2p device
303  m_remoteHostAddr = internetIpIfaces.GetAddress (1, 1);
304 
305  // Install and start applications on UEs and remote host
306  UdpEchoServerHelper echoServer1 (10);
307  UdpEchoServerHelper echoServer2 (11);
308  UdpEchoServerHelper echoServer3 (12);
309 
310  ApplicationContainer serverApps = echoServer1.Install (remoteHost);
311  serverApps.Add (echoServer2.Install (ueNodes.Get (1)));
312  serverApps.Add (echoServer3.Install (ueNodes.Get (2)));
313 
314  serverApps.Start (Seconds (4.0));
315  serverApps.Stop (Seconds (12.0));
316 
317  UdpEchoClientHelper echoClient1 (m_remoteHostAddr, 10);
318  UdpEchoClientHelper echoClient2 (m_ueIpIface.GetAddress (1,1), 11);
319  UdpEchoClientHelper echoClient3 (m_ueIpIface.GetAddress (2,1), 12);
320 
321  echoClient1.SetAttribute ("MaxPackets", UintegerValue (1000));
322  echoClient1.SetAttribute ("Interval", TimeValue (Seconds (0.2)));
323  echoClient1.SetAttribute ("PacketSize", UintegerValue (1024));
324 
325  echoClient2.SetAttribute ("MaxPackets", UintegerValue (1000));
326  echoClient2.SetAttribute ("Interval", TimeValue (Seconds (0.2)));
327  echoClient2.SetAttribute ("PacketSize", UintegerValue (1024));
328 
329  echoClient3.SetAttribute ("MaxPackets", UintegerValue (1000));
330  echoClient3.SetAttribute ("Interval", TimeValue (Seconds (0.2)));
331  echoClient3.SetAttribute ("PacketSize", UintegerValue (1024));
332 
333  ApplicationContainer clientApps1 = echoClient1.Install (ueNodes.Get (0));
334  ApplicationContainer clientApps2 = echoClient2.Install (ueNodes.Get (0));
335  ApplicationContainer clientApps3 = echoClient3.Install (ueNodes.Get (0));
336 
337  clientApps1.Start (Seconds (4.0));
338  clientApps1.Stop (Seconds (6.0));
339 
340  clientApps2.Start (Seconds (6.1));
341  clientApps2.Stop (Seconds (8.0));
342 
343  clientApps3.Start (Seconds (8.1));
344  clientApps3.Stop (Seconds (10.0));
345 
346  //Set Cllback for Client Sent and Received packets
347  Ptr<Ipv6L3Protocol> ipL3 = (ueNodes.Get (0))->GetObject<Ipv6L3Protocol> ();
350 
351  //Set Callback at SgwPgWApplication of epc to get the packets from enb and from tunnel net device
352  Ptr<Application> appPgw = pgw->GetApplication (0);
355 
356  Simulator::Schedule (Time (Seconds (12.0)), &LteIpv6RoutingTestCase::Checker, this);
357 
358  Simulator::Stop (Seconds (14));
359  Simulator::Run ();
360 
361  Simulator::Destroy ();
362 }
363 
364 
369 {
370 public:
372 };
373 
375  : TestSuite ("lte-ipv6-routing-test", UNIT)
376 {
377  AddTestCase (new LteIpv6RoutingTestCase, TestCase::QUICK);
378 }
379 
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
holds a vector of ns3::Application pointers.
Introspection did not find any typical Config paths.
Definition: config-store.h:59
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
uint64_t GetUid(void) const
Returns the packet&#39;s Uid.
Definition: packet.cc:390
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.
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).
NetDeviceContainer Install(NodeContainer c)
ApplicationContainer Install(Ptr< Node > node) const
Create a UdpEchoServerApplication on the specified Node.
A suite of tests to run.
Definition: test.h:1342
serverApps
Definition: first.py:45
Create an application which sends a UDP packet and waits for an echo of this packet.
Lte Ipv6 routing test case.
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
aggregate IP/TCP/UDP functionality to existing Nodes.
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.
mobility
Definition: third.py:101
Ipv6InterfaceContainer Assign(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer with auto-assigned addresses.
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...
bool IsEqual(const Ipv6Address &other) const
Comparison operation between two Ipv6Addresses.
void TunToPgw(Ptr< Packet > p)
Received Packet at pgw from enb.
AttributeValue implementation for Time.
Definition: nstime.h:1076
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
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:168
Ptr< Application > GetApplication(uint32_t index) const
Retrieve the index-th Application associated to this node.
Definition: node.cc:168
holds a vector of ns3::NetDevice pointers
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:290
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&#39;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...
Ipv6Address GetSourceAddress(void) const
Get the "Source address" field.
Definition: ipv6-header.cc:100
#define list
std::list< uint64_t > m_pgwUidRxFrmTun
list of uids of packets received at pgw from tunnel net device
uint32_t GetN(void) const
Get the number of Ptr<Node> stored in this container.
void ConfigureDefaults(void)
Configure the default values.
Ptr< Ipv6StaticRouting > GetStaticRouting(Ptr< Ipv6 > ipv6) const
Get Ipv6StaticRouting pointer from IPv6 stack.
Ipv6Address m_remoteHostAddr
remote host address
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
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.
ApplicationContainer Install(Ptr< Node > node) const
Create a udp echo client application on the specified node.
Helper class that adds ns3::Ipv6StaticRouting objects.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
Packet header for UDP packets.
Definition: udp-header.h:39
uint8_t GetNextHeader(void) const
Get the next header.
Definition: ipv6-header.cc:80
std::list< Ptr< Packet > > m_clientRxPkts
list of received packets at client
virtual void DoRun(void)
Implementation to actually run this TestCase.
Ipv6Address GetAddress(uint32_t i, uint32_t j) const
Get the address for the specified index.
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.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
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
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1014
void SentAtClient(Ptr< const Packet > p, Ptr< Ipv6 > ipv6, uint32_t interface)
sent Packets from client&#39;s IPv6 interface.
void Add(Vector v)
Add a position to the list of positions.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
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.
uint16_t GetSourcePort(void) const
Definition: udp-header.cc:65
void SetAttribute(std::string name, const AttributeValue &value)
Record an attribute to be set in each Application after it is is created.
Ipv6Address GetDestinationAddress(void) const
Get the "Destination address" field.
Definition: ipv6-header.cc:110
static LteIpv6RoutingTestSuite lteipv6testsuite