Design a flow record parser contract
Why flow accounting starts with an observer
A dispatcher notices two F-01 rows with different volumes in the overnight export. The gateway counts traffic at its outside observation point. A central collector receives a second observation from the application side. Each appliance calls its first flow by the same local identifier. One exporter also retried an identical record after a delayed acknowledgement. Adding all three numbers produces an impressive total, but nobody can reproduce what it measures from the flow number alone.
Define the accounting question before reading the records. In this lesson we count distinct records per observer and preserve their original counters. The application payload, hours worked by a human and the number of independent client connections all require different evidence. The restricted question gives us an unambiguous expected result to put in a unit test. Before running code, underline the two fields in the example that another reviewer would need in order to find an individual record again.
Evidence supplied by the owner
sensor,flow,start,end,octets
EDGE,F-01,11,16,720
EDGE,F-01,11,16,720
CORE,F-01,12,16,640
Read the export contract
The header fixes five columns and their order. EDGE and CORE each own an identifier namespace for this single export. Times are integral ticks on one fictional clock. The octets field already contains a byte count for the record. There is no directional breakdown in the supplied table. Zero is a legitimate measurement and deserves its own regression test. A missing field means unavailable data. Filling a blank with zero would remove the distinction before a reviewer has seen the row.
The IPFIX specification describes observation domains, exporting processes and the template that gives fields their meaning. This classroom CSV is a documented representation after export. A short sensor name stands for the agreed exporter and domain combination for this exercise alone. For a different batch, obtain the schema, units, counter semantics and identifier reset policy from the owner. A device reboot or a new export period can otherwise reuse an old key and invalidate the uniqueness assumption.
Implement and inspect
import csv, io, re
COLUMNS = ["sensor", "flow", "start", "end", "octets"]
def parse_flows(csv_text):
reader = csv.reader(io.StringIO(csv_text, newline=""), strict=True)
if next(reader, None) != COLUMNS:
raise ValueError("unexpected header")
result = {}
for fields in reader:
if len(fields) != len(COLUMNS):
raise ValueError("unexpected column count")
sensor, flow, *counters = fields
if sensor not in {"EDGE", "CORE"} or not re.fullmatch(r"F-[0-9]{2}", flow):
raise ValueError("unknown sensor or malformed local ID")
if not all(re.fullmatch(r"[0-9]{1,12}", value) for value in counters):
raise ValueError("bad integer in record")
start, end, octets = map(int, counters)
if end < start:
raise ValueError("negative duration")
key = sensor, flow
record = start, end, octets
if key in result and result[key] != record:
raise ValueError("conflicting revision")
result[key] = record
return result
Handle retries without discarding conflicts
The parser accepts the supplied text as an argument and uses csv.reader so that quoted fields and line endings follow CSV rules. After checking the record shape it converts three fields to integers. Converting before comparison makes 016 and 16 equal, as the classroom schema permits leading zeros. The width limit on numeric fields is visible in the validation rule and could become part of a later schema version.
A dictionary associates the scoped key with its measurement. Receiving that pair twice has no effect on the result. A different measurement for the same key is a revision conflict. Processing stops so the owner can restore an authoritative record. Choosing whichever row came last would make the total depend on the order of files during a retry. Keep the batch identity and explanation with the reconciliation request. Reprocess the corrected batch as one unit before handing the result to the accounting team.
Boundary experiments
Trial 1. Swap two rows from different sensors. Sorting the keys must give exactly the original records. If the result changes, inspect whether a single local identifier accidentally became the primary key.
Trial 2. Place both endpoints on the same tick. The fictional clock resolution permits a short record with zero duration. Move the end one tick before the start and verify the batch is rejected before a result is published.
Exercise. Handover to the next shift
The second shift sends an export from a training segment. The controller asks for separate sensor totals and the number of source rows behind each resulting card.
sensor,flow,start,end,octets
CORE,F-20,30,32,280
EDGE,F-20,29,32,320
CORE,F-20,30,32,280
Recover the keys, counters and repetitions for every card. Specify one extra line that exercises the conflict branch. Run the two batches independently and save the expected outcome alongside the table.
Compare your independent decision
There are two cards. EDGE/F-20 measured 320 octets once. CORE/F-20 measured 280 octets and appeared twice. Adding a CORE/F-20 row with the same timestamps and 281 octets produces a conflict. The second run has no final accounts to publish.
Sources
IETF RFC 7011. IP Flow Information Export · Python. CSV
Test your conclusion
Which device can you attribute this session to?
Gateway log
session K2 public=192.0.2.7:4110 clock=13:10:00 ±3s
Translation log
DEV-A same tuple through 13:09:59 DEV-B same tuple from 13:10:00
Insufficient evidence. Clock uncertainty spans both bindings. The unadjusted timestamp gives one candidate spurious priority.
Supported. Seek a K2 receipt with the internal address or independently narrow the clock uncertainty.
Independent exercise

In a different export a counter appears with and without a leading zero. Another observer independently used the same local number.
Evidence
sensor,flow,start,end,octets EDGE,F-09,2,4,030 CORE,F-09,2,4,21 EDGE,F-09,2,4,30
Assignment
List the scoped keys and their numeric readings. Change one field in the final row to invalidate the batch.
Compare your reasoning
EDGE/F-09 has 30 octets and CORE/F-09 has 21. The leading zero is permitted. Changing the final counter to 31 introduces a conflict and rejects the batch.
Personal practice environment
Check an excerpt, find matching lines and compute the SHA-256 of the original text. Temporary data expires after 30 minutes or when you close the environment.
Sign in