To calculate goodput in ns3, we need to follow several steps. Because, Goodput is said to be the amount of successfully received application-layer data (excluding protocol overhead and retransmissions) per unit of time.so, to calculate this we need to measure the amount of useful transmitted data in a given period which are received by the destination node.
The steps given below will guide to calculate goodput in ns3:
Steps to Calculate Goodput in ns3
- Set Up ns3 Environment:
- Make sure ns3 is installed on the system.
- Create a New ns-3 Script:
- Create a new script file in the scratch directory of ns3, e.g., goodput_calculation.cc.
- Include Necessary Headers:
- Include the necessary ns3 headers in the script.
- Define Network Topology:
- Set up a network topology with multiple nodes.
- Implement Goodput Calculation Logic:
- Use application-level data to track the amount of useful data received and calculate goodput.
- Run the Simulation:
- Set the simulation time and run the simulation using Simulator::Run() and Simulator::Destroy().
Example Code:
#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 (“GoodputCalculationExample”);
void CalculateGoodput(Ptr<FlowMonitor> flowMonitor, Ptr<Ipv4FlowClassifier> classifier, Time interval)
{
FlowMonitor::FlowStatsContainer stats = flowMonitor->GetFlowStats();
double totalReceivedBytes = 0;
for (auto it = stats.begin(); it != stats.end(); ++it)
{
Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow(it->first);
if (t.destinationPort == 9)
{
totalReceivedBytes += it->second.rxBytes;
}
}
double goodput = (totalReceivedBytes * 8) / interval.GetSeconds(); // Convert to bits per second
std::cout << Simulator::Now().GetSeconds() << “s: Goodput = ” << goodput / 1e6 << ” Mbps” << std::endl;
Simulator::Schedule(interval, &CalculateGoodput, flowMonitor, classifier, interval); // Schedule next calculation
}
int main(int argc, char *argv[])
{
uint32_t nNodes = 2; // Number of nodes
double simulationTime = 10.0; // Total simulation time in seconds
Time calculationInterval = Seconds(1.0); // Interval to calculate goodpu
CommandLine cmd;
cmd.AddValue(“nNodes”, “Number of nodes”, nNodes);
cmd.AddValue(“simulationTime”, “Total simulation time”, simulationTime);
cmd.AddValue(“calculationInterval”, “Interval to calculate goodput”, calculationInterval);
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));
FlowMonitorHelper flowmon;
Ptr<FlowMonitor> monitor = flowmon.InstallAll();
Ptr<Ipv4FlowClassifier>classifier= DynamicCast<Ipv4FlowClassifier>(flowmon.GetClassifier());
Simulator::Schedule(calculationInterval, &CalculateGoodput, monitor, classifier, calculationInterval);
Simulator::Stop(Seconds(simulationTime));
Simulator::Run();
Simulator::Destroy();
return 0;
}
Explanation:
- Nodes and Links:
- Created nodes and configured a point-to-point network for communication.
- Network is setted up with nodes connected using point-to-point links.
- Applications:
- Installed a UDP echo server on one node.
- Installed a UDP echo client on another node to generate traffic.
- Flow Monitor:
- Collect data on packet transmissions, using the FlowMonitor module which also includes the number of bytes received.
- Goodput Calculation:
- Based on the received bytes implemented the CalculateGoodput function to calculate goodput from the FlowMonitor statistics.
- Scheduled the goodput calculation at regular intervals using the Simulator::Schedule function.
- Running the Simulation:
- The simulation runs, collecting data using FlowMonitor and calculating goodput at specified intervals.
- The goodput is printed for each interval, after the simulation.
Finally, the goodput is calculated in ns3 by measuring the amount of useful data received and by setting and running the simulation process.
We will furnish you with precise results based on the parameters you provide for calculating goodput in ns3.