How to Implement Network Bundling Protocols in NS2
To implement the Network Bundling Protocols in ns2, these protocols are commonly used in Delay Tolerant Networks (DTNs) in which the network connectivity is intermittent and data must be saved and moved through disconnected nodes. The Bundle Protocol (BP) is an important protocol in such networks, allowing data to be grouped together and sent in a “store-and-forward” method. While NS2 lacks the built-in for DTN protocols, however you can execute a basic simplified bundling protocol by replicating packet bundling, delay and dispatching. We have provided the instruction to help you accomplish it in ns2:
Key Concepts of Network Bundling Protocols:
- Bundle: A bundle is a large data packet that has numerous smaller packets or pieces of data.
- Store-and-Forward: When nodes are detached, they store data (bundles) and send them when connectivity is restored.
- Delay Tolerance: Manage the long delays amongst nodes by building the bundling protocols.
- Custody Transfer: In some implementations, a node may take accountable for making certain that the bundle reaches its destination.
Steps to Implement Network Bundling in NS2
- Model Bundles: Replicate bundles as large packets that have several smaller packets.
- Store-and-Forward Mechanism: Execute a queue at each node where bundles are stored when there is no connectivity. The node forwards the bundle when connectivity is restored.
- Delay Simulation: Mimic intermittent network connections and delays in bundle transmission.
Example: Simulating Network Bundling in NS2
The given example demonstrates how to set up a simple bundling protocol in NS2, where packets are grouped together and deliver as a solitary large data unit (bundle) across a network with intermittent connectivity.
Step 1: Set Up the Network and Bundle Transmission
# 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 nodes (representing DTN nodes)
$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 three 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_ 800; $receiver set Y_ 800; $receiver set Z_ 0
# Create duplex links between sender and forwarder, and forwarder and receiver
$ns duplex-link $sender $forwarder 2Mb 10ms DropTail
$ns duplex-link $forwarder $receiver 2Mb 10ms DropTail
# Step 2: Bundle packets at the sender
# Procedure to bundle packets before transmission
proc create_bundle {src dst} {
puts “Creating a bundle of packets at sender…”
# Simulate bundling multiple smaller packets into one large bundle
set bundle_size 1000 ;# Simulate a large bundle (1000 bytes)
set num_packets 10 ;# Number of smaller packets being bundled
set total_data_size [expr $bundle_size * $num_packets]
puts “Bundle size: $total_data_size bytes”
# Send the bundle to the next node (forwarder)
send_bundle $src $dst $total_data_size
}
# Step 3: Transmit the bundle from the sender to the forwarder
# Procedure to simulate bundle transmission
proc send_bundle {src dst size} {
global ns
# Create a TCP agent at the source
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 node)
$ns connect $tcp $sink
# Simulate a large data transfer (bundle transmission)
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp start 1.0 ;# Start transmission at 1 second
$ftp stop 2.5 ;# Stop transmission at 2.5 seconds
}
# Step 4: Store-and-Forward at the intermediate node
# Procedure to simulate store-and-forward behavior at the forwarder node
proc store_and_forward {forwarder dst} {
puts “Forwarder: Storing bundle due to intermittent connectivity…”
global ns
# Simulate storing the bundle (delay due to intermittent connectivity)
set delay 5.0 ;# Simulate a 5-second delay before forwarding
# After the delay, forward the bundle to the receiver
$ns at [expr [$ns now] + $delay] “send_bundle $forwarder $dst 10000”
}
# Schedule bundle creation and transmission from sender to forwarder
$ns at 0.5 “create_bundle $sender $forwarder”
# Schedule store-and-forward at the forwarder node
$ns at 2.5 “store_and_forward $forwarder $receiver”
# Schedule the end of the simulation
$ns at 10.0 “finish”
# Run the simulation
$ns run
- Explanation of the Script
- Bundle Creation: The create_bundle technique at the sender node bundles numerous smaller packets into a large “bundle” packet, simulating how data is assembled together in DTNs.
- Transmission: The TCP is used to transmit the bundle from the sender to the forwarder node.
- Store-and-Forward: When the forwarder node obtains the bundle, it simulates intermittent connectivity by postponing the forwarding process (using the store_and_forward procedure).
- Forwarding: After a delay (simulating intermittent connectivity), the forwarder node transfers the bundle to the receiver.
- Run the Simulation
Store the script as network_bundling.tcl and execute it using:
ns network_bundling.tcl
This will create a trace file (out.tr) and a NAM file (out.nam). The trace file logs the packet transmissions, and the NAM file permits you to visualize the bundling and forwarding process.
- Visualize the Network in NAM
To visualize the simulation in NAM, use the below command:
nam out.nam
In the NAM visualization, you will see:
- Sender to Forwarder Transmission: The sender sets up a bundle and transfers it to the forwarder.
- Store-and-Forward Delay: The forwarder stores the bundle for a specific amount of time (simulating intermittent connectivity) before dispatching it to the receiver.
- Advanced Network Bundling Features
- Custody Transfer: Execute custody transfer, where the intermediate node takes accountability for the bundle and makes sure its delivery to the next node.
Example of Custody Transfer Simulation:
proc custody_transfer {forwarder} {
puts “Custody Transfer: Forwarder is now responsible for delivering the bundle.”
}
$ns at 2.5 “custody_transfer $forwarder”
- Multi-Hop Bundling: Accomplish multi-hop bundling, where the bundle is dispatched through several intermediate nodes before reaching the destination.
- Dynamic Routing for Bundling: Use dynamic routing (e.g., AODV) to choose the best path for forwarding the bundle depends on the network conditions.
The provided demonstration will walk you through the entire accomplishment of network simulation, visualization for the implementation of Network Bundling Protocols using ns2 tool. You can also include their advanced mechanisms into the simulation by following the above manual. Contact us for the best results in implementing Network Bundling Protocols using the ns2 tool. We offer fresh ideas and project support. Our focus is on DTN protocols also so get best results for your projects.