NS3 allows your simulation script to run in the desired location

Source: Internet
Author: User

Requirements:

Simulation scripts are generally placed under scratch, but with the increase of simulation programs, this directory will become more and more bloated, so the idea of creating sub-directories is generated. Can we create sub-directories? Where to create a subdirectory is more appropriate?

Solution:

Directly read/ns3.20/wscript. in this folder, I understand W: waf. Of course, script means the simulation script that the WAF compiler will call. One of the snippets is:

def add_scratch_programs(bld):    all_modules = [mod[len("ns3-"):] for mod in bld.env['NS3_ENABLED_MODULES']]    for filename in os.listdir("scratch"):        if filename.startswith('.') or filename == 'CVS':    continue        if os.path.isdir(os.path.join("scratch", filename)):            obj = bld.create_ns3_program(filename, all_modules)            obj.path = obj.path.find_dir('scratch').find_dir(filename)            obj.source = obj.path.ant_glob('*.cc')            obj.target = filename            obj.name = obj.target            obj.install_path = None        elif filename.endswith(".cc"):            name = filename[:-len(".cc")]            obj = bld.create_ns3_program(name, all_modules)            obj.path = obj.path.find_dir('scratch')            obj.source = filename            obj.target = name            obj.name = obj.target            obj.install_path = None
Program notes:

It is easy to see that this function is used to add scratch to the compiled directory. First, you can determine whether the files under scratch are folders or directories. create the NS3 program in the CC file. If it is a folder, directly create the NS3 program in the folder name, therefore, the program name in this subdirectory should be the same as that in the subfolders. the design here is mainly. CC and. H files are put together to reduce space.


Obviously, if I have a lot of. CC simulation scripts, it is not very suitable to put them here, where should I put them? Yes, it is the examples folder. Please refer to the following program:

def add_examples_programs(bld):    env = bld.env    if env['ENABLE_EXAMPLES']:        for dir in os.listdir('examples'):            if dir.startswith('.') or dir == 'CVS':                continue            if os.path.isdir(os.path.join('examples', dir)):                bld.recurse(os.path.join('examples', dir))
Program notes:

This is to add the examples folder. If the files in this directory are folders, you can directly jump to this subdirectory for processing. Then you can look at wscript in its subdirectory:

def build(bld):    obj = bld.create_ns3_program('energy-model-example', ['core', 'mobility', 'wifi', 'energy', 'internet'])    obj.source = 'energy-model-example.cc'
Create a simulation program for ns3.


We can create a directory and write a wscript. Of course, you can also modify wscript to make compilation more free.


Additional, my experience of modifying simulation scripts:

Once I ran the program, I forgot to add the scratch directory. For example, I ran first directly, but the running program did not have the desired result. The result showed that the program was running under the subdirectory examples. so how does WAF select a file with the same name? Check the wscript script:

Def build (BLD ):

In the above function, there are two calls:

add_examples_programs(bld)add_scratch_programs(bld)
We found that the program in the examples folder is placed in the front, and tried to change the order. If you run the program again, the scratch program is given priority.

Refer:

My questions on this issue at the Google NS3 Forum

WAF learning reference book



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.