Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include ns 3 / core - module.h #include ns 3 / network - module.h #include ns 3 / internet -

#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/applications-module.h"
#include "ns3/mobility-module.h"
#include "ns3/olsr-helper.h"
#include "ns3/aodv-helper.h"
#include "ns3/wifi-module.h"
#include "ns3/flow-monitor-module.h"
#include "ns3/netanim-module.h"
#include
#include
#include "ns3/flow-monitor-module.h"
#include "ns3/aodv-module.h"
#include "ns3/olsr-module.h"
using namespace ns3;
NS_LOG_COMPONENT_DEFINE("HybridAodvOlsrExample");
static uint32_t totalPacketsSent =0;
static uint32_t totalPacketsReceived =0;
static uint32_t totalAodvPacketsSent =0;
static uint32_t totalAodvPacketsReceived =0;
static uint32_t totalOlsrPacketsSent =0;
static uint32_t totalOlsrPacketsReceived =0;
const uint32_t targetPacketsReceived =1024;
bool isAodvTurn = true; // Global flag to alternate between AODV and OLSR
// Inside ReceivePacket function
//void ReceivePacket(Ptr socket){
// Ptr packet;
// while ((packet = socket->Recv())){
// Increment the total packets received counter
// totalPacketsReceived++;
// Check the port to determine AODV or OLSR packet
// Address localAddress;
// socket->GetSockName(localAddress);
// InetSocketAddress inetSocketAddress = InetSocketAddress::ConvertFrom(localAddress);
// if (inetSocketAddress.GetPort()==8080){
// totalAodvPacketsReceived++;
//} else if (inetSocketAddress.GetPort()==8081){
// totalOlsrPacketsReceived++;
//}
// Log packet details and counts
// NS_LOG_UNCOND("Received Packet of size: "<< packet->GetSize()
//<<"| AODV: "<< totalAodvPacketsReceived
//<<"| OLSR: "<< totalOlsrPacketsReceived);
// Stop the simulation if the target is reached
// if (totalPacketsReceived >= targetPacketsReceived){
// Simulator::Stop();
// break;
//}
//}
//}
//void ReceivePacket(Ptr socket){
// Ptr packet;
// while ((packet = socket->Recv())){
// totalPacketsReceived++;
// Determine the routing protocol used by the node
// Ptr ipv4= socket->GetNode()->GetObject();
// Ptr routingProtocol = ipv4->GetRoutingProtocol();
// if (DynamicCast(routingProtocol)){
// totalAodvPacketsReceived++;
// std::cout << "Received AODV Packet. Total AODV Packets Received: "<< totalAodvPacketsReceived << std::endl;
//} else if (DynamicCast(routingProtocol)){
// totalOlsrPacketsReceived++;
// std::cout << "Received OLSR Packet. Total OLSR Packets Received: "<< totalOlsrPacketsReceived << std::endl;
//}
// std::cout << "Total Packets Received: "<< totalPacketsReceived << std::endl;
// Stop the reception if the target number of packets has been received
// if (totalPacketsReceived >=1024){
// break; // Stop processing further packets
//}
//}
//}/
//void SetupReceivingSockets(NodeContainer nodes, Ipv4InterfaceContainer interfaces){
// for (uint32_t i =0; i < nodes.GetN(); ++i){
// AODV Receive Socket Setup
// Ptr aodvRecvSocket = Socket::CreateSocket(nodes.Get(i), TypeId::LookupByName("ns3::UdpSocketFactory"));
// InetSocketAddress aodvLocalAddr(Ipv4Address::GetAny(),8080);
// aodvRecvSocket->Bind(aodvLocalAddr);
// aodvRecvSocket->SetRecvCallback(MakeCallback(&ReceivePacket));
// OLSR Receive Socket Setup
// Ptr olsrRecvSocket = Socket::CreateSocket(nodes.Get(i), TypeId::LookupByName("ns3::UdpSocketFactory"));
// InetSocketAddress olsrLocalAddr(Ipv4Address::GetAny(),8081);
// olsrRecvSocket->Bind(olsrLocalAddr);
// olsrRecvSocket->SetRecvCallback(MakeCallback(&ReceivePacket));
//}
//}
//void ReceivePacket(Ptr socket){
// Ptr packet;
// while ((packet = socket->Recv())){
// totalPacketsReceived++;
// NS_LOG_UNCOND("Received packet of size: "<< packet->GetSize());
//}
//}
//void ReceivePacket(Ptr socket){
// Ptr packet;
// while ((packet = socket->Recv())){
// NS_LOG_UNCOND("Received Packet of size: "<< packet->GetSize());
// Address localAddress;
// socket->GetSockName(localAddress);
// InetSocketAddress inetSocketAddress = InetSocketAddress::ConvertFrom(localAddress);
// if (inetSocketAddress.GetPort()==8080){
// Increment the count for AODV packets
// totalAodvPacketsReceived++;
// NS_LOG_UNCOND("AODV Packet Received. Size: "<< packet->GetSize(Average End-to-End Delay: -nan s
Total Packets Sent: 1024
Total Packets Received: 59
Total AODV Packets Sent: 0
Total AODV Packets Recei wrte me code to receiv more total packets

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_2

Step: 3

blur-text-image_3

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

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

More Books

Students also viewed these Databases questions