How to Begin Implement TORA Routing in NS3
To implement Temporally Ordered Routing Algorithm (TORA) using NS3, we can create a routing protocol which able to adjusting dynamic network topologies that specifically utilized within mobile ad-hoc networks (MANETs). TORA sustains numerous paths to destination for minimizing overhead in the course of topology modifications. Below is a stepwise mechanism to execute the TORA Routing using NS3:
Steps to Begin Implement TORA Routing in NS3
Step 1: Understand TORA
- Key Features:
- Directed Acyclic Graph (DAG): Routes are sustained by DAG rooted at the destination.
- Three Phases:
- Route Creation: Launch routes to a destination.
- Route Maintenance: Once topology modifies then locally update the paths.
- Route Erasure: Eliminate invalid routes for sustaining the consistency.
- TORA Messages:
- QUERY (QRY): Demand the routes messages to a destination.
- UPDATE (UPD): Publicize route updates.
- CLEAR (CLR): Erase invalid routes.
Step 2: Set Up NS3 Environment
- Create a Protocol Directory:
- Make a protocol directory in src/, for example src/tora-routing/.
- Add Necessary Files:
- tora-routing-helper.h and tora-routing-helper.cc: Helper classes.
- tora-routing-protocol.h: Header file for TORA.
- tora-routing-protocol.cc: Execution file.
- Update Build System:
- Change the wscript within src/ containing the TORA module for updating system.
Step 3: Design TORA Protocol
Define the Protocol Class
Execute the functionality of TORA for prolonging the Ipv4RoutingProtocol class.
Header File (tora-routing-protocol.h)
#include “ns3/ipv4-routing-protocol.h”
#include “ns3/socket.h”
#include <map>
class ToraRoutingProtocol : public ns3::Ipv4RoutingProtocol {
public:
static ns3::TypeId GetTypeId (void);
ToraRoutingProtocol ();
virtual ~ToraRoutingProtocol ();
// Override Ipv4RoutingProtocol methods
virtual ns3::Ptr<ns3::Ipv4Route> RouteOutput (
ns3::Ptr<const ns3::Packet> packet,
const ns3::Ipv4Header &header,
ns3::Ptr<ns3::NetDevice> oif,
ns3::Socket::SocketErrno &sockerr);
virtual bool RouteInput (
ns3::Ptr<const ns3::Packet> packet,
const ns3::Ipv4Header &header,
ns3::Ptr<const ns3::NetDevice> idev,
ns3::UnicastForwardCallback ucb,
ns3::MulticastForwardCallback mcb,
ns3::LocalDeliverCallback lcb,
ns3::ErrorCallback ecb);
void SendQuery (ns3::Ipv4Address destination);
void SendUpdate (ns3::Ipv4Address destination, uint32_t height);
void HandleQuery (ns3::Ptr<const ns3::Packet> packet);
void HandleUpdate (ns3::Ptr<const ns3::Packet> packet);
private:
struct RouteEntry {
uint32_t height; // Height of the node
ns3::Ipv4Address nextHop; // Next-hop node
};
std::map<ns3::Ipv4Address, RouteEntry> m_routingTable; // Routing table
ns3::Ptr<ns3::Socket> m_socket; // Communication socket
};
Implement Core Functions
Route Creation
Make use of QUERY messages to manage the route creation.
void ToraRoutingProtocol::SendQuery (ns3::Ipv4Address destination) {
ns3::Ptr<ns3::Packet> packet = ns3::Create<ns3::Packet> ();
// Serialize QUERY message
// …
m_socket->SendTo(packet, 0, ns3::InetSocketAddress(ns3::Ipv4Address::GetBroadcast(), 9999));
}
void ToraRoutingProtocol::HandleQuery (ns3::Ptr<const ns3::Packet> packet) {
// Deserialize QUERY message
ns3::Ipv4Address destination = …; // Extract destination
if (m_routingTable.find(destination) != m_routingTable.end()) {
// Respond with UPDATE if route exists
SendUpdate(destination, m_routingTable[destination].height);
}
}
Route Maintenance
Manage the topology modifications to leverage the UPDATE messages.
void ToraRoutingProtocol::SendUpdate (ns3::Ipv4Address destination, uint32_t height) {
ns3::Ptr<ns3::Packet> packet = ns3::Create<ns3::Packet> ();
// Serialize UPDATE message
// …
m_socket->SendTo(packet, 0, ns3::InetSocketAddress(ns3::Ipv4Address::GetBroadcast(), 9999));
}
void ToraRoutingProtocol::HandleUpdate (ns3::Ptr<const ns3::Packet> packet) {
// Deserialize UPDATE message
ns3::Ipv4Address destination = …; // Extract destination
uint32_t height = …; // Extract height
// Update routing table
m_routingTable[destination].height = height;
m_routingTable[destination].nextHop = packet->GetSource();
}
Route Erasure
Eliminate invalid routes with the support of CLEAR messages.
void ToraRoutingProtocol::ClearRoutes (ns3::Ipv4Address destination) {
m_routingTable.erase(destination);
// Broadcast CLEAR message
ns3::Ptr<ns3::Packet> clearPacket = ns3::Create<ns3::Packet> ();
// Serialize CLEAR message
// …
m_socket->SendTo(clearPacket, 0, ns3::InetSocketAddress(ns3::Ipv4Address::GetBroadcast(), 9999));
}
Packet Forwarding
Execute the packet forwarding logic to uilize the routing table.
ns3::Ptr<ns3::Ipv4Route> ToraRoutingProtocol::RouteOutput (
ns3::Ptr<const ns3::Packet> packet,
const ns3::Ipv4Header &header,
ns3::Ptr<ns3::NetDevice> oif,
ns3::Socket::SocketErrno &sockerr) {
auto it = m_routingTable.find(header.GetDestination());
if (it != m_routingTable.end()) {
ns3::Ptr<ns3::Ipv4Route> route = ns3::Create<ns3::Ipv4Route> ();
route->SetGateway(it->second.nextHop);
route->SetOutputDevice(oif);
return route;
}
sockerr = ns3::Socket::ERROR_NOROUTETOHOST;
return nullptr;
}
Step 4: Write a Helper Class
Make a helper class to make simpler incorporation to replications.
#include “tora-routing-protocol.h”
class ToraRoutingHelper {
public:
void Install (ns3::NodeContainer nodes) {
for (auto it = nodes.Begin(); it != nodes.End(); ++it) {
ns3::Ptr<ToraRoutingProtocol> protocol = ns3::CreateObject<ToraRoutingProtocol>();
(*it)->AggregateObject(protocol);
}
}
};
Step 5: Write a Simulation Script
Example Simulation Script
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/internet-module.h”
#include “tora-routing-helper.h”
using namespace ns3;
int main (int argc, char *argv[]) {
NodeContainer nodes;
nodes.Create (4);
InternetStackHelper stack;
stack.Install (nodes);
ToraRoutingHelper toraHelper;
toraHelper.Install(nodes);
PointToPointHelper p2p;
p2p.SetDeviceAttribute (“DataRate”, StringValue (“10Mbps”));
p2p.SetChannelAttribute (“Delay”, StringValue (“2ms”));
p2p.Install (nodes.Get (0), nodes.Get (1));
p2p.Install (nodes.Get (1), nodes.Get (2));
p2p.Install (nodes.Get (2), nodes.Get (3));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
Step 6: Compile and Run
- Build the Protocol:
./waf configure
./waf build
- Run the Simulation:
./waf –run your-script
Step 7: Analyze and Extend
- Tracing:
- Examine the behaviour of routing using AsciiTraceHelper or PcapHelper.
- Enhancements:
- Execute the parameters such as energy consumption or link quality.
- Analyze performance of TORA routing in dynamic scenarios including node mobility.
We’ve successfully demonstrated the detailed implementation process for executing and extending the TORA Routing with the support of NS3 environment. Extra information can be provided if needed.