Source

imalse / emulate.py

#!/usr/bin/env python
# !/usr/bin/env pypy

# node_type = 'Server'
import argparse
import sys, os
import core.real
from util import *
# exec( 'import scenario.%s as scen'%(scenario) )
# def load_module(scenario):
#     __import__('scenario.%s'%(scenario))
#     scen = sys.modules['scenario.%s'%(scenario)]
#     return scen


def run_server(scen):
    node = core.real.PhyNode()
    # cmd = scen.ServerCMD(scen.server_fsm)
    cmd = scen.ServerCMD()
    cmd.install(node)
    node.start()


def run_client(scen):
    node = core.real.PhyNode()
    # ccmd = scen.ClientCMD(scen.client_fsm)
    ccmd = scen.ClientCMD()
    ccmd.install(node)
    node.start()

def run_botmaster(scen):
    node = core.real.PhyNode()
    # ccmd = scen.BotMaster(scen.botmaster_fsm)
    ccmd = scen.BotMaster()
    ccmd.install(node)
    node.start()

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

parser = argparse.ArgumentParser(description='imalse')
# scenario_ops = [f_name for f_name in os.listdir('./scenario/') if not f_name.lower().endswith('py')]
scenario_ops = get_scenario_option()
parser.add_argument('-s', '--scenario', default='None',
        help='specify the scenario you want to execute. Scenearios availiable are: %s'%(scenario_ops )
        )

parser.add_argument('-r', '--role', default='None',
        help='specify the role you want to emulate, 1.[server], 2.[client], 3.[botmaster]'
        )
args = parser.parse_args()
if args.scenario not in scenario_ops:
    parser.print_help()
    exit()
scen = load_module(args.scenario)
run_map[args.role](scen)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.