Performance Analysis of 50-Node Wireless Network Using NS3
AIM:
To simulate a 50-node wireless network using the NS-3
network simulator and perform detailed performance analysis by evaluating key
network metrics such as throughput, delay, packet delivery ratio (PDR), packet
loss ratio (PLR), and bytes transmitted and received.
PROMPT USED:
LLM Used: ChatGpt, Claude
Generate NS-3 code to simulate a 50-node wireless network using the AODV routing protocol and analyse network performance metrics such as throughput, delay, packet loss ratio, packet delivery ratio and bytes transmitted and received using FlowMonitor.
SOURCE CODE:
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/mobility-module.h"
#include "ns3/wifi-module.h"
#include "ns3/internet-module.h"
#include "ns3/aodv-module.h"
#include "ns3/applications-module.h"
#include "ns3/flow-monitor-module.h"
#include "ns3/netanim-module.h"
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("ImprovedNetworkAudit");
int main (int argc, char *argv[])
{
uint32_t numNodes = 50;
NodeContainer nodes;
nodes.Create(numNodes);
WifiHelper wifi;
wifi.SetStandard(WIFI_STANDARD_80211b);
YansWifiChannelHelper channel = YansWifiChannelHelper::Default();
YansWifiPhyHelper phy;
phy.SetChannel(channel.Create());
WifiMacHelper mac;
mac.SetType("ns3::AdhocWifiMac");
NetDeviceContainer devices = wifi.Install(phy, mac, nodes);
MobilityHelper mobility;
mobility.SetPositionAllocator("ns3::GridPositionAllocator",
"MinX", DoubleValue(0.0),
"MinY", DoubleValue(0.0),
"DeltaX", DoubleValue(20.0),
"DeltaY", DoubleValue(20.0),
"GridWidth", UintegerValue(10),
"LayoutType",
StringValue("RowFirst"));
mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
mobility.Install(nodes);
AodvHelper aodv;
InternetStackHelper internet;
internet.SetRoutingHelper(aodv);
internet.Install(nodes);
Ipv4AddressHelper address;
address.SetBase("10.1.1.0",
"255.255.255.0");
Ipv4InterfaceContainer interfaces;
interfaces = address.Assign(devices);
/* ---------- MULTIPLE TRAFFIC FLOWS ---------- */
uint16_t port = 9;
for (uint32_t i = 0; i < 10; i++)
{
uint32_t source = i;
uint32_t destination = i + 10;
OnOffHelper onoff("ns3::UdpSocketFactory",
Address(InetSocketAddress(interfaces.GetAddress(destination),
port)));
onoff.SetConstantRate(DataRate("1Mbps"));
ApplicationContainer app = onoff.Install(nodes.Get(source));
app.Start(Seconds(1.0 + i));
app.Stop(Seconds(20.0));
PacketSinkHelper sink("ns3::UdpSocketFactory",
Address(InetSocketAddress(Ipv4Address::GetAny(),
port)));
ApplicationContainer sinkApp = sink.Install(nodes.Get(destination));
sinkApp.Start(Seconds(0.0));
sinkApp.Stop(Seconds(20.0));
}
/* ---------- FLOW MONITOR ---------- */
FlowMonitorHelper flowmon;
Ptr<FlowMonitor> monitor = flowmon.InstallAll();
/* ---------- NETANIM ---------- */
AnimationInterface anim("network50.xml");
anim.SetMaxPktsPerTraceFile(1000000);
for (uint32_t i = 0; i < nodes.GetN(); i++)
{
anim.UpdateNodeDescription(nodes.Get(i),
"Node" + std::to_string(i));
anim.UpdateNodeColor(nodes.Get(i), 255, 0, 0);
}
/* ---------- SIMULATION ---------- */
Simulator::Stop(Seconds(20));
Simulator::Run();
/* ---------- PERFORMANCE METRICS ---------- */
monitor->CheckForLostPackets();
Ptr<Ipv4FlowClassifier> classifier =
DynamicCast<Ipv4FlowClassifier>(flowmon.GetClassifier());
std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats();
for (auto &flow : stats)
{
std::cout << "Flow ID: " << flow.first << std::endl;
std::cout << "Tx Packets = " << flow.second.txPackets << std::endl;
std::cout << "Rx Packets = " << flow.second.rxPackets << std::endl;
std::cout << "Lost Packets = " << flow.second.lostPackets << std::endl;
double throughput = flow.second.rxBytes * 8.0 /
(flow.second.timeLastRxPacket.GetSeconds() -
flow.second.timeFirstTxPacket.GetSeconds()) / 1024;
std::cout << "Throughput: " << throughput << " Kbps" << std::endl;
double delay = flow.second.delaySum.GetSeconds() /
flow.second.rxPackets;
std::cout << "Average Delay: " << delay << std::endl;
double pdr = ((double)flow.second.rxPackets /
flow.second.txPackets) * 100;
double plr = ((double)flow.second.lostPackets /
flow.second.txPackets) * 100;
std::cout << "Packet Delivery Ratio: "
<< pdr << "%" << std::endl;
std::cout << "Packet Loss Ratio: " << plr << "%" << std::endl;
}
Simulator::Destroy();
return 0;
}
TERMINAL OUTPUT:
The above terminal output displays the performance
statistics obtained from the NS-3 simulation using the FlowMonitor module. A
total of 9277 packets were transmitted during the simulation, out of which 9276
packets were successfully received, resulting in only 1 packet loss.
The network achieved a throughput of approximately
2059.86 Kbps, indicating efficient data transmission between the nodes. The average
delay recorded was 0.000687 seconds, which shows that packets were
delivered very quickly across the network.
The Packet Delivery Ratio (PDR) of 99.9892% indicates
that almost all transmitted packets successfully reached the destination.
Similarly, the Packet Loss Ratio (PLR) of 0.0107% is extremely low,
demonstrating stable and reliable network communication.
Additionally, the simulation shows 5,009,580 bytes
transmitted and 5,009,040 bytes received, confirming that the majority of the
transmitted data was successfully delivered within the network. These results
indicate that the simulated 50-node wireless network performs efficiently with
minimal packet loss and low delay.
NETWORK ANIMATION:
The NetAnim tool is used to visualize the network
topology generated by the NS-3 simulation. Each node represents a wireless device participating in network communication. The visualization helps understand the structure and connectivity of the simulated network.
Throughput and Time graph:
Graph Explanation:
The throughput graph was plotted using gnuplot based
on the simulation results obtained from the NS-3 FlowMonitor output. The graph
shows the throughput performance of the 50 node network during the simulation. The
values show the increasing throughput trend during the simulation before
stabilizing near the measured throughput value of ~2060 Kbps.
RESULT ANALYSIS:
From
the simulation output, the following results were observed.
Total Packets Transmitted: 9277
Total Packets Received: 9276
Packets Lost: 1
Throughput: 2059.86 Kbps
Average Delay: 0.000687 seconds
Packet Delivery Ratio: 99.9892%
Packet Loss Ratio: 0.0107%
The high packet delivery ratio indicates efficientcommunication in the network
while the packet loss ratio remains extremely low, demonstrating stable network
behaviour
ADDITIONAL OBSERVATIONS:
• An increasing number of nodes may increase network
congestion.
• Wireless channel interference can affect throughput.
• Efficient routing protocols help reduce packet loss.
• FlowMonitor helps analyse real-time network
performance.
Comments
Post a Comment