Beispiel #1
0
def main():
    """
    Main function, called when run as an application.
    """
    global server_address

    # check the version
    if (sys.version_info[:2] != (2, 5)):
        sys.stderr.write("Python 2.5 only\n")
        sys.exit(1)

    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)
    parser.add_argument(
        "host",
        nargs='?',
        help="address of host (default %r)" % (SERVER_HOST, ),
        default=SERVER_HOST,
    )
    parser.add_argument(
        "port",
        nargs='?',
        type=int,
        help="server port (default %r)" % (SERVER_PORT, ),
        default=SERVER_PORT,
    )
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # extract the server address and port
    host = args.host
    port = args.port
    server_address = (host, port)
    if _debug: _log.debug("    - server_address: %r", server_address)

    # build the stack
    this_console = ConsoleClient()
    if _debug: _log.debug("    - this_console: %r", this_console)

    this_middle_man = MiddleMan()
    if _debug: _log.debug("    - this_middle_man: %r", this_middle_man)

    this_director = TCPClientDirector()
    if _debug: _log.debug("    - this_director: %r", this_director)

    bind(this_console, this_middle_man, this_director)
    bind(MiddleManASE(), this_director)

    # create a task manager for scheduled functions
    task_manager = TaskManager()
    if _debug: _log.debug("    - task_manager: %r", task_manager)

    # don't wait to connect
    this_director.connect(server_address)

    if _debug: _log.debug("running")

    run()
Beispiel #2
0
def main():
    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)

    # add an argument for seconds per dog
    parser.add_argument(
        'seconds',
        metavar='N',
        type=int,
        nargs='+',
        help='number of seconds for each dog',
    )

    # now parse the arguments
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # make some dogs
    for i, sec in enumerate(args.seconds):
        dog = PrairieDog(i, sec * 1000)
        if _debug: _log.debug("    - dog: %r", dog)

    _log.debug("running")

    run()

    _log.debug("fini")
Beispiel #3
0
def main():
    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)
    parser.add_argument(
        "--host", type=str,
        help="address of host (default {!r})".format(SERVER_HOST),
        default=SERVER_HOST,
        )
    parser.add_argument(
        "--port", type=int,
        help="server port (default {!r})".format(SERVER_PORT),
        default=SERVER_PORT,
        )
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # local IO functions
    bind(SimpleServer(), ModbusServer(port=args.port))

    _log.debug("running")

    run()

    _log.debug("fini")
Beispiel #4
0
def main():
    # build a parser for the command line arguments
    parser = ArgumentParser(description=__doc__)

    # sample additional argument to change the prompt
    parser.add_argument(
        "--prompt", type=str,
        default="> ",
        help="change the prompt",
        )

    # parse the command line arguments
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # make a console
    this_console = ConsoleCmdTemplate(prompt=args.prompt)
    if _debug: _log.debug("    - this_console: %r", this_console)

    # enable sleeping will help with threads
    enable_sleeping()

    _log.debug("running")

    run()

    _log.debug("fini")
Beispiel #5
0
def main():
    global args

    # build a parser for the command line arguments
    parser = ArgumentParser(description=__doc__)

    # sample additional argument to change the prompt
    parser.add_argument(
        "--prompt", type=str,
        default="> ",
        help="change the prompt",
        )

    # accept everything else
    parser.add_argument('args', nargs=argparse.REMAINDER)

    # parse the command line arguments
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # make a console
    this_console = Shell()
    if _debug: _log.debug("    - this_console: %r", this_console)

    # enable sleeping will help with threads
    enable_sleeping()

    _log.debug("running")

    run()

    _log.debug("fini")
Beispiel #6
0
def main():
    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)

    # add an argument for seconds per dog
    parser.add_argument('seconds', metavar='N', type=int, nargs='+',
          help='number of seconds for each dog',
          )

    # now parse the arguments
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # make some dogs
    for i, sec in enumerate(args.seconds):
        dog = PrairieDog(i, sec * 1000)
        if _debug: _log.debug("    - dog: %r", dog)

    _log.debug("running")

    run()

    _log.debug("fini")
Beispiel #7
0
def main():
    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)

    # now parse the arguments
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # make a controller
    this_controller = SieveClientController()
    if _debug: _log.debug("    - this_controller: %r", this_controller)

    # local IO functions
    bind(this_controller, ModbusClient())

    # if this is being run, then a console is handy
    this_console = ConsoleClient(this_controller)
    if _debug: _log.debug("    - this_console: %r", this_console)

    _log.debug("running")

    run()

    _log.debug("fini")
Beispiel #8
0
def main():
    # parse the command line arguments
    parser = ArgumentParser(usage=__doc__)
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    address = Address("192.168.0.1/24")
    if _debug: _log.debug("    - local_address: %r", address)

    # make a network
    network = IPNetwork()

    console = ConsoleClient()
    middle_man = MiddleMan()

    fauxmux = FauxMux(address, network)
    bind(console, middle_man, fauxmux)

    # add some more debugging nodes
    for i in range(2, 4):
        debug_address = "192.168.0.{}/24".format(i)

        debug_debug = Debug(debug_address)
        debug_fauxmux = FauxMux(Address(debug_address), network)

        bind(debug_debug, debug_fauxmux)

    _log.debug("running")

    run()

    _log.debug("fini")
Beispiel #9
0
def main():
    # parse the command line arguments
    parser = ArgumentParser(usage=__doc__)
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # make a network
    network = IPNetwork()

    console = ConsoleClient()
    middle_man = MiddleMan()

    bip = BIPSimple()
    annexj = AnnexJCodec()
    mux = FauxMultiplexer("192.168.0.1/24", network)
    bind(console, middle_man, bip, annexj, mux)

    # add some more debugging nodes
    for i in range(2, 4):
        debug_address = "192.168.0.{}/24".format(i)

        debug_debug = Debug(debug_address)
        debug_bip = BIPSimple()
        debug_annexj = AnnexJCodec()
        debug_mux = FauxMultiplexer(debug_address, network)

        bind(debug_debug, debug_bip, debug_annexj, debug_mux)

    _log.debug("running")

    run()

    _log.debug("fini")
Beispiel #10
0
def main():
    global this_console

    # build a parser for the command line arguments
    parser = ArgumentParser(description=__doc__)

    # sample additional argument to change the prompt
    parser.add_argument(
        "--prompt",
        type=str,
        default="> ",
        help="change the prompt",
    )

    # parse the command line arguments
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # make a console
    this_console = ConsoleCmdTemplate(prompt=args.prompt)

    _log.debug("running")

    run()
Beispiel #11
0
def main():
    """
    Main function, called when run as an application.
    """
    global server_address

    # check the version
    if (sys.version_info[:2] != (2, 5)):
        sys.stderr.write("Python 2.5 only\n")
        sys.exit(1)

    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)
    parser.add_argument(
        "host", nargs='?',
        help="address of host (default %r)" % (SERVER_HOST,),
        default=SERVER_HOST,
        )
    parser.add_argument(
        "port", nargs='?', type=int,
        help="server port (default %r)" % (SERVER_PORT,),
        default=SERVER_PORT,
        )
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # extract the server address and port
    host = args.host
    port = args.port
    server_address = (host, port)
    if _debug: _log.debug("    - server_address: %r", server_address)

    # build the stack
    this_console = ConsoleClient()
    if _debug: _log.debug("    - this_console: %r", this_console)

    this_middle_man = MiddleMan()
    if _debug: _log.debug("    - this_middle_man: %r", this_middle_man)

    this_director = TCPClientDirector()
    if _debug: _log.debug("    - this_director: %r", this_director)

    bind(this_console, this_middle_man, this_director)
    bind(MiddleManASE(), this_director)

    # create a task manager for scheduled functions
    task_manager = TaskManager()
    if _debug: _log.debug("    - task_manager: %r", task_manager)

    # don't wait to connect
    this_director.connect(server_address)

    if _debug: _log.debug("running")

    run()
Beispiel #12
0
def main():
    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)

    # add an argument for interval
    parser.add_argument(
        'localaddr',
        type=str,
        help='local address of the BBMD',
    )

    # add an argument for interval
    parser.add_argument(
        'bdtentry',
        type=str,
        nargs='*',
        help='list of addresses of peers',
    )

    # now parse the arguments
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    local_address = Address(args.localaddr)
    if _debug: _log.debug("    - local_address: %r", local_address)

    # create a null client that will accept, but do nothing with upstream
    # packets from the BBMD
    null_client = NullClient()
    if _debug: _log.debug("    - null_client: %r", null_client)

    # create a BBMD, bound to the Annex J server on a UDP multiplexer
    bbmd = BIPBBMD(local_address)
    annexj = AnnexJCodec()
    multiplexer = UDPMultiplexer(local_address)

    # bind the layers together
    bind(null_client, bbmd, annexj, multiplexer.annexJ)

    # loop through the rest of the addresses
    for bdtentry in args.bdtentry:
        if _debug: _log.debug("    - bdtentry: %r", bdtentry)

        bdt_address = Address(bdtentry)
        bbmd.add_peer(bdt_address)

    if _debug: _log.debug("    - bbmd: %r", bbmd)

    _log.debug("running")

    run()

    _log.debug("fini")
Beispiel #13
0
def main():
    global args, this_device, this_application

    # build a parser, add some options
    parser = ArgumentParser(description=__doc__)
    parser.add_argument(
        '--lan',
        type=str,
        default=default_lan_name,
        help='lan name',
    )
    parser.add_argument(
        '--host',
        type=str,
        default=default_broker_host,
        help='broker host address',
    )
    parser.add_argument(
        '--port',
        type=int,
        default=default_broker_port,
        help='broker port',
    )
    parser.add_argument(
        '--keepalive',
        type=int,
        default=default_broker_keepalive,
        help=
        "maximum period in seconds allowed between communications with the broker",
    )

    # parse the command line arguments
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # make a simple application
    this_application = MQTTSniffer(args.lan, args.host, args.port,
                                   args.keepalive)

    # enable sleeping will help with threads
    enable_sleeping()

    # start up the client
    this_application.startup()

    _log.debug("running")

    run()

    # shutdown the client
    this_application.shutdown()

    _log.debug("fini")
Beispiel #14
0
def main():
    """
    Main function, called when run as an application.
    """
    global server_address

    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)
    parser.add_argument(
        "host",
        nargs='?',
        help="address of host",
        default=default_server_host,
    )
    parser.add_argument(
        "port",
        nargs='?',
        type=int,
        help="server port",
        default=default_server_port,
    )
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # extract the server address and port
    host = args.host
    port = args.port
    server_address = (host, port)
    if _debug: _log.debug("    - server_address: %r", server_address)

    # build the stack
    this_console = ConsoleClient()
    if _debug: _log.debug("    - this_console: %r", this_console)

    this_middle_man = MiddleMan()
    if _debug: _log.debug("    - this_middle_man: %r", this_middle_man)

    this_director = TCPClientDirector()
    if _debug: _log.debug("    - this_director: %r", this_director)

    bind(this_console, this_middle_man, this_director)
    bind(MiddleManASE(), this_director)

    # create a task manager for scheduled functions
    task_manager = TaskManager()
    if _debug: _log.debug("    - task_manager: %r", task_manager)

    # don't wait to connect
    this_director.connect(server_address)

    if _debug: _log.debug("running")

    run()
Beispiel #15
0
def main():
    """
    Main function, called when run as an application.
    """
    global server_address

    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)
    parser.add_argument(
        "host", nargs='?',
        help="address of host",
        default=default_server_host,
        )
    parser.add_argument(
        "port", nargs='?', type=int,
        help="server port",
        default=default_server_port,
        )
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # extract the server address and port
    host = args.host
    port = args.port
    server_address = (host, port)
    if _debug: _log.debug("    - server_address: %r", server_address)

    # build the stack
    this_console = ConsoleClient()
    if _debug: _log.debug("    - this_console: %r", this_console)

    this_middle_man = MiddleMan()
    if _debug: _log.debug("    - this_middle_man: %r", this_middle_man)

    this_director = TCPClientDirector()
    if _debug: _log.debug("    - this_director: %r", this_director)

    bind(this_console, this_middle_man, this_director)
    bind(MiddleManASE(), this_director)

    # create a task manager for scheduled functions
    task_manager = TaskManager()
    if _debug: _log.debug("    - task_manager: %r", task_manager)

    # don't wait to connect
    this_director.connect(server_address)

    if _debug: _log.debug("running")

    run()
Beispiel #16
0
def main():
    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)

    # add an argument for interval
    parser.add_argument(
        'addr1',
        type=str,
        help='address of first network',
    )

    # add an argument for interval
    parser.add_argument(
        'net1',
        type=int,
        help='network number of first network',
    )

    # add an argument for interval
    parser.add_argument(
        'addr2',
        type=str,
        help='address of second network',
    )

    # add an argument for interval
    parser.add_argument(
        'net2',
        type=int,
        help='network number of second network',
    )

    # now parse the arguments
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # create the router
    router = IP2IPRouter(Address(args.addr1), args.net1, Address(args.addr2),
                         args.net2)
    if _debug: _log.debug("    - router: %r", router)

    # send network topology
    deferred(router.nse.i_am_router_to_network)

    _log.debug("running")

    run()

    _log.debug("fini")
Beispiel #17
0
def main():
    # check the version
    if (sys.version_info[:2] != (2, 5)):
        sys.stderr.write("Python 2.5 only\n")
        sys.exit(1)

    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)
    parser.add_argument(
        "host",
        nargs='?',
        help="listening address of server or 'any' (default %r)" %
        (SERVER_HOST, ),
        default=SERVER_HOST,
    )
    parser.add_argument(
        "port",
        nargs='?',
        type=int,
        help="server port (default %r)" % (SERVER_PORT, ),
        default=SERVER_PORT,
    )
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # extract the server address and port
    host = args.host
    if host == "any":
        host = ''
    server_address = (host, args.port)
    if _debug: _log.debug("    - server_address: %r", server_address)

    # create a director listening to the address
    this_director = TCPServerDirector(server_address)
    if _debug: _log.debug("    - this_director: %r", this_director)

    # create an echo
    echo_master = EchoMaster()
    if _debug: _log.debug("    - echo_master: %r", echo_master)

    # bind everything together
    bind(echo_master, this_director)
    bind(MiddleManASE(), this_director)

    _log.debug("running")

    run()

    _log.debug("fini")
Beispiel #18
0
def main():
    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)

    # add an argument for interval
    parser.add_argument('localaddr', type=str,
          help='local address of the BBMD',
          )

    # add an argument for interval
    parser.add_argument('bdtentry', type=str, nargs='*',
          help='list of addresses of peers',
          )

    # now parse the arguments
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    local_address = Address(args.localaddr)
    if _debug: _log.debug("    - local_address: %r", local_address)

    # create a null client that will accept, but do nothing with upstream
    # packets from the BBMD
    null_client = NullClient()
    if _debug: _log.debug("    - null_client: %r", null_client)

    # create a BBMD, bound to the Annex J server on a UDP multiplexer
    bbmd = BIPBBMD(local_address)
    annexj = AnnexJCodec()
    multiplexer = UDPMultiplexer(local_address)

    # bind the layers together
    bind(null_client, bbmd, annexj, multiplexer.annexJ)

    # loop through the rest of the addresses
    for bdtentry in args.bdtentry:
        if _debug: _log.debug("    - bdtentry: %r", bdtentry)

        bdt_address = Address(bdtentry)
        bbmd.add_peer(bdt_address)

    if _debug: _log.debug("    - bbmd: %r", bbmd)

    _log.debug("running")

    run()

    _log.debug("fini")
Beispiel #19
0
def main():
    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)

    # add an argument for local address
    parser.add_argument('addr1', type=str,
          help='address of first network',
          )

    # add an argument for local port
    parser.add_argument('port1', type=int,
          help='port number of local network',
          )

    # add an argument for interval
    parser.add_argument('net1', type=int,
          help='network number of local network',
          )

    # add an argument for interval
    parser.add_argument('addr2', type=str,
          help='address of global network (outside NAT)',
          )

    # add an argument for local port
    parser.add_argument('port2', type=int,
          help='port number of global forwarded port',
          )

    # add an argument for interval
    parser.add_argument('net2', type=int,
          help='network number of global network',
          )

    # now parse the arguments
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # create the router
    router = NATRouter(args.addr1, args.port1, args.net1, args.addr2, args.port2, args.net2)
    if _debug: _log.debug("    - router: %r", router)

    _log.debug("running")

    run()

    _log.debug("fini")
Beispiel #20
0
def main():
    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)
    args = parser.parse_args()
    if _debug:
        _log.debug("    - args: %r", args)

    for packet_data in parse_stream(sample):
        data = xtob(packet_data)
        packet = decode_packet(data)
        if not packet:
            continue

        x = {"apdu": packet.dict_contents()}
        json.dump(x, sys.stdout, indent=4)
Beispiel #21
0
def main():
    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)

    # now parse the arguments
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    _log.debug("running")

    run()

    _log.debug("fini")
Beispiel #22
0
def main():
    # check the version
    if (sys.version_info[:2] != (2, 5)):
        sys.stderr.write("Python 2.5 only\n")
        sys.exit(1)

    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)
    parser.add_argument(
        "host", nargs='?',
        help="listening address of server or 'any' (default %r)" % (SERVER_HOST,),
        default=SERVER_HOST,
        )
    parser.add_argument(
        "port", nargs='?', type=int,
        help="server port (default %r)" % (SERVER_PORT,),
        default=SERVER_PORT,
        )
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # extract the server address and port
    host = args.host
    if host == "any":
        host = ''
    server_address = (host, args.port)
    if _debug: _log.debug("    - server_address: %r", server_address)

    # create a director listening to the address
    this_director = TCPServerDirector(server_address)
    if _debug: _log.debug("    - this_director: %r", this_director)

    # create an echo
    echo_master = EchoMaster()
    if _debug: _log.debug("    - echo_master: %r", echo_master)

    # bind everything together
    bind(echo_master, this_director)
    bind(MiddleManASE(), this_director)

    _log.debug("running")

    run()

    _log.debug("fini")
Beispiel #23
0
def setUpPackage():
    global test_options

    # create an argument parser
    parser = ArgumentParser(description=__doc__)

    # add an option
    parser.add_argument('--option', help="this is an option",
                        default=os.getenv("BACPYPES_TEST_OPTION") or BACPYPES_TEST_OPTION,
                        )

    # get the debugging args and parse them
    arg_str = os.getenv("BACPYPES_TEST") or BACPYPES_TEST
    test_options = parser.parse_args(arg_str.split())

    if _debug: setUpPackage._debug("setUpPackage")
    if _debug: setUpPackage._debug("    - test_options: %r", test_options)
Beispiel #24
0
def main():
    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)

    # now parse the arguments
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # make the thread object and start it
    bacpypes_thread = BACpypesThread()
    bacpypes_thread.start()

    # main thread
    while True:
        write_flush("#")
        time.sleep(2)
Beispiel #25
0
def main():
    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)
    parser.add_argument(
        "--host",
        nargs='?',
        help="listening address of server",
        default=default_server_host,
    )
    parser.add_argument(
        "--port",
        nargs='?',
        type=int,
        help="server port",
        default=default_server_port,
    )
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # extract the server address and port
    host = args.host
    if host == "any":
        host = ''
    port = args.port
    server_address = (host, port)
    if _debug: _log.debug("    - server_address: %r", server_address)

    # create a director listening to the address
    this_director = TCPServerDirector(server_address)
    if _debug: _log.debug("    - this_director: %r", this_director)

    # create an echo
    echo_master = EchoMaster()
    if _debug: _log.debug("    - echo_master: %r", echo_master)

    # bind everything together
    bind(echo_master, this_director)
    bind(MiddleManASE(), this_director)

    _log.debug("running")

    run()
Beispiel #26
0
def setUp(argv=None):
    global test_options

    # create an argument parser
    parser = ArgumentParser(description=__doc__)

    # add an option
    parser.add_argument(
        '--option',
        help="this is an option",
        default=os.getenv("BACPYPES_TEST_OPTION") or BACPYPES_TEST_OPTION,
    )

    # get the debugging args and parse them
    arg_str = os.getenv("BACPYPES_TEST") or BACPYPES_TEST
    test_options = parser.parse_args(argv or arg_str.split())

    if _debug: setUp._debug("setUp")
    if _debug: setUp._debug("    - test_options: %r", test_options)
Beispiel #27
0
def main():
    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)

    # now parse the arguments
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # make the thread object and start it
    process_thread = ProcessThread()
    process_thread.start()

    _log.debug("running")

    run()

    _log.debug("fini")
Beispiel #28
0
def main():
    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)
    parser.add_argument(
        "--host", nargs='?',
        help="listening address of server",
        default=default_server_host,
        )
    parser.add_argument(
        "--port", nargs='?', type=int,
        help="server port",
        default=default_server_port,
        )
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # extract the server address and port
    host = args.host
    if host == "any":
        host = ''
    port = args.port
    server_address = (host, port)
    if _debug: _log.debug("    - server_address: %r", server_address)

    # create a director listening to the address
    this_director = TCPServerDirector(server_address)
    if _debug: _log.debug("    - this_director: %r", this_director)

    # create an echo
    echo_master = EchoMaster()
    if _debug: _log.debug("    - echo_master: %r", echo_master)

    # bind everything together
    bind(echo_master, this_director)
    bind(MiddleManASE(), this_director)

    _log.debug("running")

    run()
Beispiel #29
0
def setup_package():
    global test_options

    # create an argument parser
    parser = ArgumentParser(description=__doc__)

    # add an option
    parser.add_argument(
        '--option',
        help="this is an option",
        default=os.getenv("BACPYPES_TEST_OPTION") or BACPYPES_TEST_OPTION,
    )

    # get the debugging args and parse them
    arg_str = os.getenv("BACPYPES_TEST") or BACPYPES_TEST
    test_options = parser.parse_args(arg_str.split())

    if _debug: setup_package._debug("setup_package")
    if _debug: setup_package._debug("    - test_options: %r", test_options)

    time_machine = TimeMachine()
    if _debug: setup_package._debug("    - time_machine: %r", time_machine)
Beispiel #30
0
def main():
    try:
        # parse the command line arguments
        parser = ArgumentParser(description=__doc__)

        # now parse the arguments
        args = parser.parse_args()

        if _debug: _log.debug("initialization")
        if _debug: _log.debug("    - args: %r", args)

        # local IO functions
        bind(ConsoleClient(), ModbusClient())

        _log.debug("running")

        run()

    except Exception as err:
        _log.exception("an error has occurred: %s" % (err,))
    finally:
        _log.debug("finally")
Beispiel #31
0
def main():
    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)

    # add an argument for interval
    parser.add_argument('addr1', type=str,
          help='address of first network',
          )

    # add an argument for interval
    parser.add_argument('net1', type=int,
          help='network number of first network',
          )

    # add an argument for interval
    parser.add_argument('addr2', type=str,
          help='address of second network',
          )

    # add an argument for interval
    parser.add_argument('net2', type=int,
          help='network number of second network',
          )

    # now parse the arguments
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # create the router
    router = IP2IPRouter(Address(args.addr1), args.net1, Address(args.addr2), args.net2)
    if _debug: _log.debug("    - router: %r", router)

    _log.debug("running")

    run()

    _log.debug("fini")
Beispiel #32
0
def main():
    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)

    # connection timeout paramters
    parser.add_argument(
        "--connect-timeout", nargs='?', type=int,
        help="idle connection timeout",
        default=CONNECT_TIMEOUT,
        )
    parser.add_argument(
        "--idle-timeout", nargs='?', type=int,
        help="idle connection timeout",
        default=IDLE_TIMEOUT,
        )

    # now parse the arguments
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # make a controller
    this_controller = ModbusClientController(
        connect_timeout=args.connect_timeout,
        idle_timeout=args.idle_timeout,
        )
    if _debug: _log.debug("    - this_controller: %r", this_controller)

    # make a console
    this_console = ConsoleClient(this_controller)
    if _debug: _log.debug("    - this_console: %r", this_console)

    _log.debug("running")

    run()

    _log.debug("fini")
Beispiel #33
0
def main():
    global this_console

    # build a parser for the command line arguments
    parser = ArgumentParser(description=__doc__)

    # sample additional argument to change the prompt
    parser.add_argument("--prompt", type=str, default="> ", help="change the prompt")

    # parse the command line arguments
    args = parser.parse_args()

    if _debug:
        _log.debug("initialization")
    if _debug:
        _log.debug("    - args: %r", args)

    # make a console
    this_console = ConsoleCmdTemplate(prompt=args.prompt)

    _log.debug("running")

    run()
Beispiel #34
0
def main():
    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)

    # listener arguments
    parser.add_argument(
        "--host", type=str,
        help="address of host (default {!r})".format(SERVER_HOST),
        default=SERVER_HOST,
        )
    parser.add_argument(
        "--port", type=int,
        help="server port (default {!r})".format(SERVER_PORT),
        default=SERVER_PORT,
        )

    # connection timeout arguments
    parser.add_argument(
        "--idle-timeout", nargs='?', type=int,
        help="idle connection timeout",
        default=IDLE_TIMEOUT,
        )

    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # local IO functions
    bind(SimpleServer(), ModbusServer(port=args.port, idle_timeout=args.idle_timeout))

    _log.debug("running")

    run()

    _log.debug("fini")
Beispiel #35
0
# add an argument for interval
parser.add_argument(
    'addr2',
    type=str,
    help='address of second network',
)

# add an argument for interval
parser.add_argument(
    'net2',
    type=int,
    help='network number of second network',
)

# now parse the arguments
args = parser.parse_args()

if _debug: _log.debug("initialization")
if _debug: _log.debug("    - args: %r", args)

local_address = Address(args.addr1)
local_network = args.net1
vlan_address = Address(args.addr2)
vlan_network = args.net2

# create the VLAN router, bind it to the local network
router = VLANRouter(local_address, local_network)

# create a VLAN
vlan = Network()
Beispiel #36
0
def main():
    global args

    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)

    # arguments for first network
    parser.add_argument(
        'lan',
        type=str,
        help='MQTT network name',
    )
    parser.add_argument(
        'addr1',
        type=str,
        help='address of first network',
    )
    parser.add_argument(
        'net1',
        type=int,
        help='network number of first network',
    )

    # arguments for B/IP network
    parser.add_argument(
        'addr2',
        type=str,
        help='address of second network',
    )
    parser.add_argument(
        'net2',
        type=int,
        help='network number of second network',
    )

    # additional options for the MQTT client
    parser.add_argument(
        '--host',
        type=str,
        default=bacpypes_mqtt.default_broker_host,
        help='broker host address',
    )
    parser.add_argument(
        '--port',
        type=int,
        default=bacpypes_mqtt.default_broker_port,
        help='broker port',
    )
    parser.add_argument(
        '--keepalive',
        type=int,
        default=bacpypes_mqtt.default_broker_keepalive,
        help=
        "maximum period in seconds allowed between communications with the broker",
    )

    # now parse the arguments
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # create the router
    router = MQTT2IPRouter(args.lan, Address(args.addr1), args.net1,
                           Address(args.addr2), args.net2)
    if _debug: _log.debug("    - router: %r", router)

    # start up the client
    router.s1_mse.startup()

    _log.debug("running")

    run()

    # shutdown the client
    router.s1_mse.shutdown()

    _log.debug("fini")
Beispiel #37
0
def main():
    # parse the command line arguments
    parser = ArgumentParser(
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter,
    )

    # add an argument for interval
    parser.add_argument(
        'addr1',
        type=str,
        help='address of first network',
    )

    # add an argument for interval
    parser.add_argument(
        'net1',
        type=int,
        help='network number of first network',
    )

    # add an argument for interval
    parser.add_argument(
        'addr2',
        type=str,
        help='address of second network',
    )

    # add an argument for interval
    parser.add_argument(
        'net2',
        type=int,
        help='network number of second network',
    )

    # now parse the arguments
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    local_address = Address(args.addr1)
    local_network = args.net1
    vlan_address = Address(args.addr2)
    vlan_network = args.net2

    # create the VLAN router, bind it to the local network
    router = VLANRouter(local_address, local_network)

    # create a VLAN
    vlan = Network(broadcast_address=LocalBroadcast())

    # create a node for the router, address 1 on the VLAN
    router_node = Node(Address(1))
    vlan.add_node(router_node)

    # bind the router stack to the vlan network through this node
    router.nsap.bind(router_node, vlan_network)

    # send network topology
    deferred(router.nse.i_am_router_to_network)

    # device identifier is assigned from the address
    device_instance = vlan_network * 100 + int(args.addr2)
    _log.debug("    - device_instance: %r", device_instance)

    # make a vlan device object
    vlan_device = \
        LocalDeviceObject(
            objectName="VLAN Node %d" % (device_instance,),
            objectIdentifier=('device', device_instance),
            maxApduLengthAccepted=1024,
            segmentationSupported='noSegmentation',
            vendorIdentifier=15,
            )
    _log.debug("    - vlan_device: %r", vlan_device)

    # make the application, add it to the network
    vlan_app = VLANApplication(vlan_device, vlan_address)
    vlan.add_node(vlan_app.vlan_node)
    _log.debug("    - vlan_app: %r", vlan_app)

    # make a random value object
    ravo = RandomAnalogValueObject(
        objectIdentifier=('analogValue', 1),
        objectName='Device%d/Random1' % (device_instance, ),
    )
    _log.debug("    - ravo1: %r", ravo)

    # add it to the device
    vlan_app.add_object(ravo)

    _log.debug("running")

    run()

    _log.debug("fini")
Beispiel #38
0
def main():
    global local_unicast_tuple, local_broadcast_tuple

    # parse the command line arguments
    parser = ArgumentParser(usage=__doc__)
    parser.add_argument("address",
        help="address of socket",
        )
    parser.add_argument("--nobroadcast",
        action="store_true",
        dest="noBroadcast",
        default=False,
        help="do not create a broadcast socket",
        )

    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    if args.address == "any":
        local_unicast_tuple = ('', 47808)
        local_broadcast_tuple = ('255.255.255.255', 47808)

    elif args.address.startswith("any:"):
        port = int(args.address[4:])
        local_unicast_tuple = ('', port)
        local_broadcast_tuple = ('255.255.255.255', port)

    else:
        address = Address(args.address)
        if _debug: _log.debug("    - local_address: %r", address)

        local_unicast_tuple = address.addrTuple
        local_broadcast_tuple = address.addrBroadcastTuple

    if _debug: _log.debug("    - local_unicast_tuple: %r", local_unicast_tuple)
    if _debug: _log.debug("    - local_broadcast_tuple: %r", local_broadcast_tuple)

    console = ConsoleClient()
    middle_man = MiddleMan()
    unicast_director = UDPDirector(local_unicast_tuple)
    bind(console, middle_man, unicast_director)

    if args.noBroadcast:
        _log.debug("    - skipping broadcast")

    elif local_unicast_tuple == local_broadcast_tuple:
        _log.debug("    - identical unicast and broadcast tuples")

    elif local_broadcast_tuple[0] == '255.255.255.255':
        _log.debug("    - special broadcast address only for sending")

    else:
        broadcast_receiver = BroadcastReceiver()
        broadcast_director = UDPDirector(local_broadcast_tuple, reuse=True)
        bind(broadcast_receiver, broadcast_director)

    _log.debug("running")

    run()

    _log.debug("fini")
Beispiel #39
0
def main():
    """
    Main function, called when run as an application.
    """
    global server_address

    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)
    parser.add_argument(
        "host", nargs='?',
        help="address of host (default %r)" % (SERVER_HOST,),
        default=SERVER_HOST,
        )
    parser.add_argument(
        "port", nargs='?', type=int,
        help="server port (default %r)" % (SERVER_PORT,),
        default=SERVER_PORT,
        )
    parser.add_argument(
        "--hello", action="store_true",
        default=False,
        help="send a hello message",
        )
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # extract the server address and port
    host = args.host
    port = args.port
    server_address = (host, port)
    if _debug: _log.debug("    - server_address: %r", server_address)

    # build the stack
    this_console = ConsoleClient()
    if _debug: _log.debug("    - this_console: %r", this_console)

    this_middle_man = MiddleMan()
    if _debug: _log.debug("    - this_middle_man: %r", this_middle_man)

    this_director = TCPClientDirector()
    if _debug: _log.debug("    - this_director: %r", this_director)

    bind(this_console, this_middle_man, this_director)
    bind(MiddleManASE(), this_director)

    # create a task manager for scheduled functions
    task_manager = TaskManager()
    if _debug: _log.debug("    - task_manager: %r", task_manager)

    # don't wait to connect
    deferred(this_director.connect, server_address)

    # send hello maybe
    if args.hello:
        deferred(this_middle_man.indication, PDU(xtob('68656c6c6f0a')))

    if _debug: _log.debug("running")

    run()

    if _debug: _log.debug("fini")
Beispiel #40
0
def main():
    global args, this_application

    # parse the command line arguments
    parser = ArgumentParser(
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter,
    )

    # add an argument for interval
    parser.add_argument(
        "addr1",
        type=str,
        help="address of first network",
    )

    # add an argument for interval
    parser.add_argument(
        "net1",
        type=int,
        help="network number of first network",
    )

    # add an argument for interval
    parser.add_argument(
        "net2",
        type=int,
        help="network number of second network",
    )

    # add an argument for how many virtual devices
    parser.add_argument(
        "--count",
        type=int,
        help="number of virtual devices",
        default=1,
    )

    # add an argument for how many virtual devices
    parser.add_argument(
        "--rpm",
        help="enable read property multiple",
        action="store_true",
    )

    # add an argument for including the property list
    parser.add_argument(
        "--plist",
        help="enable property list property",
        action="store_true",
    )

    # now parse the arguments
    args = parser.parse_args()

    if _debug:
        _log.debug("initialization")
    if _debug:
        _log.debug("    - args: %r", args)

    local_address = Address(args.addr1)
    local_network = args.net1
    vlan_network = args.net2

    # create the VLAN router, bind it to the local network
    router = VLANRouter(local_address, local_network)

    # create a VLAN
    vlan = Network(broadcast_address=LocalBroadcast())

    # create a node for the router, address 1 on the VLAN
    router_addr = Address(1)
    router_node = Node(router_addr)
    vlan.add_node(router_node)

    # bind the router stack to the vlan network through this node
    router.nsap.bind(router_node, vlan_network, router_addr)

    # send network topology
    deferred(router.nse.i_am_router_to_network)

    # add the dynamic property list
    if args.plist:
        RandomAnalogValueObject.properties.append(CurrentPropertyList())

    # register it now that all its properties are defined
    register_object_type(RandomAnalogValueObject, vendor_id=999)

    # console is the first device
    device_number = 2
    device_instance = vlan_network * 100 + device_number
    _log.debug("    - console device_instance: %r", device_instance)

    # make a vlan device object
    vlan_device = LocalDeviceObject(
        objectName="VLAN Console Node %d" % (device_instance, ),
        objectIdentifier=("device", device_instance),
        maxApduLengthAccepted=1024,
        segmentationSupported="noSegmentation",
        vendorIdentifier=15,
    )
    _log.debug("    - vlan_device: %r", vlan_device)

    vlan_address = Address(device_number)
    _log.debug("    - vlan_address: %r", vlan_address)

    # make the console application, add it to the network
    this_application = VLANConsoleApplication(vlan_device, vlan_address)
    vlan.add_node(this_application.vlan_node)
    _log.debug("    - this_application: %r", this_application)

    # make a console
    this_console = VLANConsoleCmd()
    if _debug:
        _log.debug("    - this_console: %r", this_console)

    # make a random value object
    ravo = RandomAnalogValueObject(
        objectIdentifier=("analogValue", 1),
        objectName="Random-1-%d" % (device_instance, ),
    )
    _log.debug("    - ravo: %r", ravo)

    # add it to the device
    this_application.add_object(ravo)

    # make some more devices
    for device_number in range(3, 3 + args.count - 1):
        # device identifier is assigned from the address
        device_instance = vlan_network * 100 + device_number
        _log.debug("    - device_instance: %r", device_instance)

        # make a vlan device object
        vlan_device = LocalDeviceObject(
            objectName="VLAN Node %d" % (device_instance, ),
            objectIdentifier=("device", device_instance),
            maxApduLengthAccepted=1024,
            segmentationSupported="noSegmentation",
            vendorIdentifier=15,
        )
        _log.debug("    - vlan_device: %r", vlan_device)

        vlan_address = Address(device_number)
        _log.debug("    - vlan_address: %r", vlan_address)

        # make the application, add it to the network
        vlan_app = VLANApplication(vlan_device, vlan_address)
        vlan.add_node(vlan_app.vlan_node)
        _log.debug("    - vlan_app: %r", vlan_app)

        # make a random value object
        ravo = RandomAnalogValueObject(
            objectIdentifier=("analogValue", 1),
            objectName="Random-1-%d" % (device_instance, ),
        )
        _log.debug("    - ravo: %r", ravo)

        # add it to the device
        vlan_app.add_object(ravo)

    # enable sleeping will help with threads
    enable_sleeping()

    _log.debug("running")

    run()

    _log.debug("fini")
Beispiel #41
0
def main():
    # parse the command line arguments
    parser = ArgumentParser(
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter,
        )

    # add an argument for interval
    parser.add_argument('addr1', type=str,
          help='address of first network',
          )

    # add an argument for interval
    parser.add_argument('net1', type=int,
          help='network number of first network',
          )

    # add an argument for interval
    parser.add_argument('addr2', type=str,
          help='address of second network',
          )

    # add an argument for interval
    parser.add_argument('net2', type=int,
          help='network number of second network',
          )

    # now parse the arguments
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    local_address = Address(args.addr1)
    local_network = args.net1
    vlan_address = Address(args.addr2)
    vlan_network = args.net2

    # create the VLAN router, bind it to the local network
    router = VLANRouter(local_address, local_network)

    # create a VLAN
    vlan = Network()

    # create a node for the router, address 1 on the VLAN
    router_node = Node(Address(1))
    vlan.add_node(router_node)

    # bind the router stack to the vlan network through this node
    router.nsap.bind(router_node, vlan_network)

    # device identifier is assigned from the address
    device_instance = vlan_network * 100 + int(args.addr2)
    _log.debug("    - device_instance: %r", device_instance)

    # make a vlan device object
    vlan_device = \
        LocalDeviceObject(
            objectName="VLAN Node %d" % (device_instance,),
            objectIdentifier=('device', device_instance),
            maxApduLengthAccepted=1024,
            segmentationSupported='noSegmentation',
            vendorIdentifier=15,
            )
    _log.debug("    - vlan_device: %r", vlan_device)

    # make the application, add it to the network
    vlan_app = VLANApplication(vlan_device, vlan_address)
    vlan.add_node(vlan_app.vlan_node)
    _log.debug("    - vlan_app: %r", vlan_app)

    # make a random value object
    ravo = RandomAnalogValueObject(
        objectIdentifier=('analogValue', 1),
        objectName='Device%d/Random1' % (device_instance,),
        )
    _log.debug("    - ravo1: %r", ravo)

    # add it to the device
    vlan_app.add_object(ravo)

    _log.debug("running")

    run()

    _log.debug("fini")
Beispiel #42
0
def main():
    # build a parser
    parser = ArgumentParser(description=__doc__)

    # add a --host option to override the default host address
    parser.add_argument(
        '--host', type=str,
        default=default_db_host,
        help='database host address',
        )

    # add a --port option to override the default database
    parser.add_argument(
        '--db', type=str,
        default=default_db_db,
        help='database',
        )

    # parse the command line arguments
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # give the connection information to the db module
    db.db_connection_kwargs = {
        'host': args.host,
        'db': args.db,
        }
    if _debug: _log.debug("    - db_connection_kwargs: %r", db.db_connection_kwargs)

    # create the test table
    create_test_table()

    # test data
    test_data = [
        (100, "a"),
        (110, "aa"),
        (111, "aaa"),
        (112, "aab"),
        (120, "ab"),
        (200, "b"),
        (210, "ba"),
        (211, "baa"),
        (212, "bab"),
        (220, "bb"),
        ]

    # insert the data
    for row_int, row_str in test_data:
        db.execute("insert into TestTable values (%s, %s)", (row_int, row_str))

    # count the number of rows
    row_count = db.fetch_value("select count(*) from TestTable")
    if _debug: _log.debug("    - row_count: %r", row_count)
    assert row_count == len(test_data)

    # test for some specific values
    for row_int, row_str in random.sample(test_data, 3):
        if _debug: _log.debug("    - row_int, row_str: %r, %r", row_int, row_str)
        row_value = db.fetch_value("select row_int from TestTable where row_str = %s", (row_str,))
        assert row_value == row_int

    # get some values
    row_ints = db.fetch_values("select row_int from TestTable where row_int < 200 order by row_int")
    if _debug: _log.debug("    - row_ints: %r", row_ints)
    assert row_ints == [100, 110, 111, 112, 120]

    # yield some objects
    for row_object in db.yield_objects("select * from TestTable where row_str >= %s", ('b',)):
        if _debug: _log.debug("    - row_object: %r, row_int=%r, row_str=%r", row_object, row_object.row_int, row_object.row_str)

    # drop the test table
    drop_test_table()

    # close the connections
    db.close_connections()

    if _debug: _log.debug("finally")
Beispiel #43
0
def main():
    """
    Main function, called when run as an application.
    """
    global args, server_address

    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)
    parser.add_argument(
        "host",
        nargs='?',
        help="address of host (default %r)" % (SERVER_HOST, ),
        default=SERVER_HOST,
    )
    parser.add_argument(
        "port",
        nargs='?',
        type=int,
        help="server port (default %r)" % (SERVER_PORT, ),
        default=SERVER_PORT,
    )
    parser.add_argument(
        "--hello",
        action="store_true",
        default=False,
        help="send a hello message",
    )
    parser.add_argument(
        "--connect-timeout",
        nargs='?',
        type=int,
        help="idle connection timeout",
        default=CONNECT_TIMEOUT,
    )
    parser.add_argument(
        "--idle-timeout",
        nargs='?',
        type=int,
        help="idle connection timeout",
        default=IDLE_TIMEOUT,
    )
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # extract the server address and port
    host = args.host
    port = args.port
    server_address = (host, port)
    if _debug: _log.debug("    - server_address: %r", server_address)

    # build the stack
    this_console = ConsoleClient()
    if _debug: _log.debug("    - this_console: %r", this_console)

    this_middle_man = MiddleMan()
    if _debug: _log.debug("    - this_middle_man: %r", this_middle_man)

    this_director = TCPClientDirector(
        connect_timeout=args.connect_timeout,
        idle_timeout=args.idle_timeout,
    )
    if _debug: _log.debug("    - this_director: %r", this_director)

    bind(this_console, this_middle_man, this_director)
    bind(MiddleManASE(), this_director)

    # create a task manager for scheduled functions
    task_manager = TaskManager()
    if _debug: _log.debug("    - task_manager: %r", task_manager)

    # don't wait to connect
    deferred(this_director.connect, server_address)

    # send hello maybe
    if args.hello:
        deferred(this_middle_man.indication, PDU(b'Hello, world!\n'))

    if _debug: _log.debug("running")

    run()

    if _debug: _log.debug("fini")
Beispiel #44
0
def main():
    global args

    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)
    parser.add_argument(
        "host",
        nargs='?',
        help="listening address of server or 'any' (default %r)" %
        (SERVER_HOST, ),
        default=SERVER_HOST,
    )
    parser.add_argument(
        "port",
        nargs='?',
        type=int,
        help="server port (default %r)" % (SERVER_PORT, ),
        default=SERVER_PORT,
    )
    parser.add_argument(
        "--idle-timeout",
        nargs='?',
        type=int,
        help="idle connection timeout",
        default=IDLE_TIMEOUT,
    )
    parser.add_argument(
        "--hello",
        action="store_true",
        default=False,
        help="send a hello message to a client when it connects",
    )
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # extract the server address and port
    host = args.host
    if host == "any":
        host = ''
    server_address = (host, args.port)
    if _debug: _log.debug("    - server_address: %r", server_address)

    # create a director listening to the address
    this_director = TCPServerDirector(server_address,
                                      idle_timeout=args.idle_timeout)
    if _debug: _log.debug("    - this_director: %r", this_director)

    # create an echo
    echo_master = EchoMaster()
    if _debug: _log.debug("    - echo_master: %r", echo_master)

    # bind everything together
    bind(echo_master, this_director)
    bind(MiddleManASE(), this_director)

    _log.debug("running")

    run()

    _log.debug("fini")
            iAmTraffic[key] += 1


#
#   __main__
#

# parse the command line arguments
parser = ArgumentParser(description=__doc__)
parser.add_argument("-s", "--source", nargs="?", type=str, help="source address")
parser.add_argument(
    "-d", "--destination", nargs="?", type=str, help="destination address"
)
parser.add_argument("--host", nargs="?", type=str, help="source or destination")
parser.add_argument("pcap", nargs="+", type=str, help="pcap file(s)")
args = parser.parse_args()

if _debug:
    _log.debug("initialization")
if _debug:
    _log.debug("    - args: %r", args)

# interpret the arguments
if args.source:
    filterSource = Address(args.source)
    if _debug:
        _log.debug("    - filterSource: %r", filterSource)
if args.destination:
    filterDestination = Address(args.destination)
    if _debug:
        _log.debug("    - filterDestination: %r", filterDestination)
Beispiel #46
0
def main():
    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)

    # add an argument for which test to run
    parser.add_argument("test_id", type=int, help="test number")

    # now parse the arguments
    args = parser.parse_args()

    if _debug:
        _log.debug("initialization")
    if _debug:
        _log.debug("    - args: %r", args)

    # VLAN needs to know what a broadcast address looks like
    vlan_broadcast_address = LocalBroadcast()

    #
    #   Router1
    #

    # create the router
    router1 = VLANRouter()
    if _debug:
        _log.debug("    - router1: %r", router1)

    #
    #   VLAN-1
    #

    # create VLAN-1
    vlan1 = Network(name="1", broadcast_address=vlan_broadcast_address)
    if _debug:
        _log.debug("    - vlan1: %r", vlan1)

    # bind the router to the vlan
    router1.bind(vlan1, 1, 1)
    if _debug:
        _log.debug("    - router1 bound to VLAN-1")

    # make the application, add it to the network
    vlan1_app = VLANApplication(objectName="VLAN Node 102",
                                deviceInstance=102,
                                address=2)
    vlan1.add_node(vlan1_app.vlan_node)
    _log.debug("    - vlan1_app: %r", vlan1_app)

    #
    #   VLAN-2
    #

    # create VLAN-2
    vlan2 = Network(name="2", broadcast_address=vlan_broadcast_address)
    if _debug:
        _log.debug("    - vlan2: %r", vlan2)

    # bind the router stack to the vlan network through this node
    router1.bind(vlan2, 1, 2)
    if _debug:
        _log.debug("    - router1 bound to VLAN-2")

    # make the application, add it to the network
    vlan2_app = VLANApplication(objectName="VLAN Node 202",
                                deviceInstance=202,
                                address=2)
    vlan2.add_node(vlan2_app.vlan_node)
    _log.debug("    - vlan2_app: %r", vlan2_app)

    #
    #   VLAN-3
    #

    # create VLAN-3
    vlan3 = Network(name="3", broadcast_address=vlan_broadcast_address)
    if _debug:
        _log.debug("    - vlan3: %r", vlan3)

    # bind the router stack to the vlan network through this node
    router1.bind(vlan3, 1, 3)
    if _debug:
        _log.debug("    - router1 bound to VLAN-3")

    # make a vlan device object
    vlan3_device = LocalDeviceObject(
        objectName="VLAN Node 302",
        objectIdentifier=("device", 302),
        maxApduLengthAccepted=1024,
        segmentationSupported="noSegmentation",
        vendorIdentifier=15,
    )
    _log.debug("    - vlan3_device: %r", vlan3_device)

    # make the application, add it to the network
    vlan3_app = VLANApplication(objectName="VLAN Node 302",
                                deviceInstance=302,
                                address=2)
    vlan3.add_node(vlan3_app.vlan_node)
    _log.debug("    - vlan3_app: %r", vlan3_app)

    #
    #   Router2
    #

    # create the router
    router2 = VLANRouter()
    if _debug:
        _log.debug("    - router2: %r", router2)

    # bind the router stack to the vlan network through this node
    router2.bind(vlan3, 255, 3)
    if _debug:
        _log.debug("    - router2 bound to VLAN-3")

    #
    #   VLAN-4
    #

    # create VLAN-4
    vlan4 = Network(name="4", broadcast_address=vlan_broadcast_address)
    if _debug:
        _log.debug("    - vlan4: %r", vlan4)

    # bind the router stack to the vlan network through this node
    router2.bind(vlan4, 1, 4)
    if _debug:
        _log.debug("    - router2 bound to VLAN-4")

    # make the application, add it to the network
    vlan4_app = VLANApplication(objectName="VLAN Node 402",
                                deviceInstance=402,
                                address=2)
    vlan4.add_node(vlan4_app.vlan_node)
    _log.debug("    - vlan4_app: %r", vlan4_app)

    #
    #   Test 1
    #

    if args.test_id == 1:
        # ask the first device to Who-Is everybody
        deferred(vlan1_app.who_is)

    #
    #   Test 2
    #

    if args.test_id == 2:
        # make a read request
        read_property_request = ReadPropertyRequest(
            destination=Address("2:2"),
            objectIdentifier=("device", 202),
            propertyIdentifier="objectName",
        )

        # ask the first device to send it
        deferred(vlan1_app.request, read_property_request)

    #
    #   Test 3
    #

    if args.test_id == 3:
        # make a read request
        read_property_request = ReadPropertyRequest(
            destination=Address("3:2"),
            objectIdentifier=("device", 302),
            propertyIdentifier="objectName",
        )

        # ask the first device to send it
        deferred(vlan1_app.request, read_property_request)

    #
    #   Test 4
    #

    if args.test_id == 4:
        # make a read request
        read_property_request = ReadPropertyRequest(
            destination=Address("4:2"),
            objectIdentifier=("device", 402),
            propertyIdentifier="objectName",
        )

        # ask the first device to send it
        deferred(vlan1_app.request, read_property_request)

    #
    #   Let the test run
    #

    _log.debug("running")

    run()

    _log.debug("fini")
Beispiel #47
0
def main():
    global args

    # parse the command line arguments
    parser = ArgumentParser(description=__doc__)

    # arguments for first network
    parser.add_argument(
        'lan',
        type=str,
        help='MQTT network name',
    )
    parser.add_argument(
        'addr1',
        type=str,
        help='address on MQTT network',
    )
    parser.add_argument(
        'net1',
        type=int,
        help='network number of MQTT network',
    )

    # VLAN arguments
    parser.add_argument(
        'net2',
        type=int,
        help='network number of VLAN',
    )
    parser.add_argument(
        '--count',
        type=int,
        help='number of virtual devices',
        default=1,
    )

    # additional options for the MQTT client
    parser.add_argument(
        '--host',
        type=str,
        default=bacpypes_mqtt.default_broker_host,
        help='broker host address',
    )
    parser.add_argument(
        '--port',
        type=int,
        default=bacpypes_mqtt.default_broker_port,
        help='broker port',
    )
    parser.add_argument(
        '--keepalive',
        type=int,
        default=bacpypes_mqtt.default_broker_keepalive,
        help=
        "maximum period in seconds allowed between communications with the broker",
    )

    # now parse the arguments
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # create the VLAN router, bind it to the local network
    router = VLANRouter(args.lan, Address(args.addr1), args.net1)

    # create a VLAN
    vlan = Network(broadcast_address=LocalBroadcast())

    # create a node for the router, address 1 on the VLAN
    router_node = Node(Address(1))
    vlan.add_node(router_node)

    # bind the router stack to the vlan network through this node
    router.nsap.bind(router_node, args.net2)

    # make some devices
    for device_number in range(2, 2 + args.count):
        # device identifier is assigned from the address
        device_instance = args.net2 * 100 + device_number
        _log.debug("    - device_instance: %r", device_instance)

        # make a vlan device object
        vlan_device = \
            LocalDeviceObject(
                objectName="VLAN Node %d" % (device_instance,),
                objectIdentifier=('device', device_instance),
                maxApduLengthAccepted=1024,
                segmentationSupported='noSegmentation',
                vendorIdentifier=15,
                )
        _log.debug("    - vlan_device: %r", vlan_device)

        vlan_address = Address(device_number)
        _log.debug("    - vlan_address: %r", vlan_address)

        # make the application, add it to the network
        vlan_app = VLANApplication(vlan_device, vlan_address)
        vlan.add_node(vlan_app.vlan_node)
        _log.debug("    - vlan_app: %r", vlan_app)

        # make a random value object
        ravo = RandomAnalogValueObject(
            objectIdentifier=('analogValue', 1),
            objectName='Random-1-%d' % (device_instance, ),
        )
        _log.debug("    - ravo: %r", ravo)

        # add it to the device
        vlan_app.add_object(ravo)

    # start up the client
    router.mse.startup()

    _log.debug("running")

    run()

    # shutdown the client
    router.mse.shutdown()

    _log.debug("fini")
Beispiel #48
0
def main():
    # build a parser
    parser = ArgumentParser(description=__doc__)

    # add a --host option to override the default host address
    parser.add_argument(
        '--host',
        type=str,
        default=default_db_host,
        help='database host address',
    )

    # add a --port option to override the default database
    parser.add_argument(
        '--db',
        type=str,
        default=default_db_db,
        help='database',
    )

    # parse the command line arguments
    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    # give the connection information to the db module
    db.db_connection_kwargs = {
        'host': args.host,
        'db': args.db,
    }
    if _debug:
        _log.debug("    - db_connection_kwargs: %r", db.db_connection_kwargs)

    # create the test table
    create_test_table()

    # test data
    test_data = [
        (100, "a"),
        (110, "aa"),
        (111, "aaa"),
        (112, "aab"),
        (120, "ab"),
        (200, "b"),
        (210, "ba"),
        (211, "baa"),
        (212, "bab"),
        (220, "bb"),
    ]

    # insert the data
    for row_int, row_str in test_data:
        db.execute("insert into TestTable values (%s, %s)", (row_int, row_str))

    # count the number of rows
    row_count = db.fetch_value("select count(*) from TestTable")
    if _debug: _log.debug("    - row_count: %r", row_count)
    assert row_count == len(test_data)

    # test for some specific values
    for row_int, row_str in random.sample(test_data, 3):
        if _debug:
            _log.debug("    - row_int, row_str: %r, %r", row_int, row_str)
        row_value = db.fetch_value(
            "select row_int from TestTable where row_str = %s", (row_str, ))
        assert row_value == row_int

    # get some values
    row_ints = db.fetch_values(
        "select row_int from TestTable where row_int < 200 order by row_int")
    if _debug: _log.debug("    - row_ints: %r", row_ints)
    assert row_ints == [100, 110, 111, 112, 120]

    # yield some objects
    for row_object in db.yield_objects(
            "select * from TestTable where row_str >= %s", ('b', )):
        if _debug:
            _log.debug("    - row_object: %r, row_int=%r, row_str=%r",
                       row_object, row_object.row_int, row_object.row_str)

    # drop the test table
    drop_test_table()

    # close the connections
    db.close_connections()

    if _debug: _log.debug("finally")
Beispiel #49
0
def main():
    global local_unicast_tuple, local_broadcast_tuple

    # parse the command line arguments
    parser = ArgumentParser(usage=__doc__)
    parser.add_argument(
        "address",
        help="address of socket",
    )
    parser.add_argument(
        "--nobroadcast",
        action="store_true",
        dest="noBroadcast",
        default=False,
        help="do not create a broadcast socket",
    )

    args = parser.parse_args()

    if _debug: _log.debug("initialization")
    if _debug: _log.debug("    - args: %r", args)

    if args.address == "any":
        local_unicast_tuple = ('', 47808)
        local_broadcast_tuple = ('255.255.255.255', 47808)

    elif args.address.startswith("any:"):
        port = int(args.address[4:])
        local_unicast_tuple = ('', port)
        local_broadcast_tuple = ('255.255.255.255', port)

    else:
        address = Address(args.address)
        if _debug: _log.debug("    - local_address: %r", address)

        local_unicast_tuple = address.addrTuple
        local_broadcast_tuple = address.addrBroadcastTuple

    if _debug: _log.debug("    - local_unicast_tuple: %r", local_unicast_tuple)
    if _debug:
        _log.debug("    - local_broadcast_tuple: %r", local_broadcast_tuple)

    console = ConsoleClient()
    middle_man = MiddleMan()
    unicast_director = UDPDirector(local_unicast_tuple)
    bind(console, middle_man, unicast_director)

    if args.noBroadcast:
        _log.debug("    - skipping broadcast")

    elif not local_broadcast_tuple:
        _log.debug("    - no local broadcast")

    elif local_unicast_tuple == local_broadcast_tuple:
        _log.debug("    - identical unicast and broadcast tuples")

    elif local_broadcast_tuple[0] == '255.255.255.255':
        _log.debug("    - special broadcast address only for sending")

    else:
        broadcast_receiver = BroadcastReceiver()
        broadcast_director = UDPDirector(local_broadcast_tuple, reuse=True)
        bind(broadcast_receiver, broadcast_director)

    _log.debug("running")

    run()

    _log.debug("fini")
Beispiel #50
0
def setup_package():
    global test_host, test_connection, test_database, test_collection, \
        test_flush, test_dump

    # create an argument parser
    parser = ArgumentParser(description=__doc__)

    # add an option to select the host
    parser.add_argument('--host', help="connect to a host",
                        default=os.getenv("MONGOTREE_HOST") or "localhost",
                        )

    # add an option to select the database
    parser.add_argument('--db', help="database",
                        default=os.getenv("MONGOTREE_DB") or "test",
                        )

    # add an option to select the collection
    parser.add_argument('--collection', help="collection",
                        default=os.getenv("MONGOTREE_COLLECTION") or "mongotree",
                        )

    # add a flush option
    parser.add_argument('--flush',
                        help="flush the collection before running test",
                        action='store_true', default=True,
                        )

    # add a dump option
    parser.add_argument('--dump',
                        help="dump the collection after running test",
                        action='store_true', default=True,
                        )

    # get the debugging args and parse them
    arg_str = os.getenv("MONGOTREE_DEBUG") or ""
    test_args = parser.parse_args(arg_str.split())

    if _debug: setup_package._debug("setup_package")
    if _debug: setup_package._debug("    - test_args: %r", test_args)

    # save the host
    test_host = test_args.host
    if _debug: setup_package._debug("    - test_host: %r", test_host)

    # create a connection
    test_connection = pymongo.MongoClient(test_args.host)
    if _debug: setup_package._debug("    - test_connection: %r", test_connection)

    # reference a database
    test_database = test_connection[test_args.db]
    if _debug: setup_package._debug("    - test_database: %r", test_database)

    # reference a collection
    test_collection = test_database[test_args.collection]
    if _debug: setup_package._debug("    - test_collection: %r", test_collection)

    # flush before each case
    test_flush = test_args.flush
    if _debug: setup_package._debug("    - test_flush: %r", test_flush)

    # dump after each case
    test_dump = test_args.dump
    if _debug: setup_package._debug("    - test_dump: %r", test_dump)

    if _debug: setup_package._debug("    - periodic executors: %r", pymongo.periodic_executor._EXECUTORS)