How to Implement DODAG Fault Tolerance in NS2

To implement the DODAG (Destination-Oriented Directed Acyclic Graph) Fault Tolerance using NS2, we will require to replicate a network rely on the RPL (Routing Protocol for Low-Power and Lossy Networks) that uses DODAGs as its underlying structure. Fault tolerance in DODAG includes mechanisms, which permit the network to retrieve from the node or link failures, make sure that packets can still be routed effectively via another paths. Get some of the best project ideas from ns2project.com based on your Research area, we assist you with ontime implementation support.Given below is stepwise procedure to execute this tolerance in NS2:

Step-by-Step Guide to Implement DODAG Fault Tolerance in NS2

  1. Set Up the Basic Network Topology:
  • Initially, we describe a network in which a set of nodes are form a DODAG structure. Every node will connect to its parent in the DODAG, with the root at the top. For simplicity, we will replicate a multi-hop network in which each node has a direct or indirect path to the root node.

Example OTcl script to set up the basic network topology:

set ns [new Simulator]

set nf [open out.tr w]

$ns trace-all $nf

set namfile [open out.nam w]

$ns namtrace-all $namfile

# Create nodes

set root [$ns node]   ;# Root node of the DODAG

set node1 [$ns node]   ;# Child node 1

set node2 [$ns node]   ;# Child node 2

set node3 [$ns node]   ;# Child node 3

# Create links between nodes to form a basic DODAG

$ns duplex-link $root $node1 1Mb 10ms DropTail

$ns duplex-link $node1 $node2 1Mb 10ms DropTail

$ns duplex-link $node2 $node3 1Mb 10ms DropTail

# Define traffic from node3 to root

set udp [new Agent/UDP]

set null [new Agent/Null]

$ns attach-agent $node3 $udp

$ns attach-agent $root $null

$ns connect $udp $null

set cbr [new Application/Traffic/CBR]

$cbr attach-agent $udp

$cbr set packetSize_ 512

$cbr set rate_ 1Mb

$ns at 1.0 “$cbr start”

$ns at 5.0 “$cbr stop”

# Run the simulation

$ns at 6.0 “finish”

proc finish {} {

global ns nf namfile

$ns flush-trace

close $nf

close $namfile

exec nam out.nam &

exit 0

}

$ns run

  • This simple topology forms a basic multi-hop DODAG in which traffic flows from node3 (leaf node) up via node2 and node1 to the root node.
  1. Define the DODAG Structure and Assign Parents:
  • Every node in a DODAG chooses a parent node, which offers the shortest or most reliable path to the root. The root node has no parent, and each node calculates its rank depends on its distance from the root.

Example of parent assignment:

# Define ranks (root has the lowest rank)

set root_rank 1

set node1_rank [expr $root_rank + 1]

set node2_rank [expr $node1_rank + 1]

set node3_rank [expr $node2_rank + 1]

# Assign parents based on rank

set parent_node3 $node2

set parent_node2 $node1

set parent_node1 $root

  • Each node calculates its rank relative to its parent, and the lowest-ranked node (the root) is the final end for all traffic.
  1. Implement Fault Tolerance (Detecting and Handling Failures):
  • To execute the fault tolerance, nodes should be able to identify while its parent or a link fails. While a node identifies a failure, it requires to choose a new parent from its neighbours or recalculate its path to the root.

We can replicate the link failures or node failures and make a mechanisms, which permit to select another path.

Example OTcl script to simulate link failure and fault recovery:

# Simulate a link failure between node1 and node2 at 3 seconds

$ns at 3.0 “$ns link $node1 $node2 down”

# Procedure to detect failure and select a new parent

proc handle_failure {node failed_parent new_parent} {

puts “Node $node detected failure in parent $failed_parent, switching to $new_parent”

# Change parent and adjust routing

$ns connect $node $new_parent

}

# Node2 detects failure and switches to root as new parent

$ns at 3.5 “handle_failure $node2 $node1 $root”

  • Above instance, while the link among the nodes node1 and node2 fails, node2 identifies the failure and switches their parent to the root node, bypassing node1.
  1. Monitor DODAG Stability and Performance:
  • Observe how the network adjusts to the node or link failures. Metrics like packet loss, delay, and route changes will signify how successfully the DODAG manages the faults.

Example of logging parent changes and recovery:

# Log the parent changes for fault tolerance

proc log_parent_change {node old_parent new_parent time} {

puts “At $time: Node $node switched parent from $old_parent to $new_parent”

}

# Monitor parent changes after a failure

$ns at 3.0 “log_parent_change $node2 $node1 $root [clock seconds]”

  • This records while a node switches these parent, specifying a recovery action after identifying a fault within the network.
  1. Simulate Multiple Paths for Fault Recovery:
  • For enhanced fault tolerance, make sure that nodes have several parent options. If the primary path fails, the node can exchange to a secondary path.

Example OTcl script for multiple path options:

# Define multiple parents for node2 and node3

set secondary_parent_node3 $root

set secondary_parent_node2 $root

# If a primary link fails, switch to the secondary parent

proc switch_to_secondary_parent {node primary_parent secondary_parent} {

puts “Node $node switching to secondary parent $secondary_parent”

$ns connect $node $secondary_parent

}

# Simulate a failure and switch to secondary parent

$ns at 4.0 “switch_to_secondary_parent $node3 $node2 $root”

  • In this case, if the node3 loses their connection to node2 then it will be switched to root as a secondary parent, make sure that continued connectivity.
  1. Run the Simulation and Collect Results:
  • Now, we run the simulation to understand how the DODAG manages the failures and how nodes are adjust to new paths. We can be used the generated trace files to evaluate the behaviour.

To run the simulation:

ns your_script.tcl

  1. Analyse Fault Tolerance Metrics:
  • Main metrics to estimate the DODAG fault tolerance contain:
    • Packet delivery ratio: How many packets effectively attain the root after a failure.
    • Path recovery time: How rapidly nodes are switch to another paths after a failure.
    • Packet loss: The number of packets lost when the failure and recovery.

Example AWK script to analyze packet delivery:

awk ‘{if ($1 == “r” && $4 == “UDP”) received_packets++;}

END { print “Total received packets:”, received_packets }’ out.tr

  • This script is counts the amount of packets effectively received at the root, specifying the resilience of the DODAG to faults.
  1. Visualize Fault Tolerance in NAM:
  • We can use the NAM (Network Animator) to envision how the DODAG adjusts to node or link failures in real time.

nam out.nam

  • NAM permits to monitor how nodes are switch the paths while a failure happens and how traffic reroutes via another paths.

Summary:

To execute the DODAG Fault Tolerance within NS2:

  1. Configure a DODAG structure with numerous nodes and parent-child relationships.
  2. Replicate node and link failures to activate the fault recovery mechanisms.
  3. Execute the fault detection logic, which permits nodes to detect while a parent or link has failed.
  4. Switch to another paths by choosing a new parent while a failure is detected.
  5. Observe the network performance by estimating the metrics like packet loss and recovery time.
  6. Run the simulation and estimate the outcomes using trace files.
  7. Envision the recovery process in NAM to understand how nodes are adjust to failures in real-time.

We concluded by explaining the details and offering examples on performing the DODAG fault tolerance that were implemented in NS2, following the above mentioned procedure. More informations will be given, if required.