A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lte-test-ipv6-routing.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 Jadavpur University, India
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Manoj Kumar Rana <manoj24.rana@gmail.com>
7 */
8
9#include "ns3/config-store.h"
10#include "ns3/core-module.h"
11#include "ns3/epc-helper.h"
12#include "ns3/internet-module.h"
13#include "ns3/ipv4-global-routing-helper.h"
14#include "ns3/ipv6-static-routing.h"
15#include "ns3/lte-helper.h"
16#include "ns3/lte-module.h"
17#include "ns3/mobility-module.h"
18#include "ns3/network-module.h"
19#include "ns3/point-to-point-helper.h"
20#include "ns3/udp-echo-helper.h"
21
22#include <algorithm>
23
24/* *
25 * Scenario: 3 UEs, 2 ENBs, 1 Remote Host, UE0<-->ENB0, UE1<-->ENB0, UE2<-->ENB1
26 Servers: UE1, UE2, Remote Host
27 Client: UE0 (3 clients)
28 UDP Echo Packets transmitted between client and server
29
30 * Pass criteria: 1) Every UDP Echo Request and Reply messages sent and received respectively
31 at UE0 must be matched by their UID, source address, destination address,
32 source port and destination port
33 2) Every request reply must follow proper route (e.g. In case of UE0->UE1,
34 packet must travel this route:
35UE0->ENB0->PGW->ENB1->UE1->ENB1->PGW->ENB0->UE0) 3) The above check also ensures no redundancy of
36the followed route for a packet
37* */
38
39using namespace ns3;
40
41/**
42 * @ingroup lte-test
43 *
44 * @brief Lte Ipv6 routing test case.
45 */
47{
48 public:
50 ~LteIpv6RoutingTestCase() override;
51
52 /**
53 * @brief Initialize testing parameters.
54 */
55 void Checker();
56
57 /**
58 * @brief sent Packets from client's IPv6 interface.
59 * @param p packet
60 * @param ipv6 Ipv6 object
61 * @param interface Ipv6interface from which the packet is transmitted
62 */
63 void SentAtClient(Ptr<const Packet> p, Ptr<Ipv6> ipv6, uint32_t interface);
64
65 /**
66 * @brief Received Packets at client's IPv6 interface.
67 * @param p packet
68 * @param ipv6 Ipv6 object
69 * @param interface Ipv6interface at which the packet is received
70 */
72
73 /**
74 * @brief Received Packet at pgw from enb.
75 * @param p packet
76 */
77 void EnbToPgw(Ptr<Packet> p);
78
79 /**
80 * @brief Received Packet at pgw from enb.
81 * @param p packet
82 */
83 void TunToPgw(Ptr<Packet> p);
84
85 private:
86 void DoRun() override;
87 Ipv6InterfaceContainer m_ueIpIface; //!< IPv6 interface container for ue
88 Ipv6Address m_remoteHostAddr; //!< remote host address
89 std::list<uint64_t> m_pgwUidRxFrmEnb; //!< list of uids of packets received at pgw from enb
90 std::list<uint64_t>
91 m_pgwUidRxFrmTun; //!< list of uids of packets received at pgw from tunnel net device
92
93 std::list<Ptr<Packet>> m_clientTxPkts; //!< list of sent packets from client
94 std::list<Ptr<Packet>> m_clientRxPkts; //!< list of received packets at client
95};
96
98 : TestCase("Test IPv6 Routing at LTE")
99{
100}
101
105
106void
108{
109 Ipv6Header ipv6Header;
110 p->PeekHeader(ipv6Header);
111 if (ipv6Header.GetNextHeader() == UdpL4Protocol::PROT_NUMBER)
112 {
113 m_clientTxPkts.push_back(p->Copy());
114 }
115}
116
117void
119{
120 Ipv6Header ipv6Header;
121 p->PeekHeader(ipv6Header);
122 if (ipv6Header.GetNextHeader() == UdpL4Protocol::PROT_NUMBER)
123 {
124 m_clientRxPkts.push_back(p->Copy());
125 }
126}
127
128void
130{
131 Ipv6Header ipv6Header;
132 p->PeekHeader(ipv6Header);
133 if (ipv6Header.GetNextHeader() == UdpL4Protocol::PROT_NUMBER)
134 {
135 m_pgwUidRxFrmEnb.push_back(p->GetUid());
136 }
137}
138
139void
141{
142 Ipv6Header ipv6Header;
143 p->PeekHeader(ipv6Header);
144 if (ipv6Header.GetNextHeader() == UdpL4Protocol::PROT_NUMBER)
145 {
146 m_pgwUidRxFrmTun.push_back(p->GetUid());
147 }
148}
149
150void
152{
153 bool b = false;
154 bool check = true;
155 // Extract each received reply packet of the client
156 for (auto it1 = m_clientRxPkts.begin(); it1 != m_clientRxPkts.end(); it1++)
157 {
158 Ipv6Header ipv6header1;
159 UdpHeader udpHeader1;
160 Ptr<Packet> p1 = (*it1)->Copy();
161 p1->RemoveHeader(ipv6header1);
162 uint64_t uid = p1->GetUid();
163 p1->RemoveHeader(udpHeader1);
164 // Search each packet in list of sent request packet of the client
165 for (auto it2 = m_clientTxPkts.begin(); it2 != m_clientTxPkts.end(); it2++)
166 {
167 Ptr<Packet> p2 = (*it2)->Copy();
168 Ipv6Header ipv6header2;
169 p2->RemoveHeader(ipv6header2);
170 Ipv6Address sourceAddress = ipv6header2.GetSource();
171 Ipv6Address destinationAddress = ipv6header2.GetDestination();
172 UdpHeader udpHeader2;
173 p2->RemoveHeader(udpHeader2);
174 uint16_t sourcePort;
175 uint16_t destinationPort;
176 sourcePort = udpHeader2.GetSourcePort();
177 destinationPort = udpHeader2.GetDestinationPort();
178 // Check whether the uids, addresses and ports match
179 if ((p2->GetUid() == p1->GetUid()) && sourceAddress == ipv6header1.GetDestination() &&
180 destinationAddress == ipv6header1.GetSource() &&
181 sourcePort == udpHeader1.GetDestinationPort() &&
182 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) !=
190 m_pgwUidRxFrmEnb.end())
191 {
192 check &= true;
193 m_pgwUidRxFrmEnb.remove(uid);
194 }
195 if (std::find(m_pgwUidRxFrmTun.begin(), m_pgwUidRxFrmTun.end(), uid) !=
196 m_pgwUidRxFrmTun.end())
197 {
198 check &= true;
199 m_pgwUidRxFrmTun.remove(uid);
200 }
201 b = false;
202 }
203
204 NS_TEST_ASSERT_MSG_EQ(check, true, "Failure Happens IPv6 routing of LENA");
206 m_clientRxPkts.size(),
207 "No. of Request and Reply messages mismatch");
208 NS_TEST_ASSERT_MSG_EQ(m_pgwUidRxFrmEnb.size(), 0, "Route is not Redundant in Lte IPv6 test");
209 NS_TEST_ASSERT_MSG_EQ(m_pgwUidRxFrmTun.size(), 0, "Route is not Redundant in Lte IPv6 test");
210}
211
212void
214{
215 double distance = 60.0;
216
219 lteHelper->SetEpcHelper(epcHelper);
220
221 ConfigStore inputConfig;
222 inputConfig.ConfigureDefaults();
223
224 Ptr<Node> pgw = epcHelper->GetPgwNode();
225
226 // Create a single RemoteHost
227 NodeContainer remoteHostContainer;
228 remoteHostContainer.Create(1);
229 Ptr<Node> remoteHost = remoteHostContainer.Get(0);
230 InternetStackHelper internet;
231 internet.Install(remoteHostContainer);
232
233 // Create the Internet
235 p2ph.SetDeviceAttribute("DataRate", DataRateValue(DataRate("100Gb/s")));
236 p2ph.SetDeviceAttribute("Mtu", UintegerValue(1500));
237 p2ph.SetChannelAttribute("Delay", TimeValue(Seconds(0.010)));
238 NetDeviceContainer internetDevices = p2ph.Install(pgw, remoteHost);
239
240 NodeContainer ueNodes;
241 NodeContainer enbNodes;
242 enbNodes.Create(2);
243 ueNodes.Create(3);
244
245 // Install Mobility Model
248
249 positionAlloc1->Add(Vector(distance * 0, 0, 0));
250 positionAlloc1->Add(Vector(distance * 0 + 5, 0, 0));
251 positionAlloc1->Add(Vector(distance * 1, 0, 0));
252
253 positionAlloc2->Add(Vector(distance * 0, 0, 0));
254 positionAlloc2->Add(Vector(distance * 1, 0, 0));
255
256 MobilityHelper mobility;
257 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
258 mobility.SetPositionAllocator(positionAlloc1);
259 mobility.Install(ueNodes);
260
261 mobility.SetPositionAllocator(positionAlloc2);
262 mobility.Install(enbNodes);
263
264 // Install the IP stack on the UEs
265 internet.Install(ueNodes);
266
267 // Install LTE Devices to the nodes
268 NetDeviceContainer enbLteDevs = lteHelper->InstallEnbDevice(enbNodes);
269 NetDeviceContainer ueLteDevs = lteHelper->InstallUeDevice(ueNodes);
270
271 // Assign IP address to UEs, and install applications
272 m_ueIpIface = epcHelper->AssignUeIpv6Address(NetDeviceContainer(ueLteDevs));
273
274 Ipv6StaticRoutingHelper ipv6RoutingHelper;
275
276 for (uint32_t u = 0; u < ueNodes.GetN(); ++u)
277 {
278 Ptr<Node> ueNode = ueNodes.Get(u);
279 // Set the default gateway for the UE
280 Ptr<Ipv6StaticRouting> ueStaticRouting =
281 ipv6RoutingHelper.GetStaticRouting(ueNode->GetObject<Ipv6>());
282 ueStaticRouting->SetDefaultRoute(epcHelper->GetUeDefaultGatewayAddress6(), 1);
283 }
284
285 // Attach two UEs at first eNodeB and one UE at second eNodeB
286 lteHelper->Attach(ueLteDevs.Get(0), enbLteDevs.Get(0));
287 lteHelper->Attach(ueLteDevs.Get(1), enbLteDevs.Get(0));
288 lteHelper->Attach(ueLteDevs.Get(2), enbLteDevs.Get(1));
289
290 Ipv6AddressHelper ipv6h;
291 ipv6h.SetBase(Ipv6Address("6001:db80::"), Ipv6Prefix(64));
292 Ipv6InterfaceContainer internetIpIfaces = ipv6h.Assign(internetDevices);
293
294 internetIpIfaces.SetForwarding(0, true);
295 internetIpIfaces.SetDefaultRouteInAllNodes(0);
296
297 Ptr<Ipv6StaticRouting> remoteHostStaticRouting =
298 ipv6RoutingHelper.GetStaticRouting(remoteHost->GetObject<Ipv6>());
299 remoteHostStaticRouting
300 ->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));
315 serverApps.Stop(Seconds(12));
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));
338 clientApps1.Stop(Seconds(6));
339
340 clientApps2.Start(Seconds(6.1));
341 clientApps2.Stop(Seconds(8));
342
343 clientApps3.Start(Seconds(8.1));
344 clientApps3.Stop(Seconds(10));
345
346 // Set Cllback for Client Sent and Received packets
347 Ptr<Ipv6L3Protocol> ipL3 = (ueNodes.Get(0))->GetObject<Ipv6L3Protocol>();
348 ipL3->TraceConnectWithoutContext("Tx",
350 ipL3->TraceConnectWithoutContext("Rx",
352
353 // Set Callback at SgwPgWApplication of epc to get the packets from enb and from tunnel net
354 // device
355 Ptr<Application> appPgw = pgw->GetApplication(0);
356 appPgw->TraceConnectWithoutContext("RxFromS1u",
358 appPgw->TraceConnectWithoutContext("RxFromTun",
360
362
365
367}
368
369/**
370 * @brief test suite 1
371 */
373{
374 public:
376};
377
379 : TestSuite("lte-ipv6-routing-test", Type::UNIT)
380{
381 AddTestCase(new LteIpv6RoutingTestCase, TestCase::Duration::QUICK);
382}
383
384/**
385 * @ingroup lte-test
386 * Static variable for test initialization
387 */
Lte Ipv6 routing test case.
Ipv6InterfaceContainer m_ueIpIface
IPv6 interface container for ue.
void TunToPgw(Ptr< Packet > p)
Received Packet at pgw from enb.
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
void DoRun() override
Implementation to actually run this TestCase.
holds a vector of ns3::Application pointers.
void Start(Time start) const
Start all of the Applications in this container at the start time given as a parameter.
void Stop(Time stop) const
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
ApplicationContainer Install(NodeContainer c)
Install an application on each node of the input container configured with all the attributes set wit...
void SetAttribute(const std::string &name, const AttributeValue &value)
Helper function used to set the underlying application attributes.
Introspection did not find any typical Config paths.
void ConfigureDefaults()
Configure the default values.
Class for representing data rates.
Definition data-rate.h:78
AttributeValue implementation for DataRate.
Definition data-rate.h:285
aggregate IP/TCP/UDP functionality to existing Nodes.
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.
Packet header for IPv6.
Definition ipv6-header.h:24
uint8_t GetNextHeader() const
Get the next header.
Ipv6Address GetDestination() const
Get the "Destination address" field.
Ipv6Address GetSource() const
Get the "Source address" field.
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition ipv6.h:71
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.
Helper class that adds ns3::Ipv6StaticRouting objects.
Ptr< Ipv6StaticRouting > GetStaticRouting(Ptr< Ipv6 > ipv6) const
Get Ipv6StaticRouting pointer from IPv6 stack.
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.
keep track of a set of node pointers.
uint32_t GetN() 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.
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)
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
AttributeValue implementation for Time.
Definition nstime.h:1431
Create an application which sends a UDP packet and waits for an echo of this packet.
Create a server application which waits for input UDP packets and sends them back to the original sen...
Packet header for UDP packets.
Definition udp-header.h:30
uint16_t GetDestinationPort() const
Definition udp-header.cc:43
uint16_t GetSourcePort() const
Definition udp-header.cc:37
static const uint8_t PROT_NUMBER
protocol number (0x11)
Hold an unsigned integer type.
Definition uinteger.h:34
static LteIpv6RoutingTestSuite g_lteipv6testsuite
Static variable for test initialization.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#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:134
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1344
-style-clang-format
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition callback.h:684