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

How to Calculate Network Resource utilization in Ns3

To calculate network resource utilization in ns3, by monitoring and measuring the various network resources such as bandwidth, CPU, memory, and energy consumption that how much these resources are used in the network operation. The following steps will guide on how to calculate the bandwidth utilization using the ns3.

Step-by-step guide to Calculate Bandwidth Utilization in ns3:

  1. Set Up the NS3 Environment:
    • Make sure NS3 is installed.
  2. Define the Network Topology:
    • Create a network topology with nodes and links.
  3. Install Applications:
    • Install traffic-generating applications on the nodes to simulate network traffic.
  4. Monitor Bandwidth Usage:
    • Use trace sources or callbacks to monitor the amount of data sent and received over the network links.
  5. Calculate Bandwidth Utilization:
    • Calculate the utilization percentage based on the total available bandwidth and the amount of bandwidth actually used.

Example Code

Here an example given on how to set up a simple NS3 simulation to calculate bandwidth utilization. This example uses a basic point-to-point network and UDP applications.

#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/flow-monitor-module.h”

using namespace ns3;

NS_LOG_COMPONENT_DEFINE (“BandwidthUtilizationExample”);

uint64_t totalBytesReceived = 0;

void PacketReceivedCallback (Ptr<const Packet> packet)

{

totalBytesReceived += packet->GetSize ();

}

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

{

CommandLine cmd;

cmd.Parse (argc, argv);

Time::SetResolution (Time::NS);

NodeContainer nodes;

nodes.Create (2);

PointToPointHelper pointToPoint;

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

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

NetDeviceContainer devices;

devices = pointToPoint.Install (nodes);

InternetStackHelper stack;

stack.Install (nodes);

Ipv4AddressHelper address;

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

Ipv4InterfaceContainer interfaces = address.Assign (devices);

// Create a UDP server on node 1

UdpServerHelper server (9);

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

serverApp.Start (Seconds (1.0));

serverApp.Stop (Seconds (10.0));

// Create a UDP client on node 0

UdpClientHelper client (interfaces.GetAddress (1), 9);

client.SetAttribute (“MaxPackets”, UintegerValue (320));

client.SetAttribute (“Interval”, TimeValue (MilliSeconds (10)));

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

ApplicationContainer clientApp = client.Install (nodes.Get (0));

clientApp.Start (Seconds (2.0));

clientApp.Stop (Seconds (10.0));

// Monitor packet reception

Config::ConnectWithoutContext (“/NodeList/1/ApplicationList/*/$ns3::UdpServer/Rx”, MakeCallback (&PacketReceivedCallback));

Simulator::Stop (Seconds (11.0));

Simulator::Run ();

Simulator::Destroy ();

// Calculate bandwidth utilization

double simulationTime = 9.0; // in seconds (from 1s to 10s)

double linkCapacity = 5.0 * 1000000 / 8; // 5 Mbps in bytes per second

double totalCapacity = linkCapacity * simulationTime;

double utilization = (totalBytesReceived / totalCapacity) * 100;

std::cout << “Total Bytes Received: ” << totalBytesReceived << ” bytes” << std::endl;

std::cout << “Link Capacity: ” << linkCapacity << ” bytes per second” << std::endl;

std::cout << “Total Capacity: ” << totalCapacity << ” bytes” << std::endl;

std::cout << “Bandwidth Utilization: ” << utilization << “%” << std::endl;

return 0;

}

Explanation

  1. Setup: The code sets up a simple point-to-point network between two nodes with a 5 Mbps link.
  2. Applications: A UDP server is installed on node 1, and a UDP client is installed on node 0 to generate traffic.
  3. Packet Reception Callback: The PacketReceivedCallback function increments the totalBytesReceived counter each time a packet is received by the server.
  4. Simulation: The simulation is run for 10 seconds, with the UDP client sending packets starting at 2 seconds.
  5. Bandwidth Utilization Calculation: After the simulation, the total bytes received is compared to the total link capacity to calculate the utilization percentage.

Running the Simulation

Compile and run the simulation using the following commands in ns3 environment:

./waf configure

./waf build

./waf –run the-script-name

Replace the-script-name with the actual name of the script file.

Here the calculation of bandwidth utilization which is one of the most commonly measured Network Resource is elaborately explained above by giving example of basic point-to-point network.

To compute the Network Resource Utilization within the Network Scenario 3 (Ns3) of your project, kindly provide us with the necessary parameters. We are committed to delivering optimal results.

Furthermore, we assist in the measurement of various network resources, including bandwidth, CPU, memory, and energy consumption. We invite you to share your project’s details with us for further assistance.