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

How to Calculate Mean Opinion Score in ns3

The Mean Opinion Score (MOS) is a measure which is used to calculate the perceived quality of multimedia streams, specifically in voice and video communication. To calculate the MOS in ns3, we need to simulate the transmission of multimedia data, collect relevant Quality of Service (QoS) metrics that includes delay, jitter, and packet loss, and then mapping these metrics to MOS values that uses a suitable model. Here is a complete guide on calculating MOS in ns3.

Steps for calculation

  1. Set up your ns3 :
  • Make sure that ns3 is installed in the computer. If not, install it.
  1. Create a new ns3 script :
  • In the scratch directory of ns3, create a new script.
  1. Include necessary libraries :
  • In your script, include the necessary libraries.
  1. Define network topology :
  • For your network topology, create multiple nodes and configure the communication settings.
  1. Implement QoS Metrics Collection :
  • During the simulation, collect metrics such as delay, jitter, and packet loss.
  1. Calculate MOS :
  • To calculate MOS based on the collected QoS metrics using a suitable model, implement a function.

Example for calculating MOS in ns3

Here is the example for the calculation of MOS :

#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 (“MOSCalculationExample”);

double CalculateMOS(double delay, double jitter, double packetLoss)

{

// Example model for calculating MOS based on delay, jitter, and packet loss

double rFactor = 94.2 – (delay / 10.0) – (jitter / 5.0) – (packetLoss * 2.5);

double mos = 1.0 + (0.035 * rFactor) + (7.0 * 1e-6 * rFactor * (rFactor – 60.0) * (100.0 – rFactor));

if (mos < 1.0) mos = 1.0;

if (mos > 5.0) mos = 5.0;

return mos;

}

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

{

uint32_t nNodes = 2; // Number of nodes

double simulationTime = 10.0; // Total simulation time in seconds

CommandLine cmd;

cmd.AddValue(“nNodes”, “Number of nodes”, nNodes);

cmd.AddValue(“simulationTime”, “Total simulation time”, simulationTime);

cmd.Parse(argc, argv);

NodeContainer nodes;

nodes.Create(nNodes);

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

UdpEchoServerHelper echoServer(9);

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

serverApps.Start(Seconds(1.0));

serverApps.Stop(Seconds(simulationTime));

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

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

echoClient.SetAttribute(“Interval”, TimeValue(Seconds(0.1)));

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

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

clientApps.Start(Seconds(2.0));

clientApps.Stop(Seconds(simulationTime));

// Flow monitor to collect QoS metrics

FlowMonitorHelper flowmon;

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

Simulator::Stop(Seconds(simulationTime));

Simulator::Run();

// Calculate delay, jitter, and packet loss

Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier>(flowmon.GetClassifier());

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

double delay = 0.0;

double jitter = 0.0;

double packetLoss = 0.0;

uint32_t totalPackets = 0;

for (auto it = stats.begin(); it != stats.end(); ++it)

{

Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow(it->first);

if (t.destinationPort == 9)

{

delay += it->second.delaySum.GetSeconds();

jitter += it->second.jitterSum.GetSeconds();

packetLoss += it->second.lostPackets;

totalPackets += it->second.rxPackets + it->second.lostPackets;

}

}

if (totalPackets > 0)

{

delay /= totalPackets;

jitter /= totalPackets;

packetLoss /= totalPackets;

}

double mos = CalculateMOS(delay, jitter, packetLoss);

std::cout << “Mean Opinion Score (MOS): ” << mos << std::endl;

Simulator::Destroy();

return 0;

}

Explanation

  1. Nodes and links :

Nodes are created. Point-to-point links between nodes are configured.

  1. Applications :

On one node, a UDP echo server is installed. and On another node, a UDP echo server is installed to generate traffic.

  1. Flow monitor :

To collect QoS metrics such as delay, jitter, and packet loss during the simulation, used the FlowMonitor module.

  1. MOS logic :

To calculate the Mean Opinion Score based on the collected delay, jitter, and packet loss metrics,  CalculateMOS is implemented. Simple example model for calculating MOS is used. You can use more sophisticated models based on your requirements.

  1. Running the Simulation :

The simulation runs collecting QoS metrics using FlowMonitor. MOS is calculated and printed, after the simulation.

Overall, we had successfully learned on calculating Mean Opinion Score (MOS) in ns3 by simulating the transmission of multimedia data, collecting relevant Quality of Service (QoS) metrics such as delay, jitter, and packet loss, and then mapping these metrics to MOS values using a suitable model. Also, we provide more related information on Mean Opinion Score (MOS).

Kindly provide us with your parameters so that we can deliver optimal results for all Mean Opinion Score concepts in ns3.