Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
shravan86 opened this issue Jan 30, 2018 · 0 comments · May be fixed by #25
Open

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

shravan86 opened this issue Jan 30, 2018 · 0 comments · May be fixed by #25

Comments

@shravan86
Copy link

shravan86 commented Jan 30, 2018

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

notti added a commit to notti/python-ipfix that referenced this issue Aug 21, 2018
This fixes britram#24 - should have looked at the issue tracker before looking
into the problem....
@notti notti linked a pull request Aug 21, 2018 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant