Implementing Temporary Ordered Routing Algorithm (TORA) in ns3 involves several steps. TORA is a reactive routing protocol that is especially designed for mobile ad hoc networks (MANETs) which works by establishing routes on-demand and maintaining routes only when they are essential.
Here are the steps to implement TORA in ns3.
Step-by-step guide on implementing TORA in ns3
- Set up your ns3 :
- Make sure that ns3 is installed in the computer. If not, install it.
- Create a New Module for TORA:
- Go to the src directory in ns3 and create a new directory named TORA. Create subdirectories named model, helper, and examples, inside the src directory.
- Define the TORA protocol:
- create .cc and .h files for the TORA protocol in the model directory. Define the TORA class that inherits from the Ipv4RoutingProtocol class.
- Implement the TORA class:
- Implement the key components of TORA such as neighbor discovery, route creation, route maintenance, and route erasure. For the TORA control messages, create classes: Query (QRY), Update (UPD), Clear (CLR), and Route Error (RERR).
- Integrate the TORA with ns3 routing system:
- Modify the RoutingHelper class to include TORA.
- Create simulation script:
- Set up a network topology.
- Install the Internet stack.
- Use the TORA helper to enable TORA.
- Set up applications and run the simulation.
Example Code Structure
Below is the example code structure for the implementation of TORA in ns3.
Define TORA Protocol
// src/tora/model/tora-routing-protocol.h
#ifndef TORA_ROUTING_PROTOCOL_H
#define TORA_ROUTING_PROTOCOL_H
#include “ns3/ipv4-routing-protocol.h”
#include “ns3/ipv4.h”
#include “ns3/ipv4-l3-protocol.h”
#include “ns3/ipv4-route.h”
#include “ns3/node.h”
#include “ns3/net-device.h”
#include “ns3/socket.h”
#include “ns3/timer.h”
namespace ns3 {
class ToraRoutingProtocol : public Ipv4RoutingProtocol
{
public:
static TypeId GetTypeId (void);
ToraRoutingProtocol ();
virtual ~ToraRoutingProtocol ();
// Inherited from Ipv4RoutingProtocol
virtual Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header,
Ptr<NetDevice> oif, Socket::SocketErrno &sockerr);
virtual bool RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
UnicastForwardCallback ucb, MulticastForwardCallback mcb,
LocalDeliverCallback lcb, ErrorCallback ecb);
virtual void NotifyInterfaceUp (uint32_t interface);
virtual void NotifyInterfaceDown (uint32_t interface);
virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address);
virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address);
virtual void SetIpv4 (Ptr<Ipv4> ipv4);
void RecvTora (Ptr<Socket> socket);
private:
void Start ();
void Stop ();
Ptr<Ipv4> m_ipv4;
std::map<Ptr<Socket>, Ipv4InterfaceAddress> m_socketAddresses;
};
} // namespace ns3
#endif // TORA_ROUTING_PROTOCOL_H
Helper Class
// src/tora/helper/tora-helper.h
#ifndef TORA_HELPER_H
#define TORA_HELPER_H
#include “ns3/ipv4-routing-helper.h”
#include “ns3/object-factory.h”
#include “ns3/tora-routing-protocol.h”
namespace ns3 {
class ToraHelper : public Ipv4RoutingHelper
{
public:
ToraHelper ();
ToraHelper (const ToraHelper &);
ToraHelper &operator= (const ToraHelper &);
virtual ~ToraHelper ();
virtual ToraHelper* Copy (void) const;
virtual Ptr<Ipv4RoutingProtocol> Create (Ptr<Node> node) const;
};
} // namespace ns3
#endif // TORA_HELPER_H
Example Simulation Script
// examples/tora-simulation.cc
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/internet-module.h”
#include “ns3/point-to-point-module.h”
#include “ns3/applications-module.h”
#include “ns3/tora-helper.h”
using namespace ns3;
NS_LOG_COMPONENT_DEFINE (“ToraSimulation”);
int main (int argc, char *argv[])
{
CommandLine cmd;
cmd.Parse (argc, argv);
// Create nodes
NodeContainer nodes;
nodes.Create (4);
// Create point-to-point links
PointToPointHelper p2p;
p2p.SetDeviceAttribute (“DataRate”, StringValue (“1Mbps”));
p2p.SetChannelAttribute (“Delay”, StringValue (“10ms”));
NetDeviceContainer devices01 = p2p.Install (nodes.Get (0), nodes.Get (1));
NetDeviceContainer devices12 = p2p.Install (nodes.Get (1), nodes.Get (2));
NetDeviceContainer devices23 = p2p.Install (nodes.Get (2), nodes.Get (3));
NetDeviceContainer devices30 = p2p.Install (nodes.Get (3), nodes.Get (0));
// Install the Internet stack
InternetStackHelper stack;
ToraHelper tora;
stack.SetRoutingHelper (tora);
stack.Install (nodes);
// Assign IP addresses
Ipv4AddressHelper address;
address.SetBase (“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces01 = address.Assign (devices01);
address.SetBase (“10.1.2.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces12 = address.Assign (devices12);
address.SetBase (“10.1.3.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces23 = address.Assign (devices23);
address.SetBase (“10.1.4.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces30 = address.Assign (devices30);
// Create a packet sink to receive packets
uint16_t sinkPort = 8080;
Address sinkAddress (InetSocketAddress (interfaces23.GetAddress (1), sinkPort));
PacketSinkHelper packetSinkHelper (“ns3::TcpSocketFactory”, sinkAddress);
ApplicationContainer sinkApps = packetSinkHelper.Install (nodes.Get (3));
sinkApps.Start (Seconds (1.0));
sinkApps.Stop (Seconds (10.0));
// Create a TCP client to send packets
OnOffHelper clientHelper (“ns3::TcpSocketFactory”, sinkAddress);
clientHelper.SetAttribute (“OnTime”, StringValue (“ns3::ConstantRandomVariable[Constant=1]”));
clientHelper.SetAttribute (“OffTime”, StringValue (“ns3::ConstantRandomVariable[Constant=0]”));
clientHelper.SetAttribute (“DataRate”, DataRateValue (DataRate (“1Mbps”)));
clientHelper.SetAttribute (“PacketSize”, UintegerValue (1024));
ApplicationContainer clientApps = clientHelper.Install (nodes.Get (0));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
// Enable tracing
AsciiTraceHelper ascii;
p2p.EnableAsciiAll (ascii.CreateFileStream (“tora-routing.tr”));
p2p.EnablePcapAll (“tora-routing”);
// Run the simulation
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
Running the Simulation
To run the simulation, compile the script and execute it:
./waf configure –enable-examples
./waf build
./waf –run tora-simulation
Detailed steps for implementation
The above example implementation provides only a skeleton of TORA . The actual implementation includes several steps involving :
- Neighbor Discovery : To discover and maintain information about their neighbours, implement mechanisms for nodes.
- Route Creation : For establishing routes, implement the process. TORA uses a directed acyclic graph (DAG) for routing, where the direction of the edges indicates the flow of packets.
- Route Maintenance : For maintaining and updating routes in response to network changes (e.g., node mobility), implement mechanisms.
- Route Erasure : For erasing routes when they are no longer needed or when a network partition occurs, implement the process.
- Control Messages : To manage route creation, maintenance, and erasure, define and implement TORA-specific control messages, such as QRY, UPD, CLR, and RERR.
We had successfully learned on implementing Temporary Ordered Routing Algorithm (TORA) in ns3 by defining the protocol and running the simulation.
Implementing Temporary Ordered Routing Algorithm (TORA) with best coding are aided by our squad of developers.