def main(): # parse the command line arguments parser = ArgumentParser(usage=__doc__) args = parser.parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # make a network network = IPNetwork() console = ConsoleClient() middle_man = MiddleMan() bip = BIPSimple() annexj = AnnexJCodec() mux = FauxMultiplexer("192.168.0.1/24", network) bind(console, middle_man, bip, annexj, mux) # add some more debugging nodes for i in range(2, 4): debug_address = "192.168.0.{}/24".format(i) debug_debug = Debug(debug_address) debug_bip = BIPSimple() debug_annexj = AnnexJCodec() debug_mux = FauxMultiplexer(debug_address, network) bind(debug_debug, debug_bip, debug_annexj, debug_mux) _log.debug("running") run() _log.debug("fini")
def __init__(self, address, vlan): if _debug: BIPBBMDStateMachine._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: BIPBBMDStateMachine._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, localNetwork, localAddress): if _debug: TestRouter._debug("__init__ %r", localAddress) # 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 generic BIP stack, bound to the Annex J server # on the UDP multiplexer self.bip = BIPSimple() self.annexj = AnnexJCodec() self.mux = UDPMultiplexer(localAddress) # bind the bottom layers bind(self.bip, self.annexj, self.mux.annexJ) # bind the BIP stack to localNetwork self.nsap.bind(self.bip, localNetwork, localAddress) # create a multiplexer for the service self.mux = TCPClientMultiplexer() # create the service, use 90 as the "hidden" network self.r2rService = RouterToRouterService(self.mux, self.nsap, 90)
def __init__(self, local_address, local_network, vlan_address, vlan_network): if _debug: VLANRouter._debug("__init__ %r %r %r %r", local_address, local_network, vlan_address, vlan_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 generic BIP stack, bound to the Annex J server # on the UDP multiplexer self.bip = BIPSimple() 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) # create a vlan node self.vlan_node = Node(vlan_address) # bind the stack to the vlan network self.nsap.bind(self.vlan_node, vlan_network)
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) #ADDED #from WhoIsIAmForeign ForeignApplication # create a generic BIP stack, bound to the Annex J server # on the UDP multiplexer self.bip = BIPForeign(Address('BBMD_ADDR'), 30) self.annexj = AnnexJCodec() self.mux = UDPMultiplexer(local_address, noBroadcast=True) #end # self.bip.add_peer(Address(BBMD_ADDR)) #ADDED # 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, 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, 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, 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, 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 setup_method(self, method): """This function is called before each test method is called as is given a reference to the test method.""" if _debug: TestAnnexJCodec._debug("setup_method %r", method) # minature trapped stack self.client = TrappedClient() self.codec = AnnexJCodec() self.server = TrappedServer() bind(self.client, self.codec, self.server)
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, 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, addr2)
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 __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, 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, 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, localDevice, localAddress, aseID=None): if _debug: TestProxyApplication._debug("__init__ %r %r aseID=%r", localDevice, localAddress, aseID) Application.__init__(self, localDevice, localAddress, 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(localDevice) # 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 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 network 5, the 'local' network self.nsap.bind(self.bip, 5, self.localAddress) # create a multiplexer for the service self.mux = TCPServerMultiplexer(self.localAddress) # proxy connections are bound to the nsap self.proxyServer = TestProxyServer(self.mux, self.nsap)
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 __init__(self, local_address: Address, local_network: int): if _debug: # pylint: disable=no-member # type: ignore _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, localDevice, localAddress, deviceInfoCache=None, aseID=None): if _debug: ReadPointListApplication._debug( "__init__ %r %r deviceInfoCache=%r aseID=%r", localDevice, localAddress, deviceInfoCache, aseID) global args Application.__init__(self, localDevice, deviceInfoCache, aseID=aseID) RecurringTask.__init__(self, args.interval * 1000) # 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 = NetworkServiceElement() 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) # install the task self.install_task() # timer self.start_time = None # pending requests self.pending_requests = {}
def __init__( self, localDevice, localAddress, bbmdAddress=None, bbmdTTL=0, deviceInfoCache=None, aseID=None, iam_req=None, ): ApplicationIOController.__init__(self, localDevice, deviceInfoCache, aseID=aseID) self.iam_req = iam_req # 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 = NetworkServiceElementWithRequests() 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 = BIPForeign(bbmdAddress, bbmdTTL) self.annexj = AnnexJCodec() self.mux = UDPMultiplexer(self.localAddress, noBroadcast=True) # bind the bottom layers bind(self.bip, self.annexj, self.mux.annexJ) # bind the NSAP to the stack, no network number self.nsap.bind(self.bip) self.i_am_counter = defaultdict(int) self.who_is_counter = defaultdict(int) # keep track of requests to line up responses self._request = None self._last_i_am_received = []
if '--port' in sys.argv: indx = sys.argv.index('--port') addr += ':' + sys.argv[indx + 1] del sys.argv[indx:indx + 2] _log.debug(" - addr: %r", addr) # a network service access point will be needed nsap = NetworkServiceAccessPoint() # give the NSAP a generic network layer service element nse = NetworkServiceElement() bind(nse, nsap) # create a generic BIP stack, bound to the Annex J server on the UDP multiplexer bip = BIPSimple() annexj = AnnexJCodec() udpmux = UDPMultiplexer(Address(addr)) # we need a way to make outgoing TCP connections and manage the proxy client service state tcpmux = TCPClientMultiplexer() # get the address of the server server_address = Address(sys.argv[1]) _log.debug(" - server_address: %r", server_address) # create a ProxyClientService proxy_client = ProxyClientService(tcpmux, server_address, testUser) # bind everything together bind(proxy_client, bip, annexj, udpmux.annexJ)