How to Calculate Network Energy Utilization in NS2
To calculate the network energy utilization using NS2 (Network Simulator 2), we want to configure an energy model for the nodes. Energy utilization refers to the total amount of energy consumed by the nodes during packet transmission, reception, and although idle. It is particularly vital within wireless sensor networks (WSNs), mobile ad hoc networks (MANETs), and other energy-constrained networks. The following is a step-by-step procedure to calculate the network energy utilization in NS2:
Steps to Calculate Network Energy Utilization:
- Define the Energy Model in NS2:
NS2 delivers an energy model, which permits to trace the energy consumption of nodes. We can be stipulated various energy consumption rates for transmission, reception, and idle states. Every single node will be consumed an energy based on the model in the course of the simulation. - Run the Simulation:
After setting up the energy model we can run the simulation, and the energy consumption of each node will be logged. - Calculate Total Energy Consumed:
The total energy utilization of the network can compute by adding the energy consumed by all the nodes during the simulation.
NS2 Energy Model Parameters:
To describe the energy model in NS2, we require to setup the below parameters:
- Initial Energy: The starting energy of each node (in joules).
- TxPower: Energy consumed for transmission (in watts).
- RxPower: Energy consumed for reception (in watts).
- IdlePower: Energy consumed while the node is idle (in watts).
Example Tcl Script to Set up Energy Model in NS2:
The following is an instance of how to configure a simple NS2 simulation with energy consumption tracking.
# Create a new simulator instance
set ns [new Simulator]
# Open trace file to record events
set tracefile [open trace.tr w]
$ns trace-all $tracefile
# Set up energy model parameters
set val(initialEnergy) 100.0 ;# Initial energy in joules
set val(txPower) 0.5 ;# Transmission power in watts
set val(rxPower) 0.3 ;# Reception power in watts
set val(idlePower) 0.01 ;# Idle power in watts
# Create mobile nodes and assign energy model
set node0 [$ns node]
set node1 [$ns node]
# Assign energy model to nodes
for {set i 0} {$i < 2} {incr i} {
$node($i) energy-model EnergyModel
$node($i) add-energy $val(initialEnergy)
}
# Create UDP agents and attach them to nodes
set udp [new Agent/UDP]
set null [new Agent/Null]
$ns attach-agent $node0 $udp
$ns attach-agent $node1 $null
$ns connect $udp $null
# Create traffic source (CBR) and attach it to UDP
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set packetSize_ 512
$cbr set rate_ 1Mb
# Start and stop traffic
$ns at 1.0 “$cbr start”
$ns at 5.0 “$cbr stop”
# Define finish procedure to output remaining energy
proc finish {} {
global ns node0 node1
puts “Node 0 remaining energy: [$node0 energy]”
puts “Node 1 remaining energy: [$node1 energy]”
$ns flush-trace
exit 0
}
# Schedule the end of the simulation
$ns at 6.0 “finish”
$ns run
- 1. Running the Simulation:
Once we run the simulation then NS2 will track the energy consumption for each node. In this script:
- Node 0 is sending packets to Node 1 through a UDP connection.
- The energy consumption is traced rely on the configured parameters.
- Trace File and Energy Consumption:
The simulation environment NS2 will generate a trace file (trace.tr), and at the destination of the simulation, the remaining energy of each node is printed. We can be estimated the energy used by subtracting the remaining energy from the initial energy.
Example Output (from finish procedure):
Node 0 remaining energy: 97.5
Node 1 remaining energy: 99.4
This outcomes displays the remaining energy for each node at the destination of the simulation.
- Calculate Energy Utilization:
To compute the total energy consumed during the simulation, we use the below formula:
Energy Utilization=Initial Energy−Remaining Energy\text{Energy Utilization} = \text{Initial Energy} – \text{Remaining Energy}Energy Utilization=Initial Energy−Remaining Energy
For example:
- Node 0 initial energy: 100.0 J
- Remaining energy: 97.5 J
- Energy consumed: 100.0−97.5=2.5 J100.0 – 97.5 = 2.5 \text{ J}100.0−97.5=2.5 J
- Node 1 initial energy: 100.0 J
- Remaining energy: 99.4 J
- Energy consumed: 100.0−99.4=0.6 J100.0 – 99.4 = 0.6 \text{ J}100.0−99.4=0.6 J
Total Network Energy Utilization:
The total energy consumption for the whole network is the sum of energy consumed by all nodes:
Total Energy Utilization=2.5 J+0.6 J=3.1 J\text{Total Energy Utilization} = 2.5 \text{ J} + 0.6 \text{ J} = 3.1 \text{ J}Total Energy Utilization=2.5 J+0.6 J=3.1 J
- Bash Script for Automating Energy Utilization Calculation:
If we have a large network then we might require to automate the computation of energy utilization using a script. Given below is a basic approach:
# Extract remaining energy from the trace file
grep “Node” tracefile.log > remaining_energy.txt
# Subtract remaining energy from initial energy for each node
awk ‘{ initial_energy=100.0; remaining_energy=$NF; energy_consumed=initial_energy-remaining_energy; print “Node ” NR “: Energy Consumed = ” energy_consumed ” J” }’ remaining_energy.txt
# Calculate total energy consumption across all nodes
awk ‘{ initial_energy=100.0; remaining_energy=$NF; total_consumed+=initial_energy-remaining_energy } END { print “Total Network Energy Utilization = ” total_consumed ” J” }’ remaining_energy.txt
- Energy Efficiency Calculation:
When we have the energy utilization, also we can compute the energy efficiency of the network such as how much data was sent per unit of energy consumed. The formula for energy efficiency is:
Energy Efficiency (bits/Joule)=Total Data Transmitted (bits)Total Energy Consumed (Joules)\text{Energy Efficiency (bits/Joule)} = \frac{\text{Total Data Transmitted (bits)}}{\text{Total Energy Consumed (Joules)}}Energy Efficiency (bits/Joule)=Total Energy Consumed (Joules)Total Data Transmitted (bits)
We can extort the total data transferred from the trace file and divide it by the total energy consumed to get the energy efficiency of the network.
Summary of Steps:
- Describe the energy model within NS2, stipulating initial energy, transmission power, reception power, and idle power.
- Run the simulation and trace the remaining energy of each node.
- Estimate the energy utilization by subtracting the remaining energy from the initial energy for each node.
- Add the energy consumed by all nodes to acquire the total network energy utilization
As above, we shown the computation approach using TCL and Bash script to calculate and analyse the Network energy utilization in the simulation platform NS2. Furthermore, we will be shared more informations about this topic as required.For any type of project details feel free to contact us we are ready with all the needed resources to guide you.