示例#1
0
def main():
    addservice(JoshService)
    
    session = pycore.Session(persistent=True)      
    
    test(2,100,session)
    
    # now we launch cored.py services so GUI can connect to this script
    print "launching cored services"
    # the following lines are from cored.py cored()
    cfg, args = cored.getMergedConfig("%s/core.conf" % CORE_CONF_DIR)
    cored.banner()
    server = cored.CoreServer(("localhost", coreapi.CORE_API_PORT),
                              cored.CoreRequestHandler, cfg)
    print "adding session %s to cored.server" % session.sessionid
    server.addsession(session)
    print "running cored server - you may now connect the GUI"
    try:
        server.serve_forever()
    except KeyboardInterrupt:
        pass    
示例#2
0
def main():
    addservice(JoshService)
    
    session = pycore.Session(persistent=True)      
    
    test(2,100,session)
    
    # now we launch cored.py services so GUI can connect to this script
    print "launching cored services"
    # the following lines are from cored.py cored()
    cfg, args = cored.getMergedConfig("%s/core.conf" % CORE_CONF_DIR)
    cored.banner()
    server = cored.CoreServer(("localhost", coreapi.CORE_API_PORT),
                              cored.CoreRequestHandler, cfg)
    print "adding session %s to cored.server" % session.sessionid
    server.addsession(session)
    print "running cored server - you may now connect the GUI"
    try:
        server.serve_forever()
    except KeyboardInterrupt:
        pass    
示例#3
0
def main():
    usagestr = "usage: %prog [-h] [options] [args]"
    parser = optparse.OptionParser(usage = usagestr)
    parser.set_defaults(numnodes = 5)

    parser.add_option("-n", "--numnodes", dest = "numnodes", type = int,
                      help = "number of nodes")

    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 options
    (options, args) = parser.parse_args()

    if options.numnodes < 1:
        usage("invalid number of nodes: %s" % options.numnodes)

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

    start = datetime.datetime.now()

    prefix = ipaddr.IPv4Prefix("10.83.0.0/16")
    session = pycore.Session(persistent=True)
    wlan = session.addobj(cls = pycore.nodes.WlanNode, name = "wlan")
    values = BasicRangeModel.getdefaultvalues()
    wlan.setmodel(BasicRangeModel, values)
    wlan.setposition(x=80,y=50)
    print "creating %d nodes with addresses from %s" % \
          (options.numnodes, prefix)
    model = "PC"
    for i in xrange(1, options.numnodes + 1):
        n = session.addobj(cls = pycore.nodes.CoreNode, name = "n%d" % i,
                             objid=i)
        n.type = model
        n.newnetif(wlan, ["%s/%s" % (prefix.addr(i), prefix.prefixlen)])
        n.cmd(["sysctl", "net.ipv4.icmp_echo_ignore_broadcasts=0"])
        n.setposition(x=150*i,y=150)
        session.services.addservicestonode(n, model, "DefaultRoute", False)
        session.services.addservicestonode(n, "", "MyHaggleService", True)
        session.services.bootnodeservices(n)        
        nodes.append(n)

    # start a shell on node 1
    nodes[1].term("bash")

    print "elapsed time: %s" % (datetime.datetime.now() - start)

    t = threading.Thread(target = wandering_node, args=(nodes[1],))
    t.start()

    # now we launch cored.py services so GUI can connect to this script
    print "launching cored services"
    # the following lines are from cored.py cored()
    cfg, args = cored.getMergedConfig("%s/core.conf" % CORE_CONF_DIR)
    cored.banner()
    server = cored.CoreServer(("localhost", coreapi.CORE_API_PORT),
                              cored.CoreRequestHandler, cfg)
    print "adding session %s to cored.server" % session.sessionid
    server.addsession(session)
    print "running cored server - you may now connect the GUI"
    try:
        server.serve_forever()
    except KeyboardInterrupt:
        pass
示例#4
0
def main():
    usagestr = "usage: %prog [-h] [options] [args]"
    parser = optparse.OptionParser(usage = usagestr)
    parser.set_defaults(numnodes = 5)

    parser.add_option("-n", "--numnodes", dest = "numnodes", type = int,
                      help = "number of nodes")

    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 options
    (options, args) = parser.parse_args()

    if options.numnodes < 1:
        usage("invalid number of nodes: %s" % options.numnodes)

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

    start = datetime.datetime.now()

    # IP subnet
    prefix = ipaddr.IPv4Prefix("10.83.0.0/16")
    session = pycore.Session(persistent=True)
    # emulated Ethernet switch
    switch = session.addobj(cls = pycore.nodes.SwitchNode, name = "switch")
    switch.setposition(x=80,y=50)
    print "creating %d nodes with addresses from %s" % \
          (options.numnodes, prefix)
    for i in xrange(1, options.numnodes + 1):
        tmp = session.addobj(cls = pycore.nodes.CoreNode, name = "n%d" % i,
                             objid=i)
        tmp.newnetif(switch, ["%s/%s" % (prefix.addr(i), prefix.prefixlen)])
        tmp.cmd(["sysctl", "net.ipv4.icmp_echo_ignore_broadcasts=0"])
        tmp.setposition(x=150*i,y=150)
        tmp.verbose = True
        print "node %s nodedir=%s" % (tmp.name, tmp.nodedir)
        session.services.addservicestonode(tmp, "", "MyService", True)
        session.services.bootnodeservices(tmp)
        n.append(tmp)

    # start a shell on node 1
    n[1].term("bash")

    print "elapsed time: %s" % (datetime.datetime.now() - start)

    # now we launch cored.py services so GUI can connect to this script
    print "launching cored services"
    # the following lines are from cored.py cored()
    cfg, args = cored.getMergedConfig("%s/core.conf" % CORE_CONF_DIR)
    cored.banner()
    server = cored.CoreServer(("localhost", coreapi.CORE_API_PORT),
                              cored.CoreRequestHandler, cfg)
    print "adding session %s to cored.server" % session.sessionid
    server.addsession(session)
    print "running cored server - you may now connect the GUI"
    try:
        server.serve_forever()
    except KeyboardInterrupt:
        pass