28.3 Usage

From a user's perspective, the only thing to do in order to use a dynamic module in ns is to load it. After this operation, the module itself can be used exactly as if it had been embedded in the ns binary.

The loading of a dynamic module should be performed at the beginning of the tcl script used for the simulation. The loading consists of the following tcl instruction:

load libmodulename.so
where libmodulename.so is the filename of the shared library.

One thing we have to take care of is to use the right path to the library. Relative and absolute paths can be used for this purpose; e.g., respectively,

load ../src/.libs/libmodulename.so
load /locale/baldo/lib/somethingelse.so

Note that you can just provide the file name without any path, if the path it resides in is in the LD_LIBRARY_PATH environmental variable in Linux, or the PATH environment variable on Cygwin.

Also remember that the format of the shared libraries is OS-dependent: .so libraries are found in unix systems, while for instance on cygwin you will need to use .dll libraries, and on OS X the .dylib suffix is used. With respect to this point, it is to be noted that also the actual name of the library file might change - for instance, the same library mentioned before would be called cygmodule-0.dll when built using libtool on a cygwin system. Just remember to chek the actual filename if you load command fails.

We note that, for libraries built using libtool (which is the method we propose in this document), when you install the library on cygwin - i.e., when you type make install -, the dll file gets installed in YOUR_PREFIX/bin, and not in YOUR_PREFIX/lib as you might expect. Therefore, you should add YOUR_PREFIX/bin to your PATH to make everything work smoothly.

Tom Henderson 2011-11-05