How to Begin Implement Network Resource Utilization in NS3

To begin implementing and examining Network Resource Utilization within NS3, during the simulation we focus on how efficiently network resources such as bandwidth, energy, and processing power are being leveraged. This parameter offers insights into the effectiveness of the network’s operation in diverse traffic and environmental situations. Here’s a simplest method to get started:

Steps to Implement Network Resource Utilization in NS3

  1. Understand Network Resource Utilization
  • Definition:
    • The percentage of the resources is used dynamically for effective data transmission to the entire obtainable resources.

Resource Utilization=Resources UsedTotal Resources Available×100\text{Resource Utilization} = \frac{\text{Resources Used}}{\text{Total Resources Available}} \times 100Resource Utilization=Total Resources AvailableResources Used​×100

  • Types of Resources:
    • Bandwidth: Data sent through volume of available channel.
    • Energy: Energy exhausted by nodes for transmission, reception, and idle states.
    • Processing Power: CPU or memory handling for packet managing and routing.
  1. Set Up NS3 Simulation Environment
  1. Install NS3:
    • We should install NS3 and download it on the computer.
  2. Choose a Network Type:
    • Based on the application, we can use PointToPoint, Wifi, or Lte components.
  3. Select Resources to Measure:
    • Choose resources whether estimating the bandwidth utilization, energy consumption, or both.
  1. Monitor Resource Utilization
  1. Bandwidth Utilization:
    • Monitor the total throughput which is equated to the highest available bandwidth with FlowMonitor.
  2. Energy Utilization:
    • Compute the energy utilized by nodes using Energy Framework of NS3.
  1. Implement Resource Utilization Calculation

Here’s a sample NS3 script for determining the bandwidth and energy consumption within a WiFi network.

Example Script: Network Resource 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”

#include “ns3/flow-monitor-helper.h”

using namespace ns3;

class ResourceUtilizationCalculator {

public:

ResourceUtilizationCalculator(double maxBandwidth, double totalEnergy)

: m_maxBandwidth(maxBandwidth), m_totalEnergy(totalEnergy), m_totalThroughput(0), m_energyConsumed(0) {}

void TrackThroughput(Ptr<FlowMonitor> monitor, double simulationTime) {

FlowMonitor::FlowStatsContainer stats = monitor->GetFlowStats();

m_totalThroughput = 0;

for (const auto &flow : stats) {

m_totalThroughput += (flow.second.rxBytes * 8.0) / simulationTime; // Throughput in bits/s

}

}

void TrackEnergyConsumption(EnergySourceContainer energySources) {

m_energyConsumed = 0;

for (uint32_t i = 0; i < energySources.GetN(); ++i) {

Ptr<BasicEnergySource> energySource = DynamicCast<BasicEnergySource>(energySources.Get(i));

if (energySource) {

m_energyConsumed += (m_totalEnergy – energySource->GetRemainingEnergy());

}

}

}

void CalculateUtilization() {

double bandwidthUtilization = (m_totalThroughput / m_maxBandwidth) * 100;

double energyUtilization = (m_energyConsumed / m_totalEnergy) * 100;

NS_LOG_UNCOND(“Bandwidth Utilization: ” << bandwidthUtilization << “%”);

NS_LOG_UNCOND(“Energy Utilization: ” << energyUtilization << “%”);

}

private:

double m_maxBandwidth; // Maximum available bandwidth in bits/s

double m_totalEnergy;  // Total energy available in Joules

double m_totalThroughput; // Total throughput in bits/s

double m_energyConsumed;  // Total energy consumed in Joules

};

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.SetPositionAllocator(“ns3::RandomRectanglePositionAllocator”,

“X”, StringValue(“ns3::UniformRandomVariable[Min=0.0|Max=100.0]”),

“Y”, StringValue(“ns3::UniformRandomVariable[Min=0.0|Max=100.0]”));

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

internet.Install(nodes);

// Assign 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 resource utilization

FlowMonitorHelper flowmonHelper;

Ptr<FlowMonitor> monitor = flowmonHelper.InstallAll();

ResourceUtilizationCalculator calculator(5e6, 100.0); // Max bandwidth: 5 Mbps, Total energy: 100 Joules

Simulator::Schedule(Seconds(10.0), &ResourceUtilizationCalculator::TrackThroughput, &calculator, monitor, 10.0);

Simulator::Schedule(Seconds(10.0), &ResourceUtilizationCalculator::TrackEnergyConsumption, &calculator, energySources);

Simulator::Schedule(Seconds(10.1), &ResourceUtilizationCalculator::CalculateUtilization, &calculator);

Simulator::Run();

Simulator::Destroy();

return 0;

}

Explanation of the Script

  1. Bandwidth Utilization:
    • Estimate the total throughput and then equates it with the highest obtainable bandwidth utilization with the support of FlowMonitor.
  2. Energy Utilization:
    • Observes the energy which is used up by nodes with BasicEnergySource.
  3. Resource Utilization Calculation:
    • At the end of the simulation, computes and records the bandwidth and energy consumption rates.
  4. WiFi Configuration:
    • Sets up a basic ad-hoc WiFi network.
  1. Run the Simulation
  1. Build the script and then execute the simulation in NS3:

./waf –run “resource-utilization-example”

  1. Monitor the records for bandwidth and energy consumption percentages.

We had shown uncomplicated method that contains several steps and practical example coding for executing and examining the Network Resource Utilization in NS3 environment. Further innovative details regarding this topic will follow.