python-ipfix icon indicating copy to clipboard operation
python-ipfix copied to clipboard

Encoding and decoding fails for template with first ie element being varlen

Open shravan86 opened this issue 8 years ago • 0 comments

Hello,

PROBLEM:

If we define a template with the first ie element being a varlen, then the decoding does not seem to work. Please see the below to reproduce the issue -

import ipfix.template import ipfix.ie import hexdump from datetime import datetime from ipaddress import ip_address

msg = ipfix.message.MessageBuffer()

msg.begin_export(8304)

ipfix.ie.use_iana_default()

tmpl = ipfix.template.from_ielist(256, ipfix.ie.spec_list(("applicationName", "flowStartMilliseconds", "sourceIPv4Address", "destinationIPv4Address", "packetDeltaCount")))

msg.add_template(tmpl)

msg.export_ensure_set(256)

rec = { "applicationName" : "testing123", "flowStartMilliseconds" : datetime.strptime("2013-06-21 14:00:00", "%Y-%m-%d %H:%M:%S"), "sourceIPv4Address" : ip_address("10.1.2.3"), "destinationIPv4Address" : ip_address("10.5.6.7"), "packetDeltaCount" : 27}

msg.export_namedict(rec)

print(msg) print(hexdump.dump(msg.to_bytes()))

###################################################

READER

###################################################

msg1 = ipfix.message.MessageBuffer() msg1.from_bytes(msg.to_bytes())

for rec in msg1.namedict_iterator(): print(sorted(rec.items()))

FIX:

The root cause of the issue is in template.py - encode_to() and decode_from() methods.

diff --git a/ipfix/template.py b/ipfix/template.py index 1203e55..87a7f5b 100644 --- a/ipfix/template.py +++ b/ipfix/template.py @@ -187,7 +187,7 @@ class Template(object): offset += packplan.st.size

     # short circuit on no varlen
  •    if not self.varlenslice:
    
  •    if self.varlenslice == None:
           return (vals, offset)
    
       # direct iteration over remaining IEs
    

@@ -239,7 +239,7 @@ class Template(object): offset += packplan.st.size

     # shortcircuit no varlen
  •    if not self.varlenslice:
    
  •    if self.varlenslice == None:
           return offset
    
       # direct iteration over remaining IEs
    

If you are ok with this fix. Please let me know how to commit this change to master. I have also attached the diff file.

Thanks Shravan

diff.txt

shravan86 avatar Jan 30 '18 18:01 shravan86