Skip to content

Add P4PifoTreeScheduler: hierarchical scheduling with a PIFO tree per port - #127

Merged
Mingyumaz merged 2 commits into
mainfrom
feat/pifo-tree-sched
Dec 1, 2026
Merged

Mingyumaz merged 2 commits into
mainfrom
feat/pifo-tree-sched

Conversation

@Mingyumaz

@Mingyumaz Mingyumaz commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Phase 3 of the PIFO work: hierarchical scheduling with a PIFO tree per output port (Sivaraman et al., SIGCOMM 2016). One PIFO (#123) orders all packets of a port by one rank; a tree lets classes share the port by one policy and the flows inside a class share the class by another, e.g. hierarchical fair queueing. It uses the input and output fields of #126.

What changes

  • ns3::P4PifoTreeScheduler, a third P4QueueScheduler:

    • Tree: the shape, e.g. root(a(a1,a2),b); at most 4 levels; leaves numbered in the order of the text. A tree of one leaf, such as root, reads no leaf field.
    • LeafField (leaf) and RankFields (rank0,rank1,rank2,rank3): the P4 program writes the packet's leaf and one rank per level from the root.
    • DequeueRankFields (none by default): the switch writes the rank that each level gave out before the egress (0 below the packet's leaf). A rank given out above the leaf may be another packet's, so a program with a virtual time per node needs it.
    • A full tree drops the arriving packet; a leaf the tree does not have drops it too (counted, GetLeafDrops(), one warning). qid is the leaf; enq_qdepth and deq_qdepth count the packets of the leaf.
  • utils/p4-pifo-tree.h: PifoTreeShape (the text and its errors) and PifoTree<T> (the tree of one port).

  • Example p4-pifo-hpfq: HPFQ (hpfq.p4, two levels of STFQ with a virtual time per node) next to flat STFQ; UDP flows A1 120, A2 60 and B1 80 Mbps into 100 Mbps (A1 and A2 differ, so class A splits evenly only if its node is fair); A1 stops at 1 s:

    A1 / A2 / B1 after A1 stops: A2 / B1
    flat STFQ, weights 1:1:2 25.0 / 25.0 / 50.0 % 33.3 / 66.7 %
    HPFQ, root(a(a1,a2),b), 1:1 at each level 25.0 / 25.0 / 50.0 % 50.0 / 50.0 %
  • Docs: switch.md (PIFO trees and what they model), examples.md, README (39 examples), TODO.md, test/Readme.md (260 cases; also the count and the fields test that Queue schedulers: input and output fields instead of one rank #126 left out).

  • Second commit (review fixes): hpfq.p4 bounds only the flows by MAX_AHEAD, not the classes (a class bound gave A1 32.7 % and A2 17.3 %), and moves the virtual times only forward and only for packets in the flow table; the example's rates; a tree of one leaf reads no leaf field; docs.

Scope

  • In: the tree scheduler and data structure, the example, 6 test cases, docs.
  • Out: shaping (non-work-conserving nodes, next PR); PSA; the VOQ fabric (a scheduler other than the default stops there, as before); a P4 program per node (PIFO-TM style).
  • Tested (ns-3.39 and ns-3.49, Docker, on main 6bf8e7e):
    • run-tests.sh passes: 24 suites, 260 cases (6 new), 47 example runs; build without warnings.
    • The 46 other example runs give the same exit codes and files as main; their output differs only in wall-clock lines.
    • PifoTree against a plain reference with random operations on four shapes, up to 4 levels; the tree root sends the same frames at the same times as P4PifoScheduler with tail drop, and runs a program without a leaf field.
    • p4-pifo-hpfq with 12 seeds on each version: 25.0 / 25.0 / 50.0 %, then 49.9 to 50.1 %, the same on both versions.
    • 15 mutants, 13 caught, among them the old class bound in hpfq.p4 (by the example). The two missed ones take the virtual times from the packet's own ranks instead of DequeueRankFields; the shares do not move because all flows stay backlogged. The suite checks DequeueRankFields itself, and examples.md says what the example does not show.
    • An independent review; its findings are fixed in the second commit.
    • clang-format clean; the JSON files are compiled with p4c 1.2.5.19 (the CI image).
  • Not tested: an example with more than two levels (the unit tests cover four).

Two reviews are needed before merging.

🤖 Generated with Claude Code

Mingyumaz and others added 2 commits December 1, 2026 15:46
… port

A PIFO tree (Sivaraman et al., SIGCOMM 2016) per output port, as a third
P4QueueScheduler. The attribute Tree gives the shape ("root(a(a1,a2),b)",
at most 4 levels, leaves numbered in the order of the text); the P4
program writes the packet's leaf (LeafField) and a rank per level
(RankFields, rank0 to rank3 by default). The leaves hold the packets, the
other nodes references to their children; to send, each level gives out
its smallest rank, from the root down to a leaf.

A rank given out above the leaf may be another packet's, so the switch
writes the rank that each level gave out into DequeueRankFields before
the egress; a program with a virtual time per node needs it. A full tree,
or a leaf the tree does not have, drops the arriving packet (the latter
with a warning, once). enq_qdepth and deq_qdepth count the packet's leaf.
No shaping yet.

- utils/p4-pifo-tree.h: PifoTreeShape (the text) and PifoTree<T> (one port).
- utils/p4-pifo-tree-scheduler.{h,cc}: the scheduler.
- Example p4-pifo-hpfq: hierarchical fair queueing (hpfq.p4, two levels
  of STFQ with a virtual time per node) next to flat STFQ, three UDP flows
  of 80 Mbps into 100 Mbps; when A1 stops, flat STFQ gives B1 two thirds,
  the tree keeps half of the port for class A.
- Tests (suite p4-queue-scheduler, 6 new cases): the tree text and its
  errors; PifoTree against a plain reference (order, the ranks the levels
  give out, random operations on four shapes); the scheduler in a switch
  (program test/p4src/pifo/tree): order, queue depths, DequeueRankFields,
  full tree, missing leaf; the tree "root" sends the same frames at the
  same times as P4PifoScheduler with tail drop.
- Docs: switch.md (PIFO trees, and what they model), examples.md, README,
  TODO.md, test/Readme.md (also the count and the fields test of the
  previous commit).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- hpfq.p4: only the flows may run at most MAX_AHEAD ahead, of their class's
  virtual time; that also bounds the class at the root. The bound on the
  class itself gave the class's places in the queue to whichever flow came
  first: with A1 at 120 and A2 at 60 Mbps, HPFQ gave them 32.7 and 17.3 %
  instead of 25 and 25. The virtual times now only move forward, and only
  for packets in the flow table (a packet without a flow set them back to 0).
- p4-pifo-hpfq: A1, A2 and B1 send at 120, 60 and 80 Mbps (--rateA1,
  --rateA2, --rateB1 instead of --rate), so that the check fails if node a
  does not share its class fairly. The shares stay 25/25/50 and 50/50.
- P4PifoTreeScheduler: a tree of one leaf reads no LeafField, so the tree
  root runs programs without a leaf field (test added).
- Docs: a level below the packet's leaf gets 0 in DequeueRankFields;
  examples.md, test/Readme.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Mingyumaz
Mingyumaz merged commit 1ddce0c into main Dec 1, 2026
2 checks passed
@Mingyumaz
Mingyumaz deleted the feat/pifo-tree-sched branch December 1, 2026 22:41
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.

1 participant