To develop the Next-Hop Routing Protocol for used the NS-3. For below the following procedures:
Steps to Develop Next Hop Protocol Projects Using NS3
- Overview of Next-Hop Routing Protocol
The Next-Hop Routing Protocol is simple routing strategy in which packet is sent to immediate next node in path to destination. We select the next hop is terms on shortest path, minimum delay, or improve the connection quality.
Key Features of Next-Hop Routing:
- Uses local forwarding decisions to select the best next-hop.
- Decreases the control overhead associated to traditional routing protocols.
- We can be executed in together wired and wireless networks.
- It performs well in MANETs (Mobile Ad Hoc Networks) and IoT networks.
- Setting Up NS-3 for Next-Hop Implementation
Execute the earlier for Next-Hop Protocol, install and set-up the NS-3 in your system.
Install NS-3
sudo apt update
sudo apt install git g++ python3 python3-pip cmake ninja-build
git clone https://gitlab.com/nsnam/ns-3-dev.git
cd ns-3-dev
./ns3 configure –enable-examples –enable-tests
./ns3 build
- Implementing Next-Hop Routing Protocol in NS-3
We require to:
- Explain a Next-Hop Packet Header.
- Estimate for Next-Hop Forwarding Logic.
- Incorporate the Next-Hop Routing in NS-3.
- Replicate the network for using a Next-Hop routing.
Step 1: Define the Next-Hop Packet Header (next-hop-header.h)
We describe the structure of Next-Hop routing packets.
#ifndef NEXT_HOP_HEADER_H
#define NEXT_HOP_HEADER_H
#include “ns3/header.h”
namespace ns3 {
class NextHopHeader : public Header {
public:
NextHopHeader();
static TypeId GetTypeId();
virtual void Serialize(Buffer::Iterator start) const;
virtual uint32_t Deserialize(Buffer::Iterator start);
virtual uint32_t GetSerializedSize() const;
virtual void Print(std::ostream &os) const;
private:
uint16_t m_source;
uint16_t m_destination;
uint16_t m_nextHop;
};
} // namespace ns3
#endif
Step 2: Implement Next-Hop Routing Logic (next-hop-routing.cc)
These files execute the Next-Hop decision logic.
#include “ns3/next-hop-header.h”
#include “ns3/next-hop-routing.h”
namespace ns3 {
NS_LOG_COMPONENT_DEFINE(“NextHopRouting”);
TypeId NextHopRouting::GetTypeId() {
static TypeId tid = TypeId(“ns3::NextHopRouting”)
.SetParent<Ipv4RoutingProtocol>()
.SetGroupName(“Internet”)
.AddConstructor<NextHopRouting>();
return tid;
}
void NextHopRouting::DoInitialize() {
NS_LOG_INFO(“Initializing Next-Hop Routing Protocol”);
Ipv4RoutingProtocol::DoInitialize();
}
// Function to select the best next-hop
Ipv4Address NextHopRouting::SelectNextHop(Ipv4Address destination) {
// Basic next-hop selection (modify with better algorithms)
if (m_routingTable.find(destination) != m_routingTable.end()) {
return m_routingTable[destination];
}
return Ipv4Address(“0.0.0.0”); // No route found
}
// Function to handle packet forwarding
void NextHopRouting::ForwardPacket(Ptr<Packet> packet, Ipv4Address src, Ipv4Address dst) {
Ipv4Address nextHop = SelectNextHop(dst);
if (nextHop != Ipv4Address(“0.0.0.0”)) {
NS_LOG_INFO(“Forwarding packet from ” << src << ” to ” << nextHop);
m_ipv4->Send(packet, src, nextHop, Ipv4Header::PROTO_NEXT_HOP);
} else {
NS_LOG_INFO(“No next-hop found for destination ” << dst);
}
}
} // namespace ns3
Step 3: Register the Next-Hop Protocol in NS-3 (next-hop-routing-helper.cc)
This registers the Next-Hop Routing Protocol in NS-3.
#include “ns3/next-hop-routing-helper.h”
#include “ns3/next-hop-routing.h”
namespace ns3 {
NextHopRoutingHelper::NextHopRoutingHelper() {}
Ptr<Ipv4RoutingProtocol> NextHopRoutingHelper::Create() const {
return CreateObject<NextHopRouting>();
}
} // namespace ns3
- Simulating Next-Hop Routing in NS-3
Now, build the network topology and setting the Next-Hop Routing.
Step 1: Create a Simulation Script (next-hop-test.cc)
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/internet-module.h”
#include “ns3/mobility-module.h”
#include “ns3/wifi-module.h”
#include “ns3/next-hop-routing-helper.h”
using namespace ns3;
int main(int argc, char *argv[]) {
CommandLine cmd;
cmd.Parse(argc, argv);
NodeContainer nodes;
nodes.Create(5);
// Set mobility model
MobilityHelper mobility;
mobility.SetMobilityModel(“ns3::RandomWalk2dMobilityModel”);
mobility.Install(nodes);
// WiFi setup
WifiHelper wifi;
wifi.SetStandard(WIFI_STANDARD_80211b);
WifiMacHelper mac;
YansWifiPhyHelper phy = YansWifiPhyHelper::Default();
YansWifiChannelHelper channel = YansWifiChannelHelper::Default();
phy.SetChannel(channel.Create());
mac.SetType(“ns3::AdhocWifiMac”);
NetDeviceContainer devices;
devices = wifi.Install(phy, mac, nodes);
InternetStackHelper internet;
NextHopRoutingHelper nextHopRouting;
internet.SetRoutingHelper(nextHopRouting);
internet.Install(nodes);
Ipv4AddressHelper address;
address.SetBase(“10.1.1.0”, “255.255.255.0”);
address.Assign(devices);
Simulator::Stop(Seconds(10));
Simulator::Run();
Simulator::Destroy();
return 0;
}
- Running the Next-Hop Simulation
Step 1: Create the NS-3
./ns3 build
Step 2: Implement the replication
./ns3 run “scratch/next-hop-test”
- Performance Analysis
Enable Logging
For alter the script to permit the recording:
LogComponentEnable(“NextHopRouting”, LOG_LEVEL_INFO);
The Next Hop Protocol for gather the performance of parameter metrices such as
Packet Delivery Ratio (PDR)
Ptr<PacketSink> sink = DynamicCast<PacketSink>(apps.Get(1));
double pdr = sink->GetTotalRx() / totalSentPackets;
End-to-End Delay
Time delay = Simulator::Now() – packetStartTime;
NS_LOG_INFO(“End-to-End Delay: ” << delay.GetSeconds() << ” sec”);
Routing Overhead
double overhead = totalControlPackets / totalDataPackets;
NS_LOG_INFO(“Routing Overhead: ” << overhead);
- Extending the Project
- It associated a Next-Hop by AODV, OLSR, and DSDV.
- Verify for Next-Hop in dynamic networks (high mobility scenarios).
- We improve the Next-Hop for congestion-aware routing.
In conclusion, we have exhibited the valuable understandings for you to know and empathizes the approaches and its simulation about the Next Hop Routing Protocol in the simulation using ns3 simulator tool.it usually helps you to transmit the information from a source to destination.