Clarification on Packet Loss in WiFi Broadcast with UDP

16 views
Skip to first unread message

Vinita Sao 2210705

unread,
Oct 8, 2025, 5:07:31 AM (yesterday) Oct 8
to ns-3-...@googlegroups.com

Dear ns-3 community,

I am working with ns-3 using WiFi and UDP.  In my setup, I generated 5 nodes, each broadcasting one packet at a time 1s. In this case, none of the nodes received any packet, resulting in 100% packet loss.

However, when I configured each node to send multiple packets (e.g., the first at 1s, the next at 1.1s, and so on), the packet loss was no longer 100%.

I am unable to understand why there is complete packet loss when only a single packet is scheduled, but not when multiple packets are sent. Could you please help me understand this behaviour or suggest resources where I can look into it?

Thank you,
Vinita

압둘하미드이드리스

unread,
Oct 8, 2025, 5:26:00 AM (yesterday) Oct 8
to ns-3-...@googlegroups.com
Hi Vinita,

The 100% loss occurs because all nodes transmit simultaneously, and WiFi broadcasts have no ACKs or retransmissions. Collisions cause drops. Sending packets at slightly different times spreads transmissions, reducing collisions, so some packets get through.

Could you also share your ns-3 code snippet? It will bolster giving more specific suggestions.

Best,
Idris A.A.
--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/ns-3-users/CAEmnCDrEdAeio%2BVEK%3DQYkHBo6SsmP3pGpux6emuuAkN-%2B7cCqQ%40mail.gmail.com.

Vinita Sao 2210705

unread,
Oct 8, 2025, 6:39:33 AM (yesterday) Oct 8
to ns-3-...@googlegroups.com
Thanks for your reply. I understand that there is no acknowledgement and retransmission, which is why there is a 100% packet drop. However, when we queue more packets, how does it work? Is it not setting all packets at the same time for each node? 

I have attached my code below.


#include "ns3/command-line.h"
#include "ns3/config.h"
#include "ns3/double.h"
#include "ns3/internet-stack-helper.h"
#include "ns3/ipv4-address-helper.h"
#include "ns3/log.h"
#include "ns3/mobility-helper.h"
#include "ns3/mobility-model.h"
#include "ns3/string.h"
#include "ns3/yans-wifi-channel.h"
#include "ns3/yans-wifi-helper.h"
#include "ns3/propagation-loss-model.h"
#include <unordered_map>
#include "ns3/wifi-mac-header.h"
#include "ns3/uinteger.h"
#include "ns3/wifi-mac.h"
#include "ns3/node-list.h"
#include "ns3/wifi-net-device.h"
#include <iomanip>
#include <fstream>
#include "ns3/core-module.h"
#include <ctime>


using namespace ns3;
std::ofstream phyLogFile;
NS_LOG_COMPONENT_DEFINE("WifiSimpleAdhoc");



void PhyMonitorSnifferRx(uint32_t rxNodeId,Ptr<const Packet> p,
                         uint16_t channelFreqMhz,
                         WifiTxVector txVector,
                         MpduInfo aMpdu,
                         SignalNoiseDbm signalNoise,
                         uint16_t extra)
{
   
   
  WifiMacHeader hdr;
  Ptr<Packet> copy = p->Copy();
  if (copy->PeekHeader(hdr))
  {
    Mac48Address src = hdr.GetAddr2(); // sender MAC

    // Map MAC to Node ID
    uint32_t nodeId = UINT32_MAX; // invalid by default
    for (NodeList::Iterator it = NodeList::Begin(); it != NodeList::End(); ++it)
    {
      Ptr<Node> node = *it;
      for (uint32_t i = 0; i < node->GetNDevices(); ++i)
      {
        Ptr<NetDevice> dev = node->GetDevice(i);
        Ptr<WifiNetDevice> wifiDev = DynamicCast<WifiNetDevice>(dev);
        if (wifiDev)
        {
          Mac48Address devAddr = wifiDev->GetMac()->GetAddress();
          if (src == devAddr)
          {
            nodeId = node->GetId();
            break;
          }
        }
      }
      if (nodeId != UINT32_MAX)
        break;
    }

   if (nodeId != UINT32_MAX)
{
  double time = Simulator::Now().GetSeconds();
  double signal = signalNoise.signal;
  double noise = signalNoise.noise;
  double snr = signal - noise;

  // Print to console
  std::cout  << time << "s [PHY] Packet received at Node " << rxNodeId
   << "s [PHY] Frame from Node" << nodeId
            << " Signal=" << signal << " dBm, "
            << "Noise=" << noise << " dBm, "
            << "SNR=" << snr << " dB"
            << std::endl;

  // Write to file
  phyLogFile << std::setw(10) << std::fixed << std::setprecision(5) << time
           << std::setw(8)  << nodeId
           << std::setw(12) << std::setprecision(4) << signal
           << std::setw(12) << noise
           << std::setw(12) << snr
           << std::endl;

}

  }
}



static void
GenerateTraffic(Ptr<Socket> socket, uint32_t pktSize, uint32_t pktCount, Time pktInterval)
{
  if (pktCount > 0)
  {
    socket->Send(Create<Packet>(pktSize));
    Simulator::Schedule(pktInterval,
                        &GenerateTraffic,
                        socket,
                        pktSize,
                        pktCount - 1,
                        pktInterval);
  }
  else
  {
    socket->Close();
  }
}

void ReceivePacket(Ptr<Socket> socket)
{
  Ptr<Packet> packet;
  Address from;
  /*
  while ((packet = socket->RecvFrom(from)))
  {
    InetSocketAddress address = InetSocketAddress::ConvertFrom(from);
    Ipv4Address senderIp = address.GetIpv4();

    // Only print when the sender is Node1 (its IP is 10.1.1.2)
   
    if (senderIp == Ipv4Address("10.1.1.2"))
    {
      std::cout << Simulator::Now().GetSeconds()
                << "s [Node0] Received packet from Node1 ("
                << senderIp << "), size=" << packet->GetSize()
                << std::endl;
    }
  }*/
}

int
main(int argc, char* argv[])
{
  std::string phyMode("DsssRate1Mbps");
  uint32_t packetSize{1500}; // bytes
  //uint32_t numPackets{3};
  Time interPacketInterval{"1s"};
  bool verbose{false};
  RngSeedManager::SetSeed (time (nullptr));  // use current time as seed

  CommandLine cmd(__FILE__);
  cmd.AddValue("phyMode", "Wifi Phy mode", phyMode);
  cmd.AddValue("packetSize", "size of application packet sent", packetSize);
  //cmd.AddValue("numPackets", "number of packets generated", numPackets);
  cmd.AddValue("interval", "interval between packets", interPacketInterval);
  cmd.AddValue("verbose", "turn on all WifiNetDevice log components", verbose);
  cmd.Parse(argc, argv);

  // Fix non-unicast data rate to be the same as that of unicast
  Config::SetDefault("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue(phyMode));
  // remove backoff (test-only)
  //Config::Set ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/CwMin", UintegerValue (0));
  //Config::Set ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/CwMax", UintegerValue (0));

  NodeContainer c;
  c.Create(2);

  WifiHelper wifi;
  if (verbose)
  {
    WifiHelper::EnableLogComponents(); // Turn on all Wifi logging
  }
  wifi.SetStandard(WIFI_STANDARD_80211b);

  YansWifiPhyHelper wifiPhy;
  wifiPhy.Set("RxGain", DoubleValue(0)); // no extra gain
  wifiPhy.SetPcapDataLinkType(WifiPhyHelper::DLT_IEEE802_11_RADIO);
  //wifiPhy.Set("TxPowerStart", DoubleValue(20.0));  // min power (dBm)
  //wifiPhy.Set("TxPowerEnd", DoubleValue(20.0));    // max power (dBm)
 //wifiPhy.Set("TxPowerLevels", UintegerValue(1));  // only one discrete level

  // Build channel with realistic propagation and error model
  YansWifiChannelHelper wifiChannel;
  wifiChannel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");
  wifiChannel.AddPropagationLoss("ns3::FriisPropagationLossModel");

  // Use ThreeLogDistance propagation model
 
 
  // By default YansWifiPhy uses a BER-based error model internally,
  // so we don’t need to set an explicit error model here.
  wifiPhy.SetChannel(wifiChannel.Create());

  WifiMacHelper wifiMac;
  wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager",
                               "DataMode", StringValue(phyMode),
                               "ControlMode", StringValue(phyMode));
  wifiMac.SetType("ns3::AdhocWifiMac");

  NetDeviceContainer devices = wifi.Install(wifiPhy, wifiMac, c);

  // Mobility (positions matter now since propagation is distance-based)
  MobilityHelper mobility;

Ptr<UniformRandomVariable> x = CreateObject<UniformRandomVariable> ();
x->SetAttribute ("Min", DoubleValue (0.0));
x->SetAttribute ("Max", DoubleValue (100.0));

Ptr<UniformRandomVariable> y = CreateObject<UniformRandomVariable> ();
y->SetAttribute ("Min", DoubleValue (0.0));
y->SetAttribute ("Max", DoubleValue (100.0));

Ptr<RandomRectanglePositionAllocator> positionAlloc = CreateObject<RandomRectanglePositionAllocator> ();
positionAlloc->SetX (x);
positionAlloc->SetY (y);

mobility.SetPositionAllocator (positionAlloc);
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (c);

// Print assigned positions
for (uint32_t i = 0; i < c.GetN (); ++i) {
  Ptr<MobilityModel> mob = c.Get (i)->GetObject<MobilityModel> ();
  Vector pos = mob->GetPosition ();
  std::cout << "Node " << i << " at (" << pos.x << ", " << pos.y << ")" << std::endl;
}

 
  // Hook sniffer on each device
  for (uint32_t i = 0; i < devices.GetN (); ++i)
  {
    Ptr<WifiNetDevice> wifiDev = DynamicCast<WifiNetDevice> (devices.Get(i));
    Ptr<WifiPhy> phy = wifiDev->GetPhy();
    phy->TraceConnectWithoutContext("MonitorSnifferRx",
        MakeBoundCallback(&PhyMonitorSnifferRx, i));
 
  }

  InternetStackHelper internet;
  internet.Install(c);

  Ipv4AddressHelper ipv4;
  ipv4.SetBase("10.1.1.0", "255.255.255.0");
  Ipv4InterfaceContainer i = ipv4.Assign(devices);

  TypeId tid = TypeId::LookupByName("ns3::UdpSocketFactory");
  Ptr<Socket> recvSink = Socket::CreateSocket(c.Get(0), tid);
  InetSocketAddress local = InetSocketAddress(Ipv4Address::GetAny(), 80);
  recvSink->Bind(local);
  recvSink->SetRecvCallback(MakeCallback(&ReceivePacket));

 
  // Install a receiving socket on every node (except the sender if you want)
for (uint32_t n = 0; n < c.GetN(); ++n)
{
   Ptr<Socket> recvSink = Socket::CreateSocket(c.Get(n), tid);
   InetSocketAddress local = InetSocketAddress(Ipv4Address::GetAny(), 80);
   recvSink->Bind(local);
   recvSink->SetRecvCallback(MakeCallback(&ReceivePacket));
}

 
  for (uint32_t sender = 1; sender <c.GetN() ; ++sender)
  {
   
Ptr<Socket> source = Socket::CreateSocket(c.Get(sender), tid);
InetSocketAddress remote = InetSocketAddress(Ipv4Address("255.255.255.255"), 80);
source->SetAllowBroadcast(true);
source->Connect(remote);


    // Schedule 10 packets at 0.01s interval
    Simulator::ScheduleWithContext(source->GetNode()->GetId(),
                                   Seconds(1.0), // start time
                                   &GenerateTraffic,
                                   source,
                                   packetSize,
                                   2,                          // numPackets per sender
                                   Seconds(0.01));              // interval
  }
  // Pcap trace
  wifiPhy.EnablePcap("wifi-simple-adhoc", devices);

  //NS_LOG_UNCOND("Testing " << numPackets << " packets with ThreeLogDistance model");

  phyLogFile.open("phy_log_1.txt", std::ios::out);
  phyLogFile << "Time(s)\t\tNodeId\t\tSignal(dBm)\t\tNoise(dBm)\t\tSNR(dB)" << std::endl;

  Simulator::Run();

 
  Simulator::Destroy();
  return 0;
}

On Wed, Oct 8, 2025 at 2:55 PM 압둘하미드이드리스 <iaabdu...@knu.ac.kr> wrote:
Hi Vinita,

The 100% loss occurs because all nodes transmit simultaneously, and WiFi broadcasts have no ACKs or retransmissions. Collisions cause drops. Sending packets at slightly different times spreads transmissions, reducing collisions, so some packets get through.

Could you also share your ns-3 code snippet? It will bolster giving more specific suggestions.

Best,
Idris A.A.


On Wednesday, October 8, 2025, 'Vinita Sao 2210705' via ns-3-users <ns-3-...@googlegroups.com> wrote:

Dear ns-3 community,

I am working with ns-3 using WiFi and UDP.  In my setup, I generated 5 nodes, each broadcasting one packet at a time 1s. In this case, none of the nodes received any packet, resulting in 100% packet loss.

However, when I configured each node to send multiple packets (e.g., the first at 1s, the next at 1.1s, and so on), the packet loss was no longer 100%.

I am unable to understand why there is complete packet loss when only a single packet is scheduled, but not when multiple packets are sent. Could you please help me understand this behaviour or suggest resources where I can look into it?

Thank you,
Vinita

--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+...@googlegroups.com.

--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/ns-3-users/CAA9%3DhGPCtHP-u%2BwOM%3D1nxzKFA6SHhHUi7cXaBe4Zr%2B-_UCL-Bw%40mail.gmail.com.

압둘하미드이드리스

unread,
Oct 8, 2025, 8:19:30 AM (yesterday) Oct 8
to ns-3-...@googlegroups.com
Hi Vinita,

When you queue multiple packets, they are not sent at the same instant. The Simulator::Schedule() call spaces them according to your interval (in your code, 0.01s apart), so each packet gets its own channel access attempt. That reduces collisions and allows some packets to go through.

If all nodes send only one packet at exactly 1.0s, they contend at the same time and collide, which explains the 100% loss. You can randomize start times slightly to confirm this.

Best Regards,
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+unsubscribe@googlegroups.com.

--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+unsubscribe@googlegroups.com.

--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/ns-3-users/CAEmnCDrR-FmY%3D60ZD4k0EqEzDEmRPdkF6g1iL3D_e9vY%3DZSCVA%40mail.gmail.com.

Vinita Sao 2210705

unread,
Oct 8, 2025, 8:59:06 AM (yesterday) Oct 8
to ns-3-...@googlegroups.com
Thanks a lot

To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+...@googlegroups.com.

--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+...@googlegroups.com.

--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+...@googlegroups.com.

--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/ns-3-users/CAA9%3DhGNaoOg189JMu%3D3TJjaHg9PPT3hOs82GsQsuShxzxC5d6g%40mail.gmail.com.

압둘하미드이드리스

unread,
Oct 8, 2025, 1:14:16 PM (yesterday) Oct 8
to ns-3-...@googlegroups.com
You’re welcome, Vinita. 
Thanks a lot

To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+unsubscribe@googlegroups.com.

--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+unsubscribe@googlegroups.com.

--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+unsubscribe@googlegroups.com.

--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+unsubscribe@googlegroups.com.

--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/ns-3-users/CAEmnCDpWO_Eov40rDZFuisR%3D48SQyiOh8duBtrHsL98dCw9peg%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages