How to put simulation scripts to project?

21 views
Skip to first unread message

Igor Plastov

unread,
Dec 19, 2025, 11:30:39 AM12/19/25
to ns-3-...@googlegroups.com

NS-3 has utility create_module.py which can make a project containing several custom modules in a folder with the name of project.  I did this and  had added  "simulations"  directory with script, resulting tree:
   
my-custom-app
├── device-a
│   ├── CMakeLists.txt
│   ├── doc
│   │   └── device-a.rst
│   ├── examples
│   │   ├── CMakeLists.txt
│   │   └── device-a-example.cc
│   ├── helper
│   │   ├── device-a-helper.cc
│   │   └── device-a-helper.h
│   ├── model
│   │   ├── device-a.cc
│   │   └── device-a.h
│   └── test
│       └── device-a-test-suite.cc
├── device-b
│   ├── CMakeLists.txt
│   ├── doc
│   │   └── device-b.rst
│   ├── examples
│   │   ├── CMakeLists.txt
│   │   └── device-b-example.cc
│   ├── helper
│   │   ├── device-b-helper.cc
│   │   └── device-b-helper.h
│   ├── model
│   │   ├── device-b.cc
│   │   └── device-b.h
│   └── test
│       └── device-b-test-suite.cc
└── simulations
    ├── CMakeLists.txt
    └── run-simulation.cc

$ ./ns3 configure --enable-examples --enable-tests
and
$ ./ns3 build
are complete successfully, but
$ ./ns3 run "run-simulation"
does not find executable file since command:
$ find /home/igor/workspace_ns3.45/ns-allinone-3.45/ns-3.45/build -name "run-simulation*"
 successfully found it in the "build" directory. Answer looks like:
/home/igor/workspace_ns3.45/ns-allinone-3.45/ns-3.45/build/run-simulation

My goal is to encapsulate my custom modules and simulation scripts inside the project. What is the right way to do this?

Thanks,
Igor

-------------------------------------------------------------------------------

Tommaso Pecorella

unread,
Dec 19, 2025, 6:08:10 PM12/19/25
to ns-3-users
You should have a directory like this:

contrib
└── myModule
    ├── CMakeLists.txt
    ├── doc
    │   └── myModule.rst
    ├── examples
    │   ├── CMakeLists.txt
    │   └── myModule-example.cc
    ├── helper
    │   ├── myModule-helper.cc
    │   └── myModule-helper.h
    ├── model
    │   ├── myModule.cc
    │   └── myModule.h
    └── test
        └── myModule-test-suite.cc


"device-a" and "device-b"  looks like they're two different modules (it might be ok, I'm not you).
About your simulation scripts, I'd make a 3rd module with empty directories except for the "examples" one.

OR you can collapse everything into a single module. 

Igor Plastov

unread,
Dec 21, 2025, 8:07:18 AM12/21/25
to ns-3-...@googlegroups.com
Hello, Tommaso!
Thank you.
Good point about the 3rd module as a place for simulations. It can help but it looks like a workaround.

At the moment  my external project can be successfully compiled. Some changes in CMakeLists.txt files help to put executables to directory build/simulation directory. Unfortunately this is also a workaround because targets corresponding to these files are not present in a targets list.
for simulations directory CMakeLists.txt looks (for simlicity project has only one module " my_module" in contrib):

#------------------------------------------------------------------------------------
add_executable(my_project-simulation my_project-simulation.cc)

target_link_libraries(my_project-simulation
  core
  network
  my_module
)

set(BUILD_DIR ${CMAKE_SOURCE_DIR}/build)

file(MAKE_DIRECTORY ${BUILD_DIR}/simulation)

set_target_properties(my_project-simulation PROPERTIES
  RUNTIME_OUTPUT_DIRECTORY ${BUILD_DIR}/simulation
)
#------------------------------------------------------------------------------------

Best regards,
Igor

сб, 20 дек. 2025 г. в 02:08, Tommaso Pecorella <tomm...@gmail.com>:
--
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 the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/ns-3-users/3c6e8f78-c4b8-45e2-a6ea-97bed0eea469n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages