To simulate Wireless Body Area Networks (WBANs) using NS2 has needs to set up wireless sensor nodes positioned on or around a human body to interact with data, often the health-related information, to a central node such as a Personal Server or Sink Node. WBANs are frequently utilized in healthcare applications to track vital signs such as heart rate, temperature, glucose levels, etc.
In NS2, we need to design WBAN by using wireless nodes to signify the sensor nodes, describing proper mobility models, and replicate data communication among these sensor nodes and a central node using protocols such as IEEE 802.15.6 (not directly supported in NS2 however it can be simulated by using 802.11 or similar wireless models).
Steps to Simulate Wireless Body Area Network Projects in NS2
- Components of a WBAN Simulation
A typical WBAN simulation in NS2 that contain:
- Sensor Nodes: Nodes placed on the human body to track different physiological signals (e.g., temperature, heart rate).
- Sink Node (Personal Server): A node that gathers information from all the sensors and forwards it to an external system or health server.
- Wireless Channel: Typically modelled with a short-range, low-power communication technology such as IEEE 802.15.6 or IEEE 802.15.4 (you can emulate this by configuring 802.11 with lower power and range).
- Traffic and Routing Protocols: Lightweight traffic for continuous or periodic data collection.
- Basic WBAN Simulation Setup in NS2
Example: Simulating WBAN Using Wireless Sensor Nodes
In this simulation, we will generate several wireless nodes to signify sensors placed on the body and simulate data transmission to a sink node.
# Create NS2 simulator instance
set ns [new Simulator]
# Define a wireless channel (with parameters suited for WBANs)
set wban_channel [new Channel/WirelessChannel]
# Configure wireless nodes for the body sensors
$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 $wban_channel
# Create a Sink node (Personal Server)
set sink [$ns node]
$sink set X_ 0.0
$sink set Y_ 0.0
$sink set Z_ 0.0
# Create sensor nodes (representing body sensors for monitoring)
set temp_sensor [$ns node]
set heart_rate_sensor [$ns node]
set glucose_sensor [$ns node]
# Set positions for the sensors (assuming the body is centered at (0,0))
$temp_sensor set X_ 10.0
$temp_sensor set Y_ 0.0
$temp_sensor set Z_ 0.0
$heart_rate_sensor set X_ 0.0
$heart_rate_sensor set Y_ 10.0
$heart_rate_sensor set Z_ 0.0
$glucose_sensor set X_ -10.0
$glucose_sensor set Y_ 0.0
$glucose_sensor set Z_ 0.0
# Set up UDP agents to simulate communication between sensors and the sink
set udp_temp [new Agent/UDP]
set udp_heart [new Agent/UDP]
set udp_glucose [new Agent/UDP]
set sink_null [new Agent/Null]
$ns attach-agent $temp_sensor $udp_temp
$ns attach-agent $heart_rate_sensor $udp_heart
$ns attach-agent $glucose_sensor $udp_glucose
$ns attach-agent $sink $sink_null
# Connect UDP agents to the sink node (data collection)
$ns connect $udp_temp $sink_null
$ns connect $udp_heart $sink_null
$ns connect $udp_glucose $sink_null
# Set up Constant Bit Rate (CBR) traffic to simulate periodic data transmission
set temp_traffic [new Application/Traffic/CBR]
$temp_traffic set packetSize_ 256
$temp_traffic set interval_ 1.0 ;# Temperature data every second
$temp_traffic attach-agent $udp_temp
set heart_traffic [new Application/Traffic/CBR]
$heart_traffic set packetSize_ 256
$heart_traffic set interval_ 0.5 ;# Heart rate data every 0.5 seconds
$heart_traffic attach-agent $udp_heart
set glucose_traffic [new Application/Traffic/CBR]
$glucose_traffic set packetSize_ 256
$glucose_traffic set interval_ 2.0 ;# Glucose data every 2 seconds
$glucose_traffic attach-agent $udp_glucose
# Schedule the traffic for each sensor
$ns at 1.0 “$temp_traffic start”
$ns at 1.0 “$heart_traffic start”
$ns at 1.0 “$glucose_traffic start”
# Enable tracing for analysis
set tracefile [open wban_trace.tr w]
$ns trace-all $tracefile
# Define a finish procedure to end the simulation
proc finish {} {
global ns tracefile
$ns flush-trace
close $tracefile
exit 0
}
# Schedule simulation end at 10 seconds
$ns at 10.0 “finish”
$ns run
Explanation:
- Wireless Nodes and Channel: The script set up wireless nodes to signify sensors and a sink node. The wireless channel models short-range communication appropriate for WBAN.
- Sink Node: A centralized sink node (Personal Server) gathers data from the sensors.
- Sensor Nodes: Three wireless nodes are generated to replicate sensors that track temperature, heart rate, and glucose levels.
- UDP Communication: UDP agents are utilized to simulate data transmission from the sensor nodes to the sink.
- CBR Traffic: We utilize CBR (Constant Bit Rate) traffic to replicate periodic health data transmission from each sensor to the sink at different intervals (such as heart rate data every 0.5 seconds, glucose data every 2 seconds).
- Tracing: The simulation outcomes are written to a trace file (wban_trace.tr) for performance evaluation.
- Mobility in WBAN
While WBANs are usually implemented on a human body, we need to replicate mobility (e.g., the person walking or moving). NS2 enables you to simulate mobility by configuring a movement pattern for the sink node (representing the person wearing the sensors).
Example: Simulating Movement of the Person (Sink Node)
# Simulate movement of the person (sink node)
$sink setdest 100.0 100.0 2.0 ;# Move the sink to (100, 100) at 2 m/s
This command moves the sink node, replicate the movement of the person wearing the sensors.
- Advanced WBAN Simulation: Energy Model
In WBAN, the energy consumption of sensor nodes is critical as these nodes are usually battery-powered. NS2 delivers an energy model to replicate energy usage in the course of communication.
Example: Adding Energy Model to WBAN Simulation
# Configure energy model for sensor nodes
$ns node-config -energyModel EnergyModel -initialEnergy 100 -rxPower 0.5 -txPower 1.0 -idlePower 0.05
# Set up energy model for each sensor node
$temp_sensor add-energy-model EnergyModel
$heart_rate_sensor add-energy-model EnergyModel
$glucose_sensor add-energy-model EnergyModel
This setup allocates an energy model to each sensor node, enable you to simulate and track energy consumption in the course of the simulation. We can query the remaining energy of each sensor at any time.
Example: Checking Energy Levels
# Check remaining energy of temperature sensor after 5 seconds
$ns at 5.0 “puts \”Remaining energy of temp_sensor: [$temp_sensor energy]\””
This command will print the remaining energy of the temperature sensor at 5 seconds into the simulation.
- Performance Metrics for WBAN
After executing the simulation, we need to evaluate several key parameters for WBAN:
- Throughput: The rate at which data is successfully routed from the sensor nodes to the sink.
- End-to-End Delay: The time taken for data to travel from the sensor to the sink.
- Packet Delivery Ratio (PDR): The percentage of packets successfully delivered to the sink.
- Energy Consumption: The amount of energy consumed by each sensor node in the period of the simulation.
- Example: Analysing the Trace File
To measure the parameters such as throughput and packet delivery, we can parse the trace file created by NS2 using AWK or Python scripts.
Example: Counting Packets Received by Sink
awk ‘{ if ($1 == “r” && $4 == “AGT” && $7 == “udp”) count++; } END { print “Packets received: “, count; }’ wban_trace.tr
This AWK script counts the number of UDP packets successfully received by the sink node.
- Visualizing WBAN Simulation in NAM
We can envision the WBAN simulation using NAM (Network Animator) to track the packet flow and sensor-to-sink communication:
# Enable NAM trace file
set namfile [open wban_simulation.nam w]
$ns namtrace-all $namfile
# Open NAM after the simulation ends
proc finish {} {
global ns namfile
$ns flush-trace
close $namfile
exec nam wban_simulation.nam &
exit 0
}
Execute the following command after the simulation to view the animation:
nam wban_simulation.nam
In the end of the simulation setup, you can able to learn and summarize the concepts and approaches that help you to walk you how to simulate and analyse the outcomes for wireless body area network using ns2 analysis framework. It helps to communicate over the network like healthcare related information. Further details will be added later in upcoming manuals.
Share the details of your Wireless Body Area Network Project with us. In return, we will provide you with tailored simulation support. Our expertise includes sensor nodes and appropriate mobility models relevant to your projects.