|
|
|
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 |
|
54 |
class LteIpv6RoutingTestCase : public TestCase |
55 |
{ |
56 |
public: |
57 |
LteIpv6RoutingTestCase (); |
58 |
virtual ~LteIpv6RoutingTestCase (); |
59 |
|
60 |
/** |
61 |
* \brief Initialize testing parameters. |
62 |
*/ |
63 |
void Checker (); |
64 |
|
65 |
/** |
66 |
* \brief sent Packets from client's IPv6 interface. |
67 |
* \param: p packet |
68 |
* \param: ipv6 Ipv6 object |
69 |
* \param: interface Ipv6interface from which the packet is transmitted |
70 |
*/ |
71 |
void SentAtClient (Ptr<const Packet> p, Ptr<Ipv6> ipv6, uint32_t interface); |
72 |
|
73 |
/** |
74 |
* \brief Received Packets at client's IPv6 interface. |
75 |
* \param: p packet |
76 |
* \param: ipv6 Ipv6 object |
77 |
* \param: interface Ipv6interface at which the packet is received |
78 |
*/ |
79 |
void ReceivedAtClient (Ptr<const Packet> p, Ptr<Ipv6> ipv6, uint32_t interface); |
80 |
|
81 |
/** |
82 |
* \brief Received Packet at pgw from enb. |
83 |
* \param: p packet |
84 |
*/ |
85 |
void EnbToPgw (Ptr<Packet> p); |
86 |
|
87 |
/** |
88 |
* \brief Received Packet at pgw from enb. |
89 |
* \param: p packet |
90 |
*/ |
91 |
void TunToPgw (Ptr<Packet> p); |
92 |
|
93 |
private: |
94 |
virtual void DoRun (void); |
95 |
Ipv6InterfaceContainer m_ueIpIface; //!< IPv6 interface container for ue |
96 |
Ipv6Address m_remoteHostAddr; //!< remote host address |
97 |
std::list<uint64_t> m_pgwUidRxFrmEnb; //!< list of uids of packets received at pgw from enb |
98 |
std::list<uint64_t> m_pgwUidRxFrmTun; //!< list of uids of packets received at pgw from tunnel net device |
99 |
|
100 |
std::list<Ptr<Packet> > m_clientTxPkts; //!< list of sent packets from client |
101 |
std::list<Ptr<Packet> > m_clientRxPkts; //!< list of received packets at client |
102 |
}; |
103 |
|
104 |
|
105 |
LteIpv6RoutingTestCase::LteIpv6RoutingTestCase () |
106 |
: TestCase ("Test IPv6 Routing at LTE") |
107 |
{ |
108 |
} |
109 |
|
110 |
LteIpv6RoutingTestCase::~LteIpv6RoutingTestCase () |
111 |
{ |
112 |
} |
113 |
|
114 |
void LteIpv6RoutingTestCase::SentAtClient (Ptr<const Packet> p, Ptr<Ipv6> ipv6, uint32_t interface) |
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 |
|
124 |
void LteIpv6RoutingTestCase::ReceivedAtClient (Ptr<const Packet> p, Ptr<Ipv6> ipv6, uint32_t interface) |
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 |
|
134 |
void LteIpv6RoutingTestCase::EnbToPgw (Ptr<Packet> p) |
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 |
|
144 |
void LteIpv6RoutingTestCase::TunToPgw (Ptr<Packet> p) |
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 |
|
154 |
void LteIpv6RoutingTestCase::Checker () |
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 |
// if (ipv6header1.GetSourceAddress ().IsEqual (m_remoteHostAddr)) |
200 |
// { |
201 |
// check &= (SearchAndDelete (m_enbPgw, uid) && SearchAndDelete (m_tunPgw, uid)); |
202 |
// } |
203 |
// else |
204 |
// { |
205 |
// check &= (SearchAndDelete (m_enbPgw, uid) && SearchAndDelete (m_tunPgw, uid) && |
206 |
// SearchAndDelete (m_enbPgw, uid) && SearchAndDelete (m_tunPgw, uid)); |
207 |
// } |
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 |
220 |
LteIpv6RoutingTestCase::DoRun (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 |
|
263 |
MobilityHelper mobility; |
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 |
|
279 |
|
280 |
for (NetDeviceContainer::Iterator it = ueLteDevs.Begin (); it != ueLteDevs.End (); ++it) |
281 |
{ |
282 |
(*it)->SetAddress (Mac64Address::Allocate ()); |
283 |
} |
284 |
|
285 |
// Assign IP address to UEs, and install applications |
286 |
m_ueIpIface = epcHelper->AssignUeIpv6Address (NetDeviceContainer (ueLteDevs)); |
287 |
|
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 = ipv6RoutingHelper.GetStaticRouting (ueNode->GetObject<Ipv6> ()); |
296 |
ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress6 (), 1); |
297 |
} |
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 |
|
306 |
Ipv6AddressHelper ipv6h; |
307 |
ipv6h.SetBase (Ipv6Address ("6001:db80::"), Ipv6Prefix (64)); |
308 |
Ipv6InterfaceContainer internetIpIfaces = ipv6h.Assign (internetDevices); |
309 |
|
310 |
internetIpIfaces.SetForwarding (0, true); |
311 |
internetIpIfaces.SetDefaultRouteInAllNodes (0); |
312 |
|
313 |
|
314 |
Ptr<Ipv6StaticRouting> remoteHostStaticRouting = ipv6RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv6> ()); |
315 |
remoteHostStaticRouting->AddNetworkRouteTo ("7777:f00d::", Ipv6Prefix (64), internetIpIfaces.GetAddress (0, 1), 1, 0); |
316 |
|
317 |
|
318 |
// interface 0 is localhost, 1 is the p2p device |
319 |
m_remoteHostAddr = internetIpIfaces.GetAddress (1, 1); |
320 |
|
321 |
|
322 |
// Install and start applications on UEs and remote host |
323 |
UdpEchoServerHelper echoServer1 (10); |
324 |
UdpEchoServerHelper echoServer2 (11); |
325 |
UdpEchoServerHelper echoServer3 (12); |
326 |
|
327 |
ApplicationContainer serverApps = echoServer1.Install (remoteHost); |
328 |
serverApps.Add (echoServer2.Install (ueNodes.Get (1))); |
329 |
serverApps.Add (echoServer3.Install (ueNodes.Get (2))); |
330 |
|
331 |
|
332 |
serverApps.Start (Seconds (4.0)); |
333 |
serverApps.Stop (Seconds (12.0)); |
334 |
|
335 |
|
336 |
UdpEchoClientHelper echoClient1 (m_remoteHostAddr, 10); |
337 |
UdpEchoClientHelper echoClient2 (m_ueIpIface.GetAddress (1,1), 11); |
338 |
UdpEchoClientHelper echoClient3 (m_ueIpIface.GetAddress (2,1), 12); |
339 |
|
340 |
echoClient1.SetAttribute ("MaxPackets", UintegerValue (1000)); |
341 |
echoClient1.SetAttribute ("Interval", TimeValue (Seconds (0.2))); |
342 |
echoClient1.SetAttribute ("PacketSize", UintegerValue (1024)); |
343 |
|
344 |
echoClient2.SetAttribute ("MaxPackets", UintegerValue (1000)); |
345 |
echoClient2.SetAttribute ("Interval", TimeValue (Seconds (0.2))); |
346 |
echoClient2.SetAttribute ("PacketSize", UintegerValue (1024)); |
347 |
|
348 |
echoClient3.SetAttribute ("MaxPackets", UintegerValue (1000)); |
349 |
echoClient3.SetAttribute ("Interval", TimeValue (Seconds (0.2))); |
350 |
echoClient3.SetAttribute ("PacketSize", UintegerValue (1024)); |
351 |
|
352 |
ApplicationContainer clientApps1 = echoClient1.Install (ueNodes.Get (0)); |
353 |
ApplicationContainer clientApps2 = echoClient2.Install (ueNodes.Get (0)); |
354 |
ApplicationContainer clientApps3 = echoClient3.Install (ueNodes.Get (0)); |
355 |
|
356 |
clientApps1.Start (Seconds (4.0)); |
357 |
clientApps1.Stop (Seconds (6.0)); |
358 |
|
359 |
clientApps2.Start (Seconds (6.1)); |
360 |
clientApps2.Stop (Seconds (8.0)); |
361 |
|
362 |
clientApps3.Start (Seconds (8.1)); |
363 |
clientApps3.Stop (Seconds (10.0)); |
364 |
|
365 |
//Set Cllback for Client Sent and Received packets |
366 |
Ptr<Ipv6L3Protocol> ipL3 = (ueNodes.Get (0))->GetObject<Ipv6L3Protocol> (); |
367 |
ipL3->TraceConnectWithoutContext ("Tx", MakeCallback (&LteIpv6RoutingTestCase::SentAtClient, this)); |
368 |
ipL3->TraceConnectWithoutContext ("Rx", MakeCallback (&LteIpv6RoutingTestCase::ReceivedAtClient, this)); |
369 |
|
370 |
//Set Callback at SgwPgWApplication of epc to get the packets from enb and from tunnel net device |
371 |
Ptr<Application> appPgw = pgw->GetApplication (0); |
372 |
appPgw->TraceConnectWithoutContext ("RxFromS1u", MakeCallback (&LteIpv6RoutingTestCase::EnbToPgw, this)); |
373 |
appPgw->TraceConnectWithoutContext ("RxFromTun", MakeCallback (&LteIpv6RoutingTestCase::TunToPgw, this)); |
374 |
|
375 |
Simulator::Schedule (Time (Seconds (12.0)), &LteIpv6RoutingTestCase::Checker, this); |
376 |
|
377 |
Simulator::Stop (Seconds (14)); |
378 |
Simulator::Run (); |
379 |
|
380 |
Simulator::Destroy (); |
381 |
} |
382 |
|
383 |
|
384 |
/** |
385 |
* \brief test suite 1 |
386 |
*/ |
387 |
class LteIpv6RoutingTestSuite : public TestSuite |
388 |
{ |
389 |
public: |
390 |
LteIpv6RoutingTestSuite (); |
391 |
}; |
392 |
|
393 |
LteIpv6RoutingTestSuite::LteIpv6RoutingTestSuite () |
394 |
: TestSuite ("lte-ipv6-routing-test", UNIT) |
395 |
{ |
396 |
AddTestCase (new LteIpv6RoutingTestCase, TestCase::QUICK); |
397 |
} |
398 |
|
399 |
static LteIpv6RoutingTestSuite lteipv6testsuite; |