How to Begin Implement Network Energy Utilization in ns3
To implement Network Energy Utilization in NS3, we can use the Energy Framework to estimate on how the network devices are consuming during replication for energy. Energy uses the estimates the amount of energy consumed through the network, typically in conditions such as wireless communication or sensor networks in which energy efficiency is Complex.
Steps to Implement Network Energy Utilization in NS3
- Understand Energy Utilization
- Definition: Energy utilization suggests to the number of energy consumed through network devices for forwarded, receive, or process data.
- Key Metrics:
- Total Energy Consumption: Calculate the energy consumed through all devices in Joules.
- Energy Per Byte Transmitted: Energy Per Byte=Total Energy ConsumedTotal Data Transmitted\text{Energy Per Byte} = \frac{\text{Total Energy Consumed}}{\text{Total Data Transmitted}}Energy Per Byte=Total Data TransmittedTotal Energy Consumed
- Energy Per Successful Transmission: Energy Per Transmission=Total Energy ConsumedNumber of Successful Packets\text{Energy Per Transmission} = \frac{\text{Total Energy Consumed}}{\text{Number of Successful Packets}}Energy Per Transmission=Number of Successful PacketsTotal Energy Consumed
- Set Up NS3 Environment
- Install NS3:
- Assure the NS3 environment is installed. Download it from the NS3 website.
- Choose a Network Type:
- Use wireless networks such as Wifi or Lte, in which energy usage is important.
- Enable the Energy Framework:
- NS3 has involves the Energy Framework for design the energy sources and traffic.
- Configure Energy Models
- Energy Source:
- Used the BasicEnergySource for express the initial energy of devices.
- Setting the features such as initial energy and energy reduction rate.
- Device Energy Model:
- Assign the WifiRadioEnergyModel network devices for WiFi improvements.
- Used for the LTE environment LteRadioEnergyModel.
- Implement Energy Utilization Calculation
Under is a sample script for estimate and log energy application in a WiFi network.
Example Script: Energy Utilization in NS3
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/internet-module.h”
#include “ns3/wifi-module.h”
#include “ns3/mobility-module.h”
#include “ns3/energy-module.h”
#include “ns3/applications-module.h”
using namespace ns3;
class EnergyUtilizationCalculator {
public:
EnergyUtilizationCalculator() : m_totalEnergyConsumed(0), m_totalDataTransmitted(0) {}
void AddEnergyConsumption(double energy) {
m_totalEnergyConsumed += energy;
}
void AddDataTransmitted(uint64_t data) {
m_totalDataTransmitted += data;
}
void CalculateEnergyUtilization() {
NS_LOG_UNCOND(“Total Energy Consumed: ” << m_totalEnergyConsumed << ” Joules”);
NS_LOG_UNCOND(“Total Data Transmitted: ” << m_totalDataTransmitted / 1e6 << ” MB”);
if (m_totalDataTransmitted > 0) {
NS_LOG_UNCOND(“Energy Per Byte Transmitted: ” << m_totalEnergyConsumed / m_totalDataTransmitted << ” J/byte”);
}
}
private:
double m_totalEnergyConsumed; // Total energy in Joules
uint64_t m_totalDataTransmitted; // Total data transmitted in bytes
};
EnergyUtilizationCalculator calculator;
void MonitorEnergyConsumption(Ptr<BasicEnergySource> energySource) {
double initialEnergy = energySource->GetInitialEnergy();
double remainingEnergy = energySource->GetRemainingEnergy();
double energyConsumed = initialEnergy – remainingEnergy;
calculator.AddEnergyConsumption(energyConsumed);
}
void MonitorDataTransmitted(Ptr<FlowMonitor> monitor, double simulationTime) {
FlowMonitor::FlowStatsContainer stats = monitor->GetFlowStats();
uint64_t totalData = 0;
for (auto const &flow : stats) {
totalData += flow.second.rxBytes;
}
calculator.AddDataTransmitted(totalData);
}
int main(int argc, char *argv[]) {
CommandLine cmd;
cmd.Parse(argc, argv);
// Create nodes
NodeContainer nodes;
nodes.Create(2);
// Configure WiFi
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default();
wifiPhy.SetChannel(wifiChannel.Create());
WifiHelper wifi;
wifi.SetStandard(WIFI_PHY_STANDARD_80211g);
WifiMacHelper mac;
mac.SetType(“ns3::AdhocWifiMac”);
NetDeviceContainer devices = wifi.Install(wifiPhy, mac, nodes);
// Configure mobility
MobilityHelper mobility;
mobility.SetMobilityModel(“ns3::ConstantPositionMobilityModel”);
mobility.Install(nodes);
// Configure energy sources
BasicEnergySourceHelper energySourceHelper;
energySourceHelper.Set(“BasicEnergySourceInitialEnergyJ”, DoubleValue(100.0)); // 100 Joules initial energy
EnergySourceContainer energySources = energySourceHelper.Install(nodes);
// Configure device energy models
WifiRadioEnergyModelHelper wifiRadioEnergyHelper;
wifiRadioEnergyHelper.Install(devices, energySources);
// Install Internet stack
InternetStackHelper stack;
stack.Install(nodes);
// Configure IP addresses
Ipv4AddressHelper address;
address.SetBase(“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces = address.Assign(devices);
// Configure applications
UdpEchoServerHelper server(9);
ApplicationContainer serverApp = server.Install(nodes.Get(1));
serverApp.Start(Seconds(1.0));
serverApp.Stop(Seconds(10.0));
UdpEchoClientHelper client(interfaces.GetAddress(1), 9);
client.SetAttribute(“MaxPackets”, UintegerValue(100));
client.SetAttribute(“Interval”, TimeValue(MilliSeconds(100)));
client.SetAttribute(“PacketSize”, UintegerValue(1024));
ApplicationContainer clientApp = client.Install(nodes.Get(0));
clientApp.Start(Seconds(2.0));
clientApp.Stop(Seconds(10.0));
// Monitor data transmitted
FlowMonitorHelper flowmonHelper;
Ptr<FlowMonitor> monitor = flowmonHelper.InstallAll();
Simulator::Schedule(Seconds(10.0), &MonitorDataTransmitted, monitor, 10.0);
// Monitor energy consumption
Ptr<BasicEnergySource> energySource = DynamicCast<BasicEnergySource>(energySources.Get(0));
Simulator::Schedule(Seconds(10.0), &MonitorEnergyConsumption, energySource);
// Calculate energy utilization
Simulator::Schedule(Seconds(10.0), &EnergyUtilizationCalculator::CalculateEnergyUtilization, &calculator);
Simulator::Run();
Simulator::Destroy();
return 0;
}
Explanation of the Script
- Energy Source:
- A BasicEnergySource track begins and remaining energy stages for estimate the energy usage.
- Energy Model:
- WifiRadioEnergyModel computes the energy consumption for forwarding a, response, and idle conditions.
- Data Transmission:
- FlowMonitor during the replication for estimates the amount of data forwarded.
- Energy Utilization Calculation:
- Associates the energy usage and data transmitted for calculate the per byte energy forwarded.
- Run the Simulation
- Build the script:
./waf –run “energy-utilization-example”
- Detect the records for energy usage, data transmitted, and energy application performance of metrics.
- Analyze Results
- Impact of Traffic Load:
- Enhance the packet rates or sizes and follow the modification in energy utilization.
- Impact of Distance:
- Improve the distance among nodes for estimate the impact of transmission energy.
we had learned about how the energy consumption analyse the results in ns3 simulator and also deliver and elaborate the further insights how the energy consumption will perform in other simulation tools.