Skip to content

[vpp] Add sonic_ext packet-trim admission shim (SAI DROP_AND_TRIM datapath) - #269

Draft
aaronber0614 wants to merge 3 commits into
sonic-net:masterfrom
aaronber0614:vpp-packet-trimming
Draft

[vpp] Add sonic_ext packet-trim admission shim (SAI DROP_AND_TRIM datapath)#269
aaronber0614 wants to merge 3 commits into
sonic-net:masterfrom
aaronber0614:vpp-packet-trimming

Conversation

@aaronber0614

@aaronber0614 aaronber0614 commented Aug 3, 2026

Copy link
Copy Markdown

What / Why

Adds the sonic_ext VPP plugin datapath that implements the SAI
DROP_AND_TRIM packet-trimming behavior for the SONiC-VPP platform.

Because SONiC-VPP has no hardware queue-admission engine, trimming is
implemented as a software admission shim on the interface-output
feature arc. When a trim-eligible egress queue cannot admit a packet, the shim
truncates it to the configured size, rewrites DSCP, and re-queues it on the
configured static trim queue on the same physical egress; non-eligible or
unconfigured queues are passed straight through unpoliced (forwarding
unchanged).

Part of the SONiC packet-trimming enablement tracked in
sonic-net/sonic-buildimage#25789.

Changes

  • New sonic_ext plugin sources: trim_admission_node.c, trim_node.c,
    trim_api.c, trim_cli.c, sonic_ext_trim.api, and sonic_ext.h state.
  • Binary API + debug CLI to program global trim policy and per-{port,queue}
    admission/eligibility state.
  • rules/vpp.mk VPP_VERSION suffix bump so sonic-buildimage rebuilds the
    changed plugin instead of pulling a stale cached deb.

Testing

  • VPP framework plugin tests for the admission/trim nodes.
  • End-to-end PTF packet-trimming stages 1–2 pass on a t1-lag-vpp testbed
    (paired with the companion sonic-sairedis and sonic-mgmt changes).

Deferred (by design, tracked in the HLD)

Asymmetric FROM_TC DSCP, dynamic queue resolution, ACL DISABLE_TRIM,
per-port/queue SAI counter sourcing, and multi-worker bucket sharding.

Draft: opened for review only; depends on the companion sonic-sairedis
translation PR.


🤖 Co-authored with GitHub Copilot.

aaronber0614 and others added 3 commits July 30, 2026 20:04
The KVM/DPDK VPP backend has no native egress QoS/admission substrate, so
add a software packet-trimming datapath to the sonic_ext plugin:

- trim_admission_node.c: per-{port,queue} software admission shim (token
  bucket driven by the SONiC scheduler rate and buffer-profile capacity) on
  the interface-output arc.
- trim_node.c: trim action (truncate -> DSCP rewrite -> static trim-queue
  retry -> counters), including the multi-segment/jumbo fix that clears
  VLIB_BUFFER_EXT_HDR_VALID on the severed segment so the virtio PMD does not
  re-append the freed tail.
- trim_api.c, sonic_ext_trim.api, trim_cli.c: binary API and debug CLI used
  to drive trimming from SAI-VPP.
- sonic_ext.{c,h}, CMakeLists.txt: register the trim nodes/API.
- rules/vpp.mk: bump VPP_VERSION for the plugin content change.

Validated end to end on vms-kvm-vpp-t1-lag (single-segment and jumbo).

Tracking: sonic-net/sonic-buildimage#25789

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Aaron Bernardino <aaronber@microsoft.com>
Address code-review gap H1 in the packet-trimming plugin:

- sonic_ext_trim_enable_disable now returns int so callers can observe
  vnet_feature_enable_disable() failures instead of silently ignoring
  them.
- sonic_ext_trim_queue_program transition-guards the interface-output
  feature-arc toggle on a new per-port feature_enabled flag: it computes
  any_eligible across all queues and only enables/disables on an actual
  eligibility transition. vnet_feature_enable_disable() is not idempotent,
  so this prevents refcount stacking (arc stuck enabled) and guarantees
  the arc is removed once no queue is trim-eligible.
- rules/vpp.mk: bump VPP_VERSION 0.6 -> 0.7 for the plugin content change
  so downstream sonic-buildimage does not pull stale cached debs.

Validated on the dev-VM t1-lag-vpp testbed: sonic-ext-trim-admission
appears exactly once on an eligible egress port and is removed (count 0)
once its queues become ineligible.

Tracking: sonic-net/sonic-buildimage#25789

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Aaron Bernardino <aaronber@microsoft.com>
…s to the API caller

Previously sonic_ext_trim_queue_program() returned void and only logged a
clib_warning when the interface-output feature-arc enable/disable transition
failed. The binary-API handler left rv=0 regardless, so SAI-VPP never saw the
failure and could not retry, contradicting HLD REQ-12 (feature-arc enable
failures must surface to the caller).

Make the helper return int (0 on success, the vnet_feature_enable_disable
error otherwise, and VNET_API_ERROR_INVALID_VALUE for an out-of-range queue),
capture that in the queue_set handler so REPLY_MACRO forwards it as the reply
retval, and surface it from the debug CLI. The queue state itself is still
always programmed; only the eligibility feature-arc transition can fail, and
port->feature_enabled is left untouched on failure so the next queue_set
retries the transition.

Bump VPP_VERSION suffix so downstream sonic-buildimage rebuilds the changed
plugin instead of pulling a stale cached deb.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Aaron Bernardino <aaronber@microsoft.com>
Copilot AI review requested due to automatic review settings August 3, 2026 18:51
@mssonicbld

Copy link
Copy Markdown

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command.

@aaronber0614

Copy link
Copy Markdown
Author

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a new sonic_ext VPP plugin datapath implementing SAI DROP_AND_TRIM packet-trimming semantics for SONiC-VPP by introducing a software egress “admission shim” on the interface-output feature arc and a trim action node to rewrite DSCP, truncate, and re-queue to a static trim queue.

Changes:

  • Introduces per-(port,queue) software token-bucket admission (sonic-ext-trim-admission) and trim action (sonic-ext-trim) nodes.
  • Adds a binary API + debug CLI to program global trim policy, DSCP→queue mapping, and per-queue admission parameters, plus counters.
  • Bumps VPP_VERSION cache key to force rebuild of modified custom plugins/patches.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
vppbld/plugins/sonic_ext/trim_admission_node.c New interface-output feature node implementing software admission and divert-to-trim on rejection.
vppbld/plugins/sonic_ext/trim_node.c New trim action node: DSCP rewrite, packet truncation, and enqueue to interface-output-arc-end / drop.
vppbld/plugins/sonic_ext/trim_api.c New binary API handlers and shared admission helpers (port state, token-bucket admit, feature toggling).
vppbld/plugins/sonic_ext/trim_cli.c New debug CLI for configuring and dumping trim policy, admission state, and counters.
vppbld/plugins/sonic_ext/sonic_ext_trim.api New API definition for global policy, DSCP map, queue admission config, and counters.
vppbld/plugins/sonic_ext/sonic_ext.h Adds trim state to sonic_ext_main_t, per-buffer orig_queue, and shared L3 parsing/DSCP rewrite inlines.
vppbld/plugins/sonic_ext/sonic_ext.c Registers trim API hookup during plugin init and updates plugin description.
vppbld/plugins/sonic_ext/CMakeLists.txt Adds new trim sources and API file; ensures include paths for generated API headers.
rules/vpp.mk Updates VPP_VERSION suffix and clarifies when to bump it (patches + custom plugins).

Comment on lines +406 to +409
u32 v =
clib_net_to_host_u32 (ip->ip_version_traffic_class_and_flow_label);
v = (v & ~(0x3full << 22)) | (((u32) (new_dscp & 0x3f)) << 22);
ip->ip_version_traffic_class_and_flow_label = clib_host_to_net_u32 (v);
Comment on lines +127 to +137
if (size != ~0)
sem->trim_size = size;
if (dscp != ~0)
sem->trim_dscp_value = dscp & 0x3f;
if (tc != ~0)
sem->trim_tc = tc;
if (queue != ~0)
sem->trim_queue = queue & (SONIC_EXT_TRIM_MAX_QUEUES - 1);
if (mode != -1)
sem->trim_dscp_mode = mode;
sem->trim_configured = 1;
Comment on lines +165 to +180
if (mp->is_enable)
{
sem->trim_size = ntohs (mp->trim_size);
sem->trim_dscp_mode = mp->dscp_mode;
sem->trim_dscp_value = mp->dscp_value & 0x3f;
sem->trim_tc = mp->tc_value;
sem->trim_queue = mp->trim_queue & (SONIC_EXT_TRIM_MAX_QUEUES - 1);
sem->trim_configured = 1;
}
else
{
sem->trim_configured = 0;
sem->trim_size = 0;
}

REPLY_MACRO (VL_API_SONIC_EXT_TRIM_GLOBAL_SET_REPLY);
Comment on lines +192 to +196
for (i = 0; i < 64; i++)
sem->dscp_to_queue[i] =
mp->dscp_to_queue[i] & (SONIC_EXT_TRIM_MAX_QUEUES - 1);

REPLY_MACRO (VL_API_SONIC_EXT_TRIM_DSCP_MAP_SET_REPLY);
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 this pull request may close these issues.

3 participants