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

How to Calculate QOS in ns3

To calculate the Quality of Service (QoS) in a network states to the performance level of a service, like throughput, delay or latency, jitter, and packet loss. In ns3, we can calculate and investigate these QoS metrics by gathering related data during the simulation run and configuring the network simulation.

Steps to Calculate QoS Metrics in ns3:

  1. Set Up the Network Topology:
    • Describe the network topology by making nodes, connecting them with proper links, and installing network protocols like TCP, UDP.
  2. Install Traffic Generators:
    • To generate traffic by using these applications like OnOffApplication, BulkSendApplication, or UdpEchoClientServer. Configure them with numerous traffic patterns, packet sizes, and data rates as essential.
  3. Enable Tracing and Logging:
    • To capture data during the simulation by using ns3 tracing mechanisms. We can permit ASCII or PCAP tracing to get complete logs of packet transmissions.

AsciiTraceHelper ascii;

pointToPoint.EnableAsciiAll(ascii.CreateFileStream(“qos.tr”));

pointToPoint.EnablePcapAll(“qos”);

  1. Measure Throughput:
    • Throughput is the amount of data effectively delivered over a network in a given amount of time. To assess throughput:
      • Obtain the amount of data received by the receiver.
      • Determine throughput as data_received / simulation_time.

uint32_t bytesTotal = DynamicCast<PacketSink>(sinkApp.Get(0))->GetTotalRx();

double throughput = (bytesTotal * 8.0) / (1e6 * simulationTime); // in Mbps

  1. Measure Latency (Delay):
    • Latency is the time taken for a packet to travel from the source to the destination.
      • Capture the send time at the source and the receive time at the end.
      • Estimate the delay for each packet and calculate average delay.

Simulator::Schedule(Seconds(0.1), &CalculateDelay, socket, srcAddr, dstAddr);

void CalculateDelay(Ptr<Socket> socket, Address src, Address dst) {

Time sendTime = Simulator::Now();

// Send packet

Ptr<Packet> packet = Create<Packet>(size);

socket->SendTo(packet, 0, dst

// Capture receive time

Time recvTime = Simulator::Now();

Time delay = recvTime – sendTime;

std::cout << “Packet delay: ” << delay.GetSeconds() << ” seconds” << std::endl;

}

  1. Measure Jitter:
    • Jitter is the variation in packet arrival times. It can be measured by taking the difference among the delays of consecutive packets.

double jitter = fabs(delay1 – delay2);

  1. Measure Packet Loss:
    • It is the percentage of packets that are sent but not effectively received.
      • Count the number of packets received and the number of packets sent.
      • Evaluate packet loss as (packets_sent – packets_received) / packets_sent * 100.

uint32_t packetsSent = sourceSocket->GetTxCount();

uint32_t packetsReceived = sinkSocket->GetRxCount();

double packetLoss = ((packetsSent – packetsReceived) / (double)packetsSent) * 100;

  1. Run the Simulation:
    • Run the simulation, after setting up the scenario and measurement.

Simulator::Run();

Simulator::Destroy();

  1. Analyse the Results:
    • Consider the trace files and logs to calculate the QoS metrics after the simulation. We can use ns3’s built-in tools, or external tools like MATLAB or Python, to process the data.

Example Implementation:

The given below is a simplified example for computing throughput and delay in a point-to-point network:

#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”

using namespace ns3;

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

// Set up the 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”));

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 the application (OnOff application)

uint16_t port = 9;

OnOffHelper onoff(“ns3::UdpSocketFactory”, InetSocketAddress(interfaces.GetAddress(1), port));

onoff.SetConstantRate(DataRate(“500kbps”));

ApplicationContainer apps = onoff.Install(nodes.Get(0));

apps.Start(Seconds(1.0));

apps.Stop(Seconds(10.0));

// Set up the packet sink on the receiver

PacketSinkHelper sink(“ns3::UdpSocketFactory”, InetSocketAddress(Ipv4Address::GetAny(), port));

apps = sink.Install(nodes.Get(1));

apps.Start(Seconds(1.0));

apps.Stop(Seconds(10.0));

// Enable tracing

AsciiTraceHelper ascii;

pointToPoint.EnableAsciiAll(ascii.CreateFileStream(“qos.tr”));

pointToPoint.EnablePcapAll(“qos”);

// Run the simulation

Simulator::Run();

// Calculate and display throughput

uint32_t totalBytes = DynamicCast<PacketSink>(apps.Get(0))->GetTotalRx();

double throughput = (totalBytes * 8) / (1e6 * 9.0); // in Mbps

std::cout << “Throughput: ” << throughput << ” Mbps” << std::endl;

Simulator::Destroy();

return 0;

}

Summary of QoS Metrics:

  • Throughput: Amount of data moved successfully over time in Mbps.
  • Delay (Latency): From source to destination, time taken for a packet to travel in seconds.
  • Jitter: Difference in packet arrival times in seconds.
  • Packet Loss: During transmission, percentage of packets lost.

Over this informations, we saw throughput, packet loss, delay, and jitter. We had execute step-by-step procedure to calculate QOS in ns3 tool. We will offer further details about QOS in various tools. Struggling to get your project done so to Quality of Service (QoS) share with us your parameter details we provide you with simulation results and best project outcomes.