def whois_router_to_network(self, args=None): # build a request try: request = WhoIsRouterToNetwork() if not args: request.pduDestination = LocalBroadcast() elif args[0].isdigit(): request.pduDestination = LocalBroadcast() request.wirtnNetwork = int(args[0]) else: request.pduDestination = Address(args[0]) if len(args) > 1: request.wirtnNetwork = int(args[1]) except: self._log.error("WhoIsRouterToNetwork : invalid arguments") return iocb = IOCB((self.this_application.nsap.local_adapter, request)) # make an IOCB iocb.set_timeout(2) deferred(self.this_application.nse.request_io, iocb) iocb.wait() try: self.init_routing_table(str( self.this_application.nse._iartn.pop())) except IndexError: pass
def do_wirtn(self, args): """ wirtn [ <addr> ] [ <net> ] Send a Who-Is-Router-To-Network message. If <addr> is not specified the message is locally broadcast. """ args = args.split() if _debug: DiscoverConsoleCmd._debug("do_wirtn %r", args) # build a request try: request = WhoIsRouterToNetwork() if not args: request.pduDestination = LocalBroadcast() elif args[0].isdigit(): request.pduDestination = LocalBroadcast() request.wirtnNetwork = int(args[0]) else: request.pduDestination = Address(args[0]) if (len(args) > 1): request.wirtnNetwork = int(args[1]) except: print("invalid arguments") return # give it to the network service element this_application.nse.request(this_application.nsap.local_adapter, request) # sleep for responses time.sleep(3.0)
def test_local_broadcast(self): if _debug: TestLocalBroadcast._debug("test_local_broadcast") # no parameters with self.assertRaises(TypeError): LocalBroadcast(1) test_addr = LocalBroadcast() self.match_address(test_addr, 1, None, None, None) assert str(test_addr) == "*"
def __init__(self): if _debug: TNetwork._debug("__init__") StateMachineGroup.__init__(self) # reset the time machine reset_time_machine() if _debug: TNetwork._debug(" - time machine reset") # create a traffic log self.traffic_log = TrafficLog() # implementation under test self.iut1 = RouterNode() # router from vlan1 to vlan2 self.iut2 = RouterNode() # router from vlan2 to vlan3 # make a little LAN self.vlan1 = Network(name="vlan1", broadcast_address=LocalBroadcast()) self.vlan1.traffic_log = self.traffic_log # sniffer node self.sniffer1 = SnifferStateMachine("1", self.vlan1) self.append(self.sniffer1) # connect vlan1 to iut1 self.iut1.add_network("2", self.vlan1, 1) # make another little LAN self.vlan2 = Network(name="vlan2", broadcast_address=LocalBroadcast()) self.vlan2.traffic_log = self.traffic_log # test device self.td = NetworkLayerStateMachine("3", self.vlan2) self.append(self.td) # sniffer node self.sniffer2 = SnifferStateMachine("4", self.vlan2) self.append(self.sniffer2) # connect vlan2 to both routers self.iut1.add_network("5", self.vlan2, 2) self.iut2.add_network("6", self.vlan2, 2) # make another little LAN self.vlan3 = Network(name="vlan3", broadcast_address=LocalBroadcast()) self.vlan3.traffic_log = self.traffic_log # sniffer node self.sniffer3 = SnifferStateMachine("7", self.vlan3) self.append(self.sniffer3) # connect vlan3 to the second router self.iut2.add_network("8", self.vlan3, 3)
def test_02(self): """Test broadcast for existing router.""" if _debug: TestWhoIsRouterToNetwork._debug("test_02") # create a network tnet = TNetwork() # all start states are successful tnet.td.start_state.doc("2-1-0") \ .send(WhoIsRouterToNetwork(2, destination=LocalBroadcast(), )).doc("2-1-1") \ .receive(IAmRouterToNetwork, iartnNetworkList=[2], ).doc("2-1-2") \ .success() tnet.sniffer1.start_state.success() # nothing received on network 2 tnet.sniffer2.start_state.doc("2-2-0") \ .timeout(3).doc("2-2-1") \ .success() tnet.sniffer3.start_state.success() # run the group tnet.run()
def __init__(self, test_name): if _debug: ApplicationNetwork._debug("__init__ %r", test_name) StateMachineGroup.__init__(self) # reset the time machine reset_time_machine() if _debug: ApplicationNetwork._debug(" - time machine reset") # create a traffic log self.traffic_log = TrafficLog() # make a little LAN self.vlan = Network(broadcast_address=LocalBroadcast()) self.vlan.traffic_log = self.traffic_log # test device object self.td_device_object = LocalDeviceObject( objectName="td", objectIdentifier=("device", 10), maxApduLengthAccepted=1024, segmentationSupported="noSegmentation", vendorIdentifier=999, ) # test device self.td = ApplicationStateMachine(self.td_device_object, self.vlan) self.append(self.td) # error device generates bad packets self.ed = ApplicationLayerStateMachine(20, self.vlan) self.append(self.ed)
def __init__(self, td_device_object, iut_device_object): if _debug: ApplicationNetwork._debug("__init__ %r %r", td_device_object, iut_device_object) StateMachineGroup.__init__(self) # reset the time machine reset_time_machine() if _debug: ApplicationNetwork._debug(" - time machine reset") # create a traffic log self.traffic_log = TrafficLog() # make a little LAN self.vlan = Network(broadcast_address=LocalBroadcast()) self.vlan.traffic_log = self.traffic_log # sniffer self.sniffer = SnifferNode(self.vlan) # test device self.td = ApplicationStateMachine(td_device_object, self.vlan) self.append(self.td) # implementation under test self.iut = ApplicationStateMachine(iut_device_object, self.vlan) self.append(self.iut)
def what_is_network_number(self, args=""): """ winn [ <addr> ] Send a What-Is-Network-Number message. If the address is unspecified the message is locally broadcast. """ args = args.split() # build a request try: request = WhatIsNetworkNumber() if len(args) > 0: request.pduDestination = Address(args[0]) else: request.pduDestination = LocalBroadcast() except: self._log.error( "Cannot build request (invalid arguments) : {}".format(args)) return iocb = IOCB((self.this_application.nsap.local_adapter, request)) # make an IOCB iocb.set_timeout(2) deferred(self.this_application.nse.request_io, iocb) iocb.wait()
def do_winn(self, args): """ winn [ <addr> ] Send a What-Is-Network-Number message. If the address is unspecified the message is locally broadcast. """ args = args.split() if _debug: DiscoverConsoleCmd._debug("do_winn %r", args) # build a request try: request = WhatIsNetworkNumber() if (len(args) > 0): request.pduDestination = Address(args[0]) else: request.pduDestination = LocalBroadcast() except: print("invalid arguments") return # give it to the network service element this_application.nse.request(this_application.nsap.local_adapter, request) # sleep for responses time.sleep(3.0)
def test_local_broadcast(self): """Local broadcast, no matching device.""" if _debug: TestUnconfirmedRequests._debug("test_local_broadcast") # create a network tnet = TNetwork() # test device sends request, no response tnet.td.start_state.doc("1-1-0") \ .send(WhoIsRequest( destination=LocalBroadcast(), )).doc("1-1-1") \ .timeout(3).doc("1-1-2") \ .success() # sniffer on network 1 sees the request and nothing else tnet.sniffer1.start_state.doc("1-2-0") \ .receive(PDU, pduData=xtob('01.00' # version, application layer '10 08' # unconfirmed Who-Is ) ).doc("1-2-1") \ .timeout(3).doc("1-2-2") \ .success() # no acitivity on network 2 tnet.sniffer2.start_state.success() # run the group tnet.run()
def test_broadcast(self): """Test a broadcast message from TD to IUT.""" if _debug: TestSimple._debug("test_broadcast") # create a network tnet = TNetwork() # make a PDU from node 1 to node 2 pdu_data = xtob('dead.beef') pdu = PDU(pdu_data, source=tnet.td.address, destination=LocalBroadcast()) if _debug: TestSimple._debug(" - pdu: %r", pdu) # test device sends it, iut gets it tnet.td.start_state.send(pdu).success() tnet.iut.start_state.receive(PDU, pduSource=tnet.td.address).success() # sniffer sees message on the wire tnet.sniffer.start_state.receive( PDU, pduSource=tnet.td.address.addrTuple, pduDestination=('192.168.4.255', 47808), pduData=xtob('81.0b.0008' # original broadcast bvlci 'deadbeef' # PDU being unicast ), ).timeout(1.0).success() # run the group tnet.run()
def test_04(self): """Test broadcast for a router to the network it is on.""" if _debug: TestWhoIsRouterToNetwork._debug("test_02") # create a network tnet = TNetwork() # request router to network 1 on network 1, no response tnet.td.start_state.doc("4-1-0") \ .send(WhoIsRouterToNetwork(1, destination=LocalBroadcast(), )).doc("4-1-1") \ .timeout(3).doc("4-1-2") \ .success() tnet.sniffer1.start_state.success() # nothing received on network 2 tnet.sniffer2.start_state.doc("4-2-0") \ .timeout(3).doc("4-2-1") \ .success() tnet.sniffer3.start_state.success() # run the group tnet.run()
def whois_router_to_network(self, network=None, *, destination=None): # build a request try: request = WhoIsRouterToNetwork() if network: request.wirtnNetwork = int(network) if destination: request.pduDestination = Address(destination) self._log.debug("WhoIsRouterToNetwork Destination : {}".format( destination)) else: request.pduDestination = LocalBroadcast() except: self._log.error("WhoIsRouterToNetwork : invalid arguments") return iocb = IOCB((self.this_application.nsap.local_adapter, request)) # make an IOCB iocb.set_timeout(2) deferred(self.this_application.nse.request_io, iocb) iocb.wait() try: self.init_routing_table(str( self.this_application.nse._iartn.pop())) except IndexError: pass
def whois(self, *args, global_broadcast=False): """ Build a WhoIs request :param args: string built as [ <addr>] [ <lolimit> <hilimit> ] **optional** :returns: discoveredDevices as a defaultdict(int) Example:: whois(global_broadcast=True) # WhoIs broadcast globally. Every device will respond with an IAm whois('2:5') # WhoIs looking for the device at (Network 2, Address 5) whois('10 1000') # WhoIs looking for devices in the ID range (10 - 1000) """ if not self._started: raise ApplicationNotStarted( "BACnet stack not running - use startApp()") if args: args = args[0].split() msg = args if args else "any" self._log.debug("do_whois {!r}".format(msg)) # build a request request = WhoIsRequest() if (len(args) == 1) or (len(args) == 3): request.pduDestination = Address(args[0]) del args[0] else: if global_broadcast: request.pduDestination = GlobalBroadcast() else: request.pduDestination = LocalBroadcast() if len(args) == 2: try: request.deviceInstanceRangeLowLimit = int(args[0]) request.deviceInstanceRangeHighLimit = int(args[1]) except ValueError: pass self._log.debug("{:>12} {}".format("- request:", request)) iocb = IOCB(request) # make an IOCB self.this_application._last_i_am_received = [] # pass to the BACnet stack deferred(self.this_application.request_io, iocb) iocb.wait() # Wait for BACnet response if iocb.ioResponse: # successful response apdu = iocb.ioResponse if iocb.ioError: # unsuccessful: error/reject/abort pass time.sleep(3) self.discoveredDevices = self.this_application.i_am_counter return self.this_application._last_i_am_received
def test_address_equality(self): if _debug: TestAddressEquality._debug("test_address_equality") assert Address(1) == LocalStation(1) assert Address("2") == LocalStation(2) assert Address("*") == LocalBroadcast() assert Address("3:4") == RemoteStation(3, 4) assert Address("5:*") == RemoteBroadcast(5) assert Address("*:*") == GlobalBroadcast()
def __init__(self): if _debug: TNetwork._debug("__init__") StateMachineGroup.__init__(self) # reset the time machine reset_time_machine() if _debug: TNetwork._debug(" - time machine reset") # implementation under test self.iut = RouterNode() # make a little LAN self.vlan1 = Network(name="vlan1", broadcast_address=LocalBroadcast()) # test device self.td = NetworkLayerStateMachine("1", self.vlan1) self.append(self.td) # sniffer node self.sniffer1 = SnifferStateMachine("2", self.vlan1) self.append(self.sniffer1) # add the network self.iut.add_network("3", self.vlan1, 1) # make another little LAN self.vlan2 = Network(name="vlan2", broadcast_address=LocalBroadcast()) # sniffer node self.sniffer2 = SnifferStateMachine("4", self.vlan2) self.append(self.sniffer2) # add the network self.iut.add_network("5", self.vlan2, 2) # make another little LAN self.vlan3 = Network(name="vlan3", broadcast_address=LocalBroadcast()) # sniffer node self.sniffer3 = SnifferStateMachine("6", self.vlan3) self.append(self.sniffer3) # add the network self.iut.add_network("7", self.vlan3, 3)
def on_message(self, client, userdata, msg): """Callback for when a PUBLISH message is received from the server. """ if _debug: MQTTClient._debug("on_message %r, %s", msg.topic, btox(msg.payload, ".")) # wrap it up and decode it pdu = PDU(msg.payload) bvlpdu = BVLPDU() bvlpdu.decode(pdu) if _debug: MQTTClient._debug(" - bvlpdu: %r", bvlpdu) # decode the next layer xpdu = bvl_pdu_types[bvlpdu.bvlciFunction]() xpdu.decode(bvlpdu) if _debug: MQTTClient._debug(" - xpdu: %r", xpdu) if isinstance(xpdu, OriginalUnicastNPDU): # from ourselves? if xpdu.bvlciAddress == self.client: if _debug: MQTTClient._debug(" - from ourselves") return # build a PDU with the client address ypdu = PDU( xpdu.pduData, source=xpdu.bvlciAddress, destination=self.client, user_data=xpdu.pduUserData, ) if _debug: MQTTClient._debug(" - upstream ypdu: %r", ypdu) deferred(self.response, ypdu) elif isinstance(xpdu, OriginalBroadcastNPDU): # from ourselves? if xpdu.bvlciAddress == self.client: if _debug: MQTTClient._debug(" - from ourselves") return # build a PDU with a local broadcast address ypdu = PDU( xpdu.pduData, source=xpdu.bvlciAddress, destination=LocalBroadcast(), user_data=xpdu.pduUserData, ) if _debug: MQTTClient._debug(" - upstream ypdu: %r", ypdu) deferred(self.response, ypdu)
def test_broadcast(self): """Test a broadcast message from the foreign device to the bbmd.""" if _debug: TestForeign._debug("test_broadcast") # create a network tnet = TNetwork() # make a broadcast pdu pdu_data = xtob('dead.beef') pdu = PDU(pdu_data, destination=LocalBroadcast()) if _debug: TestForeign._debug(" - pdu: %r", pdu) # register, wait for ack, send some beef tnet.fd.start_state.doc("4-1-0") \ .call(tnet.fd.bip.register, tnet.bbmd.address, 60).doc("4-1-1") \ .wait_event('4-registered').doc("4-1-2") \ .send(pdu).doc("4-1-3") \ .success() # the bbmd is happy when it gets the pdu tnet.bbmd.start_state \ .receive(PDU, pduSource=tnet.fd.address, pduData=pdu_data) \ .success() # home sniffer node home_node = SimpleNode("192.168.5.254/24", tnet.home_vlan) tnet.append(home_node) # home node happy when getting the pdu, broadcast by the bbmd home_node.start_state.doc("4-2-0") \ .receive(PDU, pduSource=tnet.fd.address, pduData=pdu_data).doc("4-2-1") \ .success() # remote sniffer node remote_sniffer = SnifferNode("192.168.6.254/24", tnet.remote_vlan) tnet.append(remote_sniffer) # sniffer pieces registration_request = xtob('81.05.0006' # bvlci '003c' # time-to-live (60) ) registration_ack = xtob('81.00.0006.0000') # simple ack distribute_pdu = xtob('81.09.0008' # bvlci 'deadbeef' # PDU to broadcast ) # remote sniffer sees registration remote_sniffer.start_state.doc("4-3-0") \ .receive(PDU, pduData=registration_request).doc("4-3-1") \ .receive(PDU, pduData=registration_ack).doc("4-3-2") \ .set_event('4-registered') \ .receive(PDU, pduData=distribute_pdu).doc("4-3-3") \ .success() # run the group tnet.run(4.0)
def test_14_2_1_2(self): """14.2.1.1 Execute Forwarded-NPDU (Two-hop Distribution).""" if _debug: TestBBMD._debug("test_14_2_1_2") # create a network tnet = TNetwork(2) # implementation under test iut = BIPBBMDApplication("192.168.1.2/24", tnet.vlan[0]) if _debug: TestBBMD._debug(" - iut.bip: %r", iut.bip) # BBMD on net 2 bbmd1 = BIPBBMDNode("192.168.2.2/24", tnet.vlan[1]) # add the IUT as a two-hop peer bbmd1.bip.add_peer(Address("192.168.1.2/32")) if _debug: TestBBMD._debug(" - bbmd1.bip: %r", bbmd1.bip) # test device td = BIPSimpleApplicationLayerStateMachine("192.168.2.3/24", tnet.vlan[1]) tnet.append(td) # listener looks for extra traffic listener = BIPStateMachine("192.168.1.3/24", tnet.vlan[0]) listener.mux.node.promiscuous = True tnet.append(listener) # broadcast a forwarded NPDU td.start_state.doc("2-3-0") \ .send(WhoIsRequest(destination=LocalBroadcast())).doc("2-3-1") \ .receive(IAmRequest).doc("2-3-2") \ .success() # listen for the forwarded NPDU. The packet will be sent upstream which # will generate the original unicast going back, then it will be # re-broadcast on the local LAN. Fail if there's anything after that. s241 = listener.start_state.doc("2-4-0") \ .receive(ForwardedNPDU).doc("2-4-1") # look for the original unicast going back, followed by the rebroadcast # of the forwarded NPDU on the local LAN both = s241 \ .receive(OriginalUnicastNPDU).doc("2-4-1-a") \ .receive(ForwardedNPDU).doc("2-4-1-b") # fail if anything is received after both packets both.timeout(3).doc("2-4-4") \ .success() # allow the two packets in either order s241.receive(ForwardedNPDU).doc("2-4-2-a") \ .receive(OriginalUnicastNPDU, next_state=both).doc("2-4-2-b") # run the group tnet.run()
def test_local_broadcast_routed(self): if _debug: TestLocalBroadcast._debug("test_local_broadcast_routed") if not settings.route_aware: if _debug: TestLocalBroadcast._debug(" - not route aware") return test_addr = LocalBroadcast(route=Address("1.2.3.4")) self.match_address(test_addr, 1, None, None, None) assert str(test_addr) == "*@1.2.3.4"
def whohas( self, object_id=None, object_name=None, instance_range_low_limit=0, instance_range_high_limit=4194303, destination=None, global_broadcast=False, ): """ Object ID : analogInput:1 Object Name : string Instance Range Low Limit : 0 Instance Range High Limit : 4194303 destination (optional) : If empty, local broadcast will be used. global_broadcast : False """ obj_id = ObjectIdentifier(object_id) if object_name and not object_id: obj_name = CharacterString(object_name) obj = WhoHasObject(objectName=obj_name) elif object_id and not object_name: obj = WhoHasObject(objectIdentifier=obj_id) else: obj = WhoHasObject(objectIdentifier=obj_id, objectName=obj_name) limits = WhoHasLimits( deviceInstanceRangeLowLimit=instance_range_low_limit, deviceInstanceRangeHighLimit=instance_range_high_limit, ) request = WhoHasRequest(object=obj, limits=limits) if destination: request.pduDestination = Address(destination) else: if global_broadcast: request.pduDestination = GlobalBroadcast() else: request.pduDestination = LocalBroadcast() iocb = IOCB(request) # make an IOCB iocb.set_timeout(2) deferred(self.this_application.request_io, iocb) iocb.wait() iocb = IOCB(request) # make an IOCB self.this_application._last_i_have_received = [] if iocb.ioResponse: # successful response apdu = iocb.ioResponse if iocb.ioError: # unsuccessful: error/reject/abort pass time.sleep(3) # self.discoveredObjects = self.this_application.i_am_counter return self.this_application._last_i_have_received
def __init__(self): if _debug: TNetwork._debug("__init__") StateMachineGroup.__init__(self) # reset the time machine reset_time_machine() if _debug: TNetwork._debug(" - time machine reset") # create a traffic log self.traffic_log = TrafficLog() # network 1 self.vlan1 = Network(name="vlan1", broadcast_address=LocalBroadcast()) self.vlan1.traffic_log = self.traffic_log # network 1 state machine self.td1 = NetworkLayerStateMachine("1", self.vlan1) self.append(self.td1) # network 2 self.vlan2 = Network(name="vlan2", broadcast_address=LocalBroadcast()) self.vlan2.traffic_log = self.traffic_log # network 2 state machine self.td2 = NetworkLayerStateMachine("2", self.vlan2) self.append(self.td2) # network 3 self.vlan3 = Network(name="vlan3", broadcast_address=LocalBroadcast()) self.vlan3.traffic_log = self.traffic_log # network 2 state machine self.td3 = NetworkLayerStateMachine("3", self.vlan3) self.append(self.td3) # implementation under test self.iut = RouterNode() # add the network connections self.iut.add_network("4", self.vlan1, 1) self.iut.add_network("5", self.vlan2, 2) self.iut.add_network("6", self.vlan3, 3)
def confirmation(self, pdu): if _debug: FauxMultiplexer._debug("confirmation %r", pdu) # the PDU source and destination are tuples, convert them to Address instances src = Address(pdu.pduSource) # see if the destination was our broadcast address if pdu.pduDestination == self.broadcast_tuple: dest = LocalBroadcast() else: dest = Address(pdu.pduDestination) # continue upstream self.response(PDU(pdu, source=src, destination=dest))
def test_broadcast(self): """Test a broadcast message from the foreign device to the bbmd.""" if _debug: TestForeign._debug("test_broadcast") # create a network tnet = TNetwork() # make a broadcast pdu pdu_data = xtob('dead.beef') pdu = PDU(pdu_data, destination=LocalBroadcast()) if _debug: TestForeign._debug(" - pdu: %r", pdu) # register, wait for ack, send some beef tnet.fd.start_state.doc("4-1-0") \ .call(tnet.fd.bip.register, tnet.bbmd.address, 60).doc("4-1-1") \ .wait_event('4-registered').doc("4-1-2") \ .send(pdu).doc("4-1-3") \ .success() # the bbmd is happy when it gets the pdu tnet.bbmd.start_state.doc("4-2-0") \ .receive(PDU, pduSource=tnet.fd.address, pduData=pdu_data).doc("4-2-1") \ .success() # home simple node home_node = BIPSimpleStateMachine("192.168.5.254/24", tnet.vlan_5) tnet.append(home_node) # home node happy when getting the pdu, broadcast by the bbmd home_node.start_state.doc("4-3-0") \ .receive(PDU, pduSource=tnet.fd.address, pduData=pdu_data).doc("4-3-1") \ .success() # remote sniffer node remote_sniffer = SnifferStateMachine("192.168.6.254/24", tnet.vlan_6) tnet.append(remote_sniffer) # remote traffic remote_sniffer.start_state.doc("4-4-0") \ .receive(RegisterForeignDevice).doc("4-4-1") \ .receive(Result).doc("4-4-2") \ .set_event('4-registered') \ .receive(DistributeBroadcastToNetwork).doc("4-4-3") \ .success() # run the group tnet.run(4.0)
def test_14_2_1_1(self): """14.2.1.1 Execute Forwarded-NPDU (One-hop Distribution).""" if _debug: TestBBMD._debug("test_14_2_1_1") # create a network tnet = TNetwork(2) # implementation under test iut = BIPBBMDApplication("192.168.1.2/24", tnet.vlan[0]) if _debug: TestBBMD._debug(" - iut.bip: %r", iut.bip) # BBMD on net 2 bbmd1 = BIPBBMDNode("192.168.2.2/24", tnet.vlan[1]) # add the IUT as a one-hop peer bbmd1.bip.add_peer(Address("192.168.1.2/24")) if _debug: TestBBMD._debug(" - bbmd1.bip: %r", bbmd1.bip) # test device td = BIPSimpleApplicationLayerStateMachine("192.168.2.3/24", tnet.vlan[1]) tnet.append(td) # listener looks for extra traffic listener = BIPStateMachine("192.168.1.3/24", tnet.vlan[0]) listener.mux.node.promiscuous = True tnet.append(listener) # broadcast a forwarded NPDU td.start_state.doc("2-1-0") \ .send(WhoIsRequest(destination=LocalBroadcast())).doc("2-1-1") \ .receive(IAmRequest).doc("2-1-2") \ .success() # listen for the directed broadcast, then the original unicast, # then fail if there's anything else listener.start_state.doc("2-2-0") \ .receive(ForwardedNPDU).doc("2-2-1") \ .receive(OriginalUnicastNPDU).doc("2-2-2") \ .timeout(3).doc("2-2-3") \ .success() # run the group tnet.run()
def test_01(self): """Test broadcast for any router.""" if _debug: TestWhoIsRouterToNetwork._debug("test_01") # create a network tnet = TNetwork() # test device sends request, sees response tnet.td.start_state.doc("1-1-0") \ .send(WhoIsRouterToNetwork( destination=LocalBroadcast(), )).doc("1-1-1") \ .receive(IAmRouterToNetwork, iartnNetworkList=[2, 3], ).doc("1-1-2") \ .success() # sniffer on network 1 sees the request and the response tnet.sniffer1.start_state.doc("1-2-0") \ .receive(PDU, pduData=xtob('01.80' # version, network layer '00' # message type, no network ) ).doc("1-2-1") \ .receive(PDU, pduData=xtob('01.80' # version, network layer '01 0002 0003' # message type and network list ) ).doc("1-2-2") \ .success() # nothing received on network 2 tnet.sniffer2.start_state.doc("1-3-0") \ .timeout(3).doc("1-3-1") \ .success() # nothing received on network 3 tnet.sniffer3.start_state.doc("1-4-0") \ .timeout(3).doc("1-4-1") \ .success() # run the group tnet.run()
def __init__(self, local_address: str): Network.__init__(self, broadcast_address=LocalBroadcast()) # create the VLAN router, bind it to the local network address = Address(local_address) self._router = _VLANRouter(address, 0) self._address_index = 1 # create a node for the router, address 1 on the VLAN router_node = Node(Address(self._address_index.to_bytes(4, "big"))) self._address_index += 1 self.add_node(router_node) # bind the router stack to the vlan network through this node self._router.bind(router_node, 1) self._router.start() self._sensors: Dict[int, Sensor] = {}
def what_is_network_number(self, destination=None): """ winn [ <addr> ] Send a What-Is-Network-Number message. If the address is unspecified the message is locally broadcast. """ # build a request request = WhatIsNetworkNumber() if destination: request.pduDestination = Address(destination) else: request.pduDestination = LocalBroadcast() iocb = IOCB((self.this_application.nsap.local_adapter, request)) # make an IOCB iocb.set_timeout(2) deferred(self.this_application.nse.request_io, iocb) iocb.wait()
def test_01(self): """Test broadcast for any router.""" if _debug: TestWhoIsRouterToNetwork._debug("test_01") # create a network tnet = TNetwork() # test device sends request s111 = tnet.td.start_state.doc("1-1-0") \ .send(WhoIsRouterToNetwork( destination=LocalBroadcast(), )).doc("1-1-1") # test device sees both responses both = s111 \ .receive(IAmRouterToNetwork, iartnNetworkList=[1], ).doc("1-1-2-a") \ .receive(IAmRouterToNetwork, iartnNetworkList=[3], ).doc("1-1-2-b") \ # allow the two packets in either order s111.receive(IAmRouterToNetwork, iartnNetworkList=[3], ).doc("1-1-2-c") \ .receive(IAmRouterToNetwork, iartnNetworkList=[1], next_state=both).doc("1-1-2-d") \ # fail if anything is received after both packets both.timeout(3).doc("1-1-3") \ .success() # short circuit the snifferse tnet.sniffer1.start_state.success() tnet.sniffer2.start_state.success() tnet.sniffer3.start_state.success() # run the group tnet.run()
def test_03(self): """Test broadcast for a non-existent router.""" if _debug: TestWhoIsRouterToNetwork._debug("test_03") # create a network tnet = TNetwork() # send request, receive nothing back tnet.td.start_state.doc("3-1-0") \ .send(WhoIsRouterToNetwork(4, destination=LocalBroadcast(), )).doc("3-1-1") \ .timeout(3).doc("3-1-2") \ .success() # sniffer on network 1 sees the request tnet.sniffer1.start_state.doc("3-2-0") \ .receive(PDU, pduData=xtob('01.80' # version, network layer '00 0004' # message type and network ) ).doc("3-2-1") \ .success() # sniffer on network 2 sees request forwarded by router tnet.sniffer2.start_state.doc("3-3-0") \ .receive(PDU, pduData=xtob('01.88' # version, network layer, routed '0001 01 01' # snet/slen/sadr '00 0004' # message type and network ), ).doc("3-3-1") \ .success() tnet.sniffer3.start_state.success() # run the group tnet.run()