Beispiel #1
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 #2
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 #3
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 #4
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 #5
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 #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():
    # 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 #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
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 #15
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 #16
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 #17
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 #18
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 #19
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 #20
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 #21
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 #22
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 #23
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 #24
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 #25
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 #26
0
        bind(self.s2_bip, self.s2_annexj, self.s2_mux.annexJ)

        # bind the BIP stack to the local network
        self.nsap.bind(self.s2_bip, net2)


#
#   __main__
#

try:
    # 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")
Beispiel #27
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 #28
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 #29
0
#!/bin/bash python

"""
This simple application takes a string form of a BACnet address from the
command line and attempts to interpret it.
"""

import sys

from bacpypes.consolelogging import ArgumentParser
from bacpypes.pdu import Address

# build a parser for the command line arguments
parser = ArgumentParser(description=__doc__)
parser.add_argument("address",
    help="address to interpret",
    )

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

# try to interpret the address
try:
    addr = Address(args.address)
except Exception as err:
    print(err)
    sys.exit(1)

# print the string form
print(addr)
Beispiel #30
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 #31
0
from bacpypes.errors import ExecutionError

from csv import DictReader
import logging

#---------------------------------------------------------------------------# 
# configure the service logging
#---------------------------------------------------------------------------# 
# some debugging
_debug = 0
_log = ModuleLogger(globals())

import struct

parser = ArgumentParser(description='Run a test pymodbus driver')
parser.add_argument('config', help='device registry configuration')
parser.add_argument('interface', help='interface address and optionally the port for the device to listen on')
args = parser.parse_args()

MODBUS_REGISTER_SIZE = 2

class Register(object):
    def __init__(self, point_name, instance_number, object_type, property_name, read_only):
        self.read_only = read_only
        self.register_type = "byte"
        self.property_name = property_name
        self.object_type = object_type
        self.instance_number = int(instance_number)
        self.point_name = point_name
    
    def get_register_type(self):
Beispiel #32
0
            sys.stdout.write("received broadcast %r from self\n" % (line,))
        else:
            sys.stdout.write("received broadcast %r from %s\n" % (
                line, pdu.pduSource,
                ))


#
#   __main__
#

try:
    # parse the command line arguments
    parser = ArgumentParser(description=__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)
Beispiel #33
0
        rslt = random.random() * iocb.args[0]

        # send back the result
        self.complete_io(iocb, rslt)

#
#   __main__
#

try:
    # create a parser
    parser = ArgumentParser(description=__doc__)

    # add an option to pick a controller
    parser.add_argument('--controller',
        help="controller name",
        default=CONTROLLER,
        )

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

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

    # this is an IO server
    IOServer()

    # create a test controller
    TestController(args.controller)

    _log.debug("running")
Beispiel #34
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 #35
0
        # send back the result
        self.complete_io(iocb, rslt)


#
#   __main__
#

try:
    # create a parser
    parser = ArgumentParser(description=__doc__)

    # add an option to pick a controller
    parser.add_argument(
        '--controller',
        help="controller name",
        default=CONTROLLER,
    )

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

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

    # this is an IO server
    IOServer()

    # create a test controller
    TestController(args.controller)
Beispiel #36
0
from csv import DictReader
import logging

from utils import createDaemon

#---------------------------------------------------------------------------#
# configure the service logging
#---------------------------------------------------------------------------#
# some debugging
_debug = 0
_log = ModuleLogger(globals())

import struct

parser = ArgumentParser(description='Run a test pymodbus driver')
parser.add_argument('config', help='device registry configuration')
parser.add_argument(
    'interface',
    help=
    'interface address and optionally the port and subnet mask for the device to listen on'
)
parser.add_argument('--no-daemon',
                    help='do not create a daemon process',
                    action='store_true')
parser.add_argument('--device-id',
                    help='specify the BACnet device id of the device.',
                    type=int,
                    default=1000)
args = parser.parse_args()

        # success
        return npdu


#
#   __main__
#

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

    # add an argument for interval
    parser.add_argument(
        'packet',
        type=str,
        nargs='+',
        help='packet contents in hex',
    )

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

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

    for data in args.packet:
        packet = decode_packet(data)
        packet.debug_contents()

except KeyboardInterrupt:
    pass
Beispiel #38
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 #39
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")
Beispiel #40
0
from csv import DictReader
import logging

from utils import createDaemon

#---------------------------------------------------------------------------# 
# configure the service logging
#---------------------------------------------------------------------------# 
# some debugging
_debug = 0
_log = ModuleLogger(globals())

import struct

parser = ArgumentParser(description='Run a test pymodbus driver')
parser.add_argument('config', help='device registry configuration')
parser.add_argument('interface', help='interface address and optionally the port and subnet mask for the device to listen on')
parser.add_argument('--no-daemon', help='do not create a daemon process', action='store_true')
parser.add_argument('--device-id', help='specify the BACnet device id of the device.', type=int, default=1000)
args = parser.parse_args()


class Register(object):
    def __init__(self, point_name, instance_number, object_type, property_name, read_only):
        self.read_only = read_only
        self.register_type = "byte"
        self.property_name = property_name
        self.object_type = object_type
        self.instance_number = int(instance_number)
        self.point_name = point_name
    
Beispiel #41
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 #42
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 #43
0
            self.response(PDU(repr(iocb.ioError) + '\n'))

        else:
            raise RuntimeError, "invalid state: %r" % (iocb.ioState,)

#
#   __main__
#

try:
    # create a parser
    parser = ArgumentParser(description=__doc__)

    # add an option to pick a server
    parser.add_argument('--server',
        help="server name or address",
        default=SERVER,
        )

    # add an option to pick a controller
    parser.add_argument('--controller',
        help="controller name",
        default=CONTROLLER,
        )

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

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

    # create a proxy for the real server
Beispiel #44
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")
            )
            whoIsTraffic[key] += 1

        # check for I-Am
        elif isinstance(pkt, IAmRequest):
            key = (pkt.pduSource, pkt.iAmDeviceIdentifier[1])
            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)
Beispiel #46
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)
Beispiel #47
0
        sys.stdout.write("%d woof!\n" % (self.dog_number, ))


#
#   __main__
#

try:
    # 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)
Beispiel #48
0
from csv import DictReader
import logging

from utils import createDaemon

#---------------------------------------------------------------------------#
# configure the service logging
#---------------------------------------------------------------------------#
# some debugging
_debug = 0
_log = ModuleLogger(globals())

import struct

parser = ArgumentParser(description='Run a test pymodbus driver')
parser.add_argument('config', help='device registry configuration')
parser.add_argument(
    'interface',
    help='interface address and optionally the port for the device to listen on'
)
args = parser.parse_args()

MODBUS_REGISTER_SIZE = 2


class Register(object):
    def __init__(self, point_name, instance_number, object_type, property_name,
                 read_only):
        self.read_only = read_only
        self.register_type = "byte"
        self.property_name = property_name
Beispiel #49
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 #50
0
    def process_task(self):
        if _debug: PrairieDog._debug("process_task")

        sys.stdout.write("%d woof!\n" % (self.dog_number,))

#
#   __main__
#

try:
    # 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")
Beispiel #51
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 #52
0
        # bind the bottom layers
        bind(self.bip, self.annexj, self.mux.annexJ)

        # bind the BIP stack to the local network
        self.nsap.bind(self.bip, local_network, local_address)

#
#   __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',
Beispiel #53
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 #54
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 #55
0
        # bind the BIP stack to the local network
        self.nsap.bind(self.bip, local_network, local_address)


#
#   __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',
Beispiel #56
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")