How to Begin Implement Network Throughput in NS3

To begin Network Throughput using ns3, we can adhere to these detailed steps. Throughput estimates the rate upon which data is effectively distributed through a network that normally denotes in bits for each second (bps). Below is a simple guide to get started:

Steps to Begin Implement Network Throughput in NS3

  1. Understand the Concept

Network throughput in NS3 based on:

  • Link bandwidth: Highest data rate which is supported by the bandwidth link.
  • Traffic patterns: Number and type of traffic models such as TCP, UDP.
  • Network conditions: Congestion, delay, and packet loss.
  • Routing protocols: Impacts how packets are transmitted.
  1. Set Up Your Environment

We can install and download the ns3 on the machine and working properly. Make acquainted about simple ns3 scripting using C++ or Python.

  1. Create the Network Topology

Example: Point-to-Point Network

NodeContainer nodes;

nodes.Create(2);

PointToPointHelper pointToPoint;

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

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

NetDeviceContainer devices;

devices = pointToPoint.Install(nodes);

Example: Wireless Network

YansWifiChannelHelper channel = YansWifiChannelHelper::Default();

YansWifiPhyHelper phy = YansWifiPhyHelper::Default();

phy.SetChannel(channel.Create());

WifiHelper wifi;

wifi.SetStandard(WIFI_PHY_STANDARD_80211n);

WifiMacHelper mac;

mac.SetType(“ns3::AdhocWifiMac”);

NodeContainer wifiNodes;

wifiNodes.Create(3);

NetDeviceContainer wifiDevices;

wifiDevices = wifi.Install(phy, mac, wifiNodes);

  1. Set Up the Internet Stack

We should install the Internet stack allowing IP-based interaction:

InternetStackHelper stack;

stack.Install(nodes);

Ipv4AddressHelper address;

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

Ipv4InterfaceContainer interfaces = address.Assign(devices);

  1. Install Applications to Generate Traffic

Example: TCP Bulk Traffic

uint16_t port = 9;

Address serverAddress(InetSocketAddress(interfaces.GetAddress(1), port));

BulkSendHelper bulkSender(“ns3::TcpSocketFactory”, serverAddress);

bulkSender.SetAttribute(“MaxBytes”, UintegerValue(0)); // Unlimited data

ApplicationContainer senderApps = bulkSender.Install(nodes.Get(0));

senderApps.Start(Seconds(1.0));

senderApps.Stop(Seconds(10.0));

PacketSinkHelper sink(“ns3::TcpSocketFactory”, serverAddress);

ApplicationContainer sinkApps = sink.Install(nodes.Get(1));

sinkApps.Start(Seconds(1.0));

sinkApps.Stop(Seconds(10.0));

Example: UDP Traffic

UdpEchoServerHelper echoServer(9);

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

serverApps.Start(Seconds(1.0));

serverApps.Stop(Seconds(10.0));

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

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

echoClient.SetAttribute(“Interval”, TimeValue(Seconds(0.01))); // 10ms interval

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

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

clientApps.Start(Seconds(2.0));

clientApps.Stop(Seconds(10.0));

  1. Measure Throughput

Using FlowMonitor

FlowMonitor is an ns3 module for estimate the performance parameters such as throughput, packet delivery ratio, delay, and other metrics:

FlowMonitorHelper flowmon;

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

Simulator::Stop(Seconds(10.0));

Simulator::Run();

monitor->CheckForLostPackets();

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

std::cout << “Flow ID: ” << flow.first << ” (” << t.sourceAddress << ” -> ” << t.destinationAddress << “)\n”;

std::cout << ”  Throughput: ”

<< flow.second.rxBytes * 8.0 / (flow.second.timeLastRxPacket.GetSeconds() – flow.second.timeFirstTxPacket.GetSeconds()) / 1000 / 1000

<< ” Mbps\n”;

}

Simulator::Destroy();

Using Manual Calculation

Aggregate the throughput using computation by observing the received packets:

void MonitorThroughput(Ptr<PacketSink> sink) {

static double lastTotalRx = 0;

double currentTotalRx = sink->GetTotalRx();

double throughput = (currentTotalRx – lastTotalRx) * 8.0 / 1e6; // Mbps

std::cout << “Throughput: ” << throughput << ” Mbps at time ” << Simulator::Now().GetSeconds() << “s\n”;

lastTotalRx = currentTotalRx;

Simulator::Schedule(Seconds(1.0), &MonitorThroughput, sink);

}

During the simulation, request this function:

Ptr<PacketSink> sinkApp = DynamicCast<PacketSink>(sinkApps.Get(0));

Simulator::Schedule(Seconds(1.0), &MonitorThroughput, sinkApp);

  1. Visualize Results
  • Transfer throughput data into a file to leverage MATLAB or Excel for graphical analysis.
  • For visualization, we need to apply ns3’s NetAnim tools:

AnimationInterface anim(“throughput_simulation.xml”);

  1. Experiment and Analyze
  • Vary Link Bandwidth:

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

  • Increase Traffic Load:
    • Integrate additional nodes and applications.
  • Change Network Topology:
    • Experiment network topology like star, mesh, or grid topologies.
  • Test Different Protocols:
    • Equate the performance of diver protocols such as TCP vs. UDP throughput.
  1. Run the Simulation

Finally, execute the simulation and then monitor the throughput parameters:

Simulator::Run();

Simulator::Destroy();

Here, detailed demonstration of Network Throughput through comprehensive implementation process accompanied by NS3 snippets that has been provided and we are ready to extend it further upon request.