Repository navigation
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)P4QueueScheduler(utils/p4-queue-scheduler.h, an ns-3Object):Enqueue()with the packet's metadata,Dequeue()with queue id and depth (qid,deq_qdepth),GetNextDequeueTime()(rate limits),GetDrops(), and theset_queue_depth/set_queue_ratecommands.P4StrictPrioritySchedulerwraps the existing BMv2 queueing logic: the default, same behavior as before.QueueSchedulerchooses the scheduler by type and attributes, e.g."ns3::P4PifoScheduler[RankField=rank|DropPolicy=Arriving]". Another scheduler than the default is v1model-only (not withEnableVoqFabricor a profile without queues).Commit 2 –
P4PifoSchedulerRankField(defaultrank): the user-metadata field, up to 64 bits.DropPolicy: when full, drop the largest rank (LargestRank) or the arriving packet (Arriving).P4SwitchCore::ProgramSwapped()looks up the new program's field. It runs outside BMv2's config lock:swap_notify_()runs under that lock, soget_config()there deadlocks.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.doc/switch.md(new section "Queue schedulers"),event-driven-tm-scheduler.md, README,examples.md,test/Readme.md,TODO.md.Scope
p4-queue-scheduler(13 cases); examplep4-pifo-stfq.P4QueueScheduler).run-tests.shpasses. Commit 1: 24 suites, 242 cases, 42 example runs. Commit 2: 24 suites, 253 cases, 44 example runs.maingive the same exit codes, files and output on both commits; only the lines with wall-clock times differ.p4-benchmark --packets=300000on an idle machine (default path, 3 alternating runs each): 44.1k–46.8k packets/s onmain, 44.2k–47.6k on this branch, so no slowdown.std::setper port, O(log n) per packet); a rank field inside a nested struct.Two reviews are needed before merging.
🤖 Generated with Claude Code