How to Implement Network DTN Architectures in NS2

To implement the Delay Tolerant Network (DTN) architectures using the simulation tool NS2 which require to encompass, simulating networks with intermittent connectivity in which the nodes may not always have end-to-end paths for data delivery. This architectures depends on the store-and-forward mechanisms to send the data over the network including possible long delays among the nodes. To execute the DTN architectures within NS2, we require to replicate the node mobility, message (bundle) forwarding, buffer management, and routing approaches suited for DTNs. We deliver essential steps to execute it in NS2:

Key Components of DTN Architectures:

  1. Store-and-Forward: These nodes are store messages (bundles) up to a connection to the next hop is obtainable, then send the data.
  2. Intermittent Connectivity: This connectivity among the nodes are not constantly continuous, also routes might only become obtainable intermittently.
  3. Buffer Management: These nodes are handle the buffer space to store data up to it can be sent to the next node.
  4. Routing Protocol: DTN-specific routing protocols such as Epidemic Routing, Spray-and-Wait, or Prophet Routing can be executed for routing messages in intermittent situations.
  5. Mobility Models: DTNs frequently include the node mobility in which nodes are move in and out of every other’s communication range.

 Steps to Implement DTN Architectures in NS2

  1. Simulate Node Mobility: Describe the mobility patterns for nodes within NS2 to make dynamic and intermittent connectivity.
  2. Implement Store-and-Forward Mechanism: To replicate the store-and-forward mechanism to manage the intermittent connections.
  3. Buffer Management: Execute logic for nodes to store bundles in buffers and send them while a connection is obtainable.
  4. Routing Strategy: We can use a DTN routing protocol, like Epidemic Routing, to spread messages via the network by forwarding them to several nodes.
  5. Custody Transfer (Optional): Execute the custody transfer in which an intermediate node takes responsibility for distributing the message.

Example: Simulating a Basic DTN Architecture in NS2

This specimen establishes how to execute a basic DTN architecture in NS2, with node mobility, store-and-forward message forwarding, and buffer management.

Step 1: Set Up Node Mobility and Define DTN Node

# Define the simulator object

set ns [new Simulator]

# Define trace and nam files for output

set tracefile [open out.tr w]

set namfile [open out.nam w]

$ns trace-all $tracefile

$ns namtrace-all $namfile

# Define a ‘finish’ procedure to end the simulation and visualize in NAM

proc finish {} {

global ns tracefile namfile

$ns flush-trace

close $tracefile

close $namfile

exec nam out.nam &

exit 0

}

# Set up the topography for the simulation area

set topo [new Topography]

$topo load_flatgrid 1000 1000

# Define the wireless channel

set chan [new Channel/WirelessChannel]

# Configure wireless DTN nodes (representing mobile nodes in the network)

$ns node-config -adhocRouting DSDV \

-llType LL \

-macType Mac/802_11 \

-ifqType Queue/DropTail/PriQueue \

-ifqLen 50 \

-antType Antenna/OmniAntenna \

-propType Propagation/TwoRayGround \

-phyType Phy/WirelessPhy \

-channel $chan

# Create DTN nodes: sender, forwarder, and receiver

set sender [$ns node]

set forwarder [$ns node]

set receiver [$ns node]

# Set node positions (for visualization in NAM)

$sender set X_ 100; $sender set Y_ 100; $sender set Z_ 0

$forwarder set X_ 500; $forwarder set Y_ 500; $forwarder set Z_ 0

$receiver set X_ 900; $receiver set Y_ 500; $receiver set Z_ 0

# Define mobility models to simulate node movement

# Define a random mobility pattern for each node

$ns at 0.0 “$sender setdest 300 300 10.0”   ;# Sender moves to (300, 300) at 10 units/sec

$ns at 0.0 “$forwarder setdest 600 600 5.0” ;# Forwarder moves to (600, 600) at 5 units/sec

$ns at 0.0 “$receiver setdest 900 300 7.0”  ;# Receiver moves to (900, 300) at 7 units/sec

# Step 2: Create Dynamic Wireless Links to Simulate Intermittent Connectivity

# Links between nodes will be established and broken based on their proximity

proc check_connectivity {src dst} {

global ns

# Get the positions of the source and destination nodes

set src_x [$src set X_]

set src_y [$src set Y_]

set dst_x [$dst set X_]

set dst_y [$dst set Y_]

# Calculate the Euclidean distance between the nodes

set dx [expr $src_x – $dst_x]

set dy [expr $src_y – $dst_y]

set distance [expr sqrt($dx * $dx + $dy * $dy)]

# If the nodes are within communication range (e.g., 300 meters), establish a link

if { $distance < 300 } {

puts “Connectivity between $src and $dst established (distance = $distance)”

$ns duplex-link $src $dst 2Mb 10ms DropTail

} else {

puts “Connectivity between $src and $dst lost (distance = $distance)”

$ns detach-link $src $dst

}

}

# Schedule periodic connectivity checks between nodes

for {set i 1} {$i <= 10} {incr i} {

$ns at [expr $i * 1.0] “check_connectivity $sender $forwarder”

$ns at [expr $i * 1.0] “check_connectivity $forwarder $receiver”

}

# Step 3: Implement Store-and-Forward Mechanism

proc store_and_forward {src dst bundle_size delay} {

global ns

# Create a TCP agent at the source and a sink at the destination

set tcp [new Agent/TCP]

set sink [new Agent/TCPSink]

$ns attach-agent $src $tcp

$ns attach-agent $dst $sink

# Connect the TCP agent to the sink

$ns connect $tcp $sink

# Simulate the transmission of a bundle of data (large data transfer)

set ftp [new Application/FTP]

$ftp attach-agent $tcp

$ftp start 1.0   ;# Start transmission at 1 second

$ftp stop 3.0    ;# Stop transmission at 3 seconds (simulating a bundle)

# After some delay (simulating intermittent connectivity), forward the bundle

$ns at [expr 3.0 + $delay] “forward_bundle $src $dst $bundle_size”

}

proc forward_bundle {src dst bundle_size} {

global ns

puts “Forwarding bundle of size $bundle_size bytes from $src to $dst…”

# Simulate bundle forwarding after connection restoration

# Create a TCP agent at the intermediate node and forward the data

set tcp_forward [new Agent/TCP]

set sink_forward [new Agent/TCPSink]

$ns attach-agent $src $tcp_forward

$ns attach-agent $dst $sink_forward

$ns connect $tcp_forward $sink_forward

set ftp_forward [new Application/FTP]

$ftp_forward attach-agent $tcp_forward

$ftp_forward start 5.0   ;# Forward the bundle after the connection is restored

$ftp_forward stop 6.5    ;# Stop forwarding after 1.5 seconds

}

# Step 4: Schedule Store-and-Forward Operations

# Schedule store-and-forward operation between sender and forwarder

$ns at 0.5 “store_and_forward $sender $forwarder 5000 2.0”

# Step 5: Finish the Simulation

# Schedule the end of the simulation

$ns at 15.0 “finish”

# Run the simulation

$ns run

  1. Explanation of the Script
  • Node Mobility: The sender, forwarder, and receiver nodes are transfer based on the stated mobility patterns using the setdest command, and mimicking activate and intermittent connectivity within the network.
  • Intermittent Connectivity: The check_connectivity process that verifies the distance among the nodes and determines or eliminates links dynamically according to their proximity. These nodes are ascertain a link if they are in a range and lose the link if they transfer out of range.
  • Store-and-Forward Mechanism: The store_and_forward technique that replicates the bundling data at the sender and storing it up to the association to the next hop is obtainable. The forward_bundle process sends the bundle while the connection is restored.
  • TCP for Data Transmission: The script uses TCP to replicate the large bundle transmissions among the nodes.
  1. Run the Simulation

We can save the script as dtn_architecture.tcl then run it using:

ns dtn_architecture.tcl

It will produce a trace file (out.tr) and a NAM file (out.nam). The trace file records the packet transmissions, also the NAM file permits to envision the DTN store-and-forward performance and node mobility.

  1. Visualize the Simulation in NAM

We can envision the simulation in NAM, use the given command:

nam out.nam

In NAM, we observe the nodes are moving based on their mobility patterns, and the links among them will arrive and disappear according to their distance. The data will be stored and forwarded as connectivity is ascertained.

  1. Advanced DTN Architectures Features
  • Buffer Management: Execute the buffer management in which every node can save bundles in a buffer and forward them while possible.

Example:

set buffer_size 10000  ;# Define a buffer size

proc store_bundle_in_buffer {forwarder bundle_size} {

global buffer_size

if { $bundle_size <= $buffer_size } {

puts “Bundle stored in buffer at forwarder.”

set buffer_size [expr $buffer_size – $bundle_size]

} else {

puts “Buffer full at forwarder! Cannot store bundle.”

}

}

# Simulate storing a bundle in the buffer at the forwarder

$ns at 3.0 “store_bundle_in_buffer $forwarder 5000”

  • Custody Transfer: Execute the custody transfer in which a node acquires responsibility for make certain that the bundle is sent.

Example:

proc custody_transfer {node} {

puts “Custody transfer at node $node: Node is now responsible for bundle delivery.”

}

# Schedule custody transfer at the forwarder node

$ns at 2.5 “custody_transfer $forwarder”

  • Routing Protocols: Execute the DTN-specific routing protocol like Epidemic Routing, Spray-and-Wait, or Prophet Routing, that are created for intermittent networks.

In conclusion, we were present the information on how to setup basic simulation, and how to execute the Network DTN architectures in the Network simulation called ns2 including examples with codes. Additional materials will be offered regarding this topic in various tool.

Our team helps you implement Network DTN Architectures using the NS2 tool. Simply provide your project details, and we will assist you with performance analysis, node mobility, message forwarding, buffer management, and routing methods for DTNs.