How to use the ns-3 visualizer in C++ without the command-line option --vis

184 views
Skip to first unread message

lkimuk

unread,
May 28, 2024, 11:35:07 AM5/28/24
to ns-3-users

I want to utilize the ns-3 visualizer in my project, but I prefer not to rely on the command-line option --vis (Actually I cannot because I use my own CMake instead of ./ns3). Could you please guide me on how to enable and configure ns-3 visualizer functionality in C++? Is there a way to directly enable visualization in the code instead of using a command-line option?

Thank you for your assistance!

lkimuk

unread,
May 29, 2024, 1:08:58 AM5/29/24
to ns-3-users
I found a method to do this, just set the GlobalValue SimulatorImplementationType to "ns3::VisualSimulatorImpl".

For example:
```cpp
GlobalValue::Bind ("SimulatorImplementationType", StringValue ("ns3::VisualSimulatorImpl"));
```

Then you can start the visualizer without the command-line.
Message has been deleted

Amruth Gudigar

unread,
Jun 6, 2024, 7:53:26 AM6/6/24
to ns-3-users
Where do we insert it 
Which is the correct position to inset this line in C++ Config File?

Gabriel Ferreira

unread,
Jun 6, 2024, 2:41:46 PM6/6/24
to ns-3-users
Inside the main function, Amruth.

Dimes

unread,
Oct 2, 2024, 7:10:05 AM10/2/24
to ns-3-users
Hi Ikimuk, can you work me through how to use visualizer normally? I tried this (ns3.41 on Ubuntu22.04):

1. I installed the dependency stated on this tutorial https://www.nsnam.org/docs/release/3.41/installation/singlehtml/index.html

    $ sudo apt install gir1.2-goocanvas-2.0 python3-gi python3-gi-cairo python3-pygraphviz gir1.2-gtk-3.0 ipython3 

2. I try to enable the python-binding and visualizer, but found out there is no this option in ./ns3, so I modified CMakeList.txt to make it on. 

    line 88 "option(NS3_VISUALIZER "Build visualizer module" ON)"

3. I configure, $ ./ns3 configure, and the output says both python-binding and visualizer are already on. Then I build: $ ./ns3 build all successful

4. Then I try to run the first example with visualizer: $ /ns3 run first --vis. This has error "ns3::VisualSimulatorImpl not found"

5. I realize maybe that's because I haven't installed the pyviz, and all I did was only installing prerequisites for it. 

    So I $ pip install pyviz, and it has more problem: 

  Collecting matplotlib==3.0.3 (from pyviz)
  Using cached matplotlib-3.0.3.tar.gz (36.6 MB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error
 
  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [61 lines of output]
      /tmp/pip-install-xd2dcv5u/matplotlib_536aeddc0db54185b330a0512b60cb91/setup.py:33: SetuptoolsDeprecationWarning: The test command is disabled and references to it are deprecated.
      !!
     
              ********************************************************************************
              Please remove any references to `setuptools.command.test` in all supported versions of the affected package.
     
              By 2024-Nov-15, you need to update your project and remove deprecated calls
              or your builds will no longer be supported.
              ********************************************************************************
     
      !!
        from setuptools.command.test import test as TestCommand
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/tmp/pip-install-xd2dcv5u/matplotlib_536aeddc0db54185b330a0512b60cb91/setup.py", line 225, in <module>
          msg = pkg.install_help_msg()
        File "/tmp/pip-install-xd2dcv5u/matplotlib_536aeddc0db54185b330a0512b60cb91/setupext.py", line 650, in install_help_msg
          release = platform.linux_distribution()[0].lower()
      AttributeError: module 'platform' has no attribute 'linux_distribution'
      ============================================================================
      Edit setup.cfg to change the build options


6. I googled and found this, saying that the pyviz latest release is in 2019 and it needs matplotlib-3.03 (also 2019), and it works with python3.5

but after python3.8 things changed, so it dont fit anymore. 

https://discuss.python.org/t/unable-to-install-pyviz/43284,  


Could you please help?




On Tuesday, May 28, 2024 at 11:35:07 PM UTC+8 lkimuk wrote:

Gabriel Ferreira

unread,
Oct 3, 2024, 4:20:21 AM10/3/24
to ns-3-users
For visualizer, you do not install pyviz via pip. That is a completely different thing. 
ns-3 visualizer is a python package shipped with ns-3 itself, in visualizer/visualizer.
For visualizer to work, you will also need cppyy==2.4.2 for ns-3.41.

Dimes

unread,
Oct 6, 2024, 4:56:53 AM10/6/24
to ns-3-...@googlegroups.com
Thank you. 

I tried cppyy=2.4.2 and it still doesn't work. 
But I found this issue and the corresponding commit to fix it: 
https://gitlab.com/nsnam/ns-3-dev/-/commit/02d2c11d9cc6196c4dccb3c718e9b8a09b224f19

And afterward, it works. 

I know you prob already know how it works, but I still reply to you just in case someone else also has this problem and searched into this thread. 


--
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/9pHtWvmQaV0/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/64ccd4ef-77a1-4a3b-bf0f-9b3d85bb999an%40googlegroups.com.


--


Best regards, 
Dimes.

Sent from Gmail
Reply all
Reply to author
Forward
0 new messages