ns-3 3.43 8 tests CRASH

233 views
Skip to first unread message

Mark Gregory

unread,
Oct 21, 2024, 4:05:27 AM10/21/24
to ns-3-users
ubuntu 24.10
Pre-requisites
sudo apt install g++ python3 clang-format clang-tidy cmake cmake-format ninja-build git build-essential autoconf automake bridge-utils bzr ccache cvs dia doxygen dvipng ebtables gir1.2-goocanvas-2.0 graphviz gir1.2-gtk-3.0 gnuplot-x11 gsl-bin imagemagick  sqlite3 libsqlite3-dev libopenmpi-dev  ipython3  dia imagemagick latexmk libeigen3-dev gsl-bin libgsl-dev libgslcblas0 libgtk-3-dev lxc lxc-templates libxmu-dev libxml2 libxml2-dev libboost-all-dev libgsl-dev libgslcblas0 libxml2 libxml2-dev libgtk-3-dev libxml2 libxml2-dev libboost-all-dev mercurial openmpi-bin openmpi-common openmpi-doc p7zip-full python3-gi python3-gi-cairo python3-pygraphviz python3-matplotlib python3-pip python3-sphinx python3-tk python3-venv qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools gdb texlive texlive-extra-utils texlive-latex-extra texlive-font-utils tcpdump uml-utilities valgrind vtun wireshark

.bashrc created: alias python=python3

python3 -m pip install cppyy --user --break-system-packages

reboot

cd ns-3-allinone
./download.py
./build.py --enable-examples --enable-tests
cd ns-3-dev
./test.py

List of CRASHed tests:
    examples/routing/simple-routing-ping6.py
    examples/tutorial/first.py
    examples/wireless/mixed-wired-wireless.py
    examples/wireless/wifi-ap.py
    src/bridge/examples/csma-bridge.py
    src/core/examples/sample-simulator.py
    src/energy/examples/generic-battery-discharge-example.py
    src/flow-monitor/examples/wifi-olsr-flowmon.py

I've tried the same with

I would appreciate ideas. I'm pretty stumped at this point. The contradictory tutorials and guidelines, especially where python bindings are concerned is not helping.

Tommaso Pecorella

unread,
Oct 21, 2024, 4:29:22 AM10/21/24
to ns-3-users
I don't know... we will have to look into this.

However, "--break-system-packages" doesn't look like a safe option to me. Just saying:

Tommaso Pecorella

unread,
Oct 21, 2024, 4:31:26 AM10/21/24
to ns-3-users
BTW, we'd appreciate your thoughts on "The contradictory tutorials and guidelines, especially where python bindings are concerned is not helping.".

The goal is to make them useful, so if they're contradictory we have room for improvement - but we also need to know where they're obscure.

Gabriel Ferreira

unread,
Oct 21, 2024, 4:38:04 AM10/21/24
to ns-3-users
> The contradictory tutorials and guidelines, especially where python bindings are concerned is not helping.

Would you mind giving examples? For me, they look clear, but I wrote them, so I'm biased.

The bindings work for sure, as demonstrated by our CI jobs testing it.
You didn't show exactly what failed, but I'm going to guess it is MPI, which is not supported by Cppyy, and there is nothing we can do about it.

Mark Gregory

unread,
Oct 21, 2024, 7:52:36 AM10/21/24
to ns-3-users
thank you Gabriel, this may have resolved the issue. I bundled up all of the dependencies (being an engineer, saving time by doing things once is a mantra).

I'm trying to do this again (can't count the number of times I've tried different combinations, with git, without git, allinone, not allinone, and so on) with a bare minimum of the pre-requisites. And without cppyy.

Yes, there is a need to look at cppyy - ubuntu gives warnings now.

Are you saying that the best way is to install using python venv and not --user? This needs to be cleared up in the documentation please.

Also, the documentation does not mention the paths that are essential. Worked this out through trial and error.

Can't say I'm enjoying this.

And yes, I'm available for a teams meeting at any time. Seven days spent trying to install software is enough. Never in my life have I experienced this, and don't want to again.

Mark Gregory

unread,
Oct 21, 2024, 8:28:51 AM10/21/24
to ns-3-users
Unfortunately, Gabriel's idea did not change the outcome. I removed all pre-requisites related to mpi, tried again and no luck, the 8 examples failed the test.

I'm now going to install cppyy in a python venv and see if this makes a difference.

Mark Gregory

unread,
Oct 21, 2024, 9:10:14 AM10/21/24
to ns-3-users
My final post for the evening.
sudo apt remove --purge cppyy

removed .local/bin and .local/include and .local/lib

python venv
install cppyy
update paths and environment variables.

./ns3 clean
./ns3 configure --enable-examples --enable-tests --enable-python-bindings

-- ---- Summary of ns-3 settings:
Build profile                 : default
Build directory               : /home/mark/ns-allinone-3.43/ns-3.43/build
Build with runtime asserts    : ON
Build with runtime logging    : ON
Build version embedding       : OFF (not requested)
BRITE Integration             : OFF (Missing headers: "Brite.h" and missing libraries: "brite")
DES Metrics event collection  : OFF (not requested)
DPDK NetDevice                : OFF (not requested)
Emulation FdNetDevice         : ON
Examples                      : ON
File descriptor NetDevice     : ON
GNU Scientific Library (GSL)  : ON
GtkConfigStore                : ON
LibXml2 support               : ON
MPI Support                   : OFF (not requested)
ns-3 Click Integration        : OFF (Missing headers: "simclick.h" and missing libraries: "nsclick click")
ns-3 OpenFlow Integration     : OFF (Missing headers: "openflow.h" and missing libraries: "openflow")
Netmap emulation FdNetDevice  : OFF (missing dependency)
PyViz visualizer              : ON
Python Bindings               : ON
SQLite support                : ON
Eigen3 support                : ON
Tap Bridge                    : ON
Tap FdNetDevice               : ON
Tests                         : ON


Modules configured to be built:
antenna                   aodv                      applications              
bridge                    buildings                 config-store              
core                      csma                      csma-layout              
dsdv                      dsr                       energy                    
fd-net-device             flow-monitor              internet                  
internet-apps             lr-wpan                   lte                      
mesh                      mobility                  netanim                  
network                   nix-vector-routing        olsr                      
point-to-point            point-to-point-layout     propagation              
sixlowpan                 spectrum                  stats                    
tap-bridge                test                      topology-read            
traffic-control           uan                       virtual-net-device        
visualizer                wifi                      wimax                    


Modules that cannot be built:
brite                     click                     mpi                      
openflow                  


-- Configuring done (8.8s)
-- Generating done (0.9s)
-- Build files have been written to: /home/mark/ns-allinone-3.43/ns-3.43/cmake-cache
Finished executing the following commands:
mkdir cmake-cache
/usr/bin/cmake -S /home/mark/ns-allinone-3.43/ns-3.43 -DPython3_LIBRARY_DIRS=/usr/lib/x86_64-linux-gnu -DPython3_INCLUDE_DIRS=/usr/include/python3.12 -DPython3_EXECUTABLE=/home/mark/.venv/bin/python3 -B /home/mark/ns-allinone-3.43/ns-3.43/cmake-cache -DCMAKE_BUILD_TYPE=default -DNS3_ASSERT=ON -DNS3_LOG=ON -DNS3_WARNINGS_AS_ERRORS=OFF -DNS3_NATIVE_OPTIMIZATIONS=OFF -DNS3_EXAMPLES=ON -DNS3_PYTHON_BINDINGS=ON -DNS3_TESTS=ON -G Ninja --warn-uninitialized

./ns3 build

and yes, 8 examples CRASH 

List of CRASHed tests:
    examples/routing/simple-routing-ping6.py
    examples/tutorial/first.py
    examples/wireless/mixed-wired-wireless.py
    examples/wireless/wifi-ap.py
    src/bridge/examples/csma-bridge.py
    src/core/examples/sample-simulator.py
    src/energy/examples/generic-battery-discharge-example.py
    src/flow-monitor/examples/wifi-olsr-flowmon.py
(.venv) mark@port:~/ns-allinone-3.43/ns-3.43$

Any ideas welcome.

Mark Gregory

unread,
Oct 21, 2024, 9:13:36 AM10/21/24
to ns-3-users
At this point, I'll quite happily pay for someone to get python bindings, cppyy, NetAnim working on ubuntu 24.04.1 whilst I watch (teams) and take notes. I can arrange RDP access.

I cannot continue to waste more time.

Gabriel Ferreira

unread,
Oct 21, 2024, 10:31:31 AM10/21/24
to ns-3-users
It could be indeed something related to paths because of build.py/bake, which I don't really test.
On the other hand, what you just did with the ns3 script and test.py worked just fine for me, on the same Ubuntu 24.04.01.
What is the output of "./ns3 run examples/tutorial/first.py"?

I'm going to try pushing the pip packages for 3.43 today. Haven't had the time to do so yet. In that case, you just need to `pip install ns3` and that is it.

Tom Henderson

unread,
Oct 21, 2024, 2:26:26 PM10/21/24
to ns-3-...@googlegroups.com, Mark Gregory
Hello, I tried following your steps below and could not reproduce your
reported issues. test.py should not attempt to run Python examples
unless the `--enable-python-bindings` flag is passed to the `ns3`
script, which is not the case for using bake to build ns-3. This is
because --enable-python-bindings writes some essential config into the
.lock-ns3_linux_build file, which test.py reads.

Please try Gabriel's suggestion to run this command and share the
resulting output:
$ ./ns3 run examples/tutorial/first.py

Also, can you please point out any specific inaccuracies in the
documentation that you may have found, as Tommaso suggested? I believe
that installation via venv or --user should both work, but because there
are a variety of Python installation practices in the wild, we avoid
prescribing any specific way that users must install cppyy.

Thanks,
Tom

Mark Gregory

unread,
Oct 21, 2024, 8:34:29 PM10/21/24
to ns-3-users
thank you for your responses. I appreciate the help to resolve this matter.
I believe it is a path problem - though have no idea what is the issue.
My path variable is: PATH=/home/mark/.venv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin

I ran this command: ./ns3 run examples/tutorial/first.py &> output
I attached the full output file.
the first few lines are:

In file included from input_line_3:2:
In file included from /usr/include/c++/14/string:42:
In file included from /usr/include/c++/14/bits/char_traits.h:57:
In file included from /usr/include/c++/14/bits/stl_construct.h:61:
In file included from /usr/include/c++/14/bits/stl_iterator_base_types.h:71:
/usr/include/c++/14/bits/iterator_concepts.h:1013:13: error: no matching function for call to '__begin'
        = decltype(ranges::__access::__begin(std::declval<_Tp&>()));
                   ^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/ranges_base.h:511:5: note: in instantiation of template type alias '__range_iter_t' requested here
    using iterator_t = std::__detail::__range_iter_t<_Tp>;
    ^
/usr/include/c++/14/bits/ranges_util.h:132:36: note: in instantiation of template type alias 'iterator_t' requested here
      requires contiguous_iterator<iterator_t<_Derived>>

output.txt

Mark Gregory

unread,
Oct 22, 2024, 12:51:37 AM10/22/24
to ns-3-users
an update

I moved from ubuntu 24.10 to 24.04.1
set repos to australia->aarnet
getting closer to a positive outcome, did not edit .bashrc and add paths this time, but could not run --vis because it states that Pygraphviz could not be found
I followed the following steps
2. install pre-requisites

sudo apt install g++ python3 bridge-utils ccache cmake cmake-format dia doxygen dvipng ebtables git gir1.2-goocanvas-2.0 gir1.2-gtk-3.0 graphviz gsl-bin imagemagick ipython3 latexmk libeigen3-dev libboost-all-dev libgirepository1.0-dev libgtk-3-dev libsqlite3-dev libgsl-dev libgslcblas0 libxml2 libxml2-dev lxc lxc-templates mercurial  ninja-build p7zip-full python3-venv python3-pip python3-gi python3-gi-cairo python3-pygraphviz python3-matplotlib python3-sphinx python3-tk qtbase5-dev qtbase5-dev-tools qtchooser qt5-qmake sqlite3 texlive texlive-extra-utils texlive-latex-extra texlive-font-utils uml-utilities vtun tcpdump wireshark

3. python venv and cppyy
python3 -m venv .venv
source ./.venv/bin/activate

python3 -m pip install cppyy
4. added .bashrc aliases
alias python=python3
alias pyns3='source $HOME/.venv/bin/activate

5. download and unzip ns-allinone
6. build and test
cd ns-allinone-3.43
./build.py --enable-examples --enable-tests
cd ns-3.43/
./ns3 show
./test.py
770 out of 770 tests passed

./ns3 configure --enable-examples --enable-tests --enable-python-bindings
./ns3 build
./ns3 show
./test.py
778 of 778 tests passed
7. current path

PATH=/home/mark/.venv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin
8. test visualizer
./ns3 run first.py --vis
Pygraphviz is required by the visualizer module and could not be found
Command 'build/examples/tutorial/ns3.43-first-default --SimulatorImplementationType=ns3::VisualSimulatorImpl' returned non-zero exit status 1

Mark Gregory

unread,
Oct 22, 2024, 1:13:46 AM10/22/24
to ns-3-users
another update

I've read in a post that pyviz is no longer being maintained and there are warnings, like the one below, that appear related to missing 'kiwi.ui'

there is a need for the linux install page to be updated based on what I've found. I hope this thread helps others to successfully install ns3 with cppyy and pyviz (there is a real need for a better way forward than using non-maintained pyviz)

2. install pre-requisites

sudo apt install g++ python3 bridge-utils ccache cmake cmake-format dia doxygen dvipng ebtables git gir1.2-goocanvas-2.0 gir1.2-gtk-3.0 graphviz gsl-bin imagemagick ipython3 latexmk libeigen3-dev libboost-all-dev libgirepository1.0-dev libgtk-3-dev libgraphviz-dev libsqlite3-dev libgsl-dev libgslcblas0 libxml2 libxml2-dev lxc lxc-templates mercurial ninja-build p7zip-full python3-dev python3-pip python3-gi python3-gi-cairo python3-pygraphviz python3-matplotlib python3-sphinx python3-tk python3-venv qtbase5-dev qtbase5-dev-tools qtchooser qt5-qmake sqlite3 texlive texlive-extra-utils texlive-latex-extra texlive-font-utils uml-utilities vtun tcpdump wireshark


3. python venv and cppyy
python3 -m venv .venv
source ./.venv/bin/activate
python3 -m pip install cppyy
pip install kiwi
pip install pycairo
pip install PyGObject
pip install pygraphviz
pip install matplotlib
pip install -U sphinx
pip install tk


4. added .bashrc aliases
alias python=python3
alias pyns3='source $HOME/.venv/bin/activate

5. download and unzip ns-allinone
6. build and test
cd ns-allinone-3.43
./build.py --enable-examples --enable-tests
cd ns-3.43/
./ns3 show
./test.py
770 out of 770 tests passed
./ns3 configure --enable-examples --enable-tests --enable-python-bindings
./ns3 build
./ns3 show
./test.py
778 of 778 tests passed
7. current path
PATH=/home/mark/.venv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin
8. test visualizer
./ns3 run first.py --vis
/ns3 run first --vis
[0/2] Re-checking globbed directories...
ninja: no work to do.
Could not load plugin 'show_last_packets.py': No module named 'kiwi.ui'
scanning topology: 2 nodes...
scanning topology: calling graphviz layout
scanning topology: all done.

Gabriel Ferreira

unread,
Oct 22, 2024, 4:49:06 AM10/22/24
to ns-3-users

Ah, ok. This is not actually a path problem.
It is an incompatibility between prebuilt libcling based on clang13 (shipped with cppyy) and gnu's stdlibc++ shipped with your OS.
When cppyy tries to build a PCH with all standard headers, it fails.
Disabling the PCH allows you to partially workaround the issue, for the price of running everything slower.
Unless you use concepts, in which case things will break.

Hopefully won't be a problem when they start using clang16.

More details in issue
https://github.com/wlav/cppyy/issues/258

Mark Gregory

unread,
Oct 22, 2024, 5:10:47 AM10/22/24
to ns-3-users
Hi Gabriel,

I saw the post you mentioned when I was searching, but the thread is not easy to follow.

When you say "won't be a problem when they start using clang16" - who is they? Is it Ubuntu or is it the NS3 team or is it cppyy?
This issue wasted about 10 days of my time, and it would be positive if a warning can be displayed, plus a clear instruction on what to do if this problem is encountered.
And  https://github.com/wlav/cppyy/issues/258 is not able to be understood by anyone not familiar with the ins and outs of clang - like me.

Gabriel Ferreira

unread,
Oct 22, 2024, 6:29:08 AM10/22/24
to ns-3-users
They, in this particular case, refers to Cppyy.
We have 0 control over that.
People from the LHC and other labs have been upstreaming parts of PyROOT and the Cling c++ interpreter to Clang.
It is really fun to follow them.
https://compiler-research.org/

I'm not against adding a warning, but I doubt I can catch this kind of error in the code, to emit a clear error message.
I will give it a try. If it doesn't work, I will add a note on the docs.

To be honest with you, I never intended people to try to use it from source, just from pip.
My students never had any issues. ¯\_(ツ)_/¯

Mark Gregory

unread,
Oct 22, 2024, 7:55:05 AM10/22/24
to ns-3-users
Hi Gabriel,

thank you for letting me know. If the issue is related to cppyy and it is unmaintained then it is reasonable to provide a clear warning and what to do if someone runs into problems.

I'm not sure what you mean by "I never intended people to try to use it from source, just from pip"? use what from pip?

I used the installation instructions found on the ns3 and cppyy sites. I recommend that these be changed to indicate the safest way to install and use cppyy until an alternative approach is found.
A warning would have saved me a week. I still don't know if the problem will return and how to fix Ubuntu if the problem returns.

I'm only half way to where I need to be. I want to use visual studio code to build and debug - and I can see this will be a hoot -> joking.

The problem first started when I tried to debug one of the examples using visual studio code - and I'm guessing it is because of a different compiler / path problem, and the compiler trying to include the cppyy code.

Any hints on how to ensure this does not happen again would be welcome.

If visual studio code cannot be used safely, then it should be removed as an option on the ns-3 website.

And I'll be advising my students to be wary of ns3 in the future. If ns-3 and python don't play nice due to cppyy then there should be warnings and "how to" notices related to anticipated problems, how to fix and what to look for.

I understand that ns-3 is built by volunteers, and the work is appreciated. I do hope that the ns-3 community can look at my situation and my feedback, and see that my concerns are really about ensuring that others don't have a similar outcome.

Tom Henderson

unread,
Oct 22, 2024, 9:13:18 AM10/22/24
to ns-3-...@googlegroups.com, Mark Gregory
Mark, we will look into some updates based on your experience. We have
a couple of resources below on using VScode with ns-3.

https://www.nsnam.org/docs/release/3.43/tutorial/html/getting-started.html#microsoft-visual-studio-code

https://gabrielcarvfer.github.io/NS3/installation/visualcode

- Tom

On 10/22/24 04:55, Mark Gregory wrote:
> Hi Gabriel,
>

Gabriel Ferreira

unread,
Oct 22, 2024, 10:24:06 AM10/22/24
to ns-3-users
> thank you for letting me know. If the issue is related to cppyy and it is unmaintained then it is reasonable to provide a clear warning and what to do if someone runs into problems.

It is maintained, but these issues tend to pop up with newer versions. This report is from last month, for example. I've seen it before, but you were the first raising the issue in the context of ns-3.


> A warning would have saved me a week. I still don't know if the problem will return and how to fix Ubuntu if the problem returns.

While that is true, I don't have time to check every single platform, every time. And without a user report, I'm not sure what exactly caused the issue and how to detect it. Now I know 24.10 is a problem.

> I'm not sure what you mean by "I never intended people to try to use it from source, just from pip"? use what from pip?

ns-3. ns-3 is available via pip. https://pypi.org/project/ns3/
You can even use it online in Google Colab!  https://colab.research.google.com/github/Gabrielcarvfer/ns3_for_education/blob/master/601_beamforming.ipynb
This is what is written in ns-3 readme :)


> I'm only half way to where I need to be. I want to use visual studio code to build and debug - and I can see this will be a hoot -> joking.

It totally works. But you need to remember to set PYTHONPATH and PATH, otherwise the debugger won't find the bindings nor the libraries. Best way to do this is

import sys
sys.path.append("./ns-3-dev/build/bindings/python")
sys.path.append("./ns-3-dev/build/lib")
from ns import ns

> Any hints on how to ensure this does not happen again would be welcome.

Docker container. It is the only bulletproof solution. https://www.nsnam.org/docs/manual/html/working-with-docker.html
You can install the vscode server there, and connect to your local client, then work on a mounted share, so your changes inside the container are propagated outwards.


> And I'll be advising my students to be wary of ns3 in the future

Which is a shame, because I have some pretty cool demos at https://github.com/Gabrielcarvfer/ns3_for_education
My favorites are audio and video streaming in https://nbviewer.org/github/Gabrielcarvfer/ns3_for_education/blob/master/200_the_application_layer.ipynb , or the beamforming one I linked above.

Gabriel Ferreira

unread,
Oct 22, 2024, 10:26:56 AM10/22/24
to ns-3-users

Just noticed I picked a bad example. The beamforming was from source (with the whole ns-3 source code, build, etc, like you are trying to do). You can see the sys.path.append stuff.

This one uses it straight from pip. https://colab.research.google.com/github/Gabrielcarvfer/ns3_for_education/blob/master/000_introduction_to_ns3.ipynb

markalexan...@gmail.com

unread,
Oct 22, 2024, 5:33:42 PM10/22/24
to Tom Henderson, ns-3-...@googlegroups.com
Thank you Tom,

I would appreciate learning if there is an alternative to the pyviz visualizer?

Regards,
Mark Gregory

Mark Gregory

unread,
Oct 22, 2024, 5:39:59 PM10/22/24
to ns-3-users
Hi Gabriel,

thank you for the great information.

when you mention
import sys
sys.path.append("./ns-3-dev/build/bindings/python")
sys.path.append("./ns-3-dev/build/lib")
from ns import ns

where is this occurring?
In Ubuntu, I can add to the path by modifying .bashrc or do you mean adding this information to visual studio code somewhere?
or do you mean that the four commands should occur after I enter the python venv and before I run visual studio code in ns-3-dev?
I have a feeling this is critical information that would be helpful to others.

Mark Gregory

unread,
Oct 22, 2024, 7:23:01 PM10/22/24
to ns-3-users
Hi Gabriel,

thank you again, this is very helpful. Today I'm going back to grabbing ns3 from git and using visual studio code.

I now understand that the following is carried out in the python venv with a directory .venv if this is what it is called when the venv is created
what is the purpose of the last line: from ns import ns?

for the ns-allinone the code would become

source $HOME/.venv/bin/activate
cd ./ns-allinone-3.43
import sys
sys.path.append("./ns-3.43/build/bindings/python")
sys.path.append("./ns-3.43/build/lib")
from ns import ns

Finally, it appears staying away from cppyy is a positive move, this means not using the pyviz visualizer. Is there another visualizer that can be used instead?

Tom Henderson

unread,
Oct 22, 2024, 10:57:31 PM10/22/24
to ns-3-...@googlegroups.com
There is one currently maintained and two legacy (only lightly
maintained) visualizers.

The currently maintained one is netsimulyzer. However, it is maintained
in a separate repository and has to be added to ns-3. More about it
here: https://apps.nsnam.org/app/netsimulyzer/

The legacy ones (the original authors are no longer involved) are pyviz
and netanim. Gabriel has been keeping pyviz working, and Andre has been
updating netanim for newer Qt support, but other than that, no one is
developing them further, as far as I know.

- Tom

markalexan...@gmail.com

unread,
Oct 23, 2024, 2:22:21 AM10/23/24
to ns-3-...@googlegroups.com
Thank you Tom, I'll look at netsimulyzer
--
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/m4mE9INRHK8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ns-3-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ns-3-users/eb578631-938b-6738-2a39-76210a3deeb6%40tomh.org.

Gabriel Ferreira

unread,
Oct 23, 2024, 1:44:10 PM10/23/24
to ns-3-users
>when you mention
>import sys
>sys.path.append("./ns-3-dev/build/bindings/python")
>sys.path.append("./ns-3-dev/build/lib")
>from ns import ns

>where is this occurring?
>In Ubuntu, I can add to the path by modifying .bashrc or do you mean adding this information to visual studio code somewhere?
>or do you mean that the four commands should occur after I enter the python venv and before I run visual studio code in ns-3-dev?
>I have a feeling this is critical information that would be helpful to others.

This goes into your python script, or jupyter notebook. This is an alternative to explicitly setting LIBRARY_PATH and PYTHONPATH environmental variables.
You then run this from your python interpreter after activating the venv. This way it always work as long as the interpreter has cppyy available and ns-3 was built from source.

$ git clone https://gitlab.com/nsnam/ns-3-dev
$ pip install cppyy
$ cd ns-3-dev
$ python -m venv ns3env
$ source ./ns3env/bin/activate
$ ./ns3 configure --enable-python-bindings
$ ./ns3 build

Then when you need to run, if you call via the ns3 script, it will set these environment variables for you, so you don't need to do anything

$ cp examples/tutorial/first.py ./
$ ./ns3 run ./first.py

[0/2] Re-checking globbed directories...
ninja: no work to do.
[runStaticInitializersOnce]: Failed to materialize symbols: { (main, { __cxx_global_var_initcling_module_148_, _GLOBAL__sub_I_cling_module_148, _ZN3ns3L16g_timeInitHelperE, $.cling-module-148.__inits.0, __orc_init_func.cling-module-148 }) }
[runStaticInitializersOnce]: Failed to materialize symbols: { (main, { __orc_init_func.cling-module-148 }) }
At time +2s client sent 1024 bytes to 10.1.1.2 port 9
At time +2.00369s server received 1024 bytes from 10.1.1.1 port 49153
At time +2.00369s server sent 1024 bytes to 10.1.1.1 port 49153
At time +2.00737s client received 1024 bytes from 10.1.1.2 port 9

Ignore the failed to materialize symbols stuff. It is an bug in Cppyy >=3 that appeared when they updated from Clang 9 to 13.

Working like this is terrible, in my opinion. You really want debuggers available when working Cppyy, because autocomplete doesn't really exist.
And their smart pointer stuff doesn't really play nicely with our custom implementation, so it is quite cumbersome dereferencing pointers.
If you have a quick look at the demos you will see what I mean.

If you don't set the  environment variables not set this code block I referred to, you will get this (for ns-3 examples, which have a custom error handler. For normal python scripts, you will get a ModuleNotFoundException or something like this.).

$ python3 ./first.py
Error: ns3 Python module not found; Python bindings may not be enabled or your PYTHONPATH might not be properly configured

If you prepend this code to the ./first.py, it will work normally again.

+import sys
+import os
+sys.path.append(f"{os.path.dirname(__file__)}/build/bindings/python")
+sys.path.append(f"{os.path.dirname(__file__)}/build/lib") # this assumes first.py is inside the ns-3-dev directory
try:
    from ns import ns
except ModuleNotFoundError:
    raise SystemExit( "Error: ns3 Python module not found;"
                                    " Python bindings may not be enabled"
                                    " or your PYTHONPATH might not be properly configured" )

And now you can debug it with your favorite IDE, like any python script.

$ python3 first.py
[runStaticInitializersOnce]: Failed to materialize symbols: { (main, { _GLOBAL__sub_I_cling_module_148, _ZN3ns3L16g_timeInitHelperE, __orc_init_func.cling-module-148, __cxx_global_var_initcling_module_148_, $.cling-module-148.__inits.0 }) }
[runStaticInitializersOnce]: Failed to materialize symbols: { (main, { __orc_init_func.cling-module-148 }) }
At time +2s client sent 1024 bytes to 10.1.1.2 port 9
At time +2.00369s server received 1024 bytes from 10.1.1.1 port 49153
At time +2.00369s server sent 1024 bytes to 10.1.1.1 port 49153
At time +2.00737s client received 1024 bytes from 10.1.1.2 port 9

Antarip Barman

unread,
Oct 24, 2024, 1:46:20 AM10/24/24
to ns-3-users
Hi,

I am facing similar issues running the ns3 python package.
I tried installing it via pip and building it from ns-3-dev. I also ran it by adding the code suggested before:

+import sys
+import os
+sys.path.append(f"{os.path.dirname(__file__)}/build/bindings/python")
+sys.path.append(f"{os.path.dirname(__file__)}/build/lib64")

But I still can't get it to work. It's the same cppyy error that Mark was facing.

I then I tried running it using Docker, but since I am not much experienced with Docker I could not get the Python bindings to enable.
I would appreciate if you can provide any guidance that I can follow. 

I am currently using:
Fedora 40
Python 3.12.7
Clang version 18.1.8 (Fedora 18.1.8-1.fc40)
Cmake version 3.28.2

Gabriel Ferreira

unread,
Oct 24, 2024, 2:51:23 AM10/24/24
to ns-3-...@googlegroups.com
If you installed it via pip, it will work just fine without this append stuff.

You DO NOT want ns-3 source anywhere near your python script in this case. More specifically, it should be at least two directories distant from ns-3-dev, otherwise it may get confused whether to use the libraries installed via pip or built from source. And, in case there is a lock file in the ns-3-dev (a.k.a. you configured the project), it will try to load the libraries built from source.

Try

(ns3env) ~/ns-3-dev $ mkdir ~/ns3python && cd ~/ns3python
(ns3env) ~ns3python $ python3 -c "from ns import ns"

Antarip Barman

unread,
Oct 24, 2024, 4:57:41 AM10/24/24
to ns-3-users
I made a completely new user just to be safe and type the following commands.


$ mkdir ~/ns3python && cd ~/ns3python
$ python -m venv .venv && source ./.venv/bin/activate
(.venv)$ pip install ns3
(.venv)$ python3 -c "from ns import ns"

I am still getting the same errors. I have attached the error logs.
log

Antarip Barman

unread,
Oct 24, 2024, 5:33:43 AM10/24/24
to ns-3-users
I finally got it working using docker. Used the same config given in the examples. Everything is working as expected.
But I still can't run the python scripts directly in my Fedora 40 machine. 

Gabriel Ferreira

unread,
Oct 24, 2024, 5:49:52 AM10/24/24
to ns-3-users
You got the same error as Mark. This is an incompatible GNU's stdlibc++ and the cppyy's built-in libclang.

Gabriel Ferreira

unread,
Nov 10, 2024, 12:26:38 PM11/10/24
to ns-3-users
Just an update, merging some updates to the docs and build script to avoid these problems in the future.
https://gitlab.com/nsnam/ns-3-dev/-/merge_requests/2238
Reply all
Reply to author
Forward
0 new messages