How to best add code to NS3

398 views
Skip to first unread message

steve

unread,
Mar 29, 2011, 10:25:40 AM3/29/11
to ns-3-users
I'm a newbie to NS3.

I've been following the pattern of the tutorial by adding my
simulation code to the "scratch" directory.

This worked great until I tried to create my own "Helper" class to
share between a couple of different simulation scripts I'm writing.

All the code compiles in the "scratch" directory, but "waf" is
complaining that my Helper class doesn't have a "main" function.

I tried adding my Helper class to the /src/helpers directory, but
"waf" doesn't think it needs to be built and does nothing.

Where do I need to put my helper files or how do I need to configure
NS3 so that my Helper gets built and made available to my scripts AND
doesn't get treated like a script itself?

Thanks! -SE-

Andrea Ranieri

unread,
Mar 29, 2011, 11:22:57 AM3/29/11
to ns-3-...@googlegroups.com
On Tue, Mar 29, 2011 at 16:25, steve <s.p.e...@gmail.com> wrote:

> Where do I need to put my helper files or how do I need to configure
> NS3 so that my Helper gets built and made available to my scripts AND
> doesn't get treated like a script itself?

I'm not sure that mine is the best way for adding modules to NS3, but
I chose to create my own subdirectory for my project's code. So,
suppose to have your project directory named "yourprojectdir" with
files "yourfile1.cc", "yourfile2.cc", "yourfile1.h" and "yourfile2.h",
then you have to create a "wscript" file in that directory with the
following content:

def build(bld):
module = bld.create_ns3_module('yourprojectdir', ['simulator', 'common'])
module.source = [
'yourfile1.cc',
'yourfile2.cc',
]

headers = bld.new_task_gen('ns3header')
headers.module = 'yourprojectdir'
headers.source = [
'yourfile1.h',
'yourfile2.h',
]

This makes your project a module of NS3, embedding and sharing all
your code inside libns3.so. I repeat, I'm not sure this is the best
way to do it, but it works well for me. Hope this helps.

Regards
Andrea

maxmalkav

unread,
Mar 29, 2011, 1:39:52 PM3/29/11
to ns-3-...@googlegroups.com, Andrea Ranieri
Hi Andrea

The ns-3 wiki suggest the same thing as you, so I think you are right:


At least, I'm doing stuff that way :)

Regards



2011/3/29 Andrea Ranieri <andr...@gmail.com>

--
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.




--
JuanLu
Reply all
Reply to author
Forward
0 new messages