How to Begin Implement Network Residual Energy Level in NS3
To implement and study the network residual energy levels in NS3, we can utilize the Energy Framework that is design for monitor the energy usage of nodes in a network. Residual energy level are characterizes the remaining energy for a node next consuming the energy for communication or computation challenges.
Steps to Implement Network Residual Energy Level in NS3
- Understand Residual Energy in NS3
- Definition: Residual energy is the change among the initial energy for a node in energy consumed during the network performance.
- Metrics:
- Initial Energy (EiE_iEi): Energy available at the start of the simulation.
- Remaining Energy (ErE_rEr): Energy left at any given time.
- Consumed Energy: Ec=Ei−ErE_c = E_i – E_rEc=Ei−Er
- Set up NS3 Simulation Environment
- Install NS3:
- Certify the tool NS3 is installed and functional. Download it from the NS3 website.
- Choose a Network Scenario:
- Residual energy following is generally used in wireless networks, sensor networks or mobile ad hoc networks (MANETs).
- Enable Energy Framework
- Energy Source:
- Use BasicEnergySource or LiIonEnergySource for describe the initial energy of a node.
- Device Energy Model:
- Use WifiRadioEnergyModel or further device-specific energy design to replicate the energy usage.
- Implement Residual Energy Tracking
Below is a sample script which monitors the records for residual energy levels in the nodes for a wireless network.
Example Script: Residual Energy in NS3
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/energy-module.h”
#include “ns3/wifi-module.h”
#include “ns3/mobility-module.h”
using namespace ns3;
void LogResidualEnergy(Ptr<BasicEnergySource> energySource) {
double remainingEnergy = energySource->GetRemainingEnergy();
NS_LOG_UNCOND(“Time: ” << Simulator::Now().GetSeconds() << “s, Remaining Energy: ” << remainingEnergy << ” Joules”);
Simulator::Schedule(Seconds(1.0), &LogResidualEnergy, energySource);
}
int main(int argc, char *argv[]) {
CommandLine cmd;
cmd.Parse(argc, argv);
// Create nodes
NodeContainer nodes;
nodes.Create(2);
// Set mobility model
MobilityHelper mobility;
mobility.SetMobilityModel(“ns3::ConstantPositionMobilityModel”);
mobility.Install(nodes);
// Configure WiFi
WifiHelper wifi;
wifi.SetStandard(WIFI_PHY_STANDARD_80211g);
WifiMacHelper mac;
YansWifiPhyHelper phy = YansWifiPhyHelper::Default();
YansWifiChannelHelper channel = YansWifiChannelHelper::Default();
phy.SetChannel(channel.Create());
NetDeviceContainer devices = wifi.Install(phy, mac, nodes);
// Install Internet stack
InternetStackHelper stack;
stack.Install(nodes);
// Add energy sources
BasicEnergySourceHelper energySourceHelper;
energySourceHelper.Set(“BasicEnergySourceInitialEnergyJ”, DoubleValue(100.0)); // Initial energy = 100 Joules
EnergySourceContainer energySources = energySourceHelper.Install(nodes);
// Add WiFi energy model
WifiRadioEnergyModelHelper radioEnergyHelper;
radioEnergyHelper.Install(devices, energySources);
// Log residual energy of the first node
Simulator::Schedule(Seconds(1.0), &LogResidualEnergy, DynamicCast<BasicEnergySource>(energySources.Get(0)));
Simulator::Run();
Simulator::Destroy();
return 0;
}
Explanation of the Script
- Energy Source:
- BasicEnergySource is further to every node by an initial energy of 100 Joules.
- Device Energy Model:
- WifiRadioEnergyModel design the energy usage of WiFi radios.
- Residual Energy Logging:
- The LogResidualEnergy function logs contain the remaining energy for a first node to each second.
- Wireless Configuration:
- WiFi is used to make a transmission among the nodes.
- Run the Simulation
- Generate the script:
./waf –run “your-script-name”
- Follow the logs for residual energy values for complete the duration.
- Analyze Results
- Energy Consumption Trends:
- Plot are residual energy for complete the duration to examine the energy consumption.
- Node Lifetime:
- Introduce on how well the long nodes can endure the actions before reducing the energy.
- Impact of Traffic:
- Launch the congestion and examine the impact of energy usage.
Advanced Extensions
- Dynamic Scenarios:
- Enhance the mobility models for replicate the mobile nodes and monitor the energy levels for below the dynamic environments.
- Multiple Energy Sources:
- Test by alter the energy source settings for sample LiIonEnergySource.
- Energy Efficiency:
- Association of residual energy monitoring by parameter metrics such as data transmitted per Joule.
- Visualization:
- Transfer the residual energy for logs to tools such as Python, MATLAB, or Excel for graphical analysis.
- Protocol Comparison:
- Associate the energy usage of change the MAC or routing protocols.
In the above setup, we clearly demonstrate how to calculate the residual energy in the ns3 tool that has to setup the network model and then apply the energy model to calculate the remaining energy. For further clarification, please check the additional manual to be provided.