def __init__(self, vlan_device, vlan_address, aseID=None): if _debug: VLANApplication._debug("__init__ %r %r aseID=%r", vlan_device, vlan_address, aseID) Application.__init__(self, vlan_device, vlan_address, aseID) # include a application decoder self.asap = ApplicationServiceAccessPoint() # pass the device object to the state machine access point so it # can know if it should support segmentation self.smap = StateMachineAccessPoint(vlan_device) # a network service access point will be needed self.nsap = NetworkServiceAccessPoint() # give the NSAP a generic network layer service element self.nse = NetworkServiceElement() bind(self.nse, self.nsap) # bind the top layers bind(self, self.asap, self.smap, self.nsap) # create a vlan node at the assigned address self.vlan_node = Node(vlan_address) # bind the stack to the node, no network number self.nsap.bind(self.vlan_node)
def setup_module(): if _debug: setup_module._debug("setup_module") global sap, ase # verify the echo access point is trapped correctly assert TrappedEchoAccessPoint.__mro__ == ( TrappedEchoAccessPoint, TrappedServiceAccessPoint, EchoAccessPoint, ServiceAccessPoint, object, ) # create an access point sap = TrappedEchoAccessPoint() # verify the echo service element is trapped correctly assert TrappedEchoServiceElement.__mro__ == ( TrappedEchoServiceElement, TrappedApplicationServiceElement, EchoServiceElement, ApplicationServiceElement, object, ) # create a service element ase = TrappedEchoServiceElement() # bind them together bind(ase, sap)
def test_server_state_machine(self): if _debug: TestServerStateMachine._debug("test_server_state_machine") # create a client state machine, trapped server, and bind them together client = TrappedClient() server = ServerStateMachine() bind(client, server) # make pdu object pdu = object() # make a send transition from start to success, run the machine server.start_state.send(pdu).success() # run the machine server.run() # check for success assert not server.running assert server.current_state.is_success_state # make sure the pdu was sent assert client.confirmation_received is pdu # check the transaction log assert len(server.transaction_log) == 1 assert server.transaction_log[0][1] is pdu
def __init__(self, host='', port=502, **kwargs): if _debug: ModbusServer._debug("__init__ host=%r port=%r %r", host, port, kwargs) Client.__init__(self) Server.__init__(self) # create and bind self.serverDirector = TCPServerDirector((host, port), **kwargs) bind(self, StreamToPacket(stream_to_packet), self.serverDirector)
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()
def __init__(self, **kwargs): """Initialize a MODBUS client.""" if _debug: ModbusClient._debug("__init__ %r", kwargs) Client.__init__(self) Server.__init__(self) # create and bind the client side self.director = TCPClientDirector(**kwargs) bind(self, StreamToPacket(stream_to_packet), self.director)
def main(): print "test start" s = MyServer() c = MyClient() d = Debug("packet") bind(c,d,s) c.request("hi") pdu = PDU("hello", source = 1, destination = 2) pdu.debug_contents()
def __init__(self, addr=('', PORT)): """Initialize the remote IO handler.""" if _debug: IOServer._debug("__init__ %r", addr) IOController.__init__(self) # create a UDP director self.server = UDPDirector(addr) bind(self, self.server) # dictionary of IOCBs as a server self.remoteIOCB = {}
def __init__(self, addr=('',PORT)): """Initialize the remote IO handler.""" if _debug: IOServer._debug("__init__ %r", addr) IOController.__init__(self) # create a UDP director self.server = UDPDirector(addr) bind(self, self.server) # dictionary of IOCBs as a server self.remoteIOCB = {}
def __init__(self, address, vlan): if _debug: ApplicationLayerStateMachine._debug("__init__ %r %r", address, vlan) # build a name, save the address self.name = "app @ %s" % (address, ) self.address = Address(address) # build a local device object local_device = TestDeviceObject( objectName=self.name, objectIdentifier=('device', int(address)), vendorIdentifier=999, ) # build an address and save it self.address = Address(address) if _debug: ApplicationLayerStateMachine._debug(" - address: %r", self.address) # continue with initialization ApplicationServiceElement.__init__(self) ClientStateMachine.__init__(self, name=local_device.objectName) # include a application decoder self.asap = ApplicationServiceAccessPoint() # pass the device object to the state machine access point so it # can know if it should support segmentation self.smap = StateMachineAccessPoint(local_device) # the segmentation state machines need access to some device # information cache, usually shared with the application self.smap.deviceInfoCache = DeviceInfoCache() # a network service access point will be needed self.nsap = NetworkServiceAccessPoint() # give the NSAP a generic network layer service element self.nse = _NetworkServiceElement() bind(self.nse, self.nsap) # bind the top layers bind(self, self.asap, self.smap, self.nsap) # create a node, added to the network self.node = Node(self.address, vlan) if _debug: ApplicationLayerStateMachine._debug(" - node: %r", self.node) # bind the stack to the local network self.nsap.bind(self.node)
def __init__(self, addr=('', 0), name=None): """Initialize the remote IO handler.""" if _debug: IOProxyServer._debug("__init__") IOController.__init__(self, name=name) # create a UDP director self.server = UDPDirector(addr) bind(self, self.server) if _debug: IOProxyServer._debug(" - bound to %r", self.server.socket.getsockname()) # dictionary of IOCBs as a client self.localIOCB = {}
def __init__(self, connect_timeout=None, idle_timeout=None): if _debug: ModbusClientController._debug("__init__") SieveClientController.__init__(self) # create and bind to a client which is already bound to a director self.client = ModbusClient(connect_timeout=connect_timeout, idle_timeout=idle_timeout) bind(self, self.client) # create an application service element referencing this controller and # bound to the TCPClientDirector self.client_ase = ModbusClientASE(self) bind(self.client_ase, self.client.director)
def __init__(self, objectName, deviceInstance, address, aseID=None): if _debug: VLANApplication._debug("__init__ %r %r %r aseID=%r", objectName, deviceInstance, address, aseID) # make an address vlan_address = Address(address) _log.debug(" - vlan_address: %r", vlan_address) # make a device object vlan_device = LocalDeviceObject( objectName=objectName, objectIdentifier=("device", deviceInstance), maxApduLengthAccepted=1024, segmentationSupported="noSegmentation", vendorIdentifier=15, ) _log.debug(" - vlan_device: %r", vlan_device) # continue with the initialization Application.__init__(self, vlan_device, vlan_address, aseID) # include a application decoder self.asap = ApplicationServiceAccessPoint() # pass the device object to the state machine access point so it # can know if it should support segmentation self.smap = StateMachineAccessPoint(vlan_device) # the segmentation state machines need access to the same device # information cache as the application self.smap.deviceInfoCache = self.deviceInfoCache # a network service access point will be needed self.nsap = NetworkServiceAccessPoint() # give the NSAP a generic network layer service element self.nse = NetworkServiceElement() bind(self.nse, self.nsap) # bind the top layers bind(self, self.asap, self.smap, self.nsap) # create a vlan node at the assigned address self.vlan_node = Node(vlan_address) if _debug: VLANApplication._debug(" - vlan_node: %r", self.vlan_node) # bind the stack to the node, no network number self.nsap.bind(self.vlan_node) if _debug: VLANApplication._debug(" - node bound")
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()
def __init__(self, localDevice, addr=None, noBroadcast=False): if _debug: MSTPMultiplexer._debug("__init__ %r noBroadcast=%r", addr, noBroadcast) self.address = addr self.localDevice = localDevice # create and bind the direct address self.direct = _MultiplexClient(self) self.directPort = MSTPDirector(self.localDevice, self.address) bind(self.direct, self.directPort) # create and bind the Annex H and J servers self.annexH = _MultiplexServer(self)
def __init__(self, port=502, sapID=None): if _debug: ModbusServiceAccessPoint._debug("__init__ port=%r sapID=%r", port, sapID) Client.__init__(self) Server.__init__(self) ServiceAccessPoint.__init__(self, sapID) # create and bind the client side self.clientDirector = TCPClientDirector() bind(self, StreamToPacket(stream_to_packet), self.clientDirector) # create and bind the server side self.serverDirector = TCPServerDirector(port) bind(self.serverDirector, StreamToPacket(stream_to_packet), self)
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")
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")
def __init__(self, addr, network, cid=None, sid=None): if _debug: FauxMux._debug("__init__") Client.__init__(self, cid) Server.__init__(self, sid) # get the unicast and broadcast tuples self.unicast_tuple = addr.addrTuple self.broadcast_tuple = addr.addrBroadcastTuple # make an internal node and bind to it, this takes the place of # both the direct port and broadcast port of the real UDPMultiplexer self.node = IPNode(addr, network) bind(self, self.node)
def __init__(self, address, vlan): if _debug: SnifferNode._debug("__init__ %r %r", address, vlan) ClientStateMachine.__init__(self) # save the name and address self.name = address self.address = Address(address) # create a promiscuous node, added to the network self.node = IPNode(self.address, vlan, promiscuous=True) if _debug: SnifferNode._debug(" - node: %r", self.node) # bind this to the node bind(self, self.node)
def __init__(self, node_count): if _debug: TNetwork._debug("__init__ %r", node_count) StateMachineGroup.__init__(self) self.vlan = Network(broadcast_address=0) for i in range(node_count): node = Node(i + 1, self.vlan) # bind a client state machine to the node csm = ClientStateMachine() bind(csm, node) # add it to this group self.append(csm)
def __init__(self, vlan): if _debug: SnifferNode._debug("__init__ %r", vlan) # save the name and give it a blank address self.name = "sniffer" self.address = Address() # continue with initialization Client.__init__(self) # create a promiscuous node, added to the network self.node = Node(self.address, vlan, promiscuous=True) if _debug: SnifferNode._debug(" - node: %r", self.node) # bind this to the node bind(self, self.node)
def __init__(self, address, vlan): if _debug: CodecNode._debug("__init__ %r %r", address, vlan) ClientStateMachine.__init__(self) # save the name and address self.name = address self.address = Address(address) # BACnet/IP interpreter self.annexj = AnnexJCodec() # fake multiplexer has a VLAN node in it self.mux = FauxMultiplexer(self.address, vlan) # bind the stack together bind(self, self.annexj, self.mux)
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")
def __init__(self, node_count, address_pattern): if _debug: TNetwork._debug("__init__ %r", node_count) StateMachineGroup.__init__(self) self.vlan = IPNetwork() for i in range(node_count): node_address = Address(address_pattern.format(i + 1)) node = IPNode(node_address, self.vlan) if _debug: TNetwork._debug(" - node: %r", node) # bind a client state machine to the node csm = ClientStateMachine() bind(csm, node) # add it to this group self.append(csm)
def __init__(self, address, vlan): if _debug: NetworkLayerNode._debug("__init__ %r %r", address, vlan) ClientStateMachine.__init__(self) # save the name and address self.name = address self.address = Address(address) # create a network layer encoder/decoder self.codec = NPDUCodec() if _debug: SnifferNode._debug(" - codec: %r", self.codec) # create a node, added to the network self.node = Node(self.address, vlan) if _debug: SnifferNode._debug(" - node: %r", self.node) # bind this to the node bind(self, self.codec, self.node)
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()
def __init__(self, addr): if _debug: TestBBMD._debug("TestBBMD %r", addr) BIPBBMD.__init__(self, addr) # save the address self.address = addr # make the lower layers self.annexj = AnnexJCodec() self.mux = UDPMultiplexer(self.address) # bind the bottom layers bind(self, self.annexj, self.mux.annexJ) # give this a generic network layer service access point and element self.nsap = NetworkServiceAccessPoint() self.nse = NetworkServiceElement() self.nsap.bind(self) bind(self.nse, self.nsap)
def __init__(self, localDevice, vlan): if _debug: ApplicationStateMachine._debug("__init__ %r %r", localDevice, vlan) # build an address and save it self.address = Address(localDevice.objectIdentifier[1]) if _debug: ApplicationStateMachine._debug(" - address: %r", self.address) # continue with initialization Application.__init__(self, localDevice, self.address) StateMachine.__init__(self, name=localDevice.objectName) # include a application decoder self.asap = ApplicationServiceAccessPoint() # pass the device object to the state machine access point so it # can know if it should support segmentation self.smap = StateMachineAccessPoint(localDevice) # the segmentation state machines need access to the same device # information cache as the application self.smap.deviceInfoCache = self.deviceInfoCache # a network service access point will be needed self.nsap = NetworkServiceAccessPoint() # give the NSAP a generic network layer service element self.nse = NetworkServiceElement() bind(self.nse, self.nsap) # bind the top layers bind(self, self.asap, self.smap, self.nsap) # create a node, added to the network self.node = Node(self.address, vlan) # bind the network service to the node, no network number self.nsap.bind(self.node) # placeholder for the result block self.confirmed_private_result = None
def __init__(self, vlan_device, vlan_address, aseID=None): if _debug: VLANApplication._debug("__init__ %r %r aseID=%r", vlan_device, vlan_address, aseID) ApplicationIOController.__init__(self, vlan_device, vlan_address, aseID=aseID) # include a application decoder self.asap = ApplicationServiceAccessPoint() # pass the device object to the state machine access point so it # can know if it should support segmentation self.smap = StateMachineAccessPoint(vlan_device) # the segmentation state machines need access to the same device # information cache as the application self.smap.deviceInfoCache = self.deviceInfoCache # a network service access point will be needed self.nsap = NetworkServiceAccessPoint() # give the NSAP a generic network layer service element self.nse = NetworkServiceElement() bind(self.nse, self.nsap) # bind the top layers bind(self, self.asap, self.smap, self.nsap) # create a vlan node at the assigned address self.vlan_node = Node(vlan_address) # bind the stack to the node, no network number self.nsap.bind(self.vlan_node, address=vlan_address) # keep track of requests to line up responses self._request = None if _debug: VLANApplication._debug(" - nsap.local_address: %r", self.nsap.local_address)
def __init__(self, address, vlan): if _debug: SnifferStateMachine._debug("__init__ %r %r", address, vlan) ClientStateMachine.__init__(self) # save the name and address self.name = address self.address = Address(address) # BACnet/IP interpreter self.annexj = AnnexJCodec() # fake multiplexer has a VLAN node in it self.mux = FauxMultiplexer(self.address, vlan) # might receive all packets and allow spoofing self.mux.node.promiscuous = True self.mux.node.spoofing = True # bind the stack together bind(self, self.annexj, self.mux)
def __init__(self, local_address, local_network): if _debug: VLANRouter._debug("__init__ %r %r", local_address, local_network) # a network service access point will be needed self.nsap = NetworkServiceAccessPoint() # give the NSAP a generic network layer service element self.nse = NetworkServiceElement() bind(self.nse, self.nsap) # create a BBMD, bound to the Annex J server # on the UDP multiplexer self.bip = BIPBBMD(local_address) self.annexj = AnnexJCodec() self.mux = UDPMultiplexer(local_address) # 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)
def __init__(self, local_address, local_network): if _debug: VLANRouter._debug("__init__ %r %r", local_address, local_network) # a network service access point will be needed self.nsap = NetworkServiceAccessPoint() # give the NSAP a generic network layer service element self.nse = NetworkServiceElement() bind(self.nse, self.nsap) # create a BIPSimple, bound to the Annex J server # on the UDP multiplexer self.bip = BIPSimple(local_address) self.annexj = AnnexJCodec() self.mux = UDPMultiplexer(local_address) # 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)
def __init__(self, vlan_device, vlan_address, aseID=None, register_reader=None): if _debug: VLANApplication._debug("__init__ %r %r aseID=%r", vlan_device, vlan_address, aseID) Application.__init__(self, vlan_device, vlan_address, aseID) # include a application decoder self.asap = ApplicationServiceAccessPoint() # pass the device object to the state machine access point so it # can know if it should support segmentation self.smap = StateMachineAccessPoint(vlan_device) # the segmentation state machines need access to the same device # information cache as the application self.smap.deviceInfoCache = self.deviceInfoCache # a network service access point will be needed self.nsap = NetworkServiceAccessPoint() # give the NSAP a generic network layer service element self.nse = NetworkServiceElement() bind(self.nse, self.nsap) # bind the top layers bind(self, self.asap, self.smap, self.nsap) # create a vlan node at the assigned address self.vlan_node = Node(vlan_address) # bind the stack to the node, no network number self.nsap.bind(self.vlan_node) # set register reader class that will look into block of registers for all associated slaves self.register_reader = register_reader
def __init__(self, address, vlan): if _debug: BIPSimpleApplicationLayerStateMachine._debug( "__init__ %r %r", address, vlan) # build a name, save the address self.name = "app @ %s" % (address, ) self.address = Address(address) # build a local device object local_device = TestDeviceObject( objectName=self.name, objectIdentifier=('device', 998), vendorIdentifier=999, ) # build an address and save it self.address = Address(address) if _debug: BIPSimpleApplicationLayerStateMachine._debug( " - address: %r", self.address) # continue with initialization ApplicationServiceElement.__init__(self) ClientStateMachine.__init__(self, name=local_device.objectName) # include a application decoder self.asap = ApplicationServiceAccessPoint() # pass the device object to the state machine access point so it # can know if it should support segmentation self.smap = StateMachineAccessPoint(local_device) # the segmentation state machines need access to some device # information cache, usually shared with the application self.smap.deviceInfoCache = DeviceInfoCache() # a network service access point will be needed self.nsap = NetworkServiceAccessPoint() # give the NSAP a generic network layer service element self.nse = _NetworkServiceElement() bind(self.nse, self.nsap) # bind the top layers bind(self, self.asap, self.smap, self.nsap) # BACnet/IP interpreter self.bip = BIPSimple() self.annexj = AnnexJCodec() # fake multiplexer has a VLAN node in it self.mux = FauxMultiplexer(self.address, vlan) # bind the stack together bind(self.bip, self.annexj, self.mux) # bind the stack to the local network self.nsap.bind(self.bip)
def __init__(self, vlan_device, vlan_address, aseID=None): if _debug: VLANConsoleApplication._debug("__init__ %r %r aseID=%r", vlan_device, vlan_address, aseID) global args # normal initialization ApplicationIOController.__init__(self, vlan_device, aseID=aseID) # optional read property multiple if args.rpm: self.add_capability(ReadWritePropertyMultipleServices) # include a application decoder self.asap = ApplicationServiceAccessPoint() # pass the device object to the state machine access point so it # can know if it should support segmentation self.smap = StateMachineAccessPoint(vlan_device) # the segmentation state machines need access to the same device # information cache as the application self.smap.deviceInfoCache = self.deviceInfoCache # a network service access point will be needed self.nsap = NetworkServiceAccessPoint() # give the NSAP a generic network layer service element self.nse = NetworkServiceElement() bind(self.nse, self.nsap) # bind the top layers bind(self, self.asap, self.smap, self.nsap) # create a vlan node at the assigned address self.vlan_node = Node(vlan_address) # bind the stack to the node, no network number, no addresss self.nsap.bind(self.vlan_node)
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")
def __init__(self, lan, addr1, net1): if _debug: VLANRouter._debug("__init__ %r %r %r", lan, addr1, net1) # a network service access point will be needed self.nsap = NetworkServiceAccessPoint() # give the NSAP a generic network layer service element self.nse = NetworkServiceElement() bind(self.nse, self.nsap) # create an MQTT client self.msap = bacpypes_mqtt.MQTTClient( lan, addr1, args.host, port=args.port, keepalive=args.keepalive ) # create a service element for the client self.mse = bacpypes_mqtt.MQTTServiceElement() bind(self.mse, self.msap) # bind to the MQTT network self.nsap.bind(self.msap, net1)
def __init__(self, address, vlan): if _debug: BIPBBMDApplication._debug("__init__ %r %r", address, vlan) # build a name, save the address self.name = "app @ %s" % (address,) self.address = Address(address) if _debug: BIPBBMDApplication._debug(" - address: %r", self.address) # build a local device object local_device = TestDeviceObject( objectName=self.name, objectIdentifier=('device', 999), vendorIdentifier=999, ) # continue with initialization Application.__init__(self, local_device, self.address) # include a application decoder self.asap = ApplicationServiceAccessPoint() # pass the device object to the state machine access point so it # can know if it should support segmentation self.smap = StateMachineAccessPoint(local_device) # the segmentation state machines need access to the same device # information cache as the application self.smap.deviceInfoCache = self.deviceInfoCache # a network service access point will be needed self.nsap = NetworkServiceAccessPoint() # give the NSAP a generic network layer service element self.nse = NetworkServiceElement() bind(self.nse, self.nsap) # bind the top layers bind(self, self.asap, self.smap, self.nsap) # BACnet/IP interpreter self.bip = BIPBBMD(self.address) self.annexj = AnnexJCodec() # build an address, full mask bdt_address = "%s/32:%d" % self.address.addrTuple if _debug: BIPBBMDNode._debug(" - bdt_address: %r", bdt_address) # add itself as the first entry in the BDT self.bip.add_peer(Address(bdt_address)) # fake multiplexer has a VLAN node in it self.mux = FauxMultiplexer(self.address, vlan) # bind the stack together bind(self.bip, self.annexj, self.mux) # bind the stack to the local network self.nsap.bind(self.bip)
def __init__(self, local_address, local_network, foreign_address, bbmd_ttl=30, rebootQueue=None): if _debug: VLANRouter._debug("__init__ %r %r", local_address, local_network) if isinstance(local_address, Address): self.local_address = local_address else: self.local_address = Address(local_address) if isinstance(foreign_address, Address): self.foreign_address = foreign_address else: self.foreign_address = Address(foreign_address) # a network service access point will be needed self.nsap = NetworkServiceAccessPoint() # give the NSAP a generic network layer service element self.nse = NetworkServiceElement() bind(self.nse, self.nsap) # create a BBMD, bound to the Annex J server # on the UDP multiplexer # from WhoIsIAmForeign ForeignApplication # create a generic BIP stack, bound to the Annex J server # on the UDP multiplexer self.bip = BIPForeign(self.foreign_address, bbmd_ttl) # self.bip = BIPForeign(Address('10.166.1.72'), 30) # self.bip = BIPForeign(Address('192.168.1.10'), 30) # self.bip = BIPForeign(Address('130.91.139.99'), 30) self.annexj = AnnexJCodec() # noBroadcast=True stops bcast to local ntwrk self.mux = UDPMultiplexer(self.local_address, noBroadcast=True, rebootQueue=rebootQueue) # 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, self.local_address)
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")
def __init__(self, localDevice, localAddress, deviceInfoCache=None, aseID=None): if _debug: DiscoverApplication._debug( "__init__ %r %r deviceInfoCache=%r aseID=%r", localDevice, localAddress, deviceInfoCache, aseID) ApplicationIOController.__init__(self, localDevice, localAddress, deviceInfoCache, aseID=aseID) # local address might be useful for subclasses if isinstance(localAddress, Address): self.localAddress = localAddress else: self.localAddress = Address(localAddress) # include a application decoder self.asap = ApplicationServiceAccessPoint() # pass the device object to the state machine access point so it # can know if it should support segmentation self.smap = StateMachineAccessPoint(localDevice) # the segmentation state machines need access to the same device # information cache as the application self.smap.deviceInfoCache = self.deviceInfoCache # a network service access point will be needed self.nsap = NetworkServiceAccessPoint() # give the NSAP a generic network layer service element self.nse = DiscoverNetworkServiceElement() bind(self.nse, self.nsap) # bind the top layers bind(self, self.asap, self.smap, self.nsap) # create a generic BIP stack, bound to the Annex J server # on the UDP multiplexer self.bip = BIPSimple() self.annexj = AnnexJCodec() self.mux = UDPMultiplexer(self.localAddress) # bind the bottom layers bind(self.bip, self.annexj, self.mux.annexJ) # bind the BIP stack to the network, no network number self.nsap.bind(self.bip, address=self.localAddress) # keep track of requests to line up responses self._request = None
def __init__(self, address, vlan): if _debug: BBMDNode._debug("__init__ %r %r", address, vlan) ClientStateMachine.__init__(self) # save the name and address self.name = address self.address = Address(address) # BACnet/IP interpreter self.bip = BIPBBMD(self.address) self.annexj = AnnexJCodec() # build an address, full mask bdt_address = "%s/32:%d" % self.address.addrTuple if _debug: BBMDNode._debug(" - bdt_address: %r", bdt_address) # add itself as the first entry in the BDT self.bip.add_peer(Address(bdt_address)) # fake multiplexer has a VLAN node in it self.mux = FauxMultiplexer(self.address, vlan) # bind the stack together bind(self, self.bip, self.annexj, self.mux)
def __init__(self, addr1, port1, net1, addr2, port2, net2): if _debug: NATRouter._debug("__init__ %r %r %r %r %r %r", addr1, port1, net1, addr2, port2, net2) # a network service access point will be needed self.nsap = NetworkServiceAccessPoint() # give the NSAP a generic network layer service element self.nse = NetworkServiceElement() bind(self.nse, self.nsap) #== First stack # local address local_addr = Address("{}:{}".format(addr1, port1)) # create a BBMD stack self.s1_bip = BIPBBMD(local_addr) self.s1_annexj = AnnexJCodec() self.s1_mux = UDPMultiplexer(local_addr) # bind the bottom layers bind(self.s1_bip, self.s1_annexj, self.s1_mux.annexJ) # bind the BIP stack to the local network self.nsap.bind(self.s1_bip, net1, local_addr) #== Second stack # global address global_addr = Address(addr2) nat_addr = Address("{}:{}".format(addr1, port2)) # create a NAT stack self.s2_bip = BIPNAT(global_addr) self.s2_annexj = AnnexJCodec() self.s2_mux = UDPMultiplexer(nat_addr) # bind the bottom layers bind(self.s2_bip, self.s2_annexj, self.s2_mux.annexJ) # bind the BIP stack to the global network self.nsap.bind(self.s2_bip, net2, global_addr)
def __init__(self, lan, addr1, net1, addr2, net2): if _debug: MQTT2IPRouter._debug("__init__ %r %r %r %r %r", lan, addr1, net1, addr2, net2) global args # a network service access point will be needed self.nsap = NetworkServiceAccessPoint() # give the NSAP a generic network layer service element self.nse = NetworkServiceElement() bind(self.nse, self.nsap) #== First stack # create an MQTT client self.s1_msap = bacpypes_mqtt.MQTTClient(lan, addr1, args.host, port=args.port, keepalive=args.keepalive) # create a service element for the client self.s1_mse = bacpypes_mqtt.MQTTServiceElement() bind(self.s1_mse, self.s1_msap) # bind to the MQTT network self.nsap.bind(self.s1_msap, net1) #== Second stack # create a generic BIP stack, bound to the Annex J server # on the UDP multiplexer self.s2_bip = BIPSimple() self.s2_annexj = AnnexJCodec() self.s2_mux = UDPMultiplexer(addr2) # bind the bottom layers 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)
def __init__(self, addr1, net1, addr2, net2): if _debug: IP2IPRouter._debug("__init__ %r %r %r %r", addr1, net1, addr2, net2) # a network service access point will be needed self.nsap = NetworkServiceAccessPoint() # give the NSAP a generic network layer service element self.nse = NetworkServiceElement() bind(self.nse, self.nsap) # == First stack # create a generic BIP stack, bound to the Annex J server # on the UDP multiplexer self.s1_bip = BIPSimple() self.s1_annexj = AnnexJCodec() self.s1_mux = UDPMultiplexer(addr1) # bind the bottom layers bind(self.s1_bip, self.s1_annexj, self.s1_mux.annexJ) # bind the BIP stack to the local network self.nsap.bind(self.s1_bip, net1, addr1) # == Second stack # create a generic BIP stack, bound to the Annex J server # on the UDP multiplexer self.s2_bip = BIPSimple() self.s2_annexj = AnnexJCodec() self.s2_mux = UDPMultiplexer(addr2) # bind the bottom layers 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)
# create a client state machine, trapped server, and bind them together test_application = TestApplication(test_device, test_address) # include a application decoder test_asap = ApplicationServiceAccessPoint() # pass the device object to the state machine access point so it # can know if it should support segmentation test_smap = StateMachineAccessPoint(test_device) # state machine test_server = ServerStateMachine() # bind everything together bind(test_application, test_asap, test_smap, test_server) # ============================================================================== who_is_request = WhoIsRequest( deviceInstanceRangeLowLimit=0, deviceInstanceRangeHighLimit=4194303, ) print("who_is_request") who_is_request.debug_contents() print("") test_apdu = APDU() who_is_request.encode(test_apdu) print("test_apdu")
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")
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")
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 testServer = IOProxy(args.controller, args.server) console = ConsoleClient() middleMan = MiddleMan() bind(console, middleMan) _log.debug("running") run() except Exception, e: _log.exception("an error has occurred: %s", e) finally: _log.debug("finally")
#!/usr/bin/env python """ Simple implementation of a Client and Server """ from bacpypes.comm import Client, Server, bind class MyServer(Server): def indication(self, arg): print('working on', arg) self.response(arg.upper()) class MyClient(Client): def confirmation(self, pdu): print('thanks for the ', pdu) if __name__ == '__main__': c = MyClient() s = MyServer() bind(c, s) c.request('hi')
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)