Bug 1645

Summary: Visualizer crashes decoding a transmitted packet shorter than 23 bytes.
Product: ns-3 Reporter: Ted Gao <supergao222>
Component: visualizerAssignee: Gustavo J. A. M. Carneiro <gjcarneiro>
Status: CONFIRMED ---    
Severity: major CC: ns-bugs, tomh, tommaso.pecorella
Priority: P3    
Version: ns-3-dev   
Hardware: PC   
OS: Linux   
Bug Depends on: 1785    
Bug Blocks:    
Attachments: patch to fix it, builds on top of bug 1785

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;

NS_LOG_COMPONENT_DEFINE ("VisualizerTest");

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();
	
  wifiPhy.SetChannel(wifiChannel.Create());
	
  WifiHelper wifi;
  wifi.SetStandard(WIFI_PHY_STANDARD_80211a);
  wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager",
    "DataMode", StringValue(phyMode),
    "ControlMode", StringValue(phyMode));
  wifiMac.SetType("ns3::AdhocWifiMac");
	
  NetDeviceContainer devices;
  devices = wifi.Install(wifiPhy, wifiMac, nodes);
  
  MobilityHelper mobility;
    mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
    mobility.Install(nodes);

  ns3::PacketMetadata::Enable();
	
  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