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
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
if self.varlenslice == None: return (vals, offset)
@@ -239,7 +239,7 @@ class Template(object): offset += packplan.st.size
if self.varlenslice == None: return offset
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