Skip to content

Queue schedulers: a P4QueueScheduler module and P4PifoScheduler - #123

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

Mingyumaz merged 2 commits into
mainfrom
feat/pifo

Conversation

@Mingyumaz

Copy link
Copy Markdown
Contributor

Motivation

Programmable switches schedule by ranks that the P4 program computes (PIFO, Sivaraman et al., SIGCOMM 2016): fair queueing, deadlines, least-attained service and their approximations on real hardware. P4sim's v1model output queues were a fixed strict-priority member of the core, so every new scheduling design would have meant branches in the core. This PR first makes the output queues a module of their own, then adds a PIFO scheduler as its second implementation. Next designs (more rank examples, then PIFO trees) become new classes, not core changes.

What changes

Commit 1 – P4QueueScheduler (no behavior change)

  • New interface P4QueueScheduler (utils/p4-queue-scheduler.h, an ns-3 Object): Enqueue() with the packet's metadata, Dequeue() with queue id and depth (qid, deq_qdepth), GetNextDequeueTime() (rate limits), GetDrops(), and the set_queue_depth / set_queue_rate commands.
  • P4StrictPriorityScheduler wraps the existing BMv2 queueing logic: the default, same behavior as before.
  • New device attribute QueueScheduler chooses the scheduler by type and attributes, e.g. "ns3::P4PifoScheduler[RankField=rank|DropPolicy=Arriving]". Another scheduler than the default is v1model-only (not with EnableVoqFabric or a profile without queues).

Commit 2 – P4PifoScheduler

  • One PIFO per port: the smallest rank goes first; equal ranks leave in arrival order. Its own attributes:
    • RankField (default rank): the user-metadata field, up to 64 bits.
    • DropPolicy: when full, drop the largest rank (LargestRank) or the arriving packet (Arriving).
  • The core reads the rank field that the scheduler names. A missing, ambiguous or too wide field stops with a message that lists the metadata fields.
  • After a program swap, new hook P4SwitchCore::ProgramSwapped() looks up the new program's field. It runs outside BMv2's config lock: swap_notify_() runs under that lock, so get_config() there deadlocks.
  • New example p4-pifo-stfq: STFQ computed in the ingress, weights 1:1:2. Three 60 Mbps UDP flows into 100 Mbps get 25.0 / 25.0 / 50.0 %; --scheduler=strict (one FIFO) gives about 33 % each.
  • Docs: doc/switch.md (new section "Queue schedulers"), event-driven-tm-scheduler.md, README, examples.md, test/Readme.md, TODO.md.

Scope

  • In: the scheduler interface; strict priority (unchanged) and PIFO on v1model; test suite p4-queue-scheduler (13 cases); example p4-pifo-stfq.
  • Out:
    • PSA keeps its own queues (TODO: give it a P4QueueScheduler).
    • The VOQ + fabric path stays separate.
    • Next PR: rank examples LAS, EDF, SP-PIFO, AIFO. Later: PIFO trees.
  • Tested (ns-3.39 and ns-3.49, Docker), each commit on its own:
    • run-tests.sh passes. Commit 1: 24 suites, 242 cases, 42 example runs. Commit 2: 24 suites, 253 cases, 44 example runs.
    • All 42 example runs of main give the same exit codes, files and output on both commits; only the lines with wall-clock times differ.
    • The PIFO cases check order, queue depths, both drop policies against a reference, frame-by-frame equivalence with the priority queues (one rank for all frames, also when full, same drops; rank = 7 − priority), the rank-field errors, the ignored commands and a program swap.
    • 12 mutants of the PIFO, the strict scheduler and the core are all caught.
    • p4-benchmark --packets=300000 on an idle machine (default path, 3 alternating runs each): 44.1k–46.8k packets/s on main, 44.2k–47.6k on this branch, so no slowdown.
    • clang-format clean.
  • Not tested: speed with large PIFOs (a std::set per port, O(log n) per packet); a rank field inside a nested struct.

Two reviews are needed before merging.

🤖 Generated with Claude Code

Mingyumaz and others added 2 commits November 30, 2026 20:41
The output queues of a v1model switch were a fixed member of the core
(BMv2's strict-priority queueing logic). They are now a P4QueueScheduler,
an ns-3 object that holds the packets after the ingress, picks the next
packet of a port and drops packets when it is full. The new attribute
QueueScheduler of P4SwitchNetDevice chooses it by type and attributes
("ns3::<type>[<attribute>=<value>|...]"). The default,
P4StrictPriorityScheduler, wraps the same queueing logic, so the switch
behaves as before.

- P4CoreV1model calls the scheduler instead of the queues: Enqueue() with
  the packet's metadata (its priority), Dequeue() for the next packet of a
  port with its queue and depth (qid, deq_qdepth), GetNextDequeueTime()
  for rate limits, and the commands set_queue_depth and set_queue_rate.
  New: SetQueueScheduler() and GetQueueScheduler().
- The strict-priority scheduler counts its drops (GetDrops()). A drop in
  the queues now also lets a pending program swap go ahead.
- A scheduler other than the default works with v1model only, not with
  EnableVoqFabric or a target profile without queues; the switch stops
  with a message otherwise.
- PSA keeps its own queues for now (doc/TODO.md).

New test suite p4-queue-scheduler (2 cases). Docs: switch.md (new
section), event-driven-tm-scheduler.md, README, test/Readme.md, TODO.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A second queue scheduler for v1model switches. With QueueScheduler
"ns3::P4PifoScheduler", each output port has one PIFO (push-in first-out
queue, Sivaraman et al., SIGCOMM 2016) instead of eight strict-priority
queues: it sends the packet with the smallest rank first, of equal ranks
the one that came first. The P4 program computes the rank in the ingress.

- Attribute RankField (default "rank"): the user-metadata field that holds
  the rank, by its name or full name ("metadata_t.rank"), up to 64 bits.
  P4QueueScheduler::GetRankFieldName() tells the switch to read it into
  P4QueueMetadata::rank; the core looks the field up when it starts and
  after a program swap (P4CoreV1model::FindRankField(), GetRankField()).
  A missing, ambiguous or too wide field stops with a message that lists
  the metadata fields.
- New hook P4SwitchCore::ProgramSwapped(), called after a swap and before
  the held frames re-enter: swap_notify_() runs under BMv2's config lock,
  where get_config() deadlocks.
- Attribute DropPolicy: a full PIFO drops the largest rank (LargestRank,
  default) or the arriving packet (Arriving). QueueBufferSize and
  set_queue_depth without a priority set the capacity per port;
  set_queue_rate and set_queue_depth for one priority are ignored with a
  warning. enq_qdepth and deq_qdepth count the PIFO.
- utils/p4-pifo-queue.h: the PIFOs (std::set by rank and arrival).

Suite p4-queue-scheduler: 11 new cases (PifoQueues alone; order by rank
and FIFO for equal ranks, queue depths, transfer buffer; both drop
policies; equivalence with the priority queues, frame by frame: one rank
for all frames, also when full, and rank 7 - priority; the rank field and
its errors; the commands that do not apply; a program swap).

New example p4-pifo-stfq: start-time fair queueing computed in the
ingress, weights 1:1:2 from the flow table; three UDP flows of 60 Mbps
share a 100 Mbps port 25:25:50 (a FIFO with --scheduler=strict: about a
third each).

Docs: switch.md, README, examples.md, test/Readme.md, TODO.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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