how to debug in Ns3

3,521 views
Skip to first unread message

El Hadi Cherkaoui

unread,
Mar 4, 2011, 8:18:40 AM3/4/11
to NS3
Hi all,

how to debug a program in NS3 ? I see the NS_LOG_DEBUG function but no file is generated

could you help me ?

Hadi

Chris Facchini

unread,
Mar 4, 2011, 10:04:16 AM3/4/11
to ns-3-users
Hi,

On Mar 4, 2:18 pm, El Hadi Cherkaoui <elhadi.cherka...@gmail.com>
wrote:
> how to debug a program in NS3 ? I see the NS_LOG_DEBUG function but no
> file is generated

NS_LOG_DEBUG is a macro that prints what you want it to print. Think
of it as an enhancement of 'std::cerr'.
The advantage of using NS_LOG_DEBUG (and the like, e.g. NS_LOG_ERROR,
NS_LOG_INFO, ...) over 'cout/cerr/printf/...' is that you can can
control the level of detail of these debugging messages.
Take a look here to find more: http://www.nsnam.org/docs/release/3.10/doxygen/group__logging.html
This link may be interesting as well:
http://www.nsnam.org/wiki/index.php/HOWTO_use_NS_LOG_to_find_a_problem

On the other hand, if you want to debug your code using a debugger,
you can follow the steps suggested here:
http://www.nsnam.org/wiki/index.php/User_FAQ#How_to_run_programs_with_gdb

Best,
Chris

scolfield

unread,
Mar 4, 2011, 12:31:20 PM3/4/11
to ns-3-...@googlegroups.com
Hi,

You have to use the NS_LOG environment variable into the bash, or your terminal that use.
And, inside the classes, you have some like this NS_LOG_COMPONENT_DEFINE ("PointToPointChannel");

Well, suppose that you'll want to debug simulation using this class;
now, you have set up the NS_LOG variable..

export NS_LOG=PointToPointChannel

and execute your script,

./waf --run example

--
scolfield


--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To post to this group, send email to ns-3-...@googlegroups.com.
To unsubscribe from this group, send email to ns-3-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ns-3-users?hl=en.


Miquel Angel

unread,
Mar 22, 2011, 12:37:34 PM3/22/11
to ns-3-users
I have a similar error. In my script i used:
NS_LOG_COMPONENT_DEFINE ("Escenari1");

When i want to execute it:
export Escenari1
./waf --run name

Waf: Entering directory `/Users/mabergas/repos/ns-3-allinone/ns-3-dev/
build'
program 'escenari1' not found; available programs are:...

Do you think it's a script error?
Thanks


On 4 mar, 18:31, scolfield <kscolfi...@gmail.com> wrote:
> Hi,
>
> You have to use the NS_LOG environment variable into the bash, or your
> terminal that use.
> And, inside the classes, you have some like this NS_LOG_COMPONENT_DEFINE
> ("PointToPointChannel");
>
> Well, suppose that you'll want to debug simulation using this class;
> now, you have set up the NS_LOG variable..
>
> export NS_LOG=PointToPointChannel
>
> and execute your script,
>
> ./waf --run example
>
> --
> scolfield
>
> On Fri, Mar 4, 2011 at 12:04, Chris Facchini <c.facch...@gmail.com> wrote:
> > Hi,
>
> > On Mar 4, 2:18 pm, El Hadi Cherkaoui <elhadi.cherka...@gmail.com>
> > wrote:
> > > how to debug a program in NS3 ? I see the NS_LOG_DEBUG function but no
> > > file is generated
>
> > NS_LOG_DEBUG is a macro that prints what you want it to print. Think
> > of it as an enhancement of 'std::cerr'.
> > The advantage of using NS_LOG_DEBUG (and the like, e.g. NS_LOG_ERROR,
> > NS_LOG_INFO, ...) over 'cout/cerr/printf/...' is that you can can
> > control the level of detail of these debugging messages.
> > Take a look here to find more:
> >http://www.nsnam.org/docs/release/3.10/doxygen/group__logging.html
> > This link may be interesting as well:
> >http://www.nsnam.org/wiki/index.php/HOWTO_use_NS_LOG_to_find_a_problem
>
> > On the other hand, if you want to debug your code using a debugger,
> > you can follow the steps suggested here:
> >http://www.nsnam.org/wiki/index.php/User_FAQ#How_to_run_programs_with...

scolfield

unread,
Mar 22, 2011, 4:29:00 PM3/22/11
to ns-3-...@googlegroups.com, Miquel Angel

You need to insert your program in waf script.

Miquel Angel

unread,
Mar 22, 2011, 6:44:38 PM3/22/11
to ns-3-users
First a lot of thanks! I know it is very basic, but waf script is a
file called wscript? How can I insert my program in waf script? Just
cut&paste? Or better do you somewhere I can learn that, because I
didn't see it in the manual.

Thanks

On 22 mar, 21:29, scolfield <kscolfi...@gmail.com> wrote:
> You need to insert your program in waf script.
>

Trinacriax

unread,
Mar 22, 2011, 3:05:30 PM3/22/11
to ns-3-users
Hi,

what's your program name? the one with the main. Is it "escenari1.cc"?
Because it seems that the name is wrong. Just type the right name and
it'll work.

About debug:
if you use Eclipse you can debug step-by-step:
http://www.nsnam.org/wiki/index.php/HOWTO_configure_eclipse_with_ns-3

Otherwise, you can use the NS_LOG:

$ export NS_LOG="Escenari1"
$ echo $NS_LOG ///just to check it's been set properly, it
must be Escenari1
$ ./waf --run name

please, note that you may even use something like in the main of your
test:
LogComponentEnable("Escenari1", LogLevel( LOG_LEVEL_ALL | LOG_DEBUG |
LOG_LOGIC | LOG_PREFIX_FUNC | LOG_PREFIX_TIME));

Cheers,
Ax

Trinacriax

unread,
Mar 22, 2011, 10:49:22 PM3/22/11
to ns-3-users
Where is your file? Is it under scratch or example?
wscript contains configuration info read by waf script

if your file is in scratch:
$ ls scratch
escenari1.cc simple.cc

the wscript in the main dir takes care of it,
and you have to simply run, like for simple.cc in
$ ./waf --run escenari1

in case your file is in example you have to:
- put the file in a dir
$ mkdir -p examples/Escenari1
$ mv examples/escenari1.cc examples/Escenari1

- copy the wscript in examples/Escenari1,
$ cd examples
$ cp some-example/wscript Escenari1/

- edit the wscript replacing escenari1.cc with the original file name
e.g. if the content of the wscript is something like
[...]
def build(bld):
obj = bld.create_ns3_program('simple2', [''])
obj.source = 'simple2.cc'
[...]

change the original filename with yours
[...]
def build(bld):
obj = bld.create_ns3_program('escenari1', [''])
obj.source = 'escenari1.cc'
[...]

- run it
./waf --run escenari1

Finally, to enable the log
$ export NS_LOG='Escenari1'
$ ./waf --run escenari1

Miquel Angel

unread,
Mar 23, 2011, 11:53:01 AM3/23/11
to ns-3-users
Ok. I was using my program in the folder ns-3.10. I've done what you
said. I create a new folder in examples called 'Escenari1' and I copy
files wscript and waf inside. And now I need to change the wscript
because the error is:
/home/wns3/repos/ns-3-allinone/ns-3.10/examples/Escenari1/wscript:518:
error: Could not read the file '/home/wns3/repos/ns-3-allinone/ns-3.10/
examples/Escenari1/src/wscript'

I'm using linux (university) or MAC OS (at home) but I don't know
exactly what debugger I'm using, sorry.

Moreover I don't know if my file's name is ok. I use:
#include...
#include...
...
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("Escenari1");
int main (int argc, char *argv[ ]) {
...}
Is the name ns3? or Escenari1? or don't matter? I'm confused.

Now I'll change wscript like you said.
Thanks for your patience!
Miquel Angel

Trinacriax

unread,
Mar 23, 2011, 1:50:31 PM3/23/11
to ns-3-users
Just have a look at the structure of the examples directory,
as you can see, such directories have just one level:
they don't have any subdir (like your src).
Do you really need the "src" level in the directory?
Just to start, try to follow the same structure of the "examples" dir,
just follow me in this example with "simple.cc" in scratch dir,
and then change it with your file.

$ cd /home/wns3/repos/ns-3-allinone/ns-3.10/
$ mkdir -p examples/simplex
$ cp scratch/simple.cc examples/simplex
$ cp examples/waf examples/simplex
$ vim examples/simplex/wscript

-----copy THIS-----
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil;
coding: utf-8; -*-

def build(bld):
obj = bld.create_ns3_program('simple', [''])
obj.source = 'simple.cc'
-----copy THIS-----

save and exit

$ ./waf ///you should have an output like this

Waf: Entering directory `/home/wns3/repos/ns-3-allinone/ns-3.10/build'
[1299/1462] cxx: examples/simplex/simple.cc -> build/debug/examples/
simplex/simple_1.o
[1430/1462] cxx_link: build/debug/examples/simplex/simple_1.o -> build/
debug/examples/simplex/simple
Waf: Leaving directory `/home/wns3/repos/ns-3-allinone/ns-3.10/build'
'build' finished successfully (2.486s)

run it
$ ./waf --run examples/simplex/simple
Waf: Entering directory `/home/wns3/repos/ns-3-allinone/ns-3.10/build'
Waf: Leaving directory `/home/wns3/repos/ns-3-allinone/ns-3.10/build'
'build' finished successfully (0.539s)
....output....

About the debugger, do you use emacs or vi/vim for editing your files,
or you use Netbeans or Eclipse? The link I sent works for Eclipse
through gdb.

Miquel Angel

unread,
Mar 24, 2011, 11:57:50 AM3/24/11
to ns-3-users
Finally I got it! xD. I creat a new folder in examples and I copy waf
and wscript (modified like you said). Now I only have debuger errors.
With your help I resolve the problem! Thanks, a lot of thanks!

Otherwise, why do you do ./waf?

Trinacriax

unread,
Mar 24, 2011, 2:30:32 PM3/24/11
to ns-3-users
I executed ./waf just to compile all the programs

Miquel Angel

unread,
Mar 31, 2011, 6:16:03 AM3/31/11
to ns-3-users
Ok. Thanks at all for your help!
If you let me make last question: My program was written with an older
version, and I need to update to 3.10 version.
I have some errors like these:
"../examples/Escenari1/escenari1.cc:67: error: ‘class
ns3::WifiChannel’ has no member named ‘SetPropagationDelayModel’ " or
"../examples/Escenari1/escenari1.cc:71: error: ‘class
ns3::LogDistancePropagationLossModel’ has no member named
‘SetReferenceModel’"

How can I solve them? Or where can I find a solution?
Reply all
Reply to author
Forward
0 new messages