How to Begin Implement temporally ordered routing in ns3
To begin the Temporally Ordered Routing Algorithm (TORA) is a distributed and adaptive routing protocol mainly used in mobile ad hoc networks (MANETs). It is model for multi-hop networks and adjusts the network topology changes by minimal control overhead.
Here’s how to begin implementing TORA in NS-3:
Steps to Begin Implement temporally ordered routing in ns3
Step 1: Understand TORA
- Key Features of TORA:
- Directed Acyclic Graph (DAG): Routes are formed according to a destination-oriented DAG.
- Three Phases:
- Route Creation: Make a DAG rooted in the destination.
- Route Maintenance: Alter the routes dynamically after network topology changes.
- Route Erasure: Eliminate the invalid routes.
- Main Components:
- Height Metric: Define the node’s position relative for the destination.
- Control Messages:
- Query (QRY): Demand the routing information.
- Update (UPD): Respond to requests or announce route bring up-to-date.
- Clear (CLR): Remove the invalid routes.
Step 2: Set Up NS-3 Environment
- Create a Protocol Directory:
- Create a new directory under src/, e.g., src/tora/.
- Add Required Files:
- tora-routing-protocol.h: Header file intended for TORA.
- tora-routing-protocol.cc: Application file designed for TORA.
- tora-helper.h and tora-helper.cc: Helper classes for incorporating a TORA replication.
- Update Build System:
- Change directory wscript in the src/ to contain the TORA component.
Step 3: Design TORA Protocol
Define the Protocol Class
Cover the Ipv4RoutingProtocol class to apply the TORA logic.
Header File (tora-routing-protocol.h)
#include “ns3/ipv4-routing-protocol.h”
#include “ns3/timer.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);
// TORA-specific methods
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 metric for the node
ns3::Ipv4Address nextHop; // Next hop to the destination
ns3::Ipv4Address destination; // Destination address
};
std::map<ns3::Ipv4Address, RouteEntry> m_routingTable; // Routing table
};
Implement Core Functions
Route Creation
Treat the route discovery using QRY and UPD messages.
void ToraRoutingProtocol::SendQuery (ns3::Ipv4Address destination) {
// Create and broadcast a QRY packet
ns3::Ptr<ns3::Packet> packet = ns3::Create<ns3::Packet> ();
// Serialize QRY header
// …
// Broadcast packet
m_socket->SendTo(packet, 0, ns3::InetSocketAddress(ns3::Ipv4Address::GetBroadcast(), 9999));
}
void ToraRoutingProtocol::HandleQuery (ns3::Ptr<const ns3::Packet> packet) {
// Deserialize QRY packet
ns3::Ipv4Address destination = …; // Extract destination
// Respond with an UPD packet if a route exists
if (m_routingTable.find(destination) != m_routingTable.end()) {
SendUpdate(destination, m_routingTable[destination].height);
}
}
Route Maintenance
Maintain the dynamic network topology modification and change routes.
void ToraRoutingProtocol::SendUpdate (ns3::Ipv4Address destination, uint32_t height) {
// Create and send an UPD packet
ns3::Ptr<ns3::Packet> packet = ns3::Create<ns3::Packet> ();
// Serialize UPD header
// …
m_socket->SendTo(packet, 0, ns3::InetSocketAddress(destination, 9999));
}
void ToraRoutingProtocol::HandleUpdate (ns3::Ptr<const ns3::Packet> packet) {
// Deserialize UPD packet
ns3::Ipv4Address destination = …; // Extract destination
uint32_t height = …; // Extract height
// Update routing table
m_routingTable[destination].height = height;
m_routingTable[destination].nextHop = …; // Determine next hop
}
Route Erasure
Maintain the route invalidation using CLR messages.
Packet Forwarding
Apply the packet routing according to the TORA 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) {
ns3::Ptr<ns3::Ipv4Route> route = ns3::Create<ns3::Ipv4Route> ();
if (m_routingTable.find(header.GetDestination()) != m_routingTable.end()) {
route->SetGateway(m_routingTable[header.GetDestination()].nextHop);
} else {
sockerr = ns3::Socket::ERROR_NOROUTETOHOST;
return nullptr;
}
return route;
}
Step 4: Write a Helper Class
Generate a helper class for clarify the TORA replicate the incorporation.
#include “tora-routing-protocol.h”
class ToraHelper {
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 Script:
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/internet-module.h”
#include “tora-helper.h”
using namespace ns3;
int main (int argc, char *argv[]) {
NodeContainer nodes;
nodes.Create (5);
InternetStackHelper stack;
stack.Install (nodes);
ToraHelper toraHelper;
toraHelper.Install (nodes);
// Configure links and addresses
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));
// Additional links…
// Simulate traffic…
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
- Use Tracing Tools:
- Use AsciiTraceHelper and PcapHelper for seizure and examine the packet flow.
- Enhance the Protocol:
- Enhance the energy-awareness or mobility models.
- Execute the priority-based routing for kinds of congestion.
These project examples deliver the wide range of different applications and enhancements of TORA, from handling mobility and fault tolerance to adding features also we provide the another set of examples in upcoming manuals.