|
|
|
|
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 |
/** |
| 94 |
* \brief search uid in a list and delete if found. |
| 95 |
* \param: l list |
| 96 |
* \param: item a uid |
| 97 |
*/ |
| 98 |
bool SearchAndDelete (std::list<uint64_t> *l, uint64_t item); |
| 99 |
|
| 100 |
|
| 101 |
private: |
| 102 |
virtual void DoRun (void); |
| 103 |
Ipv6InterfaceContainer ueIpIface; //IPv6 interface container for ue |
| 104 |
Ipv6Address remoteHostAddr; //remote host address |
| 105 |
std::list<uint64_t> * EnbPgw; //list of uids of packets received at pgw from enb |
| 106 |
std::list<uint64_t> * TunPgw; //list of uids of packets received at pgw from tunnel net device |
| 107 |
|
| 108 |
std::list<Ptr<Packet> > ClientSent; //list of sent packets from client |
| 109 |
std::list<Ptr<Packet> > ClientReceived; //list of received packets at client |
| 110 |
}; |
| 111 |
|
| 112 |
|
| 113 |
LteIpv6RoutingTestCase::LteIpv6RoutingTestCase () |
| 114 |
: TestCase ("Test IPv6 Routing at LTE") |
| 115 |
{ |
| 116 |
EnbPgw = new std::list<uint64_t>; |
| 117 |
TunPgw = new std::list<uint64_t>; |
| 118 |
} |
| 119 |
|
| 120 |
LteIpv6RoutingTestCase::~LteIpv6RoutingTestCase () |
| 121 |
{ |
| 122 |
} |
| 123 |
|
| 124 |
void LteIpv6RoutingTestCase::SentAtClient (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 |
ClientSent.push_back (p->Copy ()); |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
void LteIpv6RoutingTestCase::ReceivedAtClient (Ptr<const Packet> p, Ptr<Ipv6> ipv6, uint32_t interface) |
| 135 |
{ |
| 136 |
Ipv6Header ipv6Header; |
| 137 |
p->PeekHeader (ipv6Header); |
| 138 |
if (ipv6Header.GetNextHeader () == UdpL4Protocol::PROT_NUMBER) |
| 139 |
{ |
| 140 |
ClientReceived.push_back (p->Copy ()); |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
void LteIpv6RoutingTestCase::EnbToPgw (Ptr<Packet> p) |
| 145 |
{ |
| 146 |
Ipv6Header ipv6Header; |
| 147 |
p->PeekHeader (ipv6Header); |
| 148 |
if (ipv6Header.GetNextHeader () == UdpL4Protocol::PROT_NUMBER) |
| 149 |
{ |
| 150 |
EnbPgw->push_back (p->GetUid ()); |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
void LteIpv6RoutingTestCase::TunToPgw (Ptr<Packet> p) |
| 155 |
{ |
| 156 |
Ipv6Header ipv6Header; |
| 157 |
p->PeekHeader (ipv6Header); |
| 158 |
if (ipv6Header.GetNextHeader () == UdpL4Protocol::PROT_NUMBER) |
| 159 |
{ |
| 160 |
TunPgw->push_back (p->GetUid ()); |
| 161 |
} |
| 162 |
} |
| 163 |
|
| 164 |
bool LteIpv6RoutingTestCase::SearchAndDelete (std::list<uint64_t> *l, uint64_t item) |
| 165 |
{ |
| 166 |
bool b = false; |
| 167 |
std::list<uint64_t>::iterator it; |
| 168 |
it = std::find (l->begin (), l->end (), item); |
| 169 |
if (it != l->end ()) |
| 170 |
{ |
| 171 |
b = true; |
| 172 |
l->erase (it); |
| 173 |
} |
| 174 |
return b; |
| 175 |
} |
| 176 |
|
| 177 |
void LteIpv6RoutingTestCase::Checker () |
| 178 |
{ |
| 179 |
bool b = false; |
| 180 |
bool check = true; |
| 181 |
//Extract each received reply packet of the client |
| 182 |
for (std::list<Ptr<Packet> >::iterator it1 = ClientReceived.begin (); it1 != ClientReceived.end (); it1++) |
| 183 |
{ |
| 184 |
Ipv6Header ipv6header1; |
| 185 |
UdpHeader udpHeader1; |
| 186 |
Ptr<Packet> p1 = (*it1)->Copy (); |
| 187 |
p1->RemoveHeader (ipv6header1); |
| 188 |
uint64_t uid = p1->GetUid (); |
| 189 |
p1->RemoveHeader (udpHeader1); |
| 190 |
//Search each packet in list of sent request packet of the client |
| 191 |
for (std::list<Ptr<Packet> >::iterator it2 = ClientSent.begin (); it2 != ClientSent.end (); it2++) |
| 192 |
{ |
| 193 |
Ptr<Packet> p2 = (*it2)->Copy (); |
| 194 |
Ipv6Header ipv6header2; |
| 195 |
p2->RemoveHeader (ipv6header2); |
| 196 |
Ipv6Address sorceAddress = ipv6header2.GetSourceAddress (); |
| 197 |
Ipv6Address destinationAddress = ipv6header2.GetDestinationAddress (); |
| 198 |
UdpHeader udpHeader2; |
| 199 |
p2->RemoveHeader (udpHeader2); |
| 200 |
uint16_t sourcePort; |
| 201 |
uint16_t destinationPort; |
| 202 |
sourcePort = udpHeader2.GetSourcePort (); |
| 203 |
destinationPort = udpHeader2.GetDestinationPort (); |
| 204 |
//Check whether the uids, addresses and ports match |
| 205 |
if ((p2->GetUid () == p1->GetUid ()) && sorceAddress.IsEqual (ipv6header1.GetDestinationAddress ()) && destinationAddress.IsEqual (ipv6header1.GetSourceAddress ()) && sourcePort == udpHeader1.GetDestinationPort () && destinationPort == udpHeader1.GetSourcePort ()) |
| 206 |
{ |
| 207 |
b = true; |
| 208 |
break; |
| 209 |
} |
| 210 |
} |
| 211 |
check &= b; |
| 212 |
if (ipv6header1.GetSourceAddress ().IsEqual (remoteHostAddr)) |
| 213 |
{ |
| 214 |
check &= (SearchAndDelete (EnbPgw, uid) && SearchAndDelete (TunPgw, uid)); |
| 215 |
} |
| 216 |
else |
| 217 |
{ |
| 218 |
check &= (SearchAndDelete (EnbPgw, uid) && SearchAndDelete (TunPgw, uid) && SearchAndDelete (EnbPgw, uid) && SearchAndDelete (TunPgw, uid)); |
| 219 |
} |
| 220 |
|
| 221 |
b = false; |
| 222 |
} |
| 223 |
|
| 224 |
NS_TEST_ASSERT_MSG_EQ (check, true, "Failure Happens IPv6 routing of LENA"); |
| 225 |
NS_TEST_ASSERT_MSG_EQ (ClientSent.size (), ClientReceived.size (), "No. of Request and Reply messages mismatch"); |
| 226 |
NS_TEST_ASSERT_MSG_EQ (EnbPgw->size (), 0, "Route is not Redundant in Lte IPv6 test"); |
| 227 |
NS_TEST_ASSERT_MSG_EQ (TunPgw->size (), 0, "Route is not Redundant in Lte IPv6 test"); |
| 228 |
|
| 229 |
} |
| 230 |
|
| 231 |
void |
| 232 |
LteIpv6RoutingTestCase::DoRun (void) |
| 233 |
{ |
| 234 |
double distance = 60.0; |
| 235 |
|
| 236 |
Ptr<LteHelper> lteHelper = CreateObject<LteHelper> (); |
| 237 |
Ptr<PointToPointEpcHelper> epcHelper = CreateObject<PointToPointEpcHelper> (); |
| 238 |
lteHelper->SetEpcHelper (epcHelper); |
| 239 |
|
| 240 |
ConfigStore inputConfig; |
| 241 |
inputConfig.ConfigureDefaults (); |
| 242 |
|
| 243 |
Ptr<Node> pgw = epcHelper->GetPgwNode (); |
| 244 |
|
| 245 |
// Create a single RemoteHost |
| 246 |
NodeContainer remoteHostContainer; |
| 247 |
remoteHostContainer.Create (1); |
| 248 |
Ptr<Node> remoteHost = remoteHostContainer.Get (0); |
| 249 |
InternetStackHelper internet; |
| 250 |
internet.Install (remoteHostContainer); |
| 251 |
|
| 252 |
// Create the Internet |
| 253 |
PointToPointHelper p2ph; |
| 254 |
p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s"))); |
| 255 |
p2ph.SetDeviceAttribute ("Mtu", UintegerValue (1500)); |
| 256 |
p2ph.SetChannelAttribute ("Delay", TimeValue (Seconds (0.010))); |
| 257 |
NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost); |
| 258 |
|
| 259 |
NodeContainer ueNodes; |
| 260 |
NodeContainer enbNodes; |
| 261 |
enbNodes.Create (2); |
| 262 |
ueNodes.Create (3); |
| 263 |
|
| 264 |
// Install Mobility Model |
| 265 |
Ptr<ListPositionAllocator> positionAlloc1 = CreateObject<ListPositionAllocator> (); |
| 266 |
Ptr<ListPositionAllocator> positionAlloc2 = CreateObject<ListPositionAllocator> (); |
| 267 |
|
| 268 |
positionAlloc1->Add (Vector (distance * 0, 0, 0)); |
| 269 |
positionAlloc1->Add (Vector (distance * 0 + 5, 0, 0)); |
| 270 |
positionAlloc1->Add (Vector (distance * 1, 0, 0)); |
| 271 |
|
| 272 |
positionAlloc2->Add (Vector (distance * 0, 0, 0)); |
| 273 |
positionAlloc2->Add (Vector (distance * 1, 0, 0)); |
| 274 |
|
| 275 |
MobilityHelper mobility; |
| 276 |
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); |
| 277 |
mobility.SetPositionAllocator (positionAlloc1); |
| 278 |
mobility.Install (ueNodes); |
| 279 |
|
| 280 |
mobility.SetPositionAllocator (positionAlloc2); |
| 281 |
mobility.Install (enbNodes); |
| 282 |
|
| 283 |
// Install the IP stack on the UEs |
| 284 |
internet.Install (ueNodes); |
| 285 |
|
| 286 |
// Install LTE Devices to the nodes |
| 287 |
NetDeviceContainer enbLteDevs = lteHelper->InstallEnbDevice (enbNodes); |
| 288 |
NetDeviceContainer ueLteDevs = lteHelper->InstallUeDevice (ueNodes); |
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
for (NetDeviceContainer::Iterator it = ueLteDevs.Begin (); it != ueLteDevs.End (); ++it) |
| 293 |
{ |
| 294 |
(*it)->SetAddress (Mac64Address::Allocate ()); |
| 295 |
} |
| 296 |
|
| 297 |
// Assign IP address to UEs, and install applications |
| 298 |
ueIpIface = epcHelper->AssignUeIpv6Address (NetDeviceContainer (ueLteDevs)); |
| 299 |
|
| 300 |
|
| 301 |
Ipv6StaticRoutingHelper ipv6RoutingHelper; |
| 302 |
|
| 303 |
for (uint32_t u = 0; u < ueNodes.GetN (); ++u) |
| 304 |
{ |
| 305 |
Ptr<Node> ueNode = ueNodes.Get (u); |
| 306 |
// Set the default gateway for the UE |
| 307 |
Ptr<Ipv6StaticRouting> ueStaticRouting = ipv6RoutingHelper.GetStaticRouting (ueNode->GetObject<Ipv6> ()); |
| 308 |
ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress6 (), 1); |
| 309 |
} |
| 310 |
|
| 311 |
|
| 312 |
// Attach two UEs at first eNodeB and one UE at second eNodeB |
| 313 |
lteHelper->Attach (ueLteDevs.Get (0), enbLteDevs.Get (0)); |
| 314 |
lteHelper->Attach (ueLteDevs.Get (1), enbLteDevs.Get (0)); |
| 315 |
lteHelper->Attach (ueLteDevs.Get (2), enbLteDevs.Get (1)); |
| 316 |
|
| 317 |
|
| 318 |
Ipv6AddressHelper ipv6h; |
| 319 |
ipv6h.SetBase (Ipv6Address ("6001:db80::"), Ipv6Prefix (64)); |
| 320 |
Ipv6InterfaceContainer internetIpIfaces = ipv6h.Assign (internetDevices); |
| 321 |
|
| 322 |
internetIpIfaces.SetForwarding (0, true); |
| 323 |
internetIpIfaces.SetDefaultRouteInAllNodes (0); |
| 324 |
|
| 325 |
|
| 326 |
Ptr<Ipv6StaticRouting> remoteHostStaticRouting = ipv6RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv6> ()); |
| 327 |
remoteHostStaticRouting->AddNetworkRouteTo ("7777:f00d::", Ipv6Prefix (64), internetIpIfaces.GetAddress (0, 1), 1, 0); |
| 328 |
|
| 329 |
|
| 330 |
// interface 0 is localhost, 1 is the p2p device |
| 331 |
remoteHostAddr = internetIpIfaces.GetAddress (1, 1); |
| 332 |
|
| 333 |
|
| 334 |
// Install and start applications on UEs and remote host |
| 335 |
UdpEchoServerHelper echoServer1 (10); |
| 336 |
UdpEchoServerHelper echoServer2 (11); |
| 337 |
UdpEchoServerHelper echoServer3 (12); |
| 338 |
|
| 339 |
ApplicationContainer serverApps = echoServer1.Install (remoteHost); |
| 340 |
serverApps.Add (echoServer2.Install (ueNodes.Get (1))); |
| 341 |
serverApps.Add (echoServer3.Install (ueNodes.Get (2))); |
| 342 |
|
| 343 |
|
| 344 |
serverApps.Start (Seconds (4.0)); |
| 345 |
serverApps.Stop (Seconds (12.0)); |
| 346 |
|
| 347 |
|
| 348 |
UdpEchoClientHelper echoClient1 (remoteHostAddr, 10); |
| 349 |
UdpEchoClientHelper echoClient2 (ueIpIface.GetAddress (1,1), 11); |
| 350 |
UdpEchoClientHelper echoClient3 (ueIpIface.GetAddress (2,1), 12); |
| 351 |
|
| 352 |
echoClient1.SetAttribute ("MaxPackets", UintegerValue (1000)); |
| 353 |
echoClient1.SetAttribute ("Interval", TimeValue (Seconds (0.2))); |
| 354 |
echoClient1.SetAttribute ("PacketSize", UintegerValue (1024)); |
| 355 |
|
| 356 |
echoClient2.SetAttribute ("MaxPackets", UintegerValue (1000)); |
| 357 |
echoClient2.SetAttribute ("Interval", TimeValue (Seconds (0.2))); |
| 358 |
echoClient2.SetAttribute ("PacketSize", UintegerValue (1024)); |
| 359 |
|
| 360 |
echoClient3.SetAttribute ("MaxPackets", UintegerValue (1000)); |
| 361 |
echoClient3.SetAttribute ("Interval", TimeValue (Seconds (0.2))); |
| 362 |
echoClient3.SetAttribute ("PacketSize", UintegerValue (1024)); |
| 363 |
|
| 364 |
ApplicationContainer clientApps1 = echoClient1.Install (ueNodes.Get (0)); |
| 365 |
ApplicationContainer clientApps2 = echoClient2.Install (ueNodes.Get (0)); |
| 366 |
ApplicationContainer clientApps3 = echoClient3.Install (ueNodes.Get (0)); |
| 367 |
|
| 368 |
clientApps1.Start (Seconds (4.0)); |
| 369 |
clientApps1.Stop (Seconds (6.0)); |
| 370 |
|
| 371 |
clientApps2.Start (Seconds (6.1)); |
| 372 |
clientApps2.Stop (Seconds (8.0)); |
| 373 |
|
| 374 |
clientApps3.Start (Seconds (8.1)); |
| 375 |
clientApps3.Stop (Seconds (10.0)); |
| 376 |
|
| 377 |
EnbPgw = new std::list<uint64_t>; |
| 378 |
TunPgw = new std::list<uint64_t>; |
| 379 |
|
| 380 |
//Set Cllback for Client Sent and Received packets |
| 381 |
Ptr<Ipv6L3Protocol> ipl3 = (ueNodes.Get (0))->GetObject<Ipv6L3Protocol> (); |
| 382 |
ipl3->TraceConnectWithoutContext ("Tx", MakeCallback (&LteIpv6RoutingTestCase::SentAtClient, this)); |
| 383 |
ipl3->TraceConnectWithoutContext ("Rx", MakeCallback (&LteIpv6RoutingTestCase::ReceivedAtClient, this)); |
| 384 |
|
| 385 |
//Set Callback at SgwPgWApplication of epc to get the packets from enb and from tunnel net device |
| 386 |
Ptr<Application> apppgw = pgw->GetApplication (0); |
| 387 |
apppgw->TraceConnectWithoutContext ("RxfromS1u", MakeCallback (&LteIpv6RoutingTestCase::EnbToPgw, this)); |
| 388 |
apppgw->TraceConnectWithoutContext ("RxfromTun", MakeCallback (&LteIpv6RoutingTestCase::TunToPgw, this)); |
| 389 |
|
| 390 |
Simulator::Schedule (Time (Seconds (12.0)), &LteIpv6RoutingTestCase::Checker, this); |
| 391 |
|
| 392 |
Simulator::Stop (Seconds (14)); |
| 393 |
Simulator::Run (); |
| 394 |
|
| 395 |
Simulator::Destroy (); |
| 396 |
} |
| 397 |
|
| 398 |
|
| 399 |
/** |
| 400 |
* \brief test suite 1 |
| 401 |
*/ |
| 402 |
class LteIpv6RoutingTestSuite : public TestSuite |
| 403 |
{ |
| 404 |
public: |
| 405 |
LteIpv6RoutingTestSuite (); |
| 406 |
}; |
| 407 |
|
| 408 |
LteIpv6RoutingTestSuite::LteIpv6RoutingTestSuite () |
| 409 |
: TestSuite ("lte-ipv6-routing-test", UNIT) |
| 410 |
{ |
| 411 |
AddTestCase (new LteIpv6RoutingTestCase, TestCase::QUICK); |
| 412 |
} |
| 413 |
|
| 414 |
static LteIpv6RoutingTestSuite lteipv6testsuite; |