How to Implement Underwater Sensor Network in ns2

To implement an Underwater Sensor Network (UWSN) in ns2 has needs to emulate the distinct features of underwater communication, like an acoustic propagation, long delays, and higher error rates because of the underwater environment. Since ns2 is not originally planned for underwater networks, we can estimate UWSNs by tailoring the specific contexts of the simulation, like communication channels, propagation models, and node configurations. In the below procedures will guide you to implement the simple UWSN in ns2:

Step-by-Step implementation:

Step 1: Conceptualizing the UWSN Simulation

A typical Underwater Sensor Network includes:

  1. Underwater Sensor Nodes: These nodes are implemented underwater to collect data.
  2. Surface Nodes or Sinks: Nodes that collect data from the underwater sensors, possibly communicating it to a central processing station.
  3. Acoustic Communication: The primary mode of communication underwater that is slower and more prone to errors than radio communication used in terrestrial networks.

Step 2: Create the Tcl Script

The given below is an example Tcl script that emulates a simple UWSN with a few underwater sensor nodes communicating with a surface node.

Example Tcl Script for Simulating an Underwater Sensor Network in ns2

# Create a simulator object

set ns [new Simulator]

# Define the topography object (a 3D underwater environment)

set topo [new Topography]

$topo load_flatgrid 1000 1000 1000  # 1km x 1km x 1km area representing underwater space

# Create the General Operations Director (GOD) for wireless simulations

create-god 4  # Number of nodes (3 underwater sensors + 1 surface node)

# Configure the nodes for underwater communication

$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 \

-channelType Channel/WirelessChannel \

-topoInstance $topo \

-agentTrace ON \

-routerTrace ON \

-macTrace ON \

-movementTrace OFF

# Open trace and NAM files for recording the simulation

set tracefile [open uwsn_out.tr w]

$ns trace-all $tracefile

set namfile [open uwsn_out.nam w]

$ns namtrace-all-wireless $namfile 1000 1000

# Define a finish procedure to close files and end the simulation

proc finish {} {

global ns tracefile namfile

$ns flush-trace

close $tracefile

close $namfile

exec nam uwsn_out.nam &

exit 0

}

# Create underwater sensor nodes

set sensor0 [$ns node]

set sensor1 [$ns node]

set sensor2 [$ns node]

# Create the surface node (sink)

set surface_node [$ns node]

# Set initial positions for underwater sensor nodes (in 3D space)

$sensor0 set X_ 200.0

$sensor0 set Y_ 300.0

$sensor0 set Z_ 500.0  # Depth of 500 meters

$sensor1 set X_ 500.0

$sensor1 set Y_ 500.0

$sensor1 set Z_ 600.0  # Depth of 600 meters

$sensor2 set X_ 800.0

$sensor2 set Y_ 700.0

$sensor2 set Z_ 400.0  # Depth of 400 meters

# Set the position of the surface node (stationary on the surface)

$surface_node set X_ 500.0

$surface_node set Y_ 500.0

$surface_node set Z_ 0.0  # Surface level

# Introduce delay to simulate the slow propagation of acoustic signals

proc acoustic_delay {src dst packet_size delay_factor} {

global ns

# Calculate propagation delay based on distance and speed of sound in water

set distance [expr sqrt(pow([expr $src set X_] – [expr $dst set X_], 2) + \

pow([expr $src set Y_] – [expr $dst set Y_], 2) + \

pow([expr $src set Z_] – [expr $dst set Z_], 2))]

set speed_of_sound 1500.0  # Speed of sound in water (m/s)

set propagation_delay [expr $distance / $speed_of_sound * $delay_factor]

# Simulate transmission with the calculated delay

$ns at [expr $ns now + $propagation_delay] “$src send-packet $dst $packet_size”

}

# Function to simulate packet transmission from the sensor to the surface node

proc send-packet {dst packet_size} {

global ns surface_node

# Create a TCP agent at the sender (sensor node)

set tcp [new Agent/TCP]

$ns attach-agent $dst $tcp

# Create a TCP sink at the receiver (surface node)

set sink [new Agent/TCPSink]

$ns attach-agent $surface_node $sink

# Connect the sender to the receiver

$ns connect $tcp $sink

# Create an FTP application to simulate data transmission

set ftp [new Application/FTP]

$ftp attach-agent $tcp

$ftp start

# Stop the FTP after some time (simulate transmission completion)

$ns at 20.0 “$ftp stop”

}

# Schedule packet transmission from each sensor to the surface node

acoustic_delay $sensor0 $surface_node 512 1.5

acoustic_delay $sensor1 $surface_node 512 1.5

acoustic_delay $sensor2 $surface_node 512 1.5

# Schedule the end of the simulation

$ns at 40.0 “finish”

# Run the simulation

$ns run

Step 3: Run the Tcl Script

Save the script with a .tcl extension, for instance, uwsn_simulation.tcl. Executes the script using the following command in terminal:

ns uwsn_simulation.tcl

Step 4: Visualize the Simulation

To visualize the simulation, open the generated NAM file using:

nam uwsn_out.nam

Script Explanation

  • Underwater Sensor Nodes: The nodes sensor0, sensor1, and sensor2 signify underwater sensors implemented at different depths.
  • Surface Node: The surface_node acts as a sink that gathers data from the underwater sensors.
  • Acoustic Delay Simulation: The acoustic_delay function estimates the propagation latency according to the distance among the sensor and the surface node that emulates the slow speed of acoustic communication.
  • Packet Transmission: The send-packet function emulates the transmission of data packets from the sensor nodes to the surface node.

Customization

  • Mobility Models: Execute mobility models to mimic the movement of underwater sensors like due to ocean currents.
  • More Complex Network Topology: Add more sensor nodes and surface nodes to emulate a more complex UWSN.
  • Error Models: Establish error models to emulate the impacts of underwater noise, multipath propagation, and other factors that disturb acoustic communication.
  • Advanced Routing Protocols: Execute or emulate routing protocols intended for UWSNs, like VBF (Vector-Based Forwarding) or DBR (Depth-Based Routing).

Limitations

  • Simplified Approximation: The script delivers a simplified approximation of UWSN behaviour and cannot fully capture the complex dynamics of underwater acoustic communication.
  • No Physical Layer Simulation: This simulation does not include detailed modelling of acoustic signal propagation, multipath fading or Doppler shifts.
  • Limited UWSN-Specific Features: Ns2 is not considered for UWSNs, so the simulation is limited to simple functionality and high-level abstractions.

Here, we clearly understood the basic implementation procedures for Underwater Sensor Network that were securely implemented using the ns2 tool we also outline additional information about how the Underwater Sensor Network performs in diverse simulation tool. Achieve best results in your simulations, including communication channels, propagation models, and node configurations, with the expertise of our developers. We provide you with insightful guidance to ensure successful implementation for your projects.