How to Begin Implement Network Energy Efficiency in NS3

To begin a network energy efficiency in NS3 has contains the compute of ratio useful for network activity in the total energy consumed. This can be implementing the performance of based on metrices such as data transmitted per joule, successful transmissions per joule, or equal effectiveness of parameter metrics.

Steps to Implement Network Energy Efficiency in NS3

  1. Understand Network Energy Efficiency
  • Definition: Network energy effectiveness has calculated the total of useful work for instance data transmitted, packets delivered per unit of energy consumed.
  • Metrics:
    • Energy Efficiency (EE): EE=Useful Work (e.g., Data Transmitted)Energy Consumed\text{EE} = \frac{\text{Useful Work (e.g., Data Transmitted)}}{\text{Energy Consumed}}EE=Energy ConsumedUseful Work (e.g., Data Transmitted)​
    • Examples of useful work:
      • Complete the byte has transmitted successfully.
      • Packets are delivered to the destination.
  1. Set Up the NS3 Simulation
  1. Install NS3:
    • Assure the NS3 is installed. Download it from the NS3 website.
  2. Select a Network Scenario:
    • Use the related network topology, like as wireless networks, sensor networks, or IoT setups.
  1. Enable Energy Framework

NS3 offers an Energy Framework which permits the design and monitor the energy usage.

  • Components:
    1. Energy Source: It designs for energy storage for sample a battery BasicEnergySource.
    2. Device Energy Model: It patterns the energy usage for devices for instance WiFi radios WifiRadioEnergyModel.
  1. Implement Energy Efficiency Calculation

Key Steps:

  1. It monitor the energy consumed using an energy source.
  2. Calculate the useful work for instance bytes transmitted or packets delivered.
  3. Estimate the energy efficiency using the formula: EE=Bytes Transmitted (or Packets Delivered)Energy Consumed (in Joules)\text{EE} = \frac{\text{Bytes Transmitted (or Packets Delivered)}}{\text{Energy Consumed (in Joules)}}EE=Energy Consumed (in Joules)Bytes Transmitted (or Packets Delivered)​

Example Script: Network Energy Efficiency in NS3

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/energy-module.h”

#include “ns3/wifi-module.h”

#include “ns3/internet-module.h”

#include “ns3/applications-module.h”

using namespace ns3;

class EnergyEfficiencyTracker {

public:

EnergyEfficiencyTracker() : m_totalBytesTransmitted(0) {}

 

void RecordTransmission(uint32_t bytes) {

m_totalBytesTransmitted += bytes;

}

void CalculateEfficiency(Ptr<BasicEnergySource> energySource) {

double energyConsumed = energySource->GetInitialEnergy() – energySource->GetRemainingEnergy();

if (energyConsumed > 0) {

double efficiency = m_totalBytesTransmitted / energyConsumed; // Bytes/Joule

NS_LOG_UNCOND(Simulator::Now().GetSeconds() << “s: Energy Efficiency = ” << efficiency << ” Bytes/Joule”);

} else {

NS_LOG_UNCOND(Simulator::Now().GetSeconds() << “s: No energy consumed yet.”);

}

}

private:

uint32_t m_totalBytesTransmitted;

};

EnergyEfficiencyTracker efficiencyTracker;

 

void PacketSentCallback(Ptr<const Packet> packet) {

efficiencyTracker.RecordTransmission(packet->GetSize());

}

int main(int argc, char *argv[]) {

CommandLine cmd;

cmd.Parse(argc, argv);

// Create nodes

NodeContainer nodes;

nodes.Create(2);

// 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);

// Assign IP addresses

Ipv4AddressHelper address;

address.SetBase(“10.1.1.0”, “255.255.255.0”);

Ipv4InterfaceContainer interfaces = address.Assign(devices);

// Add Energy Source

BasicEnergySourceHelper energySourceHelper;

energySourceHelper.Set(“BasicEnergySourceInitialEnergyJ”, DoubleValue(100.0)); // 100 Joules

EnergySourceContainer sources = energySourceHelper.Install(nodes);

// Add Device Energy Model

WifiRadioEnergyModelHelper radioEnergyHelper;

radioEnergyHelper.Install(devices, sources);

// Install applications

uint16_t port = 9;

UdpEchoServerHelper server(port);

ApplicationContainer serverApp = server.Install(nodes.Get(1));

serverApp.Start(Seconds(1.0));

serverApp.Stop(Seconds(10.0));

UdpEchoClientHelper client(interfaces.GetAddress(1), port);

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));

// Attach callback for transmitted packets

devices.Get(0)->TraceConnectWithoutContext(“PhyTxBegin”, MakeCallback(&PacketSentCallback));

// Schedule energy efficiency calculation

Simulator::Schedule(Seconds(10.0), &EnergyEfficiencyTracker::CalculateEfficiency, &efficiencyTracker, sources.Get(0

Simulator::Run();

Simulator::Destroy();

return 0;

}

Explanation of the Script

  1. Energy Consumption:
    • The BasicEnergySource monitor the energy consumed through the WiFi radio using WifiRadioEnergyModel.
  2. Data Transmission:
    • An UdpEchoClient forward the packets to an UdpEchoServer.
    • The PhyTxBegin trace is used to register the size of transmitted packets.
  3. Energy Efficiency Calculation:
    • The EnergyEfficiencyTracker computes the efficiency as: Efficiency (Bytes/Joule)=Total Bytes TransmittedEnergy Consumed\text{Efficiency (Bytes/Joule)} = \frac{\text{Total Bytes Transmitted}}{\text{Energy Consumed}}Efficiency (Bytes/Joule)=Energy ConsumedTotal Bytes Transmitted​
  4. Output:
    • The performance of parameter metrices such as energy efficiency for end of the replication.
  1. Run the Simulation
  1. Build the script:

./waf –run “your-script-name”

  1. Follow the logs for energy effectiveness values.
  1. Advanced Extensions
  1. Dynamic Scenarios:
    • Enhance the mobility models for replicate the mobile nodes and amount of energy effectiveness for below the dynamic environments.
  2. Network Protocol Comparison:
    • Associate the energy effectiveness for various MAC or routing protocols.
  3. Multi-Hop Networks:
    • Encompass the replication of containing the intermediate nodes in a multi-hop configuration.
  4. Traffic Patterns:
    • Used the realistic congestion designs for instance video streaming, IoT data.
  5. Visualization:
    • Distribute the outcomes for a file in graphical investigation using the tools such as Python or MATLAB.

In the above setup, we clearly demonstrate how to calculate the network energy efficiency in the ns3 tool that has to setup the network model and then apply the energy model to calculate the remaining energy. If you have concerns or queries, they will be addressed in a separate manual