A Discrete-Event Network Simulator
API
lte-test-ipv6-routing.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 Jadavpur University, India
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Manoj Kumar Rana <manoj24.rana@gmail.com>
18 */
19
20#include "ns3/applications-module.h"
21#include "ns3/config-store.h"
22#include "ns3/core-module.h"
23#include "ns3/epc-helper.h"
24#include "ns3/internet-module.h"
25#include "ns3/ipv4-global-routing-helper.h"
26#include "ns3/ipv6-static-routing.h"
27#include "ns3/lte-helper.h"
28#include "ns3/lte-module.h"
29#include "ns3/mobility-module.h"
30#include "ns3/network-module.h"
31#include "ns3/point-to-point-helper.h"
32
33#include <algorithm>
34
35/* *
36 * Scenario: 3 UEs, 2 ENBs, 1 Remote Host, UE0<-->ENB0, UE1<-->ENB0, UE2<-->ENB1
37 Servers: UE1, UE2, Remote Host
38 Client: UE0 (3 clients)
39 UDP Echo Packets transmitted between client and server
40
41 * Pass criteria: 1) Every UDP Echo Request and Reply messages sent and received respectively
42 at UE0 must be matched by their UID, source address, destination address,
43 source port and destination port
44 2) Every request reply must follow proper route (e.g. In case of UE0->UE1,
45 packet must travel this route:
46UE0->ENB0->PGW->ENB1->UE1->ENB1->PGW->ENB0->UE0) 3) The above check also ensures no redundancy of
47the followed route for a packet
48* */
49
50using namespace ns3;
51
59{
60 public:
62 ~LteIpv6RoutingTestCase() override;
63
67 void Checker();
68
75 void SentAtClient(Ptr<const Packet> p, Ptr<Ipv6> ipv6, uint32_t interface);
76
84
89 void EnbToPgw(Ptr<Packet> p);
90
95 void TunToPgw(Ptr<Packet> p);
96
97 private:
98 void DoRun() override;
101 std::list<uint64_t> m_pgwUidRxFrmEnb;
102 std::list<uint64_t>
104
105 std::list<Ptr<Packet>> m_clientTxPkts;
106 std::list<Ptr<Packet>> m_clientRxPkts;
107};
108
110 : TestCase("Test IPv6 Routing at LTE")
111{
112}
113
115{
116}
117
118void
120{
121 Ipv6Header ipv6Header;
122 p->PeekHeader(ipv6Header);
123 if (ipv6Header.GetNextHeader() == UdpL4Protocol::PROT_NUMBER)
124 {
125 m_clientTxPkts.push_back(p->Copy());
126 }
127}
128
129void
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
140void
142{
143 Ipv6Header ipv6Header;
144 p->PeekHeader(ipv6Header);
145 if (ipv6Header.GetNextHeader() == UdpL4Protocol::PROT_NUMBER)
146 {
147 m_pgwUidRxFrmEnb.push_back(p->GetUid());
148 }
149}
150
151void
153{
154 Ipv6Header ipv6Header;
155 p->PeekHeader(ipv6Header);
156 if (ipv6Header.GetNextHeader() == UdpL4Protocol::PROT_NUMBER)
157 {
158 m_pgwUidRxFrmTun.push_back(p->GetUid());
159 }
160}
161
162void
164{
165 bool b = false;
166 bool check = true;
167 // Extract each received reply packet of the client
168 for (std::list<Ptr<Packet>>::iterator it1 = m_clientRxPkts.begin(); it1 != m_clientRxPkts.end();
169 it1++)
170 {
171 Ipv6Header ipv6header1;
172 UdpHeader udpHeader1;
173 Ptr<Packet> p1 = (*it1)->Copy();
174 p1->RemoveHeader(ipv6header1);
175 uint64_t uid = p1->GetUid();
176 p1->RemoveHeader(udpHeader1);
177 // Search each packet in list of sent request packet of the client
178 for (std::list<Ptr<Packet>>::iterator it2 = m_clientTxPkts.begin();
179 it2 != m_clientTxPkts.end();
180 it2++)
181 {
182 Ptr<Packet> p2 = (*it2)->Copy();
183 Ipv6Header ipv6header2;
184 p2->RemoveHeader(ipv6header2);
185 Ipv6Address sorceAddress = ipv6header2.GetSource();
186 Ipv6Address destinationAddress = ipv6header2.GetDestination();
187 UdpHeader udpHeader2;
188 p2->RemoveHeader(udpHeader2);
189 uint16_t sourcePort;
190 uint16_t destinationPort;
191 sourcePort = udpHeader2.GetSourcePort();
192 destinationPort = udpHeader2.GetDestinationPort();
193 // Check whether the uids, addresses and ports match
194 if ((p2->GetUid() == p1->GetUid()) && sorceAddress == ipv6header1.GetDestination() &&
195 destinationAddress == ipv6header1.GetSource() &&
196 sourcePort == udpHeader1.GetDestinationPort() &&
197 destinationPort == udpHeader1.GetSourcePort())
198 {
199 b = true;
200 break;
201 }
202 }
203 check &= b;
204 if (std::find(m_pgwUidRxFrmEnb.begin(), m_pgwUidRxFrmEnb.end(), uid) !=
205 m_pgwUidRxFrmEnb.end())
206 {
207 check &= true;
208 m_pgwUidRxFrmEnb.remove(uid);
209 }
210 if (std::find(m_pgwUidRxFrmTun.begin(), m_pgwUidRxFrmTun.end(), uid) !=
211 m_pgwUidRxFrmTun.end())
212 {
213 check &= true;
214 m_pgwUidRxFrmTun.remove(uid);
215 }
216 b = false;
217 }
218
219 NS_TEST_ASSERT_MSG_EQ(check, true, "Failure Happens IPv6 routing of LENA");
221 m_clientRxPkts.size(),
222 "No. of Request and Reply messages mismatch");
223 NS_TEST_ASSERT_MSG_EQ(m_pgwUidRxFrmEnb.size(), 0, "Route is not Redundant in Lte IPv6 test");
224 NS_TEST_ASSERT_MSG_EQ(m_pgwUidRxFrmTun.size(), 0, "Route is not Redundant in Lte IPv6 test");
225}
226
227void
229{
230 double distance = 60.0;
231
232 Ptr<LteHelper> lteHelper = CreateObject<LteHelper>();
233 Ptr<PointToPointEpcHelper> epcHelper = CreateObject<PointToPointEpcHelper>();
234 lteHelper->SetEpcHelper(epcHelper);
235
236 ConfigStore inputConfig;
237 inputConfig.ConfigureDefaults();
238
239 Ptr<Node> pgw = epcHelper->GetPgwNode();
240
241 // Create a single RemoteHost
242 NodeContainer remoteHostContainer;
243 remoteHostContainer.Create(1);
244 Ptr<Node> remoteHost = remoteHostContainer.Get(0);
245 InternetStackHelper internet;
246 internet.Install(remoteHostContainer);
247
248 // Create the Internet
250 p2ph.SetDeviceAttribute("DataRate", DataRateValue(DataRate("100Gb/s")));
251 p2ph.SetDeviceAttribute("Mtu", UintegerValue(1500));
252 p2ph.SetChannelAttribute("Delay", TimeValue(Seconds(0.010)));
253 NetDeviceContainer internetDevices = p2ph.Install(pgw, remoteHost);
254
255 NodeContainer ueNodes;
256 NodeContainer enbNodes;
257 enbNodes.Create(2);
258 ueNodes.Create(3);
259
260 // Install Mobility Model
261 Ptr<ListPositionAllocator> positionAlloc1 = CreateObject<ListPositionAllocator>();
262 Ptr<ListPositionAllocator> positionAlloc2 = CreateObject<ListPositionAllocator>();
263
264 positionAlloc1->Add(Vector(distance * 0, 0, 0));
265 positionAlloc1->Add(Vector(distance * 0 + 5, 0, 0));
266 positionAlloc1->Add(Vector(distance * 1, 0, 0));
267
268 positionAlloc2->Add(Vector(distance * 0, 0, 0));
269 positionAlloc2->Add(Vector(distance * 1, 0, 0));
270
272 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
273 mobility.SetPositionAllocator(positionAlloc1);
274 mobility.Install(ueNodes);
275
276 mobility.SetPositionAllocator(positionAlloc2);
277 mobility.Install(enbNodes);
278
279 // Install the IP stack on the UEs
280 internet.Install(ueNodes);
281
282 // Install LTE Devices to the nodes
283 NetDeviceContainer enbLteDevs = lteHelper->InstallEnbDevice(enbNodes);
284 NetDeviceContainer ueLteDevs = lteHelper->InstallUeDevice(ueNodes);
285
286 // Assign IP address to UEs, and install applications
287 m_ueIpIface = epcHelper->AssignUeIpv6Address(NetDeviceContainer(ueLteDevs));
288
289 Ipv6StaticRoutingHelper ipv6RoutingHelper;
290
291 for (uint32_t u = 0; u < ueNodes.GetN(); ++u)
292 {
293 Ptr<Node> ueNode = ueNodes.Get(u);
294 // Set the default gateway for the UE
295 Ptr<Ipv6StaticRouting> ueStaticRouting =
296 ipv6RoutingHelper.GetStaticRouting(ueNode->GetObject<Ipv6>());
297 ueStaticRouting->SetDefaultRoute(epcHelper->GetUeDefaultGatewayAddress6(), 1);
298 }
299
300 // Attach two UEs at first eNodeB and one UE at second eNodeB
301 lteHelper->Attach(ueLteDevs.Get(0), enbLteDevs.Get(0));
302 lteHelper->Attach(ueLteDevs.Get(1), enbLteDevs.Get(0));
303 lteHelper->Attach(ueLteDevs.Get(2), enbLteDevs.Get(1));
304
305 Ipv6AddressHelper ipv6h;
306 ipv6h.SetBase(Ipv6Address("6001:db80::"), Ipv6Prefix(64));
307 Ipv6InterfaceContainer internetIpIfaces = ipv6h.Assign(internetDevices);
308
309 internetIpIfaces.SetForwarding(0, true);
310 internetIpIfaces.SetDefaultRouteInAllNodes(0);
311
312 Ptr<Ipv6StaticRouting> remoteHostStaticRouting =
313 ipv6RoutingHelper.GetStaticRouting(remoteHost->GetObject<Ipv6>());
314 remoteHostStaticRouting
315 ->AddNetworkRouteTo("7777:f00d::", Ipv6Prefix(64), internetIpIfaces.GetAddress(0, 1), 1, 0);
316
317 // interface 0 is localhost, 1 is the p2p device
318 m_remoteHostAddr = internetIpIfaces.GetAddress(1, 1);
319
320 // Install and start applications on UEs and remote host
321 UdpEchoServerHelper echoServer1(10);
322 UdpEchoServerHelper echoServer2(11);
323 UdpEchoServerHelper echoServer3(12);
324
325 ApplicationContainer serverApps = echoServer1.Install(remoteHost);
326 serverApps.Add(echoServer2.Install(ueNodes.Get(1)));
327 serverApps.Add(echoServer3.Install(ueNodes.Get(2)));
328
329 serverApps.Start(Seconds(4.0));
330 serverApps.Stop(Seconds(12.0));
331
332 UdpEchoClientHelper echoClient1(m_remoteHostAddr, 10);
333 UdpEchoClientHelper echoClient2(m_ueIpIface.GetAddress(1, 1), 11);
334 UdpEchoClientHelper echoClient3(m_ueIpIface.GetAddress(2, 1), 12);
335
336 echoClient1.SetAttribute("MaxPackets", UintegerValue(1000));
337 echoClient1.SetAttribute("Interval", TimeValue(Seconds(0.2)));
338 echoClient1.SetAttribute("PacketSize", UintegerValue(1024));
339
340 echoClient2.SetAttribute("MaxPackets", UintegerValue(1000));
341 echoClient2.SetAttribute("Interval", TimeValue(Seconds(0.2)));
342 echoClient2.SetAttribute("PacketSize", UintegerValue(1024));
343
344 echoClient3.SetAttribute("MaxPackets", UintegerValue(1000));
345 echoClient3.SetAttribute("Interval", TimeValue(Seconds(0.2)));
346 echoClient3.SetAttribute("PacketSize", UintegerValue(1024));
347
348 ApplicationContainer clientApps1 = echoClient1.Install(ueNodes.Get(0));
349 ApplicationContainer clientApps2 = echoClient2.Install(ueNodes.Get(0));
350 ApplicationContainer clientApps3 = echoClient3.Install(ueNodes.Get(0));
351
352 clientApps1.Start(Seconds(4.0));
353 clientApps1.Stop(Seconds(6.0));
354
355 clientApps2.Start(Seconds(6.1));
356 clientApps2.Stop(Seconds(8.0));
357
358 clientApps3.Start(Seconds(8.1));
359 clientApps3.Stop(Seconds(10.0));
360
361 // Set Cllback for Client Sent and Received packets
362 Ptr<Ipv6L3Protocol> ipL3 = (ueNodes.Get(0))->GetObject<Ipv6L3Protocol>();
363 ipL3->TraceConnectWithoutContext("Tx",
365 ipL3->TraceConnectWithoutContext("Rx",
367
368 // Set Callback at SgwPgWApplication of epc to get the packets from enb and from tunnel net
369 // device
370 Ptr<Application> appPgw = pgw->GetApplication(0);
371 appPgw->TraceConnectWithoutContext("RxFromS1u",
373 appPgw->TraceConnectWithoutContext("RxFromTun",
375
376 Simulator::Schedule(Time(Seconds(12.0)), &LteIpv6RoutingTestCase::Checker, this);
377
378 Simulator::Stop(Seconds(14));
379 Simulator::Run();
380
381 Simulator::Destroy();
382}
383
388{
389 public:
391};
392
394 : TestSuite("lte-ipv6-routing-test", UNIT)
395{
396 AddTestCase(new LteIpv6RoutingTestCase, TestCase::QUICK);
397}
398
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)
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:61
void ConfigureDefaults()
Configure the default values.
AttributeValue implementation for DataRate.
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
uint8_t GetNextHeader() const
Get the next header.
Definition: ipv6-header.cc:88
Ipv6Address GetDestination() const
Get the "Destination address" field.
Definition: ipv6-header.cc:142
Ipv6Address GetSource() const
Get the "Source address" field.
Definition: ipv6-header.cc:118
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:282
NetDeviceContainer InstallEnbDevice(NodeContainer c)
Create a set of eNodeB devices.
Definition: lte-helper.cc:482
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:1044
NetDeviceContainer InstallUeDevice(NodeContainer c)
Create a set of UE devices.
Definition: lte-helper.cc:497
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.
Ipv6Address GetUeDefaultGatewayAddress6() override
Ptr< Node > GetPgwNode() const override
Get the PGW node.
Ipv6InterfaceContainer AssignUeIpv6Address(NetDeviceContainer ueDevices) override
Assign IPv6 addresses to UE devices.
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.
Ptr< Application > GetApplication(uint32_t index) const
Retrieve the index-th Application associated to this node.
Definition: node.cc:180
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:369
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition: object.h:471
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:294
Ptr< Packet > Copy() const
performs a COW copy of the packet.
Definition: packet.cc:131
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:305
uint64_t GetUid() const
Returns the packet's Uid.
Definition: packet.cc:412
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:1060
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:305
A suite of tests to run.
Definition: test.h:1256
AttributeValue implementation for Time.
Definition: nstime.h:1425
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:41
uint16_t GetDestinationPort() const
Definition: udp-header.cc:75
uint16_t GetSourcePort() const
Definition: udp-header.cc:69
Hold an unsigned integer type.
Definition: uinteger.h:45
void(* DataRate)(DataRate oldValue, DataRate newValue)
TracedValue callback signature for DataRate.
Definition: data-rate.h:328
#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:144
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
static LteIpv6RoutingTestSuite lteipv6testsuite
serverApps
Definition: first.py:48
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition: nstime.h:850
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:691
mobility
Definition: third.py:96
#define list