python binding for callbacks in ns3

458 views
Skip to first unread message

Akhila Rao

unread,
Aug 3, 2016, 11:01:19 AM8/3/16
to ns-3-users
Hi, 

I am setting up a simulation in ns3 using python bindings. I have a network with wifi APs and stations. I want to use the trace source MonitorSnifferRx which is accessed through a callback. The ns3 manual, section python to run ns3, says that "Callback based tracing is not yet properly supported for Python, as new ns-3 API needs to be provided for this to be supported." How do I work around this ? I need to perform a function on each sniffed frame, and it needs to be written as a python script. 
So far I have tried something like this based on one other post about this topic. 

ns.core.Config.ConnectWithoutContext("/NodeList/1/DeviceList/0/$ns3::WifiNetDevice/Phy/MonitorSnifferRx", ns.MakeCallback(my_func))

But this is just me guessing what it could be. The MakeCallback portion throws an error "'module' object has no attribute 'MakeCallback'" 
Help will be appreciated. 

Regards
Akhila

pdbarnes

unread,
Aug 4, 2016, 12:17:12 AM8/4/16
to ns-3-users
I think you're talking about this long standing bug:
https://www.nsnam.org/bugzilla/show_bug.cgi?id=127

Peter

Akhila Rao

unread,
Aug 4, 2016, 1:07:57 AM8/4/16
to ns-3-...@googlegroups.com
Yes, I am. I have read the discussion in the bug report. But It doesn't seem to offer a solution, just a discussion on ideas for a patch. Since I do not have the working knowledge to create this path myself, is there any othwr solution I could try ?

Thanks. 
show_bug.cgi?id=127

Peter

--
Posting to this group should follow these guidelines https://www.ns
nam.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/AEiDpD-El9s/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.
For more options, visit https://groups.google.com/d/optout.


--
Regards
Akhila

Tom Henderson

unread,
Aug 4, 2016, 2:04:32 AM8/4/16
to ns-3-...@googlegroups.com
On 08/03/2016 10:07 PM, Akhila Rao wrote:
> Yes, I am. I have read the discussion in the bug report. But It doesn't
> seem to offer a solution, just a discussion on ideas for a patch. Since
> I do not have the working knowledge to create this path myself, is there
> any othwr solution I could try ?
>

You could try to modify the wifi-phy.cc code to add an explicit callback
(in addition to the trace-source-based callback) and pass a Python
callable object to it. This new callback could be added in parallel to
the existing trace source, so that they are both called at the same
time. Then, your Python program would need to obtain the WifiPhy
pointer of interest and hook the callback.

see line 91 of utils/python-unit-tests.py for a sockets-based example.

- Tom

Akhila Rao

unread,
Aug 16, 2016, 5:54:40 AM8/16/16
to ns-3-...@googlegroups.com
Thank you Tom for the helpful instructions. By using the utils/python-unit-tests.py sockets-based example as a sample I was able to recreate that for the MonitorSnifferRx trace. I however cannot seem to test it for the following reasons. 

When I change something in the source code of ns3, like what I did, which is add a new function in the class file wifi-phy.cc (and a declaration in wifi-phy.h ) how do I then ensure that the pyhton bindings for this are complied/built/scanned ? 
I first build the ns3 code using ./build and then I use ./waf --apiscan=wifi to re-scan the wifi module that has the wifi-phy files. 
Even after this, when I try to access the function I just created  in wifi-phy.cc, I get a Object does not have this attribute error. Am I not compiling/building/scanning or hooking up something that I need to for this function to be accessible from my python script ? I can however access all the other functions that existed before, I am just unable to access the new function I added. 

Help is appreciated as always !

   

--
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/AEiDpD-El9s/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ns-3-users+unsubscribe@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.
For more options, visit https://groups.google.com/d/optout.



--
Regards
Akhila

pdbarnes

unread,
Aug 17, 2016, 10:02:15 AM8/17/16
to ns-3-users
> I get a Object does not have this attribute error.

Maybe it would help if you posted some code: your new Attribute in GetTypeId, your Config path, and the complete error message.

Peter

wucany...@gmail.com

unread,
Mar 22, 2019, 3:34:05 AM3/22/19
to ns-3-users
I also met this question, I want to know if NS3 can be used like this now. I checked a lot of related usages on the Internet, but I didn't find it. Can you tell me if NS3 can be used like this now? If not,what should I do?

Thanks

在 2016年8月3日星期三 UTC+8下午11:01:19,Akhila Rao写道:
Reply all
Reply to author
Forward
0 new messages