Skip to content

Add script to transform UDP JSON payload#61

Open
xtor wants to merge 2 commits into
Linutronix:mainfrom
xtor:udp-json-to-fixed
Open

Add script to transform UDP JSON payload#61
xtor wants to merge 2 commits into
Linutronix:mainfrom
xtor:udp-json-to-fixed

Conversation

@xtor

@xtor xtor commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

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:
  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>:

xtor added 2 commits July 5, 2026 20:08
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
shifty91 self-requested a review July 7, 2026 11:44
@shifty91 shifty91 self-assigned this Jul 7, 2026
@shifty91 shifty91 added the enhancement New feature or request label Jul 7, 2026

@shifty91 shifty91 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'
]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why reuse is unhappy here. Please, investigate and fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants