MATLAB and NS3 co-simulation
Co-simulate MATLAB with NS-3 network simulator, combining the powers of MATLAB and NS-3. Describe the scenario in MATLAB, run simulation from MATLAB, capture the results and visualize them in MATLAB. Optionally use the MATLAB PHY and Channel models, instead of the statistical models of NS-3.
This co-simulation code currently:
Following example scenarios are included in this repository:
See the included documentation in 'doc' folder, for more details.
Follow these steps to setup this co-simulation:
Download the source code (or download and extract the zip file). This gives out MATLAB-NS3 folder.
Download NS-3.29 from https://www.nsnam.org/release/ns-allinone-3.29.tar.bz2.
$sh NS3-build.sh
Note: It is strongly recommended that you add LD_LIBRARY_PATH export to the shell startup script so that it is set automatically at startup.
Add path to 'LD_LIBRARY_PATH' in the startup script
export LD_LIBRARY_PATH=<MATLAB-NS3 BASE FOLDER>/ns-allinone-3.29/ns-3.29/build/lib:$LD_LIBRARY_PATH
setenv LD_LIBRARY_PATH<MATLAB-NS3 BASE FOLDER>/ns-allinone-3.29/ns-3.29/build/lib:$LD_LIBRARY_PATH
Note: You have to launch new terminal (shell) or restart the PC to get the environment with updated LD_LIBRARY_PATH.
Launch MATLAB from the new terminal. Go to the folder MATLAB-NS3.
Run ‘buildMex.m’ to build Mex-binaries in the MATLAB Command Window.
>>MATLAB-NS3/native/mexBindings/buildMex
Note: You may ignore warnings about GCC compiler version, thrown by MATLAB MEX. It works on Debian 8 (GCC version 4.9.x) and Debian 9 (GCC version 6.3.x). Should work with other GCC versions also.
All examples are placed under ‘scenarios’ folder. Following steps are applicable to run any of the examples in this folder.
Go to any example folder, such as: MATLAB-NS3/scenarios/truckPlatooning/
Run ‘scenario.m’ script of any example. It might take around 2-3 minutes to complete. During this time the terminal will remain busy.
Note: Running the simulation scenario will clear all the variables, close all the figures and unload all the functions in the current workspace.
>>scenario.m
To visualize the results of the simulation, run the MATLAB script in the ‘visualizer’ folder of the same example.
>>topologyVisualizer.m