Skip to content

Commit

Permalink
Add test for IPFIX padding handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bitkeks committed Aug 19, 2023
1 parent d269142 commit a829d42
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion netflow/ipfix.py
Original file line number Diff line number Diff line change
Expand Up @@ -1025,4 +1025,4 @@ def rest_is_padding_zeroes(data: bytes, offset: int) -> bool:
return True

# If offset > len(data) there is an error
raise ValueError
raise ValueError("netflow.ipfix.rest_is_padding_zeroes received a greater offset value than there is data")
13 changes: 13 additions & 0 deletions tests/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,3 +310,16 @@ def single_packet(pkts):
"000000400000000100000000000000008800060000000000123456affefeaffeaffeaffe08000054" \
"fde66f14e0f196090000affeaffeaffe2a044e42020000000000000000000223e58bc8ede58be4d8" \
"00000140000000040000000000000000e54c01bb0602060000000000affeaffeaffe123456affefe"

PACKET_IPFIX_PADDING = "000a01c064e0b1900000000200000000000200480400001000080004000c00040016000400150004" \
"0001000400020004000a0004000e0004003d00010088000100070002000b00020004000100060001" \
"003c000100050001000200400401000e00080004000c000400160004001500040001000400020004" \
"000a0004000e0004003d0001008800010020000200040001003c0001000500010002004808000010" \
"001b0010001c001000160004001500040001000400020004000a0004000e0004003d000100880001" \
"00070002000b00020004000100060001003c000100050001000200400801000e001b0010001c0010" \
"00160004001500040001000400020004000a0004000e0004003d000100880001008b000200040001" \
"003c00010005000100030022010000060001008f000400a000080131000401320004013000020052" \
"0010040100547f0000017f000001ffff07d0ffff0ff7000000fc0000000300000000000000000001" \
"08000104007f0000017f000001ffff07d0ffff0ff7000000fc000000030000000000000000000100" \
"0001040000000100002a0000b2da0000018a0db59d2e000000010000000000017465737463617074" \
"7572655f73696e67"
18 changes: 17 additions & 1 deletion tests/test_ipfix.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import unittest

from tests.lib import send_recv_packets, PACKET_IPFIX_TEMPLATE, PACKET_IPFIX, PACKET_IPFIX_ETHER, \
PACKET_IPFIX_TEMPLATE_ETHER
PACKET_IPFIX_TEMPLATE_ETHER, PACKET_IPFIX_PADDING


class TestFlowExportIPFIX(unittest.TestCase):
Expand Down Expand Up @@ -98,3 +98,19 @@ def test_ipfix_contents_ether(self):
self.assertTrue(hasattr(flow, "postDestinationMacAddress"))
self.assertEqual(flow.sourceMacAddress, 0x123456affefe)
self.assertEqual(flow.postDestinationMacAddress, 0xaffeaffeaffe)

def test_ipfix_padding(self):
"""
Checks successful parsing of export packets that contain padding zeroes in an IPFIX set.
The padding in the example data is in between the last two data sets, so the successful parsing of the last
data set indicates correct handling of padding zero bytes.
"""
pkts, _, _ = send_recv_packets([PACKET_IPFIX_PADDING])
self.assertEqual(len(pkts), 1)
p = pkts[0]

# Check for length of whole export
self.assertEqual(p.export.header.length, 448)

# Check a specific value of the last flow in the export. Success means correct handling of padding in the set
self.assertEqual(p.export.flows[-1].meteringProcessId, 45786)

0 comments on commit a829d42

Please sign in to comment.