Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/ / . . . ( Previous code ) / / Function to send a specified number of hybrid RREQ packets void SendHybridRREQ ( Ptr

//...(Previous code)
// Function to send a specified number of hybrid RREQ packets
void SendHybridRREQ(Ptr source, Ipv4Address destAddress, uint32_t numPackets){
for (uint32_t i =0; i < numPackets; ++i){
CustomAODVRouteRequest(source, destAddress);
}
}
// Function to measure PDR, E2ED, throughput, and routing overhead
void MeasurePerformance(uint32_t numNodes, uint32_t numPackets){
//...(Your measurement logic goes here)
// Perform simulations with different numbers of nodes and packets
}
int main(){
//...(Previous code)
// Send 100,1000,5000 hybrid RREQ packets for 20,30,50,100 nodes
for (uint32_t numNodes : {20,30,50,100}){
NodeContainer nodes;
nodes.Create(numNodes);
//...(Rest of the setup logic)
// Send hybrid RREQ packets
Ipv4Address destAddress("192.168.1.2");
SendHybridRREQ(nodes.Get(0), destAddress, 100);
SendHybridRREQ(nodes.Get(0), destAddress, 1000);
SendHybridRREQ(nodes.Get(0), destAddress, 5000);
//...(Run simulation, measure performance, etc.)
}
// Perform additional simulations and measurements as requested
MeasurePerformance(10,1000);
MeasurePerformance(20,1000);
MeasurePerformance(30,1000);
MeasurePerformance(50,1000);
MeasurePerformance(100,1000);
MeasurePerformance(1000,1000);
//...(Rest of the main function)
} write me the whole code so can run it for ns 3.36.1 #include
"
ns
3
/
core
-
module.h
"
#include
"
ns
3
/
network
-
module.h
"
#include
"
ns
3
/
mobility
-
module.h
"
#include
"
ns
3
/
internet
-
module.h
"
#include
"
ns
3
/
applications
-
module.h
"
#include
"
ns
3
/
aodv
-
module.h
"
#include
"
ns
3
/
olsr
-
module.h
"
using namespace ns
3
;
enum RoutingProtocol
{
AODV, OLSR, HYBRID
}
;
struct RouteEntry
{
Ipv
4
Address dest;
Ipv
4
Address nextHop;
RoutingProtocol protocol;
RouteEntry
(
Ipv
4
Address dest, Ipv
4
Address nextHop, RoutingProtocol protocol
)
: dest
(
dest
)
,
nextHop
(
nextHop
)
,
protocol
(
protocol
)
{
}
}
;
std::vector routingTable;
bool IsAODVZone
(
Ptr node
)
{
/
/
Placeholder logic for AODV zone determination
return false;
}
void CustomAODVRouteRequest
(
Ptr source, Ipv
4
Address destAddress
)
{
Ptr packet
=
Create
(
)
;
Ipv
4
Header ipvHeader;
ipvHeader.SetSource
(
source
-
>
GetObject
(
)
-
>
GetAddress
(
1
,
0
)
.
GetLocal
(
)
)
;
ipvHeader.SetDestination
(
destAddress
)
;
packet
-
>
AddHeader
(
ipvHeader
)
;
packet
-
>
AddHeader
(
AodvHeader
(
)
)
;
source
-
>
Send
(
packet
)
;
}
void CustomAODVRouteReply
(
Ptr node, RouteEntry route
)
{
Ptr reply
=
Create
(
)
;
reply
-
>
AddHeader
(
route
)
;
node
-
>
Send
(
reply
)
;
}
void HybridRoutingLogic
(
Ptr node, Ipv
4
Address destAddress
)
{
if
(
IsAODVZone
(
node
)
)
{
CustomAODVRouteRequest
(
node
,
destAddress
)
;
}
else
{
/
/
Placeholder for OLSR logic
/
/
You can implement your OLSR routing logic here
/
/
For simplicity, this example does not include detailed OLSR logic
/
/
For now, let's assume OLSR does nothing
}
}
class PacketMonitor
{
public:
PacketMonitor
(
)
: lostPackets
(
0
)
{
}
void CheckForLostPackets
(
Ptr packet
)
{
if
(
!
packet
-
>
Received
(
)
)
{
lostPackets
+
+
;
}
}
int GetLostPackets
(
)
{
return lostPackets;
}
private:
int lostPackets;
}
;
int main
(
)
{
NodeContainer nodes;
nodes.Create
(
10
)
;
MobilityHelper mobility;
mobility.SetMobilityModel
(
"
ns
3
::RandomWalk
2
dMobilityModel",
"MinSpeed", StringValue
(
"
1.0
"
)
,
"MaxSpeed", StringValue
(
"
10.0
"
)
)
;
mobility.Install
(
nodes
)
;
InternetStackHelper internet;
internet.Install
(
nodes
)
;
AodvHelper aodv;
OlsrHelper olsr;
Ipv
4
StaticRoutingHelper staticRouting;
Ipv
4
AddressHelper address;
RoutingProtocol currentProtocol
=
AODV;
PacketMonitor monitor;
Ipv
4
Address destAddress
(
"
192.168
.
1.2
"
)
;
/
/
Assign IP addresses
address.SetBase
(
"
192.168
.
1.0
"
,
"
255.255
.
255.0
"

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Demystified

Authors: Andrew Oppel

1st Edition

0072253649, 9780072253641

More Books

Students also viewed these Databases questions

Question

Discuss the advantages and disadvantages of cloud computing.

Answered: 1 week ago

Question

What are the role of supervisors ?

Answered: 1 week ago