Question: #include ns 3 / core - module.h #include ns 3 / network - module.h #include ns 3 / mobility -

#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/mobility-module.h"
#include "ns3/internet-module.h"
#include "ns3/applications-module.h"
#include "ns3/aodv-module.h"
#include "ns3/olsr-module.h"
using namespace ns3;
enum RoutingProtocol { AODV, OLSR, HYBRID };
struct RouteEntry {
Ipv4Address dest;
Ipv4Address nextHop;
RoutingProtocol protocol;
RouteEntry(Ipv4Address dest, Ipv4Address 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, Ipv4Address destAddress){
Ptr packet = Create();
Ipv4Header 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, Ipv4Address 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("ns3::RandomWalk2dMobilityModel",
"MinSpeed", StringValue("1.0"),
"MaxSpeed", StringValue("10.0"));
mobility.Install(nodes);
InternetStackHelper internet;
internet.Install(nodes);
AodvHelper aodv;
OlsrHelper olsr;
Ipv4StaticRoutingHelper staticRouting;
Ipv4AddressHelper address;
RoutingProtocol currentProtocol = AODV;
PacketMonitor monitor;
Ipv4Address destAddress("192.168.1.2");
// Assign IP addresses
address.SetBase("192.168.1.0","255.255.255.0");
Ipv4InterfaceContainer interfaces = address.Assign(nodes);
// Install AODV or OLSR routing
if (currentProtocol == AODV){
aodv.Install(nodes);
} else if (currentProtocol == OLSR){
olsr.Install(nodes);
}
// Install applications
UdpEchoClientHelper clientHelper(interfaces.GetAddress(0),1024);
UdpEchoServerHelper serverHelper(1024);
serverHelper.Install(nodes.Get(9));
clientHelper.Install(nodes.Get(0));
Simulator::Run(10.0);
if (currentProtocol == AODV){
std::cout << "AODV lost packets: "<< monitor.GetLostPackets()<< std::endl;
} else if (currentProtocol == OLSR){
std::cout << "OLSR lost packets: "<< monitor.GetLostPackets()<< std::endl;
}
// Switch to AODV at time 5.0s
currentProtocol = AODV;
// Reinstall AODV routing
if (currentProtocol == AODV){
aodv.Install(nodes);
}
// Install applications for the second run
UdpEchoClientHelper clientHelper2(interfaces.GetAddress(0),1024);
UdpEchoServerHelper serverHelper2(1024);
serverHelper2.Install(nodes.Get(9));
clientHelper2.Install(nodes.Get(0));
Simulator::Run(10.0);
if (currentProtocol == AODV){
std::cout << "AODV lost packets: "<< monitor.GetLostPackets()<< std::endl;
} else if (currentProtocol == OLSR){
std::cout << "OLSR lost packets: "<< monitor.GetLostPackets()<< std::endl;
}
// Print additional information as requested
for (uint32_t i =0; i < nodes.GetN(); ++i){
Ptr ipv4= nodes.Get(i)->GetObject();
Ipv4Address nodeAddress = ipv4->GetAddress(1,0).GetLocal();
std::cout << "Node "<< i <<" IP Address: "<< nodeAddress << std::endl;
// Print other information as needed
}
Simulator::Destroy();
return 0;
} writ eme hybrid rreq, rrep, rerr, for this code send me 100,1000,5000 packets from hybrid rreq for 20,30,50,100, nodes . sent 1000 hybrid rreq, hybrid rerr, hybrid tc, mpt, neighbor for urban scenario code ns 3.36.1 measure performance of pdr e2ed ,throughput ,routing overhead of hybrid rreqi rerr,rreqfor 10,20,30,50,100,1000 nodes

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!