Getting an incompatible types error for tracesource: $ns3::WifiNetDevice/Phy/PhyTxDrop

360 views
Skip to first unread message

Yufei Yan

unread,
Jun 25, 2019, 6:39:13 PM6/25/19
to ns-3-users
Hi, 

I'm getting the error when I try to trace the dropped packets or transmitted packets in ad hoc network. 

It says: 
msg="Incompatible types. (feed to "c++filt -t" if needed)
got=CallbackImpl<void,ns3::Ptr<ns3::Packet const>>
expected=CallbackImpl<void,std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >,ns3::Ptr<ns3::Packet const>>", file=./ns3/callback.h, line=1449
msg="when connecting to /NodeList/0/DeviceList/0/$ns3::WifiNetDevice/Phy/PhyTxDrop", file=./ns3/traced-callback.h, line=280
terminate called without an active exception

Here is how I configure the node:

  WifiHelper wifi;
  wifi
.SetStandard(WIFI_PHY_STANDARD_80211b);
 
 
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default();
  wifiPhy
.Set("RxGain", DoubleValue (0.0));
 
 
//error rate model for wifi.
  wifiPhy
.SetErrorRateModel("ns3::YansErrorRateModel");
 
  wifiPhy
.SetPcapDataLinkType (WifiPhyHelper::DLT_IEEE802_11_RADIO);
 
 
YansWifiChannelHelper wifiChannel;
  wifiChannel
.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");
  wifiChannel
.AddPropagationLoss("ns3::RangePropagationLossModel",
                                 
"MaxRange", DoubleValue(100));
 
//wifiChannel.AddPropagationLoss ("ns3::FixedRssLossModel","Rss",DoubleValue (-80.0));
  wifiPhy
.SetChannel(wifiChannel.Create());
 
  wifi
.SetRemoteStationManager("ns3::ConstantRateWifiManager",
                               
"DataMode",StringValue ("DsssRate11Mbps"),
                               
"ControlMode",StringValue ("DsssRate11Mbps"));
 
 
WifiMacHelper wifiMac;
  wifiMac
.SetType("ns3::AdhocWifiMac");
 
NetDeviceContainer devices = wifi.Install(wifiPhy, wifiMac, nodes);

When I do:
PcapHelper pcapHelper;
 
Ptr<PcapFileWrapper> file = pcapHelper.CreateFile ("begin.pcap", std::ios::out, PcapHelper::DLT_IEEE802_11);
  devices
.Get(0)->TraceConnectWithoutContext("/NodeList/0/DeviceList/0/$ns3::WifiNetDevice/Phy/PhyTxBegin", MakeBoundCallback(&txBegin, file));
the generated pcap file is empty. 

When I do:
  std::ostringstream oss;
  oss
<< "/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxDrop";
 
Config::Connect(oss.str(), MakeCallback(&txDrop));
it generates the runtime error. 

The problem shouldn't be from call back signature or call back function itself. 
I copied the function from the tutorial just for testing the tracesources. 

When I test the CourseChange tracesource from mobility model, it works with following code:
  std::ostringstream oss2;
 
//oss2 << "/NodeList/" << nodes.Get(0)->GetId() << "/$ns3::MobilityModel/CourseChange";
  oss2
<< "/NodeList/*/$ns3::MobilityModel/CourseChange";
 
Config::Connect(oss2.str(), MakeCallback(&CourseChange));


I've searched for some example codes, and I don't see much difference when setting up the configuration. 

What could be wrong? 

Thank you in advance. 

Muhammad Iqbal CR

unread,
Jun 25, 2019, 10:59:55 PM6/25/19
to ns-3-users
From the error message, it seems that you supplied a callback that's something like:
void callback(Ptr<const Packet> packet);
when it's supposed to be
void callback(std::string context, Ptr<const Packet> packet);

Yufei Yan

unread,
Jun 25, 2019, 11:05:14 PM6/25/19
to ns-3-users
Hi, Muhammad, 

thanks for your reply.

The callback signature on the website is 
typedef void(* ns3::Packet::TracedCallback) (Ptr< const Packet > packet)

but I'll try your suggestion.

Yufei Yan

unread,
Jun 25, 2019, 11:49:38 PM6/25/19
to ns-3-users
Hi, Muhammad, 

I tried void callback(std::string context, Ptr<const Packet> packet);
It compiles and runs, but the program does not get the trace.

Now I have a couple of more questions: 
1. This is the new callback function
static void txBegin (std::string context, Ptr<const Packet> p)
{
  NS_LOG_UNCOND
("txBegin at " << Simulator::Now ().GetSeconds () << " " << p->GetUid());
 
//file->Write (Simulator::Now (), p);

and in the main function, I have
 nodes.Get(1)->TraceConnectWithoutContext("/NodeList/1/DeviceList/0/$ns3::WifiNetDevice/Phy/PhyTxBegin", MakeCallback(&txBegin));

I'm expecting it prints out something from the txBegin() function, but nothing prints out. Apparently, this node broadcasts packets. I can see them from the generated pcap file. 
But why does this statement not work? 

2. In the fifth example, line 218, 
devices.Get (1)->TraceConnectWithoutContext ("PhyRxDrop", MakeCallback (&RxDrop));
this device calls the callback function for the tracesource. 
The RxDrop function's signature is
static void
RxDrop (Ptr<const Packet> p)

Why does this callback not have std::string?

Thank you. 

}

On Tuesday, June 25, 2019 at 9:59:55 PM UTC-5, Muhammad Iqbal CR wrote:

Yufei Yan

unread,
Jun 26, 2019, 12:00:50 AM6/26/19
to ns-3-users
Hey, 

I actually switched 
nodes.Get(1)->TraceConnectWithoutContext("/NodeList/1/DeviceList/0/$ns3::WifiNetDevice/Phy/PhyTxBegin", MakeCallback(&txBegin));
to
  std::ostringstream oss3;
  oss3
<< "/NodeList/1/DeviceList/0/$ns3::WifiNetDevice/Phy/PhyTxBegin";
 
Config::Connect(oss3.str(), MakeCallback(&txBegin));
and it works. 

When I switch it to
  nodes.Get(1)->TraceConnectWithoutContext("PhyTxBegin", MakeCallback(&txBegin));
it does not work.

In the fifth and sixth examples, 

devices.Get (1)->TraceConnectWithoutContext ("PhyRxDrop", MakeCallback (&RxDrop));
this statement works with only "PhyRxDrop" specified in TraceConnectWithoutContext. 

Why? 
Is it because fifth and sixth examples are P2P devices? While WifiNetDevices cannot do it like that? 

Thank you.

Muhammad Iqbal CR

unread,
Jun 26, 2019, 9:38:27 AM6/26/19
to ns-3-...@googlegroups.com
On Tue, Jun 25, 2019 at 11:00 PM Yufei Yan <yanyuf...@gmail.com> wrote:
Hey, 

I actually switched 
nodes.Get(1)->TraceConnectWithoutContext("/NodeList/1/DeviceList/0/$ns3::WifiNetDevice/Phy/PhyTxBegin", MakeCallback(&txBegin));
to
  std::ostringstream oss3;
  oss3
<< "/NodeList/1/DeviceList/0/$ns3::WifiNetDevice/Phy/PhyTxBegin";
 
Config::Connect(oss3.str(), MakeCallback(&txBegin));
and it works. 
This works because you're using Config::Connect to connect the trace through the full context, therefore you need a callback that has std::string context

When I switch it to
  nodes.Get(1)->TraceConnectWithoutContext("PhyTxBegin", MakeCallback(&txBegin));
it does not work.

In the fifth and sixth examples, 
devices.Get (1)->TraceConnectWithoutContext ("PhyRxDrop", MakeCallback (&RxDrop));
this statement works with only "PhyRxDrop" specified in TraceConnectWithoutContext. 
To use TraceConnectWithoutContext, you don't need to specify the whole context ("/NodeList/*/DeviceList/*/$ns3::Foo/Bar/PhyRxDrop"), only "PhyRxDrop" is needed because the context contains the path of the target device, which has been referred from devices.Get (1)-> (but then again, you need to supply the correct object that has the trace).

Why? 
Is it because fifth and sixth examples are P2P devices? While WifiNetDevices cannot do it like that? 
Yes. The example uses PointToPointNetDevice which have PhyRxDrop trace, WifiNetDevice do not have it. To trace connect Wifi's PhyRxDrop without context, you need to get WifiPhy object contained inside WifiNetDevice, i.e.,
wifiNetDevice->GetPhy ()->TraceConnectWithoutContext("PhyRxDrop", MakeCallback (&RxDrop));

Back to your trace connect:
Config::Connect ("/NodeList/1/DeviceList/0/$ns3::WifiNetDevice/Phy/PhyTxBegin", MakeCallback (&txBegin))
this equals to:
Ptr<NetDevice> nd = nodes.Get (1)->GetDevice (0);          // Get the NetDevice
Ptr<WifiNetDevice> wd = DynamicCast<WifiNetDevice> (nd);   // Dynamic cast to WifiNetDevice
wd->GetPhy ()->TraceConnectWithoutContext ("PhyTxBegin", MakeCallback (&txBeginWithoutContext)); // Connect to WifiPhy trace

Hope that helps, I cannot check the correctness of the code since I didn't compile it, sorry if I missed something.

--
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 a topic in the Google Groups "ns-3-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ns-3-users/wqZtmak6lTk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ns-3-users+...@googlegroups.com.
To post to this group, send email to ns-3-...@googlegroups.com.
Visit this group at https://groups.google.com/group/ns-3-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/ns-3-users/eec5e3e5-6a1b-4feb-8f50-441d7f871338%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Yufei Yan

unread,
Jun 26, 2019, 4:15:14 PM6/26/19
to ns-3-users
Hi, Muhammad, 

It helps a lot.
I do appreciate it. 


To unsubscribe from this group and all its topics, send an email to ns-3-...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages