How to Calculate Network Energy Efficiency in NS2
To calculate the Network Energy Efficiency using NS2, which particularly in energy-constrained networks such as wireless sensor networks (WSNs), that refers to the amount of energy used to effectively deliver the data packets from a origin to an end. To estimate the network energy efficiency, we want to deliberate both the energy consumed by the network nodes and the data delivered.
The common formula for energy efficiency in a network is:
Energy Efficiency=Total Data Successfully DeliveredTotal Energy Consumed\text{Energy Efficiency} = \frac{\text{Total Data Successfully Delivered}}{\text{Total Energy Consumed}}Energy Efficiency=Total Energy ConsumedTotal Data Successfully Delivered
This metric computes how much data is sent per unit of energy consumed and is normally stated such as bytes per joule. Given below is a brief process to compute the network energy efficiency in NS2:
Steps to Calculate Network Energy Efficiency in NS2
- Enable the Energy Model in NS2
To compute the energy efficiency, we want to initially allow the energy model in the NS2 simulation. The energy model tracks the energy consumed by each node in the course of numerous operations, like transmission, reception, and idle periods.
Given below is an instance of how to configure the energy model in the NS2 script:
# Create a new simulator object
set ns [new Simulator]
# Set energy model parameters for each node
set initialEnergy 100.0 ;# Initial energy in Joules
set txPower 0.5 ;# Transmission power in Watts
set rxPower 0.3 ;# Reception power in Watts
set idlePower 0.01 ;# Idle power in Watts
# Create nodes and assign energy models
for {set i 0} {$i < 10} {incr i} {
set node($i) [$ns node]
$node($i) add-energy-model $initialEnergy $txPower $rxPower $idlePower
}
In this example:
- initialEnergy: Initial energy for each node in joules.
- txPower, rxPower, idlePower: Power consumption during the transmission, reception, and idle time.
- Monitor Energy Consumption
We want to trace the energy consumption for each node through the simulation. We can be verified the remaining energy of each node at any given time using the below command:
$node($i) energy
To assess the total energy consumed by each node then subtract the remaining energy from the initial energy.
- Calculate Total Energy Consumed
In the last part of the simulation we estimate the total energy consumed by all nodes. We can automate it using a loop in the TCL script:
set totalEnergyConsumed 0
for {set i 0} {$i < 10} {incr i} {
set consumed [expr $initialEnergy – [$node($i) energy]]
set totalEnergyConsumed [expr $totalEnergyConsumed + $consumed]
}
puts “Total Energy Consumed: $totalEnergyConsumed Joules”
This script:
- Iterates over all nodes and computes the energy consumed by each node.
- Gathers the total energy consumed by all nodes.
- Calculate Total Data Delivered
To measure the energy efficiency, we want to understand the total amount of data effectively delivered. It is normally calculated such as the number of bytes or packets received at the end node.
We can extort this data from the trace file, which NS2 generates. In the trace file, each received packet is recorded as an event. Given below is an AWK script to assess the total data successfully delivered:
awk ‘{
if ($1 == “r” && $4 == “tcp”) {
total_data += $6; # Sum the size of all received packets
}
} END {
print “Total Data Successfully Delivered: ” total_data ” bytes”;
}’ out.tr
In this script:
- r: Indicates a packet received event.
- $6: Signifies the packet size (in bytes).
The script adding up the size of all effectively received packets (TCP packets in this case) to compute the total data delivered.
- Calculate Energy Efficiency
When we have the total energy consumed and the total data successfully delivered then we can be assessed the energy efficiency using the formula:
Energy Efficiency=Total Data Successfully DeliveredTotal Energy Consumed\text{Energy Efficiency} = \frac{\text{Total Data Successfully Delivered}}{\text{Total Energy Consumed}}Energy Efficiency=Total Energy ConsumedTotal Data Successfully Delivered
It can be done in the TCL script after computing both values:
set energyEfficiency [expr $totalDataDelivered / $totalEnergyConsumed]
puts “Network Energy Efficiency: $energyEfficiency bytes per joule”
It will provide the network energy efficiency such as bytes per joule that expresses how efficiently the network is using its energy to deliver the data.
- Example Workflow
The following is a step-by-step summary for evaluating network energy efficiency in NS2:
- Set up the Energy Model for each node in the simulation.
- Run the simulation and generate a trace file, which records all packet transmission and reception events.
- Assess total energy consumed by tracking the energy usage of each node in the course of the simulation.
- Calculate the total data delivered by parsing the trace file and adding up the sizes of all packets successfully received at the end.
- Estimate energy efficiency using the formula:
Energy Efficiency=Total Data Successfully Delivered (bytes)Total Energy Consumed (joules)\text{Energy Efficiency} = \frac{\text{Total Data Successfully Delivered (bytes)}}{\text{Total Energy Consumed (joules)}}Energy Efficiency=Total Energy Consumed (joules)Total Data Successfully Delivered (bytes)
- Evaluate and understand the energy efficiency metric rely on the particular network protocol, topology, and conditions in the simulation.
- Advanced Considerations
Based on the kind of network and protocol we are replicating, we can refine the energy efficiency calculation by deliberating:
- Idle Energy Consumption: When nodes are idle to understand the true energy cost, contain the energy spent.
- Multi-hop Networks: In multi-hop networks, to deliberate the energy consumed by intermediate nodes when forwarding the packets.
- MAC Layer Protocols: If replicating MAC protocols then the energy consumed in collision avoidance, retransmissions, and control packet overheads should also be encompassed.
- Node Failure: In the networks in which nodes may fail because of the energy depletion, the energy efficiency calculation may end when a particular percentage of nodes deplete their energy.
Here, we understand and get more knowledge about the Network Energy Efficiency that were calculated utilising some formulas and examples in NS2 tool. Moreover, we will be delivered valuable informations regarding this topic in another manual.
To assess Network Energy Efficiency using the NS2 tool, provide us with all your parameter details, and we will assist you with performance analysis results. Discover the best project ideas with our guidance.