Ns3 Projects for B.E/B.Tech M.E/M.Tech PhD Scholars.  Phone-Number:9790238391   E-mail: ns3simulation@gmail.com

How to Calculate Energy Efficiency Networking in ns3

To calculate energy efficiency networking in ns3, we need to measure the energy consumed by network devices for successfully delivering data. Here is a complete on calculating energy efficiency in ns3.

Steps for calculating energy efficiency

  1. Set up the simulation :
  • To simulate the network, create a network topology with nodes, protocols and links configured.
  1. Install energy models :
  • To simulate energy consumption, set up energy models on the nodes.
  1. Install applications :
  • To generate and receive traffic, set up application.
  1. Trace energy consumption :
  • To monitor energy levels of the nodes, use ns3 tracing capabilities.
  1. Calculate energy efficiency :
    • Calculate the ratio of data successfully delivered to the energy consumed.

Example for simple energy efficiency

Below is an example to demonstrate the process:

  1. set up the simulation

Create a simple network topology by using a point-to-point link between two nodes.

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

#include “ns3/point-to-point-module.h”

#include “ns3/applications-module.h”

#include “ns3/energy-module.h”

#include “ns3/simple-device-energy-model.h”

#include “ns3/simple-energy-source.h”

using namespace ns3;

NS_LOG_COMPONENT_DEFINE (“EnergyEfficiencyExample”);

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

{

// Create two nodes

NodeContainer nodes;

nodes.Create (2);

// Set up the point-to-point link

PointToPointHelper pointToPoint;

pointToPoint.SetDeviceAttribute (“DataRate”, StringValue (“5Mbps”));

pointToPoint.SetChannelAttribute (“Delay”, StringValue (“2ms”));

// Install link devices on nodes

NetDeviceContainer devices;

devices = pointToPoint.Install (nodes);

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

// Set up energy source and device energy model

BasicEnergySourceHelper basicSourceHelper;

basicSourceHelper.Set (“BasicEnergySourceInitialEnergyJ”, DoubleValue (100)); // Initial energy in Joules

EnergySourceContainer sources = basicSourceHelper.Install (nodes);

WifiRadioEnergyModelHelper radioEnergyHelper;

DeviceEnergyModelContainer deviceModels = radioEnergyHelper.Install (devices, sources);

// Set up the UDP echo server on Node 1

uint16_t port = 9; // well-known echo port number

UdpEchoServerHelper echoServer (port);

ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));

serverApps.Start (Seconds (1.0));

serverApps.Stop (Seconds (10.0));

// Set up the UDP echo client on Node 0

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

echoClient.SetAttribute (“MaxPackets”, UintegerValue (100));

echoClient.SetAttribute (“Interval”, TimeValue (Seconds (0.1))); // 10 packets per second

echoClient.SetAttribute (“PacketSize”, UintegerValue (1024));

ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));

clientApps.Start (Seconds (2.0));

clientApps.Stop (Seconds (10.0));

// Enable tracing

AsciiTraceHelper ascii;

pointToPoint.EnableAsciiAll (ascii.CreateFileStream (“energy-efficiency.tr”));

// Run the simulation

Simulator::Run ();

// Calculate energy efficiency

double totalEnergyConsumed = 0.0;

for (EnergySourceContainer::Iterator iter = sources.Begin (); iter != sources.End (); ++iter)

{

Ptr<EnergySource> source = *iter;

double initialEnergy = source->GetInitialEnergy ();

double remainingEnergy = source->GetRemainingEnergy ();

totalEnergyConsumed += (initialEnergy – remainingEnergy);

}

// Get the total data delivered

uint64_t totalDataDelivered = echoClient.GetTotalData () * 8; // Convert bytes to bits

double energyEfficiency = totalDataDelivered / totalEnergyConsumed; // bits per Joule

std::cout << “Total Energy Consumed: ” << totalEnergyConsumed << ” Joules” << std::endl;

std::cout << “Total Data Delivered: ” << totalDataDelivered << ” bits” << std::endl;

std::cout << “Energy Efficiency: ” << energyEfficiency << ” bits/Joule” << std::endl;

Simulator::Destroy ();

return 0;

}

  1. Install energy models

To simulate the energy consumption of the nodes, the BasicEnergySource and WifiRadioEnergyModel are used.

  1. Install applications

In the above example, on one node a UDP echo server is installed. and on another node, a UDP echo client is installed. The client sends 1000 packets, each 1024 bytes in size, at an interval of 0.01 seconds.

  1. Trace Energy Consumption

By monitoring the EnergySource, energy consumption of each node is tracked.

  1. Calculate Energy Efficiency

By dividing the total data delivered by the total energy consumed,  energy efficiency is calculated.

  1. Simulation setup :

Two nodes are created. Those nodes are connected using a point-to-point link.

  1. Install Energy Models:

To simulate energy consumption, attach energy sources and device energy models to the nodes.

  1. Application setup :

On one node, a UDP echo server is installed. and On another node, a UDP echo client is installed. Configure the client to send a specified number of packets at a specified interval.

  1. Trace Energy Consumption:

Monitor the energy levels of the nodes throughout the simulation.

  1. Calculating Energy Efficiency:

Define energy efficiency as the ratio of total data delivered to the total energy consumed. Use the collected energy consumption data to calculate this ratio.

So we went through the guide on calculating energy efficiency networking in ns3 by measuring the energy consumed by network devices for successfully delivering data. Also, we offer more topics related to energy efficiency networking.

We provide you with advice regarding the performance of the simulation for your project and  continue following the performance analysis. For optimal outcomes, we also provide complete information on Calculation Energy Efficiency Networking for ns3tool.Contact ns3simulation.com.