How to use RateErrorModule from puthon script

59 views
Skip to first unread message

Tao Chen

unread,
Mar 31, 2024, 11:51:36 AM3/31/24
to ns-3-users
Hi, Everyone,
   I am a newbie of ns3, trying to put together a python script to simulate a simple point to point network transmission. Everything works fine (mostly copy from examples/tutorial/third.py). Except one thing, I tried to introduce the random error rate to the transmission, by import ns.rate_error_module (as ChatGPT suggested). I always get error of:
 import ns. rate_error_module
 ModuleNotFoundError: No module named 'ns. rate_error_module '
Well, it seems ns3 does have RateErrorModule class as cpp code, and could be called from cc script. And I did get the whole stuff working with cc script. But I still have a question for ns3 Python script though. 
   My question is: How do I inport this Random packet dropping rate cpp code in ns3 to my simulation with Python script? if ns. rate_error_module doesn't exist right now in my python binding.
   Any answer will be deeply appreciated, thanks in advance.
 

Tommaso Pecorella

unread,
Mar 31, 2024, 12:08:08 PM3/31/24
to ns-3-users
... and that's why you shouldn't use ChatGPT. Study the ns-3 documentation and you'll find the answers (RateErrorModel is in the Network module).

Tao Chen

unread,
Apr 7, 2024, 10:21:00 PM4/7/24
to ns-3-users
I got it working, would like to post the steps here in case others might encounter the same issue later on.
1) First of all, what I had before is ns-3 3.36, which is not good for cppyy, as nsnam site said, at least 3.37 is required.
2) So I installed the latest and greatest 3.41 (currentlyI can find from nsnam.org), my pythone script with RateErrorModule creating works now.
3) A few nuisance during installation of 3.41 (and 3.40 as well)
    -  if you configure ns3 with recommended "$ ./ns3 configure --enable-examples --enable-tests", it will fail with:
        FAILED: src/wifi/CMakeFiles/libwifi-test.dir/test/wifi-mlo-test.cc.o
        So I only configure with "./ns3 configure", it went through.
        Then I run "./ns3 build", it went through as well, after wait a cup of coffee.
    - My first test of running " ./ns3 run examples/tutorial/first.py " took a long time, it went through after I had my dinner, don't exactly know how long it took....I blame  it to my slow laptop.
   - running my script with RateErrorModule creating went though as well, no compile error, just slow, which is fine for  me :)
      ...
     #create error module
    em = ns.CreateObject("RateErrorModel")
    em.__deref__().SetAttribute("ErrorRate", ns.DoubleValue(0.001))
    devices.Get(0).__deref__().SetAttribute("ReceiveErrorModel", ns.PointerValue(em))
    ...

Thanks Tommaso for pointing me to Python expert group and getting the right direction there (https://ns-3.zulipchat.com)
Reply all
Reply to author
Forward
0 new messages