Source

imalse / simulate.py

Full commit
#!/usr/bin/env python
"""This file is the starting point for simulation modes."""

import sys
import argparse

from experiments import experiment_factory
from util.util import get_available_experiments

def parse_arguments():
    """Parse the command line arguments and specify the help strings."""
    parser.add_argument('-e', '--experiment', default='topo_exp',
        help='specify the experiment. Available experiments are [%s]'\
        % (" |").join(exper_options))
    parser.add_argument('--mode', default='sim',
        help="specify the mode, can be ['netns3' | 'sim'], default is 'sim'. "
        )
    parser.add_argument('--ehelp', action='store_true',
        help="print the help of a experiment"
        )
    
    # Print Help when there is no argument
    if len(sys.argv) == 1:
        print '----------------Experment Selection Arguments------------------'
        parser.print_help()
        print '----------------Exeriment Options------------------------------'
        for exp in exper_options:
            for mode in ['netns3','sim']:
                print '+++++++++Experiment:[%s] Mode:[%s]+++++++++++++++++++++\
                    ++' % (exp, mode)
                exper = experiment_factory(exp, mode)                
                exper.print_help()
    
        sys.exit(1)
        
    return parser.parse_known_args()

exper_options = get_available_experiments()
parser = argparse.ArgumentParser(description='imalse')

args, exper_args = parse_arguments() 
experiment = experiment_factory(args.experiment, args.mode)

if experiment == None:
    print "Experiment " + args.experiment + " does not exist."
    sys.exit()

if args.ehelp:
    print '+++++++++Experiment:[%s] Mode:[%s]+++++++++++++++++++++++'%(args.experiment, args.mode)
    experiment.print_help()
    sys.exit(1)

experiment.main(exper_args)