def main():
    ''' Main routine when running from command-line.
    '''
    usagestr = "usage: %prog [-h] [options] [args]"
    parser = optparse.OptionParser(usage = usagestr)
    parser.set_defaults(numnodes = 10, delay = 3, duration = 10, rate = 512,
                        verbose = False,
                        numping = 50, numiperf = 1, nummgen = 1)

    parser.add_option("-d", "--delay", dest = "delay", type = float,
                      help = "wait time before testing")
    parser.add_option("-l", "--logfile", dest = "logfile", type = str,
                      help = "log detailed output to the specified file")
    parser.add_option("-n", "--numnodes", dest = "numnodes", type = int,
                      help = "number of nodes")
    parser.add_option("-r", "--rate", dest = "rate", type = float,
                      help = "kbps rate to use for MGEN CPU tests")
    parser.add_option("--numping", dest = "numping", type = int,
                      help = "number of ping latency test runs")
    parser.add_option("--numiperf", dest = "numiperf", type = int,
                      help = "number of iperf throughput test runs")
    parser.add_option("--nummgen", dest = "nummgen", type = int,
                      help = "number of MGEN CPU tests runs")
    parser.add_option("-t", "--time", dest = "duration", type = int,
                      help = "duration in seconds of throughput and CPU tests")
    parser.add_option("-v", "--verbose", dest = "verbose",
                      action = "store_true", help = "be more verbose")

    def usage(msg = None, err = 0):
        sys.stdout.write("\n")
        if msg:
            sys.stdout.write(msg + "\n\n")
        parser.print_help()
        sys.exit(err)

    # parse command line opt
    (opt, args) = parser.parse_args()

    if opt.numnodes < 2:
        usage("invalid numnodes: %s" % opt.numnodes)
    if opt.delay < 0.0:
        usage("invalid delay: %s" % opt.delay)
    if opt.rate < 0.0:
        usage("invalid rate: %s" % opt.rate)

    for a in args:
        sys.stderr.write("ignoring command line argument: '%s'\n" % a)

    results = {}
    starttime = datetime.datetime.now()
    exp = Experiment(opt = opt, start=starttime)
    exp.info("Starting wlanemanetests.py tests %s" % starttime.ctime())

    # system sanity checks here
    emanever, emaneverstr = Emane.detectversionfromcmd()
    if opt.verbose:
        exp.info("Detected EMANE version %s" % (emaneverstr,))

    # bridged
    exp.info("setting up bridged tests 1/2 no link effects")
    exp.info("creating topology: numnodes = %s" % \
                (opt.numnodes, ))
    exp.createbridgedsession(numnodes=opt.numnodes, verbose=opt.verbose)
    exp.setnodes()
    exp.info("waiting %s sec (node/route bring-up)" % opt.delay)
    time.sleep(opt.delay)
    results['0 bridged'] = exp.runalltests("bridged")
    exp.info("done; elapsed time: %s" % (datetime.datetime.now() - exp.start))

    # bridged with netem
    exp.info("setting up bridged tests 2/2 with netem")
    exp.setneteffects(bw=54000000, delay=0)
    exp.info("waiting %s sec (queue bring-up)" % opt.delay)
    results['1.0 netem'] = exp.runalltests("netem")
    exp.info("shutting down bridged session")

    # bridged with netem (1 Mbps,200ms)
    exp.info("setting up bridged tests 3/2 with netem")
    exp.setneteffects(bw=1000000, delay=20000)
    exp.info("waiting %s sec (queue bring-up)" % opt.delay)
    results['1.2 netem_1M'] = exp.runalltests("netem_1M")
    exp.info("shutting down bridged session")

    # bridged with netem (54 kbps,500ms)
    exp.info("setting up bridged tests 3/2 with netem")
    exp.setneteffects(bw=54000, delay=100000)
    exp.info("waiting %s sec (queue bring-up)" % opt.delay)
    results['1.4 netem_54K'] = exp.runalltests("netem_54K")
    exp.info("shutting down bridged session")
    exp.reset()

    # EMANE bypass model
    exp.info("setting up EMANE tests 1/2 with bypass model")
    exp.createemanesession(numnodes=opt.numnodes, verbose=opt.verbose,
                           cls=EmaneBypassModel, values=None)
    exp.setnodes()
    exp.info("waiting %s sec (node/route bring-up)" % opt.delay)
    time.sleep(opt.delay)
    results['2.0 bypass'] = exp.runalltests("bypass")
    exp.info("shutting down bypass session")
    exp.reset()
    
    exp.info("waiting %s sec (between EMANE tests)" % opt.delay)
    time.sleep(opt.delay)

    # EMANE RF-PIPE model: no restrictions (max datarate)
    exp.info("setting up EMANE tests 2/4 with RF-PIPE model")
    rfpipevals = list(EmaneRfPipeModel.getdefaultvalues())
    rfpnames = EmaneRfPipeModel.getnames()
    rfpipevals[ rfpnames.index('datarate') ] = '4294967295' # max value
    if emanever < Emane.EMANE091:
        rfpipevals[ rfpnames.index('pathlossmode') ] = '2ray'
        rfpipevals[ rfpnames.index('defaultconnectivitymode') ] = '1'
    else:
        rfpipevals[ rfpnames.index('propagationmodel') ] = '2ray'
    exp.createemanesession(numnodes=opt.numnodes, verbose=opt.verbose,
                          cls=EmaneRfPipeModel, values=rfpipevals)
    exp.setnodes()
    exp.info("waiting %s sec (node/route bring-up)" % opt.delay)
    time.sleep(opt.delay)
    results['3.0 rfpipe'] = exp.runalltests("rfpipe")
    exp.info("shutting down RF-PIPE session")
    exp.reset()

    # EMANE RF-PIPE model: 54M datarate
    exp.info("setting up EMANE tests 3/4 with RF-PIPE model 54M")
    rfpipevals = list(EmaneRfPipeModel.getdefaultvalues())
    rfpnames = EmaneRfPipeModel.getnames()
    rfpipevals[ rfpnames.index('datarate') ] = '54000000'
    # TX delay != propagation delay
    #rfpipevals[ rfpnames.index('delay') ] = '5000'
    if emanever < Emane.EMANE091:
        rfpipevals[ rfpnames.index('pathlossmode') ] = '2ray'
        rfpipevals[ rfpnames.index('defaultconnectivitymode') ] = '1'
    else:
        rfpipevals[ rfpnames.index('propagationmodel') ] = '2ray'
    exp.createemanesession(numnodes=opt.numnodes, verbose=opt.verbose,
                          cls=EmaneRfPipeModel, values=rfpipevals)
    exp.setnodes()
    exp.info("waiting %s sec (node/route bring-up)" % opt.delay)
    time.sleep(opt.delay)
    results['4.0 rfpipe54m'] = exp.runalltests("rfpipe54m")
    exp.info("shutting down RF-PIPE session")
    exp.reset()

    # EMANE RF-PIPE model:  54K datarate
    exp.info("setting up EMANE tests 4/4 with RF-PIPE model pathloss")
    rfpipevals = list(EmaneRfPipeModel.getdefaultvalues())
    rfpnames = EmaneRfPipeModel.getnames()
    rfpipevals[ rfpnames.index('datarate') ] = '54000'
    if emanever < Emane.EMANE091:
        rfpipevals[ rfpnames.index('pathlossmode') ] = 'pathloss'
        rfpipevals[ rfpnames.index('defaultconnectivitymode') ] = '0'
    else:
        rfpipevals[ rfpnames.index('propagationmodel') ] = 'precomputed'
    exp.createemanesession(numnodes=opt.numnodes, verbose=opt.verbose,
                          cls=EmaneRfPipeModel, values=rfpipevals)
    exp.setnodes()
    exp.info("waiting %s sec (node/route bring-up)" % opt.delay)
    time.sleep(opt.delay)
    exp.info("sending pathloss events to govern connectivity")
    exp.setpathloss(opt.numnodes)
    results['5.0 pathloss'] = exp.runalltests("pathloss")
    exp.info("shutting down RF-PIPE session")
    exp.reset()

    # EMANE RF-PIPE model (512K, 200ms)
    exp.info("setting up EMANE tests 4/4 with RF-PIPE model pathloss")
    rfpipevals = list(EmaneRfPipeModel.getdefaultvalues())
    rfpnames = EmaneRfPipeModel.getnames()
    rfpipevals[ rfpnames.index('datarate') ] = '512000'
    rfpipevals[ rfpnames.index('delay') ] = '200'
    rfpipevals[ rfpnames.index('pathlossmode') ] = 'pathloss'
    rfpipevals[ rfpnames.index('defaultconnectivitymode') ] = '0'
    exp.createemanesession(numnodes=opt.numnodes, verbose=opt.verbose,
                          cls=EmaneRfPipeModel, values=rfpipevals)
    exp.setnodes()
    exp.info("waiting %s sec (node/route bring-up)" % opt.delay)
    time.sleep(opt.delay)
    exp.info("sending pathloss events to govern connectivity")
    exp.setpathloss(opt.numnodes)
    results['5.1 pathloss'] = exp.runalltests("pathloss")
    exp.info("shutting down RF-PIPE session")
    exp.reset()
  
    # summary of results in CSV format
    exp.info("----- summary of results (%s nodes, rate=%s, duration=%s) -----" \
             % (opt.numnodes, opt.rate, opt.duration))
    exp.info("netname:latency,mdev,throughput,cpu,loss")

    for test in sorted(results.keys()):
        (latency, mdev, throughput, cpu, loss) = results[test]
        exp.info("%s:%.03f,%.03f,%d,%.02f,%.02f" % \
                 (test, latency, mdev, throughput, cpu,loss))

    exp.logend()
    return exp
dataset/ETHPy150Open coreemu/core/daemon/examples/netns/wlanemanetests.py/main/original