To simulate the Temporally Ordered Routing Algorithm (TORA) in ns3 has numerous to steps to follow. First of all ns3 does not directly support the execution so we need to simulate the TORA-like protocol by developing custom logic or by adjusting existing routing protocols. Since it is due to the TORA is not delivered the proper process in ns3, we want to execute it physically or utilize the another protocol that is same as based on the on-demand behaviour, such as AODV (Ad-hoc On-demand Distance Vector) or DSR (Dynamic Source Routing).
For optimal results to simulate TORA Protocol projects using NS3. Using the NS3 tool, we at phdprime.com will guide you to novel results, and all of your work will be explained in detail by our technical team experts, ensuring a hassle-free research journey.
TORA is a reactive routing protocol intended for mobile ad-hoc networks (MANETs), and its primary concentrate is on to reducing the routing overhead and modifying to frequent topology changes. It achieves this through a multi-path, distributed algorithm in terms of directed acyclic graphs (DAGs).
Below is the approach on how to simulate the Temporally Ordered Routing Algorithm in ns3
Approach to Simulating a TORA-like Protocol in NS3
While TORA is not readily available in NS3, we can either:
- Manually implement TORA by coding it as a custom protocol in NS3.
- Use an alternative reactive protocol, like AODV or DSR, that are already available in NS3, as they deliver similar reactive behaviours.
In this guide, we will demonstrate how to simulate AODV as a reactive routing protocol to replicate a TORA-like scenario that can later expand or replace with a custom TORA implementation.
Steps to Simulate TORA-like Protocol (Using AODV) in NS3
- Install NS3
Ensure NS3 is installed on the system.
- Understanding the TORA Protocol
- TORA is a highly adaptive, loop-free, multi-path routing protocol intended to reduce overhead and efficiently handle routes in the face of network topology changes.
- TORA focuses on:
- Localizing control messages to a small region near the topology change.
- Handling multiple routes from source to destination.
- Responding to topology changes without flooding the entire network with control messages.
In the absence of TORA in NS3, AODV can behave as a good approximation of a TORA-like reactive protocol.
- Create a Simulation Script Using AODV
In this simulation, we will:
- Generate an ad-hoc network with mobile nodes.
- Utilize AODV as the reactive routing protocol.
- Configure a simple UDP traffic generator to validate the routing.
- Include Necessary Headers
We need the following headers for configuring the network, mobility, routing protocols, and applications in NS3.
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/internet-module.h”
#include “ns3/mobility-module.h”
#include “ns3/aodv-module.h” // AODV used as a reactive protocol
#include “ns3/wifi-module.h”
#include “ns3/applications-module.h”
#include “ns3/netanim-module.h” // For animation
- Create and Install Nodes
Generate a set of nodes that signify mobile devices in the network.
NodeContainer nodes;
nodes.Create(10); // Create 10 nodes
- Configure Wireless (Wi-Fi) Communication
Utilize WifiHelper and YansWifiChannelHelper to set up wireless communication for the nodes.
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default();
wifiPhy.SetChannel(wifiChannel.Create());
WifiHelper wifi;
wifi.SetStandard(WIFI_PHY_STANDARD_80211g);
wifi.SetRemoteStationManager(“ns3::AarfWifiManager”);
WifiMacHelper wifiMac;
wifiMac.SetType(“ns3::AdhocWifiMac”); // Ad-hoc MAC for mobile nodes
NetDeviceContainer devices = wifi.Install(wifiPhy, wifiMac, nodes); // Install Wi-Fi devices on nodes
- Install Internet Stack and AODV
Install the internet stack and the AODV routing protocol to emulate reactive behaviour.
InternetStackHelper internet;
AodvHelper aodv; // Reactive protocol (similar to TORA)
internet.SetRoutingHelper(aodv); // Use AODV for routing
internet.Install(nodes);
- Assign IP Addresses
Allocate IP addresses to the wireless devices.
Ipv4AddressHelper address;
address.SetBase(“10.1.1.0”, “255.255.255.0”); // Class C network
Ipv4InterfaceContainer interfaces = address.Assign(devices);
- Set Up Mobility Model
We will utilize a RandomWaypointMobilityModel to replicate mobile nodes moving in the network.
MobilityHelper mobility;
mobility.SetPositionAllocator(“ns3::GridPositionAllocator”,
“MinX”, DoubleValue(0.0),
“MinY”, DoubleValue(0.0),
“DeltaX”, DoubleValue(5.0),
“DeltaY”, DoubleValue(5.0),
“GridWidth”, UintegerValue(3),
“LayoutType”, StringValue(“RowFirst”));
mobility.SetMobilityModel(“ns3::RandomWaypointMobilityModel”,
“Speed”, StringValue(“ns3::UniformRandomVariable[Min=1.0|Max=3.0]”),
“Pause”, StringValue(“ns3::ConstantRandomVariable[Constant=2.0]”),
“PositionAllocator”, StringValue(“ns3::GridPositionAllocator”));
mobility.Install(nodes);
- Set Up Applications
We can emulate the traffic using applications such as UDP Echo. Here, one node will behave as the server and another as the client.
- Server (Sink Application):
uint16_t port = 8080;
UdpEchoServerHelper echoServer(port);
ApplicationContainer serverApp = echoServer.Install(nodes.Get(0)); // Server on node 0
serverApp.Start(Seconds(1.0));
serverApp.Stop(Seconds(20.0));
- Client (OnOff Application):
UdpEchoClientHelper echoClient(interfaces.GetAddress(0), port); // Client sending data to server (node 0)
echoClient.SetAttribute(“MaxPackets”, UintegerValue(50));
echoClient.SetAttribute(“Interval”, TimeValue(Seconds(1.0)));
echoClient.SetAttribute(“PacketSize”, UintegerValue(1024));
ApplicationContainer clientApp = echoClient.Install(nodes.Get(5)); // Client on node 5
clientApp.Start(Seconds(2.0));
clientApp.Stop(Seconds(20.0));
- Enable Tracing and Animation
Allow packet capture (pcap) and NetAnim animation for visualization.
wifiPhy.EnablePcapAll(“tora_simulation”); // Enable pcap trace for all nodes
AnimationInterface anim(“tora_simulation.xml”); // Enable animation output for NetAnim
- Run the Simulation
Set the simulation in period and execute the simulation.
Simulator::Stop(Seconds(20.0));
Simulator::Run();
Simulator::Destroy();
- Example Full Script for TORA-like Simulation (Using AODV)
Below is a full NS3 simulation script using AODV as a reactive routing protocol to replicate the TORA-like behavior:
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/internet-module.h”
#include “ns3/wifi-module.h”
#include “ns3/mobility-module.h”
#include “ns3/aodv-module.h”
#include “ns3/applications-module.h”
#include “ns3/netanim-module.h”
using namespace ns3;
int main(int argc, char *argv[]) {
// Step 1: Create nodes
NodeContainer nodes;
nodes.Create(10); // Create 10 nodes
// Step 2: Configure Wi-Fi communication
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default();
wifiPhy.SetChannel(wifiChannel.Create());
WifiHelper wifi;
wifi.SetStandard(WIFI_PHY_STANDARD_80211g);
wifi.SetRemoteStationManager(“ns3::AarfWifiManager”);
WifiMacHelper wifiMac;
wifiMac.SetType(“ns3::AdhocWifiMac”); // Ad-hoc MAC
NetDeviceContainer devices = wifi.Install(wifiPhy, wifiMac, nodes);
// Step 3: Install internet stack and AODV routing protocol
InternetStackHelper internet;
AodvHelper aodv;
internet.SetRoutingHelper(aodv); // Use AODV as the routing protocol (TORA-like behavior)
internet.Install(nodes);
// Step 4: Assign IP addresses
Ipv4AddressHelper address;
address.SetBase(“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces = address.Assign(devices);
// Step 5: Set up mobility model
MobilityHelper mobility;
mobility.SetPositionAllocator(“ns3::GridPositionAllocator”,
“MinX”, DoubleValue(0.0),
“MinY”, DoubleValue(0.0),
“DeltaX”, DoubleValue(5.0),
“DeltaY”, DoubleValue(5.0),
“GridWidth”, UintegerValue(3),
“LayoutType”, StringValue(“RowFirst”));
mobility.SetMobilityModel(“ns3::RandomWaypointMobilityModel”,
“Speed”, StringValue(“ns3::UniformRandomVariable[Min=1.0|Max=3.0]”),
“Pause”, StringValue(“ns3::ConstantRandomVariable[Constant=2.0]”),
“PositionAllocator”, StringValue(“ns3::GridPositionAllocator”));
mobility.Install(nodes);
// Step 6: Set up applications
// Server (Sink) on node 0
uint16_t port = 8080;
UdpEchoServerHelper echoServer(port);
ApplicationContainer serverApp = echoServer.Install(nodes.Get(0));
serverApp.Start(Seconds(1.0));
serverApp.Stop(Seconds(20.0));
// Client on node 5
UdpEchoClientHelper echoClient(interfaces.GetAddress(0), port); // Client sends packets to node 0
echoClient.SetAttribute(“MaxPackets”, UintegerValue(50));
echoClient.SetAttribute(“Interval”, TimeValue(Seconds(1.0)));
echoClient.SetAttribute(“PacketSize”, UintegerValue(1024));
ApplicationContainer clientApp = echoClient.Install(nodes.Get(5));
clientApp.Start(Seconds(2.0));
clientApp.Stop(Seconds(20.0));
// Step 7: Enable tracing and animation
wifiPhy.EnablePcapAll(“tora_simulation”);
AnimationInterface anim(“tora_simulation.xml”);
// Step 8: Run the simulation
Simulator::Stop(Seconds(20.0));
Simulator::Run();
Simulator::Destroy();
return 0;
}
- Running the Simulation
- Compile and execute the script using NS3’s waf build system:
./waf build
./waf –run <your_script_name>
- Analyse Results
- PCAP Tracing: The pcap files generated can be measured using tools such as Wireshark.
- NetAnim: We can open the generated XML file in NetAnim to envision the node movements and packet flows.
- Implementing TORA Manually (Advanced)
If you want a true TORA implementation in NS3, we will have to execute the protocol manually. This would involve:
- Generating a custom routing protocol class.
- Executing the TORA algorithms like route creation, maintenance, and route erasure based on directed acyclic graphs (DAGs).
- Handling the packet handling, route discovery, and failure notifications.
For more complex research or a project, you could also collaborate with the NS3 community or look for any external TORA module implementations that could be added to NS3.
In this entire page we had understand the concepts on how the RORA perform in ns3 tool and also we can gain knowledge on how to install ns3 and then how it create the simulation for AODV subsequently we know how to run the simulation. If you have any doubts regarding this process kindly let me know!