def test_octet_string_copy(self): if _debug: TestOctetString._debug("test_octet_string_copy") obj1 = OctetString(xtob("01")) obj2 = OctetString(obj1) assert obj2.value == xtob("01")
def test_get_context(self): """Test extracting specific context encoded content. """ if _debug: TestTagList._debug("test_get_context") tag_list_data = [ ContextTag(0, xtob('00')), ContextTag(1, xtob('01')), OpeningTag(2), IntegerTag(3), OpeningTag(0), IntegerTag(4), ClosingTag(0), ClosingTag(2), ] taglist = TagList(tag_list_data) # known to be a simple context encoded element context_0 = taglist.get_context(0) if _debug: TestTagList._debug(" - context_0: %r", context_0) assert context_0 == tag_list_data[0] # known to be a simple context encoded list of element(s) context_2 = taglist.get_context(2) if _debug: TestTagList._debug(" - context_2: %r", context_2) assert context_2.tagList == tag_list_data[3:7] # known missing context context_3 = taglist.get_context(3) if _debug: TestTagList._debug(" - context_3: %r", context_3) assert taglist.get_context(3) is None
def test_octet_string_octet_string(self): if _debug: TestOctetString._debug("test_octet_string_octet_string") obj = OctetString(xtob('01')) assert obj.value == xtob('01') assert str(obj) == "OctetString(X'01')" obj = OctetString(xtob('01020304')) assert obj.value == xtob('01020304') assert str(obj) == "OctetString(X'01020304')"
def test_remote_station_bytes(self): if _debug: TestRemoteStation._debug("test_remote_station_bytes") # multi-byte strings are hex encoded test_addr = RemoteStation(1, xtob('0102')) self.match_address(test_addr, 4, 1, 2, '0102') assert str(test_addr) == "1:0x0102" test_addr = RemoteStation(1, xtob('010203')) self.match_address(test_addr, 4, 1, 3, '010203') assert str(test_addr) == "1:0x010203" # match with an IPv4 address test_addr = RemoteStation(1, xtob('01020304bac0')) self.match_address(test_addr, 4, 1, 6, '01020304bac0') assert str(test_addr) == "1:1.2.3.4"
def test_tag(self): if _debug: TestTag._debug("test_tag") # test tag construction tag = Tag() assert (tag.tagClass, tag.tagNumber) == (None, None) # must have a valid encoded tag to extract from the data data = PDUData(xtob('')) with self.assertRaises(DecodingError): tag = Tag(data) # must have two values, class and number with self.assertRaises(ValueError): tag = Tag(0) tag = Tag(0, 1) assert (tag.tagClass, tag.tagNumber) == (0, 1) tag = Tag(0, 1, 2) assert (tag.tagClass, tag.tagNumber, tag.tagLVT) == (0, 1, 2) # tag data must be bytes or bytearray with self.assertRaises(TypeError): tag = Tag(0, 1, 2, 3)
def test_endec_2(self): """Test short tag list encoding and decoding, context tags. """ if _debug: TestTagList._debug("test_endec_2") tag0 = ContextTag(0, xtob('00')) tag1 = ContextTag(1, xtob('01')) taglist = TagList([tag0, tag1]) data = PDUData() taglist.encode(data) assert data.pduData == xtob('09001901') taglist = TagList() taglist.decode(data) assert taglist.tagList == [tag0, tag1]
def test_octet_string(self): if _debug: TestOctetString._debug("test_octet_string") obj = OctetString() assert obj.value == xtob('') with self.assertRaises(TypeError): OctetString(1)
def boolean_tag(value): """Convert an integer to an boolean application tag.""" if _debug: boolean_tag._debug("boolean_tag %r", value) tag = Tag(Tag.applicationTagClass, Tag.booleanAppTag, int(value), xtob('')) if _debug: boolean_endec._debug(" - tag: %r", tag) return tag
def integer_tag(x): """Convert a hex string to an integer application tag.""" if _debug: integer_tag._debug("integer_tag %r", x) b = xtob(x) tag = Tag(Tag.applicationTagClass, Tag.integerAppTag, len(b), b) if _debug: integer_endec._debug(" - tag: %r", tag) return tag
def octet_string_tag(x): """Convert a hex string to an octet_string application tag.""" if _debug: octet_string_tag._debug("octet_string_tag %r", x) b = xtob(x) tag = Tag(Tag.applicationTagClass, Tag.octetStringAppTag, len(b), b) if _debug: octet_string_endec._debug(" - tag: %r", tag) return tag
def double_tag(x): """Convert a hex string to an double application tag.""" if _debug: double_tag._debug("double_tag %r", x) b = xtob(x) tag = Tag(Tag.applicationTagClass, Tag.doubleAppTag, len(b), b) if _debug: double_endec._debug(" - tag: %r", tag) return tag
def test_integer_tag(self): if _debug: TestInteger._debug("test_integer_tag") tag = Tag(Tag.applicationTagClass, Tag.integerAppTag, 1, xtob('01')) obj = Integer(tag) assert obj.value == 1 tag = Tag(Tag.applicationTagClass, Tag.booleanAppTag, 0, xtob('')) with self.assertRaises(InvalidTag): Integer(tag) tag = Tag(Tag.contextTagClass, 0, 1, xtob('ff')) with self.assertRaises(InvalidTag): Integer(tag) tag = Tag(Tag.openingTagClass, 0) with self.assertRaises(InvalidTag): Integer(tag)
def test_unsigned_tag(self): if _debug: TestUnsigned._debug("test_unsigned_tag") tag = Tag(Tag.applicationTagClass, Tag.unsignedAppTag, 1, xtob('01')) obj = Unsigned(tag) assert obj.value == 1 tag = Tag(Tag.applicationTagClass, Tag.booleanAppTag, 0, xtob('')) with self.assertRaises(ValueError): Unsigned(tag) tag = Tag(Tag.contextTagClass, 0, 1, xtob('ff')) with self.assertRaises(ValueError): Unsigned(tag) tag = Tag(Tag.openingTagClass, 0) with self.assertRaises(ValueError): Unsigned(tag)
def test_double_tag(self): if _debug: TestDouble._debug("test_double_tag") tag = Tag(Tag.applicationTagClass, Tag.doubleAppTag, 8, xtob('3ff0000000000000')) obj = Double(tag) assert obj.value == 1.0 tag = Tag(Tag.applicationTagClass, Tag.booleanAppTag, 0, xtob('')) with self.assertRaises(InvalidTag): Double(tag) tag = Tag(Tag.contextTagClass, 0, 1, xtob('ff')) with self.assertRaises(InvalidTag): Double(tag) tag = Tag(Tag.openingTagClass, 0) with self.assertRaises(InvalidTag): Double(tag)
def enumerated_tag(x): """Convert a hex string to an enumerated application tag.""" if _debug: enumerated_tag._debug("enumerated_tag %r", x) b = xtob(x) tag = Tag(Tag.applicationTagClass, Tag.enumeratedAppTag, len(b), b) if _debug: enumerated_endec._debug(" - tag: %r", tag) return tag
def test_character_string_tag(self): if _debug: TestCharacterString._debug("test_character_string_tag") tag = Tag(Tag.applicationTagClass, Tag.characterStringAppTag, 1, xtob('00')) obj = CharacterString(tag) assert obj.value == '' tag = Tag(Tag.applicationTagClass, Tag.booleanAppTag, 0, xtob('')) with self.assertRaises(ValueError): CharacterString(tag) tag = Tag(Tag.contextTagClass, 0, 1, xtob('ff')) with self.assertRaises(ValueError): CharacterString(tag) tag = Tag(Tag.openingTagClass, 0) with self.assertRaises(ValueError): CharacterString(tag)
def test_application_tag(self): if _debug: TestApplicationTag._debug("test_application_tag") # application tag construction, encoding, and decoding tag = ApplicationTag(0, xtob('')) if _debug: TestApplicationTag._debug(" - tag: %r", tag_tuple(tag)) with self.assertRaises(ValueError): tag = ApplicationTag(0)
def test_boolean_tag(self): if _debug: TestBoolean._debug("test_boolean_tag") tag = Tag(Tag.applicationTagClass, Tag.booleanAppTag, 1, xtob('01')) obj = Boolean(tag) assert obj.value == 1 tag = Tag(Tag.applicationTagClass, Tag.integerAppTag, 0, xtob('')) with self.assertRaises(ValueError): Boolean(tag) tag = Tag(Tag.contextTagClass, 0, 1, xtob('ff')) with self.assertRaises(ValueError): Boolean(tag) tag = Tag(Tag.openingTagClass, 0) with self.assertRaises(ValueError): Boolean(tag)
def test_real_tag(self): if _debug: TestReal._debug("test_real_tag") tag = Tag(Tag.applicationTagClass, Tag.realAppTag, 1, xtob('3f800000')) obj = Real(tag) assert obj.value == 1.0 tag = Tag(Tag.applicationTagClass, Tag.booleanAppTag, 0, xtob('')) with self.assertRaises(InvalidTag): Real(tag) tag = Tag(Tag.contextTagClass, 0, 1, xtob('ff')) with self.assertRaises(InvalidTag): Real(tag) tag = Tag(Tag.openingTagClass, 0) with self.assertRaises(InvalidTag): Real(tag)
def tag(tag_class, tag_number, x): """Create a tag object with the given class, number, and data.""" if _debug: tag._debug("tag %r %r %r", tag_class, tag_number, x) b = xtob(x) tag = Tag(tag_class, tag_number, len(b), b) if _debug: tag_tuple._debug(" - tag: %r", tag) return tag
def test_time_tag(self): if _debug: TestTime._debug("test_time_tag") tag = Tag(Tag.applicationTagClass, Tag.timeAppTag, 1, xtob('01020304')) obj = Time(tag) assert obj.value == (1, 2, 3, 4) tag = Tag(Tag.applicationTagClass, Tag.booleanAppTag, 0, xtob('')) with self.assertRaises(InvalidTag): Time(tag) tag = Tag(Tag.contextTagClass, 0, 1, xtob('ff')) with self.assertRaises(InvalidTag): Time(tag) tag = Tag(Tag.openingTagClass, 0) with self.assertRaises(InvalidTag): Time(tag)
def test_date_tag(self): if _debug: TestInteger._debug("test_date_tag") tag = Tag(Tag.applicationTagClass, Tag.dateAppTag, 4, xtob('01020304')) obj = Date(tag) assert obj.value == (1, 2, 3, 4) tag = Tag(Tag.applicationTagClass, Tag.booleanAppTag, 0, xtob('')) with self.assertRaises(ValueError): Date(tag) tag = Tag(Tag.contextTagClass, 0, 1, xtob('ff')) with self.assertRaises(ValueError): Date(tag) tag = Tag(Tag.openingTagClass, 0) with self.assertRaises(ValueError): Date(tag)
def object_identifier_tag(x): """Convert a hex string to an object_identifier application tag.""" if _debug: object_identifier_tag._debug("object_identifier_tag %r", x) b = xtob(x) tag = Tag(Tag.applicationTagClass, Tag.objectIdentifierAppTag, len(b), b) if _debug: object_identifier_endec._debug(" - tag: %r", tag) return tag
def test_octet_string_tag(self): if _debug: TestOctetString._debug("test_octet_string_tag") tag = Tag(Tag.applicationTagClass, Tag.octetStringAppTag, 1, xtob('00')) obj = OctetString(tag) assert obj.value == xtob('00') tag = Tag(Tag.applicationTagClass, Tag.booleanAppTag, 0, xtob('')) with self.assertRaises(InvalidTag): OctetString(tag) tag = Tag(Tag.contextTagClass, 0, 1, xtob('ff')) with self.assertRaises(InvalidTag): OctetString(tag) tag = Tag(Tag.openingTagClass, 0) with self.assertRaises(InvalidTag): OctetString(tag)
def real_tag(x): """Convert a hex string to an real application tag.""" if _debug: real_tag._debug("real_tag %r", x) b = xtob(x) tag = Tag(Tag.applicationTagClass, Tag.realAppTag, len(b), b) if _debug: real_tag._debug(" - tag: %r", tag) return tag
def character_string_tag(x): """Convert a hex string to an character_string application tag.""" if _debug: character_string_tag._debug("character_string_tag %r", x) b = xtob(x) tag = Tag(Tag.applicationTagClass, Tag.characterStringAppTag, len(b), b) if _debug: character_string_endec._debug(" - tag: %r", tag) return tag
def test_enumerated_tag(self): if _debug: TestEnumerated._debug("test_enumerated_tag") tag = Tag(Tag.applicationTagClass, Tag.enumeratedAppTag, 1, xtob('01')) obj = Enumerated(tag) assert obj.value == 1 tag = Tag(Tag.applicationTagClass, Tag.booleanAppTag, 0, xtob('')) with self.assertRaises(InvalidTag): Enumerated(tag) tag = Tag(Tag.contextTagClass, 0, 1, xtob('ff')) with self.assertRaises(InvalidTag): Enumerated(tag) tag = Tag(Tag.openingTagClass, 0) with self.assertRaises(InvalidTag): Enumerated(tag)
def test_object_type_tag(self): if _debug: TestObjectType._debug("test_object_type_tag") tag = Tag(Tag.applicationTagClass, Tag.enumeratedAppTag, 1, xtob('01')) obj = ObjectType(tag) assert obj.value == 'analogOutput' tag = Tag(Tag.applicationTagClass, Tag.booleanAppTag, 0, xtob('')) with self.assertRaises(InvalidTag): ObjectType(tag) tag = Tag(Tag.contextTagClass, 0, 1, xtob('ff')) with self.assertRaises(InvalidTag): ObjectType(tag) tag = Tag(Tag.openingTagClass, 0) with self.assertRaises(InvalidTag): ObjectType(tag)
def test_object_identifier_tag(self): if _debug: TestObjectIdentifier._debug("test_object_identifier_tag") tag = Tag(Tag.applicationTagClass, Tag.objectIdentifierAppTag, 1, xtob('06000003')) obj = ObjectIdentifier(tag) assert obj.value == ('pulseConverter', 3) tag = Tag(Tag.applicationTagClass, Tag.booleanAppTag, 0, xtob('')) with self.assertRaises(ValueError): ObjectIdentifier(tag) tag = Tag(Tag.contextTagClass, 0, 1, xtob('ff')) with self.assertRaises(ValueError): ObjectIdentifier(tag) tag = Tag(Tag.openingTagClass, 0) with self.assertRaises(ValueError): ObjectIdentifier(tag)
def test_local_station(self): if _debug: TestLocalStation._debug("test_local_station") # one parameter with self.assertRaises(TypeError): LocalStation() # test integer test_addr = LocalStation(1) self.match_address(test_addr, 2, None, 1, '01') assert str(test_addr) == "1" test_addr = LocalStation(254) self.match_address(test_addr, 2, None, 1, 'fe') assert str(test_addr) == "254" # test bad integer with self.assertRaises(ValueError): LocalStation(-1) with self.assertRaises(ValueError): LocalStation(256) # test bytes test_addr = LocalStation(xtob('01')) self.match_address(test_addr, 2, None, 1, '01') assert str(test_addr) == "1" test_addr = LocalStation(xtob('fe')) self.match_address(test_addr, 2, None, 1, 'fe') assert str(test_addr) == "254" # multi-byte strings are hex encoded test_addr = LocalStation(xtob('0102')) self.match_address(test_addr, 2, None, 2, '0102') assert str(test_addr) == "0x0102" test_addr = LocalStation(xtob('010203')) self.match_address(test_addr, 2, None, 3, '010203') assert str(test_addr) == "0x010203" # match with an IPv4 address test_addr = LocalStation(xtob('01020304bac0')) self.match_address(test_addr, 2, None, 6, '01020304bac0') assert str(test_addr) == "1.2.3.4"
def test_register_foreign_device(self): """Test the RegisterForeignDevice encoding and decoding.""" if _debug: TestAnnexJCodec._debug("test_register_foreign_device") # register as a foreign device with a 30 second time-to-live pdu_bytes = xtob('81.05.0006' # bvlci '001e' # time-to-live ) self.request(RegisterForeignDevice(30)) self.indication(pduData=pdu_bytes) self.response(PDU(pdu_bytes)) self.confirmation(RegisterForeignDevice, bvlciTimeToLive=30)
def test_remote_read_2(self): """Remote read property, matching device.""" if _debug: TestConfirmedRequests._debug("test_remote_read_2") # create a network tnet = TNetwork() # test device sends request and sees the response tnet.td.start_state.doc("5-1-0") \ .send(ReadPropertyRequest( destination=RemoteStation(2, 4), objectIdentifier=('device', 4), propertyIdentifier='vendorIdentifier', )).doc("5-1-1") \ .receive(ReadPropertyACK).doc("5-1-2") \ .success() # sniffer on network 1 sees the request and the response tnet.sniffer1.start_state.doc("5-2-0") \ .receive(PDU, pduData=xtob('01.80.00.00.02' # who is router to network ) ).doc("5-2-1") \ .receive(PDU, pduData=xtob('01.80.01.00.02' # I am router to network ) ).doc("5-2-2") \ .receive(PDU, pduData=xtob('01.24.00.02.01.04.ff' # request '02.44.01.0c.0c.02.00.00.04.19.78' ) ).doc("5-2-3") \ .receive(PDU, pduData=xtob('01.08.00.02.01.04' # ack '30.01.0c.0c.02.00.00.04.19.78.3e.22.03.e7.3f' ) ).doc("5-2-4") \ .timeout(3).doc("5-2-5") \ .success() # network 2 sees routed request and unicast response tnet.sniffer2.start_state.doc('5-3-0') \ .receive(PDU, pduData=xtob('01.0c.00.01.01.01' # request '02.44.01.0c.0c.02.00.00.04.19.78' ) ).doc("5-3-1") \ .receive(PDU, pduData=xtob('01.20.00.01.01.01.ff' # ack '30.01.0c.0c.02.00.00.04.19.78.3e.22.03.e7.3f' ) ).doc("5-3-2") \ .timeout(3).doc("5-3-3") \ .success() # run the group tnet.run()
def test_context_tag(self): if _debug: TestContextTag._debug("test_context_tag") # test context tag construction tag = ContextTag(0, xtob('')) with self.assertRaises(ValueError): tag = ContextTag() # test encoding and decoding context_endec(0, '', '08') context_endec(1, '01', '1901') context_endec(2, '0102', '2A0102') context_endec(3, '010203', '3B010203') context_endec(14, '010203', 'EB010203') context_endec(15, '010203', 'FB0F010203')
def test_enumerated_unicode(self): if _debug: TestEnumerated._debug("test_enumerated_unicode") obj = QuickBrownFox(u'quick') assert obj.value == u'quick' assert str(obj) == "QuickBrownFox(quick)" with self.assertRaises(ValueError): QuickBrownFox(-1) with self.assertRaises(ValueError): QuickBrownFox(u'lazyDog') tag = Tag(Tag.applicationTagClass, Tag.enumeratedAppTag, 1, xtob('01')) obj = QuickBrownFox(tag) assert obj.value == u'brown'
def test_i_am_router_to_network_empty(self): """Test the IAmRouterToNetwork with no networks encoding and decoding.""" if _debug: TestNPDUCodec._debug("test_i_am_router_to_network_empty") # Request successful network_list = [] pdu_bytes = xtob('01.80' # version, network layer message '01' # message type, no networks ) self.request(IAmRouterToNetwork(network_list)) self.indication(pduData=pdu_bytes) self.response(PDU(pdu_bytes)) self.confirmation(IAmRouterToNetwork, iartnNetworkList=network_list)
def test_router_busy_to_networks(self): """Test the RouterBusyToNetwork with multiple networks encoding and decoding.""" if _debug: TestNPDUCodec._debug("test_router_busy_to_networks") # Request successful network_list = [1, 2, 3] pdu_bytes = xtob('01.80' # version, network layer message '04 0001 0002 0003' # message type and network list ) self.request(RouterBusyToNetwork(network_list)) self.indication(pduData=pdu_bytes) self.response(PDU(pdu_bytes)) self.confirmation(RouterBusyToNetwork, rbtnNetworkList=network_list)
def test_disconnect_connection_to_network(self): """Test the DisconnectConnectionToNetwork with a routing table entry.""" if _debug: TestNPDUCodec._debug("test_disconnect_connection_to_network") # Request successful pdu_bytes = xtob('01.80' # version, network layer message '09 0007' # message type, network ) self.request(DisconnectConnectionToNetwork(7)) self.indication(pduData=pdu_bytes) self.response(PDU(pdu_bytes)) self.confirmation(DisconnectConnectionToNetwork, dctnDNET=7)
def context_endec(tnum, x, y): """Convert the value (a primitive object) to a hex encoded string, convert the hex encoded string to and object, and compare the results to each other.""" if _debug: context_endec._debug("context_endec %r %r %r", tnum, x, y) # convert the hex strings to a blobs tdata = xtob(x) blob1 = xtob(y) # make a context tag tag1 = ContextTag(tnum, tdata) # decode the blob into a tag tag2 = context_decode(blob1) if _debug: context_endec._debug(" - tag: %r", tag) # encode the tag into a blob blob2 = context_encode(tag1) if _debug: context_endec._debug(" - blob2: %r", blob2) # compare the results assert tag1 == tag2 assert blob1 == blob2
def test_endec_3(self): """Test bracketed application tagged integer encoding and decoding.""" if _debug: TestTagList._debug("test_endec_2") tag0 = OpeningTag(0) tag1 = IntegerTag(0x0102) tag2 = ClosingTag(0) taglist = TagList([tag0, tag1, tag2]) data = PDUData() taglist.encode(data) assert data.pduData == xtob('0E3201020F') taglist = TagList() taglist.decode(data) assert taglist.tagList == [tag0, tag1, tag2]
def test_i_could_be_router_to_network(self): """Test the ICouldBeRouterToNetwork encoding and decoding.""" if _debug: TestNPDUCodec._debug("test_i_could_be_router_to_network") # Request successful pdu_bytes = xtob('01.80' # version, network layer message '02 0001 02' # message type, network, performance ) self.request(ICouldBeRouterToNetwork(1, 2)) self.indication(pduData=pdu_bytes) self.response(PDU(pdu_bytes)) self.confirmation(ICouldBeRouterToNetwork, icbrtnNetwork=1, icbrtnPerformanceIndex=2)
def test_delete_foreign_device_table_entry(self): """Test the DeleteForeignDeviceTableEntry encoding and decoding.""" if _debug: TestAnnexJCodec._debug("test_delete_foreign_device_table_entry") # delete an element addr = Address('192.168.0.11/24') pdu_bytes = xtob('81.08.000a' # bvlci 'c0.a8.00.0b.ba.c0' # address of entry to be deleted ) self.request(DeleteForeignDeviceTableEntry(addr)) self.indication(pduData=pdu_bytes) self.response(PDU(pdu_bytes)) self.confirmation(DeleteForeignDeviceTableEntry, bvlciAddress=addr)
def test_reject_message_to_network(self): """Test the RejectMessageToNetwork encoding and decoding.""" if _debug: TestNPDUCodec._debug("test_reject_message_to_network") # Request successful pdu_bytes = xtob('01.80' # version, network layer message '03 01 0002' # message type, network, performance ) self.request(RejectMessageToNetwork(1, 2)) self.indication(pduData=pdu_bytes) self.response(PDU(pdu_bytes)) self.confirmation(RejectMessageToNetwork, rmtnRejectionReason=1, rmtnDNET=2)
def test_endec_1(self): """Test short tag list encoding and decoding, application tags. """ if _debug: TestTagList._debug("test_endec_1") tag0 = IntegerTag(0x00) tag1 = IntegerTag(0x01) taglist = TagList([tag0, tag1]) data = PDUData() taglist.encode(data) assert data.pduData == xtob('31003101') taglist = TagList() taglist.decode(data) assert taglist.tagList == [tag0, tag1]
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_remote_broadcast_2(self): """Remote broadcast, matching device.""" if _debug: TestUnconfirmedRequests._debug("test_remote_broadcast_2") # create a network tnet = TNetwork() # test device sends request and sees the response tnet.td.start_state.doc("2-1-0") \ .send(WhoIsRequest( destination=RemoteBroadcast(2), )).doc("2-1-1") \ .success() # sniffer on network 1 sees the request and the response tnet.sniffer1.start_state.doc("2-2-0") \ .receive(PDU, pduData=xtob('01.80.00.00.02' # who is router to network ) ).doc("2-2-1") \ .receive(PDU, pduData=xtob('01.80.01.00.02' # I am router to network ) ).doc("2-2-1") \ .receive(PDU, pduData=xtob('01.20.00.02.00.ff' # remote broadcast goes out '10.08' ) ).doc("2-2-1") \ .receive(PDU, pduData=xtob('01.08.00.02.01.04' # unicast response '10.00.c4.02.00.00.04.22.04.00.91.00.22.03.e7' ) ).doc("2-2-2") \ .timeout(3).doc("2-2-3") \ .success() # network 2 sees local broadcast request and unicast response tnet.sniffer2.start_state.doc('2-3-0') \ .receive(PDU, pduData=xtob('01.08.00.01.01.01' # local broadcast '10.08' ) ).doc("2-3-1") \ .receive(PDU, pduData=xtob('01.20.00.01.01.01.ff' # unicast response '10.00.c4.02.00.00.04.22.04.00.91.00.22.03.e7' ) ).doc("2-3-1") \ .timeout(3).doc("2-3-2") \ .success() # run the group tnet.run()
def test_establish_connection_to_network(self): """Test the EstablishConnectionToNetwork with a routing table entry.""" if _debug: TestNPDUCodec._debug("test_establish_connection_to_network") # Request successful pdu_bytes = xtob( '01.80' # version, network layer message '08 0005 06' # message type, network, termination time ) self.request(EstablishConnectionToNetwork(5, 6)) self.indication(pduData=pdu_bytes) self.response(PDU(pdu_bytes)) self.confirmation(EstablishConnectionToNetwork, ectnDNET=5, ectnTerminationTime=6)
def test_character_string_unicode_with_latin(self): if _debug: TestCharacterString._debug( "test_character_string_unicode_with_latin") # some controllers encoding character string mixing latin-1 and utf-8 # try to cover those cases without failing b = xtob('0030b043') # zero degress celsius tag = Tag(Tag.applicationTagClass, Tag.characterStringAppTag, len(b), b) obj = CharacterString() obj.decode(tag) assert str(obj) == "CharacterString(0,X'30b043')" if sys.version_info[0] == 2: assert obj.value == "0C" # degree symbol dropped, see unicodedata.normalize() elif sys.version_info[0] == 3: assert obj.value == "0°C" else: raise RuntimeError("unsupported version")
def obj_endec(obj, x): """Convert the value (a primitive object) to a hex encoded string, convert the hex encoded string to and object, and compare the results to each other.""" if _debug: obj_endec._debug("obj_endec %r %r", obj, x) # convert the hex string to a blob blob = xtob(x) # decode the blob into an object obj2 = obj_decode(blob) if _debug: obj_endec._debug(" - obj: %r, %r", obj, obj.value) # encode the object into a blob blob2 = obj_encode(obj) if _debug: obj_endec._debug(" - blob2: %r", blob2) # compare the results assert obj == obj2 assert blob == blob2
def test_unicast(self): """Test a unicast message from the foreign device to the bbmd.""" if _debug: TestForeign._debug("test_unicast") # 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.fd.address, destination=tnet.bbmd.address) if _debug: TestForeign._debug(" - pdu: %r", pdu) # register, wait for ack, send some beef tnet.fd.start_state.doc("3-1-0") \ .call(tnet.fd.bip.register, tnet.bbmd.address, 60).doc("3-1-1") \ .wait_event('3-registered').doc("3-1-2") \ .send(pdu).doc("3-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() # remote sniffer node remote_sniffer = SnifferStateMachine("192.168.6.254/24", tnet.vlan_6) tnet.append(remote_sniffer) # sniffer traffic remote_sniffer.start_state.doc("3-2-0") \ .receive(RegisterForeignDevice).doc("3-2-1") \ .receive(Result).doc("3-2-2") \ .set_event('3-registered').doc("3-2-3") \ .receive(OriginalUnicastNPDU).doc("3-2-4") \ .success() # run the group tnet.run()
def match_address(self, addr, t, n, l, a): """Assert that the type, network, length, and address are what they should be. Note that the address parameter is a hex string that will be converted to bytes for comparison. :param addr: the address to match :param t: the address type :param n: the network number :param l: the address length :param a: the address expressed as hex bytes """ if _debug: MatchAddressMixin._debug("match_address %r %r %r %r %r", addr, t, n, l, a, ) assert addr.addrType == t assert addr.addrNet == n assert addr.addrLen == l if a is None: assert addr.addrAddr is None else: assert addr.addrAddr == xtob(a)
def closing_endec(tnum, x): """Convert the value (a primitive object) to a hex encoded string, convert the hex encoded string to and object, and compare the results to each other.""" if _debug: closing_endec._debug("closing_endec %r %r", tnum, x) # convert the hex string to a blob blob1 = xtob(x) # make a context tag tag1 = ClosingTag(tnum) if _debug: closing_endec._debug(" - tag1: %r", tag1) # decode the blob into a tag tag2 = closing_decode(blob1) if _debug: closing_endec._debug(" - tag2: %r", tag2) # encode the tag into a blob blob2 = closing_encode(tag1) if _debug: closing_endec._debug(" - blob2: %r", blob2) # compare the results assert tag1 == tag2 assert blob1 == blob2
def test_octet_string_copy(self): if _debug: TestOctetString._debug("test_octet_string_copy") obj1 = OctetString(xtob('01')) obj2 = OctetString(obj1) assert obj2.value == xtob('01')
def test_boolean_application_to_object(self): if _debug: TestApplicationTag._debug("test_boolean_application_to_object") # null obj_endec(Null(), '00') # boolean obj_endec(Boolean(True), '11') obj_endec(Boolean(False), '10') # unsigned obj_endec(Unsigned(0), '2100') obj_endec(Unsigned(1), '2101') obj_endec(Unsigned(127), '217F') obj_endec(Unsigned(128), '2180') # integer obj_endec(Integer(0), '3100') obj_endec(Integer(1), '3101') obj_endec(Integer(-1), '31FF') obj_endec(Integer(128), '320080') obj_endec(Integer(-128), '3180') # real obj_endec(Real(0), '4400000000') obj_endec(Real(1), '443F800000') obj_endec(Real(-1), '44BF800000') obj_endec(Real(73.5), '4442930000') # double obj_endec(Double(0), '55080000000000000000') obj_endec(Double(1), '55083FF0000000000000') obj_endec(Double(-1), '5508BFF0000000000000') obj_endec(Double(73.5), '55084052600000000000') # octet string obj_endec(OctetString(xtob('')), '60') obj_endec(OctetString(xtob('01')), '6101') obj_endec(OctetString(xtob('0102')), '620102') obj_endec(OctetString(xtob('010203040506')), '6506010203040506') # character string obj_endec(CharacterString(''), '7100') obj_endec(CharacterString('a'), '720061') obj_endec(CharacterString('abcde'), '7506006162636465') # bit string obj_endec(BitString([]), '8100') obj_endec(BitString([0]), '820700') obj_endec(BitString([1]), '820780') obj_endec(BitString([1, 1, 1, 1, 1]), '8203F8') obj_endec(BitString([1] * 10), '8306FFC0') # enumerated obj_endec(Enumerated(0), '9100') obj_endec(Enumerated(1), '9101') obj_endec(Enumerated(127), '917F') obj_endec(Enumerated(128), '9180') # date obj_endec(Date((1, 2, 3, 4)), 'A401020304') obj_endec(Date((255, 2, 3, 4)), 'A4FF020304') obj_endec(Date((1, 255, 3, 4)), 'A401FF0304') obj_endec(Date((1, 2, 255, 4)), 'A40102FF04') obj_endec(Date((1, 2, 3, 255)), 'A4010203FF') # time obj_endec(Time((1, 2, 3, 4)), 'B401020304') obj_endec(Time((255, 2, 3, 4)), 'B4FF020304') obj_endec(Time((1, 255, 3, 4)), 'B401FF0304') obj_endec(Time((1, 2, 255, 4)), 'B40102FF04') obj_endec(Time((1, 2, 3, 255)), 'B4010203FF') # object identifier obj_endec(ObjectIdentifier(0, 0), 'C400000000') obj_endec(ObjectIdentifier(1, 0), 'C400400000') obj_endec(ObjectIdentifier(0, 2), 'C400000002') obj_endec(ObjectIdentifier(3, 4), 'C400C00004')
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")
def test_octet_string_statement(self): if _debug: TestExtendedTagStatements._debug("test_octet_string_statement") assert statement_to_tag("octet string 0102") == tag_encode(OctetString(xtob("0102"))) assert statement_to_tag("octet string 01020304 context 7") == tag_encode(OctetString(xtob("01020304")), context=7)
def do_write(self, args): """write <addr> <objid> <prop> [ <indx> ]""" args = args.split() if _debug: WriteSomethingConsoleCmd._debug("do_write %r", args) try: addr, obj_id, prop_id = args[:3] obj_id = ObjectIdentifier(obj_id).value if prop_id.isdigit(): prop_id = int(prop_id) # build a request request = WritePropertyRequest( objectIdentifier=obj_id, propertyIdentifier=prop_id, ) request.pduDestination = Address(addr) if len(args) == 4: request.propertyArrayIndex = int(args[3]) # build a custom datastructure tag_list = TagList([ OpeningTag(1), ContextTag(0, xtob('9c40')), ContextTag(1, xtob('02')), ContextTag(2, xtob('02')), ClosingTag(1) ]) if _debug: WriteSomethingConsoleCmd._debug(" - tag_list: %r", tag_list) # stuff the tag list into an Any request.propertyValue = Any() request.propertyValue.decode(tag_list) if _debug: WriteSomethingConsoleCmd._debug(" - request: %r", request) # make an IOCB iocb = IOCB(request) if _debug: WriteSomethingConsoleCmd._debug(" - iocb: %r", iocb) # give it to the application deferred(this_application.request_io, iocb) # wait for it to complete iocb.wait() # do something for success if iocb.ioResponse: # should be an ack if not isinstance(iocb.ioResponse, SimpleAckPDU): if _debug: WriteSomethingConsoleCmd._debug(" - not an ack") return sys.stdout.write("ack\n") # do something for error/reject/abort if iocb.ioError: sys.stdout.write(str(iocb.ioError) + '\n') except Exception as error: WriteSomethingConsoleCmd._exception("exception: %r", error)
def main(): global args, schedule_objects # parse the command line arguments parser = ConfigArgumentParser(description=__doc__) # parse the command line arguments args = parser.parse_args() if _debug: _log.debug("initialization") if _debug: _log.debug(" - args: %r", args) # make a device object this_device = LocalDeviceObject(ini=args.ini) if _debug: _log.debug(" - this_device: %r", this_device) # make a sample application this_application = BIPSimpleApplication(this_device, args.ini.address) # # Simple daily schedule (actually a weekly schedule with every day # being identical. # so = LocalScheduleObject( objectIdentifier=('schedule', 1), objectName='Schedule 1', presentValue=Integer(8), effectivePeriod=DateRange( startDate=(0, 1, 1, 1), endDate=(254, 12, 31, 2), ), weeklySchedule=ArrayOf(DailySchedule)([ DailySchedule(daySchedule=[ TimeValue(time=(8, 0, 0, 0), value=Integer(8)), TimeValue(time=(14, 0, 0, 0), value=Null()), TimeValue(time=(17, 0, 0, 0), value=Integer(42)), # TimeValue(time=(0,0,0,0), value=Null()), ]), ] * 7), scheduleDefault=Integer(0), ) _log.debug(" - so: %r", so) this_application.add_object(so) schedule_objects.append(so) # # A special schedule when the Year 2000 problem was supposed to collapse # systems, the panic clears ten minutes later when it didn't. # so = LocalScheduleObject( objectIdentifier=('schedule', 2), objectName='Schedule 2', presentValue=CharacterString(""), effectivePeriod=DateRange( startDate=(0, 1, 1, 1), endDate=(254, 12, 31, 2), ), exceptionSchedule=ArrayOf(SpecialEvent)([ SpecialEvent( period=SpecialEventPeriod(calendarEntry=CalendarEntry( date=Date("2000-01-01").value, ), ), listOfTimeValues=[ TimeValue(time=(0, 0, 0, 0), value=CharacterString("Panic!")), TimeValue(time=(0, 10, 0, 0), value=Null()), ], eventPriority=1, ), ]), scheduleDefault=CharacterString("Don't panic."), ) _log.debug(" - so: %r", so) this_application.add_object(so) schedule_objects.append(so) # # A special schedule to celebrate Friday. # so = LocalScheduleObject( objectIdentifier=('schedule', 3), objectName='Schedule 3', presentValue=CharacterString(""), effectivePeriod=DateRange( startDate=(0, 1, 1, 1), endDate=(254, 12, 31, 2), ), exceptionSchedule=ArrayOf(SpecialEvent)([ SpecialEvent( period=SpecialEventPeriod(calendarEntry=CalendarEntry( weekNDay=xtob("FF.FF.05"), ), ), listOfTimeValues=[ TimeValue(time=(0, 0, 0, 0), value=CharacterString("It's Friday!")), ], eventPriority=1, ), ]), scheduleDefault=CharacterString("Keep working."), ) _log.debug(" - so: %r", so) this_application.add_object(so) schedule_objects.append(so) # # A schedule object that refers to an AnalogValueObject in the test # device. # so = LocalScheduleObject( objectIdentifier=('schedule', 4), objectName='Schedule 4', presentValue=Real(73.5), effectivePeriod=DateRange( startDate=(0, 1, 1, 1), endDate=(254, 12, 31, 2), ), weeklySchedule=ArrayOf(DailySchedule)([ DailySchedule(daySchedule=[ TimeValue(time=(9, 0, 0, 0), value=Real(78.0)), TimeValue(time=(10, 0, 0, 0), value=Null()), ]), ] * 7), scheduleDefault=Real(72.0), listOfObjectPropertyReferences=SequenceOf( DeviceObjectPropertyReference)([ DeviceObjectPropertyReference( objectIdentifier=('analogValue', 1), propertyIdentifier='presentValue', ), ]), ) _log.debug(" - so: %r", so) this_application.add_object(so) schedule_objects.append(so) # # The beast # so = LocalScheduleObject( objectIdentifier=('schedule', 5), objectName='Schedule 5', presentValue=Integer(0), effectivePeriod=DateRange( startDate=(0, 1, 1, 1), endDate=(254, 12, 31, 2), ), exceptionSchedule=ArrayOf(SpecialEvent)([ SpecialEvent( period=SpecialEventPeriod(calendarEntry=CalendarEntry( weekNDay=xtob("FF.FF.FF"), ), ), listOfTimeValues=[ TimeValue(time=(5, 0, 0, 0), value=Integer(5)), TimeValue(time=(6, 0, 0, 0), value=Null()), ], eventPriority=1, ), SpecialEvent( period=SpecialEventPeriod(calendarEntry=CalendarEntry( weekNDay=xtob("FF.FF.FF"), ), ), listOfTimeValues=[ TimeValue(time=(4, 0, 0, 0), value=Integer(4)), TimeValue(time=(7, 0, 0, 0), value=Null()), ], eventPriority=2, ), SpecialEvent( period=SpecialEventPeriod(calendarEntry=CalendarEntry( weekNDay=xtob("FF.FF.FF"), ), ), listOfTimeValues=[ TimeValue(time=(3, 0, 0, 0), value=Integer(3)), TimeValue(time=(8, 0, 0, 0), value=Null()), ], eventPriority=3, ), SpecialEvent( period=SpecialEventPeriod(calendarEntry=CalendarEntry( weekNDay=xtob("FF.FF.FF"), ), ), listOfTimeValues=[ TimeValue(time=(2, 0, 0, 0), value=Integer(2)), TimeValue(time=(9, 0, 0, 0), value=Null()), ], eventPriority=4, ), SpecialEvent( period=SpecialEventPeriod(calendarEntry=CalendarEntry( weekNDay=xtob("FF.FF.FF"), ), ), listOfTimeValues=[ TimeValue(time=(1, 0, 0, 0), value=Integer(1)), ], eventPriority=5, ), ]), scheduleDefault=Integer(0), ) _log.debug(" - so: %r", so) this_application.add_object(so) schedule_objects.append(so) # list of time values for every five minutes ltv = [] for hr in range(24): for mn in range(0, 60, 5): ltv.append( TimeValue(time=(hr, mn, 0, 0), value=Integer(hr * 100 + mn))) so = LocalScheduleObject( objectIdentifier=('schedule', 6), objectName='Schedule 6', presentValue=Integer(0), effectivePeriod=DateRange( startDate=(0, 1, 1, 1), endDate=(254, 12, 31, 2), ), exceptionSchedule=ArrayOf(SpecialEvent)([ SpecialEvent( period=SpecialEventPeriod(calendarEntry=CalendarEntry( weekNDay=xtob("FF.FF.FF"), ), ), listOfTimeValues=ltv, eventPriority=1, ), ]), scheduleDefault=Integer(0), ) _log.debug(" - so: %r", so) this_application.add_object(so) schedule_objects.append(so) # make sure they are all there _log.debug(" - object list: %r", this_device.objectList) TestConsoleCmd() _log.debug("running") run() _log.debug("fini")
def test_registration(self): """Test foreign device registration.""" if _debug: TestForeign._debug("test_registration") # create a network tnet = TNetwork() # add an addition codec node to the home vlan cnode = CodecNode("192.168.5.2/24", tnet.home_vlan) tnet.append(cnode) # home sniffer node home_sniffer = SnifferNode("192.168.5.254/24", tnet.home_vlan) tnet.append(home_sniffer) # remote sniffer node remote_sniffer = SnifferNode("192.168.6.254/24", tnet.remote_vlan) tnet.append(remote_sniffer) # tell the B/IP layer of the foreign device to register tnet.fd.start_state \ .call(tnet.fd.bip.register, tnet.bbmd.address, 30) \ .success() # sniffer pieces registration_request = xtob('81.05.0006' # bvlci '001e' # time-to-live ) registration_ack = xtob('81.00.0006.0000') # simple ack # remote sniffer sees registration remote_sniffer.start_state.doc("1-1-0") \ .receive(PDU, pduData=registration_request).doc("1-1-1") \ .receive(PDU, pduData=registration_ack).doc("1-1-2") \ .set_event('fd-registered').doc("1-1-3") \ .success() # the bbmd is idle tnet.bbmd.start_state.success() # read the FDT cnode.start_state.doc("1-2-0") \ .wait_event('fd-registered').doc("1-2-1") \ .send(ReadForeignDeviceTable(destination=tnet.bbmd.address)).doc("1-2-2") \ .receive(ReadForeignDeviceTableAck).doc("1-2-3") \ .success() # the tnode reads the registration table read_fdt_request = xtob('81.06.0004') # bvlci read_fdt_ack = xtob( '81.07.000e' # read-ack 'c0.a8.06.02.ba.c0 001e 0023' # address, ttl, remaining ) # home sniffer sees registration home_sniffer.start_state.doc("1-3-0") \ .receive(PDU, pduData=registration_request).doc("1-3-1") \ .receive(PDU, pduData=registration_ack).doc("1-3-2") \ .receive(PDU, pduData=read_fdt_request).doc("1-3-3") \ .receive(PDU, pduData=read_fdt_ack).doc("1-3-4") \ .success() # run the group tnet.run()
def do_write(self, args): """write <addr> <type> <inst> <prop> [ <indx> ]""" args = args.split() if _debug: WriteSomethingConsoleCmd._debug("do_write %r", args) try: addr = args[0] obj_type = 162 #int(obj_type) obj_inst = 1 #int(obj_inst) prop_id = 1034 #int(prop_id) idx = 2 # build a request request = WritePropertyRequest( objectIdentifier=(obj_type, obj_inst), propertyIdentifier=prop_id, ) request.pduDestination = Address(addr) if len(args) >= 5: request.propertyArrayIndex = 2 #int(args[4]) request.propertyArrayIndex = idx if len(args) == 6: #convert ip to byte array and then to hex string proxy = bytearray(args[5]) proxy_hex = str(proxy).encode('hex') # build a custom data structure... BACnet settings BCP object IP BBMD Foreign port eTCH 3.40 # Context #0 inside Opening tag #9 is the IP Type 00=Regular, 01=Foreign, 02=BBMD # Context #2 inside Opening tag #9 is the Foreign IP in hex # Context #4 inside Opening tag #9 is the Proxy IP in hex tag_list = TagList([ OpeningTag(0), ContextTag(0, xtob('19')), ContextTag(1, xtob('01')), ClosingTag(0), ContextTag(1, xtob('01')), ContextTag(2, xtob('00')), ContextTag(3, xtob('9c40')), ContextTag(4, xtob('00')), OpeningTag(5), ContextTag(0, xtob('00')), ContextTag(1, xtob('00')), ClosingTag(5), ContextTag(6, xtob('00')), ContextTag(7, xtob('00')), OpeningTag(8), ContextTag(0, xtob('00')), ContextTag(1, xtob('00')), ContextTag(2, xtob('00')), ContextTag(3, xtob('00')), ContextTag(4, xtob('00')), ContextTag(5, xtob('00')), ContextTag(6, xtob('00')), ContextTag(7, xtob('00')), ContextTag(8, xtob('ffffffff')), ClosingTag(8), OpeningTag(9), ContextTag(0, xtob('02')), ContextTag(1, xtob('bac0')), ContextTag(2, xtob('00')), ContextTag(3, xtob('3c')), ContextTag(4, xtob('480c600c')), ContextTag(5, xtob('00')), ContextTag(6, xtob('ffffffff')), ClosingTag(9), ContextTag(10, xtob('00')), ContextTag(11, xtob('00')), ContextTag(12, xtob('00')), ContextTag(13, xtob('00000000')) ]) if _debug: WriteSomethingConsoleCmd._debug(" - tag_list: %r", tag_list) # stuff the tag list into an Any request.propertyValue = Any() request.propertyValue.decode(tag_list) if _debug: WriteSomethingConsoleCmd._debug(" - request: %r", request) # make an IOCB iocb = IOCB(request) if _debug: WriteSomethingConsoleCmd._debug(" - iocb: %r", iocb) # give it to the application this_application.request_io(iocb) # wait for it to complete iocb.wait() # do something for success if iocb.ioResponse: # should be an ack if not isinstance(iocb.ioResponse, SimpleAckPDU): if _debug: WriteSomethingConsoleCmd._debug(" - not an ack") return sys.stdout.write("ack\n") # do something for error/reject/abort if iocb.ioError: sys.stdout.write(str(iocb.ioError) + '\n') except Exception as error: WriteSomethingConsoleCmd._exception("exception: %r", error)
def test_null_tag(self): if _debug: TestInteger._debug("test_null_tag") tag = Tag(Tag.applicationTagClass, Tag.nullAppTag, 0, xtob('')) obj = Null(tag) assert obj.value == ()