[pyasn1-users] (no subject)
Brought to you by:
elie
From: Nikolay N. <nik...@gm...> - 2015-02-02 20:07:10
|
Hi, I am trying to create a new module for 3gpp 32.298 MMTel CDR. I have started experimenting with simple definition: DEFINITIONS IMPLICIT TAGS ::= BEGIN -- EXPORTS everything MMTelRecord ::= SET { recordType [0] RecordType, retransmission [1] NULL OPTIONAL, sIP-Method [2] SIP-Method OPTIONAL, role-of-Node [3] Role-of-Node OPTIONAL } RecordType ::= INTEGER { -- Record Value 83 is MMTel specific. -- The contents are defined in TS 32.275 [35] -- mMTelRecord (83) } SIP-Method ::= GraphicString Role-of-Node ::= ENUMERATED { originating (0), terminating (1) } END and description of the definition in with pyasn1 that I have created is: from pyasn1.type import univ, namedtype, tag, char, namedval, constraint ''' Test to encode and decoder IMS MMTel CDR ber files Using just a subset of MMTelRecord ASN1 definition defined in 3GPP TS 32.298 ''' MAX = 64 class RecordType(univ.Integer): namedValues = namedval.NamedValues( ('mMTelRecord', 83) ) class SIPMethod(char.GraphicString): pass class RoleOfNode(univ.Enumerated): namedValues = namedval.NamedValues( ('originating', 0), ('terminating', 1) ) subtypeSpec = univ.Enumerated.subtypeSpec + constraint.SingleValueConstraint(0, 1) class MMTelRecord(univ.Set): componentType = namedtype.NamedTypes( namedtype.NamedType('recordType', RecordType().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))), namedtype.OptionalNamedType('retransmission', univ.Null().subtype( implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))), namedtype.OptionalNamedType('sIP-Method', SIPMethod().subtype( implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2))), namedtype.OptionalNamedType('role-of-Node', RoleOfNode().subtype( implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 3))), ) class MMTelRecords(univ.SetOf): componentType = MMTelRecord() sizeSpec = univ.SetOf.sizeSpec + constraint.ValueSizeConstraint(1, MAX) Here is how I try encode and write the ber file: #!/usb/bin/python from pyasn1.codec.ber import encoder, decoder from modules import mmtel3gpp32298 as mmtel from time import sleep ''' Test to encode and decoder IMS MMTel CDR ber files Using just a subset of MMTelRecord ASN1 definition defined in 3GPP TS 32.298 ''' def cdr_write(file): records = mmtel.MMTelRecords() for i in range(0,1): print "Start of cdr log: " + str(i) record = mmtel.MMTelRecord() records.setComponentByPosition(i, record.setComponentByPosition(0, mmtel.RecordType(83), '')) records.setComponentByPosition(i, record.setComponentByPosition(2, mmtel.SIPMethod('INVITE'), '')) records.setComponentByPosition(i, record.setComponentByPosition(3, mmtel.RoleOfNode(0), '')) # print record.prettyPrint() print str(record) print "End of cdr log: " + str(i) sleep(2) w_data = encoder.encode(records) print w_data # print "Filename: " + file with open(file, 'wb') as f: # f.write(w_data) f.write(w_data) f.close def cdr_read(file): with open(file, 'rb') as f: r_data = f.read f.close() data = decoder.decode(r_data, asn1Spec=mmtel.MMTelRecord) print data if __name__ == "__main__": file = 'mcdr2.ber' cdr_write(file) cdr_read(file) ########### Ber file is created but cannot it cannot be decoded: Traceback (most recent call last): File "C:/Users/nnenchev/PycharmProjects/mmtel-cdrs/mmtel.py", line 57, in <module> cdr_read(file) File "C:/Users/nnenchev/PycharmProjects/mmtel-cdrs/mmtel.py", line 46, in cdr_read data = decoder.decode(r_data, asn1Spec=mmtel.MMTelRecord) File "C:\Python27\lib\site-packages\pyasn1-0.1.7-py2.7.egg\pyasn1\codec\ber\decoder.py", line 600, in __call__ pyasn1.error.PyAsn1Error: Bad octet stream type If I compare hexdump of the produced ber file with one created from asn1 studio from OSS Nokalva, seems that my ber file is not correct. Ber file from asn1studio $ xxd.exe MMTelRecord.ber 0000000: 310e 8001 5382 0649 4e56 4954 4583 0100 1...S..INVITE... Ber file procudes with python script above. $ xxd.exe mcdr2.ber 0000000: 3110 310e 0201 5319 0649 4e56 4954 450a 1.1...S..INVITE. 0000010: 0100 Can you please advise what I am doing wrong? BR Nikolay |