Source

imalse / emulate.py

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

import argparse

from core.real.node import PhysicalNode
from util.util import get_availabe_scenarios, load_scenario

def run_server(scenario):
    """Emulate a server with a scenario specific command meta description."""
    node = PhysicalNode()    
    cmd = scenario.ServerCMD()
    cmd.install(node)
    node.start()

def run_client(scenario):
    """Emulate a client with a scenario specific command meta description."""
    node = PhysicalNode()    
    ccmd = scenario.ClientCMD()
    ccmd.install(node)
    node.start()

def run_botmaster(scenario):
    """Emulate a BotMaster with a scenario specific command meta description."""
    node = PhysicalNode()        
    ccmd = scenario.BotMaster()    
    ccmd.install(node)
    node.start()

RUN_MAP = {
        'server' : run_server,
        'client' : run_client,
        'botmaster' : run_botmaster,
        }

def parse_arguments():    
    """Parse the command line arguments and specify the help strings."""
    parser.add_argument('-s', '--scenario', default='None',
            help='specify the scenario you want to execute. Scenarios \
                available are: %s'%(available_scenarios )
            )
    parser.add_argument('-r', '--role', default='None',
            help='specify the role you want to emulate, 1.[server],\
             2.[client], 3.[botmaster]'
            )
    return parser.parse_args()

available_scenarios = get_availabe_scenarios()

parser = argparse.ArgumentParser(description='imalse')
args = parse_arguments()

if args.scenario not in available_scenarios:
    parser.print_help()
    exit()

scen = load_scenario(args.scenario)

if scen == None:
    print "Scenario could not be loaded."
    exit()

RUN_MAP[args.role](scen)