How to Implement Network DTN Prototypes in NS2
To implement the Delay Tolerant Network (DTN) prototypes within NS2 has needs to encompass, simulating networks including intermittent connectivity in which nodes are store, carry, and forward data to overwhelmed difficulties posed by disrupted or delayed communications. This prototypes frequently use bundling protocols, buffer management, store-and-forward, and specialized routing procedures such as Spray-and-Wait, Epidemic Routing, and Prophet Routing. Given below is a simple techniques to execute this prototypes in NS2:
Key Elements of a DTN Prototype:
- Store-and-Forward Mechanism: These nodes are store messages (bundles) and forward them while a communication link becomes obtainable.
- Routing Protocols: We can use the DTN-specific routing procedures such as Epidemic Routing, Spray-and-Wait, or Prophet Routing to handle message forwarding.
- Buffer Management: Handle the storage of messages (bundles) at every node.
- Custody Transfer: These nodes may take responsibility for make sure the delivery of a bundle.
- Intermittent Connectivity: To replicate the intermittent connectivity by make certain and inactivating links dynamically.
- Node Mobility: Nodes are move, making an opportunities for message sending as they come into contact with each other.
Steps to Implement DTN Prototypes in NS2
- Define Nodes with Intermittent Connectivity: To replicate the nodes are moving in and out of range of each other, then making opportunities for message forwarding.
- Implement a Routing Protocol: We can use a DTN routing algorithm, like Epidemic Routing or Spray-and-Wait.
- Simulate Store-and-Forward Mechanism: Execute a logic to store messages in a buffer up to a connection is obtainable.
- Buffer Management: Manage the buffer size at every node and also handle incoming and outgoing messages.
- Node Mobility and Connectivity: Mimic node mobility to make an opportunities for contact among the nodes.
Example: Implementing a Simple DTN Prototype in NS2
Below instance, we will execute a simple DTN prototype which uses a store-and-forward mechanism including Epidemic Routing. This routing protocol will try to provide messages to the end by flooding the networks, including the nodes are forwarding messages to all their neighbours.
Step 1: Define DTN Nodes and Mobility
# 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 DTN nodes with a simple mobility model
$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, forwarder1, forwarder2, and receiver
set sender [$ns node]
set forwarder1 [$ns node]
set forwarder2 [$ns node]
set receiver [$ns node]
# Set node positions for NAM visualization
$sender set X_ 100; $sender set Y_ 100; $sender set Z_ 0
$forwarder1 set X_ 300; $forwarder1 set Y_ 300; $forwarder1 set Z_ 0
$forwarder2 set X_ 600; $forwarder2 set Y_ 600; $forwarder2 set Z_ 0
$receiver set X_ 900; $receiver set Y_ 900; $receiver set Z_ 0
# Define mobility for the nodes to simulate dynamic network topology
$ns at 0.0 “$sender setdest 200 200 10.0”
$ns at 0.0 “$forwarder1 setdest 400 400 5.0”
$ns at 0.0 “$forwarder2 setdest 700 700 7.0”
$ns at 0.0 “$receiver setdest 800 800 3.0”
Step 2: Implement the Epidemic Routing Algorithm
# Implement the Epidemic Routing Protocol
proc epidemic_routing {src dst bundle_size} {
global ns
# Create a TCP agent at the source node
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 (forwarder/receiver node)
$ns connect $tcp $sink
# Simulate the transmission of a bundle of data (large message)
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
}
# Step 3: Simulate Store-and-Forward Mechanism
# Store-and-forward at intermediate nodes using the Epidemic Routing protocol
proc store_and_forward {src dst bundle_size delay} {
global ns
puts “Storing and forwarding bundle from $src to $dst…”
# Schedule forwarding after the delay (simulate intermittent connectivity)
$ns at [expr 3.0 + $delay] “epidemic_routing $src $dst $bundle_size”
}
# Step 4: Check Connectivity and Schedule Bundle Forwarding
# Simulate dynamic connectivity checks between nodes
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), forward the bundle
if { $distance < 300 } {
puts “Connectivity established between $src and $dst (distance = $distance)”
epidemic_routing $src $dst 5000
} else {
puts “No connectivity between $src and $dst (distance = $distance)”
}
}
# Schedule connectivity checks between sender, forwarders, and receiver
for {set i 1} {$i <= 10} {incr i} {
$ns at [expr $i * 1.0] “check_connectivity $sender $forwarder1”
$ns at [expr $i * 1.0] “check_connectivity $forwarder1 $forwarder2”
$ns at [expr $i * 1.0] “check_connectivity $forwarder2 $receiver”
}
# Schedule bundle forwarding at intermediate nodes
$ns at 0.5 “store_and_forward $sender $forwarder1 5000 2.0”
$ns at 2.5 “store_and_forward $forwarder1 $forwarder2 5000 1.5”
$ns at 4.5 “store_and_forward $forwarder2 $receiver 5000 1.0”
# Step 5: Finish the Simulation
# Schedule the end of the simulation
$ns at 15.0 “finish”
# Run the simulation
$ns run
- Explanation of the Script
- Node Mobility: These nodes (sender, forwarders, and receiver) are move based on the mobility models that replicating the dynamic and intermittent nature of a DTN.
- Epidemic Routing: In this routing procedure, messages (bundles) are transmitted among the nodes. If two nodes are in communication range, the message is sent. This replicates the Epidemic Routing protocol in which the messages are simulated then sent to several nodes to maximise the chance of delivery.
- Store-and-Forward Mechanism: The store_and_forward protocol that mimics storing a message at an intermediate node and sending it while a connection is obtainable.
- Connectivity Check: The check_connectivity technique actively verifies if two nodes are in the communication range. If they are, the message is sent.
- Run the Simulation
We can save the script as dtn_prototype.tcl then run it using:
ns dtn_prototype.tcl
It will produce a trace file (out.tr) and a NAM file (out.nam). The trace file records the packet transmissions then the NAM file is permits to envision the DTN prototype, with the node mobility and message sending.
- Visualize the Simulation in NAM
We can visualize the simulation in NAM, use the below command:
nam out.nam
In NAM, we will observe the nodes are moving based on their mobility models, and data being forwarded from node to node as they come into contact.
- Advanced DTN Prototype Features
- Buffer Management: Append a logic to handle a buffer at every node. If the buffer is occupied, the node must drop or delay the forwarding of a few bundles.
Example:
set buffer_size 10000 ;# Define a buffer size
proc store_bundle_in_buffer {node bundle_size} {
global buffer_size
if { $bundle_size <= $buffer_size } {
puts “Bundle stored in buffer at node $node.”
set buffer_size [expr $buffer_size – $bundle_size]
} else {
puts “Buffer full at node $node! Cannot store bundle.”
}
}
- Custody Transfer: Execute a custody transfer in which intermediate nodes are take responsibility for make sure that the bundle reaches its end.
- Spray-and-Wait: Execute Spray-and-Wait routing in which a limited number of message duplicates are dispersed between the nodes, decreasing the overhead caused by Epidemic Routing.
In this manual, you can acquire the knowledge regarding how to replicate the network and how to execute the DTN prototypes in the simulation platform NS2. Further insights will be offered regarding this prototypes as required.
If you need help with Network DTN Prototypes, feel free to contact us. We provide the best guidance for implementation.