From AP->STA, I am losing 50% of the packets. However from STA->AP, every packet is received.
Flow 1 (10.1.3.1 -> 10.1.3.3)
Tx Bytes: 268176
Rx Bytes: 267572
Goodput: 0.408282 Mbps
Packet Loss Ratio: 0.225225 %
mean Delay: 0.817473 ms
mean Jitter: 0.260213 ms
mean Hop count: 1
Flow 2 (10.1.3.3 -> 10.1.3.1)
Tx Bytes: 268176
Rx Bytes: 134692
Goodput: 0.205524 Mbps
Packet Loss Ratio: 49.7748 %
mean Delay: 15.5464 ms
mean Jitter: 4.68896 ms
mean Hop count: 1
The code is as below:
#include "ns3/core-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/network-module.h"
#include "ns3/applications-module.h"
#include "ns3/wifi-module.h"
#include "ns3/mobility-module.h"
#include "ns3/csma-module.h"
#include "ns3/internet-module.h"
#include "ns3/flow-monitor-module.h"
// Default Network Topology
//
// Wifi 10.1.3.0
// AP
// * * *
// | | |
// n0 n1 n2
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("ThirdScriptExample");
int
main (int argc, char *argv[])
{
CommandLine cmd;
cmd.Parse (argc,argv);
NodeContainer wifiStaNodes;
wifiStaNodes.Create (2);
NodeContainer wifiApNode;
wifiApNode.Create(1);
YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
phy.SetChannel (channel.Create ());
WifiHelper wifi = WifiHelper::Default ();
wifi.SetRemoteStationManager ("ns3::AarfWifiManager");
NqosWifiMacHelper mac = NqosWifiMacHelper::Default ();
Ssid ssid = Ssid ("ns-3-ssid");
mac.SetType ("ns3::StaWifiMac",
"Ssid", SsidValue (ssid),
"ActiveProbing", BooleanValue (false));
NetDeviceContainer staDevices;
staDevices = wifi.Install (phy, mac, wifiStaNodes);
mac.SetType ("ns3::ApWifiMac",
"Ssid", SsidValue (ssid));
NetDeviceContainer apDevices;
apDevices = wifi.Install (phy, mac, wifiApNode);
MobilityHelper mobility;
mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
"MinX", DoubleValue (0.0),
"MinY", DoubleValue (0.0),
"DeltaX", DoubleValue (5.0),
"DeltaY", DoubleValue (10.0),
"GridWidth", UintegerValue (3),
"LayoutType", StringValue ("RowFirst"));
mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
"Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
mobility.Install (wifiStaNodes);
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (wifiApNode);
InternetStackHelper stack;
stack.Install (wifiStaNodes);
stack.Install (wifiApNode);
Ipv4AddressHelper address;
address.SetBase ("10.1.3.0", "255.255.255.0");
Ipv4InterfaceContainer Interfaces;
Interfaces.Add (address.Assign (staDevices));
Interfaces.Add (address.Assign (apDevices));
ApplicationContainer clientApps, serverApps;
OnOffHelper dlClient ("ns3::UdpSocketFactory",Address(InetSocketAddress (Interfaces.GetAddress(2), 9)));
dlClient.SetConstantRate (DataRate ("1024Kb/s"), 576);
clientApps.Add (dlClient.Install (wifiStaNodes.Get(0)));
OnOffHelper ulClient ("ns3::UdpSocketFactory",Address(InetSocketAddress (Interfaces.GetAddress(0), 9)));
ulClient.SetConstantRate (DataRate ("1024Kb/s"), 576);
clientApps.Add (ulClient.Install (wifiApNode.Get(0)));
// 7.Creating Sink
PacketSinkHelper sink ("ns3::UdpSocketFactory",InetSocketAddress (Ipv4Address::GetAny (), 9));
serverApps.Add (sink.Install (wifiApNode.Get(0)));
PacketSinkHelper sink1 ("ns3::UdpSocketFactory",InetSocketAddress (Ipv4Address::GetAny (), 9));
serverApps.Add (sink1.Install (wifiStaNodes.Get(0)));
serverApps.Start (Seconds (0.0));
clientApps.Start (Seconds (0.0));
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
FlowMonitorHelper flowmon=FlowMonitorHelper();
Ptr<FlowMonitor> monitor;
monitor = flowmon.Install(wifiStaNodes);
monitor = flowmon.Install(wifiApNode);
Simulator::Stop (Seconds (2.0));
Simulator::Run ();
monitor->CheckForLostPackets ();
Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier> (flowmon.GetClassifier ());
std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats ();
for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator i = stats.begin (); i != stats.end (); ++i)
{
Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow (i->first);
std::cout << "Flow " << i->first << " (" << t.sourceAddress << " -> " << t.destinationAddress << ")\n";
std::cout << " Tx Bytes: " << i->second.txBytes << "\n";
std::cout << " Rx Bytes: " << i->second.rxBytes << "\n";
std::cout << " Goodput: " << i->second.rxBytes * 8.0 / 5.0 / (1024*1024) << " Mbps\n";
std::cout << " Packet Loss Ratio: " << (i->second.txPackets - i->second.rxPackets)*100/(double)i->second.txPackets << " %\n";
//std::cout << " Packet Dropped: " << i->second.packetsDropped << "%\n";
std::cout << " mean Delay: " << i->second.delaySum.GetSeconds()*1000/i->second.rxPackets << " ms\n";
std::cout << " mean Jitter: " << i->second.jitterSum.GetSeconds()*1000/(i->second.rxPackets - 1) << " ms\n";
std::cout << " mean Hop count: " << 1 + i->second.timesForwarded/(double)i->second.rxPackets << "\n";
}
Simulator::Destroy ();
return 0;
}
Anybody know what can be the reason for losing so many packets. I reduced data rate to 256 kbps, then also it is losing 50% packets.