Bug 1645 - Visualizer crashes decoding a transmitted packet shorter than 23 bytes.
Visualizer crashes decoding a transmitted packet shorter than 23 bytes.
Product: ns-3
Classification: Unclassified
Component: visualizer
PC Linux
: P3 major
Assigned To: Gustavo J. A. M. Carneiro
Depends on: 1785
  Show dependency treegraph
Reported: 2013-04-25 22:50 EDT by Ted Gao
Modified: 2013-10-26 15:27 EDT (History)
3 users (show)

See Also:

patch to fix it, builds on top of bug 1785 (3.92 KB, patch)
2013-10-26 15:27 EDT, Gustavo J. A. M. Carneiro
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ted Gao 2013-04-25 22:50:19 EDT
I built a environment with two wifi nodes and run it with --vis argument
When device send packet smaller than 23 bytes. An "assert failed" occourred:

assert failed. cond="m_current >= m_dataStart && m_current <= m_dataEnd", msg="You have attempted to read beyond the bounds of the available buffer space. This usually indicates that a Header::Deserialize or Trailer::Deserialize method is trying to read data which was not written by a Header::Serialize or Trailer::Serialize method. In short: check the code of your Serialize and Deserialize methods.", file=./ns3/buffer.h, line=823
terminate called without an active exception

Here is the test code:

#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/wifi-module.h"
#include "ns3/mobility-module.h"
#include <string>

using namespace ns3;


int main (int argc, char *argv[])
  CommandLine cmd;
  cmd.Parse(argc, argv);
  NodeContainer nodes;
  nodes.Create (2);

  std::string phyMode("DsssRate1Mbps");
  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default();
  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();
  NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default();
  WifiHelper wifi;
    "DataMode", StringValue(phyMode),
    "ControlMode", StringValue(phyMode));
  NetDeviceContainer devices;
  devices = wifi.Install(wifiPhy, wifiMac, nodes);
  MobilityHelper mobility;

  Ptr<Packet> p = Create<Packet>(22); // assert failed
  //Ptr<Packet> p = Create<Packet>(23); // it works
  devices.Get(0)->Send(p, Mac48Address::GetBroadcast(), 0x0);
  Simulator::Run ();
  Simulator::Destroy ();
  return 0;
Comment 1 Tommaso Pecorella 2013-07-12 17:54:42 EDT
Debugger: see http://en.wikipedia.org/wiki/Debugger

I know debugging a program with the visualizer module enabled isn't for all, but still...

Anyway, the bug isn't in the core. And it isn't in the WiFi either.

The bug is:
Visualizer hooks the WiFiNetDevice::NotifyTx function.
PyWiz::TraceNetDevTxWifi will attempt to deserialize the WiFiMacHeader. Which is NOT there, as it's added later on by WiFiMac (actually even below).

The only header available at that stage is LlcSnapHeader. This, at least, is what I could find. The ball goes to the visualizer master.
Comment 2 Gustavo J. A. M. Carneiro 2013-10-26 15:27:03 EDT
I am not sure how this happened, but somewhere along the way ns-3 must have changed the way it reports packets in wifi trace hooks.  I'm pretty sure it used to have a WifiMacHeader, but it must have been removed at some point and I didn't notice this problem.

Anyway, I filed bug 1785 for the wifi part, and I will attach a corresponding patch for pyviz that fixes the issue.
Comment 3 Gustavo J. A. M. Carneiro 2013-10-26 15:27:55 EDT
Created attachment 1689 [details]
patch to fix it, builds on top of bug 1785