How to Calculate Goodput in ns3

To calculate the goodput in ns3, it is useful for exchange the data over a network that excludes the protocol overhead and resends it. By using the ns3 tool we need to compute goodput in certain time period by observing the amount of application level data established by the destination node. Now we are going to demonstrate the procedures on how to calculate the goodput in ns3.

  1. Set up the Simulation: Create a basic network scenario, including the necessary nodes, devices, and applications.
  2. Collect Application-Level Data: To capture the amount of data received at the application layer by use of tracing mechanism.
  3. Calculate Goodput: Goodput is typically calculated as the total number of application-level bits received divided by the simulation time.

Example Implementation

Here, we offer the sample setup to build a network topology and evaluate the goodput in ns3:

Setting Up the Network Simulation

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

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

// Set up the default simulation parameters

Time::SetResolution(Time::NS);

LogComponentEnable(“GoodputExample”, LOG_LEVEL_INFO);

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

Ipv4AddressHelper address;

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

Ipv4InterfaceContainer interfaces = address.Assign(devices);

// Set up a UDP server

uint16_t port = 9;

UdpServerHelper server(port);

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

serverApps.Start(Seconds(1.0));

serverApps.Stop(Seconds(10.0));

// Set up a UDP client

uint32_t packetSize = 1024; // 1 KB

uint32_t maxPacketCount = 320; // 320 KB total data

Time interPacketInterval = Seconds(0.05); // 50 ms interval

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

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

client.SetAttribute(“Interval”, TimeValue(interPacketInterval));

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

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

clientApps.Start(Seconds(2.0));

clientApps.Stop(Seconds(10.0));

// Set up FlowMonitor to collect QoS metrics

FlowMonitorHelper flowmon;

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

Simulator::Stop(Seconds(10.0));

Simulator::Run();

// Calculate Goodput

double totalBytesReceived = 0;

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

std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats();

for (auto &flow : stats) {

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

if (t.destinationAddress == interfaces.GetAddress(1)) {

totalBytesReceived += flow.second.rxBytes;

}

}

double goodput = totalBytesReceived * 8 / 8.0; // Convert to bits and divide by simulation time

std::cout << “Goodput: ” << goodput << ” bits/second” << std::endl;

Simulator::Destroy();

return 0;

}

Explanation:

  1. Simulation Setup:
    • Create two nodes and connect them using a point-to-point link.
    • Install the Internet stack on both nodes and assign IP addresses.
  2. Application Setup:
    • Install a UDP server on the destination node (Node 1).
    • Install a UDP client on the source node (Node 0) to send packets to the server.
  3. FlowMonitor Setup:
    • Install FlowMonitor to collect data on the flows between nodes.
  4. Simulation Execution:
    • Run the simulation for a specified period.
  5. Goodput Calculation:
    • After the simulation, extract the number of received bytes from FlowMonitor.
    • Convert the received bytes to bits and divide by the simulation time to get goodput in bits per second.

In the end, goodput can computed as the total number of application-level bits received divided by the simulation time with the help of ns3 simulation. We then provide the elaborated details about how the goodput will calculate in other simulators.

We offer recommendations on project performance for your project and proceed with a comparative analysis. Furthermore, we provide in-depth information on calculating Goodput in ns3 simulation. For the best results, please contact ns3simulation.com.