Add script to transform UDP JSON payload#61
Conversation
This script transforms the statistics payload from JSON to fixed-length keys and values. This allows receivers with limited parsing capabilities to extract and display the stats. In a little bit more detail, it: 1. Receives UDP packets with RTC TB stats on localhost:<port> 2. Parses the RTC Testbench JSON payload 3. Transforms it into a sequence of fixed-length string and uint64 4. Forwards the result as payload of a UDP packet to <dest_ip>:<port> Signed-off-by: xtor <hector.blanco.alcaine@intel.com>
Signed-off-by: xtor <hector.blanco.alcaine@intel.com>
shifty91
left a comment
There was a problem hiding this comment.
The AI reviews/bugreports look legit. Please, investigate and fix. Furthermore, fix the SoB lines in your commits (xtor is not a valid name :-). And please, run pre-commit run --all-files. Thanks!
| if TRACE_OUTPUT: | ||
| # Slice in ENTRY_LEN size chunks | ||
| metrics = [output_payload[i : i + ENTRY_LEN] for i in range(0, len(output_payload), ENTRY_LEN)] | ||
| for metric in metrics: |
There was a problem hiding this comment.
AI review: This reassigns metrics, which is the same variable that holds the default/soc selection passed into run(). On the next loop iteration transform_payload(raw_data, metrics) receives a list of byte chunks instead of the mode string, so metrics == "soc" in transform_payload() is never true again — SoC metrics are silently dropped after the first packet whenever TRACE_OUTPUT is enabled.
Renaming the local, e.g. entries = [...] / for entry in entries:, fixes it.
|
|
||
| if metrics == "soc": | ||
| whitelist += SOC_METRICS | ||
|
|
There was a problem hiding this comment.
AI review: whitelist is a reference to the module-level WHITELIST_REFERENCE/WHITELIST_MIRROR list, and += on a list mutates it in place. In soc mode the global therefore grows by 9 entries on every received packet (currently masked by the metrics shadowing issue in run()).
Use a copy instead: whitelist = whitelist + SOC_METRICS
| 'RxXdp2AppMin', 'RxXdp2AppMax', | ||
|
|
||
| 'TxHwTimestampingMissing' | ||
| ] |
There was a problem hiding this comment.
AI review: The testbench emits this stat as TxHwTimestampMissing (src/stat.c, stat_to_json()), not TxHwTimestampingMissing, so this whitelist entry never matches and the stat is never forwarded.
|
|
||
| int_value: int = int(value) # raises ValueError on bad input | ||
| if not (0 <= int_value <= 0xFFFF_FFFF_FFFF_FFFF): | ||
| raise ValueError( |
There was a problem hiding this comment.
AI review: OnewayMin/OnewayMax are emitted as signed integers (append_jlog_i64() in src/stat.c) and go negative whenever the two clocks aren't synchronized. A negative value makes encode_entry() raise ValueError, and the exception handler in run() then drops the entire datagram — so one negative oneway value suppresses all stats for that traffic class, every interval.
The fixed-uint64 format needs a deliberate policy here rather than a packet drop: clamp to 0, encode the value as int64, or skip just the offending entry. Related: the averages (OnewayAv, RoundTripAv) arrive as JSON floats and are silently truncated by int(value) — probably acceptable, but worth documenting in the format description.
| #!/usr/bin/env python3 | ||
| # SPDX-License-Identifier: BSD-2-Clause | ||
| # Copyright(C) 2026 Intel Corporation | ||
| # Authors: |
There was a problem hiding this comment.
I'm not sure why reuse is unhappy here. Please, investigate and fix.
This script transforms the statistics payload from JSON to fixed-length
keys and values. This allows receivers with limited parsing capabilities
to extract and display the stats.
In a little bit more detail, it: